Skip to content

!reorganize and unify STM32 ports - #19004

Draft
raiden00pl wants to merge 27 commits into
apache:masterfrom
raiden00pl:stm32_refactor_all
Draft

raiden00pl wants to merge 27 commits into
apache:masterfrom
raiden00pl:stm32_refactor_all

Conversation

@raiden00pl

@raiden00pl raiden00pl commented May 31, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR is the first step toward unification and reorganisation of STM32 ports. This is a huge, breaking change that impacts many users. It also introduces the standard for STM32 ports described in the documentation page. Any new STM32 port or new STM32 feature should adhere to these rules.

This reorganization allows for the separation of STM32 families with minimal code duplication. Ultimately, we'll be able to eliminate most of the duplication between STM32 families, but this is a long-term task. Subsequent changes won't be as invasive, and most won't require breaking changes.

This PR focuses on the first step in the STM32 redesign, which is the most invasive and includes a lot of breaking changes.

Summary of changes:

  1. Each STM32 family has its own directory.
  2. STM32 families can use the STM32 common directory, which allows them to use common drivers and common hardware definitions shared between families.
  3. Peripheral drivers included by a family depend on the peripheral's IP core version.
  4. STM32 Kconfig option names are unified.
  5. STM32 boards can use common board drivers.
  6. STM32 hardware definition names are unified.
  7. Kconfig files have been split into smaller ones, which makes them much easier to manage. This was proposed several times for new STM32 ports before, but doing it for one STM32 port and leaving the rest untouched didn't make sense. Now it's done for all STM32 ports, as it should be.
  8. Added a documentation page discussing STM32 ports organisation.
  9. Add boards/common/stm32 support for STM32L4

What is not done yet:

  1. Migrate all other families to STM32 arch common directories.
    The stm32f7, stm32h7, and stm32l4 should be easy. The rest, based on the Cortex-M33, will require more time because I'm not familiar with these chips yet. After this migration, support for the missing stm32 families should be much easier.
  2. Migrate all other families to STM32 board common directories.
    This change will later enable us to solve another problem - the standardization of ST boards, so all nucleo board follows the same patterns and provide the same features.
  3. Unify and clean up Kconfig options and families features. Ultimately, each family should support the same features as the hardware allows. At the moment Kconfig has some long and ugly lines, they need to be analyzed and simplified. Kconfig still has a few sections that have not been generalized, mainly due to drift of some families from other implementations.
  4. Some families have driver changes that haven't been propagated to other families. This needs to be properly analyzed and ported where possible.
  5. regenerate CODEOWNERS

I know this PR is huge, but it can't really be done in smaller steps. This is an attempt to fix a problem that's been building for over a decade. I will create a separate PR so it is easier to review, this PR is to show the final effect . The best way to review this change is to download the entire branch and view it locally. Github is unable to render changes well and misses many git rename operations.

If the community deems this change desirable, it should be included in version 13.0, as it's a significant change that's causing a lot of disruption. I think this is the best time for this reorganization, even if it will upset many users and likely break something.

For all AI skeptics here - this PR was created with AI assistance and burned hundreds of dollars worth of tokens. There is no other way to do it, doing it manually is unrealistic, especially if you do it alone and for free :) This PR doesn't add new code, it only organizes the old code, so the code license remains the same as the original code

References:
#18894
#16172

Impact

Breaking change that impacts many users. There should be no functional changes; users should only need to update defconfig options in theory, but this is a huge change done mostly with AI assistance, so there is some chance that things will be broken.
The larger the PR, the greater the chance that something will break uncontrollably. Therefore, if this change is to be implemented upstream, it should be in release 13.0, which already contains a lot of breaking changes.

I tried to preserve the git history as much as possible, but for Kconfig it was not possible.

What we gain from this PR:

  1. Unification and standardization of STM32. Portability between STM32 families will finally be as it should be.
    No more questions about how to create new STM32 ports, everything is set in advance and the user has to comply.
  2. After the migration of the remaining families to common/stm32 is completed, maintaining the families will be much easier. Fewer files to track, less duplicate code.
  3. Adding support for new STM32 families will be easier. Reusable blocks can be easily included by new ports.
  4. All STM32 boards can use the same boards/common, which can significantly simplify boards code. Ultimately, it should be possible to standardize all STM32 boards like nucleo and create common board initialization logic.

Testing

CI

upstream build and test on HW:

  • nucleo-l073rz:nsh - OK
  • nucleo-f103rb:nsh - OK
  • nucleo-l152re:nsh - OK
  • nucleo-f091rc:nsh - OK
  • nucleo-c071rb:jumbo - OK
  • nucleo-h743zi:nsh - OK
  • nucleo-f446re:jumbo - OK

Later I will do tests with my Dawn project (https://github.com/railab/dawn) where I have a lot of HW automated tests based on NTFC, so it should catch most of the regressions.

PRs

These needs to go to release 13.0 as these are major breaking changes that completely reorganize STM32 ports.

Done:
#19066
#19067
#19069
#19114
#19125
#19136
#19143

Pending:

Next in line, separated PRs:

bf58190 !arch/arm/src/stm32: unify timer driver and STM32_TIMn_CLKIN across all families
e310ecb !arch/stm32: Unify and commonize stm32_uid for all STM32 families.


Can be merged after release 13.0:

2797fe0 arch/arm/src/stm32: unify quadrature encoder driver into common/stm32
eb46a77 arch/arm/src/stm32: unify TIM1/TIM8 interrupt vector names across families
194fd55 arch/arm/src/stm32: unify TIM one-shot wrapper into common/stm32
786bc83 arch/arm/src/stm32: unify TIM free-running wrapper into common/stm32
59df038 arch/arm/src/stm32: unify LSI driver and make RCC headers per-family
f371090 arch/arm/src/stm32l4: use common/stm32 1-Wire driver
cae71ff arch/arm/src/stm32: unify pulse count driver into common/stm32
baddb20 boards/arm/stm32{l5,u5,wb,wl5,n6}: switch board common to stm32 common
bf7e64f boards/arm/stm32h7: switch board common to boards/arm/common/stm32
833cd9e boards/arm/stm32h5: switch board common to boards/arm/common/stm32
fc4e631 boards/arm/stm32{f1,f4}: drop duplicated reset.c/romfs, use common board logic
a33eac8 boards/arm/stm32f7: switch board common to boards/arm/common/stm32
8099cb0 boards/arm/stm32f4: drop duplicated STM32_ROMFS, use common board logic
c5d4945 arch/arm/stm32f7: add stm32.h peripheral header
30dbca3 arch/stm32: Commonize stm32_waste across all STM32 families.

@raiden00pl raiden00pl added the breaking change This change requires a mitigation entry in the release notes. label May 31, 2026
@github-actions github-actions Bot added Area: Build system Arch: arm Issues related to ARM (32-bit) architecture Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: arm and removed breaking change This change requires a mitigation entry in the release notes. labels May 31, 2026
@raiden00pl

Copy link
Copy Markdown
Member Author

It would be good to pinging everyone who uses stm32 with nuttx

@raiden00pl
raiden00pl force-pushed the stm32_refactor_all branch 6 times, most recently from 08fef3a to 65180d0 Compare June 1, 2026 07:53
@jerpelea

jerpelea commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

I will port it to 13.0

@raiden00pl

Copy link
Copy Markdown
Member Author

FYI to all people who have contributed to stm32 recently or I know that in the past they were interested in stm32 with nuttx. This PR will be a breaking change for most stm32 users. For those who are not interested in nuttx - sorry for the pinging :)

In short, the goal of this PR is simple: unification of STM32 ports. No more unnecessary code duplication, incompatible Kconfig options and arch specific API. Ultimately, maintaining the code, applying changes, and adding new stm32 ports should be easier. However, this requires a hard breaking change that unifies and standardizes many things. The changes in this PR are the first step that contains most of the necessary breaking changes and these changes should be part of the upcoming release 13.0.

With this PR all architecture API is unified and uses stm32_xxx() functions, all public options shared between families are unified and use CONFIG_STM32_ prefix, each stm32 family has its own separate directory in arch and boards, common code between families goes to arch/src/common/stm32. At the moment common code is mainly used by f0 l0 g0 c0 f1 l1 f2 f3 f4 g4, in the future the rest of the families will be migrated to common code.

@alexcekay @ImBonkers @patrickelectric @csanchezdll @cjj66619 @dlizewski @shizacat @ppisa @pbarada @neilberkman @matiamic @vrmay23 @kywwilson11 @zdebanos @rzsa @davids5 @antmerlino @fjpanag @hartmannathan @michi-jung @juniskane @onegray @mlyszczek @stbenn @daniel-p-carvalho @rcsim

@michi-jung

Copy link
Copy Markdown
Contributor

Hi @raiden00pl

In the summary of changes you wrote:

Peripheral drivers included by a family depend on the peripheral's IP core version.

That is an excellent idea, but may I ask where you get the IP core versions from? When I asked an FAE from STMicroelectronics I was told that they do not publish the IP core version number per STM32 type.

Thanks!
Michael

@michallenc

Copy link
Copy Markdown
Contributor

This is a huge change and I will need some time to dig deep in and understand all the consequences. Just some initial thoughts.

STM32 families can use the STM32 common directory, which allows them to use common drivers and common hardware definitions shared between families.

So far I am sceptical towards this. One of the greatest NuttX design characteristics is the simplicity of source code and its arch section. Having a directory with common drivers with various compile time or runtime conditions deciding what code should be run breaks this simplicity. Yes, the current approach can bring some duplicity, but I still think it's a better approach. I would cite NuttX principles here: Sometimes is better to duplicate some logic than to introduce coupling.

We need to really consider this, because the architectural design is what makes NuttX accessible. It's super easy to explain someone the driver's organization and the relation between boards and arch section. You just call stm32_adc_initialize from your BSP and go to arch/arm/stm32l4/stm32_adc.c if you want to know what the function does. No need to figure out what file in common section is for my chip and what code actually applies because of various ifdef guards.

STM32 boards can use common board drivers.

This on the other hand is something I agree with. I will need to take a detailed look, but I like the idea BSPs would serve mainly for pin definitions and would call the common init functions. After all, these functions are nothing more than arch init call and character device driver registration.

Kconfig files have been split into smaller ones, which makes them much easier to manage. This was proposed several times for new STM32 ports before, but doing it for one STM32 port and leaving the rest untouched didn't make sense. Now it's done for all STM32 ports, as it should be.

+1 this is great, searching in or editing one large Kconfig file is a pain. Maybe I would just move all those Kconfig.adc, Kconfig.pwm and so on files to a subdirectory and keep the root directory for main Kconfig file and drivers. I think we could apply the same logic to all MCUs in the future.

@raiden00pl

Copy link
Copy Markdown
Member Author

@michi-jung This is the hardest part, it has to be done by ourself. I used to do it manually, now the comparison can be easily automated with LLM. ChibiOS might provide some guidance: https://github.com/ChibiOS/ChibiOS/tree/master/os/hal/ports/STM32/LLD
For NuttX we can make an even simpler distinction based on the registers: when the order of registers is identical, we can assume that the IP is the same, or at least compatible to the extent that the same driver code can be used

@raiden00pl

raiden00pl commented Jun 1, 2026 •

Copy link
Copy Markdown
Member Author

So far I am sceptical towards this. One of the greatest NuttX design characteristics is the simplicity of source code and its arch section. Having a directory with common drivers with various compile time or runtime conditions deciding what code should be run breaks this simplicity. Yes, the current approach can bring some duplicity, but I still think it's a better approach. I would cite NuttX principles here: Sometimes is better to duplicate some logic than to introduce coupling.

@michallenc Some code duplication makes sense. Code duplication across ~20 families and all posbile peripherals is pointless and difficult to maintain, especially when IP core implementations are shared between families. The problem here is that ST doesn't provide this information in an easy and readable way. Therefore, we can use ChibiOS whose author is or was an ST employee: https://github.com/ChibiOS/ChibiOS/tree/master/os/hal/ports/STM32/LLD

We need to really consider this, because the architectural design is what makes NuttX accessible. It's super easy to explain someone the driver's organization and the relation between boards and arch section. You just call stm32_adc_initialize from your BSP and go to arch/arm/stm32l4/stm32_adc.c if you want to know what the function does. No need to figure out what file in common section is for my chip and what code actually applies because of various ifdef guards.

That's why documentation was created that directly indicates which IP core is used by which family. Regarding the STM32L4 - this port was created based on the principle that "code duplication is not a bad thing." Currently, this code has drifted from the rest of the ports to the point that it's the worst to generalize, and it uses essentially the same peripherals as other STM32 M4s.

If we're duplicating code, we should duplicate it for all families, not as currently, where some are done this way, some are done that way (stm32/stm32f0l0g0 vs stm32l4/stm32f7/stm32h7/....). Duplicating it for all families means we need to duplicate the code for the old arch/stm32: f1, f2, f3, f4, g4, l1 and for the old arch/stm32f0l0g0: f0, l0, g0, c0. 10 new architectures to maintain. From the common stm32 arch drivers way, or ten new architectures and code duplication way, I think the common arch is the only reasonable way.

@raiden00pl
raiden00pl force-pushed the stm32_refactor_all branch from 65180d0 to 50a8628 Compare June 1, 2026 12:11
@patrickelectric

Copy link
Copy Markdown
Contributor

It appears that CODEOWNERS is still keeping stm32f0l0g0.

@raiden00pl
raiden00pl force-pushed the stm32_refactor_all branch 2 times, most recently from 0413304 to 319feeb Compare June 1, 2026 13:28

@hartmannathan hartmannathan left a comment

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.

Hi, @raiden00pl thanks for taking this HUGE task upon yourself! I have sometimes been frustrated by the stm32 support being disjoint because of the different families being treated as different archs. This is a substantial change so I just want to kindly ask you to bear with me, because it will take me some time to review and test.

@hartmannathan

Copy link
Copy Markdown
Contributor

@michi-jung This is the hardest part, it has to be done by ourself. I used to do it manually, now the comparison can be easily automated with LLM. ChibiOS might provide some guidance: https://github.com/ChibiOS/ChibiOS/tree/master/os/hal/ports/STM32/LLD For NuttX we can make an even simpler distinction based on the registers: when the order of registers is identical, we can assume that the IP is the same, or at least compatible to the extent that the same driver code can be used

Yes, although STM doesn't document the actual version numbers of the peripheral IP blocks, we can ascertain this information based on the functionality they expose via registers and register bits. We can think of the registers and bits as the API of the peripherals. If the APIs match, we can consider the peripherals to be the same version.

It's possible that the register addresses may be different, or that the bits within the register might be in a different position or order. So we might need some kind of "fuzzy matching".

@hartmannathan

Copy link
Copy Markdown
Contributor

For all AI skeptics here - this PR was created with AI assistance and burned hundreds of dollars worth of tokens. There is no other way to do it, doing it manually is unrealistic, especially if you do it alone and for free :) This PR doesn't add new code, it only organizes the old code, so the code license remains the same as the original code

@raiden00pl, I am an AI skeptic. :-) Out of curiosity, would you be willing to share the prompts you used? It could be a blog post or something like that, to document how the changes were made as well as a learning resource for others who are trying to wrap their heads around this new way of working.

@vrmay23

vrmay23 commented Jun 1, 2026 via email

Copy link
Copy Markdown
Contributor

@raiden00pl

Copy link
Copy Markdown
Member Author

@hartmannathan I had an idea and plan for this reorganisation for years in my private notes, but it was not possible to do it manually without investing months of work. This wasn't a task that could be solved with a few prompts. The AI has too small context for this and isn't able to think outside the box very well. AI was used here more like an "intelligent tool" for things that I would have had to do manually. I don't have a single master prompt but used many simple prompts in an interactive workflow. I just instructed AI how I would do it step by step, like: "rename all public STM32 arch API to use common prefix stm32_", "move all stm32f0l0g0 files to common/stm32 and rename them to use the m0 suffix", "build set of configuration after each step" and so on. In fact, the order of commits exactly reflects my plan from the beginning.

With such a huge change, keeping git history clean manually is a really big challenge, but for AI this is a really simple job. Moving files, fixups, squashing commits, and resolving conflicts is something that takes hours for a human, but can be easily done by AI.
Fixing issues found by local build/CI is also easy for AI, but not an entirely automated task and needs careful reviews. Simple for human solutions like: "Merge SPI Kconfig options with I2S options to fix undefined STM32_SPI_DMA symbol" were completely unthinkable for codex/claude/deepseek.

There were more issues that AI was not able to solve without manual intervention, like optimizing complex dependencies in Kconfig or even merge similar header files. There are still many complex conditions in Kconfig that must be simplified, but this is work for a human and careful analysis; AI has no idea how to properly solve it.

@raiden00pl

Copy link
Copy Markdown
Member Author

@vrmay23 Any compilation of externally maintained boards and configurations will be useful. Upstream configurations should be OK now (CI pass), but upstream boards don't provide full coverage for stm32 architectures features, so the more out-of-tree configurations we compile, the greater the certainty that there will be no regressions. F7 and H7 have no functional changes, so if the code compiles - it should work. Unless some Kconfig option was not migrated correctly - with such a big change there's always a chance of that

@michallenc

Copy link
Copy Markdown
Contributor

So far I am sceptical towards this. One of the greatest NuttX design characteristics is the simplicity of source code and its arch section. Having a directory with common drivers with various compile time or runtime conditions deciding what code should be run breaks this simplicity. Yes, the current approach can bring some duplicity, but I still think it's a better approach. I would cite NuttX principles here: Sometimes is better to duplicate some logic than to introduce coupling.

@michallenc Some code duplication makes sense. Code duplication across ~20 families and all posbile peripherals is pointless and difficult to maintain, especially when IP core implementations are shared between families. The problem here is that ST doesn't provide this information in an easy and readable way. Therefore, we can use ChibiOS whose author is or was an ST employee: https://github.com/ChibiOS/ChibiOS/tree/master/os/hal/ports/STM32/LLD

We need to really consider this, because the architectural design is what makes NuttX accessible. It's super easy to explain someone the driver's organization and the relation between boards and arch section. You just call stm32_adc_initialize from your BSP and go to arch/arm/stm32l4/stm32_adc.c if you want to know what the function does. No need to figure out what file in common section is for my chip and what code actually applies because of various ifdef guards.

That's why documentation was created that directly indicates which IP core is used by which family. Regarding the STM32L4 - this port was created based on the principle that "code duplication is not a bad thing." Currently, this code has drifted from the rest of the ports to the point that it's the worst to generalize, and it uses essentially the same peripherals as other STM32 M4s.

If we're duplicating code, we should duplicate it for all families, not as currently, where some are done this way, some are done that way (stm32/stm32f0l0g0 vs stm32l4/stm32f7/stm32h7/....). Duplicating it for all families means we need to duplicate the code for the old arch/stm32: f1, f2, f3, f4, g4, l1 and for the old arch/stm32f0l0g0: f0, l0, g0, c0. 10 new architectures to maintain. From the common stm32 arch drivers way, or ten new architectures and code duplication way, I think the common arch is the only reasonable way.

I agree the support for STM32 is quite messy and STM doesn't make it easy with their naming convention. We don't need duplicate implementations for f1, f2, f3 and so on though. These can be in one common folder, if the chips are the same (or with really little changes). We also have imxrt1060 and imxrt1170 in common imxrt folder or same70 and samv71 in samv7. These chips use one IP core, the differences are mostly in having different peripherals available.

But with this change, we would not only mix different IP core implementations in one directory but also different Cortex versions if I understand it correctly. And this is something I think we should duplicate. From my point of view the unification abandons the way we wrote the code for many years and I am afraid we open a Pandora box leading to more messy and unclear code.

It also forces us to assign IP core versions to chips - yes, we can automate it by relying on 3rd party project which may end in a year or two or on LLM, which is even worse, because we can't trust that thing. So we have to do it manually by comparing registers and hoping we got it right. But that's a minor issue we can handle.

…config files

Replace STM32_COMMON_* composite symbols with capability flags in
Kconfig.memory, Kconfig.sai, Kconfig.dfsdm, Kconfig.i2c, Kconfig.ltdc
and Kconfig.dma:

- STM32_COMMON_SRAM2_OPTIONS -> STM32_HAVE_SRAM2_HEAP; the
  STM32_SRAM2_INIT select condition folds away because the U5 leg of
  the new flag already requires STM32_SRAM2
- SAI PLL options -> STM32_HAVE_SAI1PLL / STM32_HAVE_SAI2PLL
- DFSDM filter options -> STM32_HAVE_IP_DFSDM_V1
- I2C v1-only options (I2C_ALT, DUTY16_9) -> STM32_HAVE_IP_I2C_M3M4_V1;
  this drops F37x/G4 from the visibility set, which select the I2C v2
  IP and never build the v1 driver these options belong to
- LTDC_REGDEBUG -> STM32_HAVE_IP_LTDC_M3M4_V1 / new
  STM32_HAVE_IP_LTDC_M7_V1; LTDC_USE_DSI composite dropped as DSIHOST
  is only selectable on F7
- STM32_DMACAPABLE -> new STM32_HAVE_DMACAPABLE driver-feature flag;
  ASSUME_CACHE_ALIGNED composite dropped as ARMV7M_DCACHE already
  implies F7/H7 within STM32

Verified .config equivalence with olddefconfig on F3/F4/G4/F7/H7/H5/
L4/U5/WB/WL5 boards: only the new capability symbols appear.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
….eth

- legacy-only PTP/enhanced-descriptor options -> existing
  STM32_HAVE_IP_ETHMAC_M3M4_V1 (selected by all legacy families with
  ETHMAC)
- H7/H5 descriptor-count and NO_PHY options -> new STM32_HAVE_IP_ETHMAC_V2
  (the newer Synopsys MAC shared by H7/H5)
- MII/RMII MCO1/MCO2 clock options -> new STM32_HAVE_MCO1/STM32_HAVE_MCO2
  hardware-capability flags
- STM32_PHYADDR default inverted to key off STM32_HAVE_IP_ETHMAC_V2
- STM32_PHY_POLLING composite dropped: STM32_PHY_HAVE_POLLED is only
  selected for non-legacy chips, so the family condition was redundant

Verified .config equivalence with olddefconfig on eth-enabled F4/F7/H7
configs and the full board matrix: only the new capability symbols
appear.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
…HAVE_ETHMAC

Three overlapping flags described the same capability:
STM32_HAVE_ETHMAC (legacy families), STM32_HAVE_ETHRNET (F7, typo) and
STM32_HAVE_ETHERNET (H7/H5 + bridge selects from the other two).

Keep STM32_HAVE_ETHMAC as the canonical flag: F7/H7/H5 chips now select
it directly, the legacy bridge selects are dropped, the STM32_ETHMAC
gate in Kconfig.periph and the chip.h STM32_NETHERNET definitions use
it, and the two redundant flags are deleted.

Verified .config equivalence on eth-enabled F4/F7/H7 configs plus the
full board matrix: only the flag rename appears. Built
nucleo-f767zi:netnsh and nucleo-h743zi:netnsh.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
…c/usb/system/flash Kconfig

- Kconfig.sdio: legacy SDIO options need no family gate (STM32_SDIO is
  only selectable on legacy chips); SDMMC options move to new
  STM32_SDMMC_HAVE_DMA / _HAVE_IDMA / _HAVE_SDIO_MODE feature flags
- Kconfig.rtc: MAGIC_REG range keyed to the RTCC IP flags; LSE drive
  capability options move to new STM32_HAVE_RTC_LSE_AUTO_DRV /
  STM32_HAVE_RTC_LSE_DRV / STM32_HAVE_RTC_LSE_DRV_LOWER; redundant
  legs folded (the AUTO option can only be enabled where implemented)
- Kconfig.usb: host debug options gate on STM32_USBHOST (legacy-only
  symbol) or new STM32_USBHOST_HAVE_DEBUG; USBFS/USBDEV REGDEBUG and
  OTG ID-pin options move to per-driver feature flags; host menus drop
  the redundant LEGACY condition
- Kconfig.system: idle-sleep option -> STM32_HAVE_DISABLE_IDLE_SLEEP;
  DFU -> DFUMODE IP flags (new M0_V1 for the Cortex-M0 group);
  tickless timer/channel -> STM32_HAVE_TICKLESS_UPTO_TIM14/_TIM17
  (encode both the family set and the timer-number range); SysTick
  clock choice keys off ARCH_CORTEXM0 per the naming rules
- Kconfig.flash: override/prefetch/progmem conditions move to
  STM32_HAVE_FLASH_OVERRIDE / _PREFETCH / _PROGMEM / _PROGMEM_MTD

Verified .config equivalence with olddefconfig on 13 configs across
F3/F4/G4/F7/H7/H5/L4/U5/WB/WL5: only new capability symbols appear.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
….spi

- STM32_SPI_INTERRUPTS -> new STM32_HAVE_SPI_INTERRUPTS
- SPIn DMA buffer options -> new STM32_HAVE_SPI_DMA_BUFFER (plus a
  per-instance STM32_SPI6_HAVE_DMA_BUFFER, since SPI6 DMA is reachable
  on F4 but its buffer option was F7/H7/H5-only)
- SPI4/5/6 DMA gates collapse onto the existing
  STM32_HAVE_SPI_DMA_FAMILY, whose family set is identical
- Cortex-M0 group DMA legs -> new STM32_HAVE_SPI_DMA_M0
- COMMTYPE options -> new STM32_HAVE_SPI_COMMTYPE
- I2S options: LEGACY legs -> existing STM32_HAVE_IP_I2S_M3M4_V1 (the
  F7 legs stay until the F7 I2S driver is unified)

The undefined STM32_SPI_INTERRUPT (singular) references are left
untouched; they predate this change.

Verified .config equivalence with olddefconfig on 13 configs: only new
capability symbols appear.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
…/periph Kconfig

- Kconfig.adc: F7/H7/H5/L5/U5 composites expand to explicit family
  names (they die when the remaining family ADC drivers are unified);
  the L4_L5_U5 tails collapse onto STM32_HAVE_ADC_L4, since L5 cannot
  reach STM32_ADCn and U5 never sets STM32_ADC
- DAC DMA-timer options -> new STM32_HAVE_DAC_DMA_TIMER
- Kconfig.periph:
  - I2S/I2S3 selects key off STM32_HAVE_IP_I2S_M3M4_V1
  - DMA2D FB selects drop the redundant LEGACY and HAVE_DMA2D terms
  - BBSRAM -> new STM32_HAVE_BBSRAM (BBSRAM IP flag or F7/H7)
  - AES ALGTEST selects simplify to STM32_HAVE_AES && CRYPTO_ALGTEST;
    this now also covers L4, which uses the same common AES driver but
    was left out of the family lists
  - drop the USBFS 'select USBDEV if ...' line shadowed by the
    unconditional select above it
  - STM32_USBHOST gates on the OTG host IP flags instead of LEGACY
  - STM32_SDIO gates on STM32_HAVE_IP_SDIO_M3M4_V1; this removes the
    dead SDIO option from G4, which has no SDIO hardware (the F1
    connectivity/value-line exclusions are encoded at the select)
  - USARTn_SERIALDRIVER selects -> new STM32_HAVE_USART_SERIALDRIVER
  - PHY_HAVE_POLLED select keys off the ETHMAC IP flag; LCD USBDEV
    select keys off ARCH_CORTEXM0

Verified .config equivalence on 13 configs: only new capability
symbols appear, plus the intended STM32_SDIO removal on G4.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
….tim

Replace all 160 STM32_COMMON_* references with capability flags:

- wrappers: STM32_PULSECOUNT/ONESHOT/FREERUN/PWM_LL_OPS gate on new
  STM32_HAVE_PULSECOUNT / STM32_HAVE_TIM_ONESHOT / STM32_HAVE_TIM_FREERUN /
  STM32_HAVE_PWM_LL_OPS; the L4-lineage tickless defaults use new
  STM32_HAVE_TICKLESS_ONESHOT; the ONESHOT_MAXTIMERS family condition is
  dropped as it repeats the STM32_ONESHOT availability set
- per-channel polarity/idle options (76 lines) -> new
  STM32_HAVE_TIM_PWM_POLARITY; the redundant STM32_TIM term is dropped
  since CHxOUT already implies it through TIMn_PWM -> STM32_TIMn
- TIM12-14 and TIM15-17 option groups -> new STM32_HAVE_TIM_PWM_TIM12_14
  / STM32_HAVE_TIM_PWM_TIM15_17
- channel 5/6 (internal) -> new STM32_HAVE_TIM_PWM_CHANNEL5/_CHANNEL6;
  the L5/U5 channel-mode quirk pairs reuse STM32_HAVE_TIM_PWM_CHMODE_LIMITED
  (equivalent: the M0 members of that flag cannot enable TIMn_CHANNEL5)
- GP-timer extended channel-mode ranges -> new
  STM32_HAVE_TIM_PWM_CHMODE_GP_EXTENDED
- capture options -> new STM32_HAVE_TIM_CAP; remaining
  L4/L5/U5/H7/H5-only capture and LPTIM legs expand to explicit family
  names that die when those family drivers are unified

Verified .config equivalence with olddefconfig on 18 configs including
PWM/FOC/capture-heavy ones (nucleo-h743zi:pwm, nucleo-f302r8:ihm07m1_f32,
nucleo-l432kc:spwm, b-g474e-dpow1:buckboost, nucleo-f302r8:qenco): only
the new capability symbols appear. Built nucleo-h743zi:pwm and
nucleo-f302r8:ihm07m1_f32.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Complete the composite removal:

- expand the remaining STM32_COMMON_* references inside Kconfig.have
  and Kconfig.qspi to explicit ARCH_CHIP_* lists (family names are
  tolerated in the capability-flag definitions, which are the single
  family->capability map)
- gate the legacy Cortex-M3/M4 system-core source block in Make.defs /
  CMakeLists.txt with new STM32_HAVE_IP_SYSCORE_M3M4_V1 instead of
  STM32_COMMON_LEGACY, and switch the stm32_dma2d.h / stm32_exti_pwr.h /
  stm32_usbhost.h facade dispatch to the same flag
- delete the composite definitions from the common Kconfig;
  'grep -r STM32_COMMON_ arch/ boards/' is now clean (modulo the
  STM32_COMMON_SRCDIR make variable)
- update the stm32_ports.rst Kconfig-simplification section

Verified .config equivalence on 18 configs: only the composite symbols
disappear and STM32_HAVE_IP_SYSCORE_M3M4_V1 appears on legacy families.
Built stm32f4discovery:nsh (make and CMake/ninja) and nucleo-f722ze:nsh.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
… names

Pure renames per the Kconfig naming rules (STM32_HAVE_* must describe
capabilities or IP versions, not families):

- STM32_HAVE_ADC_L4    -> STM32_HAVE_IP_ADC_M3M4_V3
- STM32_HAVE_ADC_H5    -> STM32_HAVE_IP_ADC_M33_V1
- STM32_HAVE_FDCAN_H7  -> STM32_HAVE_IP_FDCAN_M7_V1
- STM32_HAVE_OTG_H7    -> STM32_HAVE_IP_OTG_M7_V1

The flags still mark not-yet-unified family drivers; the final IP
mapping is decided when each driver moves to common/stm32.
STM32_HAVE_I2C_H5 and STM32_HAVE_USART_H5 are intentionally left: they
die with the I2C and serial unifications. STM32_HAVE_IP_CRYPTO_H7 is
renamed together with the CRYP driver move.

Verified .config equivalence on 18 configs (rename-only diffs); built
nucleo-h743zi:nsh, b-l475e-iot01a:nsh, nucleo-h563zi:nsh.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
…IP names

These IP blocks are about to be selected by Cortex-M7 (F7/H7) and
Cortex-M33 (H5) families as their local drivers are retired into
common/stm32. An IP version names the silicon only and must not encode
the CPU core it sits next to, so drop the transitional m3m4 prefix
before extending them:

- STM32_HAVE_IP_RNG_M3M4_V1   -> STM32_HAVE_IP_RNG_V1
- STM32_HAVE_IP_WDG_M3M4_V1   -> STM32_HAVE_IP_WDG_V1
- STM32_HAVE_IP_DMA2D_M3M4_V1 -> STM32_HAVE_IP_DMA2D_V1
- STM32_HAVE_IP_I2C_M3M4_V2   -> STM32_HAVE_IP_I2C_V2

with the matching source renames (stm32_rng_v1.c, stm32_iwdg_v1.c,
stm32_wwdg_v1.c, stm32_dma2d_v1.c/h, stm32_i2c_v2.c,
stm32_i2c_v2_slave.c). IP names still carrying a core prefix remain
used by a single core class only; each drops the prefix when it first
crosses cores, at which point the per-core version spaces are merged
deliberately.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Retire the F7/H5/H7/L4 copies of the RNG driver in favor of
common/stm32/stm32_rng_v1.c. The H7 copy was byte-identical
except the header comment; F7/H5/L4 differed only in naming style,
interrupt-enable placement, and the ISR error handling.

The common ISR now adopts the F7/H5/L4 error recovery unconditionally:
clock error (CEIS) is cleared and retried, and seed error (SEIS) is
cleared with an RNGEN toggle, instead of silently discarding the
sample. The L4 copy also ignored the nxsem_wait() return value; the
common driver's handling is kept.

The four families select STM32_HAVE_IP_RNG_V1 (if STM32_HAVE_RNG)
from their family peripheral block. The common Make.defs/CMakeLists
RNG gate moves out of the STM32_HAVE_IP_SYSCORE_M3M4_V1 legacy block
to the top level so non-legacy families reach it.
stm32l4/hardware/stm32l4_rng.h is renamed to stm32_rng.h to match the
include used by the common driver.

Built nucleo-l496zg:nsh (make and CMake), stm32f769i-disco:netnsh,
stm32f4discovery:nsh, and nucleo-h743zi/nucleo-h563zi with RNG
force-enabled.

The common driver already clears the SEIS/CEIS flags and restarts the
generator on a seed error; the STM32H7 fix for a missing RNG kernel
clock (abort the read with -EIO instead of retrying forever) is carried
over.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
The F7 stm32_dma2d.c/h were formatting-only forks of
common/stm32/stm32_dma2d_m3m4_v1.c/h. F7 now selects
STM32_HAVE_IP_DMA2D_V1 (if STM32_HAVE_DMA2D), the common facade
and build gates dispatch on that IP flag instead of the legacy SYSCORE
flag, and the gate moves out of the legacy-only Make.defs block.

Built stm32f746g-disco:fb with DMA2D force-enabled and
stm32f429i-disco:fb as the F4 regression control.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
stm32h7/stm32_aes.c drives the CRYP peripheral (not the AES IP); move
it to common/stm32/stm32_aes_cryp_v1.c with its register definitions
relocated to common hardware/stm32_cryp_v1.h, and rename
STM32_HAVE_IP_CRYPTO_H7 to STM32_HAVE_IP_CRYP_V1 accordingly. The
common stm32_aes.h facade dispatches on the new flag.

The cryptodev wrapper stm32_crypto_m3m4_v1.c adopts the H7 version:
it takes the IV from crp->crp_iv, which is where NuttX cryptodev
delivers the user IV (the old crd->crd_iv read an unset field), and it
accepts 192/256-bit AES-CTR keys, which the backend validates.

Built nucleo-h753zi:crypto (exercises both moved files); .config
equivalence verified on 18 configs.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
The stm32h7 SPI slave driver tests CONFIG_STM32H7_SPIx_SLAVE and
CONFIG_STM32H7_SPI_SLAVE_QSIZE, which no Kconfig defines.  Add the
common STM32_SPIx_SLAVE and STM32_SPI_SLAVE_QSIZE options and use them.
The queue size now comes from Kconfig with a range, so drop the size
check from the driver.

Make the SPI menu and the COMMTYPE options visible when only a slave
instance is enabled, and fix an undeclared identifier in spi_bind()
that was never seen because the driver was never built.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Several options depend on or select symbols that no Kconfig defines, so
they can never be selected:

  - STM32_SPI_INTERRUPT is a misspelling of STM32_SPI_INTERRUPTS, used in
    the dependencies of the seven SPIx_DMA options, so the guard against
    combining DMA with interrupt driven SPI did not work.
  - STM32_LTDC_L1_ARGB15555 has one 5 too many.
  - STM32_BLE_LS_CLKSRC_HSE is spelled STM32_BLE_LS_CLK_SRC_HSE.
  - STM32_HAVE_ICACHE_REMAP is selected by the H5 families and guards the
    four ICACHE remap options, but was never defined.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
The LTDC driver tests CONFIG_STM32_LCD_BACKLIGHT and the OTG drivers
test CONFIG_STM32_OTGFS_SOFOUTPUT and CONFIG_STM32_OTGHS_SOFOUTPUT,
which no Kconfig defines, so the backlight control and the SOF output
pin were never built.  Use CONFIG_STM32_LTDC_BACKLIGHT and
CONFIG_STM32_OTG_SOFOUTPUT.

Also correct the trailing comments of the OTG device drivers, which
name a CONFIG_STM32_OTGxSDEV symbol that never existed.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Two options are spelled differently in Kconfig and in the drivers, so
the option is unreachable and the code is dead:

  - STM32_HRTIM_CAP is tested as STM32_HRTIM_CAPTURE, which the per timer
    capture options also depend on.
  - STM32_HRTIM_AUTODELAY is tested as STM32_HRTIM_AUTODELAYED.

Rename the Kconfig symbols to the names the code uses.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
The ARM LLVM 17.0.1 toolchain used by CI selects its runtime libraries
from the target, architecture, FPU and ABI flags. It does not ship the
armv7em_*.cfg files requested by the ARMv7-M CMake toolchain, causing
Cortex-M7 builds with the FPU enabled to fail before compilation.

Use the existing platform flags for runtime selection, as the other ARM
CMake toolchains do. Verify full STM32F4, STM32F7 and STM32H7 firmware
builds with Clang and the FPU enabled.

Signed-off-by: raiden00pl <[email protected]>
The M33 GPIO driver is the MODER/AFR GPIO used by most STM32 families.
Rename it to GPIO v2 so families of other core classes can use it.
No functional change.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Rename GPIO_SPEED_xxMHZ to GPIO_SPEED_xxMHz, the spelling used by all
other STM32 GPIO headers and the common I2C drivers.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Configure PUPDR, OSPEEDR, OTYPER and AFR before MODER, as described in
RM0316 section 11.3.2, so a pin never runs in its new mode with its old
configuration.  The alternate function is cleared after the pin leaves
alternate function mode.  ST HAL HAL_GPIO_Init/DeInit use the same order.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Replace the local GPIO driver with the common GPIO v2 driver.  The
common driver gains the SYSCFG EXTICR port selection and the analog
switch control (ASCR) of STM32L47x/L48x that the L4 driver had.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Replace the local GPIO driver with the common GPIO v2 driver.  Port
numbers now match the SYSCFG EXTICR encoding (PD=3, PE=4, PH=7).  The
local driver numbered the existing ports consecutively, so EXTI on PH
selected the wrong port, and on parts without PD the PE and PH pins were
configured in the registers of another port.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Replace the local GPIO driver with the common GPIO v2 driver.  Port
numbers now match the SYSCFG EXTICR encoding (PH=7).  The local driver
numbered PH as port 3, so EXTI on PH selected port D.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
STM32_NPORTS is the GPIO port count used by the common GPIO v2 driver
and all other families that use it.  No functional change.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Replace the local GPIO driver with the common GPIO v2 driver.  The
common driver gains ports J and K and stm32_iocompensation().

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
Replace the local GPIO driver with the common GPIO v2 driver.  The
common driver gains ports M-P and the SBS EXTICR and compensation cell
registers of STM32H7RS.  Ports F and G of parts without them are no
longer rejected by stm32_configgpio(), the memory map defines them.

Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
@raiden00pl

Copy link
Copy Markdown
Member Author

STM32 migration to arch/arm/src/common/stm32 - status

State of stm32_refactor_all (47b3d39, master db0d438 + this PR),
2026-11-25. "Local" means the family still builds its own copy from
arch/arm/src/stm32<family>/. RCC (clock tree setup) is local in every
family and is not listed.

Families with no local drivers left (only RCC)

C0, C5, F0, F1, F2, F3, F4, G0, G4, L0, L1, U0, U3

Families with local drivers

L5, N6 and U5 have only a few local files. F7, H5, H7, L4, WB and WL5 have
most of the remaining work.

Peripherals

Peripheral Still local in Common driver(s) used by other families Note
SPI F7, H7 (+ SPI slave), L4, L5, U5, WB, WL5 spi_m0_v1, spi_m3m4_v2v3v4, spi_v5 I am working on this
I2C L4, U5, WB i2c_m0_v1, i2c_m3m4_v1, i2c_v2
USART (serial, lowputc) F7, H7, L4, WB, WL5 serial_m0_v3/v4, serial_m3m4_v1v2v3v4, serial_m33m55_v3
ADC F7, H5, H7, L4 adc_m0_v1, adc_m3m4_v1v2
DAC H7, L4 dac_m3m4_v1, dac_m33_v1
COMP L4 (+ EXTI COMP) comp_m3m4_v1, comp_m3m4_v2
PWM F7, H5, H7, L4 pwm_m0_v1, pwm_m3m4_v1v2v3
Capture F7, H5, H7 capture_m3m4_v1
bxCAN F7 (chardev + SocketCAN), L4 (chardev) can_m3m4_v1
FDCAN H5, H7 (chardev + SocketCAN) fdcan_m0_v1, fdcan_m3m4_v1 I am working on this
Ethernet F7 eth_m3m4_v1, eth_v2 I am working on this
SDMMC F7, H5, L4 sdio_m3m4_v1, sdmmc_v2 (H7, N6)
QSPI F7, H5, H7, L4 - I am working on this
XSPI H7 -
SAI F7, L4 -
I2S F7 i2s_m3m4_v1
DFSDM L4 -
FMC F7, H7 fmc_m3m4_v1
LTDC F7, H7 ltdc_v1v2 (F4, N6)
BBSRAM F7, H7 bbsram_m3m4_v1
RTC (+ alarm, wakeup EXTI) F7, H7, L4, WB rtcc_m3m4_*, rtcc_m33m55_v1, rtcounter_m3m4_v1, rtc_m3m4_v1_lowerhalf
USB OTG F7 (dev, host), L4 (FS dev, FS host) otg{fs,hs}{dev,host}_m3m4_v1, otgdev_v2, otghost_v2 (H7, N6)
USB device (FS) L4, H5 (USBFS + DRD host) usbdev_m0_v1, usbdev_m3m4_v1, usbfs_m3m4_v1
FOC F7 foc_m3m4_v1
Crypto H7 (stm32_crypto.c) crypto_m0_v1, crypto_m3m4_v1
DFU mode L4 dfumode_m3m4_v1

Core and system code

Code Still local in Common driver(s) used by other families
start, irq F7, H7, L4, N6, WB, WL5 start/irq_m0_v1, _m3m4_v1, _m33_v1
idle L4, N6, WB, WL5 idle_m0_v1, _m3m4_v1, _m33_v1
allocateheap F7, H7, L4, WB, WL5 allocateheap_m3m4_v1, _m33_v1
mpuinit, userspace F7, H7, L4, L5, U5, WB mpuinit_m3m4_v1, mpuinit_m33_v1, userspace_m3m4_v1
DMA F7, H7, L4, WB dma_m0_v1_7ch[_dmamux], dma_m3m4_v1_8ch[_dmamux], dma_m3m4_v2_stream, dma_gpdma
EXTI GPIO F7, H7, L4, WB, WL5 exti_gpio_m0_v1, _m3m4_v1v2, _m33m55_v1
EXTI PWR F7, L4, WB exti_pwr_m3m4_v1
PWR F7, H5, H7, L4, L5, N6, U5, WB, WL5 pwr_m0_v1, pwr_m0_g0, pwr_m3m4_v1
PM (sleep, stop, standby, LPR) F7, H5, H7, L4, WB pm*_m3m4_v1, pminitialize_default
FLASH (progmem) F7, H5, H7, L4, L5, U5, WB, WL5 flash_m0_g0c0, flash_m3m4_{f1f3,f2f4,g4,l1}
LSE F7, H5, H7, L4, L5, U5, WB, WL5 lse_m0_v1, lse_m3m4_v1
HSI48 H5, L4, WB hsi48_m0_v1
dumpgpio F7, L4, L5, U5, WB dumpgpio_m3m4_v1
DTCM F7, H7 -

Family-specific code with no common counterpart

Family Files
H5 DTS, EDATA, eFuse, ICACHE
H7 HSEM, dual core, RPTUN
L4 firewall
N6 RIF, OTG PHY interface
WB IPCC, mailbox, BLE HCI
WL5 IPCC

Done in this PR

GPIO v2 on F7, H7, L4, WB, WL5; RNG, DMA2D (F7) and CRYP (H7) moved to
common; Kconfig family-group composites replaced by IP capability flags.

@hartmannathan

Copy link
Copy Markdown
Contributor

Reading the above status report, it occurs to me that nowadays with the help of recent models, NuttX could have a per-arch, per-board, per-peripheral status doc and maybe even a searchable parametric DB. When you want to build your next project, you could specify the number and kind of peripherals you need, and quickly narrow down your choices of boards or microcontrollers, where the features you need exist and NuttX supports them. If the NuttX website had something like that built in?? In the past it would have been a nightmare to maintain, but maybe not anymore? It could support an agent workflow too, because instead of ingesting the whole NuttX tree, it could study just that document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Area: Documentation Improvements or additions to documentation Board: arm Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants