@@ -272,7 +272,16 @@ int serial_getc(serial_t *obj)
272
272
UART_HandleTypeDef * huart = & uart_handlers [obj_s -> index ];
273
273
274
274
while (!serial_readable (obj ));
275
- return (int )(huart -> Instance -> DR & 0x1FF );
275
+ if (obj_s -> parity == UART_PARITY_NONE ) {
276
+ return (int )(huart -> Instance -> DR & 0x1FF );
277
+ } else {
278
+ // When receiving with the parity enabled, the value read in the MSB bit is the received parity bit
279
+ if (obj_s -> databits == UART_WORDLENGTH_8B ) {
280
+ return (int )(huart -> Instance -> DR & 0x07F ); // 7 data bits + 1 parity bit
281
+ } else {
282
+ return (int )(huart -> Instance -> DR & 0x0FF ); // 8 data bits + 1 parity bit
283
+ }
284
+ }
276
285
}
277
286
278
287
void serial_putc (serial_t * obj , int c )
@@ -743,7 +752,7 @@ static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, con
743
752
}
744
753
if (type == FlowControlRTS ) {
745
754
// Enable RTS
746
- MBED_ASSERT (pinmap -> rx_flow_pin != ( UARTName ) NC );
755
+ MBED_ASSERT (pinmap -> rx_flow_pin != NC );
747
756
obj_s -> hw_flow_ctl = UART_HWCONTROL_RTS ;
748
757
obj_s -> pin_rts = pinmap -> rx_flow_pin ;
749
758
// Enable the pin for RTS function
@@ -752,7 +761,7 @@ static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, con
752
761
}
753
762
if (type == FlowControlCTS ) {
754
763
// Enable CTS
755
- MBED_ASSERT (pinmap -> tx_flow_pin != ( UARTName ) NC );
764
+ MBED_ASSERT (pinmap -> tx_flow_pin != NC );
756
765
obj_s -> hw_flow_ctl = UART_HWCONTROL_CTS ;
757
766
obj_s -> pin_cts = pinmap -> tx_flow_pin ;
758
767
// Enable the pin for CTS function
@@ -761,8 +770,8 @@ static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, con
761
770
}
762
771
if (type == FlowControlRTSCTS ) {
763
772
// Enable CTS & RTS
764
- MBED_ASSERT (pinmap -> rx_flow_pin != ( UARTName ) NC );
765
- MBED_ASSERT (pinmap -> tx_flow_pin != ( UARTName ) NC );
773
+ MBED_ASSERT (pinmap -> rx_flow_pin != NC );
774
+ MBED_ASSERT (pinmap -> tx_flow_pin != NC );
766
775
obj_s -> hw_flow_ctl = UART_HWCONTROL_RTS_CTS ;
767
776
obj_s -> pin_rts = pinmap -> rx_flow_pin ;;
768
777
obj_s -> pin_cts = pinmap -> tx_flow_pin ;;
0 commit comments