Skip to content

This PR adds a complete STM32 port for FastAccelStepper, targeting the STM32duino toolchain. Step pulses are generated via TIM2/TIM3 compare-match ISR with GPIO BSRR bit-bang, allowing any GPIO pin to be used as a step pin. Deferred queue filling runs in PendSV at the lowest NVIC priority.#364

Open
Tyuyt3975 wants to merge 43 commits into
gin66:masterfrom
Tyuyt3975:master

Conversation

@Tyuyt3975

Copy link
Copy Markdown

Summary

Add full STM32 platform support to FastAccelStepper via a new pd_stm32 backend, enabling stepper motor control on STM32 microcontrollers using the Arduino framework (stm32duino).

What's changed

New platform driver (src/pd_stm32/)

  • stm32_queue.cpp / stm32_queue.h: timer-based step queue using hardware TIM capture-compare. Supports three timer groups across all major STM32 families:
    • Group A (C0, G0): TIM3 16-bit
    • Group B (F1, L0, L1): TIM2 16-bit
    • Group C (F0, F2, F3, F4, F7, G4, H5, H7, L4, L5, U5, WB, WBA): TIM2 32-bit
  • pd_config.h: compile-time TICKS_PER_S with per-family prescaler documentation, queue topology, and feature flags
  • src/fas_arch/arduino_stm32.h: arch detection header (FAS_STM32)
  • Runtime getTimClock() with dedicated H5xx branch using RCC->CFGR2
  • fas_stm32_clock_error diagnostic: detects non-integer prescaler (= 2) or unsupported clock (= 1)
  • ISR hardening: spurious-interrupt guard per channel; STEP_PULSE_WIDTH_TICKS pulse control
  • H743 H5xx family detection via full product-line macro expansion (no assumption on CMSIS short names)

CI: 5 STM32 boards added to build matrix

Board MCU TICKS_PER_S Timer
bluepill_f103c8 STM32F103 18 000 000 (72M÷4) TIM2 16-bit
nucleo_g070rb STM32G070 16 000 000 (default) TIM3 16-bit
blackpill_f401cc STM32F401 16 800 000 (84M÷5) TIM2 32-bit
nucleo_h743zi STM32H743 20 000 000 (200M÷10) TIM2 32-bit
nucleo_l476rg STM32L476 16 000 000 (default) TIM2 32-bit

All 5 boards pass 19 examples × 5 boards = 95 builds in build_arduino_examples_matrix.yml.

Example compatibility

  • All 19 standard examples updated to compile on STM32 (#ifdef ARDUINO_ARCH_STM32 guards for pin assignments)
  • Complex examples and issue reproductions also updated

Testing

  • ✅ All 5 STM32 boards: CI green (GitHub Actions Build examples)
  • ✅ All 4 regression boards unchanged: AVR, ESP32, SAM, PICO
  • fas_stm32_clock_error validated for G070 (exact 16MHz) and H743 (non-integer prescaler path)

Notes

  • TICKS_PER_S must match a value in RampCalculator.h (16M, 16.8M, 18M, 20M); a #error fires at compile time otherwise
  • Prescaler selection is conservative: always rounds down to avoid exceeding TICKS_PER_S, then sets fas_stm32_clock_error = 2 if rounding occurred
  • No changes to AVR / ESP32 / SAM / PICO / RP2040 backends

KienTranCNC and others added 30 commits May 11, 2026 16:54
- Phase 2A: Spurious interrupt guard (FAS_SPURIOUS_MAX counter + channel disable)
- Phase 2B: FreeRTOS compile-time warning (configUSE_PORT_OPTIMISED_TASK_SELECTION)
- Phase 2C: NVIC priority documentation for jitter protection
- README: enhanced FreeRTOS compatibility section
- Phase 2A: Spurious interrupt guard (FAS_SPURIOUS_MAX counter + channel disable)
- Phase 2B: FreeRTOS compile-time warning (configUSE_PORT_OPTIMISED_TASK_SELECTION)
- Phase 2C: NVIC priority documentation for jitter protection
- README: enhanced FreeRTOS compatibility section
…in the G0 framework), now PASS with 16-bit TIM3
framework-arduinostm32@4.21200.0 for the Nucleo G070RB defines STM32G070xx (in the variant file); it DOES NOT define STM32G0 or STM32G0xx.

The current code aliases STM32G0 → STM32G0xx (lines 23-25), but it fails to catch STM32G070xx:
@Tyuyt3975

Copy link
Copy Markdown
Author

Dear @gin66,

I'm reaching out regarding PR #364 (STM32 backend support). I have successfully run and passed the CI compile workflows on my local fork across the complete STM32 test matrix.

Since this is a new contribution, the GitHub Actions workflows are currently pending your approval ("Action required"). Could you please approve and run the workflows so the automated checks can proceed on this repository?

The PR is fully ready for your review whenever you have the time.

Thank you!

@gin66

gin66 commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Great. Now all build tests pass and nothing is broken. How is the test on HW going ?

@Tyuyt3975

Copy link
Copy Markdown
Author

Dear gin66,
I will test on HW with at least 3 different STM boards over the next few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants