Skip to content

Commit 85711eb

Browse files
committed
STM32: Serial - do no clear RXNE flag
The RXNE flag is getting cleared when reading Data Register so it should not be cleared here. Especially in case of high data rate, another byte of data could have received during irq_handler call and clearing the flag would read and discard this data which would be lost for application.
1 parent 692d905 commit 85711eb

File tree

9 files changed

+11
-13
lines changed

9 files changed

+11
-13
lines changed

targets/TARGET_STM/TARGET_STM32F0/serial_device.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,7 @@ static void uart_irq(int id)
273273
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
274274
if (__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET) {
275275
irq_handler(serial_irq_ids[id], RxIrq);
276-
volatile uint32_t tmpval = huart->Instance->RDR; // Clear RXNE flag
277-
UNUSED(tmpval);
276+
/* Flag has been cleared when reading the content */
278277
}
279278
}
280279
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {

targets/TARGET_STM/TARGET_STM32F1/serial_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static void uart_irq(int id)
168168
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
169169
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE) != RESET) {
170170
irq_handler(serial_irq_ids[id], RxIrq);
171-
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_RXNE);
171+
/* Flag has been cleared when reading the content */
172172
}
173173
}
174174
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {

targets/TARGET_STM/TARGET_STM32F2/serial_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static void uart_irq(int id)
255255
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
256256
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE) != RESET) {
257257
irq_handler(serial_irq_ids[id], RxIrq);
258-
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_RXNE);
258+
/* Flag has been cleared when reading the content */
259259
}
260260
}
261261
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {

targets/TARGET_STM/TARGET_STM32F3/serial_device.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,8 @@ static void uart_irq(int id)
218218
}
219219
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
220220
if (__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET) {
221-
irq_handler(serial_irq_ids[id], RxIrq);
222-
volatile uint32_t tmpval = huart->Instance->RDR; // Clear RXNE flag
223-
UNUSED(tmpval);
221+
irq_handler(serial_irq_ids[id], RxIrq);
222+
/* Flag has been cleared when reading the content */
224223
}
225224
}
226225
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {

targets/TARGET_STM/TARGET_STM32F4/serial_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static void uart_irq(int id)
282282
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
283283
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE) != RESET) {
284284
irq_handler(serial_irq_ids[id], RxIrq);
285-
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_RXNE);
285+
/* Flag has been cleared when reading the content */
286286
}
287287
}
288288
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {

targets/TARGET_STM/TARGET_STM32F7/serial_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static void uart_irq(int id)
247247
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
248248
if (__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET) {
249249
irq_handler(serial_irq_ids[id], RxIrq);
250-
volatile uint32_t tmpval = huart->Instance->RDR; // Clear RXNE
250+
/* Flag has been cleared when reading the content */
251251
}
252252
}
253253
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {

targets/TARGET_STM/TARGET_STM32L0/serial_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void uart_irq(int id)
210210
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
211211
if (__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET) {
212212
irq_handler(serial_irq_ids[id], RxIrq);
213-
volatile uint32_t tmpval = huart->Instance->RDR; // Clear RXNE flag
213+
/* Flag has been cleared when reading the content */
214214
}
215215
}
216216
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {

targets/TARGET_STM/TARGET_STM32L1/serial_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static void uart_irq(int id)
199199
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
200200
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE) != RESET) {
201201
irq_handler(serial_irq_ids[id], RxIrq);
202-
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_RXNE);
202+
/* Flag has been cleared when reading the content */
203203
}
204204
}
205205
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {

targets/TARGET_STM/TARGET_STM32L4/serial_device.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ static void uart_irq(int id)
225225
}
226226
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
227227
if (__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET) {
228-
irq_handler(serial_irq_ids[id], RxIrq);
229-
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_RXNE);
228+
irq_handler(serial_irq_ids[id], RxIrq);
229+
/* Flag has been cleared when reading the content */
230230
}
231231
}
232232
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {

0 commit comments

Comments
 (0)