I am using SDK 15.0 with the Nordic NRF52840 development board. I wrote my own custom bootloader using CDC ACM as the transport. I am using app_usbd_cdc_acm_read_any to read the data read from the USB. The client on the other side is sending data to the bootloader. I noticed that I need to put nrf_delay_ms(20) for my bootloader to work properly. If I don't put delay of some time, then after a while I stop getting data from USBD. I just want to check if my usage is ok and why do I need to add delay of 20 ms? One more thing, that if I am running the bootloader using debugger in Keil then it works fine without the delay of 20ms. But when I run without the debugger , then it stops working and delay of 20ms is making it work for now.
case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
{
ret_code_t ret;
do
{
size_t size = app_usbd_cdc_acm_rx_size(&m_app_cdc_acm);
//processing the data
nrf_delay_ms(20);
ret = app_usbd_cdc_acm_read_any(&m_app_cdc_acm,
m_rx_buffer,
sizeof(m_rx_buffer));
}while(ret == NRF_SUCCESS);
} break;