From be7a620ec24d13a3798181252cd7765c9eb29ffd Mon Sep 17 00:00:00 2001 From: Gabriel Santos Date: Tue, 25 Aug 2026 14:02:12 +0000 Subject: [PATCH 1/5] feat: adopt emil's hal.cortex_m, deduplicating cortex/default_init 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 --- CMakeLists.txt | 3 +- examples/blink/CMakeLists.txt | 4 +- examples/freertos/CMakeLists.txt | 2 +- examples/freertos/Main.cpp | 2 +- examples/helloworld/CMakeLists.txt | 4 +- examples/sesame/CMakeLists.txt | 2 +- hal_st/CMakeLists.txt | 4 +- hal_st/bringup/Assert.cpp | 15 ++ hal_st/bringup/Bringup.cpp | 16 ++ hal_st/bringup/CMakeLists.txt | 47 ++++ hal_st/cortex/CMakeLists.txt | 19 -- hal_st/cortex/InterruptCortex.cpp | 236 ------------------ hal_st/cortex/InterruptCortex.hpp | 110 -------- hal_st/default_init/Atomic.cpp | 66 ----- hal_st/default_init/CMakeLists.txt | 34 --- hal_st/default_init/DefaultInit.cpp | 59 ----- hal_st/dwt/CMakeLists.txt | 17 ++ .../DataWatchpointAndTrace.cpp | 2 +- .../DataWatchpointAndTrace.hpp | 0 .../instantiations/StmEventInfrastructure.hpp | 4 +- hal_st/stm32fxxx/AnalogToDigitalPinStm.cpp | 2 +- hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp | 4 +- hal_st/stm32fxxx/CMakeLists.txt | 2 +- hal_st/stm32fxxx/CanStm.hpp | 8 +- hal_st/stm32fxxx/DmaStm.cpp | 10 +- hal_st/stm32fxxx/DmaStm.hpp | 8 +- hal_st/stm32fxxx/EthernetMacStm.hpp | 4 +- .../FlashInternalHighCycleAreaStm.hpp | 4 +- hal_st/stm32fxxx/FlashInternalStmBle.hpp | 6 +- hal_st/stm32fxxx/GpioStm.cpp | 2 +- hal_st/stm32fxxx/GpioStm.hpp | 44 ++-- hal_st/stm32fxxx/I2cStm.hpp | 6 +- hal_st/stm32fxxx/LpTimerStm.hpp | 4 +- hal_st/stm32fxxx/PkaStm.cpp | 2 +- hal_st/stm32fxxx/PkaStm.hpp | 4 +- hal_st/stm32fxxx/QuadSpiStmDma.hpp | 4 +- hal_st/stm32fxxx/RandomDataGeneratorStm.hpp | 4 +- hal_st/stm32fxxx/SpiMasterStm.hpp | 4 +- hal_st/stm32fxxx/SystemTickStm.hpp | 4 +- hal_st/stm32fxxx/SystemTickTimerService.hpp | 4 +- hal_st/stm32fxxx/TamperStm.hpp | 4 +- hal_st/stm32fxxx/TimerStm.hpp | 4 +- hal_st/stm32fxxx/UartStm.hpp | 6 +- hal_st/stm32fxxx/UartStmDuplexDma.hpp | 2 +- hal_st/stm32fxxx/UsbHostLinkLayerStm.hpp | 6 +- hal_st/stm32fxxx/WatchDogStm.hpp | 4 +- .../SynchronousUartStm.hpp | 4 +- integration_test/tested/CMakeLists.txt | 2 +- integration_test/tester/CMakeLists.txt | 2 +- st/ldscripts/sections.ld | 1 + 50 files changed, 192 insertions(+), 619 deletions(-) create mode 100644 hal_st/bringup/Assert.cpp create mode 100644 hal_st/bringup/Bringup.cpp create mode 100644 hal_st/bringup/CMakeLists.txt delete mode 100644 hal_st/cortex/CMakeLists.txt delete mode 100644 hal_st/cortex/InterruptCortex.cpp delete mode 100644 hal_st/cortex/InterruptCortex.hpp delete mode 100644 hal_st/default_init/Atomic.cpp delete mode 100644 hal_st/default_init/CMakeLists.txt delete mode 100644 hal_st/default_init/DefaultInit.cpp create mode 100644 hal_st/dwt/CMakeLists.txt rename hal_st/{cortex => dwt}/DataWatchpointAndTrace.cpp (92%) rename hal_st/{cortex => dwt}/DataWatchpointAndTrace.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8de55344..b60dc8f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,13 +26,14 @@ if (HALST_STANDALONE) FetchContent_Declare( emil GIT_REPOSITORY https://github.com/embedded-pro/embedded-infra-lib.git - GIT_TAG 9c3d4c32bba0123abdc0013b8b9d5aea26e1f103 # Unreleased + GIT_TAG 321a369d9ef75a41b212c38578aba774bd47bfb0 # Unreleased ) add_definitions(-DEMIL_ENABLE_TRACING=1) set(EMIL_ENABLE_DOCKER_TOOLS Off CACHE BOOL "" FORCE) set(EMIL_BUILD_ECHO_COMPILERS On CACHE BOOL "" FORCE) + set(EMIL_BUILD_CORTEX_M On CACHE BOOL "" FORCE) FetchContent_MakeAvailable(emil) diff --git a/examples/blink/CMakeLists.txt b/examples/blink/CMakeLists.txt index dc43e99d..5b864b53 100644 --- a/examples/blink/CMakeLists.txt +++ b/examples/blink/CMakeLists.txt @@ -18,7 +18,7 @@ target_link_libraries(examples_st.blink_nucleo144 PRIVATE ) halst_target_default_linker_scripts(examples_st.blink_nucleo144) -halst_target_default_init(examples_st.blink_nucleo144) +halst_target_bringup(examples_st.blink_nucleo144) emil_generate_artifacts(TARGET examples_st.blink_nucleo144 LST MAP BIN HEX) @@ -48,6 +48,6 @@ target_link_libraries(examples_st.blink_nucleo64 PRIVATE ) halst_target_default_linker_scripts(examples_st.blink_nucleo64) -halst_target_default_init(examples_st.blink_nucleo64) +halst_target_bringup(examples_st.blink_nucleo64) emil_generate_artifacts(TARGET examples_st.blink_nucleo64 LST MAP BIN HEX) diff --git a/examples/freertos/CMakeLists.txt b/examples/freertos/CMakeLists.txt index 6861fab7..a0ecf671 100644 --- a/examples/freertos/CMakeLists.txt +++ b/examples/freertos/CMakeLists.txt @@ -9,6 +9,6 @@ target_link_libraries(examples_st.freertos_nucleo144 PRIVATE ) halst_target_default_linker_scripts(examples_st.freertos_nucleo144) -halst_target_default_init(examples_st.freertos_nucleo144) +halst_target_bringup(examples_st.freertos_nucleo144) emil_generate_artifacts(TARGET examples_st.freertos_nucleo144 LST MAP BIN HEX) diff --git a/examples/freertos/Main.cpp b/examples/freertos/Main.cpp index d5138905..f7989cb0 100644 --- a/examples/freertos/Main.cpp +++ b/examples/freertos/Main.cpp @@ -38,7 +38,7 @@ int main() // Configure your clock here // ConfigureDefaultClockNucleo767ZI(); - static hal::InterruptTable::WithStorage<128> interruptTable; + static hal::cortex::InterruptTable::WithStorage<128> interruptTable; static hal::GpioStm gpio{ hal::pinoutTableDefaultStm, hal::analogTableDefaultStm }; static hal::TimerServiceFreeRtos timerService; static hal::LowPowerStrategyFreeRtos lowPowerStrategy; diff --git a/examples/helloworld/CMakeLists.txt b/examples/helloworld/CMakeLists.txt index 981e3394..c5bbe0bd 100644 --- a/examples/helloworld/CMakeLists.txt +++ b/examples/helloworld/CMakeLists.txt @@ -21,7 +21,7 @@ target_link_libraries(examples_st.helloworld_nucleo64 PRIVATE ) halst_target_default_linker_scripts(examples_st.helloworld_nucleo64) -halst_target_default_init(examples_st.helloworld_nucleo64) +halst_target_bringup(examples_st.helloworld_nucleo64) emil_generate_artifacts(TARGET examples_st.helloworld_nucleo64 LST MAP BIN HEX) @@ -45,6 +45,6 @@ target_link_libraries(examples_st.helloworld_nucleo144 PRIVATE ) halst_target_default_linker_scripts(examples_st.helloworld_nucleo144) -halst_target_default_init(examples_st.helloworld_nucleo144) +halst_target_bringup(examples_st.helloworld_nucleo144) emil_generate_artifacts(TARGET examples_st.helloworld_nucleo144 LST MAP BIN HEX) diff --git a/examples/sesame/CMakeLists.txt b/examples/sesame/CMakeLists.txt index 88287114..379aa8eb 100644 --- a/examples/sesame/CMakeLists.txt +++ b/examples/sesame/CMakeLists.txt @@ -19,7 +19,7 @@ macro(add_sesame_example target_name) ) halst_target_default_linker_scripts(${target_name}) - halst_target_default_init(${target_name}) + halst_target_bringup(${target_name}) emil_generate_artifacts(TARGET ${target_name} HEX) diff --git a/hal_st/CMakeLists.txt b/hal_st/CMakeLists.txt index 2329df98..6f1af26e 100644 --- a/hal_st/CMakeLists.txt +++ b/hal_st/CMakeLists.txt @@ -1,6 +1,6 @@ -add_subdirectory(cortex) +add_subdirectory(dwt) add_subdirectory(stm32fxxx) add_subdirectory(synchronous_stm32fxxx) add_subdirectory(middlewares) add_subdirectory(instantiations) -add_subdirectory(default_init) +add_subdirectory(bringup) diff --git a/hal_st/bringup/Assert.cpp b/hal_st/bringup/Assert.cpp new file mode 100644 index 00000000..299550c0 --- /dev/null +++ b/hal_st/bringup/Assert.cpp @@ -0,0 +1,15 @@ +#include +#include + +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(); + } +} diff --git a/hal_st/bringup/Bringup.cpp b/hal_st/bringup/Bringup.cpp new file mode 100644 index 00000000..2700398c --- /dev/null +++ b/hal_st/bringup/Bringup.cpp @@ -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()); + } +} diff --git a/hal_st/bringup/CMakeLists.txt b/hal_st/bringup/CMakeLists.txt new file mode 100644 index 00000000..7621cea3 --- /dev/null +++ b/hal_st/bringup/CMakeLists.txt @@ -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 + "$" + "$" +) + +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 + $ + $ + $ + ) +endfunction() diff --git a/hal_st/cortex/CMakeLists.txt b/hal_st/cortex/CMakeLists.txt deleted file mode 100644 index 2947e3df..00000000 --- a/hal_st/cortex/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -add_library(hal_st.cortex STATIC) -emil_build_for(hal_st.cortex TARGET_MCU_VENDOR st PREREQUISITE_BOOL HALST_STANDALONE) - -target_include_directories(hal_st.cortex PUBLIC - "$" - "$" -) - -target_link_libraries(hal_st.cortex PUBLIC - st.hal_driver - infra.event -) - -target_sources(hal_st.cortex PRIVATE - DataWatchpointAndTrace.hpp - DataWatchpointAndTrace.cpp - InterruptCortex.cpp - InterruptCortex.hpp -) diff --git a/hal_st/cortex/InterruptCortex.cpp b/hal_st/cortex/InterruptCortex.cpp deleted file mode 100644 index 5c467f64..00000000 --- a/hal_st/cortex/InterruptCortex.cpp +++ /dev/null @@ -1,236 +0,0 @@ -#include "hal_st/cortex/InterruptCortex.hpp" -#include "infra/event/EventDispatcher.hpp" -#include - -namespace hal -{ - namespace - { - void EnableInterrupt(IRQn_Type irq, InterruptPriority priority) - { - if (irq >= 0) - { - NVIC_SetPriority(irq, static_cast(priority)); - NVIC_EnableIRQ(irq); - } - else if (irq == -13 /*HardFault_IRQn*/) - ; - else if (irq == NonMaskableInt_IRQn) - ; - else if (irq == PendSV_IRQn) - ; - else if (irq == SysTick_IRQn) - { - NVIC_SetPriority(irq, static_cast(InterruptPriority::Normal)); - SysTick->CTRL |= 1 << 1; - } - else - std::abort(); - } - - void DisableInterrupt(IRQn_Type irq) - { - if (irq >= 0) - { - NVIC_DisableIRQ(irq); - } - else if (irq == -13 /*HardFault_IRQn*/) - ; - else if (irq == NonMaskableInt_IRQn) - ; - else if (irq == PendSV_IRQn) - ; - else if (irq == SysTick_IRQn) - { - SysTick->CTRL &= ~(1 << 1); - SCB->ICSR |= 1 << 25; - } - else - std::abort(); - } - } - - IRQn_Type ActiveInterrupt() - { - return static_cast(((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) >> SCB_ICSR_VECTACTIVE_Pos) - 16); - } - - InterruptHandler::InterruptHandler() - {} - - InterruptHandler::InterruptHandler(InterruptHandler&& other) - : irq(other.irq) - { - if (irq) - InterruptTable::Instance().TakeOverHandler(*irq, *this, other); - - other.irq = std::nullopt; - } - - InterruptHandler& InterruptHandler::operator=(InterruptHandler&& other) - { - if (irq) - InterruptTable::Instance().DeregisterHandler(*irq, *this); - - irq = other.irq; - - if (irq) - InterruptTable::Instance().TakeOverHandler(*irq, *this, other); - - other.irq = std::nullopt; - - return *this; - } - - InterruptHandler::~InterruptHandler() - { - if (irq) - InterruptTable::Instance().DeregisterHandler(*irq, *this); - } - - void InterruptHandler::Register(IRQn_Type irq, InterruptPriority priority) - { - this->irq = irq; - InterruptTable::Instance().RegisterHandler(*this->irq, *this, priority); - } - - void InterruptHandler::Unregister() - { - if (irq) - InterruptTable::Instance().DeregisterHandler(*irq, *this); - - irq = std::nullopt; - } - - IRQn_Type InterruptHandler::Irq() const - { - return *irq; - } - - void InterruptHandler::ClearPending() - { - NVIC_ClearPendingIRQ(*irq); - } - - InterruptTable::InterruptTable(infra::MemoryRange table) - : table(table) - { - std::fill(table.begin(), table.end(), nullptr); - } - - void InterruptTable::Invoke(IRQn_Type irq) - { - __DMB(); - if (!table[irq + 16]) - std::abort(); - - table[irq + 16]->Invoke(); - } - - InterruptHandler* InterruptTable::Handler(IRQn_Type irq) - { - return table[irq + 16]; - } - - void InterruptTable::RegisterHandler(IRQn_Type irq, InterruptHandler& handler, InterruptPriority priority) - { - assert(irq + 16 < table.size()); - assert(table[irq + 16] == nullptr); - table[irq + 16] = &handler; - __DSB(); - EnableInterrupt(irq, priority); - } - - void InterruptTable::DeregisterHandler(IRQn_Type irq, InterruptHandler& handler) - { - assert(table[irq + 16] == &handler); - DisableInterrupt(irq); - __DSB(); - table[irq + 16] = nullptr; - } - - void InterruptTable::TakeOverHandler(IRQn_Type irq, InterruptHandler& handler, const InterruptHandler& previous) - { - assert(table[irq + 16] == &previous); - table[irq + 16] = &handler; - __DSB(); - } - - DispatchedInterruptHandler::DispatchedInterruptHandler(IRQn_Type irq, const infra::Function& onInvoke) - : InterruptHandler() - , onInvoke(onInvoke) - { - Register(irq); - } - - DispatchedInterruptHandler::DispatchedInterruptHandler(DispatchedInterruptHandler&& other, const infra::Function& onInvoke) - : InterruptHandler(std::move(other)) - , onInvoke(onInvoke) - {} - - DispatchedInterruptHandler& DispatchedInterruptHandler::Assign(DispatchedInterruptHandler&& other, const infra::Function& onInvoke) - { - InterruptHandler::operator=(std::move(other)); - this->onInvoke = onInvoke; - return *this; - } - - void DispatchedInterruptHandler::Invoke() - { - DisableInterrupt(Irq()); - assert(!pending); - pending = true; - - IRQn_Type irq = Irq(); - DispatchedInterruptHandler& handler = *this; - infra::EventDispatcher::Instance().Schedule([irq, &handler]() - { - InvokeScheduled(irq, handler); - }); - } - - void DispatchedInterruptHandler::SetInvoke(const infra::Function& onInvoke) - { - this->onInvoke = onInvoke; - } - - void DispatchedInterruptHandler::InvokeScheduled(IRQn_Type irq, DispatchedInterruptHandler& handler) - { - if (InterruptTable::Instance().Handler(irq) == &handler) - { - infra::Function invoke = handler.onInvoke; - invoke(); - - if (InterruptTable::Instance().Handler(irq) == &handler) - { - handler.pending = false; - if (handler.onInvoke) - EnableInterrupt(irq, InterruptPriority::Normal); - } - } - } - - ImmediateInterruptHandler::ImmediateInterruptHandler(IRQn_Type irq, const infra::Function& onInvoke) - : InterruptHandler() - , onInvoke(onInvoke) - { - Register(irq); - } - - ImmediateInterruptHandler::ImmediateInterruptHandler(ImmediateInterruptHandler&& other, const infra::Function& onInvoke) - : InterruptHandler(std::move(other)) - , onInvoke(onInvoke) - {} - - ImmediateInterruptHandler& ImmediateInterruptHandler::Assign(ImmediateInterruptHandler&& other, const infra::Function& onInvoke) - { - InterruptHandler::operator=(std::move(other)); - this->onInvoke = onInvoke; - return *this; - } - - void ImmediateInterruptHandler::Invoke() - { - onInvoke(); - } -} diff --git a/hal_st/cortex/InterruptCortex.hpp b/hal_st/cortex/InterruptCortex.hpp deleted file mode 100644 index da0c68cf..00000000 --- a/hal_st/cortex/InterruptCortex.hpp +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef HAL_INTERRUPT_CORTEX_HPP -#define HAL_INTERRUPT_CORTEX_HPP - -#include DEVICE_HEADER -#include "infra/util/Function.hpp" -#include "infra/util/InterfaceConnector.hpp" -#include "infra/util/MemoryRange.hpp" -#include "infra/util/WithStorage.hpp" -#include -#include - -namespace hal -{ - enum class InterruptPriority : uint8_t - { - High = 1, - Normal = 2 - }; - - IRQn_Type ActiveInterrupt(); - - class InterruptHandler - { - protected: - InterruptHandler(); - InterruptHandler(const InterruptHandler& other) = delete; - InterruptHandler(InterruptHandler&& other); - InterruptHandler& operator=(const InterruptHandler& other) = delete; - InterruptHandler& operator=(InterruptHandler&& other); - ~InterruptHandler(); - - public: - void Register(IRQn_Type irq, InterruptPriority priority = InterruptPriority::Normal); - void Unregister(); - virtual void Invoke() = 0; - - IRQn_Type Irq() const; - - void ClearPending(); - - private: - std::optional irq; - }; - - class InterruptTable - : public infra::InterfaceConnector - { - public: - template - using WithStorage = infra::WithStorage>; - - InterruptTable(infra::MemoryRange table); - - void Invoke(IRQn_Type irq); - InterruptHandler* Handler(IRQn_Type irq); - - private: - friend class InterruptHandler; - - void RegisterHandler(IRQn_Type irq, InterruptHandler& handler, InterruptPriority priority); - void DeregisterHandler(IRQn_Type irq, InterruptHandler& handler); - void TakeOverHandler(IRQn_Type irq, InterruptHandler& handler, const InterruptHandler& previous); - - private: - infra::MemoryRange table; - }; - - class DispatchedInterruptHandler - : public InterruptHandler - { - public: - DispatchedInterruptHandler(IRQn_Type irq, const infra::Function& onInvoke); - DispatchedInterruptHandler(const DispatchedInterruptHandler& other) = delete; - DispatchedInterruptHandler(DispatchedInterruptHandler&& other) = delete; - DispatchedInterruptHandler(DispatchedInterruptHandler&& other, const infra::Function& onInvoke); - DispatchedInterruptHandler& operator=(const DispatchedInterruptHandler& other) = delete; - DispatchedInterruptHandler& operator=(DispatchedInterruptHandler&& other) = delete; - DispatchedInterruptHandler& Assign(DispatchedInterruptHandler&& other, const infra::Function& onInvoke); - - virtual void Invoke() final; - void SetInvoke(const infra::Function& onInvoke); - - private: - static void InvokeScheduled(IRQn_Type irq, DispatchedInterruptHandler& handler); - - private: - infra::Function onInvoke; - bool pending = false; - }; - - class ImmediateInterruptHandler - : public InterruptHandler - { - public: - ImmediateInterruptHandler(IRQn_Type irq, const infra::Function& onInvoke); - ImmediateInterruptHandler(const ImmediateInterruptHandler& other) = delete; - ImmediateInterruptHandler(ImmediateInterruptHandler&& other) = delete; - ImmediateInterruptHandler(ImmediateInterruptHandler&& other, const infra::Function& onInvoke); - ImmediateInterruptHandler& operator=(const ImmediateInterruptHandler& other) = delete; - ImmediateInterruptHandler& operator=(ImmediateInterruptHandler&& other) = delete; - ImmediateInterruptHandler& Assign(ImmediateInterruptHandler&& other, const infra::Function& onInvoke); - - virtual void Invoke() final; - - private: - infra::Function onInvoke; - }; -} - -#endif diff --git a/hal_st/default_init/Atomic.cpp b/hal_st/default_init/Atomic.cpp deleted file mode 100644 index 35e1af08..00000000 --- a/hal_st/default_init/Atomic.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include DEVICE_HEADER - -extern "C" -{ - unsigned char __attribute__((used)) __atomic_exchange_1(volatile void* mem, unsigned char val, int model) - { - __disable_irq(); - __DSB(); - - unsigned char result = *reinterpret_cast(mem); - *reinterpret_cast(mem) = val; - - __DSB(); - __enable_irq(); - - return result; - } - - unsigned int __attribute__((used)) __atomic_exchange_4(volatile void* mem, unsigned int val, int model) - { - __disable_irq(); - __DSB(); - - unsigned int result = *reinterpret_cast(mem); - *reinterpret_cast(mem) = val; - - __DSB(); - __enable_irq(); - - return result; - } - - bool __attribute__((used)) __atomic_compare_exchange_4(volatile void* mem, void* expected, unsigned int desired, bool weak, int success, int failure) - { - __disable_irq(); - __DSB(); - - if (*reinterpret_cast(mem) == *reinterpret_cast(expected)) - { - *reinterpret_cast(mem) = desired; - __DSB(); - __enable_irq(); - return true; - } - else - { - *reinterpret_cast(expected) = *reinterpret_cast(mem); - __enable_irq(); - return false; - } - } - - unsigned int __attribute__((used)) __atomic_fetch_add_4(volatile void* mem, unsigned int val, int model) - { - __disable_irq(); - __DSB(); - - uint32_t previous = *reinterpret_cast(mem); - *reinterpret_cast(mem) += val; - - __DSB(); - __enable_irq(); - - return previous; - } -} diff --git a/hal_st/default_init/CMakeLists.txt b/hal_st/default_init/CMakeLists.txt deleted file mode 100644 index 28befe64..00000000 --- a/hal_st/default_init/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_library(hal_st.default_init STATIC) -emil_build_for(hal_st.default_init TARGET_MCU_VENDOR st PREREQUISITE_BOOL HALST_STANDALONE) - -target_include_directories(hal_st.default_init PUBLIC - "$" - "$" -) - -target_link_libraries(hal_st.default_init PUBLIC - st.hal_driver - hal_st.cortex -) - -# Assembler does not understand -Werror -set_target_properties(hal_st.default_init PROPERTIES COMPILE_WARNING_AS_ERROR Off) - -target_sources(hal_st.default_init PRIVATE - $<$:Atomic.cpp> - DefaultInit.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.default_init PRIVATE - ${startup_source} - ) -endif() - -function(halst_target_default_init target) - target_link_libraries(${target} PUBLIC - $ - ) -endfunction() diff --git a/hal_st/default_init/DefaultInit.cpp b/hal_st/default_init/DefaultInit.cpp deleted file mode 100644 index 15c1bf9b..00000000 --- a/hal_st/default_init/DefaultInit.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include DEVICE_HEADER -#include "hal_st/cortex/InterruptCortex.hpp" -#include -#include - -extern "C" -{ - extern char _Heap_Begin; - extern char _Heap_Limit; - - caddr_t _sbrk(int incr) - { - static char* current_heap_end = &_Heap_Begin; - - char* current_block_address = current_heap_end; - - incr = (incr + 3) & (~3); - if (current_heap_end + incr > &_Heap_Limit) - { - errno = ENOMEM; - return reinterpret_cast(-1); - } - - current_heap_end += incr; - - return static_cast(current_block_address); - } - - // 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::InterruptTable::Instance().Invoke(hal::ActiveInterrupt()); - } - - [[gnu::weak]] void abort() - { - __BKPT(); - HAL_NVIC_SystemReset(); - __builtin_unreachable(); - } - - void _init() - {} - - void __assert_func(const char*, int, const char*, const char*) - { - std::abort(); - } - - void assert_failed(uint8_t* file, uint32_t line) - { - std::abort(); - } -} diff --git a/hal_st/dwt/CMakeLists.txt b/hal_st/dwt/CMakeLists.txt new file mode 100644 index 00000000..5af41881 --- /dev/null +++ b/hal_st/dwt/CMakeLists.txt @@ -0,0 +1,17 @@ +add_library(hal_st.dwt STATIC) +emil_build_for(hal_st.dwt TARGET_MCU_VENDOR st PREREQUISITE_BOOL HALST_STANDALONE) + +target_include_directories(hal_st.dwt PUBLIC + "$" + "$" +) + +target_link_libraries(hal_st.dwt PUBLIC + st.hal_driver + infra.util +) + +target_sources(hal_st.dwt PRIVATE + DataWatchpointAndTrace.hpp + DataWatchpointAndTrace.cpp +) diff --git a/hal_st/cortex/DataWatchpointAndTrace.cpp b/hal_st/dwt/DataWatchpointAndTrace.cpp similarity index 92% rename from hal_st/cortex/DataWatchpointAndTrace.cpp rename to hal_st/dwt/DataWatchpointAndTrace.cpp index c3b47b7d..7e21e66c 100644 --- a/hal_st/cortex/DataWatchpointAndTrace.cpp +++ b/hal_st/dwt/DataWatchpointAndTrace.cpp @@ -1,4 +1,4 @@ -#include "hal_st/cortex/DataWatchpointAndTrace.hpp" +#include "hal_st/dwt/DataWatchpointAndTrace.hpp" #if defined(__CORTEX_M) && (__CORTEX_M == 4) diff --git a/hal_st/cortex/DataWatchpointAndTrace.hpp b/hal_st/dwt/DataWatchpointAndTrace.hpp similarity index 100% rename from hal_st/cortex/DataWatchpointAndTrace.hpp rename to hal_st/dwt/DataWatchpointAndTrace.hpp diff --git a/hal_st/instantiations/StmEventInfrastructure.hpp b/hal_st/instantiations/StmEventInfrastructure.hpp index 207839a3..de00f1fb 100644 --- a/hal_st/instantiations/StmEventInfrastructure.hpp +++ b/hal_st/instantiations/StmEventInfrastructure.hpp @@ -24,7 +24,7 @@ namespace main_ void Run(); - hal::InterruptTable::WithStorage interruptTable; + hal::cortex::InterruptTable::WithStorage interruptTable; infra::EventDispatcherWithWeakPtr::WithSize<50> eventDispatcher; hal::GpioStm gpio; @@ -37,7 +37,7 @@ namespace main_ void Run(); - hal::InterruptTable::WithStorage interruptTable; + hal::cortex::InterruptTable::WithStorage interruptTable; hal::LowPowerStrategyStm lowPowerStrategy; infra::LowPowerEventDispatcher::WithSize<50> eventDispatcher; hal::GpioStm gpio; diff --git a/hal_st/stm32fxxx/AnalogToDigitalPinStm.cpp b/hal_st/stm32fxxx/AnalogToDigitalPinStm.cpp index db18aee3..daa5891c 100644 --- a/hal_st/stm32fxxx/AnalogToDigitalPinStm.cpp +++ b/hal_st/stm32fxxx/AnalogToDigitalPinStm.cpp @@ -1,6 +1,6 @@ #include "hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp" #include "generated/stm32fxxx/PeripheralTable.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/GpioStm.hpp" #include "infra/event/EventDispatcher.hpp" #include "infra/util/Function.hpp" diff --git a/hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp b/hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp index 33822480..b5c3473d 100644 --- a/hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp +++ b/hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp @@ -2,7 +2,7 @@ #define HAL_ANALOG_TO_DIGITAL_PIN_STM_HPP #include "hal/interfaces/AnalogToDigitalPin.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/GpioStm.hpp" #include "infra/util/AutoResetFunction.hpp" #include "infra/util/Function.hpp" @@ -94,7 +94,7 @@ namespace hal uint8_t index; ADC_HandleTypeDef handle{}; - DispatchedInterruptHandler interruptHandler; + cortex::DispatchedInterruptHandler interruptHandler; uint16_t sample; infra::AutoResetFunction)> onDone; }; diff --git a/hal_st/stm32fxxx/CMakeLists.txt b/hal_st/stm32fxxx/CMakeLists.txt index 79d3d747..d5305867 100644 --- a/hal_st/stm32fxxx/CMakeLists.txt +++ b/hal_st/stm32fxxx/CMakeLists.txt @@ -13,7 +13,7 @@ target_link_libraries(hal_st.stm32fxxx PUBLIC services.crypto services.flash st.hal_driver - hal_st.cortex + hal.cortex_m $<$:hal_st.stm32_wpan> ) diff --git a/hal_st/stm32fxxx/CanStm.hpp b/hal_st/stm32fxxx/CanStm.hpp index 56594774..44206fdf 100644 --- a/hal_st/stm32fxxx/CanStm.hpp +++ b/hal_st/stm32fxxx/CanStm.hpp @@ -4,7 +4,7 @@ #include DEVICE_HEADER #include "generated/stm32fxxx/PeripheralTable.hpp" #include "hal/interfaces/Can.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/GpioStm.hpp" #if defined(HAS_PERIPHERAL_CAN) @@ -44,9 +44,9 @@ namespace hal infra::Function onMessageSent; infra::Function onMessageReceived; - DispatchedInterruptHandler canTxInterruptDispatcher; - DispatchedInterruptHandler canRxInterruptDispatcher; - DispatchedInterruptHandler canErrorInterruptDispatcher; + cortex::DispatchedInterruptHandler canTxInterruptDispatcher; + cortex::DispatchedInterruptHandler canRxInterruptDispatcher; + cortex::DispatchedInterruptHandler canErrorInterruptDispatcher; }; } diff --git a/hal_st/stm32fxxx/DmaStm.cpp b/hal_st/stm32fxxx/DmaStm.cpp index dc52b1bf..5ad3d5ab 100644 --- a/hal_st/stm32fxxx/DmaStm.cpp +++ b/hal_st/stm32fxxx/DmaStm.cpp @@ -1,5 +1,5 @@ #include "hal_st/stm32fxxx/DmaStm.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/util/ByteRange.hpp" #include @@ -878,11 +878,11 @@ namespace hal DmaStm::StreamInterruptHandler::StreamInterruptHandler(Stream& stream, const infra::Function& transferFullComplete, Dispatched) : stream{ stream } - , interruptHandler{ std::in_place_type, dmaIrq[stream.dmaIndex][stream.streamIndex], [this] + , interruptHandler{ std::in_place_type, dmaIrq[stream.dmaIndex][stream.streamIndex], [this] { OnInterrupt(); } } - , interruptHandlerHandle{ &std::get(interruptHandler) } + , interruptHandlerHandle{ &std::get(interruptHandler) } , transferFullComplete{ transferFullComplete } { stream.DisableCircularMode(); @@ -891,11 +891,11 @@ namespace hal DmaStm::StreamInterruptHandler::StreamInterruptHandler(Stream& stream, const infra::Function& transferFullComplete, Immediate) : stream{ stream } - , interruptHandler{ std::in_place_type, dmaIrq[stream.dmaIndex][stream.streamIndex], [this] + , interruptHandler{ std::in_place_type, dmaIrq[stream.dmaIndex][stream.streamIndex], [this] { OnInterrupt(); } } - , interruptHandlerHandle{ &std::get(interruptHandler) } + , interruptHandlerHandle{ &std::get(interruptHandler) } , transferFullComplete{ transferFullComplete } { stream.DisableCircularMode(); diff --git a/hal_st/stm32fxxx/DmaStm.hpp b/hal_st/stm32fxxx/DmaStm.hpp index 4834e80a..fbfaca57 100644 --- a/hal_st/stm32fxxx/DmaStm.hpp +++ b/hal_st/stm32fxxx/DmaStm.hpp @@ -1,7 +1,7 @@ #ifndef HAL_DMA_STM_HPP #define HAL_DMA_STM_HPP -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/util/ByteRange.hpp" #include "infra/util/Function.hpp" #include "infra/util/MemoryRange.hpp" @@ -211,8 +211,8 @@ namespace hal Stream& stream; - std::variant interruptHandler; - InterruptHandler* interruptHandlerHandle; + std::variant interruptHandler; + cortex::InterruptHandler* interruptHandlerHandle; infra::Function transferFullComplete; }; @@ -229,7 +229,7 @@ namespace hal Stream& stream; - ImmediateInterruptHandler immediateInterruptHandler; + cortex::ImmediateInterruptHandler immediateInterruptHandler; infra::Function transferHalfComplete; infra::Function transferFullComplete; diff --git a/hal_st/stm32fxxx/EthernetMacStm.hpp b/hal_st/stm32fxxx/EthernetMacStm.hpp index d4357efe..f7b9d582 100644 --- a/hal_st/stm32fxxx/EthernetMacStm.hpp +++ b/hal_st/stm32fxxx/EthernetMacStm.hpp @@ -4,7 +4,7 @@ #include DEVICE_HEADER #include "generated/stm32fxxx/PeripheralTable.hpp" #include "hal/interfaces/Ethernet.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include #if defined(HAS_PERIPHERAL_ETHERNET) @@ -75,7 +75,7 @@ namespace hal private: EthernetSmi& ethernetSmi; MacAddress macAddress; - DispatchedInterruptHandler interrupt; + cortex::DispatchedInterruptHandler interrupt; ReceiveDescriptors receiveDescriptors; SendDescriptors sendDescriptors; diff --git a/hal_st/stm32fxxx/FlashInternalHighCycleAreaStm.hpp b/hal_st/stm32fxxx/FlashInternalHighCycleAreaStm.hpp index e23102d2..0c5e3019 100644 --- a/hal_st/stm32fxxx/FlashInternalHighCycleAreaStm.hpp +++ b/hal_st/stm32fxxx/FlashInternalHighCycleAreaStm.hpp @@ -4,7 +4,7 @@ #include DEVICE_HEADER #include "hal/interfaces/Flash.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/util/MemoryRange.hpp" #include @@ -42,7 +42,7 @@ namespace hal WithIrqHandler(uint32_t bank = FLASH_BANK_2); private: - hal::ImmediateInterruptHandler nmi; + hal::cortex::ImmediateInterruptHandler nmi; }; } diff --git a/hal_st/stm32fxxx/FlashInternalStmBle.hpp b/hal_st/stm32fxxx/FlashInternalStmBle.hpp index c3a10f66..4dd46de1 100644 --- a/hal_st/stm32fxxx/FlashInternalStmBle.hpp +++ b/hal_st/stm32fxxx/FlashInternalStmBle.hpp @@ -2,7 +2,7 @@ #ifndef HAL_FLASH_INTERNAL_STM_BLE_HPP #define HAL_FLASH_INTERNAL_STM_BLE_HPP -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/FlashInternalStm.hpp" #include "hal_st/stm32fxxx/WatchDogStm.hpp" #include "services/flash/FlashAlign.hpp" @@ -49,8 +49,8 @@ namespace hal static constexpr uint32_t hwBlockFlashReqByCpu2 = 7; infra::ConstByteRange flashMemory; WatchDogStm& watchdog; - ImmediateInterruptHandler hwSemInterruptHandler; - ImmediateInterruptHandler nmiHandler; + cortex::ImmediateInterruptHandler hwSemInterruptHandler; + cortex::ImmediateInterruptHandler nmiHandler; infra::Function onHwSemaphoreAvailable; services::FlashAlign::WithAlignment flashAlign; diff --git a/hal_st/stm32fxxx/GpioStm.cpp b/hal_st/stm32fxxx/GpioStm.cpp index aa62b06e..4606b6ee 100644 --- a/hal_st/stm32fxxx/GpioStm.cpp +++ b/hal_st/stm32fxxx/GpioStm.cpp @@ -1,6 +1,6 @@ #include "hal_st/stm32fxxx/GpioStm.hpp" #include "hal/interfaces/Gpio.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/event/EventDispatcher.hpp" #include "infra/util/BitLogic.hpp" #include "infra/util/Function.hpp" diff --git a/hal_st/stm32fxxx/GpioStm.hpp b/hal_st/stm32fxxx/GpioStm.hpp index 6358380c..6766707f 100644 --- a/hal_st/stm32fxxx/GpioStm.hpp +++ b/hal_st/stm32fxxx/GpioStm.hpp @@ -2,7 +2,7 @@ #define HAL_GPIO_STM_HPP #include "hal/interfaces/Gpio.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/util/Function.hpp" #include "infra/util/InterfaceConnector.hpp" #include "infra/util/MemoryRange.hpp" @@ -312,30 +312,30 @@ namespace hal std::array assignedPins; #if defined(STM32F0) || defined(STM32G0) - ImmediateInterruptHandler interruptDispatcher0_1; - ImmediateInterruptHandler interruptDispatcher2_3; - ImmediateInterruptHandler interruptDispatcher4_15; + cortex::ImmediateInterruptHandler interruptDispatcher0_1; + cortex::ImmediateInterruptHandler interruptDispatcher2_3; + cortex::ImmediateInterruptHandler interruptDispatcher4_15; #else - ImmediateInterruptHandler interruptDispatcher0; - ImmediateInterruptHandler interruptDispatcher1; - ImmediateInterruptHandler interruptDispatcher2; - ImmediateInterruptHandler interruptDispatcher3; - ImmediateInterruptHandler interruptDispatcher4; + cortex::ImmediateInterruptHandler interruptDispatcher0; + cortex::ImmediateInterruptHandler interruptDispatcher1; + cortex::ImmediateInterruptHandler interruptDispatcher2; + cortex::ImmediateInterruptHandler interruptDispatcher3; + cortex::ImmediateInterruptHandler interruptDispatcher4; #if defined(STM32WBA) || defined(STM32H5) - ImmediateInterruptHandler interruptDispatcher5; - ImmediateInterruptHandler interruptDispatcher6; - ImmediateInterruptHandler interruptDispatcher7; - ImmediateInterruptHandler interruptDispatcher8; - ImmediateInterruptHandler interruptDispatcher9; - ImmediateInterruptHandler interruptDispatcher10; - ImmediateInterruptHandler interruptDispatcher11; - ImmediateInterruptHandler interruptDispatcher12; - ImmediateInterruptHandler interruptDispatcher13; - ImmediateInterruptHandler interruptDispatcher14; - ImmediateInterruptHandler interruptDispatcher15; + cortex::ImmediateInterruptHandler interruptDispatcher5; + cortex::ImmediateInterruptHandler interruptDispatcher6; + cortex::ImmediateInterruptHandler interruptDispatcher7; + cortex::ImmediateInterruptHandler interruptDispatcher8; + cortex::ImmediateInterruptHandler interruptDispatcher9; + cortex::ImmediateInterruptHandler interruptDispatcher10; + cortex::ImmediateInterruptHandler interruptDispatcher11; + cortex::ImmediateInterruptHandler interruptDispatcher12; + cortex::ImmediateInterruptHandler interruptDispatcher13; + cortex::ImmediateInterruptHandler interruptDispatcher14; + cortex::ImmediateInterruptHandler interruptDispatcher15; #else - ImmediateInterruptHandler interruptDispatcher9_5; - ImmediateInterruptHandler interruptDispatcher15_10; + cortex::ImmediateInterruptHandler interruptDispatcher9_5; + cortex::ImmediateInterruptHandler interruptDispatcher15_10; #endif #endif }; diff --git a/hal_st/stm32fxxx/I2cStm.hpp b/hal_st/stm32fxxx/I2cStm.hpp index aa7413a8..726e640e 100644 --- a/hal_st/stm32fxxx/I2cStm.hpp +++ b/hal_st/stm32fxxx/I2cStm.hpp @@ -3,7 +3,7 @@ #include DEVICE_HEADER #include "hal/interfaces/I2c.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/GpioStm.hpp" #include "infra/util/AutoResetFunction.hpp" @@ -49,8 +49,8 @@ namespace hal hal::PeripheralPinStm scl; hal::PeripheralPinStm sda; - ImmediateInterruptHandler evInterruptHandler; - DispatchedInterruptHandler erInterruptHandler; + cortex::ImmediateInterruptHandler evInterruptHandler; + cortex::DispatchedInterruptHandler erInterruptHandler; I2C_HandleTypeDef i2cHandle; diff --git a/hal_st/stm32fxxx/LpTimerStm.hpp b/hal_st/stm32fxxx/LpTimerStm.hpp index 2ac61c64..35332834 100644 --- a/hal_st/stm32fxxx/LpTimerStm.hpp +++ b/hal_st/stm32fxxx/LpTimerStm.hpp @@ -3,7 +3,7 @@ #include "generated/stm32fxxx/PeripheralTable.hpp" #include "hal/interfaces/Gpio.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/util/Function.hpp" #include #include DEVICE_HEADER @@ -60,7 +60,7 @@ namespace hal void Stop(); private: - ImmediateInterruptHandler interruptHandler; + cortex::ImmediateInterruptHandler interruptHandler; infra::Function onIrq; InterruptType type; std::atomic_bool scheduled{}; diff --git a/hal_st/stm32fxxx/PkaStm.cpp b/hal_st/stm32fxxx/PkaStm.cpp index 8a43c615..c6de13c6 100644 --- a/hal_st/stm32fxxx/PkaStm.cpp +++ b/hal_st/stm32fxxx/PkaStm.cpp @@ -84,7 +84,7 @@ namespace namespace hal { PkaStm::PkaStm() - : DispatchedInterruptHandler(peripheralPkaIrq[pkaIndex], [this]() + : cortex::DispatchedInterruptHandler(peripheralPkaIrq[pkaIndex], [this]() { // Workaround: PKA triggers two interrupts: one when the operation is done and another one when the peripheral is released. if (!(peripheralPka[pkaIndex]->SR & pkaInterruptStatusFlags)) diff --git a/hal_st/stm32fxxx/PkaStm.hpp b/hal_st/stm32fxxx/PkaStm.hpp index 8587eae8..e3d4a8e4 100644 --- a/hal_st/stm32fxxx/PkaStm.hpp +++ b/hal_st/stm32fxxx/PkaStm.hpp @@ -2,7 +2,7 @@ #define HAL_PKA_STM_HPP #include "generated/stm32fxxx/PeripheralTable.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/util/Function.hpp" #include "services/crypto/EllipticCurve.hpp" @@ -12,7 +12,7 @@ namespace hal { class PkaStm : public services::EllipticCurveOperations - , protected hal::DispatchedInterruptHandler + , protected hal::cortex::DispatchedInterruptHandler { public: PkaStm(); diff --git a/hal_st/stm32fxxx/QuadSpiStmDma.hpp b/hal_st/stm32fxxx/QuadSpiStmDma.hpp index 632ae00b..d323ab61 100644 --- a/hal_st/stm32fxxx/QuadSpiStmDma.hpp +++ b/hal_st/stm32fxxx/QuadSpiStmDma.hpp @@ -3,7 +3,7 @@ #include "generated/stm32fxxx/PeripheralTable.hpp" #include "hal/interfaces/QuadSpi.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/DmaStm.hpp" #include "hal_st/stm32fxxx/GpioStm.hpp" #include "infra/util/AutoResetFunction.hpp" @@ -53,7 +53,7 @@ namespace hal infra::AutoResetFunction onDone; hal::TransceiverDmaChannel dmaStream; - DispatchedInterruptHandler interruptHandler; + cortex::DispatchedInterruptHandler interruptHandler; }; } diff --git a/hal_st/stm32fxxx/RandomDataGeneratorStm.hpp b/hal_st/stm32fxxx/RandomDataGeneratorStm.hpp index a1434b46..89ad4666 100644 --- a/hal_st/stm32fxxx/RandomDataGeneratorStm.hpp +++ b/hal_st/stm32fxxx/RandomDataGeneratorStm.hpp @@ -2,7 +2,7 @@ #define HAL_RANDOM_DATA_GENERATOR_STM_HPP #include "hal/interfaces/RandomDataGenerator.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #if defined(HAS_PERIPHERAL_RNG) @@ -10,7 +10,7 @@ namespace hal { class RandomDataGeneratorStm : public RandomDataGenerator - , private InterruptHandler + , private cortex::InterruptHandler { public: RandomDataGeneratorStm(); diff --git a/hal_st/stm32fxxx/SpiMasterStm.hpp b/hal_st/stm32fxxx/SpiMasterStm.hpp index 6819d130..e917730f 100644 --- a/hal_st/stm32fxxx/SpiMasterStm.hpp +++ b/hal_st/stm32fxxx/SpiMasterStm.hpp @@ -2,7 +2,7 @@ #define HAL_SPI_MASTER_STM_HPP #include "hal/interfaces/Spi.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/GpioStm.hpp" #include "infra/util/AutoResetFunction.hpp" @@ -44,7 +44,7 @@ namespace hal infra::AutoResetFunction onDone; ChipSelectConfigurator* chipSelectConfigurator = nullptr; CommunicationConfigurator* communicationConfigurator = nullptr; - std::optional spiInterruptRegistration; + std::optional spiInterruptRegistration; infra::ConstByteRange sendData; infra::ByteRange receiveData; bool sending; diff --git a/hal_st/stm32fxxx/SystemTickStm.hpp b/hal_st/stm32fxxx/SystemTickStm.hpp index e7a5d16f..bc5af9a2 100644 --- a/hal_st/stm32fxxx/SystemTickStm.hpp +++ b/hal_st/stm32fxxx/SystemTickStm.hpp @@ -1,13 +1,13 @@ #ifndef HAL_ST_SYSTEM_TICK_STM_HPP #define HAL_ST_SYSTEM_TICK_STM_HPP -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/timer/Timer.hpp" namespace hal { class SystemTickStm - : private InterruptHandler + : private cortex::InterruptHandler { public: SystemTickStm(const infra::Function& callback, infra::Duration tickDuration = std::chrono::milliseconds(1)); diff --git a/hal_st/stm32fxxx/SystemTickTimerService.hpp b/hal_st/stm32fxxx/SystemTickTimerService.hpp index bf717e12..8d7da184 100644 --- a/hal_st/stm32fxxx/SystemTickTimerService.hpp +++ b/hal_st/stm32fxxx/SystemTickTimerService.hpp @@ -1,7 +1,7 @@ #ifndef HAL_ST_SYSTEM_TICK_TIMER_SERVICE_HPP #define HAL_ST_SYSTEM_TICK_TIMER_SERVICE_HPP -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/timer/TickOnInterruptTimerService.hpp" #include "infra/timer/Timer.hpp" #include "infra/util/InterfaceConnector.hpp" @@ -13,7 +13,7 @@ namespace hal class SystemTickTimerService : public infra::InterfaceConnector , public infra::TickOnInterruptTimerService - , private InterruptHandler + , private cortex::InterruptHandler { public: SystemTickTimerService(infra::Duration tickDuration = std::chrono::milliseconds(1), uint32_t id = infra::systemTimerServiceId); diff --git a/hal_st/stm32fxxx/TamperStm.hpp b/hal_st/stm32fxxx/TamperStm.hpp index e5823610..77ab3d88 100644 --- a/hal_st/stm32fxxx/TamperStm.hpp +++ b/hal_st/stm32fxxx/TamperStm.hpp @@ -1,7 +1,7 @@ #ifndef HAL_TAMPER_STM_HPP #define HAL_TAMPER_STM_HPP -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/RtcStm.hpp" #include "infra/util/Function.hpp" #include DEVICE_HEADER @@ -21,7 +21,7 @@ namespace hal const uint8_t tamperInIndex; const uint8_t tamperOutIndex; infra::Function onTamperIrq; - ImmediateInterruptHandler interruptHandler; + cortex::ImmediateInterruptHandler interruptHandler; }; } #endif // HAL_TAMPER_STM_HPP diff --git a/hal_st/stm32fxxx/TimerStm.hpp b/hal_st/stm32fxxx/TimerStm.hpp index 69709ac5..7ac852b4 100644 --- a/hal_st/stm32fxxx/TimerStm.hpp +++ b/hal_st/stm32fxxx/TimerStm.hpp @@ -3,7 +3,7 @@ #include "generated/stm32fxxx/PeripheralTable.hpp" #include "hal/interfaces/Gpio.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/util/Function.hpp" #include #include @@ -87,7 +87,7 @@ namespace hal void Stop(); private: - ImmediateInterruptHandler interruptHandler; + cortex::ImmediateInterruptHandler interruptHandler; infra::Function onIrq; InterruptType type; std::atomic_bool scheduled{}; diff --git a/hal_st/stm32fxxx/UartStm.hpp b/hal_st/stm32fxxx/UartStm.hpp index d79ce82b..91a44755 100644 --- a/hal_st/stm32fxxx/UartStm.hpp +++ b/hal_st/stm32fxxx/UartStm.hpp @@ -3,7 +3,7 @@ #include "generated/stm32fxxx/PeripheralTable.hpp" #include "hal/interfaces/SerialCommunication.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/GpioStm.hpp" #include "infra/util/ByteRange.hpp" #include "infra/util/Function.hpp" @@ -25,7 +25,7 @@ namespace hal { uint32_t baudrate{ 115200 }; uint32_t parity{ USART_PARITY_NONE }; - InterruptPriority priority{ InterruptPriority::Normal }; + cortex::InterruptPriority priority{ cortex::InterruptPriority::normal }; #if defined(UART_ADVFEATURE_SWAP_INIT) bool swapTxRx{ false }; @@ -35,7 +35,7 @@ namespace hal class UartStm : public SerialCommunication - , private InterruptHandler + , private cortex::InterruptHandler { public: using Config = detail::UartStmConfig; diff --git a/hal_st/stm32fxxx/UartStmDuplexDma.hpp b/hal_st/stm32fxxx/UartStmDuplexDma.hpp index 84cc97b5..a21cb968 100644 --- a/hal_st/stm32fxxx/UartStmDuplexDma.hpp +++ b/hal_st/stm32fxxx/UartStmDuplexDma.hpp @@ -43,7 +43,7 @@ namespace hal void FullReceiveComplete(); void ReceiveComplete(size_t currentPosition); - // Implementation InterruptHandler + // Implementation cortex::InterruptHandler void Invoke() override; private: diff --git a/hal_st/stm32fxxx/UsbHostLinkLayerStm.hpp b/hal_st/stm32fxxx/UsbHostLinkLayerStm.hpp index 01d079f4..a6ada159 100644 --- a/hal_st/stm32fxxx/UsbHostLinkLayerStm.hpp +++ b/hal_st/stm32fxxx/UsbHostLinkLayerStm.hpp @@ -5,7 +5,7 @@ #include "infra/util/AutoResetFunction.hpp" #include "generated/stm32fxxx/PeripheralTable.hpp" #include "hal/interfaces/UsbLinkLayer.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/GpioStm.hpp" #include "infra/util/InterfaceConnector.hpp" #include @@ -23,7 +23,7 @@ namespace hal bool externalVBus{ true }; bool useDma{ false }; uint32_t speed{ HCD_SPEED_HIGH }; - InterruptPriority priority{ InterruptPriority::Normal }; + cortex::InterruptPriority priority{ cortex::InterruptPriority::normal }; }; } @@ -142,7 +142,7 @@ namespace hal std::variant pins; HCD_HandleTypeDef hcd; std::array channelCallbacks; - std::array, 4> immediateInterruptHandler; + std::array, 4> immediateInterruptHandler; std::array receptionBuffer __attribute__((aligned(4))); }; } diff --git a/hal_st/stm32fxxx/WatchDogStm.hpp b/hal_st/stm32fxxx/WatchDogStm.hpp index ae6cf184..2be85f9a 100644 --- a/hal_st/stm32fxxx/WatchDogStm.hpp +++ b/hal_st/stm32fxxx/WatchDogStm.hpp @@ -2,7 +2,7 @@ #define HAL_WATCHDOG_STM_HPP #include DEVICE_HEADER -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "infra/timer/Timer.hpp" #include @@ -33,7 +33,7 @@ namespace hal private: void Feed(); - ImmediateInterruptHandler interruptRegistration; + cortex::ImmediateInterruptHandler interruptRegistration; infra::TimerRepeating feedingTimer; WWDG_HandleTypeDef handle; std::atomic delay{ 0 }; diff --git a/hal_st/synchronous_stm32fxxx/SynchronousUartStm.hpp b/hal_st/synchronous_stm32fxxx/SynchronousUartStm.hpp index 4ebba910..720fbd55 100644 --- a/hal_st/synchronous_stm32fxxx/SynchronousUartStm.hpp +++ b/hal_st/synchronous_stm32fxxx/SynchronousUartStm.hpp @@ -3,7 +3,7 @@ #include "hal/synchronous_interfaces/SynchronousSerialCommunication.hpp" #include "hal/synchronous_interfaces/TimeKeeper.hpp" -#include "hal_st/cortex/InterruptCortex.hpp" +#include "hal/cortex_m/InterruptCortex.hpp" #include "hal_st/stm32fxxx/GpioStm.hpp" #include "infra/util/WithStorage.hpp" #include @@ -18,7 +18,7 @@ namespace hal #endif class SynchronousUartStm : public SynchronousSerialCommunication - , private InterruptHandler + , private cortex::InterruptHandler { public: enum HwFlowControl : uint32_t diff --git a/integration_test/tested/CMakeLists.txt b/integration_test/tested/CMakeLists.txt index 708329ab..490b2574 100644 --- a/integration_test/tested/CMakeLists.txt +++ b/integration_test/tested/CMakeLists.txt @@ -17,4 +17,4 @@ target_link_libraries(integration_test.tested PRIVATE emil_generate_artifacts(TARGET integration_test.tested BIN) halst_target_default_linker_scripts(integration_test.tested) -halst_target_default_init(integration_test.tested) +halst_target_bringup(integration_test.tested) diff --git a/integration_test/tester/CMakeLists.txt b/integration_test/tester/CMakeLists.txt index 4213bae1..1af2b962 100644 --- a/integration_test/tester/CMakeLists.txt +++ b/integration_test/tester/CMakeLists.txt @@ -19,4 +19,4 @@ target_link_libraries(integration_test.tester PRIVATE emil_generate_artifacts(TARGET integration_test.tester BIN) halst_target_default_linker_scripts(integration_test.tester) -halst_target_default_init(integration_test.tester) +halst_target_bringup(integration_test.tester) diff --git a/st/ldscripts/sections.ld b/st/ldscripts/sections.ld index ab4b1195..71f945f6 100644 --- a/st/ldscripts/sections.ld +++ b/st/ldscripts/sections.ld @@ -122,6 +122,7 @@ SECTIONS } >RAM PROVIDE(__end__ = _end_noinit); + PROVIDE(end = _end_noinit); MAPPING_TABLE (NOLOAD) : { *(MAPPING_TABLE) } >RAM_SHARED MB_MEM1 (NOLOAD) : { *(MB_MEM1) } >RAM_SHARED From ef0e4e75d5fe9a391a302f49d1aab3245ecfd26b Mon Sep 17 00:00:00 2001 From: Gabriel Santos Date: Tue, 25 Aug 2026 14:04:59 +0000 Subject: [PATCH 2/5] chore: add Claude Code project config (AGENTS.md, CLAUDE.md, .claude/settings.json) Ignore .claude/scheduled_tasks.lock, which is session-local runtime state. Co-Authored-By: Claude Sonnet 5 --- .claude/settings.json | 7 +++++ .gitignore | 1 + AGENTS.md | 72 +++++++++++++++++++++++++++++++++++++++++++ CLAUDE.md | 12 ++++++++ 4 files changed, 92 insertions(+) create mode 100644 .claude/settings.json create mode 100644 AGENTS.md create mode 100644 CLAUDE.md diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 00000000..8a692c73 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,7 @@ +{ + "permissions": { + "allow": [ + "Bash(*)" + ] + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4fe499e0..8474287d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ out/ megalinter-reports/ install/ .megalinter_github_conf +.claude/scheduled_tasks.lock diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..b08e412f --- /dev/null +++ b/AGENTS.md @@ -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`, `infra::BoundedString`, `infra::BoundedDeque`, `infra::MemoryRange` (buffer params, not raw pointer+size), `std::array`, `std::optional`. + +## 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` 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 diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..66f0a140 --- /dev/null +++ b/CLAUDE.md @@ -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. From 0e34c27db3aba3938a3004ab918d5df78313bca3 Mon Sep 17 00:00:00 2001 From: Gabriel Santos Date: Tue, 25 Aug 2026 14:14:16 +0000 Subject: [PATCH 3/5] fix: only enable EMIL_BUILD_CORTEX_M for ST cross-compiles 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 --- CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b60dc8f9..858fcfdd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,13 @@ if (HALST_STANDALONE) set(EMIL_ENABLE_DOCKER_TOOLS Off CACHE BOOL "" FORCE) set(EMIL_BUILD_ECHO_COMPILERS On CACHE BOOL "" FORCE) - set(EMIL_BUILD_CORTEX_M On CACHE BOOL "" FORCE) + + # hal.cortex_m.runtime contains ARM-only inline assembly; only build it when actually + # cross-compiling for an ST target, not for the host toolchain (TARGET_MCU_VENDOR is + # unset there). + if (TARGET_MCU_VENDOR STREQUAL st) + set(EMIL_BUILD_CORTEX_M On CACHE BOOL "" FORCE) + endif() FetchContent_MakeAvailable(emil) From 40cd3d57f6824bffba737e8ac0aaa6f54e86d20b Mon Sep 17 00:00:00 2001 From: Gabriel Santos Date: Tue, 25 Aug 2026 17:04:40 +0000 Subject: [PATCH 4/5] feat: remove DWT module, superseded by emil's implementation DataWatchPointAndTrace has been contributed upstream to embedded-infra-lib (emil); hal_st no longer needs its own copy. Co-Authored-By: Claude Sonnet 5 --- hal_st/CMakeLists.txt | 1 - hal_st/dwt/CMakeLists.txt | 17 -------------- hal_st/dwt/DataWatchpointAndTrace.cpp | 32 --------------------------- hal_st/dwt/DataWatchpointAndTrace.hpp | 22 ------------------ 4 files changed, 72 deletions(-) delete mode 100644 hal_st/dwt/CMakeLists.txt delete mode 100644 hal_st/dwt/DataWatchpointAndTrace.cpp delete mode 100644 hal_st/dwt/DataWatchpointAndTrace.hpp diff --git a/hal_st/CMakeLists.txt b/hal_st/CMakeLists.txt index 6f1af26e..e70313ad 100644 --- a/hal_st/CMakeLists.txt +++ b/hal_st/CMakeLists.txt @@ -1,4 +1,3 @@ -add_subdirectory(dwt) add_subdirectory(stm32fxxx) add_subdirectory(synchronous_stm32fxxx) add_subdirectory(middlewares) diff --git a/hal_st/dwt/CMakeLists.txt b/hal_st/dwt/CMakeLists.txt deleted file mode 100644 index 5af41881..00000000 --- a/hal_st/dwt/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -add_library(hal_st.dwt STATIC) -emil_build_for(hal_st.dwt TARGET_MCU_VENDOR st PREREQUISITE_BOOL HALST_STANDALONE) - -target_include_directories(hal_st.dwt PUBLIC - "$" - "$" -) - -target_link_libraries(hal_st.dwt PUBLIC - st.hal_driver - infra.util -) - -target_sources(hal_st.dwt PRIVATE - DataWatchpointAndTrace.hpp - DataWatchpointAndTrace.cpp -) diff --git a/hal_st/dwt/DataWatchpointAndTrace.cpp b/hal_st/dwt/DataWatchpointAndTrace.cpp deleted file mode 100644 index 7e21e66c..00000000 --- a/hal_st/dwt/DataWatchpointAndTrace.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "hal_st/dwt/DataWatchpointAndTrace.hpp" - -#if defined(__CORTEX_M) && (__CORTEX_M == 4) - -namespace hal -{ - DataWatchPointAndTrace::DataWatchPointAndTrace() - { - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - DWT->CYCCNT = 0; - } - - DataWatchPointAndTrace::~DataWatchPointAndTrace() - { - CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk; - } - - void DataWatchPointAndTrace::Start() const - { - DWT->CYCCNT = 0; - DWT->CTRL |= DWT_CTRL_CYCEVTENA_Msk; - } - - uint32_t DataWatchPointAndTrace::Stop() const - { - uint32_t cycles = DWT->CYCCNT; - DWT->CTRL &= ~DWT_CTRL_CYCEVTENA_Msk; - return cycles; - } -} - -#endif diff --git a/hal_st/dwt/DataWatchpointAndTrace.hpp b/hal_st/dwt/DataWatchpointAndTrace.hpp deleted file mode 100644 index ef63d0bb..00000000 --- a/hal_st/dwt/DataWatchpointAndTrace.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include DEVICE_HEADER -#include "infra/util/InterfaceConnector.hpp" - -#if defined(__CORTEX_M) && (__CORTEX_M == 4) - -namespace hal -{ - class DataWatchPointAndTrace - : public infra::InterfaceConnector - { - public: - DataWatchPointAndTrace(); - ~DataWatchPointAndTrace(); - - void Start() const; - uint32_t Stop() const; - }; -} - -#endif From 5423255566458e68444445996150d8c5f0f3b3cb Mon Sep 17 00:00:00 2001 From: Gabriel Santos Date: Tue, 25 Aug 2026 17:05:18 +0000 Subject: [PATCH 5/5] fix: ignore .claude directory in ls-lint .claude was added for Claude Code project config but fails the snake_case .dir rule. Co-Authored-By: Claude Sonnet 5 --- .ls-lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.ls-lint.yml b/.ls-lint.yml index 0d24e46d..5cabcdc5 100644 --- a/.ls-lint.yml +++ b/.ls-lint.yml @@ -4,6 +4,7 @@ ls: .cpp: PascalCase ignore: + - .claude - .devcontainer - .git - .github