Trouble with HOST HID examples

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Trouble with HOST HID examples

跳至解决方案
2,609 次查看
robertofrechill
Contributor III

Hi! I´m working with Bare metal USB Stack 4.1.1.

I´m debbugging this HOST HID examples in Codewarrior 10.3 and it doesn´t work! :smileysad:

At first appears the message: 

USB HID Mouse

Waiting for USB Mouse to be attached...

then, when i plug a mouse, the message: '' ISR is entered on vector number 0x3" and it repit forever while device is plugging.

Anybody could help me with this? thanks!

标记 (4)
0 项奖励
回复
1 解答
2,102 次查看
BlackNight
NXP Employee
NXP Employee

That define is used to control if a global variable is reserved for the bdt USB buffer, or if the memory for the buffer shall by allocated dynamically (e.g. malloc()).

Are you using the Freescale (non-gcc) ARM compiler?

If that define is defined, then this code is active:

#ifdef __CWCC__
#pragma define_section usb_bdt ".usb_bdt" RW
__declspec(usb_bdt) uint_8_ptr bdt;

It means that there needs to be a memory area allocated in the linker file for the USB bdt block, otherwise it will fail.

Obviously this is missing in the example :-(.


In my applications I don't want depend on malloc() for the buffer, so I use a static variable. But then it depends on the linker/compiler how to allocate this variable. The problem is that it needs to be aligned at a 512 byte boundary.

With ARM gcc this can be done in the source with

__attribute__((__aligned__(512))) uint8 bdt[512];

but not with the Freescale Kinetis compiler. To my knowledge you cannot align a variable in the source. This needs to be done in the linker file.


So I would say a better fix would be this:

/* Global variables */

#ifndef __CWCC__ /* Freescale (non-gcc) Kinetis compiler. If the macro below is enabled, the bdt buffer needs to be defined in the linker file */

  #define _BDT_RESERVED_SECTION_ /* if defined, we use a static buffer (instead of malloc()), on a 512 byte boundary */

#endif

I hope this helps to clarify the issue. I have passed this to the USB stack team.



在原帖中查看解决方案

0 项奖励
回复
6 回复数
2,102 次查看
robertofrechill
Contributor III

Hi guys! I fixed the problem!! the solutions are comment out this lines of driver/khci_kinetis.c file:

49:  //#define _BDT_RESERVED_SECTION_  // TBD

.......

592://#if!(defined _BDT_RESERVED_SECTION_) /* << EST */

.......

594://#endif /* << EST */

Thanks all for your help

2,102 次查看
robertofrechill
Contributor III

sorry, i forget say that i´m working with TWR-K20D72M Tower kit complete.

0 项奖励
回复
2,102 次查看
admin
Specialist II

Hey,

For what it's worth... I don't think it's related to the hardware.  This hidmouse example works with USB stack 4.0.3, just not the latest OS-less 4.1.1 (I'm seeing the same Hard Fault on the TWR-K20D50M).  For what it's worth...according to the vector table (in vectors.c), that vector number corresponds to "ivINT_Hard_Fault". 

It may help to study the differences between the two stacks to see what key thing might have changed and caused this.  I'm interested to investigate this as well.

-Rich

0 项奖励
回复
2,102 次查看
admin
Specialist II

Hey,

I found where the issue was and was able to get this working.  Navigate to the driver/khci_kinetis.c file and comment out line 49:

49:  //#define _BDT_RESERVED_SECTION_  // TBD

This may not be the best solution, but it should get you up and going for your hid mouse example (this _BDT_RESERVED_SECTION_  was previously undefined in 4.0.3 and appeared to be the key difference for me).  It now works on my end on the TWR-K20D50M.  Also, since the modification is to the low-level driver code which is shared by the other USB classes on your machine, you might want to make a note of this in case this breaks other USB apps.

Let me know if you have any luck with this.

Rich

2,103 次查看
BlackNight
NXP Employee
NXP Employee

That define is used to control if a global variable is reserved for the bdt USB buffer, or if the memory for the buffer shall by allocated dynamically (e.g. malloc()).

Are you using the Freescale (non-gcc) ARM compiler?

If that define is defined, then this code is active:

#ifdef __CWCC__
#pragma define_section usb_bdt ".usb_bdt" RW
__declspec(usb_bdt) uint_8_ptr bdt;

It means that there needs to be a memory area allocated in the linker file for the USB bdt block, otherwise it will fail.

Obviously this is missing in the example :-(.


In my applications I don't want depend on malloc() for the buffer, so I use a static variable. But then it depends on the linker/compiler how to allocate this variable. The problem is that it needs to be aligned at a 512 byte boundary.

With ARM gcc this can be done in the source with

__attribute__((__aligned__(512))) uint8 bdt[512];

but not with the Freescale Kinetis compiler. To my knowledge you cannot align a variable in the source. This needs to be done in the linker file.


So I would say a better fix would be this:

/* Global variables */

#ifndef __CWCC__ /* Freescale (non-gcc) Kinetis compiler. If the macro below is enabled, the bdt buffer needs to be defined in the linker file */

  #define _BDT_RESERVED_SECTION_ /* if defined, we use a static buffer (instead of malloc()), on a 512 byte boundary */

#endif

I hope this helps to clarify the issue. I have passed this to the USB stack team.



0 项奖励
回复
2,102 次查看
mauroansaloni
Contributor II

Hi. Did you try with a different mouse?

just to see if the problem is general or maybe triggered by some devices

0 项奖励
回复