@@ -737,23 +737,13 @@ pub const startup_logic = struct {
737737 : .{ .memory = true , .r0 = true , .r1 = true });
738738 }
739739
740- if (fpu_present and microzig .options .cpu .enable_fpu ) {
740+ if (microzig .options .cpu .enable_fpu and has_fpu ) {
741741 enable_fpu ();
742- } else if (! fpu_present and microzig .options .cpu .enable_fpu ) {
742+ } else if (microzig .options .cpu .enable_fpu and ! has_fpu ) {
743743 @compileError (
744- \\FPU enable requested though the chip doesn't appear to have an
745- \\FPU. If your chip does have an FPU please add the `fpu_present`
746- \\equal to `true` property to your chip file, either manually or via
747- \\patches. If you want to use patches, you can use something like
748- \\this:
749- \\```
750- \\.{ .set_device_property = .{
751- \\ .device_name = "CHIP_NAME",
752- \\ .key = "fpu_present",
753- \\ .value = "true"
754- \\} },
755- \\```
756- );
744+ \\FPU enable requested though the chip doesn't appear to have an FPU.
745+ \\
746+ ++ fpu_error_helper_message );
757747 }
758748
759749 if (@hasField (types .peripherals .SystemControlBlock , "SHCSR" )) {
@@ -1044,17 +1034,43 @@ const scb_base = scs_base + core.scb_base_offset;
10441034const mpu_base = scs_base + 0x0D90 ;
10451035const fpu_base = scs_base + 0x0F34 ;
10461036
1047- // TODO: will have to standardize this with regz code generation
1048- const mpu_present = @hasDecl (microzig .chip , "properties" ) and
1049- @hasDecl (microzig .chip .properties , "mpu_present" ) and
1050- is_property_true (microzig .chip .properties .mpu_present );
1051- const fpu_present = @hasDecl (microzig .chip , "properties" ) and
1052- @hasDecl (microzig .chip .properties , "fpu_present" ) and
1053- is_property_true (microzig .chip .properties .fpu_present );
1054-
1055- fn is_property_true (value : []const u8 ) bool {
1056- return std .mem .eql (u8 , value , "true" ) or std .mem .eql (u8 , value , "1" );
1057- }
1037+ const has_mpu = microzig .chip .properties .has_mpu orelse
1038+ @compileError (
1039+ \\It is uncertain if this chip has an MPU or not.
1040+ \\
1041+ ++ mpu_error_helper_message );
1042+
1043+ const has_fpu = microzig .chip .properties .has_fpu orelse
1044+ @compileError (
1045+ \\It is uncertain if this chip has an FPU or not.
1046+ \\
1047+ ++ fpu_error_helper_message );
1048+
1049+ const mpu_error_helper_message =
1050+ \\If you are certain the chip does have an MPU, please set `cpu.mpuPresent`
1051+ \\(or `__MPU_PRESENT`) to `true` (or `1`) in your chip file, either manually
1052+ \\or via patches. If you want to use patches, you can use something like this:
1053+ \\```
1054+ \\.{ .set_device_property = .{
1055+ \\ .device_name = "CHIP_NAME",
1056+ \\ .key = "cpu.mpuPresent",
1057+ \\ .value = "true"
1058+ \\} },
1059+ \\```
1060+ ;
1061+
1062+ const fpu_error_helper_message =
1063+ \\If you are certain your chip does have an FPU, please set `cpu.fpuPresent`
1064+ \\(or `__FPU_PRESENT`) to `true` (or `1`) in your chip file, either manually
1065+ \\or via patches. If you want to use patches, you can use something like this:
1066+ \\```
1067+ \\.{ .set_device_property = .{
1068+ \\ .device_name = "CHIP_NAME",
1069+ \\ .key = "cpu.fpuPresent",
1070+ \\ .value = "true"
1071+ \\} },
1072+ \\```
1073+ ;
10581074
10591075const core = blk : {
10601076 break :blk switch (cortex_m ) {
@@ -1078,10 +1094,13 @@ pub const peripherals = struct {
10781094 pub const scb : * volatile types.peripherals.SystemControlBlock = @ptrFromInt (scb_base );
10791095
10801096 /// Floating Point Unit (FPU).
1081- pub const fpu : * volatile types.peripherals.FloatingPointUnit = if (fpu_present )
1097+ pub const fpu : * volatile types.peripherals.FloatingPointUnit = if (has_fpu )
10821098 @ptrFromInt (fpu_base )
10831099 else
1084- @compileError ("this CPU does not have an FPU" );
1100+ @compileError (
1101+ \\This chip doesn't appear to have an FPU.
1102+ \\
1103+ ++ fpu_error_helper_message );
10851104
10861105 /// Nested Vector Interrupt Controller (NVIC).
10871106 pub const nvic : * volatile types.peripherals.NestedVectorInterruptController = @ptrFromInt (nvic_base );
@@ -1090,10 +1109,13 @@ pub const peripherals = struct {
10901109 pub const systick : * volatile types.peripherals.SysTick = @ptrFromInt (systick_base );
10911110
10921111 /// Memory Protection Unit (MPU).
1093- pub const mpu : * volatile types.peripherals.MemoryProtectionUnit = if (mpu_present )
1112+ pub const mpu : * volatile types.peripherals.MemoryProtectionUnit = if (has_mpu )
10941113 @ptrFromInt (mpu_base )
10951114 else
1096- @compileError ("this CPU does not have an MPU" );
1115+ @compileError (
1116+ \\This chip doesn't appear to have an MPU.
1117+ \\
1118+ ++ mpu_error_helper_message );
10971119
10981120 pub const dbg : (if (@hasDecl (core , "DebugRegisters" ))
10991121 * volatile core .DebugRegisters
@@ -1120,7 +1142,10 @@ pub const types = struct {
11201142 pub const FloatingPointUnit = if (@hasDecl (core , "FloatingPointUnit" ))
11211143 core .FloatingPointUnit
11221144 else
1123- @compileError ("this CPU does not have an FPU definition" );
1145+ @compileError (
1146+ \\This chip doesn't appear to have an FPU.
1147+ \\
1148+ ++ fpu_error_helper_message );
11241149
11251150 /// Nested Vector Interrupt Controller (NVIC).
11261151 pub const NestedVectorInterruptController = core .NestedVectorInterruptController ;
@@ -1186,6 +1211,9 @@ pub const types = struct {
11861211 pub const MemoryProtectionUnit = if (@hasDecl (core , "MemoryProtectionUnit" ))
11871212 core .MemoryProtectionUnit
11881213 else
1189- @compileError ("this CPU does not have an MPU definition" );
1214+ @compileError (
1215+ \\This chip doesn't appear to have an MPU.
1216+ \\
1217+ ++ mpu_error_helper_message );
11901218 };
11911219};
0 commit comments