At start-up, the RP2040 runs through

  • the hardware-controlled power-on sequence (datasheet chapter 2.13), and then
  • the processor-controlled boot sequence (datasheet chapter 2.8).

The hardware-controlled power-on sequence terminates with enabling the two processor cores. Thereafter, the cores start to execute the code in the boot-rom. Core 1 immediately goes into a low power wait state, until started by core 0 via the inter-processor FIFO.

Getting Astrobe’s Output in Place and Running

Skipping over some steps, and neglecting the programming of the RP2040’s flash memory from its USB drive,1 the boot sequence at some point will load the first 256 bytes in flash memory from address 010000000H into SRAM. These are the 256 bytes that the utility abin2uf2 prepends to Astrobe’s .bin file. This code’s responsibility is to set up the SSI-interface to the flash storage to enable XIP, execute-in-place, ie. the RP2040’s functionality to map the code in flash memory to code addresses, even though it reads it via SSI/SPI.

If the checksum of this first block of 256 bytes checks out, the code will be executed. The last few instructions load the value at flash address 010000100H into the stack pointer register, and the value at 010000104H into the program counter. Astrobe’s .bin file provides these to values as the first two entries, compatible for other Cortex-Mx microcontrollers.

Therefore abin2uf2 inserts Astrobe’s .bin file so its content will start at address 010000100H when loaded into flash memory via BOOTSEL mode. Hence, from here, we have the “normal” boot sequence, fully compatible with Astrobe’s output. We just need to set Astrobe Code Range parameters right, ie. starting from 010000100H, so that the code generated uses the correct addresses, as found in the flash memory.

Business as Usual: Module Initialisations and Program Start

Consequently, the initialisation of your program modules are done, as per Astrobe’s linker, and last but not least your program gets control when its body is executed as last step of the initialisation sequence.

  1. The USB boot code handles the flash programming. ↩︎