Skip to content

Commit d58bfa7

Browse files
authored
Merge pull request #3041 from nvlsianpu/nrf5_serial_fc
[nRF5] - added implementation of API of serial port flow control configuration.
2 parents 97670e3 + fe3a8b0 commit d58bfa7

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

targets/TARGET_NORDIC/TARGET_NRF5/serial_api.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ typedef struct {
116116

117117
static uart_ctlblock_t uart_cb[UART_INSTANCE_COUNT];
118118

119+
static void internal_set_hwfc(FlowControl type,
120+
PinName rxflow, PinName txflow);
121+
119122

120123
#if DEVICE_SERIAL_ASYNCH
121124
static void end_asynch_rx(void)
@@ -313,9 +316,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
313316
nrf_uart_baudrate_set(UART_INSTANCE, UART_CB.baudrate);
314317
nrf_uart_configure(UART_INSTANCE, UART_CB.parity, UART_CB.hwfc);
315318
if (UART_CB.hwfc == NRF_UART_HWFC_ENABLED) {
316-
serial_set_flow_control(obj, FlowControlRTSCTS,
319+
internal_set_hwfc(FlowControlRTSCTS,
317320
(PinName) UART_CB.pselrts, (PinName) UART_CB.pselcts);
318321
}
322+
319323
nrf_uart_enable(UART_INSTANCE);
320324

321325
UART_CB.initialized = true;
@@ -524,15 +528,14 @@ void serial_break_clear(serial_t *obj)
524528
nrf_uart_task_trigger(UART_INSTANCE, NRF_UART_TASK_STARTTX);
525529
}
526530

527-
void serial_set_flow_control(serial_t *obj, FlowControl type,
531+
532+
static void internal_set_hwfc(FlowControl type,
528533
PinName rxflow, PinName txflow)
529534
{
530-
(void)obj;
531-
532535
UART_CB.pselrts =
533-
(rxflow == NC) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t)rxflow;
536+
((rxflow == NC) || (type == FlowControlCTS)) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t)rxflow;
534537
UART_CB.pselcts =
535-
(txflow == NC) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t)txflow;
538+
((txflow == NC) || (type == FlowControlRTS)) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t)txflow;
536539

537540
if (UART_CB.pselrts != NRF_UART_PSEL_DISCONNECTED) {
538541
nrf_gpio_pin_set(UART_CB.pselrts);
@@ -541,11 +544,24 @@ void serial_set_flow_control(serial_t *obj, FlowControl type,
541544
if (UART_CB.pselcts != NRF_UART_PSEL_DISCONNECTED) {
542545
nrf_gpio_cfg_input(UART_CB.pselcts, NRF_GPIO_PIN_NOPULL);
543546
}
544-
nrf_uart_disable(UART_INSTANCE);
547+
548+
UART_CB.hwfc = (type == FlowControlNone)? NRF_UART_HWFC_DISABLED : UART0_CONFIG_HWFC;
549+
550+
nrf_uart_configure(UART_INSTANCE, UART_CB.parity, UART_CB.hwfc);
545551
nrf_uart_hwfc_pins_set(UART_INSTANCE, UART_CB.pselrts, UART_CB.pselcts);
552+
}
553+
554+
void serial_set_flow_control(serial_t *obj, FlowControl type,
555+
PinName rxflow, PinName txflow)
556+
{
557+
(void)obj;
558+
559+
nrf_uart_disable(UART_INSTANCE);
560+
internal_set_hwfc(type, rxflow, txflow);
546561
nrf_uart_enable(UART_INSTANCE);
547562
}
548563

564+
549565
void serial_clear(serial_t *obj) {
550566
(void)obj;
551567
}

targets/targets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@
20182018
"NRF51_DK": {
20192019
"supported_form_factors": ["ARDUINO"],
20202020
"inherits": ["MCU_NRF51_32K_UNIFIED"],
2021-
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
2021+
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
20222022
"release_versions": ["2", "5"],
20232023
"device_name": "nRF51822_xxAA"
20242024
},
@@ -2069,7 +2069,7 @@
20692069
"supported_form_factors": ["ARDUINO"],
20702070
"inherits": ["MCU_NRF52"],
20712071
"macros_add": ["BOARD_PCA10040", "NRF52_PAN_12", "NRF52_PAN_15", "NRF52_PAN_58", "NRF52_PAN_55", "NRF52_PAN_54", "NRF52_PAN_31", "NRF52_PAN_30", "NRF52_PAN_51", "NRF52_PAN_36", "NRF52_PAN_53", "S132", "CONFIG_GPIO_AS_PINRESET", "BLE_STACK_SUPPORT_REQD", "SWI_DISABLE0", "NRF52_PAN_20", "NRF52_PAN_64", "NRF52_PAN_62", "NRF52_PAN_63"],
2072-
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
2072+
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
20732073
"release_versions": ["2", "5"],
20742074
"device_name": "nRF52832_xxAA"
20752075
},

0 commit comments

Comments
 (0)