sommeil.ino
In Stop mode the GD32 drops to ~100 µA while keeping SRAM: the program resumes where it stopped, unlike deep sleep. Wake-up happens on any configured external interrupt.
Hardware required
A GD32F103C8T6 development board (Cortex-M3 at 108 MHz, Blue Pill pin-to-pin compatible), powered at 3.3 V/5 V, with an ST-Link or serial adapter. 1 button on PA0 for wake-up; a micro-ammeter to verify.
Wiring
Button PA0-GND. On battery, remove the board LDO or power the bare module: otherwise it sets the consumption floor.
How it works
LowPower.sleep enters Stop mode (CLK off, SRAM retention); PA0's EXTI wakes and the core resumes loop(). Variables keep their values. With Arduino: install the « STM32F1 » core (Roger Clark, board manager) and pick the « GD32F103C » board; the user LED is PC13 (active LOW). In C: GD32F10x firmware library + ST-Link.
Going further
Periodic wake on the internal RTC (alarm) for a timestamped sensor, losing only the serial context.
sommeil.ino
// Sommeil : le GD32 consomme ~100 uA en Stop, reveil par bouton PA0.
// Le core STM32F1 expose LowPower (STM32LowPower) sur les cartes GD32.
#include <LowPower.h>
const int REVEIL = PA0; // bouton vers GND, wake sur LOW
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(REVEIL, INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
digitalWrite(LED_BUILTIN, LOW); // temoin (actif-bas)
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(900);
Serial.flush();
// Stop : CPU et peripheriques coupes, SRAM conservee, reveil EXTI
LowPower.sleep(); // reveille sur appui PA0
Serial.println("reveille !");
}