Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
Diff: targets/TARGET_NORDIC/TARGET_NRF5/serial_api.c
- Revision:
- 150:02e0a0aed4ec
- Parent:
- 149:156823d33999
- Child:
- 162:e13f6fdb2ac4
--- a/targets/TARGET_NORDIC/TARGET_NRF5/serial_api.c Fri Oct 28 11:17:30 2016 +0100 +++ b/targets/TARGET_NORDIC/TARGET_NRF5/serial_api.c Tue Nov 08 17:45:16 2016 +0000 @@ -74,6 +74,12 @@ #define UART_DEFAULT_CTS UART0_CONFIG_PSEL_CTS #define UART_DEFAULT_RTS UART0_CONFIG_PSEL_RTS +#ifdef NRF51 + #define NRFx_MBED_UART_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW +#elif defined(NRF52) + #define NRFx_MBED_UART_IRQ_PRIORITY APP_IRQ_PRIORITY_LOWEST +#endif + // Required by "retarget.cpp". int stdio_uart_inited = 0; serial_t stdio_uart; @@ -116,6 +122,9 @@ static uart_ctlblock_t uart_cb[UART_INSTANCE_COUNT]; +static void internal_set_hwfc(FlowControl type, + PinName rxflow, PinName txflow); + #if DEVICE_SERIAL_ASYNCH static void end_asynch_rx(void) @@ -246,6 +255,10 @@ } void serial_init(serial_t *obj, PinName tx, PinName rx) { + + NVIC_SetVector(UART0_IRQn, (uint32_t) UART0_IRQHandler); + + UART_CB.pseltxd = (tx == NC) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t)tx; UART_CB.pselrxd = @@ -287,7 +300,7 @@ #if DEVICE_SERIAL_ASYNCH nrf_uart_int_enable(UART_INSTANCE, NRF_UART_INT_MASK_ERROR); #endif - nrf_drv_common_irq_enable(UART_IRQn, APP_IRQ_PRIORITY_LOW); + nrf_drv_common_irq_enable(UART_IRQn, NRFx_MBED_UART_IRQ_PRIORITY); // TX interrupt needs to be signaled when transmitter buffer is empty, // so a dummy transmission is needed to get the TXDRDY event initially @@ -313,9 +326,10 @@ nrf_uart_baudrate_set(UART_INSTANCE, UART_CB.baudrate); nrf_uart_configure(UART_INSTANCE, UART_CB.parity, UART_CB.hwfc); if (UART_CB.hwfc == NRF_UART_HWFC_ENABLED) { - serial_set_flow_control(obj, FlowControlRTSCTS, + internal_set_hwfc(FlowControlRTSCTS, (PinName) UART_CB.pselrts, (PinName) UART_CB.pselcts); } + nrf_uart_enable(UART_INSTANCE); UART_CB.initialized = true; @@ -524,15 +538,14 @@ nrf_uart_task_trigger(UART_INSTANCE, NRF_UART_TASK_STARTTX); } -void serial_set_flow_control(serial_t *obj, FlowControl type, + +static void internal_set_hwfc(FlowControl type, PinName rxflow, PinName txflow) { - (void)obj; - UART_CB.pselrts = - (rxflow == NC) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t)rxflow; + ((rxflow == NC) || (type == FlowControlCTS)) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t)rxflow; UART_CB.pselcts = - (txflow == NC) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t)txflow; + ((txflow == NC) || (type == FlowControlRTS)) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t)txflow; if (UART_CB.pselrts != NRF_UART_PSEL_DISCONNECTED) { nrf_gpio_pin_set(UART_CB.pselrts); @@ -541,11 +554,24 @@ if (UART_CB.pselcts != NRF_UART_PSEL_DISCONNECTED) { nrf_gpio_cfg_input(UART_CB.pselcts, NRF_GPIO_PIN_NOPULL); } + + UART_CB.hwfc = (type == FlowControlNone)? NRF_UART_HWFC_DISABLED : UART0_CONFIG_HWFC; + + nrf_uart_configure(UART_INSTANCE, UART_CB.parity, UART_CB.hwfc); + nrf_uart_hwfc_pins_set(UART_INSTANCE, UART_CB.pselrts, UART_CB.pselcts); +} + +void serial_set_flow_control(serial_t *obj, FlowControl type, + PinName rxflow, PinName txflow) +{ + (void)obj; + nrf_uart_disable(UART_INSTANCE); - nrf_uart_hwfc_pins_set(UART_INSTANCE, UART_CB.pselrts, UART_CB.pselcts); + internal_set_hwfc(type, rxflow, txflow); nrf_uart_enable(UART_INSTANCE); } + void serial_clear(serial_t *obj) { (void)obj; }