-
Notifications
You must be signed in to change notification settings - Fork 0
feat: adopt emil's hal.cortex_m, deduplicating cortex/default_init #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
be7a620
feat: adopt emil's hal.cortex_m, deduplicating cortex/default_init
gabrielfrasantos ef0e4e7
chore: add Claude Code project config (AGENTS.md, CLAUDE.md, .claude/…
gabrielfrasantos 0e34c27
fix: only enable EMIL_BUILD_CORTEX_M for ST cross-compiles
gabrielfrasantos a5dd0f3
Merge branch 'main' into feat/adopt-emil-cortex-m
gabrielfrasantos 40cd3d5
feat: remove DWT module, superseded by emil's implementation
gabrielfrasantos 5423255
fix: ignore .claude directory in ls-lint
gabrielfrasantos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(*)" | ||
| ] | ||
| } | ||
| } | ||
|
gabrielfrasantos marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ out/ | |
| megalinter-reports/ | ||
| install/ | ||
| .megalinter_github_conf | ||
| .claude/scheduled_tasks.lock | ||
|
gabrielfrasantos marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ ls: | |
| .cpp: PascalCase | ||
|
|
||
| ignore: | ||
| - .claude | ||
| - .devcontainer | ||
| - .git | ||
| - .github | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # hal-st — Agent Rules (canonical) | ||
|
|
||
| Single source of truth for **Claude, Copilot, and sub-agents**. `CLAUDE.md` points here. Detailed C++ coding rules: `.github/instructions/hal-st-cpp.instructions.md` (binding for all `*.hpp/*.cpp/*.h/*.c` changes). Copilot custom agents: `.github/agents/`. Build presets: `CMakePresets.json`. | ||
|
|
||
| hal-st is a Hardware Abstraction Layer for ST ARM Cortex-M microcontrollers (F4, F7, G0, G4, H5, WB, WBA families), implementing [embedded-infra-lib](https://github.com/embedded-pro/embedded-infra-lib) HAL interfaces over the STM32 HAL/LL library. It's a copy of [philips-software/amp-hal-st](https://github.com/philips-software/amp-hal-st). | ||
|
|
||
| ## Architecture | ||
|
|
||
| - `hal_st/cortex/` — ARM Cortex-M core (`InterruptCortex`, `DataWatchpointAndTrace`) | ||
| - `hal_st/stm32fxxx/` — STM32 peripheral drivers (Uart, Can, Spi, Adc, Gpio, Dma, Timer, Flash, Ethernet, USB, …), split into `ip/` (peripheral IP blocks) and `mcu/` (family wiring) | ||
| - `hal_st/synchronous_stm32fxxx/` — Blocking driver variants (`SynchronousUart`, `SynchronousSpiMaster`, …) | ||
| - `hal_st/instantiations/` — Board event infrastructure (`StmEventInfrastructure`, `NucleoUi`, `DiscoveryUi`) | ||
| - `hal_st/default_init/` — Startup code and atomics shim | ||
| - `hal_st/middlewares/` — `STM32_WPAN`, `ble_middleware` | ||
| - `hal_st_lwip/` — lwIP network stack instantiations | ||
| - `st/` — CMSIS headers, STM32 HAL driver sources (per family), `hal_conf/`, `ldscripts/` | ||
| - `services/st_util/` — ST bootloader communicator services | ||
| - `integration_test/` — hardware-in-the-loop cucumber test rig (`pcb/`, `flasher/`, `tester/`, `tested/`, `runner/`, `logic/`) | ||
| - `examples/` — `blink`, `helloworld`, `sesame`, `freertos` | ||
|
|
||
| ## Memory — no heap | ||
|
|
||
| This is a driver library that always ends up running on constrained MCUs. Forbidden everywhere: `new`/`delete`/`malloc`/`free`, `make_unique`/`make_shared`, `std::vector`/`string`/`deque`/`list`/`map`/`set`. No recursion in driver code — stack depth must be statically bounded. | ||
|
|
||
| Use: `infra::BoundedVector<T>`, `infra::BoundedString`, `infra::BoundedDeque<T>`, `infra::MemoryRange<T>` (buffer params, not raw pointer+size), `std::array<T,N>`, `std::optional<T>`. | ||
|
|
||
| ## STM32 HAL/LL & driver conventions | ||
|
|
||
| Full detail lives in `.github/instructions/hal-st-cpp.instructions.md` — read it before touching driver code. Key points: | ||
|
|
||
| - `HAL_*`/`LL_*` only; never write to registers via magic offsets | ||
| - `HAL_FOO_Init` in constructor, `HAL_FOO_DeInit` + clock disable in destructor (RAII) | ||
| - Interrupt handlers: `private InterruptHandler` (single-vector) or `DispatchedInterruptHandler` (multi-vector, one member per vector); never call `NVIC_EnableIRQ` directly | ||
| - Every alternate-function pin: a `PeripheralPinStm` member, declared in constructor-init order | ||
| - Every driver: inner `Config` struct with mandatory `constexpr Config() {}` and sensible field defaults | ||
| - `oneBasedIndex` convention for peripheral indices; `really_assert` bounds; table access as `table[oneBasedIndex - 1]` | ||
| - `HAS_PERIPHERAL_xxx` guards come from generated `PeripheralTable.hpp` — never hand-edit anything under `generated/` | ||
| - DMA: `DMA_STREAM_BASED` (F4/F7) vs `DMA_CHANNEL_BASED` (G0/G4/WB/WBA/H5) — use `hal_st` DMA wrappers, not raw HAL DMA handles | ||
| - Naming: `FooStm` drivers, `SynchronousFooStm` blocking variants | ||
|
|
||
| ## Style | ||
|
|
||
| - Allman braces, 4-space indent, `.clang-format` authoritative | ||
| - PascalCase types/methods, camelCase members/locals; `const`-correct on all observer/query methods | ||
| - `#pragma once` for new/modified headers; legacy `#ifndef` guards may stay untouched | ||
| - No C-style casts — `static_cast<>`; `reinterpret_cast<>` only where the HAL requires register/void-pointer casts | ||
| - **No comments** except non-obvious *why*. No `TODO`/`FIXME`/`HACK`, no commented-out code | ||
|
|
||
| ## Interfaces & errors | ||
|
|
||
| - Interfaces = pure virtual; `virtual ~I() = default` — **never** `= 0` destructors | ||
| - No exceptions. `std::optional<T>` or status enums. `really_assert()` for preconditions | ||
| - No global mutable state — all state lives in driver class members | ||
|
|
||
| ## Testing | ||
|
|
||
| No unit tests in this repo. hal-st is validated by manual testing on Nucleo/Discovery boards, logic-analyser/scope verification, and the `integration_test/` hardware-in-the-loop rig — not by GoogleTest suites. Don't add unit tests for new or changed drivers. (`services/st_util/test/` is a pre-existing exception gated behind `HALST_BUILD_TESTS`; leave it as-is, don't extend the pattern elsewhere.) | ||
|
|
||
| ## Build | ||
|
|
||
| ```bash | ||
| cmake --preset host && cmake --build --preset host-Debug # host tooling/build check | ||
| cmake --preset stm32f407 && cmake --build --preset stm32f407-RelWithDebInfo # embedded target | ||
| ``` | ||
|
|
||
| Other target presets: `stm32wb55`, `stm32g070`, `stm32g431`, `stm32f429`, `stm32f746`, `stm32f767`, `stm32g474`, `stm32wba52`, `stm32wba65`, `stm32h563`, `stm32h573`. | ||
|
|
||
| ## Assistant behavior — be terse | ||
|
|
||
| - Minimal prose. No preamble/postamble, no restating the plan, no summaries unless asked | ||
| - Report results as file paths + build pass/fail (no test suite to report) | ||
| - Don't re-read files already read; batch reads; prefer targeted edits |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| hal-st — Claude Instructions | ||
| Canonical rules: AGENTS.md (shared with Copilot and sub-agents). C++ coding detail: .github/instructions/hal-st-cpp.instructions.md. Copilot agents: .github/agents/. Build presets: CMakePresets.json. | ||
|
|
||
| Essentials (full detail in AGENTS.md): | ||
|
|
||
| No heap — bounded containers / std::array / std::optional; no recursion in driver code. Applies repo-wide (this is an MCU HAL library). | ||
| STM32 HAL/LL — HAL_*/LL_* only, never raw registers; HAL_FOO_Init/DeInit in ctor/dtor (RAII); InterruptHandler/DispatchedInterruptHandler, never NVIC_EnableIRQ directly; PeripheralPinStm for AF pins; DMA_STREAM_BASED vs DMA_CHANNEL_BASED wrappers. | ||
| Driver Config — inner Config struct, mandatory constexpr Config() {}, oneBasedIndex convention, HAS_PERIPHERAL_xxx guards from generated PeripheralTable.hpp (never hand-edit generated/). | ||
| Style — Allman braces, 4-space, PascalCase types/methods, camelCase members. No comments except non-obvious why. | ||
| No tests — hal-st has no unit test suite; validation is on real hardware (Nucleo/Discovery, logic analyser) and integration_test/. Don't add unit tests for driver changes. | ||
| No exceptions — std::optional/status enums; interfaces virtual ~I() = default. | ||
| Be terse — minimal prose; report file paths + build pass/fail. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| add_subdirectory(cortex) | ||
| add_subdirectory(stm32fxxx) | ||
| add_subdirectory(synchronous_stm32fxxx) | ||
| add_subdirectory(middlewares) | ||
| add_subdirectory(instantiations) | ||
| add_subdirectory(default_init) | ||
| add_subdirectory(bringup) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #include <cstdint> | ||
| #include <cstdlib> | ||
|
|
||
| extern "C" | ||
| { | ||
| void __assert_func(const char*, int, const char*, const char*) | ||
| { | ||
| std::abort(); | ||
| } | ||
|
|
||
| void assert_failed(uint8_t* file, uint32_t line) | ||
| { | ||
| std::abort(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #include DEVICE_HEADER | ||
| #include "hal/cortex_m/InterruptCortex.hpp" | ||
|
|
||
| extern "C" | ||
| { | ||
| // Avoid the SysTick handler from being initialised by HAL_Init | ||
| HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) | ||
| { | ||
| return HAL_OK; | ||
| } | ||
|
|
||
| [[gnu::weak]] void Default_Handler_Forwarded() | ||
| { | ||
| hal::cortex::InterruptTable::Instance().Invoke(hal::cortex::ActiveInterrupt()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| add_library(hal_st.bringup STATIC) | ||
| emil_build_for(hal_st.bringup TARGET_MCU_VENDOR st PREREQUISITE_BOOL HALST_STANDALONE) | ||
|
|
||
| target_include_directories(hal_st.bringup PUBLIC | ||
| "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../..>" | ||
| "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" | ||
| ) | ||
|
|
||
| target_link_libraries(hal_st.bringup PUBLIC | ||
| st.hal_driver | ||
| hal.cortex_m | ||
| ) | ||
|
|
||
| # Assembler does not understand -Werror | ||
| set_target_properties(hal_st.bringup PROPERTIES COMPILE_WARNING_AS_ERROR Off) | ||
|
|
||
| target_sources(hal_st.bringup PRIVATE | ||
| Assert.cpp | ||
| Bringup.cpp | ||
| ) | ||
|
|
||
| if (TARGET_MCU_VENDOR STREQUAL st) | ||
| get_target_property(startup_source st.hal_driver_${TARGET_MCU_FAMILY} HALST_STARTUP_SOURCE) | ||
|
|
||
| target_sources(hal_st.bringup PRIVATE | ||
| ${startup_source} | ||
| ) | ||
| endif() | ||
|
|
||
| function(halst_target_bringup target) | ||
| # hal.cortex_m's FaultTracer defines HardFault_Handler etc. as weak symbols, same as the | ||
| # vendor startup file's ".thumb_set HardFault_Handler,Default_Handler" alias; whichever | ||
| # definition the linker sees first for a given weak symbol wins, so hal.cortex_m's objects | ||
| # are listed ahead of hal_st.bringup's (which carries the startup object) to make | ||
| # FaultTracer's fault handlers win deterministically instead of by accident. | ||
| # | ||
| # hal.cortex_m.runtime (Atomic/DefaultInit/SysCallStubs) supplies abort(), _sbrk, and the | ||
| # __atomic_* shims as weak symbols; per its own design, these must reach the final ELF as | ||
| # loose objects rather than archive members, because an archived weak definition is only | ||
| # extracted once something already references it, which is too late to beat what newlib | ||
| # pulls out of libg_nano.a. | ||
| target_link_libraries(${target} PUBLIC | ||
| $<TARGET_OBJECTS:hal.cortex_m> | ||
| $<TARGET_OBJECTS:hal_st.bringup> | ||
| $<TARGET_OBJECTS:hal.cortex_m.runtime> | ||
| ) | ||
| endfunction() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.