Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] How to debug and enable a new CDC device? #6

Open
shreeve opened this issue Dec 20, 2023 · 5 comments
Open

[QUESTION] How to debug and enable a new CDC device? #6

shreeve opened this issue Dec 20, 2023 · 5 comments

Comments

@shreeve
Copy link

shreeve commented Dec 20, 2023

Summary

I have a CDC device that uses the very common FTDI-232 serial-to-USB chip. Part of the device descriptor shows:

*** Device descriptor ***

  bLength         18
  bDescriptorType 1
  bcdUSB          2.00
  bDeviceClass    0x00  <== this is a 0x00, ugh
  bDeviceSubClass 0x00  <== this is a 0x00, ugh
  bDeviceProtocol 0x00
  bMaxPacketSize0 8
  idVendor        0x0403  <== this is "FTDI" (the vendor)
  idProduct       0xcd18  <== this is "Abaxis Piccolo xpress" (the product)

Notice that the Class and SubClass are listed here both as 0x00, instead of what they should be for a normal CDC device. As a result, when the USB Host tries to enumerate this device, it's not quite sure what to do, so I think it just skips it. I would like for the USB Host to consider this device to be a CDC class device (which I think it is actually), even though it doesn't claim to be here. This capability was recently added to TinyUSB. Basically, I think TinyUSB is aware of this type of device and considers it to be a CDC class.

In addition, there are some USB control commands that need to be sent to the device to set it up properly. These are sent as a USB control transfer with the following:

# these are sent as: bmRequestType, bRequest, and wValue
cmd(0x40,  0,  0)      # resets device, purges RX/TX, clears DTR/RTS, data is 8N1, leaves baud
cmd(0x40,  1, 0x0303)  # enables DTR/RTS
cmd(0x40,  3, 0x4138)  # sets 9600 baud (3MHz/312.5)

Question

First, when trying to debug this, it would be nice to be able to do a little "printf() debugging". I am using the PicoPad/USB/USBUART example (appropriately adjusted for just the Pico). I've configured it so that I can upload code and connect to the Pico through the UART, while being able to use the on-board physical microUSB port to connect to the Piccolo (CDC device). From the main code, I can use Print("I'm here...\n"); statements, but I can't use them from sdk_usb_host.c, where I'm trying to debug to try to get this working for me. So my first question is, how can I use a Print() style message from withing sdk_usb_host.c to help me debug this?

Second, is there a way to send an arbitrary USB control transfer to the device to reset it and configure it's flow control, data bits, and baud as shown above? I think each of those cmd() calls (that code is actually in Ruby) just generate an 8-byte USB control packet that configures the device. My second question is, how can I send these packets to configure the device?

Thanks!

@Panda381
Copy link
Owner

I'm sorry, but I don't think that's gonna work. PicoLibSDK only handles basic USB functions. The modification for FTDI is quite extensive, it is not yet implementable in the library. Even CDC control packets are not supported in the library. Print to UART port (not via USB) is possible by enabling the USE_UART_STDIO switch in config.h.

@shreeve
Copy link
Author

shreeve commented Dec 20, 2023

Ok, thank you. I think it's still possible... I'll work on it now. Thank you, this code looks great @Panda381 !!

@shreeve
Copy link
Author

shreeve commented Dec 20, 2023

I was able to do some printf() style debugging from by adding:

#include "../inc/sdk_uart.h"

to sdk_usb_host.c and then using UartPrint("Testing\n"); to output to the UART and back to my laptop.

I'll work on the FTDI type of stuff now that I can debug this.

Thanks for you quick responses! :-)

@shreeve
Copy link
Author

shreeve commented Dec 20, 2023

This is where I'm comparing between TinyUSB and PicoLibSDK. I think that we should be able to add support for FTDI (and CP210X) using the same method and still be able to use everything else from the existing CDC driver:

tinyusb

@shreeve
Copy link
Author

shreeve commented Dec 21, 2023

See PR #7 for review (not really intended to merge). I think it's pretty close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants