I have a SAMD21J18A and RPI Pico 2020 ( RP2040 IC ) and I would like to read serial data which is sent through the controller ( SAMD21J18A ) through USB from RPI Pico by using Pico in USB Host Mode.
Since the peripheral is not a USB-HID device, I am not sure which library to start with.
Has anyone else tried to do so? Any hint will be appreciated. Thank you.
But the link that you've shared doesn't have anything related to poll data from CDC devices or it does but I am not understanding it. In the main.c file, how are we going to receive data, they have used tuh_cdc_receive() function but I am still not able to understand the code. Please let me know if you do.
I suggest running the example and examining the printf output to see the execution flow.
tuh_mount_cb() is called when a USB CDC is plugged in or detected on start up.
tuh_cdc_receive() schedules a USB transfer to receive data.
tuh_cdc_xfer_isr() is called when data is received. The data is printed with a call to printf(). It then calls tuh_cdc_receive() to schedule another transfer for more data.
Warning 1: Calling printf inside a function called from an Interrupt Service Routine is OK for demo and example code but is bad idea for production. Replace the printf without your own code to process the incoming data. Since interrupts are disabled inside in ISR context, slow code (such as printf) may result in dropping incoming data.
Warning 2: There is another good reason not to call printf except in demo code. There is no guarantee the data is null terminated ASCII. The buffer could contain 0-64 bytes of binary data. The xferred_bytes parameter should be the amount of valid data in the buffer.
I am debugging the code by blinking the default led and not by printing it. I am currently able to detect that a device is mounted but the blink function in the tuh_cdc_xfer_isr() doesn't execute meaning it's not able to receive the data.
I am currently taking serial data from Adruino Mega 2560 by: serial.print("MyData"); ( or serial.write(); )
by setting the baud rate to 115200 but still not able to receive it from pico.