Skip to content

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

Merged
mattnite merged 18 commits into
ZigEmbeddedGroup:mainfrom
JAicewizard:main
Oct 9, 2026
Merged

mattnite merged 18 commits into
ZigEmbeddedGroup:mainfrom
JAicewizard:main

Conversation

@JAicewizard

@JAicewizard JAicewizard commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

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 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 4 times, most recently from 5137246 to a739058 Compare May 1, 2026 11:17
Comment thread port/stmicro/stm32/src/hals/common/pins_v2.zig Outdated
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Comment thread port/stmicro/stm32/src/hals/common/pins_v2.zig Outdated
@mattnite

mattnite commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Hey @JAicewizard heads up, the update to zig master has taken place

@JAicewizard

Copy link
Copy Markdown
Contributor Author

Thanks for the heads up! I am currently overcome by events, definitly want to finish this and get this merged.

@JAicewizard
JAicewizard force-pushed the main branch 3 times, most recently from 7deb540 to ed046a9 Compare August 11, 2026 23:55
JAicewizard and others added 12 commits August 12, 2026 02:25
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
@Grazfather
Grazfather requested review from mattnite and a balanced review from Copilot October 6, 2026 02:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 High severity

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");
@mattnite
mattnite merged commit 83d847b into ZigEmbeddedGroup:main Oct 9, 2026
12 of 14 checks passed
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

3 participants