mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Wed Feb 10 07:45:10 2016 +0000
Parent:
59:d25f6f8282a3
Child:
61:4f60c38c1b8c
Commit message:
Synchronized with git revision 66c0620619055974998c52af1909fa7641cd34c9

Full URL: https://github.com/mbedmicro/mbed/commit/66c0620619055974998c52af1909fa7641cd34c9/

[STM B96B_F446VE] HW Control Flow for serial

Changed in this revision

targets/hal/TARGET_STM/TARGET_STM32F4/PeripheralPins.h Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/PeripheralPins.c Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device.h Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/objects.h Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_STM32F4/serial_api.c Show annotated file Show diff for this revision Revisions of this file
--- a/targets/hal/TARGET_STM/TARGET_STM32F4/PeripheralPins.h	Wed Feb 03 14:15:10 2016 +0000
+++ b/targets/hal/TARGET_STM/TARGET_STM32F4/PeripheralPins.h	Wed Feb 10 07:45:10 2016 +0000
@@ -55,6 +55,8 @@
 
 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 ***
 
--- a/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/PeripheralPins.c	Wed Feb 03 14:15:10 2016 +0000
+++ b/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/PeripheralPins.c	Wed Feb 10 07:45:10 2016 +0000
@@ -205,6 +205,27 @@
     {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[] = {
--- a/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device.h	Wed Feb 03 14:15:10 2016 +0000
+++ b/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device.h	Wed Feb 10 07:45:10 2016 +0000
@@ -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
--- a/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/objects.h	Wed Feb 03 14:15:10 2016 +0000
+++ b/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/objects.h	Wed Feb 10 07:45:10 2016 +0000
@@ -77,6 +77,11 @@
 #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 {
--- a/targets/hal/TARGET_STM/TARGET_STM32F4/serial_api.c	Wed Feb 03 14:15:10 2016 +0000
+++ b/targets/hal/TARGET_STM/TARGET_STM32F4/serial_api.c	Wed Feb 10 07:45:10 2016 +0000
@@ -78,7 +78,11 @@
     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 @@
 
 #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