This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF52840- USB-CDC-ACM Does not get APP_USBD_EVT_POWER_READY events after sd_power_system_off()

Hi there, 

My current setup: 

1. Custom board. 

2. SDK nRF5 SDK v17.0.2

3. Application running BLE (SoftDevice)

Using the USB CDC Class example to be able to interface my device with a PC via COM port. 

I am using the following configuration for the USB driver: 

// <i> Enable processing power events in USB event handler.

#ifndef APP_USBD_CONFIG_POWER_EVENTS_PROCESS
#define APP_USBD_CONFIG_POWER_EVENTS_PROCESS 1
#endif

// <e> APP_USBD_CONFIG_EVENT_QUEUE_ENABLE - Enable event queue.

// <i> This is the default configuration when all the events are placed into internal queue.
// <i> Disable it when an external queue is used like app_scheduler or if you wish to process all events inside interrupts.
// <i> Processing all events from the interrupt level adds requirement not to call any functions that modifies the USBD library state from the context higher than USB interrupt context.
// <i> Functions that modify USBD state are functions for sleep, wakeup, start, stop, enable, and disable.
//==========================================================
#ifndef APP_USBD_CONFIG_EVENT_QUEUE_ENABLE
#define APP_USBD_CONFIG_EVENT_QUEUE_ENABLE 0
#endif
// <o> APP_USBD_CONFIG_EVENT_QUEUE_SIZE - The size of the event queue.  <16-64> 


// <i> The size of the queue for the events that would be processed in the main loop.

#ifndef APP_USBD_CONFIG_EVENT_QUEUE_SIZE
#define APP_USBD_CONFIG_EVENT_QUEUE_SIZE 32
#endif

// <o> APP_USBD_CONFIG_SOF_HANDLING_MODE  - Change SOF events handling mode.
 

// <i> Normal queue   - SOF events are pushed normally into the event queue.
// <i> Compress queue - SOF events are counted and binded with other events or executed when the queue is empty.
// <i>                  This prevents the queue from filling up with SOF events.
// <i> Interrupt      - SOF events are processed in interrupt.
// <0=> Normal queue 
// <1=> Compress queue 
// <2=> Interrupt 

#ifndef APP_USBD_CONFIG_SOF_HANDLING_MODE
#define APP_USBD_CONFIG_SOF_HANDLING_MODE 2
#endif

The Issue: 

Once it  is programmed the USB device gets enumerated and recognized by the PC  and everything works fine, I get the following event, normal behavior: 

        case APP_USBD_EVT_POWER_READY:
            NRF_LOG_INFO("USB ready");
            app_usbd_start();
            break;

Once the device is sent to sleep as follows, I get the return value 0x2006 which seems expected as it describes -> NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN

//Set up button to wake up
nrf_gpio_cfg_sense_input(BUTTON_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);


err_code = sd_power_system_off();
  	
NRF_LOG_INFO("Return from sleep value -> 0x%x",err_code);
	
APP_ERROR_CHECK(err_code);

When the circuit is waken up I do not get any more the APP_USBD_EVT_POWER_READY, therefore the device does not get recognized by the PC unless the cable is unplugged and plugged back in. 

Is there anything that needs to be done before going to sleep to avoid this behavior ?

Is this an expected behavior for the driver ? 

Cheers, 

Parents Reply
  • Hi Kenneth, 

    Thanks for looking into this, In terms of the debugging, I am using RTT and it works like a charm. 

    I am able to replicate this behavior even if the RTT logging module is disable. 

    If the RTT module is disable, I suppose the chip is no longer in Debug mode.

    What would be the best way to find out whether or not the chip is in debug mode ?

     

    Cheers, 

Children
Related