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 Håkon,


    I have removed all build folders. Then I did a fresh build and flashed nrf52DK - works 100%. Fresh build and flash nrf52840DK - works 100%. In both these cases the BLE starts up with no problem.

    however with nrf52840 USB dongle it crashes every time when BLE starts. This is consistent for all use of BLE on this HW. 

    From what I understand there are 3 possible issues
    1) My build configuration is wrong:
    - I am using "nRF52840 Dongle nRF52840" as my target - correct?
    2) I am flashing it incorrectly:
    - I am doing this "nrfutil nrf5sdk-tools pkg generate --hw-version 52 --sd-req=0x00 --application .\merged.hex --application-version 1 mesh_provisioner.zip;nrfutil device program --firmware mesh_provisioner.zip --traits nordicDfu"     Seems to flash fine
    3) The ble soft device of the nrf52840 USB dongle has issues or is not compatible with SDK 2.9
    - here I do not know what to do

    It would be great if you could try to flash the nrf52840 USB dongle and see if it works on your side. 

    Bjorn

  • Hello Bjorn,

    Håkon is currently out of office.

    bjornolsen said:
    - I am using "nRF52840 Dongle nRF52840" as my target - correct?

    I assume you mean "nrf52840dongle/nrf52840" as your build target, right?

    bjornolsen said:
    2) I am flashing it incorrectly:

    Can you try flashing it with nRF Connect for Desktop -> Programmer, just to see if it makes any difference? Then you can just use the .hex file.

    bjornolsen said:
    3) The ble soft device of the nrf52840 USB dongle has issues or is not compatible with SDK 2.9

    I don't think that is the issue.

    The challenge when developing directly on the dongle is that you don't have a debugger. This also indirectly means no reliable logger. As you can see, whenever the application crashes, the USB will stop working, and you are not able to transmit the log to your terminal. 

    Do you have access to a DK? If so, I highly recommend that you try to run this application on that one, and then later port the application to your dongle. This will probably save you a lot of time. 

    Best regards,

    Edvin

  • Hello,

    Thank you for your reply. But as you can see from the correspondance I have already tried all of this.
    I am able to build and run all sorts of applications on nrf52DK, nrf52840DK and nrf54L15.

    I can also run programs on nrf52840dongle/nrf52840 - BUT. I am completly unable to run anything that activates BLE on the dongle -> it crashes (as you see above). I have done what I can do debug - including using a J-Link to follow what is happening (see above).

    Can you please try to replicate this (just flash any ble sample onto the nrf52840dongle)?

    I would be very grateful if you could help solve this mystery.

    Bjorn

  • bjornolsen said:
    including using a J-Link to follow what is happening

    Did you erase the pre-programmed bootloader on the dongle? Or how did you flash the firmware that you are debugging?

    BR,
    Edvin

  • Hello.

    To be honest, I am not sure if I erase(d) the pre-programmed bootloader.
    All I do is to build a HEX file and the load it the the USB dongle. I do this using nrfutil and also using the programming tool. 

    For simple programs (that do NOT include BLE), the dongle works 100% fine. The issue is when I enable BLE (or try to run a BLE sample out of the box) this causes the dongle to crash.

    *** 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

    (log when I added my J-LINK)

    Yes I may need a "correct" bootloader if that is the issue, but how?

    Bjorn

Related