2.3. Processor subsystem

The RP2040 processor subsystem consists of two Arm Cortex-M0+ processors – each with its standard internal Arm CPU peripherals – alongside external peripherals for GPIO access and inter-core communication. Details of the Arm Cortex-M0+ processors, including the specific feature configuration used on RP2040, can be found in Section 2.4 .

Figure 6. Two Cortex-M0+ processors, each with a dedicated 32-bit AHB-Lite bus port, for code fetch, loads and stores. The SIO is connected to the single-cycle IOPORT bus of each processor, and provides GPIO access, two-way communications, and other core-local peripherals. Both processors can be debugged via a single multi-drop Serial Wire Debug bus. 26 interrupts (plus NMI) are routed to the NVIC and WIC on each processor.

Figure 6: Block diagram of the RP2040 processor subsystem. It shows two identical blocks for Core 0 and Core 1, each containing an NVIC, DAP, Cortex-M0+, and Bus Interface. 'From peripherals' sends 'Interrupts' to both NVICs. 'From external debugger' connects via 'Serial Wire Debug' to both DAPs. Between the cores is an 'Events' line. Below the cores is the 'SIO' block, connected to each core's 'Bus Interface' via 'IOPORT' lines. The SIO has a 'GPIO x36' connection 'To GPIO Muxing'. Each core's 'Bus Interface' also has an 'AHB-Lite' connection 'To bus fabric'.
Figure 6: Block diagram of the RP2040 processor subsystem. It shows two identical blocks for Core 0 and Core 1, each containing an NVIC, DAP, Cortex-M0+, and Bus Interface. 'From peripherals' sends 'Interrupts' to both NVICs. 'From external debugger' connects via 'Serial Wire Debug' to both DAPs. Between the cores is an 'Events' line. Below the cores is the 'SIO' block, connected to each core's 'Bus Interface' via 'IOPORT' lines. The SIO has a 'GPIO x36' connection 'To GPIO Muxing'. Each core's 'Bus Interface' also has an 'AHB-Lite' connection 'To bus fabric'.

i NOTE

The terms core0 and core1 , proc0 and proc1 are used interchangeably in RP2040's registers and documentation to refer to processor 0, and processor 1 respectively.

The processors use a number of interfaces to communicate with the rest of the system:

2.3.1. SIO

The Single-cycle IO block (SIO) contains several peripherals that require low-latency, deterministic access from the processors. It is accessed via each processor's IOPORT: this is an auxiliary bus port on the Cortex-M0+ which can perform rapid 32-bit reads and writes. The SIO has a dedicated bus interface for each processor's IOPORT, as shown in Figure 7 . Processors access their IOPORT with normal load and store instructions, directed to the special IOPORT address segment, 0xd0000000...0xdfffffff. The SIO appears as memory-mapped hardware within the IOPORT space.

i NOTE

The SIO is not connected to the main system bus due to its tight timing requirements. It can only be accessed by the processors, or by the debugger via the processor debug ports.

Figure 7. The single-cycle IO block contains memory-mapped hardware which the processors must be able to access quickly. The FIFOs and spinlocks support message passing and synchronisation between the two cores. The shared GPIO registers provide fast and concurrency-safe direct access to GPIO-capable pins. Some core-local arithmetic hardware can be used to accelerate common tasks on the processors.

Diagram of the single-cycle IO block architecture showing Core 0 and Core 1 connected via IOPORTs to a central block containing various peripherals.

The diagram illustrates the single-cycle IO block architecture. Two cores, Core 0 and Core 1, are shown at the top, each connected to the system via an IOPORT. These IOPORTs connect to a central block labeled 'Single-cycle IO'. Inside this block, there are two 'Bus Interface' blocks, one for each core. Between these interfaces are several shared peripherals: 'CPUID 0' and 'CPUID 1' (each connected to its respective core interface), 'FIFO 0 to 1' and 'FIFO 1 to 0' (bidirectional), 'Hardware Spinlock x32', and three pairs of arithmetic units: 'Integer Divider', 'Interpolator 0', and 'Interpolator 1'. At the bottom of the central block is a large 'GPIO Registers Shared, atomic set/clear/xor' block. This block is connected to the bus interfaces and has a 'GPIO x36' output line leading to 'To GPIO Muxing'.

Diagram of the single-cycle IO block architecture showing Core 0 and Core 1 connected via IOPORTs to a central block containing various peripherals.

All IOPORT reads and writes (and therefore all SIO accesses) take place in exactly one cycle, unlike the main AHB-Lite system bus, where the Cortex-M0+ requires two cycles for a load or store, and may have to wait longer due to contention from other system bus masters. This is vital for interfaces such as GPIO, which have tight timing requirements.

SIO registers are mapped to word-aligned addresses in the range 0xd0000000...0xd000017c. The remainder of the IOPORT space is reserved for future use.

The SIO peripherals are described in more detail in the following sections.

2.3.1.1. CPUID

The register CPUID is the first register in the IOPORT space. Core 0 reads a value of 0 when accessing this address, and core 1 reads a value of 1. This is a convenient method for software to determine on which core it is running. This is checked during the initial boot sequence: both cores start running simultaneously, core 1 goes into a deep sleep state, and core 0 continues with the main boot sequence.

! IMPORTANT

CPUID should not be confused with the Cortex-M0+ CPUID register (Section 2.4.4.1.1) on each processor's internal Private Peripheral Bus, which lists the processor's part number and version.

2.3.1.2. GPIO Control

The processors have access to GPIO registers for fast and direct control of pins with GPIO functionality. There are two identical sets of registers:

NOTE

To drive a pin with the SIO's GPIO registers, the GPIO multiplexer for this pin must first be configured to select the SIO GPIO function. See Table 279 .

These GPIO registers are shared between the two cores, and both cores can access them simultaneously. There are three registers for each bank:

Reading GPIO_IN returns all 30 GPIO values (or 6 for GPIO_HI_IN ) in a single read. Software can then mask out individual pins it is interested in.

SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_gpio/include/hardware/gpio.h Lines 859 - 869

859 static inline bool gpio_get(uint gpio) {
860     #ifdef NUM_BANK0_GPIOS <= 32
861         return sio_hw->gpio_in & (1u << gpio);
862     #else
863         if (gpio < 32) {
864             return sio_hw->gpio_in & (1u << gpio);
865         } else {
866             return sio_hw->gpio_hi_in & (1u << (gpio - 32));
867         }
868     #endif
869 }

The OUT and OE registers also have atomic SET, CLR, and XOR aliases, which allows software to update a subset of the pins in one operation. This is vital not only for safe parallel GPIO access between the two cores, but also safe concurrent GPIO access in an interrupt handler and foreground code running on one core.

SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_gpio/include/hardware/gpio.h Lines 908 - 914

908 static inline void gpio_set_mask(uint32_t mask) {
909     #ifdef PICO_USE_GPIO_COPROCESSOR
910         gpior_lo_out_set(mask);
911     #else
912         sio_hw->gpio_set = mask;
913     #endif
914 }

SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_gpio/include/hardware/gpio.h Lines 955 - 961

955 static inline void gpio_clr_mask(uint32_t mask) {
956     #ifdef PICO_USE_GPIO_COPROCESSOR
957         gpior_lo_out_clr(mask);
958     #else
959         sio_hw->gpio_clr = mask;
960     #endif
961 }

SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_gpio/include/hardware/gpio.h Lines 1145 - 1170

1145 static inline void gpio_put(uint gpio, bool value) {
1146 #ifdef PICO_USE_GPIO_COPROCESSOR
1147     gpioc_bit_out_put(gpio, value);
1148 #elif NUM_BANK0_GPIOS <= 32
1149     uint32_t mask = 1ul << gpio;
1150     if (value)
1151         gpio_set_mask(mask);
1152     else
1153         gpio_clr_mask(mask);
1154 #else
1155     uint32_t mask = 1ul << (gpio & 0x1fu);
1156     if (gpio < 32) {
1157         if (value) {
1158             sio_hw->gpio_set = mask;
1159         } else {
1160             sio_hw->gpio_clr = mask;
1161         }
1162     } else {
1163         if (value) {
1164             sio_hw->gpio_hi_set = mask;
1165         } else {
1166             sio_hw->gpio_hi_clr = mask;
1167         }
1168     }
1169 #endif
1170 }

If both processors write to an OUT or OE register (or any of its SET/CLR/XOR aliases) on the same clock cycle, the result is as though core 0 wrote first, and core 1 wrote immediately afterward. For example, if core 0 SETs a bit, and core 1 simultaneously XORs it, the bit will be set to 0, irrespective of its original value.

i NOTE

This is a conceptual model for the result that is produced when two cores write to a GPIO register simultaneously. The register does not actually contain this intermediate value at any point. In the previous example, if the pin is initially 0, and core 0 performs a SET while core 1 performs a XOR, the GPIO output remains low without any positive glitch.

2.3.1.3. Hardware Spinlocks

The SIO provides 32 hardware spinlocks, which can be used to manage mutually-exclusive access to shared software resources. Each spinlock is a one-bit flag, mapped to a different address (from SPINLOCK0 to SPINLOCK31 ). Software interacts with each spinlock with one of the following operations:

If both cores try to claim the same lock on the same clock cycle, core 0 succeeds.

Generally software will acquire a lock by repeatedly polling the lock bit ("spinning" on the lock) until it is successfully claimed. This is inefficient if the lock is held for long periods, so generally the spinlocks should be used to protect the short critical sections of higher-level primitives such as mutexes, semaphores and queues.

For debugging purposes, the current state of all 32 spinlocks can be observed via SPINLOCK_ST .

2.3.1.4. Inter-processor FIFOs (Mailboxes)

The SIO contains two FIFOs for passing data, messages or ordered events between the two cores. Each FIFO is 32 bits wide, and eight entries deep. One of the FIFOs can only be written by core 0, and read by core 1. The other can only be written by core 1, and read by core 0.

Each core writes to its outgoing FIFO by writing to FIFO_WR, and reads from its incoming FIFO by reading from FIFO_RD. A status register, FIFO_ST, provides the following status signals:

Writing to the outgoing FIFO while full, or reading from the incoming FIFO while empty, does not affect the FIFO state. The current contents and level of the FIFO is preserved. However, this does represent some loss of data or reception of invalid data by the software accessing the FIFO, so a sticky error flag is raised ( ROE or WOF).

The SIO has a FIFO IRQ output for each core, mapped to system IRQ numbers 15 and 16. Each IRQ output is the logical OR of the VLD, ROE and WOF bits in that core's FIFO_ST register: that is, the IRQ is asserted if any of these three bits is high, and clears again when they are all low. The ROE and WOF flags are cleared by writing any value to FIFO_ST, and the VLD flag is cleared by reading data from the FIFO until empty.

If the corresponding interrupt line is enabled in the Cortex-M0+ NVIC, then the processor will take an interrupt each time data appears in its FIFO, or if it has performed some invalid FIFO operation (read on empty, write on full). Typically Core 0 will use IRQ15 and core 1 will use IRQ16. If the IRQs are used the other way round then it is difficult for the core that has been interrupted to correctly identify the reason for the interrupt as the core doesn't have access to the other core's FIFO status register.

i NOTE

ROE and WOF only become set if software misbehaves in some way. Generally, the interrupt handler will trigger when data appears in the FIFO (raising the VLD flag), and the interrupt handler clears the IRQ by reading data from the FIFO until VLD goes low once more.

The inter-processor FIFOs and the Cortex-M0+ Event signals are used by the bootrom (Section 2.8) wait_for_vector routine, where core 1 remains in a sleep state until it is woken, and provided with its initial stack pointer, entry point and vector table through the FIFO.

2.3.1.5. Integer Divider

The SIO provides one 8-cycle signed/unsigned divide/modulo module to each of the cores. Calculation is started by writing a dividend and divisor to the two argument registers, DIVIDEND and DIVISOR. The divider calculates the quotient / and remainder % of this division over the next 8 cycles, and on the 9th cycle the results can be read from the two result registers DIV_QUOTIENT and DIV_REMAINDER. A 'ready' bit in register DIV_CSR can be polled to wait for the calculation to complete, or software can insert a fixed 8-cycle delay.

SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_divider/divider.S Lines 12 - 16

12 regular_func_with_section hw_divider_divmod_s32
13     ldr r3, =(SIO_BASE)
14     str r0, [r3, #SIO_DIV_SDIVIDEND_OFFSET]
15     str r1, [r3, #SIO_DIV_SDIVISOR_OFFSET]
16     b hw_divider_divmod_return

Image: Note icon

NOTE

Software is free to perform other non-divider operations during these 8 cycles.

There are two aliases of the operand registers: writing to the signed alias ( DIV_SDIVIDEND and DIV_SDIVISOR ) will initiate a signed calculation, and the other ( DIV_UDIVIDEND and DIV_UDIVISOR ) will initiate an unsigned calculation.

SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_divider/divider.S Lines 20 - 24

20 regular_func_with_section hw_divider_divmod_u32
21     ldr r3, =(SIO_BASE)
22     str r0, [r3, #SIO_DIV_UDIVIDEND_OFFSET]
23     str r1, [r3, #SIO_DIV_UDIVISOR_OFFSET]
24     b hw_divider_divmod_return
  

Image: Note icon

NOTE

A new calculation begins immediately with every write to an operand register, and a new operand write immediately squashes any calculation currently in progress. For example, when dividing many numbers by the same divisor, only xDIVISOR needs to be written, and the signedness of each calculation is determined by whether SDIVIDEND or UDIVIDEND is written.

To support save and restore on interrupt handler entry/exit (or on e.g. an RTOS context switch), the result registers are also writable. Writing to a result register will cancel any operation in progress at the time. The DIV_CSR.DIRTY flag can help make save/restore more efficient: this flag is set when any divider register (operand or result) is written to, and cleared when the quotient is read.

Image: Note icon

NOTE

When enabled, the default divider AEABI support maps C level / and % to the hardware divider. When building software using the SDK and using the divider directly, it is important to read the quotient register last . This ensures the partial divider state will be correctly saved and restored by any interrupt code that uses the divider. You should read the quotient register whether you need the value or not.

The SDK module pico_divider https://github.com/raspberrypi/pico-sdk/blob/master/src/common/pico_divider_headers/include/pico/divider.h provides both the AEABI implementation needed to hook the C / and % operators for both 32-bit and 64-bit integer division, as well as some additional C functions that return quotients and remainders at the same time. All of these functions correctly save and restore the hardware divider state (when dirty) so that they can be used in either user or IRQ handler code.

The SDK module hardware_divider https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_divider/include/hardware/divider.h provides lower level macros and helper functions for accessing the hardware divider, but these do not save and restore the hardware divider state (although this header does provide separate functions to do so).

2.3.1.6. Interpolator

Each core is equipped with two interpolators ( INTERP0 and INTERP1 ) which can accelerate tasks by combining certain pre-configured operations into a single processor cycle. Intended for cases where the pre-configured operation is repeated many times, this results in code which uses both fewer CPU cycles and fewer CPU registers in the time-critical sections of the code.

The interpolators are used to accelerate audio operations within the SDK, but their flexible configuration makes it possible to optimise many other tasks such as quantization and dithering, table lookup address generation, affine texture mapping, decompression and linear feedback.

Figure 8. An interpolator. The two accumulator registers and three base registers have single-cycle read/write access from the processor. The interpolator is organised into two lanes, which perform masking, shifting and sign-extension operations on the two accumulators. This produces three possible results, by adding the intermediate shift/mask values to the three base registers. From left to right, the multiplexers on each lane are controlled by the following flags in the CTRL registers: CROSS_RESULT, CROSS_INPUT, SIGNED, ADD_RAW.

Block diagram of the RP2040 interpolator showing two lanes. Each lane has two accumulators (Accumulator 0 and Accumulator 1) and three base registers (Base 0, Base 1, Base 2). Results 0 and 1 are multiplexed into the accumulators. The accumulators output to a Right Shift block, then a Mask block, and finally a Sign-extend from Mask block. The outputs of these blocks are added to the base registers to produce three results (Result 0, Result 1, Result 2).
Block diagram of the RP2040 interpolator showing two lanes. Each lane has two accumulators (Accumulator 0 and Accumulator 1) and three base registers (Base 0, Base 1, Base 2). Results 0 and 1 are multiplexed into the accumulators. The accumulators output to a Right Shift block, then a Mask block, and finally a Sign-extend from Mask block. The outputs of these blocks are added to the base registers to produce three results (Result 0, Result 1, Result 2).

The processor can write or read any interpolator register in one cycle, and the results are ready on the next cycle. The processor can also perform an addition on one of the two accumulators ACCUM0 or ACCUM1 by writing to the corresponding ACCUMx_ADD register.

The three results are available in the read-only locations PEEK0, PEEK1, PEEK2. Reading from these locations does not change the state of the interpolator. The results are also aliased at the locations POP0, POP1, POP2; reading from a POPx alias returns the same result as the corresponding PEEKx, and simultaneously writes back the lane results to the accumulators. This can be used to advance the state of interpolator each time a result is read.

Additionally the interpolator supports simple fractional blending between two values as well as clamping values such that they lie within a given range.

The following example shows a trivial example of popping a lane result to produce simple iterative feedback.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/interp/hello_interp/hello_interp.c Lines 11 - 23

11 void times_table() {
12     puts("9 times table:");
13
14     // Initialise lane 0 on interp0 on this core
15     interp_config cfg = interp_default_config();
16     interp_set_config(interp0, 0, &cfg);
17
18     interp0->accum[0] = 0;
19     interp0->base[0] = 9;
20
21     for (int i = 0; i < 10; ++i)
22         printf("%d\n", interp0->pop[0]);
23 }

NOTE

By sheer coincidence, the interpolators are extremely well suited to SNES MODE7-style graphics routines. For example, on each core, INTERP0 can provide a stream of tile lookups for some affine transform, and INTERP1 can provide offsets into the tiles for the same transform.

2.3.1.6.1. Lane Operations

Figure 9. Each lane of each interpolator can be configured to perform mask, shift and sign-extension on one of the accumulators. This is fed into adders which produces final results, which may optionally be fed back into the accumulators with each read. The datapath can be configured using a handful of 32-bit multiplexers. From left to right, these are controlled by the following CTRL flags: CROSS_RESULT, CROSS_INPUT, SIGNED, ADD_RAW.

Figure 9: Datapath diagram of an interpolator lane. It shows two 32-bit multiplexers at the input, selecting between Result 0 and Result 1 to feed into Accumulator 0 and Accumulator 1. The outputs of the accumulators are selected by another 32-bit multiplexer and fed into a Right Shift block. The output of the Right Shift block is fed into a Mask block. The output of the Mask block is fed into a Sign-extend from Mask block. The output of the Sign-extend block is fed into two 32-bit multiplexers. The first multiplexer selects between the output of the Sign-extend block and a constant 1, and its output is added to BASE1 (for PEEK0/POP0). The second multiplexer selects between the output of the Sign-extend block and a constant 0, and its output is added to BASE2 (forms part of PEEK2/POP2).
Figure 9: Datapath diagram of an interpolator lane. It shows two 32-bit multiplexers at the input, selecting between Result 0 and Result 1 to feed into Accumulator 0 and Accumulator 1. The outputs of the accumulators are selected by another 32-bit multiplexer and fed into a Right Shift block. The output of the Right Shift block is fed into a Mask block. The output of the Mask block is fed into a Sign-extend from Mask block. The output of the Sign-extend block is fed into two 32-bit multiplexers. The first multiplexer selects between the output of the Sign-extend block and a constant 1, and its output is added to BASE1 (for PEEK0/POP0). The second multiplexer selects between the output of the Sign-extend block and a constant 0, and its output is added to BASE2 (forms part of PEEK2/POP2).

Each lane performs these three operations, in sequence:

For example, if:

Then lane 0 would produce the following results at each stage:

In software:

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/interp/hello_interp/hello_interp.c Lines 25 - 46

25 void moving_mask() {
26     interp_config cfg = interp_default_config();
27     interp0->accum[0] = 0x1234abcd;
28
29     puts("Masking:");
30     printf("ACCUM0 = %08x\n", interp0->accum[0]);
31     for (int i = 0; i < 8; ++i) {
32         // LSB, then MSB. These are inclusive, so 0,31 means "the entire 32 bit register"
33         interp_config_set_mask(&cfg, i * 4, i * 4 + 3);
34         interp_set_config(interp0, 0, &cfg);
35         // Reading from ACCUMx_ADD returns the raw lane shift and mask value, without BASEx
36         printf("Nibble %d: %08x\n", i, interp0->add_raw[0]);
37     }
38
39     puts("Masking with sign extension:");
40     interp_config_set_signed(&cfg, true);
41     for (int i = 0; i < 8; ++i) {
42         interp_config_set_mask(&cfg, i * 4, i * 4 + 3);
43         interp_set_config(interp0, 0, &cfg);
44         printf("Nibble %d: %08x\n", i, interp0->add_raw[0]);
45     }
46 }

The above example should print:

ACCUM0 = 1234abcd
Nibble 0: 0000000d
Nibble 1: 000000c0
Nibble 2: 00000b00
Nibble 3: 0000a000
Nibble 4: 00040000
Nibble 5: 00300000
Nibble 6: 02000000
Nibble 7: 10000000
Masking with sign extension:
Nibble 0: ffffffff
Nibble 1: ffffffff
Nibble 2: fffffb00
Nibble 3: fffa0000
Nibble 4: 00040000
Nibble 5: 00300000
Nibble 6: 02000000
Nibble 7: 10000000

Changing the result and input multiplexers can create feedback between the accumulators. This is useful e.g. for audio dithering.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/interp/hello_interp/hello_interp.c Lines 48 - 66

48 void cross_lanes() {
49     interp_config cfg = interp_default_config();
50     interp_config_set_cross_result(&cfg, true);
51     // ACCUM0 gets lane 1 result:
52     interp_set_config(interp0, 0, &cfg);
53     // ACCUM1 gets lane 0 result:
54     interp_set_config(interp0, 1, &cfg);
55
56     interp0->accum[0] = 123;
57     interp0->accum[1] = 456;
58     interp0->base[0] = 1;
59     interp0->base[1] = 0;
60     puts("Lane result crossover:");
61     for (int i = 0; i < 10; ++i) {
62         uint32_t peek0 = interp0->peek[0];
63         uint32_t pop1 = interp0->pop[1];
64         printf("PEEK0, POP1: %d, %d\n", peek0, pop1);
65     }
66 }

This should print:

PEEK0, POP1: 124, 456
PEEK0, POP1: 457, 124
PEEK0, POP1: 125, 457
PEEK0, POP1: 458, 125
PEEK0, POP1: 126, 458
PEEK0, POP1: 459, 126
PEEK0, POP1: 127, 459
PEEK0, POP1: 460, 127
PEEK0, POP1: 128, 460
PEEK0, POP1: 461, 128

2.3.1.6.2. Blend Mode

Blend mode is available on INTERP0 on each core, and is enabled by the CTRL_LANE0_BLEN0 control flag. It performs linear interpolation, which we define as follows:

\[ x = x_0 + \alpha(x_1 - x_0), \text{ for } 0 \leq \alpha < 1 \]

Where \( x_0 \) is the register BASE0 , \( x_1 \) is the register BASE1 , and \( \alpha \) is a fractional value formed from the least significant 8 bits of the lane 1 shift and mask value.

Blend mode has the following differences from normal mode:

The result of the linear interpolation is equal to BASE0 when the alpha value is 0, and equal to BASE0 + 255/256 * ( BASE1 - BASE0 ) when the alpha value is all-ones.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/interp/hello_interp/hello_interp.c Lines 68 - 87

68 void simple_blend1() {
69     puts("Simple blend 1:");
70
71     interp_config cfg = interp_default_config();
72     interp_config_set_blend(&cfg, true);
73     interp_set_config(interp0, 0, &cfg);
74
75     cfg = interp_default_config();
76     interp_set_config(interp0, 1, &cfg);
77
78     interp0->base[0] = 500;
79     interp0->base[1] = 1000;
80
81     for (int i = 0; i <= 6; i++) {
82         // set fraction to value between 0 and 255
83         interp0->accum[1] = 255 * i / 6;
84         // ≈ 500 + (1000 - 500) * i / 6;
85         printf("%d\n", (int) interp0->peek[1]);
86     }
87 }

This should print (note the 255/256 resulting in 998 not 1000):

500
582
666
748
832
914
998

CTRL_LANE1_SIGNED controls whether BASE0 and BASE1 are sign-extended for this interpolation (this sign extension is required because the interpolation produces an intermediate product value 40 bits in size). CTRL_LANE0_SIGNED continues to control the sign extension of the lane 0 intermediate result in PEEK2, POP2 as normal.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/interp/hello_interp/hello_interp.c Lines 90 - 121

90 void print_simple_blend2_results(bool is_signed) {
91     // lane 1 signed flag controls whether base 0/1 are treated as signed or unsigned
92     interp_config cfg = interp_default_config();
93     interp_config_set_signed(&cfg, is_signed);
94     interp_set_config(interp0, 1, &cfg);
95
96     for (int i = 0; i <= 6; i++) {
97         interp0->accum[1] = 255 * i / 6;
98         if (is_signed) {
99             printf("%d\n", (int) interp0->peek[1]);
100         } else {
101             printf("0x%08x\n", (uint) interp0->peek[1]);
102         }
103     }
104 }
105
106 void simple_blend2() {
107     puts("Simple blend 2:");
108
109     interp_config cfg = interp_default_config();
110     interp_config_set_blend(&cfg, true);
111     interp_set_config(interp0, 0, &cfg);
112
113     interp0->base[0] = (uint32_t) -1000;
114     interp0->base[1] = 1000;
115
116     puts("signed:");
117     print_simple_blend2_results(true);
118
119     puts("unsigned:");
120     print_simple_blend2_results(false);
121 }

This should print:

signed:
-1000
-672
-336
-8
328
656
992
unsigned:
0xffffffc18
0xd5fffd60
0xaaffffeb0
0x80fffff8
0x56000148
0x2c000290
0x010003e0

Finally, in blend mode when using the BASE_1AND0 register to send a 16-bit value to each of BASE0 and BASE1 with a single 32-bit write, the sign-extension of these 16-bit values to full 32-bit values during the write is controlled by CTRL_LANE1_SIGNED for both bases, as opposed to non-blend-mode operation, where CTRL_LANE0_SIGNED affects extension into BASE0 and CTRL_LANE1_SIGNED affects extension into BASE1.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/interp/hello_interp/hello_interp.c Lines 124 - 145

124 void simple_blend3() {
125     puts("Simple blend 3:");
126
127     interp_config cfg = interp_default_config();
128     interp_config_set_blend(&cfg, true);
129     interp_set_config(interp0, 0, &cfg);
130
131     cfg = interp_default_config();
132     interp_set_config(interp0, 1, &cfg);
133
134     interp0->accum[1] = 128;
135     interp0->base01 = 0x30005000;
136     printf("0x%08x\n", (int) interp0->peek[1]);
137     interp0->base01 = 0xe000f000;
138     printf("0x%08x\n", (int) interp0->peek[1]);
139
140     interp_config_set_signed(&cfg, true);
141     interp_set_config(interp0, 1, &cfg);
142
143     interp0->base01 = 0xe000f000;
144     printf("0x%08x\n", (int) interp0->peek[1]);
145 }

This should print:

0x00004000
0x0000e800
0xffffe800

2.3.1.6.3. Clamp Mode

Clamp mode is available on INTERP1 on each core, and is enabled by the CTRL_LANE0_CLAMP control flag. In clamp mode, the PEEK0/POP0 result is the lane value (shifted, masked, sign-extended ACCUM0 ) clamped between BASE0 and BASE1 . In other words, if the lane value is greater than BASE1 , a value of BASE1 is produced; if less than BASE0 , a value of BASE0 is produced; otherwise, the value passes through. No addition is performed. The signedness of these comparisons is controlled by the CTRL_LANE0_SIGNED flag.

Other than this, the interpolator behaves the same as in normal mode.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/interp/hello_interp/hello_interp.c Lines 193 - 211

193 void clamp() {
194     puts("Clamp:");
195     interp_config cfg = interp_default_config();
196     interp_config_set_clamp(&cfg, true);
197     interp_config_set_shift(&cfg, 2);
198     // set mask according to new position of sign bit..
199     interp_config_set_mask(&cfg, 0, 29);
200     // ...so that the shifted value is correctly sign extended
201     interp_config_set_signed(&cfg, true);
202     interp_set_config(interp1, 0, &cfg);
203
204     interp1->base[0] = 0;
205     interp1->base[1] = 255;
206
207     for (int i = -1024; i <= 1024; i += 256) {
208     interp1->accum[0] = i;
209     printf("%d\t%d\n", i, (int) interp1->peek[0]);
210 }
211 }

This should print:

-1024  0
-768   0
-512   0
-256   0
0       0
256    64
512    128
768    192
1024   255

2.3.1.6.4. Sample Use Case: Linear Interpolation

Linear interpolation is a more complete example of using blend mode in conjunction with other interpolator functionality:

In this example, ACCUM0 is used to track a fixed point (integer/fraction) position within a list of values to be interpolated. Lane 0 is used to produce an address into the value array for the integer part of the position. The fractional part of the position is shifted to produce a value from 0-255 for the blend. The blend is performed between two consecutive values in the array.

Finally the fractional position is updated via a single write to ACCUM0_ADD_RAW.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/interp/hello_interp/hello_interp.c Lines 147 - 191

147 void linear_interpolation() {
148     puts("Linear interpolation:");
149     const int uv_fractional_bits = 12;
150
151     // for lane 0
152     // shift and mask XXXX XXXX XXXX XXXX XXXX FFFF FFFF FFFF (accum 0)
153     // to          0000 0000 000X XXXX XXXX XXXX XXXX XXX0
154     // i.e. non fractional part times 2 (for uint16_t)
155     interp_config cfg = interp_default_config();
156     interp_config_set_shift(&cfg, uv_fractional_bits - 1);
157     interp_config_set_mask(&cfg, 1, 32 - uv_fractional_bits);
158     interp_config_set_blend(&cfg, true);
159     interp_set_config(interp0, 0, &cfg);
160
161     // for lane 1
162     // shift XXXX XXXX XXXX XXXX XXXX FFFF FFFF FFFF (accum 0 via cross input)
163     // to      0000 XXXX XXXX XXXX XXXX FFFF FFFF FFFF
164
165     cfg = interp_default_config();
166     interp_config_set_shift(&cfg, uv_fractional_bits - 8);
167     interp_config_set_signed(&cfg, true);
168     interp_config_set_cross_input(&cfg, true); // signed blending
169     interp_set_config(interp0, 1, &cfg);
170
171     int16_t samples[] = {0, 10, -20, -1000, 500};
172
173     // step is 1/4 in our fractional representation
174     uint step = (1 << uv_fractional_bits) / 4;
175
176     interp0->accum[0] = 0; // initial sample_offset;
177     interp0->base[2] = (uintptr_t) samples;
178     for (int i = 0; i < 16; i++) {
179         // result2 = samples + (lane0 raw result)
180         // i.e. ptr to the first of two samples to blend between
181         int16_t *sample_pair = (int16_t *) interp0->peek[2];
182         interp0->base[0] = sample_pair[0];
183         interp0->base[1] = sample_pair[1];
184         uint32_t peek1 = interp0->peek[1];
185         uint32_t add_raw1 = interp0->add_raw[1];
186         printf("%d\t(%d%% between %d and %d)\n", (int) peek1,
187             100 * (add_raw1 & 0xff) / 0xff,
188             sample_pair[0], sample_pair[1]);
189         interp0->add_raw[0] = step;
190     }
191 }

This should print:

0      (0% between 0 and 10)
2      (25% between 0 and 10)
5      (50% between 0 and 10)
7      (75% between 0 and 10)
10     (0% between 10 and -20)
2      (25% between 10 and -20)
-5     (50% between 10 and -20)
-13    (75% between 10 and -20)
-20    (0% between -20 and -1000)
-265   (25% between -20 and -1000)
-510   (50% between -20 and -1000)
-755   (75% between -20 and -1000)
-1000  (0% between -1000 and 500)
-625   (25% between -1000 and 500)
-250   (50% between -1000 and 500)
125    (75% between -1000 and 500)

This method is used for fast approximate audio upscaling in the SDK

2.3.1.6.5. Sample Use Case: Simple Affine Texture Mapping

Simple affine texture mapping can be implemented by using fixed point arithmetic for texture coordinates, and stepping a fixed amount in each coordinate for every pixel in a scanline. The integer part of the texture coordinates are used to form an address within the texture to lookup a pixel colour.

By using two lanes, all three base values and the CTRL_LANE x _ADD_RAW flag, it is possible to reduce what would be quite an expensive CPU operation to a single cycle iteration using the interpolator.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/interp/hello_interp/hello_interp.c Lines 214 - 272

214 void texture_mapping_setup(uint8_t *texture, uint texture_width_bits, uint
    texture_height_bits,
215                          uint uv_fractional_bits) {
216     interp_config cfg = interp_default_config();
217     // set add_raw flag to use raw (un-shifted and un-masked) lane accumulator value when
    adding
218     // it to the lane base to make the lane result
219     interp_config_set_add_raw(&cfg, true);
220     interp_config_set_shift(&cfg, uv_fractional_bits);
221     interp_config_set_mask(&cfg, 0, texture_width_bits - 1);
222     interp_set_config(interp0, 0, &cfg);
223
224     interp_config_set_shift(&cfg, uv_fractional_bits - texture_width_bits);
225     interp_config_set_mask(&cfg, texture_width_bits, texture_width_bits +
texture_height_bits - 1);
226     interp_set_config(interp0, 1, &cfg);
227
228     interp0->base[2] = (uintptr_t) texture;
229 }
230
231 void texture_mapped_span(uint8_t *output, uint32_t u, uint32_t v, uint32_t du, uint32_t dv,
uint count) {
232     // u, v are texture coordinates in fixed point with uv_fractional_bits fractional bits
233     // du, dv are texture coordinate steps across the span in same fixed point.
234     interp0->accum[0] = u;
235     interp0->base[0] = du;
236     interp0->accum[1] = v;
237     interp0->base[1] = dv;
238     for (uint i = 0; i < count; i++) {
239         // equivalent to
240         // uint32_t sm_result0 = (accum0 >> uv_fractional_bits) & (1 << (texture_width_bits -
1);
241         // uint32_t sm_result1 = (accum1 >> uv_fractional_bits) & (1 << (texture_height_bits -
1);
242         // uint8_t *address = texture + sm_result0 + (sm_result1 << texture_width_bits);
243         // output[i] = *address;
244         // accum0 = du + accum0;
245         // accum1 = dv + accum1;
246
247         // result2 is the texture address for the current pixel;
248         // popping the result advances to the next iteration
249         output[i] = *(uint8_t *) interp0->pop[2];
250     }
251 }
252
253 void texture_mapping() {
254     puts("Affine Texture mapping (with texture wrap):");
255
256     uint8_t texture[] = {
257         0x00, 0x01, 0x02, 0x03,
258         0x10, 0x11, 0x12, 0x13,
259         0x20, 0x21, 0x22, 0x23,
260         0x30, 0x31, 0x32, 0x33,
261     };
262     // 4x4 texture
263     texture_mapping_setup(texture, 2, 2, 16);
264     uint8_t output[12];
265     uint32_t du = 65536 / 2; // step of 1/2
266     uint32_t dv = 65536 / 3; // step of 1/3
267     texture_mapped_span(output, 0, 0, du, dv, 12);
268
269     for (uint i = 0; i < 12; i++) {
270         printf("0x%02x\n", output[i]);
271     }
272 }

This should print:

0x00
0x00
0x01
0x01
0x12
0x12
0x13
0x23
0x20
0x20
0x31
0x31

2.3.1.7. List of Registers

The SIO registers start at a base address of 0xd0000000(defined as SIO_BASE in SDK).

Table 16. List of SIO registers

OffsetNameInfo
0x000CPUIDProcessor core identifier
0x004GPIO_INInput value for GPIO pins
0x008GPIO_HI_INInput value for QSPI pins
0x010GPIO_OUTGPIO output value
0x014GPIO_OUT_SETGPIO output value set
0x018GPIO_OUT_CLRGPIO output value clear
0x01cGPIO_OUT_XORGPIO output value XOR
0x020GPIO_OEGPIO output enable
0x024GPIO_OE_SETGPIO output enable set
0x028GPIO_OE_CLRGPIO output enable clear
0x02cGPIO_OE_XORGPIO output enable XOR
0x030GPIO_HI_OUTQSPI output value
0x034GPIO_HI_OUT_SETQSPI output value set
0x038GPIO_HI_OUT_CLRQSPI output value clear
0x03cGPIO_HI_OUT_XORQSPI output value XOR
0x040GPIO_HI_OEQSPI output enable
0x044GPIO_HI_OE_SETQSPI output enable set
0x048GPIO_HI_OE_CLRQSPI output enable clear
0x04cGPIO_HI_OE_XORQSPI output enable XOR
0x050FIFO_STStatus register for inter-core FIFOs (mailboxes).
0x054FIFO_WRWrite access to this core's TX FIFO
0x058FIFO_RDRead access to this core's RX FIFO
0x05cSPINLOCK_STSpinlock state
0x060DIV_UDIVIDENDDivider unsigned dividend
OffsetNameInfo
0x064DIV_UDIVISORDivider unsigned divisor
0x068DIV_SDIVIDENDDivider signed dividend
0x06cDIV_SDIVISORDivider signed divisor
0x070DIV_QUOTIENTDivider result quotient
0x074DIV_REMAINDERDivider result remainder
0x078DIV_CSRControl and status register for divider.
0x080INTERP0_ACCUM0Read/write access to accumulator 0
0x084INTERP0_ACCUM1Read/write access to accumulator 1
0x088INTERP0_BASE0Read/write access to BASE0 register.
0x08cINTERP0_BASE1Read/write access to BASE1 register.
0x090INTERP0_BASE2Read/write access to BASE2 register.
0x094INTERP0_POP_LANE0Read LANE0 result, and simultaneously write lane results to both accumulators (POP).
0x098INTERP0_POP_LANE1Read LANE1 result, and simultaneously write lane results to both accumulators (POP).
0x09cINTERP0_POP_FULLRead FULL result, and simultaneously write lane results to both accumulators (POP).
0x0a0INTERP0_PEEK_LANE0Read LANE0 result, without altering any internal state (PEEK).
0x0a4INTERP0_PEEK_LANE1Read LANE1 result, without altering any internal state (PEEK).
0x0a8INTERP0_PEEK_FULLRead FULL result, without altering any internal state (PEEK).
0x0acINTERP0_CTRL_LANE0Control register for lane 0
0x0b0INTERP0_CTRL_LANE1Control register for lane 1
0x0b4INTERP0_ACCUM0_ADDValues written here are atomically added to ACCUM0
0x0b8INTERP0_ACCUM1_ADDValues written here are atomically added to ACCUM1
0x0bcINTERP0_BASE_1AND0On write, the lower 16 bits go to BASE0, upper bits to BASE1 simultaneously.
0x0c0INTERP1_ACCUM0Read/write access to accumulator 0
0x0c4INTERP1_ACCUM1Read/write access to accumulator 1
0x0c8INTERP1_BASE0Read/write access to BASE0 register.
0x0ccINTERP1_BASE1Read/write access to BASE1 register.
0x0d0INTERP1_BASE2Read/write access to BASE2 register.
0x0d4INTERP1_POP_LANE0Read LANE0 result, and simultaneously write lane results to both accumulators (POP).
0x0d8INTERP1_POP_LANE1Read LANE1 result, and simultaneously write lane results to both accumulators (POP).
0x0dcINTERP1_POP_FULLRead FULL result, and simultaneously write lane results to both accumulators (POP).
0x0e0INTERP1_PEEK_LANE0Read LANE0 result, without altering any internal state (PEEK).
OffsetNameInfo
0x0e4INTERP1_PEEK_LANE1Read LANE1 result, without altering any internal state (PEEK).
0x0e8INTERP1_PEEK_FULLRead FULL result, without altering any internal state (PEEK).
0x0ecINTERP1_CTRL_LANE0Control register for lane 0
0x0f0INTERP1_CTRL_LANE1Control register for lane 1
0x0f4INTERP1_ACCUM0_ADDValues written here are atomically added to ACCUM0
0x0f8INTERP1_ACCUM1_ADDValues written here are atomically added to ACCUM1
0x0fcINTERP1_BASE_1AND0On write, the lower 16 bits go to BASE0, upper bits to BASE1 simultaneously.
0x100SPINLOCK0Spinlock register 0
0x104SPINLOCK1Spinlock register 1
0x108SPINLOCK2Spinlock register 2
0x10cSPINLOCK3Spinlock register 3
0x110SPINLOCK4Spinlock register 4
0x114SPINLOCK5Spinlock register 5
0x118SPINLOCK6Spinlock register 6
0x11cSPINLOCK7Spinlock register 7
0x120SPINLOCK8Spinlock register 8
0x124SPINLOCK9Spinlock register 9
0x128SPINLOCK10Spinlock register 10
0x12cSPINLOCK11Spinlock register 11
0x130SPINLOCK12Spinlock register 12
0x134SPINLOCK13Spinlock register 13
0x138SPINLOCK14Spinlock register 14
0x13cSPINLOCK15Spinlock register 15
0x140SPINLOCK16Spinlock register 16
0x144SPINLOCK17Spinlock register 17
0x148SPINLOCK18Spinlock register 18
0x14cSPINLOCK19Spinlock register 19
0x150SPINLOCK20Spinlock register 20
0x154SPINLOCK21Spinlock register 21
0x158SPINLOCK22Spinlock register 22
0x15cSPINLOCK23Spinlock register 23
0x160SPINLOCK24Spinlock register 24
0x164SPINLOCK25Spinlock register 25
0x168SPINLOCK26Spinlock register 26
0x16cSPINLOCK27Spinlock register 27
OffsetNameInfo
0x170SPINLOCK28Spinlock register 28
0x174SPINLOCK29Spinlock register 29
0x178SPINLOCK30Spinlock register 30
0x17cSPINLOCK31Spinlock register 31

SIO: CPUID Register

Offset: 0x000

Description

Processor core identifier

Table 17. CPUID Register

BitsDescriptionTypeReset
31:0Value is 0 when read from processor core 0, and 1 when read from processor core 1.RO-

SIO: GPIO_IN Register

Offset: 0x004

Description

Input value for GPIO pins

Table 18. GPIO_IN Register

BitsDescriptionTypeReset
31:30Reserved.--
29:0Input value for GPIO0...29RO0x00000000

SIO: GPIO_HI_IN Register

Offset: 0x008

Description

Input value for QSPI pins

Table 19. GPIO_HI_IN Register

BitsDescriptionTypeReset
31:6Reserved.--
5:0Input value on QSPI IO in order 0..5: SCLK, SSn, SD0, SD1, SD2, SD3RO0x00

SIO: GPIO_OUT Register

Offset: 0x010

Description

GPIO output value

Table 20. GPIO_OUT Register

BitsDescriptionTypeReset
31:30Reserved.--
BitsDescriptionTypeReset
29:0Set output level (1/0 → high/low) for GPIO0...29.
Reading back gives the last value written, NOT the input value from the pins.
If core 0 and core 1 both write to GPIO_OUT simultaneously (or to a SET/CLR/XOR alias),
the result is as though the write from core 0 took place first,
and the write from core 1 was then applied to that intermediate result.
RW0x00000000

SIO: GPIO_OUT_SET Register

Offset: 0x014

Description

GPIO output value set

Table 21.
GPIO_OUT_SET
Register

BitsDescriptionTypeReset
31:30Reserved.--
29:0Perform an atomic bit-set on GPIO_OUT, i.e. GPIO_OUT |= wdataWO0x00000000

SIO: GPIO_OUT_CLR Register

Offset: 0x018

Description

GPIO output value clear

Table 22.
GPIO_OUT_CLR
Register

BitsDescriptionTypeReset
31:30Reserved.--
29:0Perform an atomic bit-clear on GPIO_OUT, i.e. GPIO_OUT &= ~wdataWO0x00000000

SIO: GPIO_OUT_XOR Register

Offset: 0x01c

Description

GPIO output value XOR

Table 23.
GPIO_OUT_XOR
Register

BitsDescriptionTypeReset
31:30Reserved.--
29:0Perform an atomic bitwise XOR on GPIO_OUT, i.e. GPIO_OUT ^= wdataWO0x00000000

SIO: GPIO_OE Register

Offset: 0x020

Description

GPIO output enable

Table 24. GPIO_OE
Register

BitsDescriptionTypeReset
31:30Reserved.--
BitsDescriptionTypeReset
29:0Set output enable (1/0 → output/input) for GPIO0...29.
Reading back gives the last value written.
If core 0 and core 1 both write to GPIO_OE simultaneously (or to a SET/CLR/XOR alias),
the result is as though the write from core 0 took place first,
and the write from core 1 was then applied to that intermediate result.
RW0x00000000

SIO: GPIO_OE_SET Register

Offset: 0x024

Description

GPIO output enable set

Table 25.
GPIO_OE_SET Register

BitsDescriptionTypeReset
31:30Reserved.--
29:0Perform an atomic bit-set on GPIO_OE, i.e. \( \text{GPIO\_OE} |= \text{wdata} \)WO0x00000000

SIO: GPIO_OE_CLR Register

Offset: 0x028

Description

GPIO output enable clear

Table 26.
GPIO_OE_CLR Register

BitsDescriptionTypeReset
31:30Reserved.--
29:0Perform an atomic bit-clear on GPIO_OE, i.e. \( \text{GPIO\_OE} \&= \sim\text{wdata} \)WO0x00000000

SIO: GPIO_OE_XOR Register

Offset: 0x02c

Description

GPIO output enable XOR

Table 27.
GPIO_OE_XOR
Register

BitsDescriptionTypeReset
31:30Reserved.--
29:0Perform an atomic bitwise XOR on GPIO_OE, i.e. \( \text{GPIO\_OE} \wedge= \text{wdata} \)WO0x00000000

SIO: GPIO_HI_OUT Register

Offset: 0x030

Description

QSPI output value

Table 28.
GPIO_HI_OUT Register

BitsDescriptionTypeReset
31:6Reserved.--
BitsDescriptionTypeReset
5:0Set output level (1/0 → high/low) for QSPI IO0...5.
Reading back gives the last value written, NOT the input value from the pins.
If core 0 and core 1 both write to GPIO_HI_OUT simultaneously (or to a SET/CLR/XOR alias),
the result is as though the write from core 0 took place first,
and the write from core 1 was then applied to that intermediate result.
RW0x00

SIO: GPIO_HI_OUT_SET Register

Offset: 0x034

Description

QSPI output value set

Table 29.
GPIO_HI_OUT_SET
Register

BitsDescriptionTypeReset
31:6Reserved.--
5:0Perform an atomic bit-set on GPIO_HI_OUT, i.e. GPIO_HI_OUT |= wdataWO0x00

SIO: GPIO_HI_OUT_CLR Register

Offset: 0x038

Description

QSPI output value clear

Table 30.
GPIO_HI_OUT_CLR
Register

BitsDescriptionTypeReset
31:6Reserved.--
5:0Perform an atomic bit-clear on GPIO_HI_OUT, i.e. GPIO_HI_OUT &= ~wdataWO0x00

SIO: GPIO_HI_OUT_XOR Register

Offset: 0x03c

Description

QSPI output value XOR

Table 31.
GPIO_HI_OUT_XOR
Register

BitsDescriptionTypeReset
31:6Reserved.--
5:0Perform an atomic bitwise XOR on GPIO_HI_OUT, i.e. GPIO_HI_OUT ^= wdataWO0x00

SIO: GPIO_HI_OE Register

Offset: 0x040

Description

QSPI output enable

Table 32. GPIO_HI_OE
Register

BitsDescriptionTypeReset
31:6Reserved.--
BitsDescriptionTypeReset
5:0Set output enable (1/0 → output/input) for QSPI I00...5.
Reading back gives the last value written.
If core 0 and core 1 both write to GPIO_HI_OE simultaneously (or to a SET/CLR/XOR alias),
the result is as though the write from core 0 took place first,
and the write from core 1 was then applied to that intermediate result.
RW0x00

SIO: GPIO_HI_OE_SET Register

Offset: 0x044

Description

QSPI output enable set

Table 33.
GPIO_HI_OE_SET
Register

BitsDescriptionTypeReset
31:6Reserved.--
5:0Perform an atomic bit-set on GPIO_HI_OE, i.e. GPIO_HI_OE |= wdataWO0x00

SIO: GPIO_HI_OE_CLR Register

Offset: 0x048

Description

QSPI output enable clear

Table 34.
GPIO_HI_OE_CLR
Register

BitsDescriptionTypeReset
31:6Reserved.--
5:0Perform an atomic bit-clear on GPIO_HI_OE, i.e. GPIO_HI_OE &= ~wdataWO0x00

SIO: GPIO_HI_OE_XOR Register

Offset: 0x04c

Description

QSPI output enable XOR

Table 35.
GPIO_HI_OE_XOR
Register

BitsDescriptionTypeReset
31:6Reserved.--
5:0Perform an atomic bitwise XOR on GPIO_HI_OE, i.e. GPIO_HI_OE ^= wdataWO0x00

SIO: FIFO_ST Register

Offset: 0x050

Description

Status register for inter-core FIFOs (mailboxes).

There is one FIFO in the core 0 → core 1 direction, and one core 1 → core 0. Both are 32 bits wide and 8 words deep.

Core 0 can see the read side of the 1 → 0 FIFO (RX), and the write side of 0 → 1 FIFO (TX).

Core 1 can see the read side of the 0 → 1 FIFO (RX), and the write side of 1 → 0 FIFO (TX).

The SIO IRQ for each core is the logical OR of the VLD, WOF and ROE fields of its FIFO_ST register.

Table 36. FIFO_ST Register

BitsDescriptionTypeReset
31:4Reserved.--
3ROE : Sticky flag indicating the RX FIFO was read when empty. This read was ignored by the FIFO.WC0x0
2WOF : Sticky flag indicating the TX FIFO was written when full. This write was ignored by the FIFO.WC0x0
1RDY : Value is 1 if this core's TX FIFO is not full (i.e. if FIFO_WR is ready for more data)RO0x1
0VLD : Value is 1 if this core's RX FIFO is not empty (i.e. if FIFO_RD is valid)RO0x0

SIO: FIFO_WR Register

Offset: 0x054

Table 37. FIFO_WR Register

BitsDescriptionTypeReset
31:0Write access to this core's TX FIFOWF0x00000000

SIO: FIFO_RD Register

Offset: 0x058

Table 38. FIFO_RD Register

BitsDescriptionTypeReset
31:0Read access to this core's RX FIFORF-

SIO: SPINLOCK_ST Register

Offset: 0x05c

Table 39. SPINLOCK_ST Register

BitsDescriptionTypeReset
31:0Spinlock state
A bitmap containing the state of all 32 spinlocks (1=locked).
Mainly intended for debugging.
RO0x00000000

SIO: DIV_UDIVIDEND Register

Offset: 0x060

Table 40. DIV_UDIVIDEND Register

BitsDescriptionTypeReset
31:0Divider unsigned dividend
Write to the DIVIDEND operand of the divider, i.e. the p in \( p / q \) .
Any operand write starts a new calculation. The results appear in QUOTIENT, REMAINDER.
UDIVIDEND/SDIVIDEND are aliases of the same internal register. The U alias starts an unsigned calculation, and the S alias starts a signed calculation.
RW0x00000000

SIO: DIV_UDIVISOR Register

Offset: 0x064

Table 41.
DIV_UDIVISOR
Register

BitsDescriptionTypeReset
31:0Divider unsigned divisor
Write to the DIVISOR operand of the divider, i.e. the q in \( p / q \) .
Any operand write starts a new calculation. The results appear in QUOTIENT, REMAINDER.
UDIVISOR/SDIVISOR are aliases of the same internal register. The U alias starts an unsigned calculation, and the S alias starts a signed calculation.
RW0x00000000

SIO: DIV_SDIVIDEND Register

Offset: 0x068

Table 42.
DIV_SDIVIDEND
Register

BitsDescriptionTypeReset
31:0Divider signed dividend
The same as UDIVIDEND, but starts a signed calculation, rather than unsigned.
RW0x00000000

SIO: DIV_SDIVISOR Register

Offset: 0x06c

Table 43.
DIV_SDIVISOR
Register

BitsDescriptionTypeReset
31:0Divider signed divisor
The same as UDIVISOR, but starts a signed calculation, rather than unsigned.
RW0x00000000

SIO: DIV_QUOTIENT Register

Offset: 0x070

Table 44.
DIV_QUOTIENT
Register

BitsDescriptionTypeReset
31:0Divider result quotient
The result of \( DIVIDEND / DIVISOR \) (division). Contents undefined while CSR_READY is low.
For signed calculations, QUOTIENT is negative when the signs of DIVIDEND and DIVISOR differ.
This register can be written to directly, for context save/restore purposes. This halts any in-progress calculation and sets the CSR_READY and CSR_DIRTY flags.
Reading from QUOTIENT clears the CSR_DIRTY flag, so should read results in the order
REMAINDER, QUOTIENT if CSR_DIRTY is used.
RW0x00000000

SIO: DIV_REMAINDER Register

Offset: 0x074

Table 45.
DIV_REMAINDER
Register

BitsDescriptionTypeReset
31:0Divider result remainder
The result of DIVIDEND % DIVISOR (modulo). Contents undefined while CSR_READY is low.
For signed calculations, REMAINDER is negative only when DIVIDEND is negative.
This register can be written to directly, for context save/restore purposes. This halts any in-progress calculation and sets the CSR_READY and CSR_DIRTY flags.
RW0x00000000

SIO: DIV_CSR Register

Offset: 0x078

Description

Control and status register for divider.

Table 46. DIV_CSR
Register

BitsDescriptionTypeReset
31:2Reserved.--
1DIRTY : Changes to 1 when any register is written, and back to 0 when QUOTIENT is read.
Software can use this flag to make save/restore more efficient (skip if not DIRTY).
If the flag is used in this way, it's recommended to either read QUOTIENT only, or REMAINDER and then QUOTIENT, to prevent data loss on context switch.
RO0x0
0READY : Reads as 0 when a calculation is in progress, 1 otherwise.
Writing an operand (xDIVIDEND, xDIVISOR) will immediately start a new calculation, no matter if one is already in progress.
Writing to a result register will immediately terminate any in-progress calculation and set the READY and DIRTY flags.
RO0x1

SIO: INTERP0_ACCUM0 Register

Offset: 0x080

Table 47.
INTERP0_ACCUM0
Register

BitsDescriptionTypeReset
31:0Read/write access to accumulator 0RW0x00000000

SIO: INTERP0_ACCUM1 Register

Offset: 0x084

Table 48.
INTERP0_ACCUM1
Register

BitsDescriptionTypeReset
31:0Read/write access to accumulator 1RW0x00000000

SIO: INTERP0_BASE0 Register

Offset: 0x088

Table 49.
INTERP0_BASE0
Register

BitsDescriptionTypeReset
31:0Read/write access to BASE0 register.RW0x00000000

SIO: INTERP0_BASE1 Register

Offset: 0x08c

Table 50.
INTERP0_BASE1
Register

BitsDescriptionTypeReset
31:0Read/write access to BASE1 register.RW0x00000000

SIO: INTERP0_BASE2 Register

Offset: 0x090

Table 51.
INTERP0_BASE2
Register

BitsDescriptionTypeReset
31:0Read/write access to BASE2 register.RW0x00000000

SIO: INTERP0_POP_LANE0 Register

Offset: 0x094

Table 52.
INTERP0_POP_LANE0
Register

BitsDescriptionTypeReset
31:0Read LANE0 result, and simultaneously write lane results to both accumulators (POP).RO0x00000000

SIO: INTERP0_POP_LANE1 Register

Offset: 0x098

Table 53.
INTERP0_POP_LANE1
Register

BitsDescriptionTypeReset
31:0Read LANE1 result, and simultaneously write lane results to both accumulators (POP).RO0x00000000

SIO: INTERP0_POP_FULL Register

Offset: 0x09c

Table 54.
INTERP0_POP_FULL
Register

BitsDescriptionTypeReset
31:0Read FULL result, and simultaneously write lane results to both accumulators (POP).RO0x00000000

SIO: INTERP0_PEEK_LANE0 Register

Offset: 0x0a0

Table 55.
INTERP0_PEEK_LANE
0 Register

BitsDescriptionTypeReset
31:0Read LANE0 result, without altering any internal state (PEEK).RO0x00000000

SIO: INTERP0_PEEK_LANE1 Register

Offset: 0x0a4

Table 56.
INTERP0_PEEK_LANE
1 Register

BitsDescriptionTypeReset
31:0Read LANE1 result, without altering any internal state (PEEK).RO0x00000000

SIO: INTERP0_PEEK_FULL Register

Offset: 0x0a8

Table 57.
INTERP0_PEEK_FULL
Register

BitsDescriptionTypeReset
31:0Read FULL result, without altering any internal state (PEEK).RO0x00000000

SIO: INTERP0_CTRL_LANE0 Register

Offset: 0x0ac

Description

Control register for lane 0

Table 58.
INTERP0_CTRL_LANE
0 Register

BitsDescriptionTypeReset
31:26Reserved.--
25OVERF : Set if either OVERF0 or OVERF1 is set.RO0x0
24OVERF1 : Indicates if any masked-off MSBs in ACCUM1 are set.RO0x0
23OVERF0 : Indicates if any masked-off MSBs in ACCUM0 are set.RO0x0
22Reserved.--
21BLEND : Only present on INTERP0 on each core. If BLEND mode is enabled:
- LANE1 result is a linear interpolation between BASE0 and BASE1, controlled by the 8 LSBs of lane 1 shift and mask value (a fractional number between 0 and 255/256ths)
- LANE0 result does not have BASE0 added (yields only the 8 LSBs of lane 1 shift+mask value)
- FULL result does not have lane 1 shift+mask value added (BASE2 + lane 0 shift+mask)
LANE1 SIGNED flag controls whether the interpolation is signed or unsigned.
RW0x0
20:19FORCE_MSB : ORed into bits 29:28 of the lane result presented to the processor on the bus.
No effect on the internal 32-bit datapath. Handy for using a lane to generate sequence of pointers into flash or SRAM.
RW0x0
18ADD_RAW : If 1, mask + shift is bypassed for LANE0 result. This does not affect FULL result.RW0x0
17CROSS_RESULT : If 1, feed the opposite lane's result into this lane's accumulator on POP.RW0x0
16CROSS_INPUT : If 1, feed the opposite lane's accumulator into this lane's shift + mask hardware.
Takes effect even if ADD_RAW is set (the CROSS_INPUT mux is before the shift+mask bypass)
RW0x0
15SIGNED : If SIGNED is set, the shifted and masked accumulator value is sign-extended to 32 bits before adding to BASE0, and LANE0 PEEK/POP appear extended to 32 bits when read by processor.RW0x0
Bits 14:10 9:5 4:0 BitsDescription SHIFT DescriptionMASK_MSB : The most-significant bit allowed to pass by the mask (inclusive) MASK_LSB : The least-significant bit allowed to pass by the mask (inclusive) : Logical right-shift applied to accumulator before maskingType RW RW RW TypeReset 0x00 0x00 0x00 Reset
1 Register 31:21Reserved.--
20:19FORCE_MSB sequence: ORed into bits 29:28 of the lane result presented to the processor on the bus.RW0x0
18ADD_RAWof pointers into flash or SRAM. : If 1, mask + shift is bypassed for LANE1 result. This does not affect FULL result.RW0x0
17CROSS_RESULT: If 1, feed the opposite lane’s result into this lane’s accumulator on POP.RW0x0
16CROSS_INPUT: If 1, feed the opposite lane’s accumulator into this lane’s shift + mask hardware. Takes effect even if ADD_RAW is set (the CROSS_INPUT mux is before the shift+mask bypass)RW0x0
15SIGNED: If SIGNED is set, the shifted and masked accumulator value is sign- extended to 32 bits before adding to BASE1, and LANE1 PEEK/POP appear extended to 32 bits when read by processor.RW0x0
14:10MASK_MSB: The most-significant bit allowed to pass by the mask (inclusive) Setting MSB < LSB may cause chip to turn inside-outRW0x00
9:5MASK_LSB: The least-significant bit allowed to pass by the mask (inclusive)RW0x00
4:0 SIOSHIFT: Logical right-shift applied to accumulator before masking : INTERP0_ACCUM0_ADD RegisterRW0x00
Table 60. Offset Bits INTERP0_ACCUM0_AD: 0x0b4 DescriptionTypeReset
D Register 31:24Reserved.--
23:0Values written here are atomically added to ACCUM0RW0x000000

SIO: INTERP0_CTRL_LANE1 Register

Offset: 0x0b0

Description

Control register for lane 1

Table 59.
INTERP0_CTRL_LANE1 Register

SIO: INTERP0_ACCUM0_ADD Register

Offset: 0x0b4

Table 60.
INTERP0_ACCUM0_ADD Register

SIO: INTERP0_ACCUM1_ADD Register

Offset: 0x0b8

Table 61.
INTERP0_ACCUM1_AD
D Register

BitsDescriptionTypeReset
31:24Reserved.--
23:0Values written here are atomically added to ACCUM1
Reading yields lane 1's raw shift and mask value (BASE1 not added).
RW0x000000

SIO: INTERP0_BASE_1AND0 Register

Offset: 0x0bc

Table 62.
INTERP0_BASE_1AND
0 Register

BitsDescriptionTypeReset
31:0On write, the lower 16 bits go to BASE0, upper bits to BASE1 simultaneously.
Each half is sign-extended to 32 bits if that lane's SIGNED flag is set.
WO0x00000000

SIO: INTERP1_ACCUM0 Register

Offset: 0x0c0

Table 63.
INTERP1_ACCUM0
Register

BitsDescriptionTypeReset
31:0Read/write access to accumulator 0RW0x00000000

SIO: INTERP1_ACCUM1 Register

Offset: 0x0c4

Table 64.
INTERP1_ACCUM1
Register

BitsDescriptionTypeReset
31:0Read/write access to accumulator 1RW0x00000000

SIO: INTERP1_BASE0 Register

Offset: 0x0c8

Table 65.
INTERP1_BASE0
Register

BitsDescriptionTypeReset
31:0Read/write access to BASE0 register.RW0x00000000

SIO: INTERP1_BASE1 Register

Offset: 0x0cc

Table 66.
INTERP1_BASE1
Register

BitsDescriptionTypeReset
31:0Read/write access to BASE1 register.RW0x00000000

SIO: INTERP1_BASE2 Register

Offset: 0x0d0

Table 67.
INTERP1_BASE2
Register

BitsDescriptionTypeReset
31:0Read/write access to BASE2 register.RW0x00000000

SIO: INTERP1_POP_LANE0 Register

Offset: 0x0d4

Table 68.
INTERP1_POP_LANE0
Register

BitsDescriptionTypeReset
31:0Read LANE0 result, and simultaneously write lane results to both accumulators (POP).RO0x00000000

SIO: INTERP1_POP_LANE1 Register

Offset: 0x0d8

Table 69.
INTERP1_POP_LANE1
Register

BitsDescriptionTypeReset
31:0Read LANE1 result, and simultaneously write lane results to both accumulators (POP).RO0x00000000

SIO: INTERP1_POP_FULL Register

Offset: 0x0dc

Table 70.
INTERP1_POP_FULL
Register

BitsDescriptionTypeReset
31:0Read FULL result, and simultaneously write lane results to both accumulators (POP).RO0x00000000

SIO: INTERP1_PEEK_LANE0 Register

Offset: 0x0e0

Table 71.
INTERP1_PEEK_LANE
0 Register

BitsDescriptionTypeReset
31:0Read LANE0 result, without altering any internal state (PEEK).RO0x00000000

SIO: INTERP1_PEEK_LANE1 Register

Offset: 0x0e4

Table 72.
INTERP1_PEEK_LANE
1 Register

BitsDescriptionTypeReset
31:0Read LANE1 result, without altering any internal state (PEEK).RO0x00000000

SIO: INTERP1_PEEK_FULL Register

Offset: 0x0e8

Table 73.
INTERP1_PEEK_FULL
Register

BitsDescriptionTypeReset
31:0Read FULL result, without altering any internal state (PEEK).RO0x00000000

SIO: INTERP1_CTRL_LANE0 Register

Offset: 0x0ec

Description

Control register for lane 0

Table 74.
INTERP1_CTRL_LANE
0 Register

BitsDescriptionTypeReset
31:26Reserved.--
25OVERF : Set if either OVERF0 or OVERF1 is set.RO0x0
24OVERF1 : Indicates if any masked-off MSBs in ACCUM1 are set.RO0x0
23OVERF0 : Indicates if any masked-off MSBs in ACCUM0 are set.RO0x0
Bits 14:10 9:5 4:0 BitsDescription SHIFT DescriptionMASK_MSB : The most-significant bit allowed to pass by the mask (inclusive) MASK_LSB : The least-significant bit allowed to pass by the mask (inclusive) : Logical right-shift applied to accumulator before maskingType RW RW RW TypeReset 0x00 0x00 0x00 Reset
21Reserved.--
20:19FORCE_MSB sequence: ORed into bits 29:28 of the lane result presented to the processor on the bus.RW0x0
18ADD_RAWof pointers into flash or SRAM. : If 1, mask + shift is bypassed for LANE0 result. This does not affect FULL result.RW0x0
17CROSS_RESULT: If 1, feed the opposite lane’s result into this lane’s accumulator on POP.RW0x0
16CROSS_INPUT: If 1, feed the opposite lane’s accumulator into this lane’s shift + mask hardware. Takes effect even if ADD_RAW is set (the CROSS_INPUT mux is before the shift+mask bypass)RW0x0
15SIGNED: If SIGNED is set, the shifted and masked accumulator value is sign- extended to 32 bits before adding to BASE0, and LANE0 PEEK/POP appear extended to 32 bits when read by processor.RW0x0
14:10MASK_MSB: The most-significant bit allowed to pass by the mask (inclusive) Setting MSB < LSB may cause chip to turn inside-outRW0x00
9:5MASK_LSB: The least-significant bit allowed to pass by the mask (inclusive)RW0x00
4:0 SIOSHIFT: Logical right-shift applied to accumulator before masking : INTERP1_CTRL_LANE1 RegisterRW0x00
Table 75. Description Bits INTERP1_CTRL_LANEDescriptionTypeReset
1 Register 31:21Reserved.--
20:19FORCE_MSB sequence: ORed into bits 29:28 of the lane result presented to the processor on the bus.RW0x0
18ADD_RAWof pointers into flash or SRAM. : If 1, mask + shift is bypassed for LANE1 result. This does not affect FULL result.RW0x0
17CROSS_RESULT: If 1, feed the opposite lane’s result into this lane’s accumulator on POP.RW0x0

SIO: INTERP1_CTRL_LANE1 Register

Offset: 0x0f0

Description

Control register for lane 1

Table 75.
INTERP1_CTRL_LANE1 Register

BitsDescriptionTypeReset
16CROSS_INPUT : If 1, feed the opposite lane's accumulator into this lane's shift + mask hardware.
Takes effect even if ADD_RAW is set (the CROSS_INPUT mux is before the shift+mask bypass)
RW0x0
15SIGNED : If SIGNED is set, the shifted and masked accumulator value is sign-extended to 32 bits before adding to BASE1, and LANE1 PEEK/POP appear extended to 32 bits when read by processor.RW0x0
14:10MASK_MSB : The most-significant bit allowed to pass by the mask (inclusive)
Setting MSB < LSB may cause chip to turn inside-out
RW0x00
9:5MASK_LSB : The least-significant bit allowed to pass by the mask (inclusive)RW0x00
4:0SHIFT : Logical right-shift applied to accumulator before maskingRW0x00

SIO: INTERP1_ACCUM0_ADD Register

Offset: 0x0f4

Table 76.
INTERP1_ACCUM0_ADD
Register

BitsDescriptionTypeReset
31:24Reserved.--
23:0Values written here are atomically added to ACCUM0
Reading yields lane 0's raw shift and mask value (BASE0 not added).
RW0x000000

SIO: INTERP1_ACCUM1_ADD Register

Offset: 0x0f8

Table 77.
INTERP1_ACCUM1_ADD
Register

BitsDescriptionTypeReset
31:24Reserved.--
23:0Values written here are atomically added to ACCUM1
Reading yields lane 1's raw shift and mask value (BASE1 not added).
RW0x000000

SIO: INTERP1_BASE_1AND0 Register

Offset: 0x0fc

Table 78.
INTERP1_BASE_1AND
0 Register

BitsDescriptionTypeReset
31:0On write, the lower 16 bits go to BASE0, upper bits to BASE1 simultaneously.
Each half is sign-extended to 32 bits if that lane's SIGNED flag is set.
WO0x00000000

SIO: SPINLOCK0, SPINLOCK1, ..., SPINLOCK30, SPINLOCK31 Registers

Offsets: 0x100, 0x104, ..., 0x178, 0x17c

Table 79. SPINLOCK0,
SPINLOCK1, ...,
SPINLOCK30,
SPINLOCK31
Registers

BitsDescriptionTypeReset
31:0

Reading from a spinlock address will:

  • - Return 0 if lock is already locked
  • - Otherwise return nonzero, and simultaneously claim the lock

Writing (any value) releases the lock.

If core 0 and core 1 attempt to claim the same lock simultaneously, core 0 wins.

The value returned on success is \( 0x1 \ll \text{lock number} \) .

RW0x00000000

2.3.2. Interrupts

Each core is equipped with a standard ARM Nested Vectored Interrupt Controller (NVIC) which has 32 interrupt inputs. Each NVIC has the same interrupts routed to it, with the exception of the GPIO interrupts: there is one GPIO interrupt per bank, per core. These are completely independent, so e.g. core 0 can be interrupted by GPIO 0 in bank 0, and core 1 by GPIO 1 in the same bank.

On RP2040, only the lower 26 IRQ signals are connected on the NVIC, and IRQs 26 to 31 are tied to zero (never firing). The core can still be forced to enter the relevant interrupt handler by writing bits 26 to 31 in the NVIC ISPR register.

Table 80. Interrupts

IRQInterrupt SourceIRQInterrupt SourceIRQInterrupt SourceIRQInterrupt SourceIRQInterrupt Source
0TIMER_IRQ_06XIP_IRQ12DMA_IRQ_118SPI0_IRQ24I2C1_IRQ
1TIMER_IRQ_17PIO0_IRQ_013IO_IRQ_BANK019SPI1_IRQ25RTC_IRQ
2TIMER_IRQ_28PIO0_IRQ_114IO_IRQ_QSPI20UART0_IRQ
3TIMER_IRQ_39PIO1_IRQ_015SIO_IRQ_PROC021UART1_IRQ
4PWM_IRQ_WRAP10PIO1_IRQ_116SIO_IRQ_PROC122ADC_IRQ_FIFO
5USBCTRL_IRQ11DMA_IRQ_017CLOCKS_IRQ23I2C0_IRQ

i NOTE

XIP_IRQ is from the SSI block that makes up part of the XIP block. It could be used in a configuration where code is running from SRAM instead of flash. In this configuration, the XIP block could be used as a normal SSI peripheral.

Nested interrupts are supported in hardware: a lower-priority interrupt can be preempted by a higher-priority interrupt (or another exception e.g. HardFault), and the lower-priority interrupt will resume once higher-priority exceptions have completed. The priority order is determined by:

Some care has gone into arranging the RP2040 interrupt table to give a sensible default priority ordering, but individual interrupts can be raised or lowered in priority, using NVIC_IPR0 through NVIC_IPR7 , to suit a particular use case.

The 26 system IRQ signals are masked (NMI mask) and then ORed together creating the NMI signal for the core. The NMI mask for each core can be configured using PROC0_NMI_MASK and PROC1_NMI_MASK in the Syscfg register block. Each of these registers has one bit for each system interrupt, and the each core's NMI is asserted if a system interrupt is asserted and the corresponding NMI mask bit is set for that core.

⚠ CAUTION

If the watchdog is armed, and some bits are set on the core 1 NMI mask, the RESETS block (and hence Syscfg) should be included in the watchdog reset list. Otherwise, following a watchdog event, core 1 NMI may be asserted when the core enter the bootrom. It is safe for core 0 to take an NMI when entering the bootrom (the handler will clear the NMI mask).

2.3.3. Event Signals

The Cortex-M0+ can enter a sleep state until an "event" (or interrupt) takes place, using the WFE instruction. It can also generate events, using the SEV instruction. On RP2040 the event signals are cross-wired between the two processors, so that an event sent by one processor will be received on the other.

i NOTE

The event flag is "sticky", so if both processors send an event ( SEV ) simultaneously, and then both go to sleep ( WFE ), they will both wake immediately, rather than getting stuck in a sleep state.

While in a WFE (or WFI ) sleep state, the processor can shut off its internal clock gates, consuming much less power. When both processors are sleeping, and the DMA is inactive, RP2040 as a whole can enter a sleep state, disabling clocks on unused infrastructure such as the busfabric, and waking automatically when one of the processors wakes. See Section 2.11.2 .

2.3.4. Debug

The 2-wire Serial Wire Debug (SWD) port provides access to hardware and software debug features including:

The SWD bus is exposed on two dedicated pins and is immediately available after power-on.

i NOTE

We recommend a max SWD frequency of 24MHz. This depends heavily on your setup. You may need to run much slower (1MHz) depending on the quality and length of your cables.

Debug access is via independent DAPs (one per core) attached to a shared multidrop SWD bus (SWD v2). Each DAP will only respond to debug commands if correctly addressed by a SWD TARGETSEL command; all others tristate their outputs. Additionally, a Rescue DP (see Section 2.3.4.2 ) is available which is connected to system control features. Default addresses of each debug port are given below:

The Instance IDs (top 4 bits of ID above) can be changed via a sysconfig register which may be useful in a multichip application. However note that ID=0xf is reserved for the internal Rescue DP (see Section 2.3.4.2 ).

Figure 10. RP2040 Debugging

Figure 10: RP2040 Debugging block diagram. The diagram shows the internal architecture for debugging. On the left, an IO block contains SWCLK and SWDIO pins. These connect to an SWD Multidrop arbiter. The arbiter is connected to two DAP (Debug Access Port) blocks: DAP_0 (DP-0 AP) and DAP_1 (DP-1 AP). Each DAP block is connected to a corresponding processor core (Core0 and Core1). A Rescue DP block is also connected to the SWD Multidrop arbiter. Control signals include sys_cfg_proc0_dap_instid, sys_cfg_proc1_dap_instid, and pam_restart.
Figure 10: RP2040 Debugging block diagram. The diagram shows the internal architecture for debugging. On the left, an IO block contains SWCLK and SWDIO pins. These connect to an SWD Multidrop arbiter. The arbiter is connected to two DAP (Debug Access Port) blocks: DAP_0 (DP-0 AP) and DAP_1 (DP-1 AP). Each DAP block is connected to a corresponding processor core (Core0 and Core1). A Rescue DP block is also connected to the SWD Multidrop arbiter. Control signals include sys_cfg_proc0_dap_instid, sys_cfg_proc1_dap_instid, and pam_restart.

2.3.4.1. Software control of SWD pins

The SWD pins for Core 0 and Core 1 can be bit-banged via registers in syscfg (see DBGFORCE ). This means that Core 1 could run a USB application that allows debug of Core 0, or similar.

2.3.4.2. Rescue DP

The Rescue DP (debug port) is available over the SWD bus and is only intended for use in the specific case where the chip has locked up, for example if code has been programmed into flash which permanently halts the system clock: in such a case, the normal debugger can not communicate with the processors to return the system to a working state, so more drastic action is needed. A rescue is invoked by setting the CDBGPWRUPREQ bit in the Rescue DP’s CTRL/STAT register.

This causes a hard reset of the chip (functionally similar to a power-on-reset), and sets a flag in the Chip Level Reset block to indicate that a rescue reset took place. The bootrom checks this flag almost immediately in the initial boot process (before watchdog, flash or USB boot), acknowledges by clearing the bit, then halts the processor. This leaves the system in a safe state, with the system clock running, so that the debugger can reattach to the cores and load fresh code.

For a practical example of using the Rescue DP, see the Hardware design with RP2040 book.