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

Support serial over USB (CEC ADC) #161

Open
negz opened this issue Dec 11, 2023 · 3 comments
Open

Support serial over USB (CEC ADC) #161

negz opened this issue Dec 11, 2023 · 3 comments

Comments

@negz
Copy link

negz commented Dec 11, 2023

I'd like to have a log.zig logFn that I could use to emit debug logs over USB, rather than UART.

Currently Microzig has support for acting as a USB HID device. I believe emitting debug logs over USB would require support for acting as a "serial device", which uses USB CDC/ADC.

@negz
Copy link
Author

negz commented Dec 11, 2023

https://github.com/tinygo-org/tinygo/blob/731532cd2/src/machine/usb.go#L261

I'm attempting to take a shot at this, using TinyGo's implementation as a reference. In part because it seems more minimal than alternatives like TinyUSB. I believe TinyGo have implemented just enough of CEC to be a serial device, not support for modems etc. I'm also trying to use TinyGo as a reference because I'm fluent in Go, but not Zig, or microcontrollers, or USB. 😄

@rosshadden
Copy link

rosshadden commented Jan 31, 2024

Any luck with this? I read that picotool needs the firmware running on a microcontroller to implement USB-CDC in order for its load --force argument to work (letting you reboot picos outside of BOOTSEL mode). When using C you can set pico_enable_stdio_usb(<project-name> 1) in CMakeLists.txt to accomplish this.

Apparently this is because picotool uses PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE though I don't know enough of how this stuff works to provide any of my own insight.

@negz
Copy link
Author

negz commented Jan 31, 2024

Unfortunately I didn't get very far before my vacation ended.

I was finding it pretty hard to figure out how to cleanly extend the existing USB implementation. A lot of this is probably just because I don't know Zig, but I think it was exacerbated by the fact that the implementation isn't designed for extensibility.

My understanding based on ZigEmbeddedGroup/raspberrypi-rp2040#40 is that the USB implementation is a port of https://github.com/cbiffle/rp2040-usb-device-in-one-file/blob/4878f4/src/main.rs, which per its header comments is intended "for reference and study".

Here's what I ended up with. It's mostly just all the structs that I think are needed to make CDC work: 846e994e

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