cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4R5 UART interrupt mode not working with UART Handler blocking

ACord.1
Associate II

Hi ! I’m testing UART interrupt mode to transfer data with STM32L4R5 (IDE : STM32CubeIDE).

I’m using HAL_UART_Transmit_IT and I have a problem with UART Handler. No data is send and the instructions in while loop in main function are not executed because the UART Handler is triggered without stopping.

In debug mode I see that the isrflags and errorflags varaibles in HAL_UART_IRQHandler are equal to 0. That’s why no data are sent I think and the callback function is never called.

I don’t understand my problem. Could anyone please help me ?

Here is my code :

// main.c file //

/* Private variables ---------------------------------------------------------*/

UART_HandleTypeDef hlpuart1;

UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */

uint8_t tx_buf[] = "Hello\n\r";

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_LPUART1_UART_Init(void);

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)

{

      //Never reached unfortunately

}

int main(void)

{

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* Configure the system clock */

 SystemClock_Config();

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_LPUART1_UART_Init();

 HAL_UART_Transmit_IT(&hlpuart1, tx_buf, sizeof(tx_buf)); // It returns HAL_OK

 while (1)

 {

     HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_7); // It blocks here

     HAL_Delay(1000);

 }

}

static void MX_LPUART1_UART_Init(void)

{

 hlpuart1.Instance = LPUART1;

 hlpuart1.Init.BaudRate = 9600;

 hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;

 hlpuart1.Init.StopBits = UART_STOPBITS_1;

 hlpuart1.Init.Parity = UART_PARITY_NONE;

 hlpuart1.Init.Mode = UART_MODE_TX_RX;

 hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;

 hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 hlpuart1.FifoMode = UART_FIFOMODE_DISABLE;

 if (HAL_UART_Init(&hlpuart1) != HAL_OK)

 {

   Error_Handler();

 }

 if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)

 {

   Error_Handler();

 }

 if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)

 {

   Error_Handler();

 }

 if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)

 {

   Error_Handler();

 }

}

// stm32l4xx_it.c file

void LPUART1_IRQHandler(void)

{

 HAL_UART_IRQHandler(&huart1); // There isrflags = 0 and errorflags = 0

}

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

It looks like you're using the UART handle in the LPUART handler. No doubt you want this instead:

void LPUART1_IRQHandler(void)
{
  HAL_UART_IRQHandler(&hlpuart1);
}

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

View solution in original post

3 REPLIES 3
TDK
Guru

It looks like you're using the UART handle in the LPUART handler. No doubt you want this instead:

void LPUART1_IRQHandler(void)
{
  HAL_UART_IRQHandler(&hlpuart1);
}

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

Yes I'm stupid ! Thank you very much !!!

However it's weird because I've only activated the LPUART1 in the Cube but UART1 HandleTypeDef is also generated in the code. (That's why I thought it was the same peripheral)

We can find it also in LPUART1_UART_Init function whis is automatically generated by the Cube :

static void MX_LPUART1_UART_Init(void)

{

{

 hlpuart1.Instance = LPUART1;

//

......

//

 if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)

 {

   Error_Handler();

 }

 if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)

 {

   Error_Handler();

 }

}

In STM32L4R5 there are only LPUART1 (the one I use), USART1, USART2, USART3 and UART4, UART5.

No UART1, so where does he come from?

TDK
Guru

> No UART1, so where does he come from?

It appears to be a bug in CubeMX. I can reproduce both of the issues you point out in CubeMX v5.6.1.

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