Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
STM32: Put some serial code in common between families
  • Loading branch information
LMESTM committed Jun 9, 2017
commit f77ecf4e1200b13be3abf461a153fad55c762ff4
37 changes: 2 additions & 35 deletions targets/TARGET_STM/TARGET_STM32F0/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,54 +468,21 @@ void serial_putc(serial_t *obj, int c)
huart->Instance->TDR = (uint32_t)(c & (uint16_t)0xFF);
}

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;
}

int serial_writable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

// Check if data is transmitted
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) ? 1 : 0;
}

void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

huart->TxXferCount = 0;
huart->RxXferCount = 0;
}

void serial_pinout_tx(PinName tx)
{
pinmap_pinout(tx, PinMap_UART_TX);
}

void serial_break_set(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

//HAL_LIN_SendBreak(huart);
}

void serial_break_clear(serial_t *obj)
{
(void)obj;
//HAL_LIN_SendBreak(huart);
Copy link
Contributor

@0xc0170 0xc0170 Jun 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this dead cone here? Please remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good question indeed ;-)
The diff somehow displays even though I haven't changed this line at all - it was there already before and I decided to leave it for now as this is not directly related to this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, shall be removed anyway. Can you ? Otherwise will be left in here .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather activate it than remove it ... but that would require some more testing which I could not do yet. Do you know of any test that is checking serial break ?

}

#if DEVICE_SERIAL_ASYNCH
Expand Down
37 changes: 2 additions & 35 deletions targets/TARGET_STM/TARGET_STM32F1/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,54 +285,21 @@ void serial_putc(serial_t *obj, int c)
}
}

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;
}

int serial_writable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

// Check if data is transmitted
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) ? 1 : 0;
}

void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

huart->TxXferCount = 0;
huart->RxXferCount = 0;
}

void serial_pinout_tx(PinName tx)
{
pinmap_pinout(tx, PinMap_UART_TX);
}

void serial_break_set(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

HAL_LIN_SendBreak(huart);
}

void serial_break_clear(serial_t *obj)
{
(void)obj;
HAL_LIN_SendBreak(huart);
}

#if DEVICE_SERIAL_ASYNCH
Expand Down
37 changes: 2 additions & 35 deletions targets/TARGET_STM/TARGET_STM32F2/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,54 +434,21 @@ void serial_putc(serial_t *obj, int c)
huart->Instance->DR = (uint32_t)(c & (uint16_t)0x1FF);
}

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;
}

int serial_writable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

// Check if data is transmitted
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) ? 1 : 0;
}

void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

huart->TxXferCount = 0;
huart->RxXferCount = 0;
}

void serial_pinout_tx(PinName tx)
{
pinmap_pinout(tx, PinMap_UART_TX);
}

void serial_break_set(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

HAL_LIN_SendBreak(huart);
}

void serial_break_clear(serial_t *obj)
{
(void)obj;
HAL_LIN_SendBreak(huart);
}

#if DEVICE_SERIAL_ASYNCH
Expand Down
35 changes: 1 addition & 34 deletions targets/TARGET_STM/TARGET_STM32F3/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,29 +369,6 @@ void serial_putc(serial_t *obj, int c)
}
}

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;
}

int serial_writable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

// Check if data is transmitted
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) ? 1 : 0;
}

void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
Expand All @@ -401,22 +378,12 @@ void serial_clear(serial_t *obj)
__HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST);
}

void serial_pinout_tx(PinName tx)
{
pinmap_pinout(tx, PinMap_UART_TX);
}

void serial_break_set(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

HAL_LIN_SendBreak(huart);
}

void serial_break_clear(serial_t *obj)
{
(void)obj;
HAL_LIN_SendBreak(huart);
}

#if DEVICE_SERIAL_ASYNCH
Expand Down
33 changes: 0 additions & 33 deletions targets/TARGET_STM/TARGET_STM32F4/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,29 +431,6 @@ void serial_putc(serial_t *obj, int c)
huart->Instance->DR = (uint32_t)(c & 0x1FF);
}

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;
}

int serial_writable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

// Check if data is transmitted
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) ? 1 : 0;
}

void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
Expand All @@ -463,11 +440,6 @@ void serial_clear(serial_t *obj)
huart->RxXferCount = 0;
}

void serial_pinout_tx(PinName tx)
{
pinmap_pinout(tx, PinMap_UART_TX);
}

void serial_break_set(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
Expand All @@ -476,11 +448,6 @@ void serial_break_set(serial_t *obj)
HAL_LIN_SendBreak(huart);
}

void serial_break_clear(serial_t *obj)
{
(void)obj;
}

#if DEVICE_SERIAL_ASYNCH

/******************************************************************************
Expand Down
39 changes: 3 additions & 36 deletions targets/TARGET_STM/TARGET_STM32F7/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ int serial_getc(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_readable(obj));
return (int)(huart->Instance->RDR & 0x1FF);
}
Expand All @@ -417,34 +417,11 @@ void serial_putc(serial_t *obj, int c)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_writable(obj));
huart->Instance->TDR = (uint32_t)(c & 0x1FF);
}

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;
}

int serial_writable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

// Check if data is transmitted
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) ? 1 : 0;
}

void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
Expand All @@ -454,22 +431,12 @@ void serial_clear(serial_t *obj)
__HAL_UART_CLEAR_IT(huart, UART_FLAG_RXNE);
}

void serial_pinout_tx(PinName tx)
{
pinmap_pinout(tx, PinMap_UART_TX);
}

void serial_break_set(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

HAL_LIN_SendBreak(huart);
}

void serial_break_clear(serial_t *obj)
{
(void)obj;
HAL_LIN_SendBreak(huart);
}

#if DEVICE_SERIAL_ASYNCH
Expand Down
Loading