diff options
Diffstat (limited to 'os')
-rw-r--r-- | os/hal/ports/NRF51/NRF51822/serial_lld.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/os/hal/ports/NRF51/NRF51822/serial_lld.c b/os/hal/ports/NRF51/NRF51822/serial_lld.c index bddc4c3..1451857 100644 --- a/os/hal/ports/NRF51/NRF51822/serial_lld.c +++ b/os/hal/ports/NRF51/NRF51822/serial_lld.c @@ -94,47 +94,56 @@ static void configure_uart(const SerialConfig *config) default: osalDbgAssert(0, "invalid baudrate"); break;
};
- /* Configure PINs */
+ /* Configure PINs mode */
if (config->tx_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
palSetPadMode(IOPORT1, config->tx_pad, PAL_MODE_OUTPUT_PUSHPULL);
- NRF_UART0->PSELTXD = config->tx_pad;
}
if (config->rx_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
palSetPadMode(IOPORT1, config->rx_pad, PAL_MODE_INPUT);
- NRF_UART0->PSELRXD = config->rx_pad;
}
#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
if (config->rts_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
palSetPadMode(IOPORT1, config->rts_pad, PAL_MODE_OUTPUT_PUSHPULL);
- NRF_UART0->PSELRTS = config->rts_pad;
}
if (config->cts_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
palSetPadMode(IOPORT1, config->cts_pad, PAL_MODE_INPUT);
- NRF_UART0->PSELCTS = config->cts_pad;
}
#endif
+
+ /* Select PINs used by UART */
+ NRF_UART0->PSELTXD = config->tx_pad;
+ NRF_UART0->PSELRXD = config->rx_pad;
+#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
+ NRF_UART0->PSELRTS = config->rts_pad;
+ NRF_UART0->PSELCTS = config->cts_pad;
+#else
+ NRF_UART0->PSELRTS = NRF51_SERIAL_PAD_DISCONNECTED;
+ NRF_UART0->PSELCTS = NRF51_SERIAL_PAD_DISCONNECTED;
+#endif
+ /* Set baud rate */
NRF_UART0->BAUDRATE = speed;
+
+ /* Set parity */
NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos);
- NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled;
- NRF_UART0->EVENTS_RXDRDY = 0;
- NRF_UART0->EVENTS_TXDRDY = 0;
+ /* Set flow control */
#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
if ((config->rts_pad < TOTAL_GPIO_PADS) ||
(config->cts_pad < TOTAL_GPIO_PADS)) {
- NRF_UART0->CONFIG |= UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos;
+ NRF_UART0->CONFIG |= UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos;
} else {
- NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
+ NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
}
- NRF_UART0->PSELRTS = config->rts_pad;
- NRF_UART0->PSELCTS = config->cts_pad;
#else
- NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
-
- NRF_UART0->PSELRTS = NRF51_SERIAL_PAD_DISCONNECTED;
- NRF_UART0->PSELCTS = NRF51_SERIAL_PAD_DISCONNECTED;
+ NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
#endif
+
+ /* Enable UART and clear events */
+ NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled;
+ NRF_UART0->EVENTS_RXDRDY = 0;
+ NRF_UART0->EVENTS_TXDRDY = 0;
+
if (config->rx_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
while (NRF_UART0->EVENTS_RXDRDY != 0) {
|