2.1. Bus Fabric

The RP2040 bus fabric routes addresses and data across the chip.

Figure 4 shows the high-level structure of the bus fabric. The main AHB-Lite crossbar routes addresses and data between its 4 upstream ports and 10 downstream ports: up to four bus transfers can take place each cycle. All data paths are 32 bits wide. Memory devices have dedicated ports on the main crossbar, to satisfy their high bandwidth requirements. High-bandwidth AHB-Lite peripherals have a shared port on the crossbar, and an APB bridge provides bus access to system control registers and lower-bandwidth peripherals.

Figure 4. RP2040 bus fabric overview.

Figure 4: RP2040 bus fabric overview diagram. The diagram shows the high-level structure of the bus fabric. At the top, two Cortex-M0+ cores (Core 0 and Core 1) are connected to the AHB-Lite Crossbar 4:10. The crossbar has 4 upstream ports and 10 downstream ports. The upstream ports are connected to ROM (16 kB), SRAM0 (64 kB), SRAM1 (64 kB), SRAM2 (64 kB), SRAM3 (64 kB), SRAM4 (4 kB), and SRAM5 (4 kB). The downstream ports are connected to the APB Bridge, Flash XIP, PI00, PI01, and USB. The APB Bridge is connected to the APB Splitter, which routes addresses and data to various APB peripherals: UART0, UART1, SPI0, SPI1, I2C0, I2C1, ADC, PWM, Timer, Watchdog, RTC, and other peripherals and system control registers. The APB Splitter also connects to the AHB-Lite Splitter, which routes addresses and data to the APB Bridge, Flash XIP, PI00, PI01, and USB. The AHB-Lite Splitter also connects to the System DMA (1-Write 1-Read) block, which is connected to the AHB-Lite Crossbar 4:10. The System DMA block is also connected to the AHB-Lite Splitter and the APB Bridge.
Figure 4: RP2040 bus fabric overview diagram. The diagram shows the high-level structure of the bus fabric. At the top, two Cortex-M0+ cores (Core 0 and Core 1) are connected to the AHB-Lite Crossbar 4:10. The crossbar has 4 upstream ports and 10 downstream ports. The upstream ports are connected to ROM (16 kB), SRAM0 (64 kB), SRAM1 (64 kB), SRAM2 (64 kB), SRAM3 (64 kB), SRAM4 (4 kB), and SRAM5 (4 kB). The downstream ports are connected to the APB Bridge, Flash XIP, PI00, PI01, and USB. The APB Bridge is connected to the APB Splitter, which routes addresses and data to various APB peripherals: UART0, UART1, SPI0, SPI1, I2C0, I2C1, ADC, PWM, Timer, Watchdog, RTC, and other peripherals and system control registers. The APB Splitter also connects to the AHB-Lite Splitter, which routes addresses and data to the APB Bridge, Flash XIP, PI00, PI01, and USB. The AHB-Lite Splitter also connects to the System DMA (1-Write 1-Read) block, which is connected to the AHB-Lite Crossbar 4:10. The System DMA block is also connected to the AHB-Lite Splitter and the APB Bridge.

The bus fabric connects 4 AHB-Lite masters, i.e. devices which generate addresses:

These are routed through to 10 downstream ports on the main crossbar:

The four bus masters can access any four different crossbar ports simultaneously, the bus fabric does not add wait

states to any AHB-Lite slave access. So at a system clock of 125MHz the maximum sustained bus bandwidth is 2.0GBps. The system address map has been arranged to make this parallel bandwidth available to as many software use cases as possible – for example, the striped SRAM alias ( Section 2.6.2 ) scatters main memory accesses across four crossbar ports (SRAM0...3), so that more memory accesses can proceed in parallel.

2.1.1. AHB-Lite Crossbar

At the centre of the RP2040 bus fabric is a 4:10 fully-connected crossbar. Its 4 upstream ports are connected to the 4 system bus masters, and the 10 downstream ports connect to the highest-bandwidth AHB-Lite slaves (namely the memory interfaces) and to lower layers of the fabric. Figure 5 shows the structure of a 2:3 AHB-Lite crossbar, arranged identically to the 4:10 crossbar on RP2040, but easier to show in the diagram.

Figure 5. A 2:3 AHB-Lite crossbar. Each upstream port connects to a splitter, which routes bus requests toward one of the 3 downstream ports, and routes responses back. Each downstream port connects to an arbiter, which safely manages concurrent access to the port.

Diagram of a 2:3 AHB-Lite crossbar. It shows two upstream ports (Upstream Port 0 and Upstream Port 1) at the top, each connected to a 1:3 splitter. Below the splitters are three downstream ports (Downstream Port 0, Downstream Port 1, and Downstream Port 2), each connected to a 2:1 arbiter. Bidirectional arrows indicate the flow of requests and responses between the upstream ports, splitters, arbiters, and downstream ports.
graph TD
    U0[Upstream Port 0] <--> S0[Splitter 1:3]
    U1[Upstream Port 1] <--> S1[Splitter 1:3]
    S0 --> A0[Arbiter 2:1]
    S0 --> A1[Arbiter 2:1]
    S0 --> A2[Arbiter 2:1]
    S1 --> A0
    S1 --> A1
    S1 --> A2
    A0 <--> D0[Downstream Port 0]
    A1 <--> D1[Downstream Port 1]
    A2 <--> D2[Downstream Port 2]
Diagram of a 2:3 AHB-Lite crossbar. It shows two upstream ports (Upstream Port 0 and Upstream Port 1) at the top, each connected to a 1:3 splitter. Below the splitters are three downstream ports (Downstream Port 0, Downstream Port 1, and Downstream Port 2), each connected to a 2:1 arbiter. Bidirectional arrows indicate the flow of requests and responses between the upstream ports, splitters, arbiters, and downstream ports.

The crossbar is built from two components:

The main crossbar on RP2040 consists of 4 1:10 splitters and 10 4:1 arbiters, with a mesh of 40 AHB-Lite bus channels between them. Note that, as AHB-Lite is a pipelined bus, the splitter may be routing back a response to an earlier request from downstream port A, whilst a new request to downstream port B is already in progress. This does not incur any cycle penalty.

2.1.1.1. Bus Priority

The arbiters in the main AHB-Lite crossbar implement a two-level bus priority scheme. Priority levels are configured per-master, using the BUS_PRIORITY register in the BUSCTRL register block.

When there are multiple simultaneous accesses to same arbiter, any requests from high-priority masters (priority level 1) will be considered before any requests from low-priority masters (priority 0). If multiple masters of the same priority level attempt to access the same slave simultaneously, a round-robin tie break is applied, i.e. the arbiter grants access to each master in turn.

NOTE

Priority arbitration only applies to multiple masters attempting to access the same slave on the same cycle. Accesses to different slaves, e.g. different SRAM banks, can proceed simultaneously.

When accessing a slave with zero wait states, such as SRAM (i.e. can be accessed once per system clock cycle), high-priority masters will never observe any slowdown or other timing effects caused by accesses from low-priority masters. This allows guaranteed latency and throughput for hard real time use cases; it does however mean a low-priority master may get stalled until there is a free cycle.

2.1.1.2. Bus Performance Counters

The performance counters automatically count accesses to the main AHB-Lite crossbar arbiters. This can assist in diagnosing performance issues, in high-traffic use cases.

There are four performance counters. Each is a 24-bit saturating counter. Counter values can be read from BUSCTRL_PERFCTR x, and cleared by writing any value to BUSCTRL_PERFCTR x. Each counter can count one of the 20 available events at a time, as selected by BUSCTRL_PERFSEL x. The available bus events are:

PERFSEL xEventDescription
0APB access, contestedCompletion of an access to the APB arbiter (which is upstream of all APB peripherals), which was previously delayed due to an access by another master.
1APB accessCompletion of an access to the APB arbiter
2FASTPERI access, contestedCompletion of an access to the FASTPERI arbiter (which is upstream of PIOs, DMA config port, USB, XIP aux FIFO port), which was previously delayed due to an access by another master.
3FASTPERI accessCompletion of an access to the FASTPERI arbiter
4SRAM5 access, contestedCompletion of an access to the SRAM5 arbiter, which was previously delayed due to an access by another master.
5SRAM5 accessCompletion of an access to the SRAM5 arbiter
6SRAM4 access, contestedCompletion of an access to the SRAM4 arbiter, which was previously delayed due to an access by another master.
7SRAM4 accessCompletion of an access to the SRAM4 arbiter
8SRAM3 access, contestedCompletion of an access to the SRAM3 arbiter, which was previously delayed due to an access by another master.
9SRAM3 accessCompletion of an access to the SRAM3 arbiter
10SRAM2 access, contestedCompletion of an access to the SRAM2 arbiter, which was previously delayed due to an access by another master.
11SRAM2 accessCompletion of an access to the SRAM2 arbiter
12SRAM1 access, contestedCompletion of an access to the SRAM1 arbiter, which was previously delayed due to an access by another master.
13SRAM1 accessCompletion of an access to the SRAM1 arbiter
14SRAM0 access, contestedCompletion of an access to the SRAM0 arbiter, which was previously delayed due to an access by another master.
15SRAM0 accessCompletion of an access to the SRAM0 arbiter
PERFSEL
x
EventDescription
16XIP_MAIN access, contestedCompletion of an access to the XIP_MAIN arbiter, which was previously delayed due to an access by another master.
17XIP_MAIN accessCompletion of an access to the XIP_MAIN arbiter
18ROM access, contestedCompletion of an access to the ROM arbiter, which was previously delayed due to an access by another master.
19ROM accessCompletion of an access to the ROM arbiter

2.1.2. Atomic Register Access

Each peripheral register block is allocated 4kB of address space, with registers accessed using one of 4 methods, selected by address decode.

This allows individual fields of a control register to be modified without performing a read-modify-write sequence in software: instead the changes are posted to the peripheral, and performed in-situ. Without this capability, it is difficult to safely access IO registers when an interrupt service routine is concurrent with code running in the foreground, or when the two processors are running code in parallel.

The four atomic access aliases occupy a total of 16kB. Most peripherals on RP2040 provide this functionality natively, and atomic writes have the same timing as normal read/write access. Some peripherals (I2C, UART, SPI and SSI) instead have this functionality added using a bus interposer, which translates upstream atomic writes into downstream read-modify-write sequences, at the boundary of the peripheral. This extends the access time by two system clock cycles.

The SIO ( Section 2.3.1 ), a single-cycle IO block attached directly to the cores' IO ports, does not support atomic accesses at the bus level, although some individual registers (e.g. GPIO) have set/clear/xor aliases.

2.1.3. APB Bridge

The APB bridge interfaces the high-speed main AHB-Lite interconnect to the lower-bandwidth peripherals. Whilst the AHB-Lite fabric offers zero-wait-state access everywhere, APB accesses have a cycle penalty:

As a result, the throughput of the APB portion of the bus fabric is somewhat lower than the AHB-Lite portion. However, there is more than sufficient bandwidth to saturate the APB serial peripherals.

2.1.4. Narrow IO Register Writes

Memory-mapped IO registers on RP2040 ignore the width of bus read/write accesses. They treat all writes as though they were 32 bits in size. This means software can not use byte or halfword writes to modify part of an IO register: any write to an address where the 30 address MSBs match the register address will affect the contents of the entire

register.

To update part of an IO register, without a read-modify-write sequence, the best solution on RP2040 is atomic set/clear/XOR (see Section 2.1.2 ). Note that this is more flexible than byte or halfword writes, as any combination of fields can be updated in one operation.

Upon a 8-bit or 16-bit write (such as a strb instruction on the Cortex-M0+), an IO register will sample the entire 32-bit write databus. The Cortex-M0+ and DMA on RP2040 will always replicate narrow data across the bus:

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/system/narrow_io_write/narrow_io_write.c Lines 19 - 62

19 int main() {
20     stdio_init_all();
21
22     // We'll use WATCHDOG_SCRATCH0 as a convenient 32 bit read/write register
23     // that we can assign arbitrary values to
24     io_rw_32 *scratch32 = &watchdog_hw->scratch[0];
25     // Alias the scratch register as two halfwords at offsets +0x0 and +0x2
26     volatile uint16_t *scratch16 = (volatile uint16_t *) scratch32;
27     // Alias the scratch register as four bytes at offsets +0x0, +0x1, +0x2, +0x3:
28     volatile uint8_t *scratch8 = (volatile uint8_t *) scratch32;
29
30     // Show that we can read/write the scratch register as normal:
31     printf("Writing 32 bit value\n");
32     *scratch32 = 0xdeadbeef;
33     printf("Should be 0xdeadbeef: 0x%08x\n", *scratch32);
34
35     // We can do narrow reads just fine -- IO registers treat this as a 32 bit
36     // read, and the processor/DMA will pick out the correct byte lanes based
37     // on transfer size and address LSBs
38     printf("\nReading back 1 byte at a time\n");
39     // Little-endian!
40     printf("Should be ef be ad de: %02x ", scratch8[0]);
41     printf("%02x ", scratch8[1]);
42     printf("%02x ", scratch8[2]);
43     printf("%02x\n", scratch8[3]);
44
45     // Byte writes are replicated four times across the 32-bit bus, and IO
46     // registers usually sample the entire write bus.
47     printf("\nWriting 8 bit value 0xa5 at offset 0\n");
48     scratch8[0] = 0xa5;
49     // Read back the whole scratch register in one go
50     printf("Should be 0xa5a5a5a5: 0x%08x\n", *scratch32);
51
52     // The IO register ignores the address LSBs [1:0] as well as the transfer
53     // size, so it doesn't matter what byte offset we use
54     printf("\nWriting 8 bit value at offset 1\n");
55     scratch8[1] = 0x3c;
56     printf("Should be 0x3c3c3c3c: 0x%08x\n", *scratch32);
57
58     // Halfword writes are also replicated across the write data bus
59     printf("\nWriting 16 bit value at offset 0\n");
60     scratch16[0] = 0xf00d;
61     printf("Should be 0xf00df00d: 0x%08x\n", *scratch32);
62 }

2.1.5. List of Registers

The Bus Fabric registers start at a base address of 0x40030000(defined as BUSCTRL_BASE in SDK).

Table 4. List of
BUSCTRL registers

OffsetNameInfo
0x00BUS_PRIORITYSet the priority of each master for bus arbitration.
0x04BUS_PRIORITY_ACKBus priority acknowledge
0x08PERFCTR0Bus fabric performance counter 0
0x0cPERFSEL0Bus fabric performance event select for PERFCTR0
0x10PERFCTR1Bus fabric performance counter 1
0x14PERFSEL1Bus fabric performance event select for PERFCTR1
0x18PERFCTR2Bus fabric performance counter 2
0x1cPERFSEL2Bus fabric performance event select for PERFCTR2
0x20PERFCTR3Bus fabric performance counter 3
0x24PERFSEL3Bus fabric performance event select for PERFCTR3

BUSCTRL: BUS_PRIORITY Register

Offset: 0x00

Description

Set the priority of each master for bus arbitration.

Table 5.
BUS_PRIORITY
Register

BitsDescriptionTypeReset
31:13Reserved.--
12DMA_W : 0 - low priority, 1 - high priorityRW0x0
11:9Reserved.--
8DMA_R : 0 - low priority, 1 - high priorityRW0x0
7:5Reserved.--
4PROC1 : 0 - low priority, 1 - high priorityRW0x0
3:1Reserved.--
0PROC0 : 0 - low priority, 1 - high priorityRW0x0

BUSCTRL: BUS_PRIORITY_ACK Register

Offset: 0x04

Description

Bus priority acknowledge

Table 6.
BUS_PRIORITY_ACK
Register

BitsDescriptionTypeReset
31:1Reserved.--
0Goes to 1 once all arbiters have registered the new global priority levels. Arbiters update their local priority when servicing a new nonsequential access. In normal circumstances this will happen almost immediately.RO0x0

BUSCTRL: PERFCTR0 Register

Offset: 0x08

Description

Bus fabric performance counter 0

Table 7. PERFCTR0 Register

BitsDescriptionTypeReset
31:24Reserved.--
23:0Busfabric saturating performance counter 0
Count some event signal from the busfabric arbiters.
Write any value to clear. Select an event to count using PERFSEL0
WC0x000000
BUSCTRL: PERFSEL0 Register

Offset: 0x0c

Description

Bus fabric performance event select for PERFCTR0

Table 8. PERFSEL0 Register

BitsDescriptionTypeReset
31:5Reserved.--
4:0Select an event for PERFCTR0. Count either contested accesses, or all accesses, on a downstream port of the main crossbar.RW0x1f
Enumerated values:
0x00 → APB_CONTESTED
0x01 → APB
0x02 → FASTPERI_CONTESTED
0x03 → FASTPERI
0x04 → SRAM5_CONTESTED
0x05 → SRAM5
0x06 → SRAM4_CONTESTED
0x07 → SRAM4
0x08 → SRAM3_CONTESTED
0x09 → SRAM3
0x0a → SRAM2_CONTESTED
0x0b → SRAM2
0x0c → SRAM1_CONTESTED
0x0d → SRAM1
0x0e → SRAM0_CONTESTED
0x0f → SRAM0
0x10 → XIP_MAIN_CONTESTED
0x11 → XIP_MAIN
0x12 → ROM_CONTESTED
0x13 → ROM
BUSCTRL: PERFCTR1 Register Offset: 0x10 Description

Bus fabric performance counter 1

Table 9. PERFCTR1 Register

BitsDescriptionTypeReset
31:24Reserved.--
23:0Busfabric saturating performance counter 1
Count some event signal from the busfabric arbiters.
Write any value to clear. Select an event to count using PERFSEL1
WC0x000000
BUSCTRL: PERFSEL1 Register Offset: 0x14 Description

Bus fabric performance event select for PERFCTR1

Table 10. PERFSEL1 Register

BitsDescriptionTypeReset
31:5Reserved.--
4:0Select an event for PERFCTR1. Count either contested accesses, or all accesses, on a downstream port of the main crossbar.RW0x1f
Enumerated values:
0x00 → APB_CONTESTED
0x01 → APB
0x02 → FASTPERI_CONTESTED
0x03 → FASTPERI
0x04 → SRAM5_CONTESTED
0x05 → SRAM5
0x06 → SRAM4_CONTESTED
0x07 → SRAM4
0x08 → SRAM3_CONTESTED
0x09 → SRAM3
0x0a → SRAM2_CONTESTED
0x0b → SRAM2
0x0c → SRAM1_CONTESTED
0x0d → SRAM1
0x0e → SRAM0_CONTESTED
0x0f → SRAM0
0x10 → XIP_MAIN_CONTESTED
0x11 → XIP_MAIN
0x12 → ROM_CONTESTED
0x13 → ROM

BUSCTRL: PERFCTR2 Register

Offset: 0x18

Description

Bus fabric performance counter 2

Table 11. PERFCTR2 Register

BitsDescriptionTypeReset
31:24Reserved.--
23:0Busfabric saturating performance counter 2
Count some event signal from the busfabric arbiters.
Write any value to clear. Select an event to count using PERFSEL2
WC0x000000

BUSCTRL: PERFSEL2 Register

Offset: 0x1c

Description

Bus fabric performance event select for PERFCTR2

Table 12. PERFSEL2 Register

BitsDescriptionTypeReset
31:5Reserved.--
4:0Select an event for PERFCTR2. Count either contested accesses, or all accesses, on a downstream port of the main crossbar.RW0x1f
Enumerated values:
0x00 → APB_CONTESTED
0x01 → APB
0x02 → FASTPERI_CONTESTED
0x03 → FASTPERI
0x04 → SRAM5_CONTESTED
0x05 → SRAM5
0x06 → SRAM4_CONTESTED
0x07 → SRAM4
0x08 → SRAM3_CONTESTED
0x09 → SRAM3
0x0a → SRAM2_CONTESTED
0x0b → SRAM2
0x0c → SRAM1_CONTESTED
0x0d → SRAM1
0x0e → SRAM0_CONTESTED
0x0f → SRAM0
0x10 → XIP_MAIN_CONTESTED
0x11 → XIP_MAIN
0x12 → ROM_CONTESTED
BitsDescriptionTypeReset
0x13 → ROM

BUSCTRL: PERFCTR3 Register

Offset: 0x20

Description

Bus fabric performance counter 3

Table 13. PERFCTR3 Register

BitsDescriptionTypeReset
31:24Reserved.--
23:0Busfabric saturating performance counter 3
Count some event signal from the busfabric arbiters.
Write any value to clear. Select an event to count using PERFSEL3
WC0x000000

BUSCTRL: PERFSEL3 Register

Offset: 0x24

Description

Bus fabric performance event select for PERFCTR3

Table 14. PERFSEL3 Register

BitsDescriptionTypeReset
31:5Reserved.--
4:0Select an event for PERFCTR3. Count either contested accesses, or all accesses, on a downstream port of the main crossbar.RW0x1f
Enumerated values:
0x00 → APB_CONTESTED
0x01 → APB
0x02 → FASTPERI_CONTESTED
0x03 → FASTPERI
0x04 → SRAM5_CONTESTED
0x05 → SRAM5
0x06 → SRAM4_CONTESTED
0x07 → SRAM4
0x08 → SRAM3_CONTESTED
0x09 → SRAM3
0x0a → SRAM2_CONTESTED
0x0b → SRAM2
0x0c → SRAM1_CONTESTED
0x0d → SRAM1
0x0e → SRAM0_CONTESTED
0x0f → SRAM0
0x10 → XIP_MAIN_CONTESTED
BitsDescriptionTypeReset
0x11 → XIP_MAIN
0x12 → ROM_CONTESTED
0x13 → ROM