Datasheet

Table Of Contents
1 .program autopull
2 .side_set 1
3
4 .wrap_target
5 out pins, 1 side 0 [1]
6 nop side 1 [1]
7 .wrap
This is shorter and simpler than the original, and can run twice as fast, if the delay cycles are removed, since the hardware
refills the OSR "for free". Note that the program does not determine the total number of bits to be shifted before the next
pull; the hardware automatically pulls once the programmable threshold, SHIFCTRL_PULL_THRESH, is reached, so the same
program could also shift out e.g. 16 or 32 bits from each FIFO word.
Finally, note that the above program is not exactly the same as the original, since it stalls with the clock output low, rather
than high. We can change the location of the stall, using the PULL IFEMPTY instruction, which uses the same configurable
threshold as autopull:
1 .program somewhat_manual_pull
2 .side_set 1
3
4 .wrap_target
5 out pins, 1 side 0 [1]
6 pull ifempty side 1 [1]
7 .wrap
Below is a complete example (PIO program, plus a C program to load and run it) which illustrates autopull and autopush
both enabled on the same state machine. It programs state machine 0 to loopback data from the TX FIFO to the RX FIFO,
with a throughput of one word per two clocks. It also demonstrates how the state machine will stall if it tries to OUT when
both the OSR and TX FIFO are empty.
1 .program auto_push_pull
2
3 .wrap_target
4 out x, 32
5 in x, 32
6 .wrap
Ê1 #include "tb.h" // TODO this is built against existing sw tree, so that we get printf etc
Ê2
Ê3 #include "platform.h"
Ê4 #include "pio_regs.h"
Ê5 #include "system.h"
Ê6 #include "hardware.h"
Ê7
Ê8 #include "auto_push_pull.pio.h"
Ê9
10 int main()
11 {
12 tb_init();
13
14 // Load program and configure state machine 0 for autopush/pull with
15 // threshold of 32, and wrapping on program boundary. A threshold of 32 is
16 // encoded by a register value of 00000.
17 for (int i = 0; i < count_of(auto_push_pull_program); ++i)
RP2040 Datasheet
3.5. Functional Details 336