add STM32 backend (STM32duino / Arduino_Core_STM32)#359
Open
Tyuyt3975 wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add STM32 backend (STM32duino / Arduino_Core_STM32)
Overview
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.
The implementation has been reviewed across three audit rounds (R1–R3): critical bug fixes, CI/documentation, and line-by-line code verification against STM32duino core headers.
Supported families
New / modified files
Source (4 files)
src/fas_arch/arduino_stm32.hFAS_STM32define, reentrant-safe PRIMASK IRQ control (fasDisableInterrupts/fasEnableInterrupts),FAS_PSTRsrc/pd_stm32/pd_config.hTICKS_PER_S, queue topology, timing constants, feature flagssrc/pd_stm32/stm32_queue.hStepperQueueclass, GPIO BSRR direction macros,setDirPin()with null-checksrc/pd_stm32/stm32_queue.cppNew example file (1)
examples/StepperDemo/StepperPins_stm32.hCI / build (3 files)
extras/ci/build_matrix.yamlextras/ci/platformio.ini.github/workflows/build_arduino_examples_matrix.ymlKey design details
Timer abstraction (
FAS_TIMERmacros)Timer selection is resolved entirely at compile time:
16-bit wrap-safe CCR write (
fas_tim_set_ccr)STM32F1 (TIM2) and STM32C0 (TIM3) have 16-bit ARR. A naïve
CNT + delayoverflows above 65535. The fix:This correctly wraps: if
cnt=65520, delay=432→ target=416, actual ticks =(65536−65520)+416 = 432. ✓Memory barrier (
FAS_DMB)Cortex-M0/M0+ (F0, G0, L0, C0) do not have
__DMB(). The wrapper uses__DSB()on ARMv6-M and__DMB()on ARMv7-M/ARMv8-M.main:Runtime clock validation
initStepTimer()reads the actual APB1 timer clock viagetTimClock()and compares againstTICKS_PER_S. If mismatched, it setsfas_stm32_clock_error(code 1 = impossible, code 2 = non-integer prescaler) and prints a warning toSerialatengine.init().Two independent clock domains
TICKS_PER_S(user-defined at compile time). Determines all motion parameters.uwTick/ SysTick, fires PendSV every ~3 ms. Does not affect step pulse accuracy.Direction pin: atomic BSRR writes
Direction changes use BSRR (set: low half, clear: high half =
mask << 16), valid on all STM32 families. No ODR read-modify-write race condition.CI test matrix (5 boards)
stm32_f103c8stm32_g070rb__DSB()on M0+, 32-bit TIM2stm32_f401ccstm32_h743ziD2CFGRclock detectionstm32_l476rgUsage
In
platformio.ini, defineTICKS_PER_Smatching the board's APB1 timer clock:Deferred (out of scope for this PR)
README.mdWarning Stop and SetCurrentPosition methods #2: update "TIM2 reserved" note to mention TIM3 on C0 (requires manual edit in fork's README)Change summary