YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
reset_rp2350.S
1// ---------------------------------------------
2// This file is part of
3// _ _ __ _ _ __ __
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
7//
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
11//
12// ---------------------------------------------
13//
14// Low-level reset code for the RP2350 Launchpad
15//
16// This code will
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)
22//
23// The following boot scenarios for the RP2350 Launchpad are supported:
24//
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.
28// UF2 upload: Works
29//
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
34//
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
39
40#include "board.h"
41
42#define VTOR_REG 0xe000ed08
43#define GPIO0_CTRL 0x40028004
44#define GPIO0_PAD_CTRL 0x40038004
45#define XIP_CTRL_REG 0x400c8000
46
47 .syntax unified
48 .thumb
49 .section .reset,"ax"
50 .global reset_handler
51 .global _elf_entry_point
52
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).
56 .word __StackTop
57 .word reset_handler
58
59 .thumb_func
60reset_handler:
61 // Initialize the PSRAM CS pin
62 #ifdef PSRAM_CS_GPIO
63 mov r5, #PSRAM_CS_GPIO
64
65 // Set ISO=0, drive strengh 4mA, PUE=1, SLEWFAST=1
66 ldr r0, =GPIO0_PAD_CTRL
67 mov r1, #0x19
68 str r1, [r0, r5, LSL #2]
69
70 // Set function to QMI /CS1
71 ldr r0, =GPIO0_CTRL
72 mov r1, #9
73 str r1, [r0, r5, LSL #3]
74
75 // Set WRITABLE_M1 = 1
76 ldr r0, =XIP_CTRL_REG
77 ldr r1, [r0]
78 orr r1, 0x800
79 str r1, [r0]
80 #endif
81
82 // Check if we have to relocate the image
83 ldr r0, =__image_load__
84 ldr r1, =__image_start__
85 cmp r0, r1
86 beq no_copy
87copy_loop:
88 // Copy the complete image (.text, .rodata, .data)
89 // to the runtime memory area in RAM
90 ldr r2, =__image_end__
91 ldmia r0!, {r3}
92 stmia r1!, {r3}
93 cmp r1, r2
94 blo copy_loop
95no_copy:
96 // Setup stack pointer, because the C-part
97 // of the reset handler will use it!!
98 ldr r0, =__StackTop
99 msr msp, r0
100
101 // Set the ISR vector offset register (VTOR)
102 ldr r0, =__vector_start__
103 ldr r1, =VTOR_REG
104 str r0, [r1]
105
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
111 blx r0
112
113endless:
114 // We should never get here, but just in case
115 // run into an endless loop
116 b endless
117
118
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
122 .thumb_func
123_elf_entry_point:
124 // Set the ISR vector offset register (VTOR)
125 movs r0, #0
126 ldr r1, =VTOR_REG
127 str r0, [r1]
128
129 // r1=initial SP, r2=reset handler of bootrom
130 ldmia r0!, {r1, r2}
131 msr msp, r1
132 blx r2
133
134 // We should never get here, but just in case
135 // run into an endless loop
136 b endless
137
138 .end