Hi,
I would like to create a UART on the nRF54L15 DK, but currently it seems that only the pins bound to CONFIG_UART_CONSOLE (P1.04 / P1.05) are working as below Output.
I am unable to assign other TXD/RXD pins, for example (P2.00 / P2.01) or (P2.02 / P2.00) .
Could you please advise on how to properly configure alternative UART pins on this platform?
nrf54l15dk_nrf54l15_cpuapp.overlay
&pinctrl {
uart20_default: uart20_default {
group1 {
psels = <NRF_PSEL(UART_TX, 2, 0)>,
<NRF_PSEL(UART_RX, 2, 1)>;
};
};
};
&uart20 {
status = "okay";
current-speed = <115200>;
};
prj.conf
CONFIG_SERIAL=y CONFIG_UART_NRFX=y CONFIG_UART_ASYNC_API=y CONFIG_GPIO=y CONFIG_MAIN_STACK_SIZE=2048 CONFIG_LOG=n CONFIG_USE_SEGGER_RTT=n CONFIG_UART_CONSOLE=y CONFIG_SHELL=n
main.c
#include <zephyr/kernel.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/device.h>
#include <string.h>
#include <stdio.h>
#define RX_TIMEOUT_US 20000
#define LINE_MAX 128
static const struct device *uart;
static char line[LINE_MAX];
static size_t linelen;
static uint8_t rxbuf1[64];
static uint8_t rxbuf2[64];
static bool buf2_in_use;
static void on_evt(const struct device *dev, struct uart_event *evt, void *ud)
{
ARG_UNUSED(dev); ARG_UNUSED(ud);
switch (evt->type) {
case UART_RX_RDY: {
const struct uart_event_rx *rx = &evt->data.rx;
for (size_t i = rx->offset; i < rx->offset + rx->len; ++i) {
char c = rx->buf[i];
if (c == '\r' || c == '\n') {
if (linelen > 0) {
line[linelen] = 0;
printk("Received: %s\n", line);
linelen = 0;
}
} else if (linelen + 1 < sizeof(line)) {
line[linelen++] = c;
} else {
linelen = 0;
}
}
break;
}
case UART_RX_BUF_REQUEST:
if (!buf2_in_use) {
uart_rx_buf_rsp(uart, rxbuf2, sizeof(rxbuf2));
buf2_in_use = true;
}
break;
case UART_RX_BUF_RELEASED:
if (evt->data.rx_buf.buf == rxbuf2) buf2_in_use = false;
break;
case UART_RX_DISABLED:
uart_rx_enable(uart, rxbuf1, sizeof(rxbuf1), RX_TIMEOUT_US);
break;
default:
break;
}
}
int main(void)
{
uart = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
if (!device_is_ready(uart)) {
return 0;
}
printk("Hello World!\n");
/* Async */
uart_callback_set(uart, on_evt, NULL); //uart20
uart_rx_enable(uart, rxbuf1, sizeof(rxbuf1), RX_TIMEOUT_US);
while (1) {
k_sleep(K_SECONDS(1));
}
}
Output:
*** Booting nRF Connect SDK v3.1.0-6c6e5b32496e ***
*** Using Zephyr OS v4.1.99-1612683d4010 ***
Hello World!
Received: 123456
thanks.