Pi Pico boot process

Copyright © 2024 J. M. Spivey
Revision as of 12:08, 14 April 2023 by Mike (talk | contribs) (Created page with "==Stage 1== The RP2040 has an inbuilt, immutable ROM that includes the initial startup code at address {{Hex|0000 0000}}. This code copies the first 256 bytes of an external...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Stage 1

The RP2040 has an inbuilt, immutable ROM that includes the initial startup code at address 0x0000 0000. This code copies the first 256 bytes of an external SPI Flash memory into RAM (at address 0x2000 0000), verifies a checksum, then executes it.

On coming out of reset, the system clock is taken from an internal ring oscillator that runs at about 3.5 MHz.

Stage 2

The second-stage boot code is specific to the kind of Flash chip on the board. It configures the execute-in-place (XIP) interface to run code from the Flash chip, with the chip contents appearing at address 0x1000 0000. Then, assuming that the Flash image has a vector table immediately following the stage 2 bootloader, it sets the stack pointer from the vector table, and branches to the reset vector, which is configured to point into the Flash image.

Stage 3

The reset code runs from Flash, and initialises the hardware, including starting the crystal oscillator and PLLs that derive system clocks from it. Different configurations then behave in different ways; the usual default is to continue running code from the Flash memory using XIP, and benefitting from a read-only cache. For micro:bian, the routine __reset runs from Flash, and instead copies the text and data segments of the program from Flash into RAM, sets the VTOR to the RAM copy of the vector table, then begins to execute the program at function __start in RAM. The function __start never returns, so the system makes no further use of Flash unless the program makes explicit access to it.