Skip to content

feat: adopt emil's hal.cortex_m, deduplicating cortex/default_init - #55

Merged
gabrielfrasantos merged 6 commits into
mainfrom
feat/adopt-emil-cortex-m
Aug 25, 2026
Merged

feat: adopt emil's hal.cortex_m, deduplicating cortex/default_init#55
gabrielfrasantos merged 6 commits into
mainfrom
feat/adopt-emil-cortex-m

Conversation

@gabrielfrasantos

Copy link
Copy Markdown
Contributor

Bump the emil pin to 321a369d (embedded-pro/embedded-infra-lib#95, "generic Cortex-M layer") and link hal.cortex_m instead of hal_st's own copy of InterruptCortex.hpp/cpp, across all 32 drivers that use InterruptHandler/ InterruptTable/DispatchedInterruptHandler/ImmediateInterruptHandler/ InterruptPriority/ActiveInterrupt (now hal::cortex::*).

hal.cortex_m also brings FaultTracer, whose weak HardFault_Handler etc. collide with the vendor startup files' ".thumb_set HardFault_Handler, Default_Handler" alias. halst_target_bringup() now forces the link order of hal.cortex_m, hal_st.bringup, and hal.cortex_m.runtime explicitly so FaultTracer wins deterministically instead of by linker luck, and reuses emil's abort()/_sbrk instead of hal-st's own (removing another duplicate; _sbrk needs the end linker symbol, added to sections.ld).

hal_st/cortex and hal_st/default_init are gone. What's left of the latter (Default_Handler_Forwarded, HAL_InitTick, __assert_func, assert_failed) has no emil equivalent -- it's ST HAL bring-up glue, not portable -- so it moves to hal_st/bringup/, named after emil's own term for this category of code. DataWatchpointAndTrace, the other tenant of the old cortex/ folder, moves to its own hal_st/dwt/ since nothing else needs it.

Verified by direct arm-none-eabi-g++/ld compilation and linking against the real emil source (the full stm32g431 CMake preset needs a packaged host build this environment can't produce in reasonable time): all edited drivers compile clean, and -Wl,-y traces confirm HardFault_Handler, abort, _init, _sbrk, and assert_failed each resolve to exactly the intended definition with no multiple-definition conflicts.

Bump the emil pin to 321a369d (embedded-pro/embedded-infra-lib#95, "generic
Cortex-M layer") and link hal.cortex_m instead of hal_st's own copy of
InterruptCortex.hpp/cpp, across all 32 drivers that use InterruptHandler/
InterruptTable/DispatchedInterruptHandler/ImmediateInterruptHandler/
InterruptPriority/ActiveInterrupt (now hal::cortex::*).

hal.cortex_m also brings FaultTracer, whose weak HardFault_Handler etc.
collide with the vendor startup files' ".thumb_set HardFault_Handler,
Default_Handler" alias. halst_target_bringup() now forces the link order
of hal.cortex_m, hal_st.bringup, and hal.cortex_m.runtime explicitly so
FaultTracer wins deterministically instead of by linker luck, and reuses
emil's abort()/_sbrk instead of hal-st's own (removing another duplicate;
_sbrk needs the `end` linker symbol, added to sections.ld).

hal_st/cortex and hal_st/default_init are gone. What's left of the latter
(Default_Handler_Forwarded, HAL_InitTick, __assert_func, assert_failed) has
no emil equivalent -- it's ST HAL bring-up glue, not portable -- so it moves
to hal_st/bringup/, named after emil's own term for this category of code.
DataWatchpointAndTrace, the other tenant of the old cortex/ folder, moves to
its own hal_st/dwt/ since nothing else needs it.

Verified by direct arm-none-eabi-g++/ld compilation and linking against the
real emil source (the full stm32g431 CMake preset needs a packaged host
build this environment can't produce in reasonable time): all edited
drivers compile clean, and `-Wl,-y` traces confirm HardFault_Handler,
abort, _init, _sbrk, and assert_failed each resolve to exactly the intended
definition with no multiple-definition conflicts.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 25, 2026 14:03
…settings.json)

Ignore .claude/scheduled_tasks.lock, which is session-local runtime state.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@gabrielfrasantos

gabrielfrasantos commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

⚠️MegaLinter analysis: Success with warnings

Descriptor Linter Files Fixed Errors Max errors Warnings Elapsed time
✅ ACTION actionlint 5 0 0 0.07s
✅ CPP clang-format 15 6 0 0 0.33s
✅ CPP cppcheck 15 0 0 0.2s
✅ DOCKERFILE hadolint 1 0 0 0.05s
✅ JSON jsonlint 8 0 0 0.09s
✅ JSON prettier 8 3 0 0 0.58s
⚠️ MARKDOWN markdownlint 14 1 20 0 0.96s
✅ MARKDOWN markdown-table-formatter 14 1 0 0 0.56s
✅ REPOSITORY betterleaks yes no no 0.87s
✅ REPOSITORY checkov yes no no 19.68s
✅ REPOSITORY git_diff yes no no 0.05s
✅ REPOSITORY grype yes no no 66.41s
✅ REPOSITORY ls-lint yes no no 0.01s
✅ REPOSITORY osv-scanner yes no no 0.77s
✅ REPOSITORY secretlint yes no no 5.26s
✅ REPOSITORY syft yes no no 2.13s
✅ REPOSITORY trivy yes no no 10.4s
✅ REPOSITORY trivy-sbom yes no no 0.43s
✅ REPOSITORY trufflehog yes no no 3.75s
⚠️ SPELL lychee 41 5 0 55.06s
✅ YAML prettier 8 1 0 0 0.46s
✅ YAML v8r 8 0 0 4.78s
✅ YAML yamllint 8 0 0 0.42s

Detailed Issues

⚠️ SPELL / lychee - 5 errors
📝 Summary
---------------------
🔍 Total..........263
🔗 Unique.........243
✅ Successful.....253
⏳ Timeouts.........0
🔀 Redirected.....111
👻 Excluded.........5
❓ Unknown..........0
🚫 Errors...........5
⛔ Unsupported......5

Errors in .github/agents/orchestrator.agent.md
[ERROR] file://.github/copilot-instructions.md (at 52:23) | File not found. Check if file exists and path is correct
[ERROR] file://hal_st/cortex/InterruptCortex.hpp (at 56:22) | File not found. Check if file exists and path is correct

Errors in .github/ISSUE_TEMPLATE/add-or-update-hal-driver.md
[ERROR] http://mcd.rou.st.com/modules.php?name=mcu (at 28:63) | Connection failed. Check network connectivity and firewall settings

Errors in README.md
[404] https://api.securityscorecards.dev/projects/github.com/embedded-pro/hal-st (at 3:199) | Rejected status code: 404 Not Found
[ERROR] https://st.com/ (at 5:93) | HTTP/2 protocol error. Server may not support HTTP/2 properly | Followed 1 redirect. Redirects: https://st.com/ --[301]--> https://www.st.com/

Hint: Followed 111 redirects. You might want to consider replacing redirecting URLs with the resolved URLs. Use verbose mode (`-v`/`-vv`) to see redirection details.
Hint: You can configure accepted/rejected response codes with `-a` or `--accept`
⚠️ MARKDOWN / markdownlint - 20 errors
.github/agents/executor.agent.md:11 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "You are the executor agent for..."]
.github/agents/orchestrator.agent.md:18:401 error MD013/line-length Line length [Expected: 400; Actual: 420]
.github/agents/orchestrator.agent.md:18 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "You are the orchestrator agent..."]
.github/agents/planner.agent.md:11 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "You are the planner agent for ..."]
.github/agents/planner.agent.md:39 error MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
.github/agents/reviewer.agent.md:14 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "You are the reviewer agent for..."]
.github/agents/reviewer.agent.md:122 error MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
.github/instructions/hal-st-cpp.instructions.md:18 error MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
.github/ISSUE_TEMPLATE/add-or-update-hal-driver.md:10 error MD025/single-title/single-h1 Multiple top-level headings in the same document [Context: "How to import a HAL driver"]
.github/prompts/orchestrate.prompt.md:8 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "Start a new development workfl..."]
CHANGELOG.md:83 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "⚠ BREAKING CHANGES"]
CHANGELOG.md:87 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:94 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Bug Fixes"]
CHANGELOG.md:103 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:122 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Bug Fixes"]
CHANGELOG.md:140 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "⚠ BREAKING CHANGES"]
CHANGELOG.md:144 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:151 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:162 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Bug Fixes"]
CLAUDE.md:1 error MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "hal-st — Claude Instructions"]

Notices

⚠️ Your configuration references items that have been removed from MegaLinter and are ignored: REPOSITORY_GITLEAKS, REPOSITORY_KICS. See Removed linters to find their replacements.

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@10.0.0 --custom-flavor-setup --custom-flavor-linters ACTION_ACTIONLINT,CPP_CPPCHECK,CPP_CLANG_FORMAT,DOCKERFILE_HADOLINT,JSON_JSONLINT,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_BETTERLEAKS,REPOSITORY_GRYPE,REPOSITORY_LS_LINT,REPOSITORY_OSV_SCANNER,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,SPELL_LYCHEE,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is provided by OX Security
Show us your support by starring ⭐ the repository

Copilot AI 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.

Pull request overview

This PR migrates hal-st off its in-tree Cortex-M interrupt/default-init implementation and onto emil’s hal.cortex_m layer, removing duplicated startup/runtime pieces and making fault-handler resolution deterministic via explicit link ordering.

Changes:

  • Switch STM32 drivers and examples from hal_st/cortex/InterruptCortex.* to hal/cortex_m/InterruptCortex.hpp and hal::cortex::* types.
  • Replace default_init with a new bringup library + halst_target_bringup() that controls object link order so FaultTracer handlers and runtime stubs win consistently.
  • Add a linker-provided end symbol (aliasing _end_noinit) to support the new _sbrk expectations.

Reviewed changes

Copilot reviewed 52 out of 54 changed files in this pull request and generated no comments.

Show a summary per file
File Description
st/ldscripts/sections.ld Provides end symbol required by the adopted runtime stubs.
integration_test/tester/CMakeLists.txt Switches test target to halst_target_bringup().
integration_test/tested/CMakeLists.txt Switches test target to halst_target_bringup().
hal_st/synchronous_stm32fxxx/SynchronousUartStm.hpp Updates interrupt include and base type to hal::cortex.
hal_st/stm32fxxx/WatchDogStm.hpp Uses cortex::ImmediateInterruptHandler.
hal_st/stm32fxxx/UsbHostLinkLayerStm.hpp Updates interrupt include/types and priority enum usage.
hal_st/stm32fxxx/UartStmDuplexDma.hpp Updates interrupt-handler comment to new namespace.
hal_st/stm32fxxx/UartStm.hpp Updates interrupt include/types and priority enum usage.
hal_st/stm32fxxx/TimerStm.hpp Uses cortex::ImmediateInterruptHandler.
hal_st/stm32fxxx/TamperStm.hpp Uses cortex::ImmediateInterruptHandler.
hal_st/stm32fxxx/SystemTickTimerService.hpp Updates base class to cortex::InterruptHandler.
hal_st/stm32fxxx/SystemTickStm.hpp Updates base class to cortex::InterruptHandler.
hal_st/stm32fxxx/SpiMasterStm.hpp Uses cortex::ImmediateInterruptHandler optional.
hal_st/stm32fxxx/RandomDataGeneratorStm.hpp Updates base class to cortex::InterruptHandler.
hal_st/stm32fxxx/QuadSpiStmDma.hpp Uses cortex::DispatchedInterruptHandler.
hal_st/stm32fxxx/PkaStm.hpp Updates base class to hal::cortex::DispatchedInterruptHandler.
hal_st/stm32fxxx/PkaStm.cpp Updates ctor init to cortex::DispatchedInterruptHandler.
hal_st/stm32fxxx/LpTimerStm.hpp Uses cortex::ImmediateInterruptHandler.
hal_st/stm32fxxx/I2cStm.hpp Uses cortex::{Immediate,Dispatched}InterruptHandler.
hal_st/stm32fxxx/GpioStm.hpp Updates all IRQ dispatcher members to cortex::ImmediateInterruptHandler.
hal_st/stm32fxxx/GpioStm.cpp Updates interrupt include path to emil’s hal/cortex_m.
hal_st/stm32fxxx/FlashInternalStmBle.hpp Uses cortex::ImmediateInterruptHandler for IRQ hooks.
hal_st/stm32fxxx/FlashInternalHighCycleAreaStm.hpp Uses hal::cortex::ImmediateInterruptHandler for NMI hook.
hal_st/stm32fxxx/EthernetMacStm.hpp Uses cortex::DispatchedInterruptHandler.
hal_st/stm32fxxx/DmaStm.hpp Re-namespaces interrupt handler variant + pointer type.
hal_st/stm32fxxx/DmaStm.cpp Updates std::in_place_type / std::get to cortex::* types.
hal_st/stm32fxxx/CMakeLists.txt Links hal.cortex_m instead of the removed hal_st.cortex.
hal_st/stm32fxxx/CanStm.hpp Uses cortex::DispatchedInterruptHandler members.
hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp Uses cortex::DispatchedInterruptHandler.
hal_st/stm32fxxx/AnalogToDigitalPinStm.cpp Updates interrupt include path to emil’s hal/cortex_m.
hal_st/instantiations/StmEventInfrastructure.hpp Updates InterruptTable storage type to hal::cortex::InterruptTable.
hal_st/dwt/DataWatchpointAndTrace.hpp Adds a dedicated DWT header in the new hal_st/dwt module.
hal_st/dwt/DataWatchpointAndTrace.cpp Updates include to new DWT header path.
hal_st/dwt/CMakeLists.txt Introduces hal_st.dwt library target.
hal_st/default_init/DefaultInit.cpp Removes in-tree default-init/runtime stubs (moved to emil + bringup).
hal_st/default_init/CMakeLists.txt Removes hal_st.default_init target and helper function.
hal_st/default_init/Atomic.cpp Removes local __atomic_* shims (now supplied by emil runtime).
hal_st/cortex/InterruptCortex.hpp Removes duplicated Cortex-M interrupt abstractions.
hal_st/cortex/InterruptCortex.cpp Removes duplicated Cortex-M interrupt implementation.
hal_st/cortex/CMakeLists.txt Removes hal_st.cortex library target.
hal_st/CMakeLists.txt Replaces cortex/default_init subdirs with dwt/bringup.
hal_st/bringup/CMakeLists.txt Adds bringup library + halst_target_bringup() with explicit object ordering.
hal_st/bringup/Bringup.cpp Adds ST HAL tick override + forwarded default handler using hal::cortex.
hal_st/bringup/Assert.cpp Adds ST HAL assert hooks that delegate to std::abort().
examples/sesame/CMakeLists.txt Switches example targets to halst_target_bringup().
examples/helloworld/CMakeLists.txt Switches example targets to halst_target_bringup().
examples/freertos/Main.cpp Uses hal::cortex::InterruptTable storage type.
examples/freertos/CMakeLists.txt Switches example target to halst_target_bringup().
examples/blink/CMakeLists.txt Switches example targets to halst_target_bringup().
CMakeLists.txt Updates emil pin and enables building emil’s Cortex-M layer.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

gabrielfrasantos and others added 4 commits August 25, 2026 14:14
hal.cortex_m.runtime (Atomic/DefaultInit/SysCallStubs) contains ARM-only
inline assembly (mrs/cpsid/msr, bkpt). Forcing EMIL_BUILD_CORTEX_M on
unconditionally pulled it into the host x86_64 build too, since
TARGET_MCU_VENDOR is only "st" for the stm32* cross-compile presets and
unset for "host" -- CI failed assembling those instructions for the host
toolchain. Gate the flag on TARGET_MCU_VENDOR so it's only forced on when
actually cross-compiling for ST.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
DataWatchPointAndTrace has been contributed upstream to
embedded-infra-lib (emil); hal_st no longer needs its own copy.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
.claude was added for Claude Code project config but fails the
snake_case .dir rule.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread .claude/settings.json
Comment thread .claude/settings.json
Comment thread .ls-lint.yml
@gabrielfrasantos
gabrielfrasantos merged commit f5a0735 into main Aug 25, 2026
14 checks passed
@gabrielfrasantos
gabrielfrasantos deleted the feat/adopt-emil-cortex-m branch August 25, 2026 17:43
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