STM32: serial: clear Overrun flag if it is set when checking if readable

Note that this could have side effects on the application as it would
not be aware that data has been missed. This may be later solved by
adding an error management parameter to the Serial API in mbed.

The advantage is that the serial link can work again.
pull/4502/head
Laurent MEUNIER 2017-06-08 16:51:33 +02:00
parent 072a227bc9
commit c5c33f1d0f
9 changed files with 54 additions and 9 deletions

View File

@ -472,7 +472,12 @@ int serial_readable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
/* To avoid a target blocking case, let's check for
* possible OVERRUN error and discard it
*/
if(__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE)) {
__HAL_UART_CLEAR_OREFLAG(huart);
}
// Check if data is received
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) ? 1 : 0;
}

View File

@ -289,7 +289,12 @@ int serial_readable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
/* To avoid a target blocking case, let's check for
* possible OVERRUN error and discard it
*/
if(__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE)) {
__HAL_UART_CLEAR_OREFLAG(huart);
}
// Check if data is received
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) ? 1 : 0;
}

View File

@ -438,7 +438,12 @@ int serial_readable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
/* To avoid a target blocking case, let's check for
* possible OVERRUN error and discard it
*/
if(__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE)) {
__HAL_UART_CLEAR_OREFLAG(huart);
}
// Check if data is received
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) ? 1 : 0;
}

View File

@ -373,7 +373,12 @@ int serial_readable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
/* To avoid a target blocking case, let's check for
* possible OVERRUN error and discard it
*/
if(__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE)) {
__HAL_UART_CLEAR_OREFLAG(huart);
}
// Check if data is received
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) ? 1 : 0;
}

View File

@ -435,7 +435,12 @@ int serial_readable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
/* To avoid a target blocking case, let's check for
* possible OVERRUN error and discard it
*/
if(__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE)) {
__HAL_UART_CLEAR_OREFLAG(huart);
}
// Check if data is received
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) ? 1 : 0;
}

View File

@ -426,7 +426,12 @@ int serial_readable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
/* To avoid a target blocking case, let's check for
* possible OVERRUN error and discard it
*/
if(__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE)) {
__HAL_UART_CLEAR_OREFLAG(huart);
}
// Check if data is received
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) ? 1 : 0;
}

View File

@ -355,7 +355,12 @@ int serial_readable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
/* To avoid a target blocking case, let's check for
* possible OVERRUN error and discard it
*/
if(__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE)) {
__HAL_UART_CLEAR_OREFLAG(huart);
}
// Check if data is received
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) ? 1 : 0;
}

View File

@ -345,7 +345,12 @@ int serial_readable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
/* To avoid a target blocking case, let's check for
* possible OVERRUN error and discard it
*/
if(__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE)) {
__HAL_UART_CLEAR_OREFLAG(huart);
}
// Check if data is received
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) ? 1 : 0;
}

View File

@ -391,7 +391,12 @@ int serial_readable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
/* To avoid a target blocking case, let's check for
* possible OVERRUN error and discard it
*/
if(__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE)) {
__HAL_UART_CLEAR_OREFLAG(huart);
}
// Check if data is received
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) ? 1 : 0;
}