servo.ino
The STM32F1 core's Servo library places each object on a free hardware timer: the servo gets its exact 50 Hz without the code caring. The real topic stays the servo's separate supply.
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 SG90/MG90 servo + external 5 V supply.
Wiring
Signal on PC8, + to the external supply, common grounds. The GD32 is 3.3 V: the servo tolerates that logic level.
How it works
write(angle) converts to a 1-2 ms pulse via the timer the library picks; the core generates nothing afterwards. The 20 ms period is held by hardware. 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
Two servos on two timers for an arm, or control from the UART bridge console.
servo.ino
// Servo sur PC8 (timer attribue par la bibliotheque).
#include <Servo.h>
Servo servo;
int angle = 0;
int pas = 5;
void setup() {
Serial.begin(115200);
servo.attach(PC8); // n'importe quelle broche avec timer
Serial.println("Balayage 0-180");
}
void loop() {
angle += pas;
if (angle >= 180 || angle <= 0) pas = -pas;
servo.write(angle);
delay(30);
}