cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f446 waking from UART in STOP mode

PToma.14
Associate II

I am putting board into STOP mode for saving power. From the manuals the board can be woken up from STOP by EXTI interrupt. Is it possible to waking it up by UART by configuring it as EXTI interrupt on Rx pin. If yes how can I achieve this?

2 REPLIES 2

As with any external interrupt - map the pin in the respective SYSCFG_EXTICRx register, then select the edge upon which to trigger, presumably falling thus in EXTI_FTSR, enable the given interrupt in EXTI_IMR and also in NVIC for the given interrupt vector. And don't forget to write the respective interrupt service routine.

JW

PToma.14
Associate II

I am doing it following manner. I want to wake up board from STOP mode on receiving data on UART.

void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
 
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(huart->Instance==UART4)
  {
  /* USER CODE BEGIN UART4_MspInit 0 */
 
  /* USER CODE END UART4_MspInit 0 */
    /* Peripheral clock enable */
    __HAL_RCC_UART4_CLK_ENABLE();
  
    __HAL_RCC_GPIOA_CLK_ENABLE();
    /**UART4 GPIO Configuration    
    PA0-WKUP     ------> UART4_TX
    PA1     ------> UART4_RX 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF8_UART4;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  /* USER CODE BEGIN UART4_MspInit 1 */
    EXTI_InitTypeDef EXTI_InitStruct;
    NVIC_InitTypeDef NVIC_InitStruct;
    /* Tell system that you will use PA1 for EXTI_Line1 */
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);
 
    /* PA1 is connected to EXTI_Line1 */
    EXTI_InitStruct.EXTI_Line = EXTI_Line1;
    EXTI_InitStruct.EXTI_LineCmd = ENABLE;
    EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
    EXTI_Init(&EXTI_InitStruct);
 
    NVIC_InitStruct.NVIC_IRQChannel = EXTI1_IRQn;
    NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00;
    NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x00;
    NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStruct);
  /* USER CODE END UART4_MspInit 1 */
  }
}
 
void EXTI1_IRQHandler(void) {
    if (EXTI_GetITStatus(EXTI_Line1) != RESET) {
        /* Clear interrupt flag */
        EXTI_ClearITPendingBit(EXTI_Line1);
    }
}
 
//Code for putting board to STOP mode
void lwpSleepMode()
{
      HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
}

But this code is not working board doesn't wake up on receiving data on UART from PC side.