TCS Pune

STM32 H7 — GPIO LED and Safe Current

Embedded Project Builder

STM32 H7 — GPIO LED and Safe Current

Drive an LED with a calculated resistor and verify HIGH/LOW voltage. Program and practical guide for STM32 H7.

Problem statement

Drive an LED with a calculated resistor and verify HIGH/LOW voltage. The implementation must operate inside the electrical, timing and memory limits of the exact STM32 H7 device.

System design

Circuit & Wiring Studio

Exact target required

Drag components. In Connect mode, select one pin and then another pin.

Rich media learning

Print lab worksheet

Instructor media is being prepared for this project.

Project execution and evidence

Log in to start this practical, save readings and submit evidence.

Log in to start

Recommendations & learning path

Bookmark project

Equivalent and related projects

Components required

ComponentQtyNotes
LED and 220–1 kΩ resistor1Verify voltage/current rating
Breadboard and insulated jumpers1Inspect before power
USB data/programming cable1Must support data
Digital multimeter1Lab tool
Current-limited bench supply1Lab tool

Pin-connection table

Controller pinConnected deviceDevice pinVoltage / notes
Board supplyTarget VCCConfirm exact board input and regulator
Board groundModule groundShared reference unless isolated
GPIO / timer outputSelected peripheral pins3.3 V maximum; confirm pin mux
Protected outputDriver inputNever power high-current load from GPIO

Project files

Source-code files

Instructor file pending.

PCB and Gerber files

Instructor file pending.

Enclosure design files

Instructor file pending.

Target-specific program

Toolchain: · Language:

// STM32 H7 — complete gpio starter program
// Map BOARD_LED, BOARD_INPUT, ADC and serial helpers to the exact board support package.
#include "main.h"
#include <stdint.h>
#include <stdbool.h>
static uint32_t deadline_ms;static uint32_t faults;
static void safe_outputs(void){board_gpio_write(BOARD_LED,false);}
static void project_step(void){uint16_t sample=board_adc_read(0);bool input=board_gpio_read(BOARD_INPUT);bool output=(sample>2048u)||input;board_gpio_write(BOARD_LED,output);board_serial_printf("TYPE=gpio ADC=%u IN=%u FAULTS=%lun",sample,input,(unsigned long)faults);}
int main(void){board_init();safe_outputs();board_serial_init(115200);board_serial_write("TCS STM32 H7 PROJECT READYn");deadline_ms=board_millis();for(;;){uint32_t now=board_millis();if((int32_t)(now-deadline_ms)>=0){deadline_ms+=100u;project_step();}board_watchdog_service_if_healthy();}}

Testing and observations

  1. Inspect wiring with power disconnected.
  2. Power from a current-limited supply.
  3. Build with the exact target and warning level enabled.
  4. Flash the program and capture startup output.
  5. Measure supply and relevant I/O signals.
  6. Inject one safe input or communication fault.
  7. Repeat the functional test for at least 20 cycles.
  8. Record code version, board revision and results.
TestExpectedInstrumentAcceptance criteria
Supply railWithin target-board tolerance
Idle currentBelow approved project limit
Functional outputMatches the stated objective
Fault responseSafe and recoverable
Repeated test20 of 20 cycles pass

Viva questions

Why was this pin selected?

Explain pin capability, boot function and voltage limit.

What fails if timing blocks?

Other work and fault response become delayed.

How was current limited?

Use a resistor, driver and protected supply as required.

What evidence proves operation?

Code version, measurements, serial output and repeated tests.

Prototype safety

Verify voltage, polarity, GPIO limits and isolation before power-up. Use current limiting and disconnect power before wiring changes.

Guided practical

Complete learning and build guide

Beginner2–3 hoursBeginner GPIO and LED projects

Objective

Drive an LED with a calculated resistor and verify HIGH/LOW voltage.

Required knowledge

  • STM32 H7 pin functions and voltage limits
  • Embedded C/C++ fundamentals
  • Safe breadboard wiring
  • Serial debugging and measurement

Power and current calculation

Calculate total current from the board, sensor/module and output load. GPIO supplies only logic-level current; motors, relays, buzzers and high-current LEDs require a correctly rated driver and protected external rail. Start with current limiting and verify actual idle and peak current.

Libraries and build procedure

Libraries: STM32 HAL or LL generated for the exact MCU, No external paid API

  1. Create a project for STM32 H7 using STM32CubeIDE.
  2. Select the exact MCU/board and clock configuration.
  3. Paste the complete program and change only the documented pin constants.
  4. Install only the libraries listed for this project.
  5. Build with warnings enabled and resolve every error.
  6. Connect the board with outputs disconnected and upload/program it.
  7. Confirm startup diagnostics, then connect the protected load.
  8. Record the final binary size and test evidence.

Complete source code

// STM32 H7 — complete gpio starter program
// Map BOARD_LED, BOARD_INPUT, ADC and serial helpers to the exact board support package.
#include "main.h"
#include <stdint.h>
#include <stdbool.h>
static uint32_t deadline_ms;static uint32_t faults;
static void safe_outputs(void){board_gpio_write(BOARD_LED,false);}
static void project_step(void){uint16_t sample=board_adc_read(0);bool input=board_gpio_read(BOARD_INPUT);bool output=(sample>2048u)||input;board_gpio_write(BOARD_LED,output);board_serial_printf("TYPE=gpio ADC=%u IN=%u FAULTS=%lun",sample,input,(unsigned long)faults);}
int main(void){board_init();safe_outputs();board_serial_init(115200);board_serial_write("TCS STM32 H7 PROJECT READYn");deadline_ms=board_millis();for(;;){uint32_t now=board_millis();if((int32_t)(now-deadline_ms)>=0){deadline_ms+=100u;project_step();}board_watchdog_service_if_healthy();}}
SectionExplanation
ConfigurationSelects the exact target pins, baud rate and safe defaults.
InitialisationConfigures peripherals and reports startup state.
Non-blocking loopSchedules input, processing and output without long delays.
Fault handlingDetects invalid data or timeout and selects a safe output.
DiagnosticsPrints measurements and state for repeatable testing.

Expected Serial Monitor output

TCS STM32 H7 PROJECT
SELFTEST: PASS
STATE: READY
VALUE: 0
FAULTS: 0
PointExpectedToleranceInstrument
Board supplyRated board logic rail±5%DMM
GPIO LOW0 VWithin datasheet VOLDMM/oscilloscope
GPIO HIGH3.3 VWithin datasheet VOHDMM/oscilloscope
Signal timingProgrammed period±5%Oscilloscope/logic analyser
SignalTest pointReference
Digital/PWM outputConfigured output pinClean transitions inside 3.3 V limits
Serial outputUART TXStable frames at configured baud
Sensor busSDA/SCL or SCK/dataValid idle level, timing and acknowledgements

Troubleshooting decision tree

SymptomCheckCorrective action
Board not detectedUSB cable, driver, boot mode and targetUse data cable and correct programmer settings
No outputSupply, ground, pin mapping and safe defaultCorrect one item with power disconnected
Wrong readingsReference voltage, scaling and sensor rangeCompare raw value and DMM result
Random resetsCapture supply during peak loadImprove supply/decoupling and separate load power
Communication failsLogic voltage, pull-ups, mode/address and baudMatch both endpoints and use common reference

Extension challenges

  • Replace blocking timing with a state machine.
  • Add calibrated measurement and retained configuration.
  • Add serial commands with bounds checking and timeout.
  • Measure active and sleep current.
  • Create a PCB-ready pin and connector table.
  • Add watchdog recovery and diagnostic export.

Project-report guidance

Include objective, exact MCU/board, schematic, pin table, BOM, complete code, compiler/tool versions, expected and measured readings, waveform evidence, fault injection, corrections, limitations and extension results.

Ready when you are

Need help with your laptop or computer?

Send us the model and fault details. Start your repair request online or contact TCS Pune directly.

WA