nrf5340: USBD disabling itself on USBD_DETACHED event

While developing on the nRF5340, I noticed that the USB CDC ACM driver I had been using as the Zephyr console, shell, and log backend didn't seem to want to re-enumerate when the USB port was unplugged and then plugged back in.

To test this behavior, I have compiled the zephyr/samples/subsys/usb/cdc_acm example for the nrf5340dk_nrf5340_cpuapp_ns board and fully erased and flashed it on my nRF5340-DK. 

The USB device port does enumerate and work properly the first time it is plugged in. I get a virtual COM port and can open a terminal emulator and the USB console echoes each character I type. If I unplug the USB device port, wait a few seconds, and plug it back in, the device does not enumerate, and the previous virtual COM port is not present.

I've included the hex file usbd_not_reconnecting.hex which is based on NCS 2.3.0 and compiled for the nrf5340dk_nrf5340_cpuapp_ns.

usbd_not_reconnecting.hex

In an effort to try to discover the root cause, I noticed that nrfx_usbd_disable() is called in zephyr/drivers/usb/device/usb_dc_nrfx.c when handling the USBD_DETACHED usbd_pwr_event. As an experiment, I tried commenting out the call to nrfx_usbd_disable() in that handler, and this appears to completely fix the problem.

	case USBD_DETACHED:
		ctx->ready = false;
		//nrfx_usbd_disable();
		err = hfxo_stop(ctx);
		__ASSERT_NO_MSG(err >= 0);

		LOG_DBG("USB Removed");

		if (ctx->status_cb) {
			ctx->status_cb(USB_DC_DISCONNECTED, NULL);
		}
		break;

Please advise how we should move forward with this workaround. I can implement this workaround in a private fork of the sdk-zephyr repository, but this bug will affect anybody using the usbd_nrfx driver, so it might be worth fixing in the next NCS release.

Thanks!

Parents Reply Children
  • It looks like this issue is unfortunatly making slow progress internally.

    I can find from your intial description of the case that you have found a workaround where you simply don't disable USB, are you able to use this workaround in your application? Instead of waiting for the team internally find the root cause of the issue.

    Kenneth

  • Sorry I'm not the original poster of the issue, I just also ran into it using a different example as a starting point and reported that here instead of creating a new issue for the same problem. 

    The original poster reported that the workaround does not work if the application is built using the non-secure compilation target, which is unfortunately what I'm using. I'm working on other parts of my project at the moment so I can wait a bit longer, I'll consider switching to the other target when I have to get back to working on this part of the project. 

  • No, we are not using this workaround in our application. This workaround was put in simply to identify the function causing the SPU error as part of the debugging process.

    This workaround isn't going to be suitable our application because we must disable USB when unplugged to save on power consumption.

  • Hello,

    Sorry for the time this is taking, before the developers can start to look into making a workaround they need to ensure the designers understand the root cause (it's only then they can be sure that any workaround will handle the issue). The issue have been recreated on actual boards, and next step is to recreate the issue by simulation (to find the root cause), simulation is a time consuming task both to setup but not least running the actual test in simulation (the entire chip is simulated so they need to simplify the software to for instance avoid any busy waits etc to reduce the simulation time). I expect simulations will be finished sometime next week, and I will update you when I learn more.

    Kenneth

  • Hello again,

    I can confirm they have been able to recreate the issue in simulation, so they understand more of what exactly is causing the issue, they are now looking into finding the least intrusive workaround. This will take some time, since workaround needs to be confirmed by actual test on the board but also simulations. I will update you when I know more.

    Kenneth

Related