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

Serial over USB? #7

Open
rmortes opened this issue Mar 28, 2024 · 1 comment
Open

Serial over USB? #7

rmortes opened this issue Mar 28, 2024 · 1 comment

Comments

@rmortes
Copy link

rmortes commented Mar 28, 2024

FIrst of all, I'm extremely new to MCU programming so sorry if I'm asking something stupid.

Is it possible to get the debug output over USB? Via serial, uart, I don't know. I have a CH582M in one of the dev boards with the type-c, and I've been trying to get the debug output, but it hasn't been working for me. May be a drivers thing (I'm using Windows 10), but the computer can't recognize the device when it's actually running the code, so the "serial" and "uart-echo" examples don't do much for me.

Thanks!

@rgoulter
Copy link

The WCH EVT examples tend to use UART1 TX (typically PA9) for writing 'debug' output.

I see this codebase has some examples which do the same thing: setup UART1 (using PA9 for TX), which is then used with writeln!.
https://github.com/ch32-rs/ch58x-hal/blob/20eac4fd7d65b2eaa8b4eae40f882724a5710646/examples/serial.rs

To read these over USB, you'd connect the TX from the CH58x to RX to something that you can read from your PC.

e.g. If it's cheap/easy for you to obtain a FTDI FT232RL USB Adapter, that would work.

Otherwise, using a spare Pro Micro or Raspberry Pi Pico could be used.

e.g. here's CircuitPython code to read bytes from a UART RX, and output to USB CDC serial console.

"""Relay UART to CDC console."""
import board
import busio
import usb_cdc

uart = busio.UART(None, board.GP1, baudrate=115200)

while True:
    data = uart.read(32)

    if data is not None:
        usb_cdc.console.write(data)
        usb_cdc.console.flush()

You'd flash CircuitPython to a Pico, update the code.py with that program, connect the CH58x's UART1 TX (PA9) to GPIO1 of the Pico.

And you can connect to the USB serial console (e.g. the 232RL adapter, or CircuitPython on the Pico) using Putty https://wiki.archlinux.org/title/Working_with_the_serial_console#Making_Connections


For USB serial connection from the CH58x directly, I think you'd want to study/port this example. https://github.com/openwch/ch583/blob/main/EVT/EXAM/USB/Device/COM/src/Main.c

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