Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep uart RX interrupt enabled forever using HAL library on a STM32F1

Tags:

I see HAL provides the following function for receiving serial data with interrupts: HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
which basically setups rx interrupts and returns.
HAL_UART_RxCpltCallback() will be called once the amount of bytes received reaches Size.
HAL disables rx interrupts just before executing this callback

Problem:
The amount of incoming bytes will be variable (from 1 to ~100) and I need to put them into a ring buffer.
So I set Size to 1 and call HAL_UART_Receive_IT() again inside the callback to re-enable interrupts, and it works well if the board gets sent 1 or 2 bytes every now and then, but bytes are missed beyond that

My guess is they are missed because they arrive between interrupt disabling - enabling

Is there a way to keep interrupts running forever without overwriting HAL Cube generated code?
If not, what would be a clean way of overwriting the involved functions?
Is there something I'm missing that would avoid the need to find this solution?

like image 947
Gerard Vuyk Avatar asked Apr 15 '16 23:04

Gerard Vuyk


1 Answers

Try this

__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
like image 117
Besnik B Avatar answered Sep 28 '22 01:09

Besnik B