diff options
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -108,6 +108,14 @@ pub fn build(b: *std.Build) void { // cycle counts. Off by default because it puts a line on the wire per frame, which is the very // resource being measured - it answers "where did the 34 ms go", not "how fast is it". options.addOption(bool, "prof", b.option(bool, "prof", "print per-phase cycle counts (pardes)") orelse false); + // The CPU clock, in MHz. The bootloader leaves 90; the CPLL is already at 360, so 180 and 360 + // are a divider change away and nothing else (see hal/clkrst.zig:setCpuFreq). Opt-in rather + // than default because it is the one setting here that changes how every other timing in the + // image behaves, and because 90 is what every measurement in experiments/ was taken against. + const cpu_mhz = b.option(u16, "cpu-mhz", "HP CPU clock: 90 (bootloader default), 180 or 360") orelse 90; + if (cpu_mhz != 90 and cpu_mhz != 180 and cpu_mhz != 360) + std.debug.panic("-Dcpu-mhz must be 90, 180 or 360; the P4's CPLL divides 360 by 4, 2 or 1", .{}); + options.addOption(u16, "cpu_mhz", cpu_mhz); options.addOption([]const u8, "wifi_ssid", wifi_ssid); options.addOption([]const u8, "wifi_psk", if (psk_file) |path| blk: { const raw = std.Io.Dir.cwd().readFileAlloc(b.graph.io, path, b.allocator, .limited(256)) catch @@ -1216,6 +1224,9 @@ fn linkerScript(b: *std.Build, stack_size: u32, peripherals_ld: ?[]const u8) []c \\/* ESP32-P4 mask ROM entry points, the only "library" this image links against */ \\ets_printf = 0x4fc00024; \\ets_delay_us = 0x4fc0003c; + \\/* Recalibrate the ROM's cycles-per-microsecond after a CPU clock change; without it every + \\ ets_delay_us is wrong by exactly the frequency ratio (esp32p4.rom.ld:32). */ + \\ets_update_cpu_frequency = 0x4fc00044; \\/* Invalidate the caches. The bootloader leaves lines that do not match the mapping it \\ finally installs, so a large image reads its own .rodata and gets its own .text back. */ \\Cache_Invalidate_All = 0x4fc00404; |
