Repository navigation
Implement pins_v2.zig for stm32f429 and extend support for stm32l479 - #939
Conversation
5137246 to
a739058
Compare
| GPIOF, | ||
| GPIOG, | ||
| pub const Port = enum(u8) { | ||
| GPIOA = if (util.has_port('A')) 0 else undefined, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I fixed this, although it is a small breaking change. Any usage of Port.Configuration should be replaced with PortConfiguration. This is not something that is implementable with generated enums
|
Hey @JAicewizard heads up, the update to zig master has taken place |
|
Thanks for the heads up! I am currently overcome by events, definitly want to finish this and get this merged. |
7deb540 to
ed046a9
Compare
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
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The linked issue’s hal.parse_pin example remains unsupported because that API was removed.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds STM32F429 Discovery HAL and GPIO support while generalizing STM32 GPIO-port discovery.
Changes:
- Dynamically detects available GPIO ports.
- Consolidates GPIO configuration into
pins_v2.zig. - Adds STM32F429 board and blinky support.
| File | Description |
|---|---|
STM32F429.zig |
Adds pins and RCC support. |
common/util.zig |
Adds GPIO-port detection. |
common/pins_v2.zig |
Generalizes pin configuration. |
common/gpio_v2.zig |
Removes superseded implementation. |
STM32F429IDISCOVERY.zig |
Defines LED configuration. |
build.zig |
Attaches the STM32F429 HAL. |
blinky.zig |
Supports STM32F429 Discovery LEDs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| const Digital_IO = microzig.drivers.base.Digital_IO; | ||
|
|
||
| pub const pins = @import("./common/pins_v2.zig"); |

fixes #938
This mostly makes
comon/pins_v2.ziggeneric 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.zigitself, 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.