Skip to content

Commit 72f71c1

Browse files
GrazfatherFelix "xq" Queißnertact1m4n3
authored
Add pico2 arm flashless target board (#604)
Co-authored-by: Felix "xq" Queißner <[email protected]> Co-authored-by: tact1m4n3 <[email protected]>
1 parent 8f12e65 commit 72f71c1

File tree

14 files changed

+302
-130
lines changed

14 files changed

+302
-130
lines changed

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ pub fn MicroBuild(port_select: PortSelect) type {
569569
.chip_name = target.chip.name,
570570
.memory_regions = target.chip.memory_regions,
571571
.generate = linker_script_options.generate,
572+
.ram_image = target.ram_image,
572573
};
573574

574575
const args_str = std.json.stringifyAlloc(

core/src/cpus/cortex_m.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ pub const startup_logic = struct {
591591
extern var microzig_bss_end: u8;
592592
extern const microzig_data_load_start: u8;
593593

594-
pub fn ram_image_entrypoint() linksection(".entry") callconv(.naked) void {
594+
pub fn ram_image_entry_point() linksection("microzig_ram_start") callconv(.naked) void {
595595
asm volatile (
596596
\\
597597
// Set VTOR to point to ram table
@@ -684,20 +684,20 @@ fn is_ramimage() bool {
684684

685685
pub fn export_startup_logic() void {
686686
if (is_ramimage())
687-
@export(&startup_logic.ram_image_entrypoint, .{
687+
@export(&startup_logic.ram_image_entry_point, .{
688688
.name = "_entry_point",
689689
.linkage = .strong,
690+
})
691+
else
692+
@export(&startup_logic._vector_table, .{
693+
.name = "_vector_table",
694+
.section = "microzig_flash_start",
695+
.linkage = .strong,
690696
});
691697

692698
@export(&startup_logic._start, .{
693699
.name = "_start",
694700
});
695-
696-
@export(&startup_logic._vector_table, .{
697-
.name = "_vector_table",
698-
.section = "microzig_flash_start",
699-
.linkage = .strong,
700-
});
701701
}
702702

703703
const scs_base = 0xE000E000;

examples/raspberrypi/rp2xxx/build.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub fn build(b: *std.Build) void {
2626
.{ .target = raspberrypi.pico, .name = "pico_pcf8574", .file = "src/rp2040_only/pcf8574.zig" },
2727
.{ .target = raspberrypi.pico, .name = "pico_i2c_slave", .file = "src/rp2040_only/i2c_slave.zig" },
2828
.{ .target = raspberrypi.pico_flashless, .name = "pico_flashless_blinky", .file = "src/blinky.zig" },
29+
.{ .target = raspberrypi.pico2_arm_flashless, .name = "pico2_arm_flashless_blinky", .file = "src/blinky.zig" },
30+
.{ .target = raspberrypi.pico2_riscv_flashless, .name = "pico2_riscv_flashless_blinky", .file = "src/blinky.zig" },
2931

3032
.{ .target = raspberrypi.pico2_arm, .name = "pico2_arm_random_data", .file = "src/rp2350_only/random_data.zig" },
3133
.{ .target = raspberrypi.pico2_riscv, .name = "pico2_riscv_random_data", .file = "src/rp2350_only/random_data.zig" },

port/raspberrypi/rp2xxx/build.zig

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ boards: struct {
1717
pico: *const microzig.Target,
1818
pico_flashless: *const microzig.Target,
1919
pico2_arm: *const microzig.Target,
20+
pico2_arm_flashless: *const microzig.Target,
2021
pico2_riscv: *const microzig.Target,
22+
pico2_riscv_flashless: *const microzig.Target,
2123
},
2224
waveshare: struct {
2325
rp2040_plus_4m: *const microzig.Target,
@@ -175,13 +177,13 @@ pub fn init(dep: *std.Build.Dependency) Self {
175177
},
176178
}),
177179
.pico_flashless = chip_rp2040.derive(.{
178-
.entry = .{ .symbol_name = "_entry_point" },
179-
.linker_script = .{ .generate = .none, .file = b.path("ld/rp2040/ram_image_linker.ld") },
180180
.ram_image = true,
181+
// we can use the default generated linker script
182+
.linker_script = .{},
181183
.board = .{
182184
.name = "RaspberryPi Pico (ram image)",
183185
.url = "https://www.raspberrypi.com/products/raspberry-pi-pico/",
184-
.root_source_file = b.path("src/boards/raspberry_pi_pico2.zig"),
186+
.root_source_file = b.path("src/boards/raspberry_pi_pico_flashless.zig"),
185187
},
186188
}),
187189
.pico2_arm = chip_rp2350_arm.derive(.{
@@ -191,13 +193,35 @@ pub fn init(dep: *std.Build.Dependency) Self {
191193
.root_source_file = b.path("src/boards/raspberry_pi_pico2.zig"),
192194
},
193195
}),
196+
.pico2_arm_flashless = chip_rp2350_arm.derive(.{
197+
.ram_image = true,
198+
.linker_script = .{
199+
.file = b.path("ld/rp2350/arm_ram_image_sections.ld"),
200+
},
201+
.board = .{
202+
.name = "RaspberryPi Pico 2 (ram image)",
203+
.url = "https://www.raspberrypi.com/products/raspberry-pi-pico2/",
204+
.root_source_file = b.path("src/boards/raspberry_pi_pico2.zig"),
205+
},
206+
}),
194207
.pico2_riscv = chip_rp2350_riscv.derive(.{
195208
.board = .{
196209
.name = "RaspberryPi Pico 2",
197210
.url = "https://www.raspberrypi.com/products/raspberry-pi-pico2/",
198211
.root_source_file = b.path("src/boards/raspberry_pi_pico2.zig"),
199212
},
200213
}),
214+
.pico2_riscv_flashless = chip_rp2350_riscv.derive(.{
215+
.ram_image = true,
216+
.linker_script = .{
217+
.file = b.path("ld/rp2350/riscv_ram_image_sections.ld"),
218+
},
219+
.board = .{
220+
.name = "RaspberryPi Pico 2 (ram image)",
221+
.url = "https://www.raspberrypi.com/products/raspberry-pi-pico2/",
222+
.root_source_file = b.path("src/boards/raspberry_pi_pico2.zig"),
223+
},
224+
}),
201225
},
202226
.waveshare = .{
203227
.rp2040_plus_4m = chip_rp2040.derive(.{

port/raspberrypi/rp2xxx/ld/rp2040/ram_image_linker.ld

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SECTIONS {
2+
.bootmeta :
3+
{
4+
__bootmeta_start__ = .;
5+
KEEP(*(.bootmeta))
6+
__bootmeta_end__ = .;
7+
} > ram0
8+
}
9+
INSERT AFTER .ram_start;
10+
11+
SECTIONS {
12+
.ram_vectors (NOLOAD) :
13+
{
14+
KEEP(*(ram_vectors))
15+
} > ram0
16+
}
17+
INSERT AFTER .bss;
18+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
SECTIONS {
2+
.bootmeta :
3+
{
4+
__bootmeta_start__ = .;
5+
KEEP(*(.bootmeta))
6+
__bootmeta_end__ = .;
7+
} > ram0
8+
9+
.vectors :
10+
{
11+
KEEP(*(core_vectors))
12+
} > ram0
13+
}
14+
INSERT AFTER .ram_start;
15+
16+
SECTIONS {
17+
.ram_vectors (NOLOAD) :
18+
{
19+
KEEP(*(ram_vectors))
20+
} > ram0
21+
}
22+
INSERT AFTER .bss;
23+

port/raspberrypi/rp2xxx/ld/rp2350/riscv_sections.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SECTIONS {
1515
INSERT AFTER .flash_start;
1616

1717
SECTIONS {
18-
.ram_vectors (NOLOAD) :
18+
.ram_vectors (NOLOAD) :
1919
{
2020
KEEP(*(ram_vectors))
2121
} > ram0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub const xosc_freq = 12_000_000;

port/raspberrypi/rp2xxx/src/cpus/hazard3.zig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,10 @@ var ram_vectors: [vector_count]Handler = undefined;
169169
pub const startup_logic = struct {
170170
extern fn microzig_main() noreturn;
171171

172-
pub export fn _start() linksection("microzig_flash_start") callconv(.naked) noreturn {
172+
pub export fn _start() linksection(if (microzig.config.ram_image)
173+
"microzig_ram_start"
174+
else
175+
"microzig_flash_start") callconv(.naked) noreturn {
173176
asm volatile (
174177
\\.option push
175178
\\.option norelax
@@ -199,7 +202,9 @@ pub const startup_logic = struct {
199202
}
200203

201204
pub export fn _start_c() callconv(.c) noreturn {
202-
root.initialize_system_memories();
205+
if (!microzig.config.ram_image) {
206+
root.initialize_system_memories();
207+
}
203208

204209
// Move vector table to RAM if requested
205210
if (interrupt.has_ram_vectors()) {
@@ -316,7 +321,7 @@ pub fn export_startup_logic() void {
316321

317322
@export(&startup_logic.external_interrupt_table, .{
318323
.name = "_external_interrupt_table",
319-
.section = "flash_vectors",
324+
.section = if (!microzig.config.ram_image) "flash_vectors" else null,
320325
.linkage = .strong,
321326
});
322327
}

0 commit comments

Comments
 (0)