Skip to content

STM32L4: Fix the UART RX & TX data reg bitmasks #12341

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

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 14 additions & 2 deletions targets/TARGET_STM/TARGET_STM32F0/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,15 @@ int serial_getc(serial_t *obj)
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

/* Computation of UART mask to apply to RDR register */
UART_MASK_COMPUTATION(huart);
uint16_t uhMask = huart->Mask;

while (!serial_readable(obj));
return (int)(huart->Instance->RDR & (uint16_t)0xFF);
/* When receiving with the parity enabled, the value read in the MSB bit
* is the received parity bit.
*/
return (int)(huart->Instance->RDR & uhMask);
}

void serial_putc(serial_t *obj, int c)
Expand All @@ -273,7 +280,12 @@ void serial_putc(serial_t *obj, int c)
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_writable(obj));
huart->Instance->TDR = (uint32_t)(c & (uint16_t)0xFF);
/* When transmitting with the parity enabled (PCE bit set to 1 in the
* USART_CR1 register), the value written in the MSB (bit 7 or bit 8
* depending on the data length) has no effect because it is replaced
* by the parity.
*/
huart->Instance->TDR = (uint16_t)(c & 0x1FFU);
}

void serial_clear(serial_t *obj)
Expand Down
24 changes: 14 additions & 10 deletions targets/TARGET_STM/TARGET_STM32F3/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,15 @@ int serial_getc(serial_t *obj)
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

/* Computation of UART mask to apply to RDR register */
UART_MASK_COMPUTATION(huart);
uint16_t uhMask = huart->Mask;

while (!serial_readable(obj));
if (obj_s->databits == UART_WORDLENGTH_8B) {
return (int)(huart->Instance->RDR & (uint8_t)0xFF);
} else {
return (int)(huart->Instance->RDR & (uint16_t)0x1FF);
}
/* When receiving with the parity enabled, the value read in the MSB bit
* is the received parity bit.
*/
return (int)(huart->Instance->RDR & uhMask);
}

void serial_putc(serial_t *obj, int c)
Expand All @@ -216,11 +219,12 @@ void serial_putc(serial_t *obj, int c)
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_writable(obj));
if (obj_s->databits == UART_WORDLENGTH_8B) {
huart->Instance->TDR = (uint8_t)(c & (uint8_t)0xFF);
} else {
huart->Instance->TDR = (uint16_t)(c & (uint16_t)0x1FF);
}
/* When transmitting with the parity enabled (PCE bit set to 1 in the
* USART_CR1 register), the value written in the MSB (bit 7 or bit 8
* depending on the data length) has no effect because it is replaced
* by the parity.
*/
huart->Instance->TDR = (uint16_t)(c & 0x1FFU);
}

void serial_clear(serial_t *obj)
Expand Down
16 changes: 14 additions & 2 deletions targets/TARGET_STM/TARGET_STM32F7/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,15 @@ int serial_getc(serial_t *obj)
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

/* Computation of UART mask to apply to RDR register */
UART_MASK_COMPUTATION(huart);
uint16_t uhMask = huart->Mask;

while (!serial_readable(obj));
return (int)(huart->Instance->RDR & 0x1FF);
/* When receiving with the parity enabled, the value read in the MSB bit
* is the received parity bit.
*/
return (int)(huart->Instance->RDR & uhMask);
}

void serial_putc(serial_t *obj, int c)
Expand All @@ -244,7 +251,12 @@ void serial_putc(serial_t *obj, int c)
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_writable(obj));
huart->Instance->TDR = (uint32_t)(c & 0x1FF);
/* When transmitting with the parity enabled (PCE bit set to 1 in the
* USART_CR1 register), the value written in the MSB (bit 7 or bit 8
* depending on the data length) has no effect because it is replaced
* by the parity.
*/
huart->Instance->TDR = (uint16_t)(c & 0x1FFU);
}

void serial_clear(serial_t *obj)
Expand Down
16 changes: 14 additions & 2 deletions targets/TARGET_STM/TARGET_STM32G0/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,15 @@ int serial_getc(serial_t *obj)
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

/* Computation of UART mask to apply to RDR register */
UART_MASK_COMPUTATION(huart);
uint16_t uhMask = huart->Mask;

while (!serial_readable(obj));
return (int)(huart->Instance->RDR & (uint16_t)0xFF);
/* When receiving with the parity enabled, the value read in the MSB bit
* is the received parity bit.
*/
return (int)(huart->Instance->RDR & uhMask);
}

void serial_putc(serial_t *obj, int c)
Expand All @@ -200,7 +207,12 @@ void serial_putc(serial_t *obj, int c)
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_writable(obj));
huart->Instance->TDR = (uint32_t)(c & (uint16_t)0xFF);
/* When transmitting with the parity enabled (PCE bit set to 1 in the
* USART_CR1 register), the value written in the MSB (bit 7 or bit 8
* depending on the data length) has no effect because it is replaced
* by the parity.
*/
huart->Instance->TDR = (uint16_t)(c & 0x1FFU);
}

void serial_clear(serial_t *obj)
Expand Down
16 changes: 14 additions & 2 deletions targets/TARGET_STM/TARGET_STM32H7/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,15 @@ int serial_getc(serial_t *obj)
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

/* Computation of UART mask to apply to RDR register */
UART_MASK_COMPUTATION(huart);
uint16_t uhMask = huart->Mask;

while (!serial_readable(obj));
return (int)(huart->Instance->RDR & 0x1FF);
/* When receiving with the parity enabled, the value read in the MSB bit
* is the received parity bit.
*/
return (int)(huart->Instance->RDR & uhMask);
}

void serial_putc(serial_t *obj, int c)
Expand All @@ -257,7 +264,12 @@ void serial_putc(serial_t *obj, int c)
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_writable(obj));
huart->Instance->TDR = (uint32_t)(c & 0x1FF);
/* When transmitting with the parity enabled (PCE bit set to 1 in the
* USART_CR1 register), the value written in the MSB (bit 7 or bit 8
* depending on the data length) has no effect because it is replaced
* by the parity.
*/
huart->Instance->TDR = (uint16_t)(c & 0x1FFU);
}

void serial_clear(serial_t *obj)
Expand Down
16 changes: 14 additions & 2 deletions targets/TARGET_STM/TARGET_STM32L0/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,15 @@ int serial_getc(serial_t *obj)
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

/* Computation of UART mask to apply to RDR register */
UART_MASK_COMPUTATION(huart);
uint16_t uhMask = huart->Mask;

while (!serial_readable(obj));
return (int)(huart->Instance->RDR & (uint16_t)0xFF);
/* When receiving with the parity enabled, the value read in the MSB bit
* is the received parity bit.
*/
return (int)(huart->Instance->RDR & uhMask);
}

void serial_putc(serial_t *obj, int c)
Expand All @@ -214,7 +221,12 @@ void serial_putc(serial_t *obj, int c)
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_writable(obj));
huart->Instance->TDR = (uint32_t)(c & (uint16_t)0xFF);
/* When transmitting with the parity enabled (PCE bit set to 1 in the
* USART_CR1 register), the value written in the MSB (bit 7 or bit 8
* depending on the data length) has no effect because it is replaced
* by the parity.
*/
huart->Instance->TDR = (uint16_t)(c & 0x1FFU);
}

void serial_clear(serial_t *obj)
Expand Down
24 changes: 14 additions & 10 deletions targets/TARGET_STM/TARGET_STM32L4/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,15 @@ int serial_getc(serial_t *obj)
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

/* Computation of UART mask to apply to RDR register */
UART_MASK_COMPUTATION(huart);
uint16_t uhMask = huart->Mask;

while (!serial_readable(obj));
if (obj_s->databits == UART_WORDLENGTH_8B) {
return (int)(huart->Instance->RDR & (uint8_t)0xFF);
} else {
return (int)(huart->Instance->RDR & (uint16_t)0x1FF);
}
/* When receiving with the parity enabled, the value read in the MSB bit
* is the received parity bit.
*/
return (int)(huart->Instance->RDR & uhMask);
}

void serial_putc(serial_t *obj, int c)
Expand All @@ -229,11 +232,12 @@ void serial_putc(serial_t *obj, int c)
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_writable(obj));
if (obj_s->databits == UART_WORDLENGTH_8B) {
huart->Instance->TDR = (uint8_t)(c & (uint8_t)0xFF);
} else {
huart->Instance->TDR = (uint16_t)(c & (uint16_t)0x1FF);
}
/* When transmitting with the parity enabled (PCE bit set to 1 in the
* USART_CR1 register), the value written in the MSB (bit 7 or bit 8
* depending on the data length) has no effect because it is replaced
* by the parity.
*/
huart->Instance->TDR = (uint16_t)(c & 0x1FFU);
}

void serial_clear(serial_t *obj)
Expand Down
24 changes: 14 additions & 10 deletions targets/TARGET_STM/TARGET_STM32WB/serial_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,15 @@ int serial_getc(serial_t *obj)
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

/* Computation of UART mask to apply to RDR register */
UART_MASK_COMPUTATION(huart);
uint16_t uhMask = huart->Mask;

while (!serial_readable(obj));
if (obj_s->databits == UART_WORDLENGTH_8B) {
return (int)(huart->Instance->RDR & (uint8_t)0xFF);
} else {
return (int)(huart->Instance->RDR & (uint16_t)0x1FF);
}
/* When receiving with the parity enabled, the value read in the MSB bit
* is the received parity bit.
*/
return (int)(huart->Instance->RDR & uhMask);
}

void serial_putc(serial_t *obj, int c)
Expand All @@ -174,11 +177,12 @@ void serial_putc(serial_t *obj, int c)
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];

while (!serial_writable(obj));
if (obj_s->databits == UART_WORDLENGTH_8B) {
huart->Instance->TDR = (uint8_t)(c & (uint8_t)0xFF);
} else {
huart->Instance->TDR = (uint16_t)(c & (uint16_t)0x1FF);
}
/* When transmitting with the parity enabled (PCE bit set to 1 in the
* USART_CR1 register), the value written in the MSB (bit 7 or bit 8
* depending on the data length) has no effect because it is replaced
* by the parity.
*/
huart->Instance->TDR = (uint16_t)(c & 0x1FFU);
}

void serial_clear(serial_t *obj)
Expand Down