STM32L4R5 UART interrupt mode not working with UART Handler blocking
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
}