Skip to content

Commit 916ecab

Browse files
author
Jakub Rzeszutko
committed
drivers: serial: nrf: Serial driver modification to use DT
1. dts.fixup files updated with peripheral address and IRQ NUMBER. 2. Peripheral address is taken from DT. 3. IRQ number is taken from DT. Signed-off-by: Jakub Rzeszutko <[email protected]>
1 parent f733da8 commit 916ecab

File tree

4 files changed

+77
-67
lines changed

4 files changed

+77
-67
lines changed

arch/arm/soc/nordic_nrf/nrf51/dts.fixup

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/* SoC level DTS fixup file */
22

33
#define CONFIG_NUM_IRQ_PRIO_BITS ARM_V6M_NVIC_E000E100_ARM_NUM_IRQ_PRIORITY_BITS
4+
#define CONFIG_UART_0_BASE NORDIC_NRF_UART_40002000_BASE_ADDRESS
45
#define CONFIG_UART_0_IRQ_PRI NORDIC_NRF_UART_40002000_IRQ_0_PRIORITY
6+
#define CONFIG_UART_0_IRQ_NUM NORDIC_NRF_UART_40002000_IRQ_0
57
#define CONFIG_UART_0_BAUD_RATE NORDIC_NRF_UART_40002000_CURRENT_SPEED
68
#define CONFIG_UART_0_NAME NORDIC_NRF_UART_40002000_LABEL
79

arch/arm/soc/nordic_nrf/nrf52/dts.fixup

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33
#define CONFIG_NUM_IRQ_PRIO_BITS ARM_V7M_NVIC_E000E100_ARM_NUM_IRQ_PRIORITY_BITS
44
#if defined(NORDIC_NRF_UARTE_40002000_BASE_ADDRESS)
5+
#define CONFIG_UART_0_BASE NORDIC_NRF_UARTE_40002000_BASE_ADDRESS
56
#define CONFIG_UART_0_IRQ_PRI NORDIC_NRF_UARTE_40002000_IRQ_0_PRIORITY
7+
#define CONFIG_UART_0_IRQ_NUM NORDIC_NRF_UARTE_40002000_IRQ_0
68
#define CONFIG_UART_0_BAUD_RATE NORDIC_NRF_UARTE_40002000_CURRENT_SPEED
79
#define CONFIG_UART_0_NAME NORDIC_NRF_UARTE_40002000_LABEL
810
#else
11+
#define CONFIG_UART_0_BASE NORDIC_NRF_UART_40002000_BASE_ADDRESS
912
#define CONFIG_UART_0_IRQ_PRI NORDIC_NRF_UART_40002000_IRQ_0_PRIORITY
13+
#define CONFIG_UART_0_IRQ_NUM NORDIC_NRF_UART_40002000_IRQ_0
1014
#define CONFIG_UART_0_BAUD_RATE NORDIC_NRF_UART_40002000_CURRENT_SPEED
1115
#define CONFIG_UART_0_NAME NORDIC_NRF_UART_40002000_LABEL
1216
#endif
1317

18+
#define CONFIG_UART_1_BASE NORDIC_NRF_UARTE_40028000_BASE_ADDRESS
1419
#define CONFIG_UART_1_IRQ_PRI NORDIC_NRF_UARTE_40028000_IRQ_0_PRIORITY
20+
#define CONFIG_UART_1_IRQ_NUM NORDIC_NRF_UARTE_40028000_IRQ_0
1521
#define CONFIG_UART_1_BAUD_RATE NORDIC_NRF_UARTE_40028000_CURRENT_SPEED
1622
#define CONFIG_UART_1_NAME NORDIC_NRF_UARTE_40028000_LABEL
1723

drivers/serial/uart_nrfx_uart.c

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <hal/nrf_gpio.h>
1414

1515

16+
static NRF_UART_Type *const uart0_addr = (NRF_UART_Type *)CONFIG_UART_0_BASE;
17+
1618
#ifdef CONFIG_UART_0_INTERRUPT_DRIVEN
1719

1820
static uart_irq_callback_t irq_callback; /**< Callback function pointer */
@@ -29,7 +31,7 @@ static volatile u8_t uart_sw_event_txdrdy;
2931

3032
static bool event_txdrdy_check(void)
3133
{
32-
return (nrf_uart_event_check(NRF_UART0, NRF_UART_EVENT_TXDRDY)
34+
return (nrf_uart_event_check(uart0_addr, NRF_UART_EVENT_TXDRDY)
3335
#ifdef CONFIG_UART_0_INTERRUPT_DRIVEN
3436
|| uart_sw_event_txdrdy
3537
#endif
@@ -38,7 +40,7 @@ static bool event_txdrdy_check(void)
3840

3941
static void event_txdrdy_clear(void)
4042
{
41-
nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_TXDRDY);
43+
nrf_uart_event_clear(uart0_addr, NRF_UART_EVENT_TXDRDY);
4244
#ifdef CONFIG_UART_0_INTERRUPT_DRIVEN
4345
uart_sw_event_txdrdy = 0;
4446
#endif
@@ -127,7 +129,7 @@ static int baudrate_set(struct device *dev, u32_t baudrate)
127129
return -EINVAL;
128130
}
129131

130-
nrf_uart_baudrate_set(NRF_UART0, nrf_baudrate);
132+
nrf_uart_baudrate_set(uart0_addr, nrf_baudrate);
131133

132134
return 0;
133135
}
@@ -143,15 +145,15 @@ static int baudrate_set(struct device *dev, u32_t baudrate)
143145

144146
static int uart_nrfx_poll_in(struct device *dev, unsigned char *c)
145147
{
146-
if (!nrf_uart_event_check(NRF_UART0, NRF_UART_EVENT_RXDRDY)) {
148+
if (!nrf_uart_event_check(uart0_addr, NRF_UART_EVENT_RXDRDY)) {
147149
return -1;
148150
}
149151

150152
/* Clear the interrupt */
151-
nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_RXDRDY);
153+
nrf_uart_event_clear(uart0_addr, NRF_UART_EVENT_RXDRDY);
152154

153155
/* got a character */
154-
*c = nrf_uart_rxd_get(NRF_UART0);
156+
*c = nrf_uart_rxd_get(uart0_addr);
155157

156158
return 0;
157159
}
@@ -182,7 +184,7 @@ static unsigned char uart_nrfx_poll_out(struct device *dev,
182184
event_txdrdy_clear();
183185

184186
/* send a character */
185-
nrf_uart_txd_set(NRF_UART0, (u8_t)c);
187+
nrf_uart_txd_set(uart0_addr, (u8_t)c);
186188

187189
/* Wait for transmitter to be ready */
188190
while (!event_txdrdy_check()) {
@@ -196,9 +198,9 @@ static int uart_nrfx_err_check(struct device *dev)
196198
{
197199
u32_t error = 0;
198200

199-
if (nrf_uart_event_check(NRF_UART0, NRF_UART_EVENT_ERROR)) {
201+
if (nrf_uart_event_check(uart0_addr, NRF_UART_EVENT_ERROR)) {
200202
/* register bitfields maps to the defines in uart.h */
201-
error = nrf_uart_errorsrc_get_and_clear(NRF_UART0);
203+
error = nrf_uart_errorsrc_get_and_clear(uart0_addr);
202204
}
203205

204206
return error;
@@ -221,7 +223,7 @@ static int uart_nrfx_fifo_fill(struct device *dev,
221223
event_txdrdy_clear();
222224

223225
/* Send a character */
224-
nrf_uart_txd_set(NRF_UART0, (u8_t)tx_data[num_tx++]);
226+
nrf_uart_txd_set(uart0_addr, (u8_t)tx_data[num_tx++]);
225227
}
226228

227229
return (int)num_tx;
@@ -235,12 +237,12 @@ static int uart_nrfx_fifo_read(struct device *dev,
235237
u8_t num_rx = 0;
236238

237239
while ((size - num_rx > 0) &&
238-
nrf_uart_event_check(NRF_UART0, NRF_UART_EVENT_RXDRDY)) {
240+
nrf_uart_event_check(uart0_addr, NRF_UART_EVENT_RXDRDY)) {
239241
/* Clear the interrupt */
240-
nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_RXDRDY);
242+
nrf_uart_event_clear(uart0_addr, NRF_UART_EVENT_RXDRDY);
241243

242244
/* Receive a character */
243-
rx_data[num_rx++] = (u8_t)nrf_uart_rxd_get(NRF_UART0);
245+
rx_data[num_rx++] = (u8_t)nrf_uart_rxd_get(uart0_addr);
244246
}
245247

246248
return num_rx;
@@ -251,7 +253,7 @@ static void uart_nrfx_irq_tx_enable(struct device *dev)
251253
{
252254
u32_t key;
253255

254-
nrf_uart_int_enable(NRF_UART0, NRF_UART_INT_MASK_TXDRDY);
256+
nrf_uart_int_enable(uart0_addr, NRF_UART_INT_MASK_TXDRDY);
255257

256258
/* Critical section is used to avoid any UART related interrupt which
257259
* can occur after the if statement and before call of the function
@@ -262,27 +264,27 @@ static void uart_nrfx_irq_tx_enable(struct device *dev)
262264
/* Due to HW limitation first TXDRDY interrupt shall be
263265
* triggered by the software.
264266
*/
265-
NVIC_SetPendingIRQ(NRFX_IRQ_NUMBER_GET(NRF_UART0));
267+
NVIC_SetPendingIRQ(CONFIG_UART_0_IRQ_NUM);
266268
}
267269
irq_unlock(key);
268270
}
269271

270272
/** Interrupt driven transfer disabling function */
271273
static void uart_nrfx_irq_tx_disable(struct device *dev)
272274
{
273-
nrf_uart_int_disable(NRF_UART0, NRF_UART_INT_MASK_TXDRDY);
275+
nrf_uart_int_disable(uart0_addr, NRF_UART_INT_MASK_TXDRDY);
274276
}
275277

276278
/** Interrupt driven receiver enabling function */
277279
static void uart_nrfx_irq_rx_enable(struct device *dev)
278280
{
279-
nrf_uart_int_enable(NRF_UART0, NRF_UART_INT_MASK_RXDRDY);
281+
nrf_uart_int_enable(uart0_addr, NRF_UART_INT_MASK_RXDRDY);
280282
}
281283

282284
/** Interrupt driven receiver disabling function */
283285
static void uart_nrfx_irq_rx_disable(struct device *dev)
284286
{
285-
nrf_uart_int_disable(NRF_UART0, NRF_UART_INT_MASK_RXDRDY);
287+
nrf_uart_int_disable(uart0_addr, NRF_UART_INT_MASK_RXDRDY);
286288
}
287289

288290
/** Interrupt driven transfer empty function */
@@ -294,29 +296,29 @@ static int uart_nrfx_irq_tx_ready_complete(struct device *dev)
294296
/** Interrupt driven receiver ready function */
295297
static int uart_nrfx_irq_rx_ready(struct device *dev)
296298
{
297-
return nrf_uart_event_check(NRF_UART0, NRF_UART_EVENT_RXDRDY);
299+
return nrf_uart_event_check(uart0_addr, NRF_UART_EVENT_RXDRDY);
298300
}
299301

300302
/** Interrupt driven error enabling function */
301303
static void uart_nrfx_irq_err_enable(struct device *dev)
302304
{
303-
nrf_uart_int_enable(NRF_UART0, NRF_UART_INT_MASK_ERROR);
305+
nrf_uart_int_enable(uart0_addr, NRF_UART_INT_MASK_ERROR);
304306
}
305307

306308
/** Interrupt driven error disabling function */
307309
static void uart_nrfx_irq_err_disable(struct device *dev)
308310
{
309-
nrf_uart_int_disable(NRF_UART0, NRF_UART_INT_MASK_ERROR);
311+
nrf_uart_int_disable(uart0_addr, NRF_UART_INT_MASK_ERROR);
310312
}
311313

312314
/** Interrupt driven pending status function */
313315
static int uart_nrfx_irq_is_pending(struct device *dev)
314316
{
315-
return ((nrf_uart_int_enable_check(NRF_UART0,
317+
return ((nrf_uart_int_enable_check(uart0_addr,
316318
NRF_UART_INT_MASK_TXDRDY) &&
317319
event_txdrdy_check())
318320
||
319-
(nrf_uart_int_enable_check(NRF_UART0,
321+
(nrf_uart_int_enable_check(uart0_addr,
320322
NRF_UART_INT_MASK_RXDRDY) &&
321323
uart_nrfx_irq_rx_ready(dev)));
322324
}
@@ -378,7 +380,7 @@ static int uart_nrfx_init(struct device *dev)
378380

379381
nrf_gpio_cfg_input(CONFIG_UART_0_NRF_RX_PIN, NRF_GPIO_PIN_NOPULL);
380382

381-
nrf_uart_txrx_pins_set(NRF_UART0,
383+
nrf_uart_txrx_pins_set(uart0_addr,
382384
CONFIG_UART_0_NRF_TX_PIN,
383385
CONFIG_UART_0_NRF_RX_PIN);
384386

@@ -391,12 +393,12 @@ static int uart_nrfx_init(struct device *dev)
391393

392394
nrf_gpio_cfg_input(CONFIG_UART_0_NRF_CTS_PIN, NRF_GPIO_PIN_NOPULL);
393395

394-
nrf_uart_hwfc_pins_set(NRF_UART0,
396+
nrf_uart_hwfc_pins_set(uart0_addr,
395397
CONFIG_UART_0_NRF_RTS_PIN,
396398
CONFIG_UART_0_NRF_CTS_PIN);
397399
#endif /* CONFIG_UART_0_NRF_FLOW_CONTROL */
398400

399-
nrf_uart_configure(NRF_UART0,
401+
nrf_uart_configure(uart0_addr,
400402
#ifdef CONFIG_UART_0_NRF_PARITY_BIT
401403
NRF_UART_PARITY_INCLUDED,
402404
#else
@@ -415,12 +417,12 @@ static int uart_nrfx_init(struct device *dev)
415417
}
416418

417419
/* Enable receiver and transmitter */
418-
nrf_uart_enable(NRF_UART0);
420+
nrf_uart_enable(uart0_addr);
419421

420-
nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_RXDRDY);
422+
nrf_uart_event_clear(uart0_addr, NRF_UART_EVENT_RXDRDY);
421423

422-
nrf_uart_task_trigger(NRF_UART0, NRF_UART_TASK_STARTTX);
423-
nrf_uart_task_trigger(NRF_UART0, NRF_UART_TASK_STARTRX);
424+
nrf_uart_task_trigger(uart0_addr, NRF_UART_TASK_STARTTX);
425+
nrf_uart_task_trigger(uart0_addr, NRF_UART_TASK_STARTRX);
424426

425427
#ifdef CONFIG_UART_0_INTERRUPT_DRIVEN
426428

@@ -429,12 +431,12 @@ static int uart_nrfx_init(struct device *dev)
429431
*/
430432
uart_sw_event_txdrdy = 1;
431433

432-
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_UART0),
434+
IRQ_CONNECT(CONFIG_UART_0_IRQ_NUM,
433435
CONFIG_UART_0_IRQ_PRI,
434436
uart_nrfx_isr,
435437
DEVICE_GET(uart_nrfx_uart0),
436438
0);
437-
irq_enable(NRFX_IRQ_NUMBER_GET(NRF_UART0));
439+
irq_enable(CONFIG_UART_0_IRQ_NUM);
438440
#endif
439441

440442
return 0;
@@ -474,3 +476,4 @@ DEVICE_AND_API_INIT(uart_nrfx_uart0,
474476
PRE_KERNEL_1,
475477
CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
476478
&uart_nrfx_uart_driver_api);
479+

drivers/serial/uart_nrfx_uarte.c

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,6 @@ static int uarte_instance_init(struct device *dev,
483483

484484
#if UARTE_INTERRUPT_DRIVEN
485485
if (interrupts_active) {
486-
487-
irq_enable(NRFX_IRQ_NUMBER_GET(uarte));
488-
489486
/* Set ENDTX event by requesting fake (zero-length) transfer.
490487
* Pointer to RAM variable (data->tx_buffer) is set because
491488
* otherwise such operation may result in HardFault or RAM
@@ -502,37 +499,37 @@ static int uarte_instance_init(struct device *dev,
502499
return 0;
503500
}
504501

505-
#define UART_NRF_UARTE_DEVICE(idx) \
506-
DEVICE_DECLARE(uart_nrfx_uarte##idx); \
507-
UARTE_##idx##_CREATE_TX_BUFF; \
508-
static struct uarte_nrfx_data uarte_##idx##_data = { \
509-
UARTE_##idx##_DATA_INIT \
510-
}; \
511-
static const struct uarte_nrfx_config uarte_##idx##_config = { \
512-
.uarte_regs = (NRF_UARTE_Type *)NRF_UARTE##idx, \
513-
UARTE_##idx##_CONFIG_INIT \
514-
}; \
515-
static int uarte_##idx##_init(struct device *dev) \
516-
{ \
517-
const struct uarte_init_config init_config = { \
518-
.pseltxd = CONFIG_UART_##idx##_NRF_TX_PIN, \
519-
.pselrxd = CONFIG_UART_##idx##_NRF_RX_PIN, \
520-
UARTE_##idx##_NRF_HWFC_CONFIG \
521-
.parity = UARTE_##idx##_NRF_PARITY_BIT, \
522-
.baudrate = CONFIG_UART_##idx##_BAUD_RATE \
523-
}; \
524-
UARTE_##idx##_INTERRUPTS_INIT(); \
525-
return uarte_instance_init(dev, \
526-
&init_config, \
527-
UARTE_##idx##_INTERRUPT_DRIVEN); \
528-
} \
529-
DEVICE_AND_API_INIT(uart_nrfx_uarte##idx, \
530-
CONFIG_UART_##idx##_NAME, \
531-
uarte_##idx##_init, \
532-
&uarte_##idx##_data, \
533-
&uarte_##idx##_config, \
534-
PRE_KERNEL_1, \
535-
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
502+
#define UART_NRF_UARTE_DEVICE(idx) \
503+
DEVICE_DECLARE(uart_nrfx_uarte##idx); \
504+
UARTE_##idx##_CREATE_TX_BUFF; \
505+
static struct uarte_nrfx_data uarte_##idx##_data = { \
506+
UARTE_##idx##_DATA_INIT \
507+
}; \
508+
static const struct uarte_nrfx_config uarte_##idx##_config = { \
509+
.uarte_regs = (NRF_UARTE_Type *)CONFIG_UART_##idx##_BASE, \
510+
UARTE_##idx##_CONFIG_INIT \
511+
}; \
512+
static int uarte_##idx##_init(struct device *dev) \
513+
{ \
514+
const struct uarte_init_config init_config = { \
515+
.pseltxd = CONFIG_UART_##idx##_NRF_TX_PIN, \
516+
.pselrxd = CONFIG_UART_##idx##_NRF_RX_PIN, \
517+
UARTE_##idx##_NRF_HWFC_CONFIG \
518+
.parity = UARTE_##idx##_NRF_PARITY_BIT, \
519+
.baudrate = CONFIG_UART_##idx##_BAUD_RATE \
520+
}; \
521+
UARTE_##idx##_INTERRUPTS_INIT(); \
522+
return uarte_instance_init(dev, \
523+
&init_config, \
524+
UARTE_##idx##_INTERRUPT_DRIVEN); \
525+
} \
526+
DEVICE_AND_API_INIT(uart_nrfx_uarte##idx, \
527+
CONFIG_UART_##idx##_NAME, \
528+
uarte_##idx##_init, \
529+
&uarte_##idx##_data, \
530+
&uarte_##idx##_config, \
531+
PRE_KERNEL_1, \
532+
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
536533
&uart_nrfx_uarte_driver_api)
537534

538535
#define UARTE_NRF_HWFC_ENABLED(idx) \
@@ -549,7 +546,8 @@ static int uarte_instance_init(struct device *dev,
549546
CONFIG_UART_##idx##_IRQ_PRI, \
550547
uarte_nrfx_isr, \
551548
DEVICE_GET(uart_nrfx_uarte##idx), \
552-
0)
549+
0); \
550+
irq_enable(CONFIG_UART_##idx##_IRQ_NUM)
553551

554552
#define UARTE_TX_BUFFER_SIZE(idx) \
555553
CONFIG_UART_##idx##_NRF_TX_BUFFER_SIZE < \
@@ -626,3 +624,4 @@ static int uarte_instance_init(struct device *dev,
626624

627625
UART_NRF_UARTE_DEVICE(1);
628626
#endif /* CONFIG_UART_1_NRF_UARTE */
627+

0 commit comments

Comments
 (0)