I’m working on stm32l4 MCU with freertos. My application task stopped working after waking up from stop2 mode. If I do not enter into stop2 mode its works fine. But if its go to stop2 mode and wakeup it get stuck after a while. What I found is if I do not set the deepsleep bit in stop2 mode it works fine as soon as I set that bit, after a while couple of task stopped and those task have long delay as well about 10sec.
If anyone have gone through this situation please help me or do you have any idea why deepsleep bit making problem.
Also remember that STOP mode disables some clocks “permanently”, which means after wake-up you have to re-enable them. Similarly, waking from STOP mode selects a specific clock to be SYSCLK, so if that’s not the one you want, you have to re-select the desired SYSCLK.
The clock configuration that might change due to STOP mode is held in RCC->CR and RCC->CFGR. If you’re using MSI for SYSCLK (or HSI for SYSCLK with STOPWUCK set) then these registers won’t change with stop mode.
What is happening when the application “gets stuck”? Can you see in the debugger what the system is doing?
Can you post the task code that puts the system to sleep and wakes it up again?
I have looked in STOPWUCK bit its cleared before going to sleep and after waking up.
I’m using USART with dma with 1MB/s baudrate. task stop at some point while waiting for the data and one task are sending data to the Queues and other receive the data in the queue and transmit through the usart. if the problem with task priorities than why its not get stuck when deepsleep bit not set. I run application for couple of days with high traffic but it never crash or stuck but as soon as seepsleep bit set it start getting stuck after a while.
Those screen shots of the initialization structure are showing the wrong thing. If you want to be sure STOP mode did not change your clock config, you should check the registers RCC->CR and RCC->CFGR before and after STOP mode.
I think your issue is probably trying to use DMA and/or the USART in STOP mode. They don’t work in stop mode and would likely cause your exact symptoms if you try to use them in STOP mode.
Can you “pause” execution in the debugger to see what these tasks are doing when they are “stuck” but in the READY state? Then you might find an important clue.
Can you post the code the enters STOP mode? Then we might be able to suggest a method to divide and conquer. For example, the problem may be in the code to enter/exit stop mode instead of stop mode itself.
Yes sure. I find that my dma and usart not getting work properly after waking up: I can’t debug that ready task because they are stop execution I tried to put breakpoints as well they are not executing.
this the Sleep function
void Sleep(void){
bool can_sleep = true;
vTaskDelay(10);
if (errts_awake_tasks)
can_sleep = false;
if (wakeup_required())
can_sleep = false;
if(UPDATE_ANALOG) can_sleep = false; // if analog +24v loop supply ON from diagnostic will keep wake up for 2 minutes.
/* Don't sleep while registered tasks are awake */
if (can_sleep){
vTaskDelay_Out = Set;
Leds_ctrl_db = 0x00; Leds_ctrl_IO = 0x00; // turn off all leds
Daug_Board_PinSet(IO_LED_ALL_OFF, DB_LED_ALL, ALL_OFF);
USB_DEINIT();
while (1){
/*Disabling Modules and powers............*/
DisablePWR();
DeInit_Modules();
disable_clocks();
/*Enter in STOP2 MODE.....................*/
HAL_SuspendTick();
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
HAL_ResumeTick();
/*Enabling and Initializing the modules and powers........*/
if (Init_Modules()){
HAL_Delay(10);
Daug_Board_PinSet(IO_LED_ALL_OFF, DB_LED_ALL, ALL_OFF);
if (wakeup_required()){
break;
}
/* else just keep the OK LED on for 100msec and then back to sleep. */
ERRTS_Delay(100);
Daug_Board_PinSet(IO_LED_ALL_OFF, DB_LED_ALL, ALL_OFF);
}
}
vTaskDelay_Out = clear;
}
vTaskDelay(10);
Are you absolutely sure there’s no possibility of a FreeRTOS context switch occurring when can_sleep is true? If there is a context switch during your preparations for stop mode or during your recovery after stop mode, the other task allowed to run could be very confused – especially if it uses the HAL. One specific case worth extra consideration is the interrupt that wakes you from stop mode. Be sure its ISR does not induce a context switch. To this end, you might consider calling vTaskSuspendAll() and vTaskResumeAll() in the same places where you set vTaskDelay_Out. That will protect you from context switches.
To see if stop mode itself is really the culprit, you might try this experiment:
}
else
{
/* Request Wait For Event /
__SEV();
__WFE();
__WFE();
}
/ Reset SLEEPDEEP bit of Cortex System Control Register */
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
}
If I do not set SCB->SCR register it start working but if I set does not work.
Thanks for taking the time to report your solution. It seems many people have struggled with the problems caused by letting the ST HAL use systick for its timebase.