Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

STM32F1 FreeRTOS template for Panda Rev1

A CMake project for the STM32F103C8T6: Cortex-M3, 64 KB Flash, 20 KB RAM, using the internal 8 MHz HSI clock. The firmware target is stm32f103-rtos-template.

src/main.c initializes the board, creates LED tasks for RED1 (PA2) and RED2 (PA1), then starts FreeRTOS. Task priorities and delays can be changed there to explore scheduling. Enable the corresponding LED DIP switches on the Panda board.

Required tools

Use OpenOCD for both flashing and debugging through an ST-Link V2.

Tool Purpose
Arm GNU Toolchain (arm-none-eabi) Compile the firmware and supply ARM GDB
CMake 3.30+ and Ninja Configure and build; available with CLion
OpenOCD 0.12+ Program the STM32 and provide the GDB server
CLion Build, flash and debug from the IDE

Install the Windows ST-Link USB driver. Set these paths for your installation:

Setting File Example
ARM_DIR cmake/ArmToolchain.cmake C:/Tools/arm-gnu-toolchain-15.3.rel2
OPENOCD_BIN_DIR cmake/Programming.cmake C:/Tools/xpack-openocd-0.12.0-7/bin

On first opening the project, use Reset Cache and Reload Project in CLion. Repeat this after changing a previously cached path. See the initial setup screenshots. OpenOCD uses debug/panda-stlink.cfg for the ST-Link/SWD connection.

FreeRTOS integration: FreeRTOS.cmake

CMakeLists.txt includes the added cmake/FreeRTOS.cmake, which adds the kernel source files and include paths to the firmware target.

FreeRTOS Kernel V11.3.1, from FreeRTOSv202604.01-LTS, is stored under:

FreeRTOSv202604.01/FreeRTOS-Kernel/

The CMake source list contains:

File relative to the kernel folder Purpose
tasks.c Task creation, scheduling and delays
list.c Internal lists used by the kernel
queue.c Queues and semaphore support
timers.c Software timers
event_groups.c Event groups
stream_buffer.c Stream and message buffers
croutine.c Co-routines
portable/GCC/ARM_CM3/port.c GCC Cortex-M3 context switching and tick setup
portable/MemMang/heap_1.c RTOS memory allocation

The include paths are include/ and portable/GCC/ARM_CM3/ inside the kernel folder, plus the project's include/ directory.

include/FreeRTOSConfig.h sets a 1 kHz tick, an 8 KB heap, preemption and time slicing. It maps the FreeRTOS interrupt handlers to the existing SVC_Handler, PendSV_Handler and SysTick_Handler. Optional features such as software timers, event groups, stream buffers and co-routines are currently disabled in the configuration, even though their source files are listed in CMake.

heap_1 cannot free allocated memory, so task deletion is disabled. Only heap_1.c is selected for compilation from the available heap implementations.

Call SystemCoreClockUpdate() after setting the clock and before starting the scheduler. DelayMs() is an approximate busy-wait that leaves SysTick untouched; use vTaskDelay() or xTaskDelayUntil() when a task should block.

Project files

Folder Contents
src/ Application tasks and startup in main.c
include/ Application configuration, including FreeRTOSConfig.h
BSP/Panda/ Board pins and buzzer setup
Drivers/ GPIO, RCC and USART drivers
Lib/ Shared types and delay utility
cmake/ Toolchain, sources, FreeRTOS and programming targets
debug/ OpenOCD configuration and GDB scripts
STM32-base/, STM32-base-STM32Cube/ Startup, linker scripts and device headers

Third-party license information is in THIRD_PARTY.md.

Flash and debug

Connect ST-Link SWDIO to PA13, SWCLK to PA14, and GND to GND on the Blue Pill SWD header. Set BOOT0 = 0. Power the board and connect the probe's voltage reference as required by its pin labels; avoid connecting two power outputs together. The Panda USB Type-B port provides the CH340 serial connection.

Follow README_CLION.md for Panda Run (HEX), Panda Debug (ELF) and equivalent terminal commands. To view USART output, follow the CLion Serial Connections steps.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages