🛠 Console série sur RP2350 : USB CDC natif et UART0 de secours
Objectives
The RP2350 integrates a single USB controller: USB 2.0 Full-Speed device (12 Mb/s) and Full/Low-Speed host with an integrated 1.1 PHY (RP2350 datasheet, §12 USB). Under MicroPython, the console uses this native USB CDC — there is no serial chip on the board. However, as soon as USB is occupied (HID mode, battery power) or the USB pins are not wired (poorly soldered Pro Micro, bare module), you need UART: the RP2350 has 2 UARTs mappable to any GPIO. This tutorial sets up both fallback methods.
Hardware
- 1 × generic RP2350 board + MicroPython rp2 (previous tutorial)
- 1 × USB↔TTL adapter (CP2102, CH340, FTDI…) at 3.3 V — the RP2350 IO operates at IOVDD 1.8–3.3 V: 5 V on a pin can destroy it
- 3 × cables: GP0 (TX0) → RX of the adapter, GP1 (RX0) → TX, GND ↔ GND (common ground is mandatory)
- Do not connect the adapter's VCC to the board if it is already powered
Complete Code
# main.py — printf sur USB CDC ET trace sur UART0 (GP0/GP1, 115200 8N1)
import sys
from machine import UART, Pin
import time
# 1) La console par défaut est l'USB CDC natif du RP2350 :
print('Bonjour depuis USB CDC') # visible dans Thonny / mpremote
# 2) Console de secours indépendante sur UART0 :
uart = UART(0, baudrate=115200, tx=Pin(0), rx=Pin(1))
uart.write('RP2350 pret (UART0 115200 8N1)\r\n')
n = 0
while True:
n += 1
msg = 'tick %d uptime_ms=%d\r\n' % (n, time.ticks_ms)
sys.stdout.write(msg) # USB CDC
uart.write(msg) # UART0 physique
if uart.any: # écho de ce que le PC envoie
uart.write('recu: ' + uart.read.decode(errors='replace') + '\r\n')
time.sleep_ms(500)
Expected Verification
Two windows, same lines: Thonny (board's CDC port) and your serial terminal on the adapter (115200 8N1 — picocom -b 115200 /dev/ttyUSB0, or the COM port under Windows). A character typed on the adapter side returns as an echo. Unplug the board's USB while keeping it powered at 5 V on VREG_VIN (2.7–5.5 V): the UART trace continues — you have a console decoupled from USB, essential for debugging a program that crashes USB enumeration.
Common Errors
- TX connected to TX: always cross — board TX → adapter RX.
- Missing common ground: nothing, or garbled bytes.
- 5 V adapter: the RP2350 is not 5 V tolerant on IO (range 1.8–3.3 V depending on IOVDD) — check the adapter's voltage selector.
- Confusing the two: USB CDC is a virtual serial port (ttyACM/COM) created by the board; the TTL adapter is a second port (ttyUSB…). Both can coexist.
- GP0/GP1 already used by your setup: the RP2350's UART can be routed to any GPIO —
UART(1, tx=Pin(4), rx=Pin(5))frees up the bus. - Silent REPL on UART: under MicroPython rp2, the REPL remains on USB CDC; if you want the REPL on UART, you must configure it (
machine.UART+ stdio reassignment) or use the C SDK withstdio_init_uart. - Power cable only: USB CDC only exists if the data pins are connected — again, the cable.
Other tutorials for this board
- Flasher MicroPython sur une carte RP2350 générique et faire clignoter la première LED
- Lire l'ADC 12 bits et le capteur de température interne du RP2350
- Exploiter les 3 blocs PIO et 12 machines d'état du RP2350 (avec IRQ dédiées)
- Pico SDK 2.x sur une carte RP2350 générique : CMake, board header et PICO_BOARD
- Basculer les cœurs de Arm Cortex-M33 à Hazard3 RISC-V avec ARCHSEL
- Secure boot et TrustZone-M sur RP2350 : signer son firmware sans se faire avoir
Code examples for this board
clignotante.pyPythonbouton-interruption.pyPythonpwm-servo.pyPythonlecture-adc.pyPythonneopixel.pyPythonoled-i2c.pyPython