Showing results for 
Search instead for 
Did you mean: 

STM32H745 USB HOST and FreeRTOS CMSIS V1 problem

Senior III

I have a project created with TouchGFX for STM32CubeIDE.

All in latest versions and it works. The firmware pack has a support for the WM8994 audio chip as BSP driver. I lost like a month of my work trying to figure out why the driver fails randomly to communicate with the chip.

I figured out it's because it doesn't use any mechanism to synchronize access to the I2C that is needed to read and write the chip's registers. However, the BSP driver in fact has the required code, just disabled, because I had to set BSP_USE_CMSIS_OS macro first. So I set the macro, the relevant code was unlocked, but failed to compile, because it uses CMSIS V1, not V2 that was default for the project.

As I wanted to be sure I don't change ANYTHING in the audio driver, I just switched the project's CMSIS API to V1. I had to update some of my code, but it was pretty trivial, so my project seemed to work at first. Until I noticed I don't have USB support anymore.

A short investigation showed that the USB HOST process is not started. It is supposed to be started by FreeRTOS, but it fails to start because of zero passed as the stack size for the process. So I manually fixed it in my `usbh_conf.h` file like this: `#define USBH_PROCESS_STACK_SIZE ((uint16_t)512)`. Naturally it worked, we're good. But here's the actual problem:


There's no way to define the stack size in STM32CubeIDE. So any change made with CubeIDE will reset my change to zero, and I must remember to manually fix it to 512.

Now I'll be just guessing. When a new thread is created with CMSIS V2, when the stack size zero is passed, it doesn't actually set the stack size to zero, but to a certain default value, like 512 or 1024. So in V2 zero probably means "use default". In V1, using zero sized stack is invalid. I think it makes more sense than V2 approach.

Anyway, why can't it be set with CubeIDE? It seems like a bug to me, I wonder if anyone knows how to fix this annoyance, so I could safely save changes in IOC file not having to worry about invalid stack size for the process. Maybe is there a way to manually edit the IOC file to make it work properly?

I can think of a workaround of just copying the initialization code to a separate file and function, that would just not be overwritten by CubeIDE, but it just doesn't feel right.

Senior III

Oopsie. There is a gear icon when the value is clicked, I can choose "No check" and then I can enter whatever, like 512.