cancel
Showing results for 
Search instead for 
Did you mean: 

H7 USB doesn't work with Core WFI

The USB Host seems to not work if WFI is executed in the FreeRTOS Idle task.  Is it not possible to use USB with a WFI Core sleep?

Thanks for any insight.  A forum search yielded mention of similar problems on other devices (over years!) but no definitive (or even helpful) answers/solutions/explanations.

7 REPLIES 7
Piranha
Chief II

Show the exact and complete code of the vApplicationIdleHook() function.

Hi Piranha,

void vApplicationIdleHook( void )
{

    HAL_PWR_EnterSLEEPMode( PWR_MAINREGULATOR_ON /* Regulator */,
                            PWR_SLEEPENTRY_WFI /* SLEEPEntry */ );

}   /* close vApplicationIdleHook( ... */

Not much to it...other peripherals, SPI, UART, I2C, etc., seem to be operating just fine.

Piranha
Chief II

Oh, the self torture by the broken bloatware again... Apart from being useless and bloated by design, that HAL function is also broken, because it is missing a DSB instruction. This is how the correct implementation looks like:

 

void vApplicationIdleHook(void)
{
	__DSB();
	__WFI();
}

 

Seriously?  That's it?  Just curious, how does that convince USB to play nice?

I'm guessing I can do the DSB before the HAL call and it'll still work?

Tried the __DSB() with the same USB (mis)behavior.  Any other suggestions, please?

Piranha
Chief II

Couldn't be more serious - that is an ARM architectural requirement and on Cortex-M7 it is mandatory. Instead of clicking Cube and spending a time on broken bloatware made by incompetent fools, I read the documentation and implement decent code - that's why I know this! 😉 DSB keeps away instruction reorder, data pre-fetch and drains the write buffer. Imagine the CPU going to sleep before some important store instruction is actually written out. Or the CPU reading some data, which should be read after wake-up, before executing the WFI. That is the "fun" the broken bloatware provides! And no, the DSB is a barrier instruction and must be executed right before WFI.

Is the USB stack also the broken bloatware? In that case, are you using it correctly? Read more about it in this post and further discussion:

https://community.st.com/t5/stm32-mcus-products/issue-with-stm32-usb-transmit-interrupted-by-receive/m-p/588507/highlight/true#M222512

Oh, I never doubted that the DSB is absolutely required and I fully agree it's pure sloppy stupidity for it to not be in the HAL from the outset.  I'll have to look further into your USB stack comments - up to this point someone else has (thankfully) wrestled with USB.  However, attempting to reduce power consumption with the WFI renders USB inoperable and guess what gets blamed?  Hahaha, yeah, the WFI.  Go figure.