Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
💥 Upgrade to libhal/3.0.0 (#5)
Browse files Browse the repository at this point in the history
* 💥 Upgrade to libhal/3.0.0
  • Loading branch information
FluffyFTW authored Mar 7, 2024
1 parent 752439d commit 0455099
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 193 deletions.
31 changes: 19 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,37 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: Checks
name: CI

on:
workflow_dispatch:
pull_request:
release:
types:
- published
- deleted
push:
branches:
- main
schedule:
- cron: "0 12 * * 0"

jobs:
ci:
uses: libhal/ci/.github/workflows/library.yml@4.x.y
library_checks:
uses: libhal/ci/.github/workflows/library_check.yml@5.x.y
secrets: inherit

stm32f411re:
uses: libhal/ci/.github/workflows/platform_deploy.yml@4.x.y
deploy_cortex-m4f_check:
uses: libhal/ci/.github/workflows/deploy.yml@5.x.y
with:
profile: stm32f411re
# Replace with appropriate processor profile
processor_profile: https://github.com/libhal/libhal-armcortex.git
arch: cortex-m4f
os: baremetal
compiler: gcc
compiler_version: 12.3
compiler_package: arm-gnu-toolchain
secrets: inherit

demo_check:
uses: libhal/ci/.github/workflows/[email protected]
with:
compiler_profile_url: https://github.com/libhal/arm-gnu-toolchain.git
compiler_profile: v1/arm-gcc-12.3
platform_profile_url: https://github.com/FluffyFTW/libhal-stm32f4.git
platform_profile: stm32f411re
secrets: inherit
8 changes: 0 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,4 @@ libhal_test_and_make_library(
TEST_SOURCES
tests/output_pin.test.cpp
tests/main.test.cpp

PACKAGES
libhal
libhal-util

LINK_LIBRARIES
libhal::libhal
libhal::util
)
3 changes: 0 additions & 3 deletions conan/profiles/profile1

This file was deleted.

3 changes: 0 additions & 3 deletions conan/profiles/profile2

This file was deleted.

6 changes: 6 additions & 0 deletions conan/profiles/stm32f4
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[settings]
build_type=MinSizeRel
os=baremetal
arch={{ arch }}
libc=custom

[options]
*:platform={{ platform }}

Expand Down
2 changes: 1 addition & 1 deletion conan/profiles/stm32f411re
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% include "cortex-m4" %}
{% set arch = "cortex-m4f" %}
{% set platform = "stm32f411re" %}
{% include "stm32f4" %}
69 changes: 6 additions & 63 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@
# limitations under the License.

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.files import copy
from conan.tools.build import check_min_cppstd
import os


required_conan_version = ">=2.0.6"
required_conan_version = ">=2.0.14"


class libhal_stm32f4_conan(ConanFile):
name = "libhal-stm32f4"
version = "0.0.1"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://libhal.github.io/libhal-stm32f4"
Expand All @@ -36,7 +31,9 @@ class libhal_stm32f4_conan(ConanFile):
settings = "compiler", "build_type", "os", "arch"
exports_sources = ("include/*", "linker_scripts/*", "tests/*", "LICENSE",
"CMakeLists.txt", "src/*")
generators = "CMakeToolchain", "CMakeDeps", "VirtualBuildEnv"

python_requires = "libhal-bootstrap/[^0.0.4]"
python_requires_extend = "libhal-bootstrap.library"

options = {
"platform": ["ANY"],
Expand All @@ -53,70 +50,16 @@ def package_id(self):
def _use_linker_script(self):
return (self.options.platform == "stm32f411re")

@property
def _min_cppstd(self):
return "20"

@property
def _compilers_minimum_version(self):
return {
"gcc": "11",
"clang": "14",
"apple-clang": "14.0.0"
}

@property
def _bare_metal(self):
return self.settings.os == "baremetal"

def validate(self):
if self.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, self._min_cppstd)

def build_requirements(self):
self.tool_requires("cmake/3.27.1")
self.tool_requires("libhal-cmake-util/2.2.0")
self.test_requires("libhal-mock/[^2.0.1]")
self.test_requires("boost-ext-ut/1.1.9")

def requirements(self):
self.requires("libhal/[^2.0.1]")
self.requires("libhal-util/[^3.0.0]")
# Replace with appropriate processor library
self.requires("libhal-armcortex/[^2.2.0]")

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self,
"LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
copy(self,
"*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"))
copy(self,
"*.hpp",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"))
copy(self,
"*.ld",
dst=os.path.join(self.package_folder, "linker_scripts"),
src=os.path.join(self.source_folder, "linker_scripts"))

cmake = CMake(self)
cmake.install()
self.requires("libhal-armcortex/[^3.0.0]")

def package_info(self):
self.cpp_info.set_property("cmake_target_name", "libhal::stm32f4")
self.cpp_info.libs = ["libhal-stm32f4"]
self.cpp_info.set_property("cmake_target_name", "libhal::stm32f4")

if self._bare_metal and self._use_linker_script:
linker_path = os.path.join(self.package_folder, "linker_scripts")
Expand Down
2 changes: 2 additions & 0 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ libhal_build_demos(

PACKAGES
libhal-stm32f4
libhal-exceptions

LINK_LIBRARIES
libhal::stm32f4
libhal::exceptions
)
11 changes: 5 additions & 6 deletions demos/applications/blinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
#include <libhal-util/steady_clock.hpp>

void delay_by_cycles(int cycles);
hal::status application()
void application()
{
using namespace hal::literals;
auto led = HAL_CHECK(
hal::stm32f4::output_pin::get(hal::stm32f4::peripheral::gpio_a, 5));
HAL_CHECK(led.level(true));
hal::stm32f4::output_pin led(hal::stm32f4::peripheral::gpio_a, 5);
led.level(true);
while (true) {
HAL_CHECK(led.level(false));
led.level(false);
delay_by_cycles(1000000);
HAL_CHECK(led.level(true));
led.level(true);
delay_by_cycles(1000000);
}
}
Expand Down
25 changes: 7 additions & 18 deletions demos/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,18 @@
# limitations under the License.

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout


class demos(ConanFile):
settings = "compiler", "build_type", "os", "arch"
generators = "CMakeToolchain", "CMakeDeps", "VirtualBuildEnv"
settings = "compiler", "build_type", "os", "arch", "libc"
options = {"platform": ["ANY"]}
default_options = {"platform": "unspecified"}

def layout(self):
platform_directory = "build/" + str(self.options.platform)
cmake_layout(self, build_folder=platform_directory)

def build_requirements(self):
self.tool_requires("cmake/3.27.1")
self.tool_requires("libhal-cmake-util/2.2.0")
python_requires = "libhal-bootstrap/[^0.0.4]"
python_requires_extend = "libhal-bootstrap.demo"

def requirements(self):
self.requires("libhal/[2.2.0]")
self.requires(f"prebuilt-picolibc/{self.settings.compiler.version}")
self.requires("libhal-stm32f4/0.0.1")

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
bootstrap = self.python_requires["libhal-bootstrap"]
bootstrap.module.add_demo_requirements(self, is_platform=True)
self.requires("libhal-exceptions/[^0.0.1]")
self.requires("libhal-stm32f4/[>=0.0.1]")
31 changes: 12 additions & 19 deletions demos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,29 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Replace with the correct processor includes
#include <libhal-armcortex/startup.hpp>
#include <libhal-armcortex/system_control.hpp>
#include <libhal/error.hpp>

// Application function must be implemented by one of the compilation units
// (.cpp) files.
extern hal::status application();

extern void application();
int main()
{
// Put platform initialization stuff here...
// Initialize data section in RAM here...
// Enable necessary coprocessors here...

auto is_finished = application();

if (!is_finished) {
// Replace line below here with reset() here.
try {
application();
} catch (...) {
hal::cortex_m::reset();
} else {
hal::halt();
}

return 0;
}

namespace boost {
void throw_exception(std::exception const&)
extern "C"
{
hal::halt();
}
} // namespace boost
struct _reent* _impure_ptr = nullptr; // NOLINT

void _exit([[maybe_unused]] int rc) // NOLINT
{
std::terminate();
}
}
20 changes: 9 additions & 11 deletions include/libhal-stm32f4/output_pin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,29 @@

#pragma once

#include "pin.hpp"
#include <libhal/output_pin.hpp>

#include "pin.hpp"

namespace hal::stm32f4 {
class output_pin : public hal::output_pin
{
public:
/**
* @brief Get the output pin object
* @brief Construct a new output pin object
*
* @param p_port - selects pin port to use
* @param p_pin - selects which pin within the port to use
* @param p_settings - initial pin settings
* @return result<output_pin> - reference to the statically allocated output
* pin
*/
static result<output_pin> get(hal::stm32f4::peripheral p_port,
std::uint8_t p_pin,
output_pin::settings p_settings = {});
output_pin(hal::stm32f4::peripheral p_port,
std::uint8_t p_pin,
output_pin::settings p_settings = {});

private:
output_pin(hal::stm32f4::peripheral p_port, std::uint8_t p_pin);
hal::status driver_configure(const settings& p_settings) override;
hal::result<set_level_t> driver_level(bool p_high) override;
hal::result<level_t> driver_level() override;
void driver_configure(const settings& p_settings) override;
void driver_level(bool p_high) override;
bool driver_level() override;

hal::stm32f4::peripheral m_port{};
std::uint8_t m_pin{};
Expand Down
8 changes: 4 additions & 4 deletions include/libhal-stm32f4/pin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class pin
* @param p_port - selects pin port to use
* @param p_pin - selects pin within the port to use
*/
constexpr pin(peripheral p_port, std::uint8_t p_pin)
constexpr pin(peripheral p_port, std::uint8_t p_pin) noexcept
: m_port(p_port)
, m_pin(p_pin)
{
Expand All @@ -73,23 +73,23 @@ class pin
* @param p_function - the pin function (I,O, alternatex)
* @return pin& - reference to this pin for chaining
*/
const pin& function(pin_function p_function) const;
const pin& function(pin_function p_function) const noexcept;

/**
* @brief Set the internal resistor connection for this pin
*
* @param p_resistor - resistor type
* @return pin& - reference to this pin for chaining
*/
const pin& resistor(hal::pin_resistor p_resistor) const;
const pin& resistor(hal::pin_resistor p_resistor) const noexcept;

/**
* @brief Disable or enable hysteresis mode for this pin
*
* @param p_enable - enable this mode, set to false to disable this mode
* @return pin& - reference to this pin for chaining
*/
const pin& open_drain(bool p_enable = true) const;
const pin& open_drain(bool p_enable = true) const noexcept;

private:
peripheral m_port{};
Expand Down
Loading

0 comments on commit 0455099

Please sign in to comment.