Skip to content

Implement pins_v2.zig for stm32f429 and extend support for stm32l479#939

Open
JAicewizard wants to merge 10 commits into
ZigEmbeddedGroup:mainfrom
JAicewizard:main
Open

Implement pins_v2.zig for stm32f429 and extend support for stm32l479#939
JAicewizard wants to merge 10 commits into
ZigEmbeddedGroup:mainfrom
JAicewizard:main

Conversation

@JAicewizard
Copy link
Copy Markdown

@JAicewizard JAicewizard commented Apr 27, 2026

fixes #938

This mostly makes comon/pins_v2.zig generic to the number of GPIO ports available on a chip.

I have looked into other methods, like having a function that determins the number of ports in pins_v2.zig itself, but found that it was very cumbersome to implement and it would be easier to pass it down when importing. Since the only files importing this are from microzig itself, this seems like a reasonable option.

JAicewizard and others added 8 commits April 27, 2026 16:32
They were tightly coupled together, but had different types for the same
concept. This introduced unneeded enum casts from and to int, and added
complexity.
Previously pins_v2 was only available on the F303 and L47x, and only
implemented for 7 GPIO ports on the later.

This makes the pins api available to any number of pins (soft limited to
11 due to comptime LUT size). Importer can provide the available number
of ports.

This also makes the api available for stm32f429
@JAicewizard JAicewizard changed the title Enable (and fix) hal for stm32f429 DISC1 board Implement pins_v2.zig for stm32f429 and extend support for stm32l479 Apr 29, 2026
@JAicewizard JAicewizard force-pushed the main branch 3 times, most recently from 8c2aaee to 5137246 Compare May 1, 2026 11:15
pin: Pin,
port: Port,

inline fn write_pin_config(_gpio: GPIO_Pin, mode: Mode) void {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_gpio => p for pin is more inline with the style.

GPIOF,
GPIOG,
pub const Port = enum(u8) {
GPIOA = if (util.has_port('A')) 0 else undefined,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this does not work:

/home/runner/work/microzig/microzig/port/stmicro/stm32/src/hals/common/pins_v2.zig:342:5: error: use of undefined value here causes illegal behavior
    GPIOI = if (util.has_port('I')) 8 else undefined,

The right way to do this is to create an enum at compile-time based on what ports are available. This also brings the benefit of getting rid of the backing integer.

GPIOE: ?Port.Configuration = null,
GPIOF: ?Port.Configuration = null,
GPIOG: ?Port.Configuration = null,
GPIOA: ?if (util.has_port('A')) Port.Configuration else undefined = null,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

microzig.hal is void for stm32f429idiscovery

2 participants