mesh sensor observer sample on nrf52840 USB dongle

Hello,

I am developing a mesh solution when the nrf52840 USB dongle will act as an observer.

I am using the mesh sensor observer sample. I am able to build and flash it to the device. 

But I am unable to make the USB connection stable. 

I am adding this to the prj.conf (otherwise I am using the default prj.conf in the sample - and I am using SDK2.9)

CONFIG_GPIO=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="My USB Stick"
CONFIG_USB_DEVICE_MANUFACTURER="My company"
CONFIG_USB_DEVICE_SN="0001"
CONFIG_USB_CDC_ACM=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

CONFIG_CJSON_LIB=y

and needed to add this to main file in order for the usb stick to show up at all.

int main(void)
{

	usb_enable(NULL);

    printk("USB enabled\n");
		
	uint32_t start = k_uptime_get();

	while (k_uptime_get() - start < 20000) {  // 20 seconds = 20000 ms
		k_sleep(K_SECONDS(1));
		printk("Printing before enabling BLE! %d\n", k_uptime_get_32());
	}
	

	printk("Starting...\n");

	int err;

	printk("Initializing...\n");

	err = bt_enable(bt_ready);
	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
	}

	return 0;
}

The output (I use python to read out from the USB port - pyserial) is:

📡 Connected to COM17 at 115200 baud
🔹 *** Booting Mesh Sensor Observer v2.9.0-54e858a1d142 ***
🔹 *** Using nRF Connect SDK v2.9.0-7787b2649840 ***
🔹 *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
🔹 USB enabled
🔹
🔹 uart:~$ Printing before enabling BLE! 1003
🔹 Printing before enabling BLE! 2004
🔹 Printing before enabling BLE! 3004
🔹 Printing before enabling BLE! 4004
🔹 Printing before enabling BLE! 5005
🔹 Printing before enabling BLE! 6005
🔹 Printing before enabling BLE! 7005
🔹 Printing before enabling BLE! 8006
🔹 Printing before enabling BLE! 9006
🔹 Printing before enabling BLE! 10006
🔹 Printing before enabling BLE! 11007
🔹 Printing before enabling BLE! 12007
🔹 Printing before enabling BLE! 13007
🔹 Printing before enabling BLE! 14008
🔹 Printing before enabling BLE! 15008
🔹 Printing before enabling BLE! 16009
🔹 Printing before enabling BLE! 17009
🔹 Printing before enabling BLE! 18009
🔹 Printing before enabling BLE! 19010
🔹 Printing before enabling BLE! 20010
🔹 Starting...
⚠️ Serial error: ClearCommError failed (PermissionError(13, 'The device does not recognize the command.', None, 22))


So BLE conflicts with the USB - but how to fix this?

  • Hi,

     

    Since you are using usb for your logger, I assume that this line:

    ⚠️ Serial error: ClearCommError failed (PermissionError(13, 'The device does not recognize the command.', None, 22))

    Occurs due to an assertion (where the default behavior is a soft-reset). This then masks out the assertion log.

     

    My first guess would be a stack overflow, so try to adjust the CONFIG_MAIN_STACK_SIZE and see if the issue still occurs.

     

    Kind regards,

    Håkon

  • Hi Håkon.

    I increased the stack size several times - same issue.
    I guess the problem is that BLE somehow interfers with the UART console.
    It clear that it is doing a soft reset.

    It is not absolutely required to use the usb for the logger (although that would be nice). However, I do need to be able to communicate with the USB device.

    All suggestions are welcome.

  • Hi,

     

    Setup your project with CONFIG_RESET_ON_FATAL_ERROR=n and attach your debugger.

    It should then show a fault on the call stack.

     

    Look then at one of the frames in fault.c (z_arm_fault or fault_handle) and read out the *esf variable.

    Use the contents of this to check where the fault occurred via addr2line:

    addr2line -e build/my_project/zephyr/zephyr.elf 0xFAULTING_ADDR

    Use the LR and PC.

     

    The depth of the call stack can, in some cases, also show the faulting module/src.

     

    Kind regards,

    Håkon

  • Hello.


    hm. I connected my SEGGER J-link to the nrf52840 dongle.

    I take the plain sensor_client example, and I add this for the logger (nothing else)

    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y

    It crashes when the BLE is initialized.

    *** Booting Mesh Sensor Observer v2.9.1-31d0e132576e ***
    *** Using nRF Connect SDK v2.9.1-60d0d6c8d42d ***
    *** Using Zephyr OS v3.7.99-ca954a6216c9 ***
    Initializing...
    [00:00:00.010,620] <err> os: ***** BUS FAULT *****
    [00:00:00.010,620] <err> os:   Imprecise data bus error
    [00:00:00.010,650] <err> os: r0/a1:  0x000000c3  r1/a2:  0x00000000  r2/a3:  0x00000003
    [00:00:00.010,650] <err> os: r3/a4:  0x00000012 r12/ip:  0xaaaaaaaa r14/lr:  0x0001f349
    [00:00:00.010,681] <err> os:  xpsr:  0x81000000
    [00:00:00.010,681] <err> os: Faulting instruction address (r15/pc): 0x0001f2ea
    [00:00:00.010,711] <err> os: >>> ZEPHYR FATAL ERROR 26: Unknown error on CPU 0
    [00:00:00.010,772] <err> os: Current thread: 0x20003820 (shell_uart)
    [00:00:00.303,955] <err> fatal_error: Resetting system

    I then removed RTT configuration (basic sensor observer samble). I only added to turn on a led just to see if it stays on after ble starts.

    int main(void)
    {
    	gpio_pin_configure_dt(&led0, GPIO_OUTPUT_INACTIVE);
    	gpio_pin_set_dt(&led0, 1);
    	int err;
    
    	printk("Initializing...\n");
    	k_msleep(1000);
    
    	err = bt_enable(bt_ready);
    	if (err) {
    		printk("Bluetooth init failed (err %d)\n", err);
    	}
    
    	return 0;
    }

    But it does not. My conclusion is that hte Mesh Sensor Observer samble does not work on nrf52840 usb dongle with SDK 2.9.1

  • Hi,

     

    I took the stock mesh/sensor_client sample, compiled it for the nrf52840dongle/nrf52840, and got this output:

    --- 3 messages dropped ---
    *** Booting Mesh Sensor Observer v2.9.1-60d0d6c8d42d ***
    *** Using nRF Connect SDK v2.9.1-60d0d6c8d42d ***
    *** Using Zephyr OS v3.7.99-ca954a6216c9 ***
    Initializing...
    [00:00:00.010,253] <inf> fs_nvs: 8 Sectors of 4096 bytes
    [00:00:00.010,253] <inf> fs_nvs: alloc wra: 0, fe8
    [00:00:00.010,284] <inf> fs_nvs: data wra: 0, 0
    [00:00:00.010,681] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision: 
                                                79 a3 10 be e6 80 b7 e9  a3 ba cc a9 fc 08 66 12 |y....... ......f.
                                                90 cf 45 a9                                      |..E.             
    [00:00:00.014,282] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.014,343] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
    [00:00:00.014,373] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 121.4259 Build 3078678206
    [00:00:00.014,709] <inf> bt_hci_core: No ID address. App must call settings_load()
    Bluetooth initialized
    [00:00:00.277,740] <inf> bt_hci_core: Identity: FD:1C:5D:F7:F9:9A (random)
    [00:00:00.277,801] <inf> bt_hci_core: HCI: version 6.0 (0x0e) revision 0x109a, manufacturer 0x0059
    uart:~$ 
    

    I do not have a dongle readily available, so I had to configure "CONFIG_BOARD_HAS_NRF5_BOOTLOADER=n" and ran this on a nRF52840-DK.

     

    Added your suggested config, ie. appending these to prj.conf:

    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
     

    Then I get the RTT output:

    00> *** Booting Mesh Sensor Observer v2.9.1-60d0d6c8d42d ***
    00> *** Using nRF Connect SDK v2.9.1-60d0d6c8d42d ***
    00> *** Using Zephyr OS v3.7.99-ca954a6216c9 ***
    00> Initializing...
    00> [00:00:00.009,246] <inf> fs_nvs: 8 Sectors of 4096 bytes
    00> [00:00:00.009,277] <inf> fs_nvs: alloc wra: 0, fb8
    00> [00:00:00.009,277] <inf> fs_nvs: data wra: 0, 4c
    00> [00:00:00.009,643] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision: 
    00>                                             79 a3 10 be e6 80 b7 e9  a3 ba cc a9 fc 08 66 12 |y....... ......f.
    00>                                             90 cf 45 a9                                      |..E.             
    00> [00:00:00.013,275] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    00> [00:00:00.013,305] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
    00> [00:00:00.013,336] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 121.4259 Build 3078678206
    00> [00:00:00.013,702] <inf> bt_hci_core: No ID lized

     

    Have you tried removing your build folder and regenerating the build itself?

     

    Kind regards,

    Håkon

Related