Trying to Implement central_uart on a nrf52840 dongle

Hello! I am a newcomer to nrf and embedded programming (other than basic arduino and micropython projects). So far I have gone through many of the devacademy walkthroughs. What I want to do is simply implement central_uart and peripheral_uart on two nrf52840 dongles so I can use NUS to send messages back and forth between them. I already have my peripheral send messages to my phone's nrf connect app and this works well, however it is very basic (I wrote it myself with peripheral_nus example) so I want to transition to peripheral_uart. My first step was to get central_uart and/or peripheral_uart working on my dongles. I started with central_uart. However, when flashing it onto my device and looking at the log through the serial port I run into "<err> central_uart: uart_init failed (err -88). After adding some debugging messages into the uart_init function I find that the -88 error is coming from the "uart_callback_set" command. I am not sure how to remedy this, or if additional work needs to be done from the stock central_uart before I flash it onto my nrf 52840 dongle.

Other than debug messages and enabling them I have not edited the code from the stock.

Thoughts? Advice?

Parents
  • Hello,

    Please note that the nRF Connect SDK samples will not work with the dongle out of the box, as the dongle is programmed with the nRF5 SDK bootloader. You will need to modify your application to ensure compatibility with the dongle. For guidance, refer to this thread and review the dongle programming tutorial. Although the tutorial is based on our previous SDK, it contains relevant information that can help you.

    Kind Regards,

    Abhijith

  • I am able to make literally all other examples work though, just not the central uart or peripheral uart. For those examples I get the -88 error from the uart_cb initialization (uart_callback_set). The dongle programming tutorial mentioned that all I need to do is change the board type to nrf52840dongle_nrf52840 when using the nrd connect SDK which I am using through vs code. All other examples work just fine (they compile, create a .hex file), I can flash the .hex file to the dongle and then the programs run just fine- all expect the central_uart and peripheral_uart.

    This is the serial output from the dongle running the central_uart. I added some debugging messages to try and pinpoint the error. I found that the -88 error is coming from the uart_callback_set(uart, uart_cb, NULL) function. Other than the debug messages I haven't changed. Again, this code is almost exactly from the nrd connect sdk central_uart sample.

    *** Booting nRF Connect SDK 3758bcbfa5cd ***
    [00:00:00.008,209] <inf> fs_nvs: 4 Sectors of 4096 bytes
    [00:00:00.008,239] <inf> fs_nvs: alloc wra: 0, fd0
    [00:00:00.008,239] <inf> fs_nvs: data wra: 0, 1c
    [00:00:00.008,422] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision: 
                                                36 f0 e5 0e 87 68 48 fb  02 fd 9f 82 cc 32 e5 7b |6....hH. .....2.{
                                                91 b1 5c ed                                      |..\.             
    [00:00:00.011,840] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.011,871] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
    [00:00:00.011,901] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 54.58864 Build 1214809870
    [00:00:00.012,512] <inf> bt_hci_core: No ID address. App must call settings_load()
    [00:00:00.012,512] <inf> central_uart: Bluetooth initialized
    [00:00:00.013,214] <inf> bt_hci_core: Identity: DF:E7:9E:9D:A8:C2 (random)
    [00:00:00.013,244] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x118f, manufacturer 0x0059
    [00:00:00.013,275] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x118f
    [00:00:00.014,404] <inf> central_uart: Settings Loaded
    [00:00:00.014,434] <dbg> central_uart: uart_init: Initializing UART
    [00:00:00.014,465] <dbg> central_uart: uart_init: UART device is ready
    [00:00:00.014,465] <dbg> central_uart: uart_init: rx len is 0
    [00:00:00.014,495] <dbg> central_uart: uart_init: Setting uart_callback
    [00:00:00.014,526] <dbg> central_uart: uart_init: was callback set?: -88
    [00:00:00.014,526] <err> central_uart: uart_init failed (err -88)

    This is my .overlay file:

    &pinctrl {
    	uart0_default: uart0_default {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 1, 2)>,
    					<NRF_PSEL(UART_RX, 1, 1)>;
    		};
    	};
    };
    
    &uart0 {
    	compatible = "nordic,nrf-uarte";
    	status = "okay";
    	current-speed = <115200>;
    	pinctrl-0 = <&uart0_default>;
    	pinctrl-1 = <&uart0_sleep>;
    	pinctrl-names = "default", "sleep";
    };

    This is my config file:

    # Enable the UART driver
    CONFIG_UART_ASYNC_API=y
    CONFIG_NRFX_UARTE0=y
    CONFIG_SERIAL=y
    CONFIG_CONSOLE=y
    CONFIG_UART_CONSOLE=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    #CONFIG_UART_0_ASYNC=y
    
    # Enable the BLE stack with GATT Client configuration
    CONFIG_BT=y
    CONFIG_BT_CENTRAL=y
    CONFIG_BT_SMP=y
    CONFIG_BT_GATT_CLIENT=y
    
    # Enable the BLE modules from NCS
    CONFIG_BT_NUS_CLIENT=y
    CONFIG_BT_SCAN=y
    CONFIG_BT_SCAN_FILTER_ENABLE=y
    CONFIG_BT_SCAN_UUID_CNT=1
    CONFIG_BT_GATT_DM=y
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    # This example requires more stack
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    CONFIG_MAIN_STACK_SIZE=2048
    
    # Enable bonding
    CONFIG_BT_SETTINGS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    
    # Config logger
    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=y
    CONFIG_LOG_PRINTK=y
    CONFIG_LOG_MAX_LEVEL=4
    CONFIG_LOG_BUFFER_SIZE=10000
    
    CONFIG_ASSERT=y

    And this is the relevant code where the error is coming from 

    static int uart_init(void)
    {
    	int err;
    	struct uart_data_t *rx;
    	LOG_DBG("Initializing UART");
    
    	if (!device_is_ready(uart)) {
    		LOG_ERR("UART device not ready");
    		return -ENODEV;
    	}
    
    	LOG_DBG("UART device is ready");
    
    	rx = k_malloc(sizeof(*rx));
    
    	if (rx) {
    		rx->len = 0;
    		LOG_DBG("rx len is 0");
    	} else {
    		return -ENOMEM;
    		LOG_DBG("rx len not 0");
    	}
    
    	k_work_init_delayable(&uart_work, uart_work_handler);
    
    	LOG_DBG("Setting uart_callback");
    
    	err = uart_callback_set(uart, uart_cb, NULL);
    	if (err) {
    		LOG_DBG("was callback set?: %d", err);
    		return err;
    		LOG_DBG("uart_callback_set error");
    	} else {
    		LOG_DBG("uart_callback is set");
    	}
    
    	err = uart_rx_enable(uart, rx->data, sizeof(rx->data),
    			      UART_RX_TIMEOUT);
    
    	if (err == 0) {
    		LOG_DBG("UART RX enabled successfully");
    	} else {
    		LOG_ERR("FAILED to enable UART RX (err %d)", err);
    	}
    	return err;
    
    }

Reply
  • I am able to make literally all other examples work though, just not the central uart or peripheral uart. For those examples I get the -88 error from the uart_cb initialization (uart_callback_set). The dongle programming tutorial mentioned that all I need to do is change the board type to nrf52840dongle_nrf52840 when using the nrd connect SDK which I am using through vs code. All other examples work just fine (they compile, create a .hex file), I can flash the .hex file to the dongle and then the programs run just fine- all expect the central_uart and peripheral_uart.

    This is the serial output from the dongle running the central_uart. I added some debugging messages to try and pinpoint the error. I found that the -88 error is coming from the uart_callback_set(uart, uart_cb, NULL) function. Other than the debug messages I haven't changed. Again, this code is almost exactly from the nrd connect sdk central_uart sample.

    *** Booting nRF Connect SDK 3758bcbfa5cd ***
    [00:00:00.008,209] <inf> fs_nvs: 4 Sectors of 4096 bytes
    [00:00:00.008,239] <inf> fs_nvs: alloc wra: 0, fd0
    [00:00:00.008,239] <inf> fs_nvs: data wra: 0, 1c
    [00:00:00.008,422] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision: 
                                                36 f0 e5 0e 87 68 48 fb  02 fd 9f 82 cc 32 e5 7b |6....hH. .....2.{
                                                91 b1 5c ed                                      |..\.             
    [00:00:00.011,840] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.011,871] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
    [00:00:00.011,901] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 54.58864 Build 1214809870
    [00:00:00.012,512] <inf> bt_hci_core: No ID address. App must call settings_load()
    [00:00:00.012,512] <inf> central_uart: Bluetooth initialized
    [00:00:00.013,214] <inf> bt_hci_core: Identity: DF:E7:9E:9D:A8:C2 (random)
    [00:00:00.013,244] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x118f, manufacturer 0x0059
    [00:00:00.013,275] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x118f
    [00:00:00.014,404] <inf> central_uart: Settings Loaded
    [00:00:00.014,434] <dbg> central_uart: uart_init: Initializing UART
    [00:00:00.014,465] <dbg> central_uart: uart_init: UART device is ready
    [00:00:00.014,465] <dbg> central_uart: uart_init: rx len is 0
    [00:00:00.014,495] <dbg> central_uart: uart_init: Setting uart_callback
    [00:00:00.014,526] <dbg> central_uart: uart_init: was callback set?: -88
    [00:00:00.014,526] <err> central_uart: uart_init failed (err -88)

    This is my .overlay file:

    &pinctrl {
    	uart0_default: uart0_default {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 1, 2)>,
    					<NRF_PSEL(UART_RX, 1, 1)>;
    		};
    	};
    };
    
    &uart0 {
    	compatible = "nordic,nrf-uarte";
    	status = "okay";
    	current-speed = <115200>;
    	pinctrl-0 = <&uart0_default>;
    	pinctrl-1 = <&uart0_sleep>;
    	pinctrl-names = "default", "sleep";
    };

    This is my config file:

    # Enable the UART driver
    CONFIG_UART_ASYNC_API=y
    CONFIG_NRFX_UARTE0=y
    CONFIG_SERIAL=y
    CONFIG_CONSOLE=y
    CONFIG_UART_CONSOLE=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    #CONFIG_UART_0_ASYNC=y
    
    # Enable the BLE stack with GATT Client configuration
    CONFIG_BT=y
    CONFIG_BT_CENTRAL=y
    CONFIG_BT_SMP=y
    CONFIG_BT_GATT_CLIENT=y
    
    # Enable the BLE modules from NCS
    CONFIG_BT_NUS_CLIENT=y
    CONFIG_BT_SCAN=y
    CONFIG_BT_SCAN_FILTER_ENABLE=y
    CONFIG_BT_SCAN_UUID_CNT=1
    CONFIG_BT_GATT_DM=y
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    # This example requires more stack
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    CONFIG_MAIN_STACK_SIZE=2048
    
    # Enable bonding
    CONFIG_BT_SETTINGS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    
    # Config logger
    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=y
    CONFIG_LOG_PRINTK=y
    CONFIG_LOG_MAX_LEVEL=4
    CONFIG_LOG_BUFFER_SIZE=10000
    
    CONFIG_ASSERT=y

    And this is the relevant code where the error is coming from 

    static int uart_init(void)
    {
    	int err;
    	struct uart_data_t *rx;
    	LOG_DBG("Initializing UART");
    
    	if (!device_is_ready(uart)) {
    		LOG_ERR("UART device not ready");
    		return -ENODEV;
    	}
    
    	LOG_DBG("UART device is ready");
    
    	rx = k_malloc(sizeof(*rx));
    
    	if (rx) {
    		rx->len = 0;
    		LOG_DBG("rx len is 0");
    	} else {
    		return -ENOMEM;
    		LOG_DBG("rx len not 0");
    	}
    
    	k_work_init_delayable(&uart_work, uart_work_handler);
    
    	LOG_DBG("Setting uart_callback");
    
    	err = uart_callback_set(uart, uart_cb, NULL);
    	if (err) {
    		LOG_DBG("was callback set?: %d", err);
    		return err;
    		LOG_DBG("uart_callback_set error");
    	} else {
    		LOG_DBG("uart_callback is set");
    	}
    
    	err = uart_rx_enable(uart, rx->data, sizeof(rx->data),
    			      UART_RX_TIMEOUT);
    
    	if (err == 0) {
    		LOG_DBG("UART RX enabled successfully");
    	} else {
    		LOG_ERR("FAILED to enable UART RX (err %d)", err);
    	}
    	return err;
    
    }

Children
No Data
Related