diff --git a/port/raspberrypi/rp2xxx/build.zig b/port/raspberrypi/rp2xxx/build.zig index fd39dd5ee..4d4f01033 100644 --- a/port/raspberrypi/rp2xxx/build.zig +++ b/port/raspberrypi/rp2xxx/build.zig @@ -62,14 +62,14 @@ pub fn init(dep: *std.Build.Dependency) Self { .cpu_arch = .thumb, .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m33 }, .os_tag = .freestanding, - .abi = .eabi, + .abi = .eabihf, }, .register_definition = .{ .svd = b.path("src/chips/rp2350.svd") }, .memory_regions = &.{ .{ .kind = .flash, .offset = 0x10000000, .length = 2048 * 1024 }, .{ .kind = .ram, .offset = 0x20000000, .length = 256 * 1024 }, }, - .patches = @import("patches/rp2350.zig").patches, + .patches = @import("patches/rp2350_arm.zig").patches, }, .hal = hal, .linker_script = b.path("rp2350_arm.ld"), @@ -105,14 +105,7 @@ pub fn init(dep: *std.Build.Dependency) Self { .{ .kind = .flash, .offset = 0x10000000, .length = 256 }, .{ .kind = .ram, .offset = 0x20000000, .length = 256 * 1024 }, }, - .patches = &.{ - .{ - .override_arch = .{ - .device_name = "RP2350", - .arch = .hazard3, - }, - }, - }, + .patches = @import("patches/rp2350_riscv.zig").patches, }, .hal = hal, .linker_script = b.path("rp2350_riscv.ld"), diff --git a/port/raspberrypi/rp2xxx/patches/rp2350.zig b/port/raspberrypi/rp2xxx/patches/rp2350_arm.zig similarity index 71% rename from port/raspberrypi/rp2xxx/patches/rp2350.zig rename to port/raspberrypi/rp2xxx/patches/rp2350_arm.zig index ae3f66efa..51319659c 100644 --- a/port/raspberrypi/rp2xxx/patches/rp2350.zig +++ b/port/raspberrypi/rp2xxx/patches/rp2350_arm.zig @@ -1,19 +1,17 @@ pub const patches = &.{ - .{ - .add_enum = .{ - .parent = "types.peripherals.USB_DPRAM", - .@"enum" = .{ - .name = "EndpointType", - .bitsize = 2, - .fields = &.{ - .{ .value = 0x0, .name = "control" }, - .{ .value = 0x1, .name = "isochronous" }, - .{ .value = 0x2, .name = "bulk" }, - .{ .value = 0x3, .name = "interrupt" }, - }, + .{ .add_enum = .{ + .parent = "types.peripherals.USB_DPRAM", + .@"enum" = .{ + .name = "EndpointType", + .bitsize = 2, + .fields = &.{ + .{ .value = 0x0, .name = "control" }, + .{ .value = 0x1, .name = "isochronous" }, + .{ .value = 0x2, .name = "bulk" }, + .{ .value = 0x3, .name = "interrupt" }, }, }, - }, + } }, .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP1_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP1_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP2_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, @@ -44,4 +42,49 @@ pub const patches = &.{ .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP14_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP15_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP15_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 40, + .name = "PROC0_IRQ_CTI", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 41, + .name = "PROC1_IRQ_CTI", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 46, + .name = "SPAREIRQ_IRQ_0", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 47, + .name = "SPAREIRQ_IRQ_1", + .description = "Spare interrupt 1 (triggered only by software)", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 48, + .name = "SPAREIRQ_IRQ_2", + .description = "Spare interrupt 2 (triggered only by software)", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 49, + .name = "SPAREIRQ_IRQ_3", + .description = "Spare interrupt 3 (triggered only by software)", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 50, + .name = "SPAREIRQ_IRQ_4", + .description = "Spare interrupt 4 (triggered only by software)", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 51, + .name = "SPAREIRQ_IRQ_5", + .description = "Spare interrupt 5 (triggered only by software)", + } }, }; diff --git a/port/raspberrypi/rp2xxx/patches/rp2350_riscv.zig b/port/raspberrypi/rp2xxx/patches/rp2350_riscv.zig new file mode 100644 index 000000000..1424339ce --- /dev/null +++ b/port/raspberrypi/rp2xxx/patches/rp2350_riscv.zig @@ -0,0 +1,95 @@ +pub const patches = &.{ + .{ .override_arch = .{ + .device_name = "RP2350", + .arch = .hazard3, + } }, + .{ .add_enum = .{ + .parent = "types.peripherals.USB_DPRAM", + .@"enum" = .{ + .name = "EndpointType", + .bitsize = 2, + .fields = &.{ + .{ .value = 0x0, .name = "control" }, + .{ .value = 0x1, .name = "isochronous" }, + .{ .value = 0x2, .name = "bulk" }, + .{ .value = 0x3, .name = "interrupt" }, + }, + }, + } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP1_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP1_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP2_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP2_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP3_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP3_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP4_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP4_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP5_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP5_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP6_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP6_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP7_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP7_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP8_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP8_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP9_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP9_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP10_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP10_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP11_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP11_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP12_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP12_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP13_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP13_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP14_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP14_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP15_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP15_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 40, + .name = "PROC0_IRQ_CTI", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 41, + .name = "PROC1_IRQ_CTI", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 46, + .name = "SPAREIRQ_IRQ_0", + .description = "Spare interrupt 0 (triggered only by software)", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 47, + .name = "SPAREIRQ_IRQ_1", + .description = "Spare interrupt 1 (triggered only by software)", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 48, + .name = "SPAREIRQ_IRQ_2", + .description = "Spare interrupt 2 (triggered only by software)", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 49, + .name = "SPAREIRQ_IRQ_3", + .description = "Spare interrupt 3 (triggered only by software)", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 50, + .name = "SPAREIRQ_IRQ_4", + .description = "Spare interrupt 4 (triggered only by software)", + } }, + .{ .add_interrupt = .{ + .device_name = "RP2350", + .idx = 51, + .name = "SPAREIRQ_IRQ_5", + .description = "Spare interrupt 5 (triggered only by software)", + } }, +}; diff --git a/port/raspberrypi/rp2xxx/rp2350_arm.ld b/port/raspberrypi/rp2xxx/rp2350_arm.ld index 71e0d14cd..30d7b8293 100644 --- a/port/raspberrypi/rp2xxx/rp2350_arm.ld +++ b/port/raspberrypi/rp2xxx/rp2350_arm.ld @@ -52,7 +52,7 @@ SECTIONS *(.bss*) microzig_bss_end = .; } > ram0 - + .flash_end : { microzig_flash_end = .; diff --git a/tools/regz/src/Database.zig b/tools/regz/src/Database.zig index b4d8c3fea..bd2b3d556 100644 --- a/tools/regz/src/Database.zig +++ b/tools/regz/src/Database.zig @@ -2027,6 +2027,17 @@ pub fn apply_patch(db: *Database, ndjson: []const u8) !void { try db.set_register_field_enum_id(register_id, field_name, enum_id); try db.cleanup_unused_enums(); }, + .add_interrupt => |add_interrupt| { + const device_id = try db.get_device_id_by_name(add_interrupt.device_name) orelse { + return error.DeviceNotFound; + }; + + _ = try db.create_interrupt(device_id, .{ + .name = add_interrupt.name, + .description = add_interrupt.description, + .idx = add_interrupt.idx, + }); + }, } } } diff --git a/tools/regz/src/patch.zig b/tools/regz/src/patch.zig index d9a55d2b5..915b7ee43 100644 --- a/tools/regz/src/patch.zig +++ b/tools/regz/src/patch.zig @@ -32,6 +32,12 @@ pub const Patch = union(enum) { of: []const u8, to: []const u8, }, + add_interrupt: struct { + device_name: []const u8, + idx: i32, + name: []const u8, + description: ?[]const u8 = null, + }, pub fn from_json_str(allocator: Allocator, json_str: []const u8) !std.json.Parsed(Patch) { return std.json.parseFromSlice(Patch, allocator, json_str, .{}); diff --git a/tools/regz/src/svd.zig b/tools/regz/src/svd.zig index 3a7d72516..6332a71e9 100644 --- a/tools/regz/src/svd.zig +++ b/tools/regz/src/svd.zig @@ -267,6 +267,11 @@ fn arch_from_str(str: []const u8) Database.Arch { pub fn load_peripheral(ctx: *Context, node: xml.Node, device_id: DeviceID) !void { const db = ctx.db; + // load interrupts regardless of the fact that the peripheral is derived + var interrupt_it = node.iterate(&.{}, &.{"interrupt"}); + while (interrupt_it.next()) |interrupt_node| + try load_interrupt(db, interrupt_node, device_id); + if (node.get_attribute("derivedFrom")) |derived_from| { try ctx.derived_peripherals.put(ctx.arena.allocator(), node, derived_from); return; @@ -304,10 +309,6 @@ pub fn load_peripheral(ctx: *Context, node: xml.Node, device_id: DeviceID) !void }); _ = instance_id; - var interrupt_it = node.iterate(&.{}, &.{"interrupt"}); - while (interrupt_it.next()) |interrupt_node| - try load_interrupt(db, interrupt_node, device_id); - //if (node.get_value("version")) |version| // try db.add_version(instance_id, version);