Skip to content

Commit 92a3452

Browse files
mridup0xc0170
authored andcommitted
adding hwflwctl support for NUCLEO_L476RG (#1658)
1 parent a11f73c commit 92a3452

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L4/PeripheralPins.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ extern const PinMap PinMap_PWM[];
5555

5656
extern const PinMap PinMap_UART_TX[];
5757
extern const PinMap PinMap_UART_RX[];
58+
extern const PinMap PinMap_UART_RTS[];
59+
extern const PinMap PinMap_UART_CTS[];
5860

5961
//*** SPI ***
6062

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L476RG/PeripheralPins.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ const PinMap PinMap_UART_RX[] = {
184184
{NC, NC, 0}
185185
};
186186

187+
const PinMap PinMap_UART_RTS[] = {
188+
{PA_1, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
189+
{PA_12, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
190+
// {PA_15, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
191+
// {PB_14, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, // MEMs
192+
// {PC_8, UART_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART5)},
193+
// {PD_4, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
194+
// {PD_12, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART3)}, // LED D4
195+
{NC, NC, 0}
196+
};
197+
198+
const PinMap PinMap_UART_CTS[] = {
199+
{PA_0, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
200+
{PA_11, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
201+
// {PB_0, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
202+
// {PB_13, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
203+
// {PC_9, UART_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART5)},
204+
// {PD_3, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
205+
// {PD_11, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART3)}, // LED D4
206+
{NC, NC, 0}
207+
};
208+
187209
//*** SPI ***
188210

189211
const PinMap PinMap_SPI_MOSI[] = {

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L476RG/device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define DEVICE_ANALOGOUT 1
4141

4242
#define DEVICE_SERIAL 1
43+
#define DEVICE_SERIAL_FC 1
4344

4445
#define DEVICE_I2C 1
4546
#define DEVICE_I2CSLAVE 1

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L476RG/objects.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ struct serial_s {
7575
uint32_t parity;
7676
PinName pin_tx;
7777
PinName pin_rx;
78+
#if DEVICE_SERIAL_FC
79+
uint32_t hw_flow_ctl;
80+
PinName pin_rts;
81+
PinName pin_cts;
82+
#endif
7883
};
7984

8085
struct spi_s {

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L4/serial_api.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ UART_HandleTypeDef UartHandle;
4949
int stdio_uart_inited = 0;
5050
serial_t stdio_uart;
5151

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+
5258
static void init_uart(serial_t *obj)
5359
{
5460
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
@@ -57,7 +63,11 @@ static void init_uart(serial_t *obj)
5763
UartHandle.Init.WordLength = obj->databits;
5864
UartHandle.Init.StopBits = obj->stopbits;
5965
UartHandle.Init.Parity = obj->parity;
66+
#if DEVICE_SERIAL_FC
67+
UartHandle.Init.HwFlowCtl = SERIAL_OBJ(hw_flow_ctl);
68+
#else
6069
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
70+
#endif
6171
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
6272
UartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_ENABLE;
6373

@@ -231,6 +241,62 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
231241
init_uart(obj);
232242
}
233243

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+
234300
/******************************************************************************
235301
* INTERRUPTS HANDLING
236302
******************************************************************************/

0 commit comments

Comments
 (0)