clignotante.c
The reference blink in bare C with STM32 HAL: the board LED on pin 0 toggles every 500 ms thanks to the 1 ms HAL SysTick. The skeleton is the one generated by STM32CubeIDE, ready to compile.
Hardware
A Nucleo H7 board (STM32H743ZI, Cortex-M7 @ 480 MHz) programmed via ST-LINK (USB), 3.3 V pins. None: the user LED (LD1, broche PB0 selon la cartographie officielle de la carte) is enough. The board is programmed via its USB connector (ST-LINK or bootloader).
Wiring
Nothing to wire: internal LED on GPIOB/GPIO_PIN_0, active HIGH.
How it works
HAL_Init() sets up SysTick (1 ms tick); HAL_GetTick() acts as a non-blocking clock. HAL_GPIO_WritePin drives the push-pull pin. __WFI() sleeps the CPU between ticks.
Running it
STM32CubeIDE project based on the Nucleo-H743ZI: drop the code into main.c, declare peripherals in the .ioc, then Run over ST-LINK. The ST-LINK serial monitor shows printf at 115200.
Variants
Create the project from the ST-provided .ioc (or an equivalent one), or use the LL library for leaner code.
clignotante.c
// Clignotement LED en STM32 HAL (projet genere par STM32CubeIDE/.ioc).
#include "main.h"
/* Broche de la LED utilisateur de la carte. */
#define LED_PORT GPIOB
#define LED_PIN GPIO_PIN_0
/* LED active a l'etat HIGH. */
uint32_t dernierBlink = 0;
uint8_t etat = 0;
int main(void) {
HAL_Init(); // SysTick 1 ms + priorites NVIC
SystemClock_Config(); // horloge generee depuis CubeMX
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
GPIO_InitTypeDef g = {0};
g.Pin = LED_PIN;
g.Mode = GPIO_MODE_OUTPUT_PP; // sortie push-pull
g.Pull = GPIO_NOPULL;
g.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_PORT, &g);
for (;;) {
if (HAL_GetTick() - dernierBlink >= 500) { // 500 ms
dernierBlink = HAL_GetTick();
etat ^= 1;
HAL_GPIO_WritePin(LED_PORT, LED_PIN, etat ? GPIO_PIN_SET : GPIO_PIN_RESET);
}
__WFI(); // attend l'interruption SysTick : consomme moins
}
}