mohitmishra786/low-level-dev-skills

stm32-baremetal

STM32 bare-metal skill for CMSIS-only MCU projects.

查看源码

使用方法

  1. 复制安装命令,在自己的智能体环境安装前先检查源码包。
  2. 从原始文档核对所需工具、凭据和支持的宿主。
  3. 说明输入材料与期望交付物,并对照来源检查输出。
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill stm32-baremetal

开始前需了解

  • 安装不包含模型订阅、API 额度或访问文件的权限。
  • 仓库星数和安装量反映活跃情况,不等于独立质量或安全测试。
仓库原始内容

按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。

STM32 Bare-Metal (CMSIS, No HAL)

Purpose

Guide agents through a minimal STM32 bare-metal project using CMSIS device headers and startup code only — no STM32 HAL — covering clock setup, linker script integration, peripheral register access, and a reproducible build layout for STM32F/G/H/L families.

When to Use

  • Starting STM32 firmware without Cube HAL dependency
  • Porting vendor examples to register-level drivers
  • Integrating with skills/baremetal/baremetal-startup and skills/embedded/linker-scripts
  • Debugging clock or flash placement issues on STM32
  • Teaching register-level STM32 before RTOS or Zephyr

Workflow

1. Minimal project layout

stm32-bare/
├── startup_stm32f407xx.s   # vector table + Reset_Handler
├── system_stm32f4xx.c      # SystemInit(), SystemCoreClockUpdate()
├── stm32f407xx.h           # CMSIS (from ST pack or copy)
├── linker.ld               # FLASH/RAM regions
├── main.c
└── Makefile

Use CMSIS-Core (core_cm4.h) and device header from ST CMSIS pack or open-source packs (e.g. stm32-cmsis-device-f4).

2. Clock configuration (RCC)

STM32 requires explicit HSE/HSI and PLL setup before high-speed peripherals:

c
/* system_stm32f4xx.c — simplified PLL from 8 MHz HSE */
void SystemInit(void)
{
    RCC->CR |= RCC_CR_HSEON;
    while (!(RCC->CR & RCC_CR_HSERDY)) {}

    RCC->PLLCFGR = RCC_PLLCFGR_PLLSRC_HSE | (8 << 0) | (336 << 6) | (0 << 16) | (7 << 24);
    RCC->CFGR   |= RCC_CFGR_PPRE1_DIV2 | RCC_CFGR_PPRE2_DIV1 | RCC_CFGR_HPRE_DIV1;
    RCC->CR     |= RCC_CR_PLLON;
    while (!(RCC->CR & RCC_CR_PLLRDY)) {}

    FLASH->ACR = FLASH_ACR_LATENCY_5WS;
    RCC->CFGR  |= RCC_CFGR_SW_PLL;
    while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL) {}

    SystemCoreClockUpdate();
}

Always match FLASH_ACR wait states to voltage scale and SYSCLK per reference manual table.

3. Enable peripheral clock before MMIO

c
#define RCC_AHB1ENR_GPIOAEN (1U << 0)

static inline void gpioa_clock_enable(void)
{
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
    (void)RCC->AHB1ENR; /* AHB read-after-write — required on STM32 */
}

4. Build flags (arm-none-eabi-gcc)

makefile
MCU      = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS   = $(MCU) -Wall -Wextra -ffunction-sections -fdata-sections -g3
LDFLAGS  = $(MCU) -T linker.ld -Wl,--gc-sections -specs=nano.specs -lc -lm -lnosys

5. Flash map (typical F4)

RegionAddressNotes
Flash0x08000000Vector table at boot
SRAM10x20000000Stack, heap, .data/.bss
CCM0x10000000F4 only — not DMA-accessible from all masters

Bootloader apps often link at 0x08010000 and set SCB->VTOR = 0x08010000 on entry.

6. QEMU note

QEMU STM32 machines (stm32vldiscovery, netduinoplus2, etc.) use different MCUs than F407 and omit GPIO/DMA/I2C per QEMU STM32 docs. Use skills/qemu/qemu-embedded-simulation for simulation; validate F4 firmware on hardware.

7. Agent usage

/stm32-baremetal Scaffold CMSIS-only STM32F407 project with USART2 printf

Common Problems

SymptomCauseFix
Hang in SystemInitHSE not populated / wrong PLLUse HSI for bring-up; verify crystal
Peripheral deadRCC clock gate offEnable AHB/APB bit; read-back RCC
HardFault on bootStack in wrong region / VTORCheck _estack in linker.ld
Wrong baud rateSystemCoreClock staleCall SystemCoreClockUpdate() after PLL
DMA fails from CCMCCM not on AHB matrix pathPlace DMA buffers in SRAM1

Related Skills

  • skills/baremetal/baremetal-startup — vector table and .data/.bss
  • skills/baremetal/mmio-and-bit-manipulation — register access patterns
  • skills/baremetal/bootloaders-embedded — app offset and VTOR relocation
  • skills/embedded/linker-scripts — FLASH/RAM MEMORY blocks
  • skills/embedded/openocd-jtag — flash and GDB via ST-Link

按任务相关推荐

来自同一仓库

更多 Skills

全部 Skills
mohitmishra786
社区

core-dumps

Core dump analysis skill for production crash triage. Use when loading core files in GDB or LLDB, enabling core dump generation on Linux/macOS, mapping symbols with debuginfo or debuginfod, or extracting backtraces from crashes without re-running the program. Activates on queries about core files, ulimit, coredumpctl, debuginfod, crash triage, or analyzing segfaults from production binaries.

安装量
2
GitHub Stars
267
最近更新
6月27日
mohitmishra786
社区

custom-allocators

Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator, GlobalAlloc, or fragmentation.

安装量
2
GitHub Stars
267
最近更新
6月27日
mohitmishra786
社区

ebpf

eBPF skill for Linux observability and networking. Use when writing eBPF programs with libbpf or bpftrace, attaching kprobes/tracepoints/XDP hooks, debugging verifier errors, working with eBPF maps, or achieving CO-RE portability across kernel versions. Activates on queries about eBPF, bpftool, bpftrace, XDP programs, libbpf, verifier errors, eBPF maps, or kernel tracing with BPF.

安装量
2
GitHub Stars
267
最近更新
6月27日
mohitmishra786
社区

flamegraphs

Flamegraph generation and interpretation skill. Use when converting perf, Valgrind Callgrind, or other profiler output into SVG flamegraphs using Brendan Gregg's FlameGraph tools, or when reading flamegraphs to identify performance bottlenecks. Activates on queries about flamegraphs, stackcollapse, flamegraph.svg, identifying hot frames, wide vs tall frames, or performance visualisation.

安装量
2
GitHub Stars
267
最近更新
6月27日