From 44b71cf351562a6c8366e94090450f5de0c5e028 Mon Sep 17 00:00:00 2001 From: Khalil Estell Date: Thu, 16 Nov 2023 05:42:48 -0800 Subject: [PATCH] :boom: Move to libhal/3.0.0 --- .github/workflows/ci.yml | 54 +++---------------- conan/profiles/cortex | 16 ++++++ conan/profiles/cortex-m4+nofp | 2 + conanfile.py | 12 ++--- include/libhal-armcortex/systick_timer.hpp | 8 +-- .../libhal-armcortex/third_party/standard.ld | 12 ++--- src/systick_timer.cpp | 16 +++--- test_package/CMakeLists.txt | 1 - test_package/conanfile.py | 6 +-- test_package/linker.ld | 23 ++++++++ test_package/main.cpp | 31 ++++++++--- 11 files changed, 98 insertions(+), 83 deletions(-) create mode 100644 conan/profiles/cortex create mode 100644 conan/profiles/cortex-m4+nofp create mode 100644 test_package/linker.ld diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3405ab7..6d836f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,61 +3,23 @@ name: ✅ CI on: workflow_dispatch: pull_request: - release: - types: - - published - - deleted push: branches: - main + # Remove before merging with main + - exceptions schedule: - cron: "0 12 * * 0" jobs: ci: - uses: libhal/ci/.github/workflows/library.yml@4.x.y - with: - library: libhal-armcortex - secrets: inherit - - cortex-m0: - uses: libhal/ci/.github/workflows/platform_deploy.yml@4.x.y - with: - profile: cortex-m0 - upload: true - secrets: inherit - - cortex-m0plus: - uses: libhal/ci/.github/workflows/platform_deploy.yml@4.x.y - with: - profile: cortex-m0plus - upload: true - secrets: inherit - - cortex-m1: - uses: libhal/ci/.github/workflows/platform_deploy.yml@4.x.y - with: - profile: cortex-m1 - upload: true - secrets: inherit - - cortex-m3: - uses: libhal/ci/.github/workflows/platform_deploy.yml@4.x.y - with: - profile: cortex-m3 - upload: true - secrets: inherit - - cortex-m4: - uses: libhal/ci/.github/workflows/platform_deploy.yml@4.x.y - with: - profile: cortex-m4 - upload: true + uses: libhal/ci/.github/workflows/library_check.yml@5.x.y secrets: inherit - cortex-m4f: - uses: libhal/ci/.github/workflows/platform_deploy.yml@4.x.y + test-cortex-m0: + uses: libhal/ci/.github/workflows/deploy.yml@5.x.y with: - profile: cortex-m4f - upload: true + arch: cortex-m0 + os: baremetal + compiler_package: arm-gnu-toolchain secrets: inherit diff --git a/conan/profiles/cortex b/conan/profiles/cortex new file mode 100644 index 0000000..6adfbd8 --- /dev/null +++ b/conan/profiles/cortex @@ -0,0 +1,16 @@ +[settings] +compiler=gcc +compiler.cppstd=20 +compiler.libcxx=libstdc++ +compiler.version=12.2 +os=baremetal +arch={{ cpu }} + +[tool_requires] +arm-gnu-toolchain/12.2.1 +picolibc/12.2.1 + +[conf] +tools.build:cflags=["-mcpu={{ cpu }}", "-mfloat-abi=hard", "-mthumb", "-ffunction-sections", "-fdata-sections"] +tools.build:cxxflags=["-mcpu={{ cpu }}", "-fno-rtti", "-mfloat-abi=hard", "-mthumb", "-ffunction-sections", "-fdata-sections"] +tools.build:exelinkflags=["--specs=nosys.specs", "--specs=picolibc.specs", "-mcpu={{ cpu }}", "-mfloat-abi=hard", "-mthumb", "-fno-rtti", "-Wl,--gc-sections", "-Wl,--print-memory-usage"] diff --git a/conan/profiles/cortex-m4+nofp b/conan/profiles/cortex-m4+nofp new file mode 100644 index 0000000..f5ca159 --- /dev/null +++ b/conan/profiles/cortex-m4+nofp @@ -0,0 +1,2 @@ +{% set cpu = "cortex-m4+nofp" %} +{% include "cortex" %} diff --git a/conanfile.py b/conanfile.py index b9c224e..d99a2f6 100644 --- a/conanfile.py +++ b/conanfile.py @@ -26,7 +26,6 @@ class libhal_arm_cortex_conan(ConanFile): name = "libhal-armcortex" - version = "2.2.1" license = "Apache-2.0" url = "https://github.com/conan-io/conan-center-index" homepage = "https://libhal.github.io/libhal-armcortex" @@ -63,12 +62,15 @@ def validate(self): def build_requirements(self): self.tool_requires("cmake/3.27.1") + if self._bare_metal: + self.tool_requires( + f"arm-gnu-toolchain/{self.settings.compiler.version}") self.tool_requires("libhal-cmake-util/3.0.1") self.test_requires("boost-ext-ut/1.1.9") def requirements(self): - self.requires("libhal/[^2.0.3]", transitive_headers=True) - self.requires("libhal-util/[^3.0.1]") + self.requires("libhal/3.0.0-alpha.1", transitive_headers=True) + self.requires("libhal-util/4.0.0-alpha.1") def layout(self): cmake_layout(self) @@ -109,9 +111,7 @@ def package_info(self): if ( self._bare_metal and self.settings.compiler == "gcc" and - (self.settings.arch == "thumbv6" or - self.settings.arch == "thumbv7" or - self.settings.arch == "thumbv8") + "cortex-" in str(self.settings.arch) ): linker_path = os.path.join(self.package_folder, "linker_scripts") self.cpp_info.exelinkflags.append("-L" + linker_path) diff --git a/include/libhal-armcortex/systick_timer.hpp b/include/libhal-armcortex/systick_timer.hpp index 9b0e4b6..3e0c99e 100644 --- a/include/libhal-armcortex/systick_timer.hpp +++ b/include/libhal-armcortex/systick_timer.hpp @@ -81,10 +81,10 @@ class systick_timer : public hal::timer ~systick_timer(); private: - result driver_is_running() override; - result driver_cancel() override; - result driver_schedule(hal::callback p_callback, - hal::time_duration p_delay) override; + is_running_t driver_is_running() override; + cancel_t driver_cancel() override; + schedule_t driver_schedule(hal::callback p_callback, + hal::time_duration p_delay) override; hertz m_frequency = 1'000'000.0f; }; diff --git a/linker_scripts/libhal-armcortex/third_party/standard.ld b/linker_scripts/libhal-armcortex/third_party/standard.ld index 6229518..6bf5da0 100644 --- a/linker_scripts/libhal-armcortex/third_party/standard.ld +++ b/linker_scripts/libhal-armcortex/third_party/standard.ld @@ -42,18 +42,18 @@ ENTRY(_start) MEMORY { - flash (rxai!w) : ORIGIN = DEFINED(__flash) ? __flash : 0x10000000, LENGTH = DEFINED(__flash_size) ? __flash_size : 0x10000 - ram (wxa!ri) : ORIGIN = DEFINED(__ram ) ? __ram : 0x20000000, LENGTH = DEFINED(__ram_size ) ? __ram_size : 0x08000 + flash : ORIGIN = __flash, LENGTH = __flash_size + ram : ORIGIN = __ram, LENGTH = __ram_size } ENTRY(_start) PHDRS { - text PT_LOAD; - ram PT_LOAD; - ram_init PT_LOAD; - tls PT_TLS; + text PT_LOAD FLAGS(5); + ram PT_LOAD FLAGS(6); + ram_init PT_LOAD FLAGS(6); + tls PT_TLS FLAGS(6); } SECTIONS diff --git a/src/systick_timer.cpp b/src/systick_timer.cpp index a86ab7f..ff00158 100644 --- a/src/systick_timer.cpp +++ b/src/systick_timer.cpp @@ -76,7 +76,7 @@ systick_timer::~systick_timer() cortex_m::interrupt(event_number).disable(); } -result systick_timer::driver_is_running() +systick_timer::is_running_t systick_timer::driver_is_running() { auto running_bit = static_cast( hal::bit_extract( @@ -84,7 +84,7 @@ result systick_timer::driver_is_running() return is_running_t{ .is_running = running_bit }; } -result systick_timer::driver_cancel() +systick_timer::cancel_t systick_timer::driver_cancel() { // All that is needed is to stop the timer. When the timer is started again // via `schedule()`, the timer value will be reloaded/reset. @@ -92,22 +92,22 @@ result systick_timer::driver_cancel() return cancel_t{}; } -result systick_timer::driver_schedule( +systick_timer::schedule_t systick_timer::driver_schedule( hal::callback p_callback, hal::time_duration p_delay) { - static constexpr std::int64_t maximum = 0x00FFFFFF; + constexpr std::int64_t maximum = 0x00FFFFFF; auto cycle_count = cycles_per(m_frequency, p_delay); if (cycle_count <= 1) { cycle_count = 1; } else if (cycle_count > maximum) { auto tick_period = wavelength(m_frequency); - auto max_duration = HAL_CHECK(duration_from_cycles(m_frequency, maximum)); - return hal::new_error(out_of_bounds_error{ + auto max_duration = duration_from_cycles(m_frequency, maximum); + throw out_of_bounds_error{ .tick_period = tick_period, - .maximum = max_duration, - }); + .maximum = max_duration.value_or(std::chrono::nanoseconds(-1)), + }; } // Stop the previously scheduled event diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index 913e564..935075a 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -18,6 +18,5 @@ project(test_package LANGUAGES CXX) find_package(libhal-armcortex CONFIG REQUIRED) add_executable(test_package main.cpp) -target_include_directories(test_package PUBLIC .) target_compile_features(test_package PRIVATE cxx_std_20) target_link_libraries(test_package PRIVATE libhal::armcortex) diff --git a/test_package/conanfile.py b/test_package/conanfile.py index ad90aa2..ec64b4b 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -22,10 +22,6 @@ class TestPackageConan(ConanFile): settings = "os", "compiler", "arch", "build_type" generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" - @property - def _bare_metal(self): - return self.settings.os == "baremetal" - def build_requirements(self): self.tool_requires("cmake/3.27.1") @@ -37,7 +33,7 @@ def layout(self): def build(self): cmake = CMake(self) - cmake.configure(variables={"BAREMETAL": self._bare_metal}) + cmake.configure() cmake.build() def test(self): diff --git a/test_package/linker.ld b/test_package/linker.ld new file mode 100644 index 0000000..617dc5c --- /dev/null +++ b/test_package/linker.ld @@ -0,0 +1,23 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +__flash = 0x00000000; +__flash_size = 64K; +__ram = 0x10000000; +__ram_size = 8K; +__stack_size = 1K; + +INCLUDE "libhal-armcortex/standard.ld" diff --git a/test_package/main.cpp b/test_package/main.cpp index ec21b60..5d38f56 100644 --- a/test_package/main.cpp +++ b/test_package/main.cpp @@ -12,17 +12,34 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include +#include + #include -int main() +// Demonstrate function that throws +void foo() { - hal::cortex_m::dwt_counter counter(1'000'000.0f); - return counter.uptime().ticks; + // volatile integer used to keep + static volatile int a = 0; + a = a + 1; + throw 5; } -namespace boost { -void throw_exception(std::exception const& e) +int main() { - hal::halt(); + try { + hal::cortex_m::dwt_counter counter(1'000'000.0f); + counter.uptime().ticks; + } catch (...) { + std::terminate(); + } + try { + foo(); + } catch (...) { + std::terminate(); + } + + return 0; } -} // namespace boost \ No newline at end of file