本文へ移動
cccskills
無料GitHub で公開

stm32f411-blackpill

Firmware development for the WeAct Studio "Black Pill" (STM32F411CEU6) and its clones such as the DFRobot DFR0864 — the 25 MHz HSE and 32.768 kHz LSE crystals, PC13 LED, K1 button, USB-C wired straight to USB_OTG_FS, ROM DFU flashing, the SPI-flash footprint, and the STM32Cube HAL + PlatformIO setup around them. Use when working on this board or any STM32F411CE/F401CC Black Pill: project setup, platformio.ini, clock and PLL configuration for 96 MHz plus 48 MHz USB, pin mapping on the 48-pin package, USB CDC console, RTC on the LSE crystal, the internal temperature sensor, ADC accuracy, DFU flashing and recovery, or debugging why something on the board does not work.

インストール方法を見る

含まれるファイル(32)

  • SKILL.md9.0 KB
  • assets/IMAGE.md453 B
  • reference/board-hardware.md35.1 KB
  • reference/recipes.md39.0 KB
  • template/.gitignore94 B
  • template/include/board.h1.4 KB
  • template/include/README1.2 KB
  • template/include/temp_sensor.h501 B
  • template/include/usb_device.h244 B
  • template/include/usbd_cdc_if.h382 B
  • template/include/usbd_conf.h1.0 KB
  • template/include/usbd_desc.h137 B
  • template/lib/README1.0 KB
  • template/lib/USBDevice/usbd_cdc.c28.3 KB
  • template/lib/USBDevice/usbd_cdc.h5.3 KB
  • template/lib/USBDevice/usbd_core.c30.1 KB
  • template/lib/USBDevice/usbd_core.h5.7 KB
  • template/lib/USBDevice/usbd_ctlreq.c25.4 KB
  • template/lib/USBDevice/usbd_ctlreq.h2.1 KB
  • template/lib/USBDevice/usbd_def.h16.4 KB
  • template/lib/USBDevice/usbd_ioreq.c4.9 KB
  • template/lib/USBDevice/usbd_ioreq.h2.4 KB
  • template/platformio.ini1.5 KB
  • template/README.md4.7 KB
  • template/src/main.c11.8 KB
  • template/src/temp_sensor.c4.4 KB
  • template/src/usb_device.c583 B
  • template/src/usbd_cdc_if.c3.3 KB
  • template/src/usbd_conf.c7.8 KB
  • template/src/usbd_desc.c5.0 KB
  • template/variants/minimal/main.c3.3 KB
  • template/variants/new-project.sh1.5 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

WeAct "Black Pill" — STM32F411CEU6

Board-specific firmware knowledge. The two reference files hold the detail — read the one you need rather than guessing, because most of the failure modes below are silent (the board runs, just wrongly).

  • reference/board-hardware.md — complete hardware reference: pin map for the 48-pin package with every alternate function, power tree, memory map, boot modes, plus a full development guide (Part II: §12 PlatformIO, §13 bring-up order, §14 peripheral cookbook, §15 F4/M4 gotchas, §16 flashing and recovery, §17 pitfall table).
  • reference/recipes.md — copy-paste-ready code: platformio.ini, board.h, the clock tree, RTC on the LSE crystal, the calibrated temperature sensor, the complete USB CDC stack.
  • template/ — a complete working project that builds and flashes, plus a scaffolding script. It is where every recipe was extracted from; see template/README.md.

Orientation

MCUSTM32F411CEU6, Cortex-M4F, 512 KB flash, 128 KB SRAM, UFQFPN48, 100 MHz max
CrystalsHSE 25 MHz on PH0/PH1, LSE 32.768 kHz on PC14/PC15 — both fitted from the factory
Working clock treePLL M25/N192/P2/Q4 → SYSCLK 96 MHz, HCLK 96, PCLK1 48, PCLK2 96, USB 48
LED / buttonPC13 lit = LOW (anode on 3V3) / K1 on PA0 pressed = LOW, needs a pull-up
USBUSB-C straight to USB_OTG_FS on PA11/PA12. No USB-serial chip on the board
FlashingROM DFU over that same USB-C (0483:DF11), entered by hand with BOOT0 + NRST
DebugSWD on the 4-pin header: 3V3, PA13 (SWDIO), PA14 (SWCLK), GND
ADCADC1 only, 10 external channels (PA0–PA7, PB0, PB1). No DAC. VDDA = VREF+ = the 3V3 LDO
Storageunpopulated SOIC-8 pad underneath for an SPI flash on SPI1 (PA4–PA7)

Rules that prevent the expensive mistakes

Check these before writing code — each one produces a failure that looks like something else.

  1. Define SysTick_Handler() yourself. framework-stm32cube ships no stm32f4xx_it.c, and the startup file's weak handler is an infinite loop. Without void SysTick_Handler(void) { HAL_IncTick(); } the board boots and then hangs in the first HAL_Delay() — which reads like a clock problem and is not. This is the single most common way a first project on this board fails.
  2. 96 MHz, not 100. USB_OTG_FS needs exactly 48 MHz off PLLQ, which divides the same VCO as PLLP. No integer pair gives 100 MHz and 48 MHz together. PLLM 25 / PLLN 192 / PLLP 2 / PLLQ 4. Set SYSCLK to 100 and USB silently never enumerates.
  3. FLASH_LATENCY_3 at 96 MHz, and PWR_REGULATOR_VOLTAGE_SCALE1 (after __HAL_RCC_PWR_CLK_ENABLE()) because Scale 2 caps at 84 MHz. Too few wait states → hard fault on the first fetch past the clock switch.
  4. -DHSE_VALUE=25000000 in build_flags. CubeF4's default template happens to be 25 MHz already, so it works by luck — until someone drops in a CubeMX-generated stm32f4xx_hal_conf.h written for an 8 MHz board and every baud rate and timer period shifts by 3.125× with no error.
  5. PC13 is lit by a LOW level and sits behind the backup-domain power switch: 3 mA maximum, GPIO_SPEED_FREQ_LOW, and never as a current source. Same limit applies to PC14/PC15, which are the LSE crystal here anyway.
  6. K1 on PA0 needs GPIO_PULLUP — not every revision fits an external one, and PA0 is one of only two pins on this package that are not 5 V tolerant (the other is PB5).
  7. Backup domain before RTC: __HAL_RCC_PWR_CLK_ENABLE() then HAL_PWR_EnableBkUpAccess(), or the LSE configuration reports success and the clock never starts. Expect the LSE itself to take ~2 s to stabilise on a cold start — that pause is normal, not a hang.
  8. HAL_RTC_GetTime() before HAL_RTC_GetDate(), always. The F4's calendar sits in shadow registers that unlock only after both are read. Reversed, the date freezes — a bug that first shows up at midnight.
  9. The temperature sensor is ADC channel 18 on the F411, not 16, and it shares that channel with the VBAT divider. Use ADC_CHANNEL_TEMPSENSOR and never call HAL_ADCEx_EnableVBAT(). F401 examples — which is most Black Pill material online — use channel 16 and return a plausible wrong number.
  10. Any internal ADC channel needs ADC_SAMPLETIME_480CYCLES (≥ 10 µs per the datasheet). The 3-cycle default reads noise. And use the factory calibration at 0x1FFF7A2A/2C/2E rather than the datasheet's typical 2.5 mV/°C — VDDA here is just an LDO output, not a reference.
  11. The USB device library is not in the framework. framework-stm32cubef4 has no STM32_USB_Device_Library; vendor usbd_core/ctlreq/ioreq/cdc into lib/. And point USBD_malloc at a static buffer — ST's default is malloc() against a 0x200-byte heap, which fails silently and the device never appears.

When the task is "how do I print something"

This board has no USB-serial chip. That surprises people coming from an Arduino Nano or an ESP32 devkit, and it shapes every debugging session. Options, cheapest first:

RouteCostNotes
USB CDC~14 KB flash, PA11/PA12, the USB peripheralsame cable as power and flashing; what template/ does
USART1 on PA9/PA10two pins + an external USB-UART donglealso the ROM bootloader's UART, so it doubles as recovery
SWO on PB3one pin + a trace-capable SWD probeno extra cable
Semihostingnonevery slow, halts on every write, needs the debugger attached

USB CDC is the default answer, and it is why rule 2 exists.

Starting a new project

Do not hand-assemble one — the USB stack alone is five files that have to be written, not installed. template/ is a verified-working project; scaffold from it:

~/.claude/skills/stm32f411-blackpill/template/variants/new-project.sh <target-dir> [--full|--minimal]
cd <target-dir> && pio run
  • --full (default) — LSE-backed RTC, USB CDC console with echo, calibrated temperature sensor, LED and K1. 19808 B of 512 KB flash, 4840 B of 128 KB RAM.
  • --minimal — LED + K1 only, same clock tree and startup order. 3476 B flash, 44 B RAM. Flash this first on a new board to prove toolchain, crystal and the DFU route before adding anything.

Both build clean with -Wall (verified). Nothing is generated and no paths are embedded, so copying the tree by hand works equally well. template/README.md maps files to subsystems, so a --full scaffold can be stripped back cleanly.

When the user already has a project, prefer bringing it in line with the template's platformio.ini and board.h over rewriting their code.

Flashing

DFU over the USB-C cable, no probe: hold BOOT0, tap NRST, release → the board enumerates as 0483:DF11 → pio run -t upload. PlatformIO passes :leave to dfu-util so the board restarts into the new firmware by itself; only entering DFU is manual, every time. SWD on the 4-pin header when you need breakpoints (debug_tool = stlink — the board definition defaults to blackmagic).

Nothing you flash can brick this board: the ROM bootloader runs before user code, so BOOT0 + NRST always gets you back, including after firmware that reconfigures PA13/PA14 and locks out SWD. If no DFU device appears at all, suspect BOOT1/PB2 being held high by attached hardware — that selects an SRAM boot instead. reference/board-hardware.md §16.3 has the full recovery ladder.

Confirm the board first

WeAct sells the same PCB with an STM32F401CCU6 (256 KB flash, 64 KB RAM, 84 MHz max, temperature sensor on ADC channel 16). The silkscreen next to the MCU says which. Most Black Pill tutorials online are written for the F401, so code lifted from them compiles on an F411 and misreads the temperature sensor. Everything in this skill is F411-specific unless it says otherwise; the clock tree in rule 2 works unchanged on an F401.

Reporting

State honestly what was verified on hardware versus derived from the datasheet. In this skill: the clock tree, LSE-backed RTC, USB CDC, DFU flashing and PC13 polarity were confirmed on a WeAct V3.x board; the temperature-sensor module is build-verified only; and K1 on PA0, the SPI-flash footprint pins and the header order come from the published WeAct pinout rather than from a schematic. Say so rather than presenting all of it as equally certain.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Firmware development for the Arduino Nano (A000005, ATmega328P @ 16 MHz, 5 V) — its 30 KB usable flash, 2 KB SRAM, 1 KB EEPROM, 8-channel 10-bit ADC, six 8-bit PWM pins across three timers, UART shared with the USB-serial chip, I2C on A4/A5, SPI on D10–D13, sleep modes, and the Arduino AVR core + PlatformIO setup around them. Use when working on this board or any ATmega328P Nano clone (FTDI or CH340 USB): project setup, platformio.ini, old-vs-new bootloader uploads, pin mapping, A6/A7 restrictions, timer/Servo/tone conflicts, the 2 KB SRAM budget, analog references, powering from VIN, ICSP recovery, or debugging why something on the board does not work.

日本語の概要は準備中です。原文の説明を表示しています。

alexex1993/mcu-skills182026年9月25日 更新

Firmware development for the Beetle — the CJMCU / DFRobot "Mini Arduino Leonardo" USB board (ATmega32U4 @ 16 MHz, 5 V, 21×28 mm, castellated pads) — its native USB (CDC serial + HID keyboard/mouse/joystick), Caterina bootloader and 1200 bps touch upload, ten exposed I/O pads, four PWM pins across Timer0/Timer1, five ADC channels, I2C on D2/D3, SPI on the back-side ICSP pads, 28 KB usable flash and 2.5 KB SRAM, and the PlatformIO + Arduino AVR core (`board = leonardo`) setup around them. Use when working on this board or any ATmega32U4 Leonardo/Micro/Pro-Micro-class clone: project setup, platformio.ini, why the board shows up as two different serial ports, uploads that fail or hang, recovering a bricked or HID-spamming board by shorting the ICSP reset pads, pin mapping and which pads are missing, PWM/timer conflicts, Servo and tone, USB HID keyboard projects, the SRAM budget, powering from the + pad, or debugging why something on the board does not work.

日本語の概要は準備中です。原文の説明を表示しています。

alexex1993/mcu-skills182026年9月25日 更新

Разработка прошивок для BE-U1000 (Baikal Electronics / Байкал Электроникс, три ядра RISC-V: BR-350 и BM-310) на отладочных платах EVU-BA-2.1, EVU-BA-2.0 и EVU-BA-1.2 — её eFlash и QSPI flash, UART0/BootROM CLI, PWMA (захват и импульсы), АЦП с DMA, CAN FD, SPI, WDT, CLIC, а также SDK Байкала и его система сборки на make. Use when working on this board or any BE-U1000 / BMCU_U project (SDK 2.1/2.3, riscv32-none-elf, dfu-util, OpenOCD): настройка проекта, Makefile и MEM_REG_ROM, карта выводов и разъёмы XP1/XP8/XP9/XP10, режимы начальной загрузки и страповые выводы, прошивка по UART XMODEM либо USB DFU, работа с eFlash и TCM, прерывания и CLIC, отладка по JTAG — и разбор, почему плата молчит, не стартует, зависает или почему периферия «настроилась», а обмена нет.

日本語の概要は準備中です。原文の説明を表示しています。

alexex1993/mcu-skills182026年9月25日 更新

Firmware development for the 30-pin ESP32-WROOM-32 development board — the DOIT ESP32 DevKit V1 / ESP32 CH340 Type-C / NodeMCU-ESP32 30-pin form factor, 15 pins per side, CH340G or CP2102 USB-UART bridge, AMS1117 LDO, user LED on GPIO2. Use when working on a 30-pin ESP32 devkit (ESP32-D0WDQ6 / ESP32-D0WD-V3, ESP-WROOM-32 module): project setup, platformio.ini and sdkconfig for ESP-IDF or Arduino, pin mapping and which GPIOs are safe, strapping pins, ADC1 vs ADC2 with Wi-Fi, SPI speed and IO_MUX pins, I2C, deep sleep and RTC wake pins, flashing over the CH340 bridge, BOOT/EN recovery, brownouts, or debugging why something on the board does not work.

日本語の概要は準備中です。原文の説明を表示しています。

alexex1993/mcu-skills182026年9月25日 更新

Firmware development for the 36-pin ESP32-WROOM-32 development board — the original DOIT ESP32 DevKit V1 with 18 pins per side, i.e. the 30-pin layout plus the six in-package flash pins (SD0 SD1 SD2 SD3 CMD CLK = GPIO6-11) broken out at the USB end, CH340G or CP2102 bridge, AMS1117 LDO, user LED on GPIO2, GPIO0 not on the header. Use when working on a 36-pin ESP32 devkit (ESP32-D0WDQ6 / ESP32-D0WD-V3, ESP-WROOM-32 module), or when identifying which ESP32 board size you have: project setup, platformio.ini and sdkconfig for ESP-IDF or Arduino, pin mapping and which GPIOs are safe, the flash-pin trap, strapping pins, ADC1 vs ADC2 with Wi-Fi, SPI speed and IO_MUX pins, deep sleep and RTC wake pins, flashing, BOOT/EN recovery, brownouts, or debugging why something on the board does not work.

日本語の概要は準備中です。原文の説明を表示しています。

alexex1993/mcu-skills182026年9月25日 更新

Firmware development for the 38-pin ESP32-WROOM-32 development board — Espressif ESP32-DevKitC V4, Ai-Thinker NodeMCU-32S, DOIT ESP32 DevKit V1 38-pin and their CH340/CP2102 clones, 19 pins per side, with GPIO0 and the six in-package flash pins (GPIO6-11, labelled D0 D1 D2 D3 CMD CLK or SD0-SD3) broken out. Use when working on a 38-pin ESP32 devkit (ESP32-D0WDQ6 / ESP32-D0WD-V3, ESP-WROOM-32 or ESP32-WROVER module): project setup, platformio.ini and sdkconfig for ESP-IDF or Arduino, pin mapping and which GPIOs are safe, the flash-pin and IO0 traps, WROVER GPIO16/17 PSRAM conflict, strapping pins, ADC1 vs ADC2 with Wi-Fi, SPI speed and IO_MUX pins, deep sleep and RTC wake pins, flashing, BOOT/EN recovery, brownouts, or debugging why something on the board does not work.

日本語の概要は準備中です。原文の説明を表示しています。

alexex1993/mcu-skills182026年9月25日 更新

alexex1993 のスキルをすべて見る

このスキルの問題を報告する