@@ -49,6 +49,12 @@ UART_HandleTypeDef UartHandle;
49
49
int stdio_uart_inited = 0 ;
50
50
serial_t stdio_uart ;
51
51
52
+ #if DEVICE_SERIAL_ASYNCH
53
+ #define SERIAL_OBJ (X ) (obj->serial.X)
54
+ #else
55
+ #define SERIAL_OBJ (X ) (obj->X)
56
+ #endif
57
+
52
58
static void init_uart (serial_t * obj )
53
59
{
54
60
UartHandle .Instance = (USART_TypeDef * )(obj -> uart );
@@ -57,7 +63,11 @@ static void init_uart(serial_t *obj)
57
63
UartHandle .Init .WordLength = obj -> databits ;
58
64
UartHandle .Init .StopBits = obj -> stopbits ;
59
65
UartHandle .Init .Parity = obj -> parity ;
66
+ #if DEVICE_SERIAL_FC
67
+ UartHandle .Init .HwFlowCtl = SERIAL_OBJ (hw_flow_ctl );
68
+ #else
60
69
UartHandle .Init .HwFlowCtl = UART_HWCONTROL_NONE ;
70
+ #endif
61
71
UartHandle .Init .OverSampling = UART_OVERSAMPLING_16 ;
62
72
UartHandle .Init .OneBitSampling = UART_ONE_BIT_SAMPLE_ENABLE ;
63
73
@@ -231,6 +241,62 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
231
241
init_uart (obj );
232
242
}
233
243
244
+ #if DEVICE_SERIAL_FC
245
+ /** Set HW Control Flow
246
+ * @param obj The serial object
247
+ * @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS)
248
+ * @param rxflow Pin for the rxflow
249
+ * @param txflow Pin for the txflow
250
+ */
251
+ void serial_set_flow_control (serial_t * obj , FlowControl type , PinName rxflow , PinName txflow )
252
+ {
253
+
254
+ // Determine the UART to use (UART_1, UART_2, ...)
255
+ UARTName uart_rts = (UARTName )pinmap_peripheral (rxflow , PinMap_UART_RTS );
256
+ UARTName uart_cts = (UARTName )pinmap_peripheral (txflow , PinMap_UART_CTS );
257
+
258
+ // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
259
+ SERIAL_OBJ (uart ) = (UARTName )pinmap_merge (uart_cts , uart_rts );
260
+
261
+ MBED_ASSERT (SERIAL_OBJ (uart ) != (UARTName )NC );
262
+ UartHandle .Instance = (USART_TypeDef * )(SERIAL_OBJ (uart ));
263
+
264
+ if (type == FlowControlNone ) {
265
+ // Disable hardware flow control
266
+ SERIAL_OBJ (hw_flow_ctl ) = UART_HWCONTROL_NONE ;
267
+ }
268
+ if (type == FlowControlRTS ) {
269
+ // Enable RTS
270
+ MBED_ASSERT (uart_rts != (UARTName )NC );
271
+ SERIAL_OBJ (hw_flow_ctl ) = UART_HWCONTROL_RTS ;
272
+ SERIAL_OBJ (pin_rts ) = rxflow ;
273
+ // Enable the pin for RTS function
274
+ pinmap_pinout (rxflow , PinMap_UART_RTS );
275
+ }
276
+ if (type == FlowControlCTS ) {
277
+ // Enable CTS
278
+ MBED_ASSERT (uart_cts != (UARTName )NC );
279
+ SERIAL_OBJ (hw_flow_ctl ) = UART_HWCONTROL_CTS ;
280
+ SERIAL_OBJ (pin_cts ) = txflow ;
281
+ // Enable the pin for CTS function
282
+ pinmap_pinout (txflow , PinMap_UART_CTS );
283
+ }
284
+ if (type == FlowControlRTSCTS ) {
285
+ // Enable CTS & RTS
286
+ MBED_ASSERT (uart_rts != (UARTName )NC );
287
+ MBED_ASSERT (uart_cts != (UARTName )NC );
288
+ SERIAL_OBJ (hw_flow_ctl ) = UART_HWCONTROL_RTS_CTS ;
289
+ SERIAL_OBJ (pin_rts ) = rxflow ;
290
+ SERIAL_OBJ (pin_cts ) = txflow ;
291
+ // Enable the pin for CTS function
292
+ pinmap_pinout (txflow , PinMap_UART_CTS );
293
+ // Enable the pin for RTS function
294
+ pinmap_pinout (rxflow , PinMap_UART_RTS );
295
+ }
296
+ init_uart (obj );
297
+ }
298
+ #endif
299
+
234
300
/******************************************************************************
235
301
* INTERRUPTS HANDLING
236
302
******************************************************************************/
0 commit comments