cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 wake up from stop mode with UART

MKosa.2
Associate

I am using STM32F407VG MCU (STM32F4 Discovery board) and I want my MCU to wake-up from STOP mode when it receives a message from UART. I had to adjust some things manually because the STM32CubeMX is unable to set UART Rx pin as an GPIO interrupt pin when is configured for UART functionality. I am using DMA with UART. The function for reading UART is HAL_UART_Receive_DMA().

The wake-up from STOP mode when UART receives the msg works, but the problem is that a lot of bytes that are read are corrupted. I thought that only the first byte should be corrupted but not also the others. If I send another msg it is received fully and everything is OK, the problem is only with the first msg that is send and is used for wake-up the MCU. Any idea what the problem could be?

I tested it in a way that whatever I send via UART to the MCU, it sends it back after wake-up. Here is the result (green - what I sent, white - what MCU received):

0693W0000059MTEQA2.png 

It seems that somehow the data that is received by the MCU it depends where the space character is situated (except when space character is first).

Here is some parts of my code:

void MX_USART3_UART_Init(void)
{
 
  huart3.Instance = USART3;
  huart3.Init.BaudRate = 9600;
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
  huart3.Init.StopBits = UART_STOPBITS_1;
  huart3.Init.Parity = UART_PARITY_NONE;
  huart3.Init.Mode = UART_MODE_TX_RX;
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart3) != HAL_OK)
  {
    Error_Handler();
  }
 
}
 
//-----------------------------------
 
// Setting the UART rx pin to trigger an interrupt on falling edge
EXTI_ConfigTypeDef hExtiConfig;
hExtiConfig.Line = EXTI_LINE_9; // PD9
hExtiConfig.Mode = EXTI_MODE_INTERRUPT;
hExtiConfig.Trigger = EXTI_TRIGGER_FALLING;
hExtiConfig.GPIOSel = EXTI_GPIOD;   // PD9
HAL_EXTI_SetConfigLine(&g_hExtiHandle, &hExtiConfig);
HAL_EXTI_RegisterCallback(&g_hExtiHandle, HAL_EXTI_COMMON_CB_ID, my_func);
 
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 4);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
 
 
// Enter STOP mode
HAL_PWREx_EnableFlashPowerDown();
HAL_SuspendTick();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
 
//-----------------------------------
 
void EXTI9_5_IRQHandler(void)
{
  HAL_ResumeTick();
  SystemClock_Config();
  MX_USART3_UART_Init();
 
  HAL_PWREx_DisableFlashPowerDown();
 
  HAL_EXTI_IRQHandler(&g_hExtiHandle);
}
 
//-----------------------------------
 
// Callback function after the wake-up
void my_func(void)
{
    HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_SET);
    HAL_EXTI_ClearPending(&g_hExtiHandle, EXTI_TRIGGER_FALLING);
    HAL_EXTI_ClearConfigLine(&g_hExtiHandle);   
}

1 REPLY 1
TDK
Guru

If the MCU misses the first start bit, it's not going to know where the next byte starts, so it may mess that one up as well. Going to depend on the actual bytes sent and the delay between them, if any. Pretty sure UART is not active during stop mode.

If you feel a post has answered your question, please click "Accept as Solution".