The "hello world" of microcontrollers. You find the LED on the board, follow its wire to an MCU pin, switch on the pin’s clock, make it an output and toggle it. Every step points at the page that explains it.
- Find what an on-board part is connected to, using the user manual and the schematic
- Why a peripheral does nothing until its clock is enabled in the RCC
- How
GPIOx_MODERandGPIOx_BSRRcontrol a pin - What active-low means and how to spot it on a schematic
- STM32H750B-DK and a USB cable to CN14 (the ST-LINK connector)
- STM32CubeIDE installed
On this board
Pulled from the datasheet tables and the board schematic. Click a pin for everything the finder knows about it.
Find the LED in the user manual
The board has eight LEDs, but most belong to the ST-LINK or the power circuit. The user manual has a table of all of them. The two meant for you are LD6 (red, "USER1") and LD7 (green, "USER2"), driven by PI13 and PJ2.
Whenever you want to use something on the board (a LED, a button, the screen), start in the user manual: it tells you which MCU signal it uses.
Confirm it on the schematic
The user manual says "PJ2", but the schematic shows how the LED is wired, and that decides whether you write 0 or 1 to turn it on.
On the MCU sheet, pin PJ2 leaves the chip on net LED1. Follow that net to the small LED circuit on the same sheet: 3V3 → LD7 → R233 (510 Ω) → LED1 → PJ2. The LED’s anode sits on 3.3 V, so current only flows when the pin pulls its side low. That is an active-low LED: pin low = LED on.
Tip. Click the LED1 label in the schematic viewer: it lists every other place that net appears.
Turn on the clock of GPIO port J
After reset every peripheral is unclocked to save power, and an unclocked peripheral ignores your writes. GPIO ports hang on the AHB4 bus, so their enable bits are in RCC_AHB4ENR. Port J is bit 9, GPIOJEN.
This is the step beginners forget most. If your pin "does nothing", check the clock enable first.
Make PJ2 an output
Each pin has two bits in GPIOx_MODER: 00 input, 01 output, 10 alternate function, 11 analog (the reset value for most pins). For pin 2 these are bits 5:4, so you clear both and set the low one.
The other output settings can stay at their reset values: GPIOx_OTYPER = push-pull and GPIOx_OSPEEDR = low speed, which is plenty for a LED.
Toggle the pin
You could write GPIOx_ODR, but that is a read-modify-write and can clash with an interrupt touching the same port. GPIOx_BSRR changes single pins in one write: bit n sets pin n high, bit n+16 drives it low. Because LD7 is active-low, reset turns it on.
#include "stm32h7xx.h" /* with STM32H750xx defined by the project */
static void delay(volatile uint32_t n) { while (n--) { } }
int main(void)
{
/* 1. clock for GPIO port J (RCC_AHB4ENR bit 9) */
RCC->AHB4ENR |= RCC_AHB4ENR_GPIOJEN;
(void)RCC->AHB4ENR; /* read back: lets the enable take effect */
/* 2. PJ2 as general-purpose output: MODER2[1:0] = 01 */
GPIOJ->MODER = (GPIOJ->MODER & ~GPIO_MODER_MODE2_Msk)
| (1U << GPIO_MODER_MODE2_Pos);
for (;;) {
GPIOJ->BSRR = GPIO_BSRR_BR2; /* PJ2 low -> LD7 on (active-low) */
delay(2000000);
GPIOJ->BSRR = GPIO_BSRR_BS2; /* PJ2 high -> LD7 off */
delay(2000000);
}
}/* in main(), after HAL_Init() and the generated clock setup */
__HAL_RCC_GPIOJ_CLK_ENABLE(); /* = RCC_AHB4ENR.GPIOJEN */
GPIO_InitTypeDef io = {0};
io.Pin = GPIO_PIN_2;
io.Mode = GPIO_MODE_OUTPUT_PP; /* MODER = 01, OTYPER = 0 */
io.Pull = GPIO_NOPULL; /* PUPDR = 00 */
io.Speed = GPIO_SPEED_FREQ_LOW; /* OSPEEDR = 00 */
HAL_GPIO_Init(GPIOJ, &io);
while (1) {
HAL_GPIO_TogglePin(GPIOJ, GPIO_PIN_2); /* writes BSRR for you */
HAL_Delay(500); /* SysTick based, in ms */
}Tip. The busy-wait delay() speed depends on the clock and the compiler optimisation level. For real timing use SysTick or a timer: see the PWM guide.
Build, flash, and make it yours
In STM32CubeIDE create a project for the STM32H750B-DK board, put the code in main.c, and press Run: the ST-LINK flashes and starts it. Then try:
- Blink LD6 (PI13) in turns with LD7. Port I needs its own clock bit.
- Make a heartbeat pattern: two short blinks, one long pause.
- Look up
GPIOJin the memory map and compute the address ofGPIOJ->BSRRyourself (base + offset 0x18).
Common mistakes
- Writing 1 to turn the LED on. These LEDs are active-low: 0 = on.
- Forgetting the RCC clock enable. The registers read back as 0 and writes are lost.
- Setting
MODERwith|=only. The reset value of most pins is11(analog), so OR-ing in01leaves11. Clear the two bits first.
Check yourself
Try to answer before opening. If you get stuck, the pages linked above have the answer.
Why does a 1 in BSRR bit 2 turn LD7 off?
BS2 drives PJ2 high. The LED’s anode is at 3.3 V, so with the cathode side also high no current flows.
Which register and bit would you need for an LED on PE3 instead?
Port E clock: GPIOEEN in RCC_AHB4ENR, then MODE3 in GPIOE->MODER and BS3/BR3 in GPIOE->BSRR.
What is LD8 connected to, and could you blink it too?
Table 6 in the user manual says LD8 (green, "ARDUINO") is on PD3. It is also Arduino pin D13, so yes, same recipe on port D.
Reading list
Every page this guide sent you to, by document. Reading them in order is a good revision.
Search next
Each of these opens the finder with pins, registers, schematic hits and document pages for the term.