Repository navigation
Description
Is your feature request related to a problem? Please describe.
STM32 ports are a complete mess. Some have their own directory, some don't. Adding new ports means duplicating a whole bunch of code or adding a new family to already existing ports, which is also not elegant.
There is also a problem with naming (kconfig options, port directory, board directory): #16172
Maintaining such code is becoming increasingly difficult and we already have differences in the features supported by STM32 families. We need a better solution that will work better in the long term.
Here is a previous discussion on this topic: https://groups.google.com/g/nuttx/c/G3-EWjjVIT8
Since then, no one has proposed any solution, the number of STM32 maintainers in the project has decreased and the situation with code duplication and chaos in the code has become even worse.
Describe the solution you'd like
I think we should do it like risc-v ports from Espressif. Introduce common directory for STM32, move all duplicated code there and gradually clean up duplicates.
https://github.com/apache/nuttx/tree/master/arch/risc-v/src/common/espressif
https://github.com/apache/nuttx/tree/master/arch/risc-v/src/esp32c3
https://github.com/apache/nuttx/tree/master/arch/risc-v/src/esp32c6
https://github.com/apache/nuttx/tree/master/arch/risc-v/src/esp32h2
This is a really nice solution. Ultimately, the family-specific directory should contain only the family-specific code. No code shared between families in the family-specific directory.
This requires a breaking change on the Kconfig options side. All Kconfig options must be generalized:
CONFIG_STM32L4_ -> CONFIG_STM32_
CONFIG_STM32H7_ -> CONFIG_STM32_
CONFIG_STM32F7_ -> CONFIG_STM32_
and so one. Common Kconfig with common options must be placed in arch/arm/src/common/stm32/Kconfig to avoid Kconfig complaining.
This is the only breaking change that is necessary, and it's the first necessary step to reorganize the STM32. The breaking change is rather easy to fix on the user side, as it requires simply replacing CONFIG_STM32XX_ with CONFIG_STM32_. This change should be implemented in release 13.0 if we want to reorganize STM32 ports as this is significant change. Further work can be done later, gradually, as it's a lot of work.
The longer we wait with this reorganization, the worse it will get. With each new STM32 family, the problem will only get worse.
Work plan:
- generalize hardware definitions for STM32 ports. Use the same prefix for all STM32 chips
CONFIG_STM32_. Breaking change. - generalize Kconfig options for STM32. Use the same prefix for all STM32 chips
CONFIG_STM32_. Breaking change. - New page in Docoumentation with descriptions of all supported and unsupported STM32 families. Listing of all IP cores used by the families. Chibios may be helpful here: https://github.com/ChibiOS/ChibiOS/tree/master/os/hal/ports/STM32/LLD
- move common source code to
arch/arm/src/common/stm32/. Keep all reusable sources in one place. No code will be removed yet, there are still a lot of duplicates, but reusing files for new architectures will be easier. - split
arch/arm/src/common/stm32/intoarch/arm/src/common/stm32f1/,arch/arm/src/common/stm32f2/,arch/arm/src/common/stm32f3/,arch/arm/src/common/stm32f4/,arch/arm/src/common/stm32g4/,arch/arm/src/common/stm32l1/. The same for boards. - split
arch/arm/src/common/stm32f0l0g0/intoarch/arm/src/common/stm32f0/,arch/arm/src/common/stm32g0/,arch/arm/src/common/stm32l0/,arch/arm/src/common/stm32c0/. The same for boards. - regenerate CODEOWNERS.
- unify common sources, remove duplicates and so one. The longest and most difficult step, but it can be done gradually.
The remaining problem is how to handle drivers that are shared between arm and arm64 cores (as in the case of stm32mp). One approach is to create arch/common/src/stm32 shared by different archs, another is to just duplicate the code in arm64.
Describe alternatives you've considered
No response
Verification
- I have verified before submitting the report.
Activity
linguini1 commentedon May 25, 2026
Great initiative!
raiden00pl commentedon May 28, 2026
I have already completed tasks from 1 to 5, but for now moved to common/stm32 only files from stm32 m3/m4 and stm32 m0.
It looks pretty good. Unfortunately, the differences between the families are so great that this task is HUGE and DIFFICULT. Impossible to complete without AI and burning a huge amount of tokens.
The maintainers for years didn't pay much attention to keeping the STM32 ports similar and merged the PRs without much understanding or thought about the future of code maintenance. I'm therefore even more convinced that the proposed change, even if it can piss off many people because it is breaking change, is the only reasonable approach to taming the stm32 sources
raiden00pl commentedon May 29, 2026
here is my work in progress branch raiden00pl#50 The change is huge, but there is no other way to do it.
Github is poor for viewing such large changes, it's better to download the entire branch locally
acassis commentedon Jul 2, 2026
@raiden00pl I think we can close this Issue, right?
raiden00pl commentedon Jul 3, 2026
@acassis step 8 of the plan is still not finished, but since it's a long term task that require substantial work I'll create a separate issue for it. I'm closing this issue now.
linguini1 commentedon Jul 3, 2026
Great work @raiden00pl