Skip to content

Commit

Permalink
Merge pull request #1521 from adustm/b_b96b_serial_flow_control
Browse files Browse the repository at this point in the history
[STM B96B_F446VE] HW Control Flow for serial
  • Loading branch information
0xc0170 committed Feb 10, 2016
2 parents 1b8d317 + 6da4190 commit 66c0620
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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

0 comments on commit 66c0620

Please sign in to comment.