Problem with Async UART Example from peripheral_uart

Trying to integrate the serial part of the example code for use with a custom nRF52840 board. The problem is that I'm getting an error in uart_callback_set(uart, uart_cb, NULL) that is causing "Cannot initialize UART callback" to be displayed. I'm using UART1 which works with a different interrupt version of this code. Not sure what I'm missing here to get the callback initialized.

int initUart() {
int err;
int pos;
struct uart_data_t *rx;
struct uart_data_t *tx;

   //fifoInit();
   uart = device_get_binding("UART_1");
	__ASSERT(uart, "Failed to get UART device");
	//interrupt_driven(uart);

	if (!uart) {
		return -ENXIO;
	}

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

	k_work_init_delayable(&uart_work, uart_work_handler);

	err = uart_callback_set(uart, uart_cb, NULL);
	if (err) {
		LOG_ERR("Cannot initialize UART callback");
		return err;
	}

CONFIG_STDOUT_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_NRF_SW_LPUART=n
CONFIG_NRF_SW_LPUART_INT_DRIVEN=y

# UART
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=n
CONFIG_UART_ASYNC_API=y
CONFIG_UART_0_ASYNC=y
CONFIG_UART_1_ASYNC=y
CONFIG_UART_0_NRF_HW_ASYNC=y
CONFIG_UART_1_NRF_HW_ASYNC=y
CONFIG_UART_0_NRF_HW_ASYNC_TIMER=1
CONFIG_UART_1_NRF_HW_ASYNC_TIMER=2
CONFIG_NRFX_UARTE=y
CONFIG_NRFX_UARTE0=y
CONFIG_NRFX_UARTE1=y
CONFIG_NRFX_TIMER=y
CONFIG_NRFX_TIMER1=y
CONFIG_NRFX_TIMER2=y
CONFIG_NRFX_PPI=y
CONFIG_NRFX_TIMER2=y

  • Here is the UART part of the device tree. Are there any issues here?

    &uart1 {
    	compatible = "nordic,nrf-uarte";
    	status = "okay";
    	current-speed = <115200>;
    	tx-pin = <20>;
    	rx-pin = <21>;
    	//pinctrl-0 = <&uart1_default>;
    	//pinctrl-1 = <&uart1_sleep>;
    	//pinctrl-names = "default", "sleep";
    	lpuart: nrf-sw-lpuart {
    		compatible = "nordic,nrf-sw-lpuart";
    		status = "okay";
    		label = "LPUART";
    		req-pin = <8>;
    		rdy-pin = <4>;
    	};
    	/delete-property/ rts-pin;
       	/delete-property/ cts-pin;
       	/delete-property/ hw-flow-control;
    };

  • Hello Paul, 

    NautDesigner said:
    Here is the UART part of the device tree. Are there any issues here?

    The first thing that catches my attention is that no register space is defined. 

    reg = < 0x40028000 0x1000 >;

    Otherwise, from NCS v2.0.0 it is recommended to use the pin control API, as described here.  

    Cheers, 

    Markus 

  • I would say, you should try this:

    • disabling interrupt driven api if you don't need it -> remove 'CONFIG_UART_INTERRUPT_DRIVEN=y'

      AND/OR

    • disabling interrupt driven api for UART1 -> CONFIG_UART_1_INTERRUPT_DRIVEN=n
      • I noticed that not disabling the interrupt driven api on a specific interface leads to using it per default., which does not correspond to the function that you are calling (uart_callback_set)
Related