🛠 Console série sur USART0 (PA9/PA10)
Objectives
Set up a serial console on USART0 (verified pins: TX on PA9, RX on PA10 on most GD32F103C8 Blue Pill-style boards), send periodic messages, and read back what you type. This is the basic debugging tool: most subsequent tutorials depend on it.
Hardware
- GD32F103C8T6 / CBT6 Blue Pill-compatible board
- USB-to-serial converter (FT232, CP2102, CH340) strictly set to 3.3 V logic: the GD32F103 power supply and pins are specified from 2.6 to 3.6 V; a 5 V module in standard TTL mode is not guaranteed (only certain pins are "5 V tolerant")
- 3 wires: PA9 → adapter RX, PA10 → adapter TX, common ground
- IDE serial monitor or any terminal at 115200 baud, 8N1
Complete code
// console_usart0.ino — GD32F103C8, core CommunityGD32Cores
// Serial = USART0 sur PA9 (TX) / PA10 (RX), comme sur les Blue Pill.
#include <Arduino.h>
uint32_t compteur = 0;
void setup {
Serial.begin(115200);
delay(100);
Serial.println("GD32F103 : console serie prete");
Serial.println("Envoyez n'importe quel caractere pour l'echo.");
}
void loop {
if (Serial.available > 0) {
char c = (char)Serial.read;
Serial.print("Recu : ");
Serial.println(c);
}
if (compteur % 20 == 0) {
Serial.print("tick ");
Serial.println(compteur / 20);
}
compteur++;
delay(50);
}
Expected verification
At 115200 baud, you see "tick 1", "tick 2"… scrolling once per second, and each key pressed is echoed as "Recu : x". If you see constant unreadable characters, it is almost always a wrong baud rate or a missing ground connection.
Common errors
- TX and RX not crossed: TX from the board to RX on the adapter and vice versa; "straight" wiring never communicates.
- No common ground: without a common GND, you read noise or nothing at all.
- 5 V levels: an adapter configured for 5 V exceeds the guaranteed power supply range (2.6 to 3.6 V); use a 3.3 V module.
- Wrong hardware serial port: on this core,
Serialcorresponds to USART0 (PA9/PA10); if you wired other pins, check the core's port/pin mapping. - Pins occupied: on some boards, the monitor uses a second USART connected to the "debug" micro-USB connector; make sure you connect to the pins you have wired.
- Program does not start: check BOOT0 (must be 0 to boot from main flash, otherwise the board stays in the system bootloader located starting at 0x1FFF B000 — an address specific to GD32, different from STM32F103).
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinopotentiometre.inoArduinopont-uart.inoArduinooled-i2c.inoArduino