New to FreeRTOS and liking it so far.
We (company I’m working for) decided to dive into the deeper end of the pool and go with using the the tickless approach and putting the CPU into Stop mode. This saves power by a significant amount and need to do this to meet the design criteria for the product.
The problem comes in where I have to wake up the CPU on an I2C message. The I2C Peripheral seems to hang fairly consistently (but not always) the first time around. Not quite sure what, but something appears to reset the peripheral after several seconds or it gives up or something and there on out it fairly consistently (but not always) works. There are other interrupts that happen on a periodic basis (every 10 seconds) and I suspect the peripheral comes to life and the error handling resets it.
I am using code out of an STM32 cortex-M0+ port that was available, here is how I get into STOP mode:
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI); __HAL_RCC_PWR_CLK_ENABLE(); HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
The original code was wrong, it disabled interrupts before going to stop mode which ensured the CPU would never wakeup.
In my ISR, I start and stop timers and have been told that I need to do special things because tasks that are higher priority can get scheduled in because of some action in the ISR.
So, it looks like I need to call portEND_SWITCHING_ISR(x) in the ISR. Does this have to be at the end of the ISR or can I call it right after I call the Start/Stop timer code? There are several places where I might manipulate the timers, which is why I ask if I it is ok to do the portEND_SWITCHING_ISR in the middle of the ISR.
Has anyone done the same thing (STM32 Cortex-M0+ in Stop mode and wake up on I2C message) successfully? Or something close? The difference may be that the I2C peripheral will stretch the clock line on the I2C START condition until the internal clock spins up from sleep and allows the processor to run at normal speeds. It then compares the address to makes sure the message has the right address and if so, wakes up the CPU core, otherwise it goes back to Stop mode as if nothing happened.
Any help or suggestions would be greatly appreciated.
Thanks in advance!