Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

nrf_delay_ms() is not available for usbd communication (usbd_cdc_acm)

Hello, World

Please note that the following questions may be difficult to read as the text was created using a translation tool.

I have downloaded version 17.0.2 of the nrf sdk and obtained the directory nRF5_SDK_17.0.2_d674dde. Then, open examples/peripheral/usbd_cdc_acm/pca10056/blank/ses/usbd_cdc_acm_pca10056.emProject in the directory with SEGGER Embedded Studio for ARM 5.10a The main.c was written to nordic's development kit nRF52840 DK. Then I connected it to a PC via USB and got usb output from the kit. When I wrote the main.c code as downloaded, I was able to confirm that pressing the button on the kit outputs a string as expected.

 I wanted to add a 100 ms delay after the usbd process, so I modified part of the program as follows. This modification adds a 100 ms delay by nrf_delay_ms(100) after the usbd process by while (app_usbd_event_queue_process()){}. I wrote this modified code and tried to run it, but communication by usb was not possible (I could not check the usb port with the ls command).

 Can I use some other function with delay, sleep, wait, etc., to do the behaviour I expect - a 100 ms delay after the usbd process? Incidentally, I have confirmed that if the delay time is less than 16 ms, it works as I expect.

Thanks!

while (true)

{

while (app_usbd_event_queue_process())

{

// Nothing to do

}

nrf_delay_ms(100); //Delay added

        

if(m_send_flag)

{

static int frame_counter;

size_t size = sprintf(m_tx_buffer, "Hello USB CDC FA demo: %u\r\n", frame_counter);

ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m _tx_buffer, size);

if (ret == NRF_SUCCESS)

{

++frame_counter;

}

}

Translated with DeepL.com (free version)

Parents Reply Children
  • Alright, let us figure out how to solve this with nRF5 SDK 17.0.1 then.

    First: Why do you need a 100ms delay after the usbd process?

  • The existing program controls a sensor. In the control of the sensor, nrf_delay_ms(100) is run every time when sensing (x need not be 100, x>30). I would like to control the sensor by communication (both way of sending and receiving) between PC and nRF52840 by usb.

    To do the control, I have applied usbd_cdc_acm to an existing program. However, I discovered that when nrf_delay_ms(x) is executed, PC is no longer recognized by nRF52840. From this result, I thought that the reason might be the existing program or the part I rewrote. However, the same problem occurred with the sample program's usbd_cdc_acm.

    Therefore, I am looking for a delay, sleep or wait instead of nrf_delay_ms(), or some other method.

  • Hello,

    The delay function you added doesn't explain why the USB is no longer enumerating on your PC. Does it also fail when you try loading the precompiled HEX file located in /examples/peripheral/usbd_cdc_acm/hex/usbd_cdc_acm_pca10056.hex?

    That said, if you want to perform a task every 100 ms, it would be much more efficient to create a periodic app timer instance that calls a timeout handler every 100 ms that you can perform your task in. You can use the ble_peripheral/ble_app_hrs example as a reference for how you can use the app timer.

    Best regards,

    Vidar

Related