Skip to content

Get the VCP working #22

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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

jonathanherbstgrapple
Copy link
Contributor

Here's an implementation of the hardware serial port that keeps all the features that use the usb serial port working with it.

The implementation uses an intermediate buffer for transmitting, but uses only the buffer internal to the usb serial software for receiving. When data is received on the usb side the usb interrupt is triggered and it writes data to the intermediate transmit buffer before writing it to the hardware transmit fifo in the uart peripheral. When data is received on the uart side the uart interrupt is triggered and reads all data from the hardware transmit buffer and writes it to the usb serial buffer to be transmitted over usb.

Transmitting data from the usb side to the uart side can get a little funky. When my host tries to write more data than the combined transmit buffers on the device it rails the usb until all it's data gets buffered on the device. When it's finished buffering everything, the usb interrupts stop so the uart interrupt needs to take over reading from the usb buffer to keep the transmit data flowing. I setup the flush_write_buffer function to enable the uart transmit interrupt so the uart interrupt can pull more data in from the buffer. It also needs to disable the transmit interrupt once there is no more data to write because the driver never clears the transmit interrupt.

Changes:

  • Created a uart class that abstracts on top of the RP2040 uart driver to buffer incoming data.
  • Ferry data between the usb serial port and the hardware uart
  • Detect changes in line coding from the usb serial port and pass them to the hardware uart.

Testing:

  • Created a program uart-test to test overloading the serial buffers on the device.
  • With a rusty-probe and another uart adapter connected together I opened both in screen with 115200 baud, if I type in one I get output in the other.
  • With a rusty-probe and another uart adapter connected together I ran uart-test with 512 count switching to different baud rates.
  • Same setup, but with firmware with usb-serial-reboot, I ran uart-test with bootload and it went into the usb bootloader

Related Issues:

@korken89
Copy link
Collaborator

Thank you for adding the UART functionality! I'm going to give it a look and a try.

How did it feel to implement? I've been planning to switch to embassy's HAL so we get an async UART.
Feels like it would make this easier to handle in the future.

@jonathanherbstgrapple
Copy link
Contributor Author

It was honestly quite a pain to implement. I've used embassy on a couple projects and it can be really nice, especially since their hal is well integrated and a lot of the abstractions already have dma written into them. However I believe async gets complicated pretty fast especially when you start using some of the magic like pin.

@hexdae
Copy link

hexdae commented Apr 8, 2025

This branch is great and I would love to see this functionality merged into main, anything I can do to help here?

@korken89
Copy link
Collaborator

Sorry for the delay, I'm not having the bandwidth to properly review this.
My direct impression is that it looks ok, can you @hexdae / @jonathanherbstgrapple confirm it has been working in your testing?
Also when changing configs?

One thing that sticks out to me is that it basically implements an IRQ based UART driver. It feels like we should port the entire app to embassy-rp to get the async DMA drivers.
But! That can be a future improvement :)

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

Successfully merging this pull request may close these issues.

3 participants