Execution of PostSleepProcessing()

groger57 wrote on Monday, March 11, 2019:

Hello:
I am using version 9.0 FreeRTOS, and the processor is an STM32L476. I initially set the code up using CubeMX, in tickless mode. I then added the code to use FreeRTOS. I changed the necessary defines in FreeRTOSConfig as required to support tickless mode.

The call to PreSleepProcessing() is getting executed. In there, I am powering off GPIOs not being used and then calling:
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);

Currently there is no code in the function PostSleepProcessing().

Objective:
I have a hardware line connected to the sys wake pin, but not looking at that right now. At present, I would like to just have a single task execute every 1000ms. One of the things it does is refresh the IWDG. The problem is, once it goes to sleep, it never “wakes up”. At least the function to PostSleepProcessing never executes.

Appears my understanding of how this functions isn’t there. What’s missing? Should the task not generate an interrupt every 1000ms?

Is there some demo code for the STM32F/L4 that shows how this is accomplished? Or a webpage with a clear explanation so I can fill in the missing pieces?

Thanks for your help, Gary

groger57 wrote on Monday, March 11, 2019:

Hello,
If this post and my questions too elementary for this website, where can I get detailed information on how to implement the code I need to accomplish the above? I would appreciate it if someone could at least provide that.

Thanks.

groger57 wrote on Monday, March 11, 2019:

To be clear, I find bits and pieces on this topic but not a single clear, basic example of implementation. that provides a bit of explanation. Sorry, I cannot put those pieces together, too many holes between.

rtel wrote on Monday, March 11, 2019:

The main question is, why is it not waking up.

Are you using the ‘generic’ tickless idle code that is implemented in
the FreeRTOS’s port.c file? Or is there something chip specific?

What does HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON,
PWR_SLEEPENTRY_WFI); turn off? Specifically, does it turn off the clock
that you are using to generate the interrupt that wakes you from sleep
mode? If you are using the generic tickless idle mode that will be the
SysTick timer.

Does it work if you don’t call HAL_PWR_EnterSLEEPMode()? I know you
need to call that, but trying without that call will give a clue as to
whether it is that which is preventing the code from waking.

groger57 wrote on Tuesday, March 12, 2019:

I really appreciate your time to help me out. Using CubeMX, I selected TIM17 to generate the tick. I can see in the interrupt handler it is executed. Let me clarify.

In vApplicationIdleHook( void ), if I do this and only this:
__HAL_RCC_CAN1_CLK_DISABLE();
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON,PWR_SLEEPENTRY_WFI);

My single task keeps executing, and current drops about 30%. I know the task is executing because the IWDG is getting kicked, so it appears the HAL call does not disable the timer, rather, just puts the CPU into a low power state, not sleep. If it was in sleep, the current should be much lower, less than half, correct?

I then place those 2 lines of code in the function “PreSleepProcessing”. Then in the vApplicationIdleHook I place this code instead:
interval = 0;
PreSleepProcessing(interval);

The PreSleepProcessing function is called and executes those 2 lines, goes to sleep but stays there. So in this case, the timer is getting shut off it appears. What am I missing?

Thanks!

groger57 wrote on Tuesday, March 12, 2019:

I am reading the manual section on portSUPPRESS_TICKS_AND_SLEEP and it’s now making a bit more sense. I’m going to give the implemntation a try and may have some questions. Thanks.