Skip to content

Conversation

@RecursiveError
Copy link
Collaborator

@RecursiveError RecursiveError commented Dec 1, 2025

Note: This is not the final version; renames and configuration corrections are still planned.

  • add clockhelper fork as a internal HAL import

Includes tests for the following microcontrollers (tests are also valid for all microcontrollers in the same sub-family):

  • STM32F103
  • STM32F303
  • STM32L476
  • STM32H723
  • STM32U575
  • STM32G061
  • STM32F777

@RecursiveError
Copy link
Collaborator Author

Note on recursive expressions:

After analyzing the latest bug fix during unit testing for U575, I noticed that some expressions are not actually recursive. What happens is that the reference name ends up being the same as the node name, resulting in confusion during code generation.

Hopefully, by fixing this problem, support for F7/WB/N6 and MP will be restored.

- nuke recursive expr (fix compilation error on STMM/F7/N/W clocktrees)
- add STM32G061 Unit test
- remove unused files from STM32F103
@RecursiveError RecursiveError marked this pull request as ready for review December 17, 2025 22:35
@RecursiveError RecursiveError marked this pull request as draft December 20, 2025 00:37
@RecursiveError
Copy link
Collaborator Author

RecursiveError commented Dec 20, 2025

Just one more small detail: translate flags to booleans instead of optional in out.config

And separate configurations in out.config into Advanced, Normal, and Flags, just like the configuration.

@mattnite
Copy link
Contributor

@RecursiveError i see that there is a massive diff for this PR. Let's put data files in their own repo, what should I call it?

@mathk
Copy link
Collaborator

mathk commented Dec 21, 2025

@RecursiveError i see that there is a massive diff for this PR. Let's put data files in their own repo, what should I call it?

Or could we generate them instead and not check in the file?

@RecursiveError
Copy link
Collaborator Author

@mattnite Well, they actually already have their own repository. This module is basically a copy of it, because I didn’t want to introduce an external dependency.

That said, if the idea is to create one under the org, I originally named it something generic like “ClockHelper”, so I think that name could work. (I do like the name CubeMZ, but I admit it’s kind of a stretch for just clock configuration 😄)

I agree that keeping it as a separate repo makes more sense anyway — there are still going to be a lot of updates coming. I mainly need feedback at this stage to know what should be changed.

RecursiveError and others added 2 commits December 22, 2025 21:18
Co-authored-by: Mathieu Suen <[email protected]>
@mathk
Copy link
Collaborator

mathk commented Dec 23, 2025

Let me know if you need help solving the conflict. I have change the hal.zig file. and move it back to the STM32F103.zig file. That might be the source of it.

@RecursiveError RecursiveError marked this pull request as ready for review December 24, 2025 00:10
@RecursiveError
Copy link
Collaborator Author

RecursiveError commented Dec 24, 2025

The clockhelper is ready for now.

@mattnite Regarding separating the data files into their own repository, do you have any ideas in mind? I intended to just add the original repository as a dependency of this module and pass hal_imports as an argument in the init() function of chips.zig.

@mattnite
Copy link
Contributor

@RecursiveError I think the best way to split it up would be to incorporate the ClockHelper repo into microzig, but keep the mcu_data directory as a data repository. Then what I'd like to see is file generation on the fly. Ideally we'd only generate what we need, not every clock tree for every device. This way code generation for the clock tree looks pretty similar to how Regz works.

@RecursiveError
Copy link
Collaborator Author

@mattnite That makes sense. I can modify the code generator to emit individual clock trees, or even a small set on the fly, instead of producing everything upfront.

What I’m still not fully clear on is how the pieces are expected to be wired together:
how would the generator receive information about what needs to be generated, and how should the generated code be exposed or integrated so that the HALs can actually consume it?

Understanding that interface/flow will help me align the generator with the intended architecture.

@mathk
Copy link
Collaborator

mathk commented Dec 26, 2025

What I’m still not fully clear on is how the pieces are expected to be wired together:
how would the generator receive information about what needs to be generated, and how should the generated code be exposed or integrated so that the HALs can actually consume it?

I have no clear idea too but I guess once this is merge we can start pushing more RCC related work to the common folder. And I got the feeling that clocks is core components for HAL so it would really improve STM32 HAL. :)

@mattnite
Copy link
Contributor

@RecursiveError I'm going to be diving into this patch further tomorrow so I can better determine what the interface should be.

@mattnite
Copy link
Contributor

mattnite commented Dec 28, 2025

@RecursiveError I have some ideas. First off, we have something workable, the main reason I want to structure things differently is so that generated code, with potentially very large changes every once in a while is something I'd like to keep in separate repos. One exception of note is the Chips.zig file for our stm32 port, I don't think there's a way around that one.

I've created a repo for you: https://github.com/ZigEmbeddedGroup/ClockHelper, essentially what I want you to do is move everything under stm32-clocks there. From what I understand, we should have a very clean interface which is very similar to how things work currently: a single ClockHelper module which is imported by every stm32 target in the port. I know I said I wanted to separate things chip-by-chip but let's kick that can down the road.

From my understanding of this single module, it has all the clock trees for all the chips, and we currently select which one by chip name at comptime using a mapping function.

This should provide a great starting point that we can iterate on. Thank you for all this amazing work, and putting even more effort into integrating it with MicroZig.

@RecursiveError
Copy link
Collaborator Author

what I want you to do is move everything under stm32-clocks there.

I don't have permission to make the initial commit to the repo :(

@mattnite
Copy link
Contributor

@RecursiveError fixed, made you a maintainer and pushed an init commit

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🔍 Lint Results

Found 2 issues on changed lines in 2 files:

  • port/stmicro/stm32/src/hals/STM32F103/mcu_trees.zig: 1 issue
  • port/stmicro/stm32/src/hals/STM32F103/rcc.zig: 1 issue
ℹ️ Additional issues on unchanged lines
The following 19 issue(s) exist but are not on lines changed in this PR:

examples/stmicro/stm32/src/stm32f1xx/rtc.zig:24: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/timer_capture.zig:1: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig:1: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig:2: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig:210: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig:438: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig:1: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig:2: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig:154: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig:246: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig:277: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/generate.zig:256: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:2: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:100: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:102: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:309: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:430: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:552: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:568: TODO style comments need to have a linked microzig issue on the same line.

@@ -0,0 +1,134 @@
//TODO: find a better way to select and configure the clock tree for each MCU

Choose a reason for hiding this comment

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

TODO style comments need to have a linked microzig issue on the same line.

@@ -1,23 +1,20 @@
//NOTE: this file is only valid for densities: Low, Medium, High, and XL. Connectivity line devices are not supported in this version.
//NOTE: this file is only valid for densities: Low, Medium and High. Connectivity/XL line devices are not supported in this version.

Choose a reason for hiding this comment

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

TODO style comments need to have a linked microzig issue on the same line.

@github-actions github-actions bot dismissed their stale review December 28, 2025 19:05

Updating with new lint results

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🔍 Lint Results

Found 1 issue on changed lines in 1 file:

  • port/stmicro/stm32/src/hals/STM32F103/rcc.zig: 1 issue
ℹ️ Additional issues on unchanged lines
The following 19 issue(s) exist but are not on lines changed in this PR:

examples/stmicro/stm32/src/stm32f1xx/rtc.zig:24: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/timer_capture.zig:1: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig:1: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig:2: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig:210: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig:438: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig:1: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig:2: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig:154: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig:246: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig:277: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/generate.zig:256: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:2: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:100: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:102: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:309: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:430: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:552: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:568: TODO style comments need to have a linked microzig issue on the same line.

@mattnite mattnite merged commit 157b58f into ZigEmbeddedGroup:main Dec 28, 2025
48 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.

3 participants