Skip to main content
YMAIL
Associate III
August 16, 2019
Question

After wake up from stop mode with a RTC Alarm the device stop working when I use the uart link. Do you know why ?

  • August 16, 2019
  • 0 replies
  • 529 views

Hi !

I got a discovery board B-L072cz-LRWAN1. It go to stop mode and when the Alarm trig it wake up and run the program correctly. But when I use the uart for print or anything else, the program stop.

Here is my code. It's based on the cube-LRWAN1 example :

int main()
{
 HAL_Init( );
 
 SystemClock_Config( );
 
 DBG_Init( );
 
 HW_Init( );
 
	while(1)
 {
 PRINTF("Sleep\r");
	 SX1276SetSleep();
	 HAL_Delay(200);
	 stm32l_lowPowerSetup();
	 stm32l_lowPowerResume();
	 PRINTF("Wake\r");
 }
}
 
void stm32l_lowPowerSetup(void)
{
__HAL_RCC_PWR_CLK_ENABLE(); // Enable Power Control clock
HAL_PWREx_EnableUltraLowPower(); // Ultra low power mode
HAL_PWREx_EnableFastWakeUp(); // Fast wake-up for ultra low power mode
 
// Disable Unused Gpios
_stm32l_disableGpios(); // Disable GPIOs based on configuration
 
HW_RTC_SetAlarm(10000);
// Switch to STOPMode
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
}
 
void stm32l_lowPowerResume(void)
{
 
 HAL_Init( );
 
 SystemClock_Config( );
 
 HAL_RTC_MspInit(&hrtc);
 
 DBG_Init( );
 
 HW_Init( );
 HAL_UART_MspInit(&huart2);
}
 
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
 static DMA_HandleTypeDef hdma_tx;
 
 
 /*##-1- Enable peripherals and GPIO Clocks #################################*/
 /* Enable GPIO TX/RX clock */
 USARTx_TX_GPIO_CLK_ENABLE();
 USARTx_RX_GPIO_CLK_ENABLE();
 
 /* Enable USARTx clock */
 USARTx_CLK_ENABLE();
 
 /* Enable DMA clock */
 DMAx_CLK_ENABLE();
 
 /*##-2- Configure peripheral GPIO ##########################################*/ 
 /* UART pin configuration */
 vcom_IoInit();
 
 /*##-3- Configure the DMA ##################################################*/
 /* Configure the DMA handler for Transmission process */
 hdma_tx.Instance = USARTx_TX_DMA_CHANNEL;
 hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
 hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE;
 hdma_tx.Init.MemInc = DMA_MINC_ENABLE;
 hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
 hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
 hdma_tx.Init.Mode = DMA_NORMAL;
 hdma_tx.Init.Priority = DMA_PRIORITY_LOW;
#ifndef STM32L152xE
 hdma_tx.Init.Request = USARTx_TX_DMA_REQUEST;
#endif
 HAL_DMA_Init(&hdma_tx);
 
 /* Associate the initialized DMA handle to the UART handle */
 __HAL_LINKDMA(huart, hdmatx, hdma_tx);
 
 /*##-4- Configure the NVIC for DMA #########################################*/
 /* NVIC configuration for DMA transfer complete interrupt (USART1_TX) */
 HAL_NVIC_SetPriority(USARTx_DMA_TX_IRQn, USARTx_Priority, 1);
 HAL_NVIC_EnableIRQ(USARTx_DMA_TX_IRQn);
 
 /* NVIC for USART, to catch the TX complete */
 HAL_NVIC_SetPriority(USARTx_IRQn, USARTx_DMA_Priority, 1);
 HAL_NVIC_EnableIRQ(USARTx_IRQn);
}

This topic has been closed for replies.