A bare metal C++ project for the STM32F407VET6 Black Board featuring FreeRTOS task scheduling, LED control, PWM output, quadrature encoder decoding, and a simple motor position controller task.
- STM32F407VET6 Black Board (512KB Flash, 128KB RAM)
- ST-Link V2 or compatible programmer/debugger
- USB cable for power and programming
- Board schematic: STM32F407VET6 Black Board (STM32_F4VE V2.0) schematic
- ARM GCC Toolchain (
arm-none-eabi-gcc) - OpenOCD (for flashing and debugging)
- Make
- Git (for cloning FreeRTOS kernel)
brew install gcc-arm-embeddedbrew install openocdThis project uses FreeRTOS v10.6.2 for real-time task scheduling. The FreeRTOS kernel is not included in the repository and must be cloned separately:
git clone --depth 1 --branch V10.6.2 https://github.com/FreeRTOS/FreeRTOS-Kernel.git FreeRTOSFor detailed FreeRTOS configuration and usage information, see docs/FREERTOS.md.
.
├── Makefile # Build configuration
├── STM32F407VETx_FLASH.ld # Linker script
├── openocd.cfg # OpenOCD configuration
├── FreeRTOS/ # FreeRTOS kernel (not in repo - clone separately)
├── docs/
│ ├── FREERTOS.md # FreeRTOS integration documentation
│ ├── QUADRATURE_DECODER.md # Quadrature encoder documentation
│ └── MOTOR_CONTROLLER.md # PWM + encoder wrapper with position task
├── inc/
│ ├── FreeRTOSConfig.h # FreeRTOS configuration
│ ├── led.h # LED control header
│ ├── motor_controller.h # Motor controller (PWM + encoder + task)
│ ├── pwm_driver.h # PWM driver header
│ ├── quadrature_decoder.h # Encoder decoder header
│ ├── stm32f407xx.h # Device header file
│ ├── system_stm32f4xx.h # System header
│ └── timer_common.h # Common timer definitions
├── src/
│ ├── main.cpp # Main application with FreeRTOS tasks
│ ├── led.cpp # LED control implementation
│ ├── motor_controller.cpp # Motor controller implementation
│ ├── pwm_driver.cpp # PWM driver implementation
│ ├── quadrature_decoder.cpp # Encoder decoder implementation
│ ├── system_stm32f4xx.c # System initialization
│ └── startup_stm32f407xx.s # Startup code and vector table
└── build/ # Build output directory (created automatically)
First, ensure you have cloned the FreeRTOS kernel (see FreeRTOS Setup above).
To build the project:
makeThis will create:
build/stm32f407_hello.elf- ELF executablebuild/stm32f407_hello.hex- Intel HEX formatbuild/stm32f407_hello.bin- Binary formatbuild/stm32f407_hello.map- Memory map
To clean build artifacts:
make cleanConnect your ST-Link V2 to the board and run:
make flashThis uses OpenOCD to program the microcontroller.
Alternatively, you can flash manually:
openocd -f openocd.cfg -c "program build/stm32f407_hello.elf verify reset exit"The program uses FreeRTOS for task scheduling with the following features:
- System Initialization: Sets up system clock and hardware peripherals
- FreeRTOS Tasks: Creates and manages multiple concurrent tasks
- LED Control: Implements LED blinking using FreeRTOS task delays
- PWM Generation: Provides PWM output for motor control or other applications
- Quadrature Decoder: Reads position and direction from rotary encoders
- Motor Position Task: Optional FreeRTOS task that holds a target position using a proportional loop over PWM and encoder feedback
For detailed information about each component, see the documentation files in the docs/ directory.
On the STM32F407VET6 Black Board:
- LED1: PA6
- LED2: PA7
The LEDs blink using FreeRTOS tasks with independent timing periods.
To debug with OpenOCD and GDB:
- Start OpenOCD in one terminal:
openocd -f openocd.cfg- In another terminal, start GDB:
arm-none-eabi-gdb build/stm32f407_hello.elf- Connect to OpenOCD:
(gdb) target remote localhost:3333
(gdb) monitor reset halt
(gdb) load
(gdb) continue
- Flash: 512KB (0x08000000 - 0x0807FFFF)
- RAM: 128KB (0x20000000 - 0x2001FFFF)
- CCM RAM: 64KB (0x10000000 - 0x1000FFFF)
To modify LED behavior, PWM settings, or encoder configuration, see the respective source files:
- LED control: src/led.cpp and inc/led.h
- PWM driver: src/pwm_driver.cpp and inc/pwm_driver.h
- Quadrature decoder: src/quadrature_decoder.cpp and inc/quadrature_decoder.h
- Motor controller + position task: src/motor_controller.cpp, inc/motor_controller.h, and docs/MOTOR_CONTROLLER.md
- FreeRTOS configuration: inc/FreeRTOSConfig.h
This is a starter project for embedded development with FreeRTOS - feel free to use and modify as needed.