NRF9160 DK failed to add another UART to BLE NUS example

Hello,

I am currently working on a project using the NRF9160DK and I am encountering an issue when trying to add another UART (UART3) to the BLE NUS example.

I have successfully managed to use the hci_lpuart for BLE communication and can run the BLE NUS sample. However, for my use case, I need to add UART3 to my project.

The problem arises when initializing UART3 and trying to assign a callback function for it. I receive the following error on RTT: <err> peripheral_uart: Cannot initialize UART callback.

Here is my overlay:

#include <nrf9160dk_nrf52840_reset_on_if5.dtsi>
/ {
	chosen {
		nordic,nus-uart = &uart0;
		zephyr,bt-uart=&lpuart;
	};

	compatible = "nordic,nrf9160-dk-nrf9160";
	model = "Nordic nRF9160 DK NRF9160";
};

&gpiote {
	interrupts = <49 NRF_DEFAULT_IRQ_PRIORITY>;
};

&uart2 {
	current-speed = <230400>;
	status = "okay";
	/delete-property/ hw-flow-control;

	pinctrl-0 = <&uart2_default_alt>;
	pinctrl-1 = <&uart2_sleep_alt>;
	pinctrl-names = "default", "sleep";
	lpuart: nrf-sw-lpuart {
		compatible = "nordic,nrf-sw-lpuart";
		status = "okay";
		req-pin = <21>; /* <&interface_to_nrf52840 3 0>; */
		rdy-pin = <19>; /* <&interface_to_nrf52840 2 0>; */
	};
};

uart3: &uart3 {
    status = "okay";
	reg = <0xb000 0x1000>;
	current-speed = <115200>;
	pinctrl-0 = <&uart3_default_alt>;
	pinctrl-1 = <&uart3_sleep_alt>;
	pinctrl-names = "default", "sleep";
};

&pinctrl {
	uart2_default_alt: uart2_default_alt {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 18)>,
				<NRF_PSEL(UART_RX, 0, 17)>;
		};
	};

	uart2_sleep_alt: uart2_sleep_alt {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 18)>,
				<NRF_PSEL(UART_RX, 0, 17)>;
			low-power-enable;
		};
	};
	uart3_default_alt: uart3_default_alt {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 25)>,
				<NRF_PSEL(UART_RX, 0, 24)>;
		};
	};

	uart3_sleep_alt: uart3_sleep_alt {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 25)>,
				<NRF_PSEL(UART_RX, 0, 24)>;
			low-power-enable;
		};
	};
};

And relevant code for uart3 initialization:

static const struct device *uart = DEVICE_DT_GET(DT_CHOSEN(nordic_nus_uart));
static const struct device *livecon_uart = DEVICE_DT_GET(DT_NODELABEL(uart3));

void uart_cb_2(const struct device *dev, struct uart_event *evt, void *user_data)
{
    switch (evt->type) {
    case UART_RX_RDY:
    
        break;
    case UART_RX_BUF_REQUEST:
        // printk("RX_BUF_REQUEST\n");

        break;
    case UART_RX_DISABLED:

        break;
    default:
        break;
    }
}
static int livecon_uart_init(void)
{
	int err;
	int pos;
	struct uart_data_t *rx;
	struct uart_data_t *tx;

	if (!device_is_ready(livecon_uart)) {
		return -ENODEV;
	}

	rx = k_malloc(sizeof(*rx));
	if (rx) {
		rx->len = 0;
	} else {
		return -ENOMEM;
	}

	err = uart_callback_set(livecon_uart, uart_cb_2, NULL);
	if (err) {
		k_free(rx);
		LOG_ERR("Cannot initialize UART callback");
		return err;
	}

	err = uart_rx_enable(livecon_uart, rx->data, sizeof(rx->data), 50);
	if (err) {
		LOG_ERR("Cannot enable uart reception (err: %d)", err);
		/* Free the rx buffer only because the tx buffer will be handled in the callback */
		k_free(rx);
	}

	return err;
}

Any guidance on how to resolve this issue would be greatly appreciated.

Thank you in advance for your help.

Best regards, Vincent

Parents Reply Children
No Data
Related