Datasheet

Table Of Contents
WARNING
Sampling a metastable input can lead to unpredictable state machine behaviour. This should be avoided.
3.5.7. Forced and EXEC’d Instructions
Besides the instruction memory, state machines can execute instructions from 3 other sources:
MOV EXEC which executes an instruction from some register Source
OUT EXEC which executes data shifted out from the OSR
The SMx_INSTR control registers, to which the system can write instructions for immediate execution
Ê1 .program exec_example
Ê2
Ê3 hang:
Ê4 jmp hang
Ê5 execute:
Ê6 out exec, 32
Ê7 jmp execute
Ê8
Ê9 .program instructions_to_push
10
11 out x, 32
12 in x, 32
13 push
Ê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 "exec_example.pio.h"
Ê9
10 int main()
11 {
12 tb_init();
13
14 for (int i = 0; i < count_of(exec_example_program); ++i)
15 mm_pio->instr_mem[i] = exec_example_program[i];
16
17 // Enable autopull, threshold of 32
18 mm_pio->sm[0].shiftctrl = (1u << PIO_SM0_SHIFTCTRL_AUTOPULL_LSB);
19
20 // Start state machine 0 -- will sit in "hang" loop
21 hw_set_bits(&mm_pio->ctrl, 1u << (PIO_CTRL_SM_ENABLE_LSB + 0));
22
23 // Force a jump to program location 1
24 mm_pio->sm[0].instr = 0x0000 | 0x1; // jmp execute
25
26 // Feed a mixture of instructions and data into FIFO
27 mm_pio->txf[0] = instructions_to_push_program[0]; // out x, 32
28 mm_pio->txf[0] = 12345678; // data to be OUTed
29 mm_pio->txf[0] = instructions_to_push_program[1]; // in x, 32
RP2040 Datasheet
3.5. Functional Details 342