🛠 Faire clignoter la LED PC13
Objectives
Discover the GD32F103C8T6 board compatible with the "Blue Pill" form factor (the GD32F103 from GigaDevice is a near pin-to-pin "drop-in" replacement for the STM32F103, a Cortex-M3 clocked up to 108 MHz) and make the onboard LED blink. By the end of this tutorial, you will know how to install an Arduino core adapted for the GD32, compile, flash, and above all understand why the Blue Pill's LED lights up when writing a LOW level: it is wired in active-LOW on PC13.
Hardware
- GD32F103C8T6 "core board" (64 KB flash) or GD32F103CBT6 (128 KB), Blue Pill format (LQFP48)
- ST-Link programmer (SWD) with OpenOCD compatible with GD32 (e.g., tool-openocd-gd32 from CommunityGD32Cores), or a USB-to-serial converter for the system bootloader on USART0
- Onboard LED on PC13, wired in active-LOW (lit when the pin is in the LOW state)
- 3.3 V power supply only: the power supply and I/O pins of the GD32F103 range from 2.6 to 3.6 V (some pins tolerate 5 V, but never power the board with 5 V on a non-tolerant pin)
Complete Code
Arduino IDE with the community core CommunityGD32Cores/ArduinoCore-GD32 (board index URL: https://raw.githubusercontent.com/CommunityGD32Cores/GD32Core-New/main/package_gd32_index.json), board "Generic GD32F103C8".
// blink_pc13.ino — GD32F103C8, core Arduino CommunityGD32Cores
#include <Arduino.h>
void setup {
pinMode(PC13, OUTPUT); // LED embarquée, active-LOW sur les cartes Blue Pill
}
void loop {
digitalWrite(PC13, LOW); // LED ALLUMÉE (logique inversée !)
delay(250);
digitalWrite(PC13, HIGH); // LED ÉTEINTE
delay(750);
}
Expected Verification
The LED blinks with a brief flash (250 ms on) followed by a pause (750 ms off), resulting in a cycle of approximately 1 Hz. If you write HIGH and the LED lights up, your board has an active-HIGH LED (rare) or you are not on the correct pin. Also verify that the program is actually running: on these boards, a flash that "succeeds" on the wrong target leaves the LED off.
Common Errors
- LED "inverted": On the Blue Pill, PC13 is active-LOW; forgetting the inversion results in inverted blinking (or an LED that appears always on).
- Wrong Arduino core: The official ST core (Arduino_Core_STM32) does not contain any GD32 variants; use the CommunityGD32Cores core or the Roger Clark core (Arduino_STM32/GD32F1).
- The GD32 is not an STM32: GigaDevice's application note AN001 requires HSE_STARTUP_TIMEOUT = 0xFFFF (instead of 0x0500) in projects derived from ST code, otherwise startup may remain blocked waiting for the crystal.
- BOOT0 left high: The board would boot into the system bootloader (memory starting at 0x1FFF B000, a different address than the STM32F103) instead of your program.
- ST-Link rejecting the target: A "standard STM32" OpenOCD may reject the GD32; use an OpenOCD configuration compatible with GD32.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinopotentiometre.inoArduinopont-uart.inoArduinooled-i2c.inoArduino