nRF52840&Zephyr: Send the data from sensor readings over USB

Hello there!

We have different sensors connected to our custom nRF52840-based board running Zephyr OS. The goal is to transfer sensor readings to the PC by using a USB link. I found USB CDC ACM Sample Application to be a good starting point for our needs.

However, by diving deeper into the sample, I figured out that the sample is interrupt-driven. The only way to transfer data from our custom board to the PC would be through the interrupt_handler() function which is called at the moment some data are being sent from the PC to our custom board.

Is there any way we can modify the sample so that the USB transfer from our custom board to the PC is initialized at the moment we want (i.e. at the moment we collect readings from the sensors)? Should we modify the sample to use CONFIG_UART_ASYNC_API instead of CONFIG_UART_INTERRUPT_DRIVEN in that case?

Is there any USB-related Zephyr sample that will be a better starting point for us?

Thanks in advance for your time and efforts.

Sincerely,

Bojan.

  • Yes, you can easily modify that not to be interrupt driven and move the modified logic inside the interrupt_handler into another thread that waits on a flag/event/poll/Semaphore/mutex from one of the other contexts that signals that there is new sensor data. I do not necessarily see a need to change this to CONFIG_UART_ASYNC_API , but using CONFIG_UART_ASYNC_API  would be neater than using interrupt driven and ignoring the interrupt.

Related