cancel
Showing results for 
Search instead for 
Did you mean: 

LPUART is stuck after HAL_UART_Receive. L081KZT6

HRaup.1
Associate II

Hello,

I have some Issues with LPUART1 on a STM32L081KZT. What I want to do is:

- Receive Data of variable length via LPUART1 using the HAL_UART_Receive function.

- Reading bytewise in a loop

- Using an External Interrupt to start the receive.

My Code looks like this:

void Receive_UART()
{
 
	while(rs232_inbuf[rs232_inbuf_index-1] != LF){
		HAL_UART_Receive(&hlpuart1, &rs232_inbuf[rs232_inbuf_index], 1, 100);
		rs232_inbuf_index++;
		
		if ((rs232_inbuf_index > 120))
		{
			rs232_inbuf_index = 0;
			return;
		}
	}
	rs232_tellen = --rs232_inbuf_index;
	rs232_inbuf_index = 0;
	HAL_UART_Transmit(&hlpuart1, (uint8_t*)&rs232_inbuf, rs232_tellen + 1, 100);
	reset_inbuf();
}
 
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	if(GPIO_Pin == 2){
		Receive_UART();
	return;
	 }
}

I can successfully read like this, but after the first HAL_UART_Receive, the code stops working and only interrupts can be used. When I use the Debugger to see what happens, I notice, that the code is stuck in stm32l0xx_hal_uart.c. It seems to me that it wait for a Flag, that it never receives from the UART. The function it is stuck in is HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout).

It works fine with HAL_UART_Receive_IT, but I cant use that for reasons.

Please help.

2 REPLIES 2
TDK
Guru

> void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

Don't call blocking functions from within an interrupt. Set a volatile flag and call them from the main loop instead.

Or ensure that systick interrupt has a higher (numerically lower) priority than EXTI interrupt.

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

Hi, thanks for your answer!

This kind of fixed my problem. When I tried to use the UART as described above, I hoped it would fix my actual problem. I opened another Question about this issue:

https://community.st.com/s/question/0D53W00001QgmDOSAZ/lpuart-acts-strange-with-stopmode-stm32l081kzt6