multi-uart.ino
The signature of big STM32 boards: several hardware UARTs at once. This three-port bridge (USB-C console, GPS on Serial1, module on Serial2) shows the multiplexing with no extra library.
Hardware
An Arduino Portenta H7 (ST STM32H747 dual-core module Cortex-M7 @ 480 MHz + M4 @ 240 MHz, 8 MB SDRAM, high-density connector), powered by USB-C or 5 V. A serial GPS or USB-serial module to test.
Wiring
Crossed TX/RX to each module (board TX → module RX), common grounds, 3.3 V levels. Confirm the pairs on the carrier board schematic.
How it works
Each Serial is an independent peripheral; the loop pumps non-blocking buffers from port to port. At 480 MHz three simultaneous bridges are imperceptible.
Running it
Arduino IDE with the « Arduino Mbed OS Portenta Boards » core: pick « Portenta H7 » (M7 core), the USB-C port, then Upload. The DFU mode M7/M4 selector also loads the M4 core.
Variants
Add a ring buffer per port (Mbed RingBuffer), or route to the M4 core to pre-process frames.
multi-uart.ino
// Trois UART materiels en parallele : USB-C, GPS, module.
// Serial = CDC USB-C
// Serial1 = TX D8 / RX D9
// Serial2 = TX D7 / RX D8 selon carrier (verifier le schema)
void setup() {
Serial.begin(9600); // console USB-C
Serial1.begin(9600); // vers GPS/module 1
Serial2.begin(115200); // vers module 2
Serial.println("3 UART actifs");
}
void loop() {
// Pont GPS -> console : ce qui arrive sur Serial1 est reprint.
while (Serial1.available()) {
char c = Serial1.read();
Serial.write(c);
Serial2.write(c); // et repete vers le module 2
}
// Ce que tape le module 2 revient sur la console.
while (Serial2.available()) {
Serial.write(Serial2.read());
}
}