Skip to content

[stm32] Adapt enum.zig - #945

Open
JAicewizard wants to merge 15 commits into
ZigEmbeddedGroup:mainfrom
JAicewizard:adapt_common
Open

JAicewizard wants to merge 15 commits into
ZigEmbeddedGroup:mainfrom
JAicewizard:adapt_common

Conversation

@JAicewizard

Copy link
Copy Markdown

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_index works. 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.

JAicewizard and others added 15 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
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.

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 F429 HAL has a compile-time argument mismatch, and peripheral sorting does not produce the intended numeric order.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity

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

No deployments
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.

2 participants