Skip to content

feat(stm32): MCU foundation — CMSIS, device headers, startup, linker#413

Open
nhuvaoanh123 wants to merge 2 commits into
eclipse-openbsw:mainfrom
nhuvaoanh123:stm32-pr-1
Open

feat(stm32): MCU foundation — CMSIS, device headers, startup, linker#413
nhuvaoanh123 wants to merge 2 commits into
eclipse-openbsw:mainfrom
nhuvaoanh123:stm32-pr-1

Conversation

@nhuvaoanh123
Copy link
Copy Markdown
Contributor

Purpose of this PR

  • Bugfix
  • New Feature
  • Documentation Update
  • Other

Description

First PR in a 10-part series adding STM32 Cortex-M4 platform support to OpenBSW.

This PR establishes the MCU foundation layer for two STM32 Nucleo boards:

  • NUCLEO-G474RE (STM32G4, FDCAN, 170 MHz, 512 KB Flash)
  • NUCLEO-F413ZH (STM32F4, bxCAN, 100 MHz, 1.5 MB Flash)

What's included

  • ARM CMSIS-Core v6.1 headers (Cortex-M4) — Apache-2.0 licensed
  • ST CMSIS Device headers for STM32F413xx and STM32G474xx
  • GNU AS startup files (startup_stm32f413xx.s, startup_stm32g474xx.s)
  • Linker scripts for both chips
  • Chip-selection cmake modules (stm32f413zh.cmake, stm32g474re.cmake)
  • CMakePresets for all four build variants (2 boards × 2 RTOS)
  • Root CMakeLists.txt integration for STM32 platform detection

Milestone

cmake --preset nucleo-g474re-freertos-gcc configures successfully with ARM GCC cross-compiler.

Series overview

PR Content Depends on
1 (this) MCU foundation
2 UART + GPIO + Clock BSP 1
3 bxCAN driver + unit tests 2
4 FDCAN driver + unit tests 2
5 HardFault handler + safety/watchdog 2
6 FreeRTOS board config (G474RE) 1–5
7 ThreadX board config 6
8 Second board (F413ZH) 6
9 CAN system + DoCAN transport 6
10 UDS services + 405 HIL test qualification 9

Related Issues

Continues the STM32 platform port discussed in #408 (closed, now split into reviewable PRs).

Breaking Changes

  • Yes
  • No

Test Plan

  1. Configure with ARM GCC: CC=arm-none-eabi-gcc CXX=arm-none-eabi-g++ cmake --preset nucleo-g474re-freertos-gcc
  2. Verify configure completes without errors
  3. Existing posix and S32K builds are unaffected (no libs/bsw/ changes)

Regression Tests

Have tests been added/updated? [ ] Yes [x] No — unit tests come in PRs 3–4

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Introduces the initial STM32 Cortex‑M4 platform foundation for OpenBSW (NUCLEO‑G474RE and NUCLEO‑F413ZH), including CMSIS/ST device headers, startup code, linker scripts, and CMake integration/presets for cross-compiling.

Changes:

  • Adds STM32 platform selection + per-chip CMake configuration modules (STM32F413ZH / STM32G474RE).
  • Adds bspMcu with CMSIS/ST headers, startup assembly, linker scripts, and a software reset wrapper.
  • Adds STM32 CMake presets and root build integration for the new STM32 platforms.

Reviewed changes

Copilot reviewed 31 out of 34 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
platforms/stm32/CMakeLists.txt Adds STM32 platform entrypoint and chip selection via STM32_CHIP.
platforms/stm32/cmake/stm32g474re.cmake Defines STM32G474RE chip parameters and paths to startup/linker artifacts.
platforms/stm32/cmake/stm32f413zh.cmake Defines STM32F413ZH chip parameters and paths to startup/linker artifacts.
platforms/stm32/bsp/CMakeLists.txt Adds STM32 BSP subtree (currently only bspMcu).
platforms/stm32/bsp/bspMcu/startup/startup_stm32g474xx.s Startup/reset handler + vector table for STM32G474xx.
platforms/stm32/bsp/bspMcu/startup/startup_stm32f413xx.s Startup/reset handler + vector table for STM32F413xx.
platforms/stm32/bsp/bspMcu/src/reset/softwareSystemReset.cpp Adds software-triggered system reset wrapper with weak pre-reset hook.
platforms/stm32/bsp/bspMcu/module.spec Declares module metadata.
platforms/stm32/bsp/bspMcu/linker/STM32G474RExx_FLASH.ld Linker script for STM32G474RE flash/RAM layout.
platforms/stm32/bsp/bspMcu/linker/STM32F413ZHxx_FLASH.ld Linker script for STM32F413ZH flash/RAM layout.
platforms/stm32/bsp/bspMcu/include/reset/softwareSystemReset.h Public header for software reset API.
platforms/stm32/bsp/bspMcu/include/mcu/typedefs.h Adds NVIC convenience macro mappings.
platforms/stm32/bsp/bspMcu/include/mcu/mcu.h Single include point for chip headers + platform interrupt macros.
platforms/stm32/bsp/bspMcu/include/3rdparty/st/stm32g4/system_stm32g4xx.h Imports ST system header for G4 family.
platforms/stm32/bsp/bspMcu/include/3rdparty/st/stm32g4/stm32g4xx.h Imports ST device-family header for G4.
platforms/stm32/bsp/bspMcu/include/3rdparty/st/stm32f4/system_stm32f4xx.h Imports ST system header for F4 family.
platforms/stm32/bsp/bspMcu/include/3rdparty/st/stm32f4/stm32f4xx.h Imports ST device-family header for F4.
platforms/stm32/bsp/bspMcu/include/3rdparty/cmsis/m-profile/cmsis_gcc_m.h Imports CMSIS compiler support header (GCC, M-profile).
platforms/stm32/bsp/bspMcu/include/3rdparty/cmsis/m-profile/cmsis_clang_m.h Imports CMSIS compiler support header (Clang, M-profile).
platforms/stm32/bsp/bspMcu/include/3rdparty/cmsis/m-profile/armv7m_mpu.h Imports CMSIS MPU API for Armv7‑M.
platforms/stm32/bsp/bspMcu/include/3rdparty/cmsis/LICENSE Adds Apache-2.0 license text for CMSIS import.
platforms/stm32/bsp/bspMcu/include/3rdparty/cmsis/cmsis_version.h Imports CMSIS version header.
platforms/stm32/bsp/bspMcu/include/3rdparty/cmsis/cmsis_gcc.h Imports CMSIS GCC compiler abstraction header.
platforms/stm32/bsp/bspMcu/include/3rdparty/cmsis/cmsis_compiler.h Imports CMSIS compiler selection header.
platforms/stm32/bsp/bspMcu/include/3rdparty/cmsis/cmsis_clang.h Imports CMSIS Clang compiler abstraction header.
platforms/stm32/bsp/bspMcu/doc/index.rst Adds module documentation for the STM32 MCU foundation layer.
platforms/stm32/bsp/bspMcu/CMakeLists.txt Defines bspMcu library and includes/compile defs for STM32.
executables/referenceApp/platforms/nucleo_g474re/Options.cmake Adds referenceApp options for NUCLEO‑G474RE.
executables/referenceApp/platforms/nucleo_g474re/CMakeLists.txt Adds placeholder board CMakeLists.
CMakePresets.json Adds STM32 build/test presets (boards × RTOS).
CMakeLists.txt Adds STM32 platform detection for selecting platforms/stm32 and Rust target.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CMakePresets.json
Comment thread platforms/stm32/bsp/bspMcu/startup/startup_stm32g474xx.s
Comment thread platforms/stm32/bsp/bspMcu/startup/startup_stm32f413xx.s
Comment thread platforms/stm32/bsp/bspMcu/startup/startup_stm32g474xx.s Outdated
Comment thread platforms/stm32/bsp/bspMcu/startup/startup_stm32f413xx.s Outdated
Comment thread platforms/stm32/bsp/bspMcu/linker/STM32F413ZHxx_FLASH.ld Outdated
Comment thread platforms/stm32/cmake/stm32g474re.cmake Outdated
Comment thread platforms/stm32/cmake/stm32f413zh.cmake Outdated
Comment thread platforms/stm32/bsp/bspMcu/include/3rdparty/cmsis/m-profile/armv7m_mpu.h Outdated
Comment thread NOTICE.md Outdated
Comment thread CMakePresets.json Outdated
}
},
{
"name": "nucleo-f413zh-freertos-gcc",
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.

cmake --preset nucleo-f412zh-freertos-gcc -DCMAKE_CXX_STANDARD=17
cmake --build --preset nucleo-f413zh-freertos-gcc --verbose

gives me:

CMake Error at CMakeLists.txt:41 (include):
  include could not find requested file:

    executables/referenceApp/platforms/nucleo_f413zh/Options.cmake

I understand that you intend to add this other board in another PR. Consider merging them to make it testable. Or better refactor between the PRs.

Comment thread CMakePresets.json Outdated
}
},
{
"name": "nucleo-g474re-freertos-gcc",
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.

cmake --preset nucleo-g474re-freertos-gcc -DCMAKE_CXX_STANDARD=17
cmake --build --preset nucleo-g474re-freertos-gcc --verbose

gives me:

In file included from /home/rr/openbsw/libs/3rdparty/freeRtos/include/FreeRTOS.h:64,
                 from /home/rr/openbsw/libs/3rdparty/freeRtos/src/croutine.c:29:
/home/rr/openbsw/libs/bsw/asyncFreeRtos/freeRtosConfiguration/FreeRTOSConfig.h:82:10: fatal error: os/FreeRtosPlatformConfig.h: No such file or directory
   82 | #include "os/FreeRtosPlatformConfig.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@nhuvaoanh123
Copy link
Copy Markdown
Contributor Author

nhuvaoanh123 commented Apr 16, 2026

Thank you for the review.

  • CMSIS duplication: moving to libs/3rdparty/cmsis/ as a separate prep PR, shared by s32k1xx and stm32. Both copies are CMSIS 6.1.0 — 6 of 9 files byte-identical, 3 differ only in Doxygen comment style. Impact is 6 files: one CMakeLists path change per platform, one #include path fix in s32k1xx mcu.h, one module.spec glob update, one NOTICE.md consolidation. Nothing outside platforms/ uses CMSIS-Core. Full impact analysis in the strategy doc.
  • F413ZH preset fails: removing all board presets from this PR. They'll ship in the PR that provides the full board directory.
  • G474RE FreeRTOS build fails: same — FreeRTOS preset moves to the PR that provides the port, config, and main.cpp.

Full restructured plan: docs/stm32-pr-strategy.md

We'll rebase the series to match and update the PRs.

@rolandreichweinbmw
Copy link
Copy Markdown
Contributor

rolandreichweinbmw commented Apr 21, 2026

Are you still planning to provide the PR 0, and update the others, as documented there?

OTOH, you can also convert the PRs to "draft" for now, and in the beginning of collaboration in this project, first work on one of the smaller tasks under "issues".

@nhuvaoanh123
Copy link
Copy Markdown
Contributor Author

Yes, sticking with the plan. Starting with PR 0 (CMSIS move to libs/3rdparty/cmsis/). Will update the series once that lands.

@nhuvaoanh123
Copy link
Copy Markdown
Contributor Author

Hi @rolandreichweinbmw — PR 0 is now open as #445 (cmake-format CI cleared via 473d0713). On the earlier NOTICE.md ask: this branch already includes new entries for CMSIS at platforms/stm32/bsp/bspMcu/include/3rdparty/cmsis/LICENSE and ST STM32 Device Headers at .../st/LICENSE. Once #445 lands, the stack will be rebased to consume libs/3rdparty/cmsis/ and drop the duplicate stm32 CMSIS row.

Marking #414–422 as draft for now while #445 is in review, per your suggestion.

@rolandreichweinbmw
Copy link
Copy Markdown
Contributor

Now that #445 is merged, you can pick up this PR, resolve conflicts and remove the redundant CMSIS copy.

@nhuvaoanh123
Copy link
Copy Markdown
Contributor Author

Thanks, this is done now. I rebased the branch, resolved the conflict, removed the redundant STM32 CMSIS copy, and CI is green.

Comment thread docs/stm32-platform-overview.md Outdated
Comment thread docs/stm32-pr-strategy.md Outdated
Additional definitions in ``mcu.h``:

``INCLUDE_CORE_CM4_IN_MCU_H``
Guard required by the OpenBSW-patched ``core_cm4.h``.
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.

Can you please explain what was patched here?

I just noticed that in libs/3rdparty/cmsis/.riminfo there are actually more files listed as "ignores" than actually exist under libs/3rdparty/cmsis/. Can you please clarify how this can be?

Comment thread platforms/stm32/bsp/bspMcu/doc/index.rst Outdated
@@ -0,0 +1,301 @@
/**
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.

Can you put the files under 3rdparty/st/* also under RIM control?

Comment thread platforms/stm32/bsp/bspMcu/include/mcu/typedefs.h Outdated
Import the STM32F4 and STM32G4 CMSIS device headers from STMicroelectronics' dedicated RIM-tracked repositories. Keep only the F413 and G474 headers needed by the STM32 MCU foundation and record the unused upstream headers as RIM ignores.
Add the STM32 platform entry point, chip CMake files, bspMcu startup code, reset wrapper, and the STM32 unit-test preset. Keep the change self-contained by excluding board application presets and PR-process documentation from the repository.
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