usb_cdc_acm: Ring buffer full, using uart_fifo_fill(), SAADC sample USB transmission

Hello,

in use is the nrf connect sdk v2.6.2 toolchain v2.6.2 on my nrf5340DK

I struggle transmitting ADC data from my nrf5340DK via USB to my windows PC. On my PC there is some .py chart script or windows form app WFA. These two programs are tested with some older project on an esp8266. On this esp MCU I simple

void task_printOutFast(void) {
    if (nonBlockingBoolean_1) {
        nonBlockingBoolean_1 = false;
        Serial.printf("%.2f\n", current_mA_prim); //current_mA_prim =
    }
}

every 2-5 ms, and the response on my PC visualisation is kinda real time.
Unfortunately I dont accomplish this with the nrf MCU Disappointed

So any help is very much appreciated Slight smile

On my nrf MCU the SAADC software and hardware events are well evaluated through gpio toggle and oszi measurement. Althoug I couldnt slow down the advanced non-blocking internal timer , the internal timer I did some workaround and only used every 32th sample to evaluate with slower speed. Anyway, the 

#define BUFFER_SIZE 512UL
and the sampling rate is 125us, so the buffer is full everys 64ms, which i can confirm on my oszi. 
To handle the USB data transmission I looked for the USB CDC ACM example  and created some workqueue. The handler function from the workque looks like

void test_work_handler(struct k_work *work) {

    struct usb_work_item *item = CONTAINER_OF(work, struct usb_work_item, work);

    static char bulk_buffer[8192]; // Large enough for multiple samples
    int bulk_index = 0;

    // Serialize all ADC data into the bulk buffer
    for (uint16_t i = 0; i < item->size; i++) {
        bulk_index += snprintf(&bulk_buffer[bulk_index], sizeof(bulk_buffer) - bulk_index, "%u\n", item->data[i]);
        if (bulk_index >= sizeof(bulk_buffer) - 8) {
            // Ensure we don't overflow the buffer
            break;
        }
    }

    // Send the bulk buffer via UART
    uart_fifo_fill(dev, bulk_buffer, bulk_index);

    // Toggle GPIO to indicate completion
    nrfx_gpiote_out_task_trigger(&gpiote_inst, GPIO_TO_TOGGLE);
}

The gpio toggle (different gpio in use) also has 64ms, despite that after some time (30sec) I get

[00:22:44.568,511] <wrn> usb_cdc_acm: Ring buffer full, drop 64 bytes

data is received on my windows PC but response, when i turn the poti gets more and more latency. I changed
#larger ring buffer
CONFIG_USB_CDC_ACM_RINGBUF_SIZE=8192
Can someome explain whats wrong when using 

    // Send the bulk buffer via UART
    uart_fifo_fill(dev, bulk_buffer, bulk_index);

or explain why its so strait forward when using cheap esp MCU compared to great nrf device?
Thank you in advance,
Christoph Slight smile



Parents Reply Children
No Data
Related