Skip to content

Commit

Permalink
💥 Move to libhal/3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Khalil Estell committed Dec 11, 2023
1 parent adf2616 commit 44b71cf
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 83 deletions.
54 changes: 8 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
library: libhal-armcortex
secrets: inherit

cortex-m0:
uses: libhal/ci/.github/workflows/[email protected]
with:
profile: cortex-m0
upload: true
secrets: inherit

cortex-m0plus:
uses: libhal/ci/.github/workflows/[email protected]
with:
profile: cortex-m0plus
upload: true
secrets: inherit

cortex-m1:
uses: libhal/ci/.github/workflows/[email protected]
with:
profile: cortex-m1
upload: true
secrets: inherit

cortex-m3:
uses: libhal/ci/.github/workflows/[email protected]
with:
profile: cortex-m3
upload: true
secrets: inherit

cortex-m4:
uses: libhal/ci/.github/workflows/[email protected]
with:
profile: cortex-m4
upload: true
uses: libhal/ci/.github/workflows/[email protected]
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
16 changes: 16 additions & 0 deletions conan/profiles/cortex
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 2 additions & 0 deletions conan/profiles/cortex-m4+nofp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% set cpu = "cortex-m4+nofp" %}
{% include "cortex" %}
12 changes: 6 additions & 6 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
8 changes: 4 additions & 4 deletions include/libhal-armcortex/systick_timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ class systick_timer : public hal::timer
~systick_timer();

private:
result<is_running_t> driver_is_running() override;
result<cancel_t> driver_cancel() override;
result<schedule_t> driver_schedule(hal::callback<void(void)> 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<void(void)> p_callback,
hal::time_duration p_delay) override;

hertz m_frequency = 1'000'000.0f;
};
Expand Down
12 changes: 6 additions & 6 deletions linker_scripts/libhal-armcortex/third_party/standard.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/systick_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,38 @@ systick_timer::~systick_timer()
cortex_m::interrupt(event_number).disable();
}

result<systick_timer::is_running_t> systick_timer::driver_is_running()
systick_timer::is_running_t systick_timer::driver_is_running()
{
auto running_bit = static_cast<bool>(
hal::bit_extract<systick_control_register::enable_counter>(
sys_tick->control));
return is_running_t{ .is_running = running_bit };
}

result<systick_timer::cancel_t> 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.
stop();
return cancel_t{};
}

result<systick_timer::schedule_t> systick_timer::driver_schedule(
systick_timer::schedule_t systick_timer::driver_schedule(
hal::callback<void(void)> 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<std::nano>(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
Expand Down
1 change: 0 additions & 1 deletion test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 1 addition & 5 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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):
Expand Down
23 changes: 23 additions & 0 deletions test_package/linker.ld
Original file line number Diff line number Diff line change
@@ -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"
31 changes: 24 additions & 7 deletions test_package/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,34 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <array>
#include <exception>
#include <span>

#include <libhal-armcortex/dwt_counter.hpp>

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

0 comments on commit 44b71cf

Please sign in to comment.