2022-02-03 02:14 AM
#include <string.h>
#include <stdio.h>
#define printf(...) HAL_UART_Transmit((UART_HandleTypeDef *)&hlpuart1, (uint8_t *)u_buf,\
sprintf((char*)u_buf,__VA_ARGS__), 0xFFFF);
uint8_t u_buf[256];
/* USER CODE BEGIN 2 */
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); // clear the flag
/** display the string **/
printf("Wakeup from the STANDBY MODE\r\n");
/** Blink the LED **/
for (int i=0; i<20; i++)
{
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_Delay(200);
}
/** Disable the WWAKEUP PIN **/
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // disable PA0
/** Deactivate the RTC wakeup **/
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
}
/** Now enter the standby mode **/
/* Clear the WU FLAG */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
/* clear the RTC Wake UP (WU) flag */
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
/* Display the string */
printf("About to enter the STANDBY MODE\r\n");
/* Blink the LED */
for (int i=0; i<5; i++)
{
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_Delay(750);
}
/* Enable the WAKEUP PIN */
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
/* enable the RTC Wakeup */
/* RTC Wake-up Interrupt Generation:
Wake-up Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSI))
==> WakeUpCounter = Wake-up Time / Wake-up Time Base
To configure the wake up timer to 5s the WakeUpCounter is set to 0x2710:
RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16
Wake-up Time Base = 16 /(32KHz) = 0.0005 seconds
==> WakeUpCounter = ~5s/0.0005s = 20000 = 0x2710
*/
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x5F46, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
{
Error_Handler();
}
/* one last string to be sure */
printf("STANDBY MODE is ON\r\n");
/* Finally enter the standby mode */
HAL_PWR_EnterSTANDBYMode();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
Solved! Go to Solution.
2022-02-08 10:38 PM
The problem was the boot0 pin. Connecting the boot0 pin to gnd with a 1k resistor solved the problem. StandBy works.
2022-02-03 06:47 AM
Related/duplicate:
2022-02-03 07:10 AM
As first you need reconfig stlink to no debug in low power mode and turn off power to mcu .
After this flash code (no debug) and measure.Current must drop.
Second stage is wake up... read examples in firmware lib folder.
2022-02-08 10:38 PM
The problem was the boot0 pin. Connecting the boot0 pin to gnd with a 1k resistor solved the problem. StandBy works.