I’m currently working on a project using the nRF5340 chip, specifically focusing on utilizing both UART0 and UART1 on the App core. I’ve encountered an interesting challenge while trying to get both UARTs operational simultaneously. Here’s what I’ve discovered and how I’m approaching the solution.
First, I’ll start by sharing my overlay file configuration. I’ve set up the pin controls for both UART0 and UART1, ensuring that they’re properly assigned to their respective pins. Here’s a snippet of my overlay file:
&pinctrl {
uart0_default: uart0_default {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 20)>, <NRF_PSEL(UART_RTS, 0, 19)>;
};
group2 {
psels = <NRF_PSEL(UART_RX, 0, 22)>, <NRF_PSEL(UART_CTS, 0, 21)>;
bias-pull-up;
};
};
uart1_default: uart1_default {
group1 {
psels = <NRF_PSEL(UART_TX, 1, 1)>;
};
group2 {
psels = <NRF_PSEL(UART_RX, 1, 0)>;
bias-pull-up;
};
};
uart0_sleep: uart0_sleep {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 20)>, <NRF_PSEL(UART_RX, 0, 22)>, <NRF_PSEL(UART_RTS, 0, 19)>, <NRF_PSEL(UART_CTS, 0, 21)>;
low-power-enable;
};
};
uart1_sleep: uart1_sleep {
group1 {
psels = <NRF_PSEL(UART_TX, 1, 1)>, <NRF_PSEL(UART_RX, 1, 0)>;
low-power-enable;
};
};
};
I’ve also configured the UART devices in my prj.conf file to ensure both UART0 and UART1 are enabled and set to the correct parameters. Here’s a relevant excerpt:
CONFIG_UART_NRFX=y
CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_1_ASYNC=y
CONFIG_UART_1_INTERRUPT_DRIVEN=n
CONFIG_NRFX_UARTE1=y
CONFIG_UART_MUX_DEVICE_NAME=“uart1”
The challenge I’m facing is that when I try to use both UARTs, I consistently receive the UART_RX_BUF_REQUEST event without any error codes. I’ve attempted to pass different buffers to handle the incoming data, but the issue persists. Here’s a snippet of my callback function:
static void uart_user_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
switch (evt->type) {
case UART_RX_RDY:
printk(“UART_RX_RDY event\n”);
break;
case UART_RX_BUF_REQUEST:
printk(“UART_RX_BUF_REQUEST event\n”);
int err = uart_rx_buf_rsp(uart_user, rx_buf2, sizeof(rx_buf2));
if (err) {
printk(“uart_rx_buf_rsp errored with code %d.\n”, err);
}
break;
default:
printk(“Unexpected UART event: %d\n”, evt->type);
break;
}
}
I’m curious if others have encountered similar issues when working with multiple UARTs on the nRF5340 or if there are specific configurations or workarounds that can resolve this problem. Any insights or suggestions would be greatly appreciated!
Cheers,
Marika