Skip to content

Commit

Permalink
[NRF_5] add configuration for serial flow control
Browse files Browse the repository at this point in the history
  • Loading branch information
ytsuboi committed Aug 19, 2016
1 parent bdb4ab9 commit 0417427
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hal/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,9 @@
"macros_add": ["TARGET_NRF_32MHZ_XTAL"],
"progen": {"target": "ty51822r3"},
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
"overrides": {
"serial_fc": "WITHOUT_FC"
},
"detect_code": ["1019"],
"release_versions": ["2", "5"]
},
Expand Down Expand Up @@ -1887,6 +1890,11 @@
"lf_clock_src": {
"value": "NRF_LF_SRC_XTAL",
"macro_name": "MBED_CONF_NORDIC_NRF_LF_CLOCK_SRC"
},
"serial_fc": {
"help": "Choose serial with flow control or without",
"value": "WITH_FC",
"macro_name": "MBED_CONF_NORDIC_NRF_SERIAL_FC"
}
}
},
Expand Down
19 changes: 19 additions & 0 deletions hal/targets/hal/TARGET_NORDIC/TARGET_NRF5/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@
#define UART_DEFAULT_CTS UART0_CONFIG_PSEL_CTS
#define UART_DEFAULT_RTS UART0_CONFIG_PSEL_RTS

#ifndef MBED_CONF_NORDIC_NRF_SERIAL_FC
#define MBED_CONF_NORDIC_NRF_SERIAL_FC (WITH_FC)
#warning No configuration for serial flow control. Serial will be used as a default, with flow control.
#endif

#define WITH_FC 2
#define WITHOUT_FC 3


// Required by "retarget.cpp".
int stdio_uart_inited = 0;
serial_t stdio_uart;
Expand Down Expand Up @@ -257,9 +266,16 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
else {
UART_CB.baudrate = UART_DEFAULT_BAUDRATE;
UART_CB.parity = UART_DEFAULT_PARITY;

#if MBED_CONF_NORDIC_NRF_SERIAL_FC == WITH_FC
UART_CB.hwfc = UART_DEFAULT_HWFC;
UART_CB.pselcts = UART_DEFAULT_CTS;
UART_CB.pselrts = UART_DEFAULT_RTS;
#elif MBED_CONF_NORDIC_NRF_SERIAL_FC == WITHOUT_FC
// Not init UART with HWFC.
#else
#error Bad flow control configuration. Declare proper source through mbed configuration.
#endif

nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_RXDRDY);
nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_TXDRDY);
Expand Down Expand Up @@ -639,4 +655,7 @@ void serial_rx_abort_asynch(serial_t *obj)

#endif // DEVICE_SERIAL_ASYNCH

#undef WITH_FC
#undef WITHOUT_FC

#endif // DEVICE_SERIAL

0 comments on commit 0417427

Please sign in to comment.