Skip to content

Commit 073ab29

Browse files
committed
Make STM32 HAL and board more align and push more peripheral to common
folder
1 parent cec6800 commit 073ab29

File tree

25 files changed

+537
-474
lines changed

25 files changed

+537
-474
lines changed

examples/stmicro/stm32/build.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ pub fn build(b: *std.Build) void {
1616
const available_examples = [_]Example{
1717
.{ .target = stm32.boards.stm32f3discovery, .name = "stm32f3discovery", .file = "src/blinky.zig" },
1818
// TODO: stm32.pins.GlobalConfiguration is not available on those targets
19-
// .{ .target = stm32.chips.stm32f303vc, .name = "stm32f303vc", .file = "src/blinky.zig" },
2019
// .{ .target = stm32.chips.stm32f407vg, .name = "stm32f407vg", .file = "src/blinky.zig" },
2120
// .{ .target = stm32.chips.stm32f429zit6u, .name = "stm32f429zit6u", .file = "src/blinky.zig" },
2221
// .{ .target = stm32.boards.stm32f4discovery, .name = "stm32f4discovery", .file = "src/blinky.zig" },
2322
// .{ .target = stm32.boards.stm3240geval, .name = "stm3240geval", .file = "src/blinky.zig" },
2423
// .{ .target = stm32.boards.stm32f429idiscovery, .name = "stm32f429idiscovery", .file = "src/blinky.zig" },
25-
.{ .target = stm32.boards.stm32f3discovery, .name = "STM32F303_HTS221", .file = "src/stm32f303/hts221.zig" },
24+
.{ .target = stm32.boards.stm32f3discovery, .name = "STM32F303_HTS221", .file = "src/hts221.zig" },
2625
.{ .target = stm32.boards.stm32l476discovery, .name = "STM32L476Discovery_Lcd", .file = "src/stm32l476/lcd.zig" },
26+
.{ .target = stm32.boards.stm32l476discovery, .name = "STM32L476Discovery_Blinky", .file = "src/blinky.zig" },
27+
.{ .target = stm32.boards.stm32l476discovery, .name = "STM32L476Discovery_HTS211", .file = "src/hts221.zig" },
2728
.{ .target = stm32.chips.STM32F103C8, .name = "STM32F1xx_blink", .file = "src/blinky.zig" },
2829
.{ .target = stm32.chips.STM32F100RB, .name = "STM32F1xx_semihost", .file = "src/semihosting.zig" }, //QEMU target: stm32vldiscovery
2930
.{ .target = stm32.chips.STM32F103C8, .name = "STM32F1xx_adc", .file = "src/stm32f1xx/adc.zig" },

examples/stmicro/stm32/src/blinky.zig

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const std = @import("std");
22
const microzig = @import("microzig");
3-
const stm32 = microzig.hal;
3+
const hal = microzig.hal;
4+
const board = microzig.board;
45

56
fn delay() void {
67
var i: u32 = 0;
@@ -13,35 +14,33 @@ fn delay() void {
1314
pub fn main() !void {
1415
const pins, const all_leds = res: {
1516
if (comptime std.mem.eql(u8, microzig.config.chip_name, "STM32F103C8")) {
16-
const pins = (stm32.pins.GlobalConfiguration{ .GPIOC = .{
17+
const pins = (hal.pins.GlobalConfiguration{ .GPIOC = .{
1718
.PIN13 = .{ .name = "led", .mode = .{ .output = .general_purpose_push_pull } },
1819
} }).apply();
1920
const all_leds = .{
2021
pins.led,
2122
};
2223
break :res .{ pins, all_leds };
2324
} else if (comptime microzig.config.board_name != null and std.mem.eql(u8, microzig.config.board_name.?, "STM32F3DISCOVERY")) {
24-
const pins = (stm32.pins.GlobalConfiguration{
25-
.GPIOE = .{
26-
.PIN8 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
27-
.PIN9 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
28-
.PIN10 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
29-
.PIN11 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
30-
.PIN12 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
31-
.PIN13 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
32-
.PIN14 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
33-
.PIN15 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
34-
},
35-
}).apply();
25+
const pins = board.leds_config.apply();
26+
const all_leds = .{
27+
pins.LD3,
28+
pins.LD4,
29+
pins.LD5,
30+
pins.LD6,
31+
pins.LD7,
32+
pins.LD8,
33+
pins.LD9,
34+
pins.LD10,
35+
};
36+
37+
break :res .{ pins, all_leds };
38+
} else if (comptime microzig.config.board_name != null and std.mem.eql(u8, microzig.config.board_name.?, "STM32L476DISCOVERY")) {
39+
const pins = board.leds_config.apply();
40+
3641
const all_leds = .{
37-
pins.PE8,
38-
pins.PE9,
39-
pins.PE10,
40-
pins.PE11,
41-
pins.PE12,
42-
pins.PE13,
43-
pins.PE14,
44-
pins.PE15,
42+
pins.LD4,
43+
pins.LD5,
4544
};
4645

4746
break :res .{ pins, all_leds };

examples/stmicro/stm32/src/stm32f303/hts221.zig renamed to examples/stmicro/stm32/src/hts221.zig

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
const std = @import("std");
22
const microzig = @import("microzig");
33
const stm32 = microzig.hal;
4+
const board = microzig.board;
45
const HTS221 = microzig.drivers.sensor.HTS221;
56

67
fn delay() void {
78
var i: u32 = 0;
8-
while (i < 8_000_000) {
9+
while (i < 800_000) {
910
microzig.cpu.nop();
1011
i += 1;
1112
}
@@ -16,24 +17,12 @@ pub const microzig_options: microzig.Options = .{
1617
};
1718

1819
pub fn init() void {
19-
microzig.board.init();
20-
microzig.board.init_log();
20+
board.init();
21+
board.init_log();
2122
}
2223

2324
pub fn main() !void {
24-
_ = (stm32.pins.GlobalConfiguration{
25-
.GPIOB = .{
26-
// I2C
27-
.PIN6 = .{ .mode = .{ .alternate_function = .{
28-
.afr = .AF4,
29-
} } },
30-
.PIN7 = .{ .mode = .{ .alternate_function = .{
31-
.afr = .AF4,
32-
} } },
33-
},
34-
}).apply();
35-
36-
var i2c1 = stm32.i2c.I2C_Device.init(.I2C1);
25+
var i2c1 = board.i2c1();
3726
try i2c1.apply();
3827
var device = i2c1.i2c_device();
3928

port/stmicro/stm32/src/Chips.zig

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4560,7 +4560,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
45604560
},
45614561
},
45624562
.hal = .{
4563-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4563+
.root_source_file = b.path("src/hals/STM32F103.zig"),
45644564
},
45654565
};
45664566

@@ -4585,7 +4585,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
45854585
},
45864586
},
45874587
.hal = .{
4588-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4588+
.root_source_file = b.path("src/hals/STM32F103.zig"),
45894589
},
45904590
};
45914591

@@ -4610,7 +4610,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
46104610
},
46114611
},
46124612
.hal = .{
4613-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4613+
.root_source_file = b.path("src/hals/STM32F103.zig"),
46144614
},
46154615
};
46164616

@@ -4635,7 +4635,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
46354635
},
46364636
},
46374637
.hal = .{
4638-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4638+
.root_source_file = b.path("src/hals/STM32F103.zig"),
46394639
},
46404640
};
46414641

@@ -4660,7 +4660,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
46604660
},
46614661
},
46624662
.hal = .{
4663-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4663+
.root_source_file = b.path("src/hals/STM32F103.zig"),
46644664
},
46654665
};
46664666

@@ -4685,7 +4685,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
46854685
},
46864686
},
46874687
.hal = .{
4688-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4688+
.root_source_file = b.path("src/hals/STM32F103.zig"),
46894689
},
46904690
};
46914691

@@ -4710,7 +4710,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
47104710
},
47114711
},
47124712
.hal = .{
4713-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4713+
.root_source_file = b.path("src/hals/STM32F103.zig"),
47144714
},
47154715
};
47164716

@@ -4735,7 +4735,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
47354735
},
47364736
},
47374737
.hal = .{
4738-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4738+
.root_source_file = b.path("src/hals/STM32F103.zig"),
47394739
},
47404740
};
47414741

@@ -4760,7 +4760,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
47604760
},
47614761
},
47624762
.hal = .{
4763-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4763+
.root_source_file = b.path("src/hals/STM32F103.zig"),
47644764
},
47654765
};
47664766

@@ -4785,7 +4785,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
47854785
},
47864786
},
47874787
.hal = .{
4788-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4788+
.root_source_file = b.path("src/hals/STM32F103.zig"),
47894789
},
47904790
};
47914791

@@ -4810,7 +4810,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
48104810
},
48114811
},
48124812
.hal = .{
4813-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4813+
.root_source_file = b.path("src/hals/STM32F103.zig"),
48144814
},
48154815
};
48164816

@@ -4836,7 +4836,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
48364836
},
48374837
},
48384838
.hal = .{
4839-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4839+
.root_source_file = b.path("src/hals/STM32F103.zig"),
48404840
},
48414841
};
48424842

@@ -4862,7 +4862,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
48624862
},
48634863
},
48644864
.hal = .{
4865-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4865+
.root_source_file = b.path("src/hals/STM32F103.zig"),
48664866
},
48674867
};
48684868

@@ -4887,7 +4887,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
48874887
},
48884888
},
48894889
.hal = .{
4890-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4890+
.root_source_file = b.path("src/hals/STM32F103.zig"),
48914891
},
48924892
};
48934893

@@ -4912,7 +4912,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
49124912
},
49134913
},
49144914
.hal = .{
4915-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4915+
.root_source_file = b.path("src/hals/STM32F103.zig"),
49164916
},
49174917
};
49184918

@@ -4937,7 +4937,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
49374937
},
49384938
},
49394939
.hal = .{
4940-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4940+
.root_source_file = b.path("src/hals/STM32F103.zig"),
49414941
},
49424942
};
49434943

@@ -4962,7 +4962,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
49624962
},
49634963
},
49644964
.hal = .{
4965-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4965+
.root_source_file = b.path("src/hals/STM32F103.zig"),
49664966
},
49674967
};
49684968

@@ -4987,7 +4987,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
49874987
},
49884988
},
49894989
.hal = .{
4990-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
4990+
.root_source_file = b.path("src/hals/STM32F103.zig"),
49914991
},
49924992
};
49934993

@@ -5012,7 +5012,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
50125012
},
50135013
},
50145014
.hal = .{
5015-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5015+
.root_source_file = b.path("src/hals/STM32F103.zig"),
50165016
},
50175017
};
50185018

@@ -5037,7 +5037,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
50375037
},
50385038
},
50395039
.hal = .{
5040-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5040+
.root_source_file = b.path("src/hals/STM32F103.zig"),
50415041
},
50425042
};
50435043

@@ -5062,7 +5062,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
50625062
},
50635063
},
50645064
.hal = .{
5065-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5065+
.root_source_file = b.path("src/hals/STM32F103.zig"),
50665066
},
50675067
};
50685068

@@ -5087,7 +5087,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
50875087
},
50885088
},
50895089
.hal = .{
5090-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5090+
.root_source_file = b.path("src/hals/STM32F103.zig"),
50915091
},
50925092
};
50935093

@@ -5113,7 +5113,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
51135113
},
51145114
},
51155115
.hal = .{
5116-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5116+
.root_source_file = b.path("src/hals/STM32F103.zig"),
51175117
},
51185118
};
51195119

@@ -5139,7 +5139,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
51395139
},
51405140
},
51415141
.hal = .{
5142-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5142+
.root_source_file = b.path("src/hals/STM32F103.zig"),
51435143
},
51445144
};
51455145

@@ -5164,7 +5164,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
51645164
},
51655165
},
51665166
.hal = .{
5167-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5167+
.root_source_file = b.path("src/hals/STM32F103.zig"),
51685168
},
51695169
};
51705170

@@ -5189,7 +5189,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
51895189
},
51905190
},
51915191
.hal = .{
5192-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5192+
.root_source_file = b.path("src/hals/STM32F103.zig"),
51935193
},
51945194
};
51955195

@@ -5214,7 +5214,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
52145214
},
52155215
},
52165216
.hal = .{
5217-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5217+
.root_source_file = b.path("src/hals/STM32F103.zig"),
52185218
},
52195219
};
52205220

@@ -5240,7 +5240,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
52405240
},
52415241
},
52425242
.hal = .{
5243-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5243+
.root_source_file = b.path("src/hals/STM32F103.zig"),
52445244
},
52455245
};
52465246

@@ -5266,7 +5266,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
52665266
},
52675267
},
52685268
.hal = .{
5269-
.root_source_file = b.path("src/hals/STM32F103/hal.zig"),
5269+
.root_source_file = b.path("src/hals/STM32F103.zig"),
52705270
},
52715271
};
52725272

0 commit comments

Comments
 (0)