eclipse-threadx / usbx

Eclipse ThreadX - USBX is a high-performance USB host, device, and on-the-go (OTG) embedded stack, that is fully integrated with Eclipse ThreadX RTOS
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/usbx/index.md
MIT License
154 stars 89 forks source link

USB host stack sizes need to be large. #21

Open maxkunes opened 3 years ago

maxkunes commented 3 years ago

Hi,

It seems the default stack size for UsbX in the gnu port file is too small for even my basic application of USB mouse and keyboard. I believe it is set to 2048 by default. 8192 seems to do the trick for me. However, I can probably get away with something in the middle.

When the stack size is too small I always get a hard fault in the UX function that searches for a free memory block called by the ux allocate function. This occurs when I plug in a device for a second time. IE: plug in a device, unplug the device, and plug it back in. 100% hardfault using that scenario with the default stack size on USBx v6.1.7. I know it is a stack corruption as the local variables get corrupted and simply upping the stack size fixes the issue. This issues happens nomatter how many devices are used. It happens constantly with just a basic mouse after the second plug in.

It's not really a bug, but it seems something has changed recently, from the older versions, that are requiring a larger stack size. This is more so a note to others that might run into a similar issue.

I'm on the ARM platform using an MXRT1064

parthindia47 commented 3 years ago

Max, Is this stack size for threads or is it stack size for USBx ?

Thread size is provided here

tx_thread_create(&tx_mass_storage_thread, "tx demo", mass_storage_thread_entry, 0,
          stack_pointer, DEMO_STACK_SIZE,
          30, 30, 1, TX_AUTO_START);

USBx stack size is passed in this function call : ux_system_initialize(memory_pointer, USBX_MEMORY_SIZE, UX_NULL, 0);

And I would be surprised if USBx stack works with 8K.

maxkunes commented 3 years ago

I'm referring to the thread stack sizes inside of usbx. They can be configured in ux_user or ux_port.h

Like here: https://github.com/azure-rtos/usbx/blob/master/ports/cortex_m7/gnu/inc/ux_port.h#L121

I'm not talking about the RAM given to ux in initialization. I already give USBX > 100k of memory to play with.

On Thu, Jun 24, 2021, 10:09 PM parth pandya @.***> wrote:

Max, Is this stack size for threads or is it stack size for USBx ?

Thread size is provided here tx_thread_create(&tx_mass_storage_thread, "tx demo", mass_storage_thread_entry, 0, stack_pointer, DEMO_STACK_SIZE, 30, 30, 1, TX_AUTO_START);

USBx stack size is passed in this function call : ux_system_initialize(memory_pointer, USBX_MEMORY_SIZE, UX_NULL, 0);

And I would be surprised if this works with 8K stack.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/azure-rtos/usbx/issues/21#issuecomment-868208273, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACZP7FFOEOPKGQQXGWYCIHLTUQFRNANCNFSM47I7QB2Q .

wetechautomation commented 2 years ago

I am able to get usbx working in 20KB in host mode stack

yuxin-azrtos commented 2 years ago

@maxkunes The intention is to allow developers to specify a suitable stack size in ux_port.h. Given different architectures we support, and the individual use case, its hard to set a default that is big enough but not too big to waste RAM space.