Recently, I am learning the ODrive Firmware source code.
I am confused about the function usb_rx_process_packet().

void usb_rx_process_packet(uint8_t *buf, uint32_t len, uint8_t endpoint_pair) {
    if (endpoint_pair == CDC_OUT_EP && usb_cdc_rx_stream.rx_end_) {
        usb_cdc_rx_stream.rx_end_ += len;
        osMessagePut(usb_event_queue, 5, 0);
    } else if (endpoint_pair == ODRIVE_OUT_EP && usb_native_rx_stream.rx_end_) {
        usb_native_rx_stream.rx_end_ += len;
        osMessagePut(usb_event_queue, 6, 0);

In this function, there are only two osMessagePut(usb_event_queue, 6, 0) and I did not find the code to process the incoming data in buf.
In the usb task, I also did not find the related code.
Can anyone help me?
Thank you!

I now figure out the USB receiving process.

In USB connected event the fibre_over_usb.start({}) call the LegacyProtocolPacketBased::start().
In the start() function, we can see the code rx_channel_->start_read(rx_buf_, &dummy, MEMBER_CB(this, on_read_finished));.
rx_channel_ is initialized to the pointer of usb_native_rx_stream.
Stm32UsbRxStream::start_read() sets the callback function to on_read_finished().
Once the USB receives the data, CDC_Receive_FS() adds the message to the usb_event_queue.
Then, did_finish() invokes the callback function.

1 Like