[stm32] Adapt enum.zig - #945
Open
JAicewizard wants to merge 15 commits into
Open
JAicewizard wants to merge 15 commits into
JAicewizard wants to merge 15 commits into
Conversation
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
This makes it so that all peripherals always get added, so this should be good for almost any chip. Only thing that needs to be done is potentially add more indexed peripherals. This commit also fixes the peripheral index to work on chips where the peripherals are not coincidentally in order.
JAicewizard
force-pushed
the
adapt_common
branch
from
August 13, 2026 14:27
f708e7e to
5397a8f
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The F429 HAL has a compile-time argument mismatch, and peripheral sorting does not produce the intended numeric order.
Review effort: Balanced
Findings: 1
Open (3)
What changed in this PR
Adapts STM32 peripheral enums and incorporates generic GPIO support from #939.
Changes:
- Generates peripheral enums dynamically with reordered subtype indices.
- Generalizes GPIO ports and adds STM32F429 HAL/board support.
- Adds STM32F429 to the blinky example path.
| File | Description |
|---|---|
port/stmicro/stm32/src/hals/STM32F429.zig |
Adds pins, enums, and RCC support. |
port/stmicro/stm32/src/hals/STM32F303.zig |
Corrects the enums import path. |
port/stmicro/stm32/src/hals/STM32F103.zig |
Exposes common enums. |
port/stmicro/stm32/src/hals/common/util.zig |
Generates and sorts peripheral enums. |
port/stmicro/stm32/src/hals/common/pins_v2.zig |
Generalizes GPIO configuration across available ports. |
port/stmicro/stm32/src/hals/common/gpio_v2.zig |
Removes the superseded GPIO implementation. |
port/stmicro/stm32/src/hals/common/enums.zig |
Expands peripheral subtype generation and indexing. |
port/stmicro/stm32/src/hals/common/bdma_v2.zig |
Applies formatting only. |
port/stmicro/stm32/src/boards/STM32F429IDISCOVERY.zig |
Adds HAL access and LED configuration. |
port/stmicro/stm32/build.zig |
Attaches the F429 HAL to its board target. |
examples/stmicro/stm32/src/blinky.zig |
Adds F429 Discovery LED handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+59
to
+61
| pub const Peripherals = util.create_peripheral_enum(&.{ | ||
| "GPIO", | ||
| }); |
| pub const TIMGP16_Type = util.sub_peripheral_enum(Peripherals, &[_][]const u8{"TIM"}, "TIM_GP16"); | ||
| pub const ADC_Type = util.sub_peripheral_enum(Peripherals, &[_][]const u8{"ADC"}, null); | ||
| pub const CAN_Type = util.sub_peripheral_enum(Peripherals, &[_][]const u8{"CAN"}, null); | ||
| pub const SAL_Type = util.sub_peripheral_enum(Peripherals, &[_][]const u8{"SAL"}, null); |
Comment on lines
+42
to
+43
| const ai = std.fmt.parseInt(u8, aname[an.len..aname.len], 10) catch 0; | ||
| const bi = std.fmt.parseInt(u8, bname[bn.len..bname.len], 10) catch 0; |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This is currently a bit messy as it includes the changes in #939, this will be fixed once that is merged.
[The commits intended to be in] this PR remove remove the constant strings for which peripherals should be included, and change how
base_perihperal_indexworks. This last change could technically breaking, but it was extremely unreliable as it depended on the order the peripherals were specified by embassy. I do not believe any correct usage is affected.