-2

i am testing the low power mode in my bl072z lora board, i call the low power mode function and when i wake up from this state (after a timer set to 20 seconds) the led blinks, everything ok, but if i print a message using PRINTF instead the blink led to know if the board wakes up i never enter in low power mode and just see the PRINTF message in the terminal, why i can't use PRINTF with the low power function?

//does not works

while(1)
{

LPM_EnterLowPower( );
PRINTF("woke up\n\r");

}

//works

while(1)
{

LPM_EnterLowPower( );
BSP_LED_Toggle(LED_GREEN);

}

//works

while(1)
{

LPM_EnterLowPower( );
PRINTF("woke up\n\r");
HAL_Delay(500); //works with this delay but i don't know why

}

//low power function:
void LPM_EnterLowPower(void)
{
 HAL_PWR_EnterSTOPMode ( PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI );
}

i use the "woke up" message to know if i exit from sleep mode, i call the low power function and after 20 seconds i expect to see "woke up" just once in the terminal and then go to sleep again and repeat the process, everything works fine with the led but does not works printing a message,in the terminal i only see (indefinitely):

woke up
woke up
woke up
woke up
  • I'm guessing that the output from `PRINTF` goes to a serial port. Which means it goes through a UART. Typically a UART will generate an interrupt after it sends each character. An interrupt will cause the processor to leave low power mode. So you need to wait until the UART finishes sending the message before entering low power mode. That's what the `HAL_Delay(500)` is doing. It gives the UART time to finish. – user3386109 Aug 19 '19 at 05:03
  • @Brian Tompsett - 汤莱恩, i have edited my question, do you think is ok now?, if not, what changes should i do?, thanks – jg_spitfire Aug 23 '19 at 12:02
  • @dandan78, i have edited my question, do you think is ok now?, if not, what changes should i do?, thanks – jg_spitfire Aug 23 '19 at 12:02
  • @tarleb, i have edited my question, do you think is ok now?, if not, what changes should i do?, thanks – jg_spitfire Aug 23 '19 at 12:02

1 Answers1

1

As soon as PRINTF("woke up"\n\r); is called, you call LPM_EnterLowPower();.
The message "woke up" can't be displayed before the low power function is called, because there's no delay between the two, so low power mode is never entered except for the first time.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
  • Hi, how do you know that?, according to me, when i call a function as PRINTF in this case, the program executes the function and runs all the code inside it, then starts with the next function (LPM_EnterLowPower), so, why the program starts to execute the next function if have not finished to execute the first? – jg_spitfire Aug 23 '19 at 21:48
  • @JairoGallardoGonzalez The hardware doesn't have time to write "woke up" on the screen before it's signaled to enter low power mode. It's still processing `PRINTF("woke up"\n\r);` when `LPM_EnterLowPower();` is called. – S.S. Anne Aug 24 '19 at 13:51