1// ---------------------------------------------
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
12// ---------------------------------------------
14// Low-level reset code for the RP2350 Launchpad
17// - Initialize the PSRAM /CS pin
18// - Check wether the image is a COPY_TO_xxx image, and relocates
19// the image if necessary
20// - Sets the VTOR register
21// - Jumps to the C++-part of the reset routine (Reset_Handler)
23// The following boot scenarios for the RP2350 Launchpad are supported:
25// 1.) Normal flash image
26// OpenOcd upload: Works, target is reset and enters reset_handler via bootrom.
27// OpenOcd debug: Works, targer is reset and enters reset_handler via bootrom.
30// 2.) Image linked with COPY_TO_RAM / COPY_TO_PSRAM
31// OpenOcd upload: Works, target is reset and enters reset_handler via bootrom.
32// OpenOcd debug: Works, targer is reset and enters reset_handler via bootrom.
33// UF2 upload: Works for COPY_TO_RAM, COPY_TO_PSRAM not working
35// 3.) Images linked with LOAD_INTO_RAM / LOAD_INTO_PSRAM
36// OpenOcd upload: Works, target is not reset and resumes at 0x20000101 or 0x11000101
37// OpenOcd debug: Needs special debugger setup, reset is not allowed.
38// UF2 upload: Works for LOAD_INTO_RAM, LOAD_INTO_PSRAM not working
42#define VTOR_REG 0xe000ed08
43#define GPIO0_CTRL 0x40028004
44#define GPIO0_PAD_CTRL 0x40038004
45#define XIP_CTRL_REG 0x400c8000
51 .global _elf_entry_point
53 // This is a fake vector table to start the
54 // reset_handler, in case this code is put right
55 // at the beginning of the flash (0x10000000).
61 // Initialize the PSRAM CS pin
63 mov r5, #PSRAM_CS_GPIO
65 // Set ISO=0, drive strengh 4mA, PUE=1, SLEWFAST=1
66 ldr r0, =GPIO0_PAD_CTRL
68 str r1, [r0, r5, LSL #2]
70 // Set function to QMI /CS1
73 str r1, [r0, r5, LSL #3]
75 // Set WRITABLE_M1 = 1
82 // Check if we have to relocate the image
83 ldr r0, =__image_load__
84 ldr r1, =__image_start__
88 // Copy the complete image (.text, .rodata, .data)
89 // to the runtime memory area in RAM
90 ldr r2, =__image_end__
96 // Setup stack pointer, because the C-part
97 // of the reset handler will use it!!
101 // Set the ISR vector offset register (VTOR)
102 ldr r0, =__vector_start__
106 // Finally jump to the C++-based part of
107 // the reset handler, which will initialize
108 // the system and jump to main(). Use a long
109 // jump here in case the jump target is in RAM
110 ldr r0, =Reset_Handler
114 // We should never get here, but just in case
115 // run into an endless loop
119 // If the image is entered via the _elf_entry_point,
120 // take a loop through the bootrom, to make sure the
121 // flash and other related things are initialized
124 // Set the ISR vector offset register (VTOR)
129 // r1=initial SP, r2=reset handler of bootrom
134 // We should never get here, but just in case
135 // run into an endless loop