Skip to content

Commit 44c5867

Browse files
Initial commit, basic sanity
Some paths hardcoded to my custom toolchain build dir, will be updated to a package.json tools setup soon. https://github.com/earlephilhower/pico-quick-toolchain Blink and Fade examples work (i.e. digitalWrite/analogWrite/delay). Includes a discovery script which will detect RPI Picos in UF2 bootmode.
0 parents  commit 44c5867

21 files changed

+1483
-0
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "ArduinoCore-API"]
2+
path = ArduinoCore-API
3+
url = https://github.com/arduino/ArduinoCore-API.git
4+
[submodule "pico-sdk"]
5+
path = pico-sdk
6+
url = https://github.com/raspberrypi/pico-sdk.git

ArduinoCore-API

Submodule ArduinoCore-API added at 2af4a9c
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Padded and checksummed version of: /home/earle/src/pico/pico-examples/build/pico_sdk/src/rp2_common/boot_stage2/bs2_default.bin
2+
3+
.section .boot2, "a"
4+
5+
.byte 0x00, 0xb5, 0x2f, 0x4b, 0x21, 0x20, 0x58, 0x60, 0x98, 0x68, 0x02, 0x21, 0x88, 0x43, 0x98, 0x60
6+
.byte 0xd8, 0x60, 0x18, 0x61, 0x58, 0x61, 0x2b, 0x4b, 0x00, 0x21, 0x99, 0x60, 0x02, 0x21, 0x59, 0x61
7+
.byte 0x01, 0x21, 0xf0, 0x22, 0x99, 0x50, 0x28, 0x49, 0x19, 0x60, 0x01, 0x21, 0x99, 0x60, 0x35, 0x20
8+
.byte 0x00, 0xf0, 0x3e, 0xf8, 0x02, 0x22, 0x90, 0x42, 0x14, 0xd0, 0x06, 0x21, 0x19, 0x66, 0x00, 0xf0
9+
.byte 0x2e, 0xf8, 0x19, 0x6e, 0x01, 0x21, 0x19, 0x66, 0x00, 0x20, 0x18, 0x66, 0x1a, 0x66, 0x00, 0xf0
10+
.byte 0x26, 0xf8, 0x19, 0x6e, 0x19, 0x6e, 0x19, 0x6e, 0x05, 0x20, 0x00, 0xf0, 0x29, 0xf8, 0x01, 0x21
11+
.byte 0x08, 0x42, 0xf9, 0xd1, 0x00, 0x21, 0x99, 0x60, 0x18, 0x49, 0x19, 0x60, 0x00, 0x21, 0x59, 0x60
12+
.byte 0x17, 0x49, 0x18, 0x48, 0x01, 0x60, 0x01, 0x21, 0x99, 0x60, 0xeb, 0x21, 0x19, 0x66, 0xa0, 0x21
13+
.byte 0x19, 0x66, 0x00, 0xf0, 0x0c, 0xf8, 0x00, 0x21, 0x99, 0x60, 0x13, 0x49, 0x11, 0x48, 0x01, 0x60
14+
.byte 0x01, 0x21, 0x99, 0x60, 0x01, 0xbc, 0x00, 0x28, 0x00, 0xd1, 0x10, 0x48, 0x00, 0x47, 0x03, 0xb5
15+
.byte 0x99, 0x6a, 0x04, 0x20, 0x01, 0x42, 0xfb, 0xd0, 0x01, 0x20, 0x01, 0x42, 0xf8, 0xd1, 0x03, 0xbd
16+
.byte 0x02, 0xb5, 0x18, 0x66, 0x18, 0x66, 0xff, 0xf7, 0xf2, 0xff, 0x18, 0x6e, 0x18, 0x6e, 0x02, 0xbd
17+
.byte 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x07, 0x00, 0x00, 0x03, 0x5f, 0x00
18+
.byte 0x21, 0x22, 0x00, 0x00, 0xf4, 0x00, 0x00, 0x18, 0x22, 0x20, 0x00, 0xa0, 0x01, 0x01, 0x00, 0x10
19+
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
20+
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x27, 0x2a, 0x60

assembly/crt0.S

Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
/*
2+
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include "hardware/regs/m0plus.h"
8+
#include "hardware/platform_defs.h"
9+
#include "hardware/regs/addressmap.h"
10+
#include "hardware/regs/sio.h"
11+
#include "pico/binary_info/defs.h"
12+
13+
#ifdef NDEBUG
14+
#ifndef COLLAPSE_IRQS
15+
#define COLLAPSE_IRQS
16+
#endif
17+
#endif
18+
19+
.syntax unified
20+
.cpu cortex-m0plus
21+
.thumb
22+
23+
.section .vectors, "ax"
24+
.align 2
25+
26+
.global __vectors
27+
__vectors:
28+
.word __StackTop
29+
.word _reset_handler
30+
.word isr_nmi
31+
.word isr_hardfault
32+
.word isr_invalid // Reserved, should never fire
33+
.word isr_invalid // Reserved, should never fire
34+
.word isr_invalid // Reserved, should never fire
35+
.word isr_invalid // Reserved, should never fire
36+
.word isr_invalid // Reserved, should never fire
37+
.word isr_invalid // Reserved, should never fire
38+
.word isr_invalid // Reserved, should never fire
39+
.word isr_svcall
40+
.word isr_invalid // Reserved, should never fire
41+
.word isr_invalid // Reserved, should never fire
42+
.word isr_pendsv
43+
.word isr_systick
44+
.word isr_irq0
45+
.word isr_irq1
46+
.word isr_irq2
47+
.word isr_irq3
48+
.word isr_irq4
49+
.word isr_irq5
50+
.word isr_irq6
51+
.word isr_irq7
52+
.word isr_irq8
53+
.word isr_irq9
54+
.word isr_irq10
55+
.word isr_irq11
56+
.word isr_irq12
57+
.word isr_irq13
58+
.word isr_irq14
59+
.word isr_irq15
60+
.word isr_irq16
61+
.word isr_irq17
62+
.word isr_irq18
63+
.word isr_irq19
64+
.word isr_irq20
65+
.word isr_irq21
66+
.word isr_irq22
67+
.word isr_irq23
68+
.word isr_irq24
69+
.word isr_irq25
70+
.word isr_irq26
71+
.word isr_irq27
72+
.word isr_irq28
73+
.word isr_irq29
74+
.word isr_irq30
75+
.word isr_irq31
76+
77+
// Declare a weak symbol for each ISR.
78+
// By default, they will fall through to the undefined IRQ handler below (breakpoint),
79+
// but can be overridden by C functions with correct name.
80+
81+
.macro decl_isr_bkpt name
82+
.weak \name
83+
.type \name,%function
84+
.thumb_func
85+
\name:
86+
bkpt #0
87+
.endm
88+
89+
// these are separated out for clarity
90+
decl_isr_bkpt isr_invalid
91+
decl_isr_bkpt isr_nmi
92+
decl_isr_bkpt isr_hardfault
93+
decl_isr_bkpt isr_svcall
94+
decl_isr_bkpt isr_pendsv
95+
decl_isr_bkpt isr_systick
96+
97+
.macro decl_isr name
98+
.weak \name
99+
.type \name,%function
100+
.thumb_func
101+
\name:
102+
.endm
103+
104+
decl_isr isr_irq0
105+
decl_isr isr_irq1
106+
decl_isr isr_irq2
107+
decl_isr isr_irq3
108+
decl_isr isr_irq4
109+
decl_isr isr_irq5
110+
decl_isr isr_irq6
111+
decl_isr isr_irq7
112+
decl_isr isr_irq8
113+
decl_isr isr_irq9
114+
decl_isr isr_irq10
115+
decl_isr isr_irq11
116+
decl_isr isr_irq12
117+
decl_isr isr_irq13
118+
decl_isr isr_irq14
119+
decl_isr isr_irq15
120+
decl_isr isr_irq16
121+
decl_isr isr_irq17
122+
decl_isr isr_irq18
123+
decl_isr isr_irq19
124+
decl_isr isr_irq20
125+
decl_isr isr_irq21
126+
decl_isr isr_irq22
127+
decl_isr isr_irq23
128+
decl_isr isr_irq24
129+
decl_isr isr_irq25
130+
decl_isr isr_irq26
131+
decl_isr isr_irq27
132+
decl_isr isr_irq28
133+
decl_isr isr_irq29
134+
decl_isr isr_irq30
135+
decl_isr isr_irq31
136+
137+
// All unhandled USER IRQs fall through to here
138+
.global __unhandled_user_irq
139+
.thumb_func
140+
__unhandled_user_irq:
141+
bl __get_current_exception
142+
subs r0, #16
143+
.global unhandled_user_irq_num_in_r0
144+
unhandled_user_irq_num_in_r0:
145+
bkpt #0
146+
147+
.section .reset, "ax"
148+
149+
// This is the beginning of the image, which is entered from stage2 or bootrom USB MSD watchdog reboot
150+
151+
// note if we are NO_FLASH then start: below is currently identical anyway, so save 4 bytes
152+
#if !PICO_NO_FLASH
153+
// We simply install our own vector table and redirect through it
154+
ldr r0, =__vectors
155+
b __vector_entry
156+
#endif
157+
158+
// ELF entry point generally called when we load an ELF via debugger
159+
.type _entry_point,%function
160+
.thumb_func
161+
.global _entry_point
162+
_entry_point:
163+
164+
#if PICO_NO_FLASH
165+
// non flash
166+
ldr r0, =__vectors
167+
#else
168+
// todo clear watchdog?
169+
// When using flash, we install and use the ROM vector table to go thru regular bootrom/stage2 flash sequence
170+
movs r0, #0
171+
#endif
172+
173+
__vector_entry:
174+
ldr r1, =(PPB_BASE + M0PLUS_CPUID_OFFSET)
175+
str r0, [r1, #8]
176+
ldmia r0!, {r1, r2}
177+
msr msp, r1
178+
bx r2
179+
180+
// ----------------------------------------------------------------------------
181+
// Reset handler:
182+
// - initialises .data
183+
// - clears .bss
184+
// - calls runtime_init
185+
// - calls main
186+
// - calls exit (which should eventually hang the processor via _exit)
187+
188+
.type _reset_handler,%function
189+
.thumb_func
190+
_reset_handler:
191+
// Hang all cores except core 0
192+
ldr r0, =(SIO_BASE + SIO_CPUID_OFFSET)
193+
ldr r0, [r0]
194+
cmp r0, #0
195+
bne wait_for_vector
196+
197+
adr r4, data_cpy_table
198+
199+
// assume there is at least one entry
200+
1:
201+
ldmia r4!, {r1-r3}
202+
cmp r1, #0
203+
beq 2f
204+
bl data_cpy
205+
b 1b
206+
2:
207+
208+
// Zero out the BSS
209+
ldr r1, =__bss_start__
210+
ldr r2, =__bss_end__
211+
movs r0, #0
212+
b bss_fill_test
213+
bss_fill_loop:
214+
stm r1!, {r0}
215+
bss_fill_test:
216+
cmp r1, r2
217+
bne bss_fill_loop
218+
219+
platform_entry: // symbol for stack traces
220+
// Use 32-bit jumps, in case these symbols are moved out of branch range
221+
// (e.g. if main is in SRAM and crt0 in flash)
222+
ldr r1, =runtime_init
223+
blx r1
224+
ldr r1, =main
225+
blx r1
226+
ldr r1, =exit
227+
blx r1
228+
// exit should not return. If it does, hang the core.
229+
// (fall thru into our hang _exit impl
230+
.weak _exit
231+
.type _exit,%function
232+
.thumb_func
233+
_exit:
234+
1: // separate label because _exit can be moved out of branch range
235+
bkpt #0
236+
b 1b
237+
238+
data_cpy_loop:
239+
ldm r1!, {r0}
240+
stm r2!, {r0}
241+
data_cpy:
242+
cmp r2, r3
243+
blo data_cpy_loop
244+
bx lr
245+
246+
#if !PICO_NO_BINARY_INFO
247+
binary_info_header:
248+
.word BINARY_INFO_MARKER_START
249+
.word __binary_info_start
250+
.word __binary_info_end
251+
.word data_cpy_table // we may need to decode pointers that are in RAM at runtime.
252+
.word BINARY_INFO_MARKER_END
253+
#endif
254+
255+
.align 2
256+
data_cpy_table:
257+
#if PICO_COPY_TO_RAM
258+
.word __ram_text_source__
259+
.word __ram_text_start__
260+
.word __ram_text_end__
261+
#endif
262+
.word __etext
263+
.word __data_start__
264+
.word __data_end__
265+
266+
.word __scratch_x_source__
267+
.word __scratch_x_start__
268+
.word __scratch_x_end__
269+
270+
.word __scratch_y_source__
271+
.word __scratch_y_start__
272+
.word __scratch_y_end__
273+
274+
.word 0 // null terminator
275+
276+
// ----------------------------------------------------------------------------
277+
// Provide safe defaults for _exit and runtime_init
278+
// Full implementations usually provided by platform.c
279+
280+
.weak runtime_init
281+
.type runtime_init,%function
282+
.thumb_func
283+
runtime_init:
284+
bx lr
285+
286+
// ----------------------------------------------------------------------------
287+
// In case core 1's VTOR has already been moved into flash, we need to handle
288+
// core 1 reset. However, we do so by just jumping back into bootrom version of
289+
// wait_for_vector
290+
291+
wait_for_vector:
292+
ldr r0, = 'W' | ('V' << 8)
293+
bl rom_func_lookup
294+
bx r0
295+
296+
.global __get_current_exception
297+
.thumb_func
298+
__get_current_exception:
299+
mrs r0, ipsr
300+
uxtb r0, r0
301+
bx lr
302+
303+
// ----------------------------------------------------------------------------
304+
// Stack/heap dummies to set size
305+
306+
.section .stack
307+
// align to allow for memory protection (although this alignment is pretty much ignored by linker script)
308+
.align 5
309+
.equ StackSize, PICO_STACK_SIZE
310+
.space StackSize
311+
312+
.section .heap
313+
.align 2
314+
.equ HeapSize, PICO_HEAP_SIZE
315+
.space HeapSize

0 commit comments

Comments
 (0)