cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L151RCTxA RTC Stop Mode UART/DMA

buff thokoa
Associate III
Posted on May 02, 2018 at 14:30

Hi all,

I am using the STM32L151RCTxA MCU with STM32CUBEMX.

I have configured FREERTOS, a UART using DMA and tickless IDLE.

I am attempting to run my MCU in low power mode.

My first misunderstanding is how to get the MCU to trigger the PreSleepProcessing and PostSleepProcessing functions. Should it not be a case of simply suspending all my tasks with osThreadSuspendAll()?

If I bypass these functions and manually call the sleep functions I am successful calling HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);

I would like to go one step further and go into STOP RTC mode. I have configured an RTC to wake up every 10s.

I am sending a command to a LoRa module to tell it to go to sleep. I am expecting an 'OK' response when it times out so that I can do some processing. If I call HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); when I wake up via the RTC I seem to have lost my connection to the module and have to reset it to communicate on it again. I have read that I must deinit the UART and renitialise again on wakeup but that does not seem to help.

Has anybody experienced similar and found a way around it? My code to enter STOP mode is below.

HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);

HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x5F46, RTC_WAKEUPCLOCK_RTCCLK_DIV16);

HAL_UART_MspDeInit(&huart3);

//if (HAL_UART_DeInit(&huart3) != HAL_OK)

//{

// _Error_Handler(__FILE__, __LINE__);

//}

HAL_SuspendTick();

/* Enter Stop Mode */

//HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);

HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

HAL_ResumeTick();

/* Configures system clock after wake-up from STOP: enable HSI, PLL and select

PLL as system clock source (HSI and PLL are disabled automatically in STOP mode) */

SystemClockConfig_STOP();

On wakeup I simply initialise the UART and wait for the OK.

/* Disable Wakeup Counter */

HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);

HAL_UART_MspInit(&huart3);

//MX_USART3_UART_Init();

//if (HAL_UART_Init(&huart3) != HAL_OK)

//{

// _Error_Handler(__FILE__, __LINE__);

//}

I would really appreciate any help here. I feel I am close but there is some final thing I am not understanding

18 REPLIES 18
Posted on June 21, 2018 at 18:20

It is working in a bare metal code configuration... It does not work when running on freeRTOS.

That's weird...

Posted on June 22, 2018 at 12:02

I'm using the RN2483 module...

I don't think it's the module... It's the communication link to it... re the USART.

Posted on June 22, 2018 at 12:03

Does the vPortSuppressTicksAndSleep function not keep track of all of that as soon as you configure ticklessidle more in the RTOS??

Posted on June 22, 2018 at 13:14

The vTaskStepTick() tells the amount of ticks that the OS has lost during tickless idle. (When the tick interrupt hasn't been running.)

And the sleep should not exceed the amount of ticks that the OS gives to the tickless idle function via the parameter.

And the default template for vPortSuppressTicksAndSleep() is often not tickless. You are supposed to make that function applicable to your needs.

(Actually that vPortSuppressTicksAndSleep() is usually a macro that you are supposed to 'overload'.)

Posted on June 22, 2018 at 13:16

The code you showed in the beginning of this thread is supposed to go into the vPortSuppressTicksAndSleep() function.

Posted on June 22, 2018 at 13:21

This might be of help:

https://www.freertos.org/low-power-tickless-rtos.html

 
Posted on June 22, 2018 at 13:35

How do you put the module to sleep and how do you wake it up? Do you wake it up, or do you let it wake up on its own?

2.3.1

sys sleep <length>

<length>

: decimal number representing the number of milliseconds the system is

put to Sleep, from 100 to 4294967296.

Response:

ok

after the system gets back from Sleep mode

invalid_param

if the length is not valid

This command puts the system to Sleep for the specified number of milliseconds. The

module can be forced to exit from Sleep by sending a break condition followed by a

0x55

character at the new baud rate. Note that the break condition needs to be long

enough not to be interpreted as a valid character at the current baud rate

Posted on June 22, 2018 at 13:43

I'm letting it wake up on its own... I might also wake it up later but for now I am just letting it wake up on its own

Posted on June 22, 2018 at 14:44

Thankx... will check it out