77* allows up to 200000 generated steps per second
88* RP2040 has two PIO blocks and RP2350 has three. Each block has four state
99 machines, and one loaded stepper program serves that block's free machines.
10- The builds offer 8 queues on the Pico and 12 on the Pico 2.
10+ The builds offer up to 8 queues on the Pico and 12 on the Pico 2; a
11+ ` __FREERTOS ` build gives 7 and 11 because the core's PIO cycle counter
12+ holds one machine.
1113* RISC-V is the Pico 2 only. The RP2040 has no RISC-V core.
12- * Measured on 2026-11-08 with ` -D__FREERTOS=1 ` on a Pico 2: ** 11 steppers
13- connect and the twelfth is refused** . One PIO block holds the core's 2-word
14- cycle counter and still serves three steppers, so the count is 4 + 4 + 3.
15- The Pico (RP2040) has not been re-measured; the same mechanism should give
16- 7 of its 8 queues.
14+ * Measured on 2026-11-08 on a Pico 2: ** 12 steppers connect and the
15+ thirteenth is refused** without ` __FREERTOS ` , because the core takes its
16+ SysTick cycle counter and spends no PIO state machine on it. With
17+ ` -D__FREERTOS=1 ` the core's 2-word PIO ` ccount ` program holds one machine;
18+ the relocatable stepper program fits beside it, so that block still serves
19+ three and the count is 11. The Pico (RP2040) no-` __FREERTOS ` count is
20+ expected to be 8; with ` __FREERTOS ` it is expected to be 7 (4 was measured
21+ before the 27-word program). RISC-V has no SysTick path, so a RISC-V Pico 2
22+ connects 11 either way.
1723* On the Pico 2 the step pins must be in 16..31 to reach all three blocks:
1824 PIO0/PIO1 cover 0..31 and PIO2's window starts at 16. Below 16 the first two
1925 blocks take every pin and PIO2 is never reached. The count probe is
@@ -29,10 +35,15 @@ three pios. Each pio contains four state machines and every state machine can
2935drive one stepper. ` claim_pio_resources() ` claims every free state machine of a
3036block and loads the 27-word program once, so all claimed machines share it.
3137
38+ The Pico driver runs with or without the core's FreeRTOS SMP. With
39+ ` __FREERTOS ` defined, a FreeRTOS task calls ` manageSteppers() ` ; without it, a
40+ Pico repeating timer (alarm pool) calls the same function at the same rate.
41+ The choice also decides the cycle counter, see below.
42+
3243SoftwareSerial is implemented via pio, too. The program is relocatable, so a
3344block that already holds another program is still usable when 27 free words
34- remain. The cycle counter holds 2 words, so its block still serves three
35- steppers.
45+ remain. In a ` __FREERTOS ` build the cycle counter holds 2 words, so its block
46+ still serves three steppers; without ` __FREERTOS ` no block is reserved .
3647
3748## Cycle-counter state machine
3849
@@ -63,27 +74,28 @@ No flag in `begin()` skips the program when `__riscv` is set.
6374
6475` PIOProgram::prepare() ` (` cores/rp2040/PIOProgram.cpp ` ) adds those 2 words
6576with ` pio_add_program ` at a free origin. The stepper program is 27 words and
66- relocatable, so it fits beside them (29 of 32 words) and the block keeps its
67- three free state machines for steppers.
68-
69- Every Pico environment in ` extras/ci/platformio.ini ` passes
70- ` build_flags = -D__FREERTOS=1 ` . On 6.1.0 that macro is the preprocessor
71- symbol in the ` #if ` above (the core's own FreeRTOS menu uses ` -D__FREERTOS ` ).
72- Cortex with the macro defined takes the PIO path. RISC-V takes it because
73- ` __riscv ` is set. RISC-V exists on the RP2350 only. The RP2040 image is
74- Cortex. With the counter loaded it connects 4 steppers, measured on
75- ` /dev/cu.usbmodem4101 ` .
77+ relocatable, so in the ` __FREERTOS ` build it fits beside them (29 of 32 words)
78+ and the block keeps its three free state machines for steppers. Without
79+ ` __FREERTOS ` on Cortex the ` #if ` takes the SysTick branch, no ccount program
80+ is loaded, and all four machines on every block stay free.
81+
82+ The CI has both variants. ` rpipico ` and ` rpipico2 ` define
83+ ` -D__FREERTOS=1 ` ; ` rpipico2_nofreertos ` does not. On 6.1.0 the macro in the
84+ ` #if ` above is exactly ` __FREERTOS ` (the core's FreeRTOS menu also sets
85+ ` -D__FREERTOS ` ). Cortex with the macro defined takes the PIO path; without it
86+ it takes SysTick. RISC-V takes the PIO path because ` __riscv ` is set, with or
87+ without ` __FREERTOS ` . RISC-V exists on the RP2350 only; the RP2040 is Cortex.
7688
7789The previous wording on this page said the Arduino core allocates one PIO
7890when the build is not RISC-V, and that a RISC-V build can use every stepper.
7991That wording does not match ` begin() ` in 6.1.0.
8092
81- ** Verified on the ` rpipico2 ` compile line (2026-11-08).**
82- ` RP2040Support.cpp ` is compiled with ` -D__FREERTOS=1 ` . ` build_flags ` does
83- reach the core. The same command has ` -DF_CPU=150000000L ` . ` boards.txt `
84- in the core package says 125 MHz for ` rpipico2 ` ; the PlatformIO board
85- the saleae env resolves overrides that to 150 MHz. One PIO cycle on this
86- firmware is 1/150 MHz.
93+ ** Verified on the compile lines (2026-11-08).** ` rpipico2 ` compiles
94+ ` RP2040Support.cpp ` with ` -D__FREERTOS=1 ` ; ` rpipico2_nofreertos ` does not.
95+ ` build_flags ` reaches the core either way. Both commands have
96+ ` -DF_CPU=150000000L ` . ` boards.txt ` in the core package says 125 MHz for
97+ ` rpipico2 ` ; the PlatformIO board the saleae env resolves overrides that to
98+ 150 MHz. One PIO cycle on that firmware is 1/150 MHz.
8799
88100** Measured on a Pico 2, Cortex, 2026-11-08, before the 27-word program.**
89101Env ` rpipico2 ` with ` -D__FREERTOS=1 ` . A throwaway sketch called
@@ -95,12 +107,13 @@ counter's block was lost. The Pico (RP2040) measured 4 of 8 for the same
95107reason.
96108
97109** Measured on a Pico 2, Cortex, 2026-11-08, with the 27-word relocatable
98- program.** ` extras/tests/pico_stepper_count ` connects GPIO 16 through 31 and
99- reports ** 11 connected, first failure at 27** . The counter's block contributes
100- three state machines and the other two blocks four each. GPIO 16..31 is the
101- range inside all three PIO windows: PIO0/PIO1 cover 0..31 and PIO2 starts at
102- 16 . Below 16 the first two blocks take every pin, PIO2 is never reached, and
103- the count is 8.
110+ program.** ` extras/tests/pico_stepper_count ` connects GPIO 16 through 31.
111+ Without ` __FREERTOS ` it reports ** 12 connected, first failure at 28** : all
112+ three blocks serve four state machines. With ` -D__FREERTOS=1 ` it reports
113+ ** 11 connected, first failure at 27** : the ccount block contributes three
114+ machines and the other two blocks four each. GPIO 16..31 is the range inside
115+ all three PIO windows: PIO0/PIO1 cover 0..31 and PIO2 starts at 16. Below 16
116+ the first two blocks take every pin, PIO2 is never reached, and the count is 8.
104117
105118The Saleae firmware cannot make this count: ` SALEAE_STEPPER_BOUND ` in
106119` extras/tests/saleae_based/common/saleae_app.cpp ` is 8 and the analyzer has 8
@@ -112,7 +125,10 @@ USB comes up on that image. The image built with `-D__FREERTOS=1` still
112125does not. Before any stepper program is added, PIO2 has one state
113126machine claimed. A 30-word program fits there and a 31-word program
114127does not, so that block holds 2 instruction words. PIO0 and PIO1 are
115- empty. This measurement predates the 27-word relocatable program.
128+ empty. This measurement predates the 27-word relocatable program. RISC-V
129+ has no SysTick branch, so it takes this PIO path with or without
130+ ` __FREERTOS ` ; with the 27-word program the block keeps three machines and
131+ the count should be 11 (not re-measured on RISC-V).
116132
117133` pio_can_add_program ` builds its occupancy mask with ` 1u << length ` .
118134A shift of 32 is undefined. This RISC-V compiler emits ` bset ` of bit
@@ -134,17 +150,18 @@ No Pico environment in this tree uses a `framework` other than `arduino`.
134150` src/fas_arch/common.h ` also has a branch on ` PICO_SDK_RP2350 ` . That macro
135151is not defined by pico-sdk or by framework-arduinopico 6.1.0 (it occurs only
136152in this repository). The header it selects, ` src/fas_arch/pico_sdk_rp_pico.h ` ,
137- calls FreeRTOS ` portENTER_CRITICAL ` / ` portEXIT_CRITICAL ` , and
138- ` src/pd_pico/pd_config.h ` includes ` FreeRTOS.h ` . That branch is not a
139- bare-metal port, and it is not built in CI.
153+ calls FreeRTOS ` portENTER_CRITICAL ` / ` portEXIT_CRITICAL ` , and has no
154+ bare-metal task source. That branch still requires FreeRTOS, and it is not
155+ built in CI. (The Arduino branch now builds either way.)
140156
141157The cycle counter is started by the Arduino class ` RP2040::begin() ` . A
142158pico-sdk image does not call it. In the pico-sdk shipped inside
143159framework-arduinopico 6.1.0, the only ` pio_add_program ` is the implementation
144160in ` hardware_pio/pio.c ` . A non-Arduino image therefore keeps every PIO block,
145161on Cortex and on RISC-V. FastAccelStepper still has to be ported to build
146- that way: the hook that exists today requires FreeRTOS, and no such platform
147- is packaged here.
162+ that way: the ` PICO_SDK_RP2350 ` hook uses FreeRTOS critical sections and
163+ requires FreeRTOS, and no such platform is packaged here. (The Arduino hook
164+ now builds with or without ` __FREERTOS ` ; see the section above.)
148165
149166` platform = raspberrypi ` from the PlatformIO registry is a separate failure
150167(issue #339 ). Version 1.20.0 ships only the Arduino ** mbed** core
@@ -163,7 +180,9 @@ not run at the same time.
163180Step edges are produced by the PIO at ` clk_sys ` . Comparing step periods
164181between ` rpipico2 ` and ` rpipico2-riscv ` on a logic analyzer measures the PIO
165182clock, which is the same clock. It does not measure which CPU is faster.
166- The comparison that tests this page is how many steppers connect.
183+ The comparison that tests this page is how many steppers connect: 12 for the
184+ no-` __FREERTOS ` Cortex build, 11 for the FreeRTOS build and 11 for RISC-V
185+ (which always takes the PIO cycle counter).
167186
168187Which core finishes a given integer workload first depends on that code.
169188A secondary CoreMark table (kreier.github.io/benchmark/CoreMark, update
@@ -183,8 +202,9 @@ Integration with applications using pio: `claim_pio_resources()` claims every
183202free state machine of a block and keeps the ones it does not use, so another
184203PIO caller cannot be told the block is empty. With every block free the first
185204block serves four steppers and the second the next four; on the Pico 2 the
186- third serves the next four. The cycle-counter block keeps three free machines
187- and serves three. All claimed machines on a block share one 27-word
205+ third serves the next four, for 12 in the no-` __FREERTOS ` build. In a
206+ ` __FREERTOS ` build the cycle-counter block keeps three free machines and
207+ serves three, for 11. All claimed machines on a block share one 27-word
188208relocatable program, so 5 of the 32 words remain free on that block.
189209
190210## Loop budget, measured
0 commit comments