STM32LORA discovery- PingPong Standby wake up by RTC timer
Hi Support Team
I am using STM32LORA discovery- PingPong , in slave role after sending data to Masetr , slave has to go to STANDBY mode ,and wake up via RTC timer event..
void SystemClock_Config( void )
{/*----------------------------------------FROM MASTER-AT---------------------------------------------------*/
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit; __PWR_CLK_ENABLE(); /**Configure the main internal regulator output voltage */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); // VP JUL 10/**Initializes the CPU, AHB and APB busses clocks
*//* Enable HSE Oscillator and Activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_MSI; RCC_OscInitStruct.HSEState = RCC_HSE_OFF; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.LSIState = RCC_LSI_ON; // VP JUL 10 RCC_OscInitStruct.MSIState = RCC_MSI_ON; // VP JUL 10 RCC_OscInitStruct.MSICalibrationValue = 0; // VP JUL 10 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5; // VP JUL 10 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE ; // VP JUL 11 RCC_PLL_ON; //RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; VP JUL 11 //RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_6; VP JUL 11 //RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3; VP JUL 11if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{ Error_Handler(); }/***********************VP JUL 10 ******************************/ /* Set Voltage scale1 as MCU will run at 32MHz */ // __HAL_RCC_PWR_CLK_ENABLE(); /* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */ while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET) {};/*****************************************************/ /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI ; // RCC_SYSCLKSOURCE_PLLCLK; VP JUL 11 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { Error_Handler(); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_RTC; // VP JUL 10 PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_HSI; PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI; PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI; // VP JUL 10 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); /***********************VP JUL 10***************************************/ /**Configure the Systick interrupt time */ HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);/**Configure the Systick
*/ HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);/**************************************************************/ __SYSCFG_CLK_ENABLE(); // VP JUL 12}static void SystemPower_Config(void)
{ /* Enable Power Control clock */ __HAL_RCC_PWR_CLK_ENABLE();HAL_PWREx_EnableUltraLowPower();
/* Enable the fast wake up from Ultra low power mode */
HAL_PWREx_EnableFastWakeUp();}void Enter_Stand_by_Mode(void){ /****************************************************************/ __HAL_RCC_PWR_CLK_ENABLE();HAL_DBGMCU_EnableDBGStandbyMode();
/* Check and handle if the system was resumed from StandBy mode */
if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) { /* Clear Standby flag */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); } /* Insert 5 seconds delay */ HAL_Delay(5000); /* The Following Wakeup sequence is highly recommended prior to each Standby mode entry mainly when using more than one wakeup source this is to not miss any wakeup event. - Disable all used wakeup sources, - Clear all related wakeup flags, - Re-enable all used wakeup sources, - Enter the Standby mode. */ /* Disable all used wakeup sources*/ HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle); /* Re-enable all used wakeup sources*/ /* ♯♯ Setting the Wake up time ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/ /* RTC Wakeup Interrupt Generation: Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSI)) Wakeup Time = Wakeup Time Base * WakeUpCounter = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSI)) * WakeUpCounter ==> WakeUpCounter = Wakeup Time / Wakeup Time Base To configure the wake up timer to 4s the WakeUpCounter is set to 0x1FFF: RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 Wakeup Time Base = 16 /(~39.000KHz) = ~0,410 ms Wakeup Time = ~4s = 0,410ms * WakeUpCounter ==> WakeUpCounter = ~4s/0,410ms = 9750 = 0x2616 */ HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, 0x2616, RTC_WAKEUPCLOCK_RTCCLK_DIV16); __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG (&RtcHandle, RTC_FLAG_WUTF); /* Clear all related wakeup flags */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); /* Enter the Standby mode */ HAL_PWR_EnterSTANDBYMode();}
But STANDBY and RTC wake up is not working , what am i missing ??
#stm32f072-discovery