From 6da4190be932bea439c5530c337edb4adbcfe6c5 Mon Sep 17 00:00:00 2001 From: adustm Date: Fri, 29 Jan 2016 17:59:45 +0100 Subject: [PATCH] [STM B96B_F446VE] HW Control Flow for serial --- .../TARGET_STM32F4/PeripheralPins.h | 2 + .../TARGET_B96B_F446VE/PeripheralPins.c | 21 +++++++ .../TARGET_B96B_F446VE/device.h | 2 +- .../TARGET_B96B_F446VE/objects.h | 5 ++ .../TARGET_STM/TARGET_STM32F4/serial_api.c | 61 ++++++++++++++++++- 5 files changed, 89 insertions(+), 2 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/PeripheralPins.h b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/PeripheralPins.h index cc2fcaaf11..99f00a5591 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/PeripheralPins.h +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/PeripheralPins.h @@ -55,6 +55,8 @@ extern const PinMap PinMap_PWM[]; extern const PinMap PinMap_UART_TX[]; extern const PinMap PinMap_UART_RX[]; +extern const PinMap PinMap_UART_RTS[]; +extern const PinMap PinMap_UART_CTS[]; //*** SPI *** diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/PeripheralPins.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/PeripheralPins.c index b36a155c15..6bf06630cd 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/PeripheralPins.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/PeripheralPins.c @@ -205,6 +205,27 @@ const PinMap PinMap_UART_RX[] = { {NC, NC, 0} }; +const PinMap PinMap_UART_RTS[] = { + {PA_1, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, + {PA_12, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, + // {PA_15, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, + // {PB_14, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, // MEMs + {PC_8, UART_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART5)}, + {PD_4, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, + // {PD_12, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART3)}, // LED D4 + {NC, NC, 0} +}; + +const PinMap PinMap_UART_CTS[] = { + // {PA_0, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, + {PA_11, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, + {PB_0, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, + // {PB_13, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, + // {PC_9, UART_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART5)}, // unsolder JP69 to use it + // {PD_3, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, // unsolder JP14 to use it + // {PD_11, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART3)}, // LED D4 + {NC, NC, 0} +}; //*** SPI *** const PinMap PinMap_SPI_MOSI[] = { diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device.h b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device.h index 112494dfd6..e5ec5cb94c 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device.h +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device.h @@ -42,7 +42,7 @@ #define DEVICE_SERIAL 1 #define DEVICE_SERIAL_ASYNCH 1 #define DEVICE_SERIAL_ASYNCH_DMA 1 -#define DEVICE_SERIAL_FC 0 +#define DEVICE_SERIAL_FC 1 #define DEVICE_I2C 1 #define DEVICE_I2CSLAVE 1 diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/objects.h b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/objects.h index 1b1c0a4ecc..137da19148 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/objects.h +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/objects.h @@ -77,6 +77,11 @@ struct serial_s { #if DEVICE_SERIAL_ASYNCH uint32_t events; #endif +#if DEVICE_SERIAL_FC + uint32_t hw_flow_ctl; + PinName pin_rts; + PinName pin_cts; +#endif }; struct spi_s { diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/serial_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/serial_api.c index 9176b8b6f0..e40896d7aa 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/serial_api.c @@ -78,7 +78,11 @@ static void init_uart(serial_t *obj) UartHandle.Init.WordLength = SERIAL_OBJ(databits); UartHandle.Init.StopBits = SERIAL_OBJ(stopbits); UartHandle.Init.Parity = SERIAL_OBJ(parity); - UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; +#if DEVICE_SERIAL_FC + UartHandle.Init.HwFlowCtl = SERIAL_OBJ(hw_flow_ctl); +#else + UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; +#endif UartHandle.Init.OverSampling = UART_OVERSAMPLING_16; if (SERIAL_OBJ(pin_rx) == NC) { @@ -1177,4 +1181,59 @@ void serial_rx_abort_asynch(serial_t *obj) #endif +#if DEVICE_SERIAL_FC +/** Set HW Control Flow + * @param obj The serial object + * @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS) + * @param rxflow Pin for the rxflow + * @param txflow Pin for the txflow + */ +void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) +{ + + // Determine the UART to use (UART_1, UART_2, ...) + UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); + UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); + + // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object + SERIAL_OBJ(uart) = (UARTName)pinmap_merge(uart_cts, uart_rts); + + MBED_ASSERT(SERIAL_OBJ(uart) != (UARTName)NC); + UartHandle.Instance = (USART_TypeDef *)(SERIAL_OBJ(uart)); + + if(type == FlowControlNone) { + // Disable hardware flow control + SERIAL_OBJ(hw_flow_ctl) = UART_HWCONTROL_NONE; + } + if (type == FlowControlRTS) { + // Enable RTS + MBED_ASSERT(uart_rts != (UARTName)NC); + SERIAL_OBJ(hw_flow_ctl) = UART_HWCONTROL_RTS; + SERIAL_OBJ(pin_rts) = rxflow; + // Enable the pin for RTS function + pinmap_pinout(rxflow, PinMap_UART_RTS); + } + if (type == FlowControlCTS) { + // Enable CTS + MBED_ASSERT(uart_cts != (UARTName)NC); + SERIAL_OBJ(hw_flow_ctl) = UART_HWCONTROL_CTS; + SERIAL_OBJ(pin_cts) = txflow; + // Enable the pin for CTS function + pinmap_pinout(txflow, PinMap_UART_CTS); + } + if (type == FlowControlRTSCTS) { + // Enable CTS & RTS + MBED_ASSERT(uart_rts != (UARTName)NC); + MBED_ASSERT(uart_cts != (UARTName)NC); + SERIAL_OBJ(hw_flow_ctl) = UART_HWCONTROL_RTS_CTS; + SERIAL_OBJ(pin_rts) = rxflow; + SERIAL_OBJ(pin_cts) = txflow; + // Enable the pin for CTS function + pinmap_pinout(txflow, PinMap_UART_CTS); + // Enable the pin for RTS function + pinmap_pinout(rxflow, PinMap_UART_RTS); + } + init_uart(obj); +} +#endif #endif