Hi,
I’m having some trouble getting a raspberry pico 2 to run bare metal zig code (code available here ) and I’m hoping to get some help from the community.
I’m trying to do the basic embedded hello world to blink the on board LED, but i can’t get my code to run. The pico just reboots in usb flash mode immediately after i flash the uf2 file to it.
This is what i get when generating the uf2 file with picotool:
read_ph ph offset 52 #entries 4
read_sh sh offset 65860 #entries 7
Detected FLASH binary
Mapped segment 10000000->10000028 (10000000->10000028)
Mapped segment 10000028->10000060 (10000028->10000060)
Page 0 / 1 10000000
And here is the structure of the ELF file:
zig-out/bin/blink: file format elf32-littlearm
Sections:
Idx Name Size VMA LMA File off Algn
0 .vector_table 00000008 10000000 10000000 00010000 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .ARM.exidx 00000020 10000008 10000008 00010008 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .text 00000038 10000028 10000028 00010028 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
3 .ARM.attributes 00000034 00000000 00000000 00010060 2**0
CONTENTS, READONLY
4 .comment 0000006d 00000000 00000000 00010094 2**0
CONTENTS, READONLY
I have tried looking at example projects available online, but most of it is in C or python using complex full featured SDKs that make it hard to understand at a basic level what i need to do at the linking and building stages for my code to run.
I tried following the microzig getting started guide from scratch in a new project, but i get a similar result as with my own code: the compilation and uf2 generation complete without errors but the code doesn’t do anything and the chip reboots right away.
I don’t think anything is wrong with the chip itself because the pre-compiled uf2 blink example from the official docs runs as expected.
I guess the problem is related to the initial stack pointer and/or reset handler either not being at the right memory addresses or not pointing to the right addresses, but i’m not sure how to set that up properly.
If someone has managed to run some basic zig code on the pico 2 i would very much appreciate some help to understand how to set up the binary correctly so the chip can run it.