@@ -272,7 +272,16 @@ int serial_getc(serial_t *obj)
272272 UART_HandleTypeDef * huart = & uart_handlers [obj_s -> index ];
273273
274274 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+ }
276285}
277286
278287void serial_putc (serial_t * obj , int c )
@@ -743,7 +752,7 @@ static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, con
743752 }
744753 if (type == FlowControlRTS ) {
745754 // Enable RTS
746- MBED_ASSERT (pinmap -> rx_flow_pin != ( UARTName ) NC );
755+ MBED_ASSERT (pinmap -> rx_flow_pin != NC );
747756 obj_s -> hw_flow_ctl = UART_HWCONTROL_RTS ;
748757 obj_s -> pin_rts = pinmap -> rx_flow_pin ;
749758 // Enable the pin for RTS function
@@ -752,7 +761,7 @@ static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, con
752761 }
753762 if (type == FlowControlCTS ) {
754763 // Enable CTS
755- MBED_ASSERT (pinmap -> tx_flow_pin != ( UARTName ) NC );
764+ MBED_ASSERT (pinmap -> tx_flow_pin != NC );
756765 obj_s -> hw_flow_ctl = UART_HWCONTROL_CTS ;
757766 obj_s -> pin_cts = pinmap -> tx_flow_pin ;
758767 // Enable the pin for CTS function
@@ -761,8 +770,8 @@ static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, con
761770 }
762771 if (type == FlowControlRTSCTS ) {
763772 // 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 );
766775 obj_s -> hw_flow_ctl = UART_HWCONTROL_RTS_CTS ;
767776 obj_s -> pin_rts = pinmap -> rx_flow_pin ;;
768777 obj_s -> pin_cts = pinmap -> tx_flow_pin ;;
0 commit comments