Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/compile-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -737,3 +737,29 @@ jobs:
with:
name: stm32h7-compile-all-2
path: test/all/log

nrf52-compile-all:
if: github.event.label.name == 'ci:hal'
runs-on: ubuntu-24.04
container:
image: ghcr.io/modm-ext/modm-build-cortex-m:2025-05-18
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Fix Git permission/ownership problem
run: |
git config --global --add safe.directory /__w/modm/modm
- name: Update lbuild
run: |
pip3 install --upgrade --upgrade-strategy=eager --break-system-packages modm
- name: Compile HAL for all nrf52
run: |
(cd test/all && python3 run_all.py nrf52 --quick-remaining)
- name: Upload log artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: nrf52-compile-all
path: test/all/log
28 changes: 24 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ jobs:
name: hal-compile-quick-avr
path: test/all/log

nrf-examples:
runs-on: ubuntu-24.04
container:
image: ghcr.io/modm-ext/modm-build-cortex-m:2025-05-18
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Fix Git permission/ownership problem
run: |
git config --global --add safe.directory /__w/modm/modm
- name: Update lbuild
run: |
pip3 install --upgrade --upgrade-strategy=eager --break-system-packages modm
- name: Examples NRF52840 Without Discovery Board
if: always()
run: |
(cd examples && ../tools/scripts/examples_compile.py nrf)

hal-compile-quick-1:
runs-on: ubuntu-24.04
container:
Expand All @@ -304,7 +324,7 @@ jobs:
- name: Quick compile HAL for Cortex-M Part 1
if: always()
run: |
(cd test/all && python3 run_all.py stm32 sam rp --quick --split 4 --part 0)
(cd test/all && python3 run_all.py stm32 sam rp nrf --quick --split 4 --part 0)
- name: Upload log artifacts
uses: actions/upload-artifact@v4
with:
Expand All @@ -329,7 +349,7 @@ jobs:
- name: Quick compile HAL for Cortex-M Part 2
if: always()
run: |
(cd test/all && python3 run_all.py stm32 sam rp --quick --split 4 --part 1)
(cd test/all && python3 run_all.py stm32 sam rp nrf --quick --split 4 --part 1)
- name: Upload log artifacts
uses: actions/upload-artifact@v4
with:
Expand All @@ -354,7 +374,7 @@ jobs:
- name: Quick compile HAL for Cortex-M Part 3
if: always()
run: |
(cd test/all && python3 run_all.py stm32 sam rp --quick --split 4 --part 2)
(cd test/all && python3 run_all.py stm32 sam rp nrf --quick --split 4 --part 2)
- name: Upload log artifacts
uses: actions/upload-artifact@v4
with:
Expand All @@ -379,7 +399,7 @@ jobs:
- name: Quick compile HAL for Cortex-M Part 4
if: always()
run: |
(cd test/all && python3 run_all.py stm32 sam rp --quick --split 4 --part 3)
(cd test/all && python3 run_all.py stm32 sam rp nrf --quick --split 4 --part 3)
- name: Upload log artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,8 @@ jobs:
if: always()
run: |
(cd examples && ../tools/scripts/examples_compile.py avr)

- name: Compile NRF Examples
if: always()
run: |
(cd examples && ../tools/scripts/examples_compile.py nrf)
6 changes: 6 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,9 @@ jobs:
shell: bash
run: |
(cd examples && ../tools/scripts/examples_compile.py avr arduino_nano arduino_uno srxe)

- name: Compile NRF Examples
if: always()
shell: bash
run: |
(cd examples && ../tools/scripts/examples_compile.py nrf)
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[submodule "ext/st/stm32"]
path = ext/st/stm32
url = https://github.com/modm-io/cmsis-header-stm32.git
[submodule "ext/nordic/nrf"]
path = ext/nordic/nrf
url = https://github.com/elli89/cmsis-header-nrf.git
[submodule "ext/modm-devices"]
path = ext/modm-devices
url = https://github.com/modm-io/modm-devices.git
url = https://github.com/elli89/modm-devices.git
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked at this repo, it looks manually copied? Where from? I'm seeing a lot of linker script and so many header files it would be nice to have the some folders that structure this just a little bit (at least by family?). Preferrably automated via update.py similiar to the other cmsis-header repos to simplify maintenance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, never mind, I just looked at the top-level nrf.h file and it looks like it is not meant to be split apart by family. Let's keep this in mind as a future goal, currently this copies all family files, which is unfortunate.

[submodule "ext/ros/ros-lib"]
path = ext/ros/ros-lib
url = https://github.com/modm-io/ros-lib
Expand Down
31 changes: 31 additions & 0 deletions examples/nrf/blink/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2010-2011, Fabian Greif
* Copyright (c) 2013-2014, 2016-2017, Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <modm/platform.hpp>

using namespace modm::platform;

typedef GpioOutputP0_22 Led;

int
main()
{
Led::setOutput();

while (true)
{
Led::toggle();

modm::delay_ms(1000);
}
}

14 changes: 14 additions & 0 deletions examples/nrf/blink/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<library>
<options>
<option name="modm:target">nrf52840-xxaa</option>
<option name="modm:build:build.path">../../../build/nrf/blink</option>
</options>
<modules>
<module>modm:architecture:delay</module>
<module>modm:platform:core</module>
<module>modm:platform:clock</module>
<module>modm:platform:hfclk</module>
<module>modm:platform:gpio</module>
<module>modm:build:scons</module>
</modules>
</library>
29 changes: 29 additions & 0 deletions ext/nordic/device.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2019 Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#ifndef MODM_DEVICE_HPP
#define MODM_DEVICE_HPP

#define DONT_USE_CMSIS_INIT 1
%% for define in defines
#define {{ define }} 1
%% endfor

#include <stdint.h>
// Defines for example the modm_always_inline macro
#include <modm/architecture/utils.hpp>

// Include external device headers:
%% for header in headers
#include <{{ header }}>
%% endfor

#endif // MODM_DEVICE_HPP
81 changes: 81 additions & 0 deletions ext/nordic/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2019, Niklas Hauser
# Copyright (c) 2020, Hannes Ellinger
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

import re
from pathlib import Path


# -----------------------------------------------------------------------------
def init(module):
module.name = ":cmsis:device"


def prepare(module, options):
device = options[":target"]
if device.identifier["platform"] != "nrf":
return False

module.depends(":cmsis:core")
return True


pp = {}


def validate(env):
device = env[":target"]
device_name = device.identifier.string.split("-")[0]

define = "{}".format(device_name.upper())
family_file = None
famfile = Path(localpath("nrf/nrf.h"))
content = famfile.read_text(encoding="utf-8", errors="replace")
match = re.findall(r"defined \((?P<define>_?.*)\)", content)
for m in match:
if define in m:
family_file = famfile.relative_to(localpath("."))

if family_file is None:
raise ValidateException("No device define found for '{}'!".format(device.partname))

family_folder = family_file.parent
if device_name == "nrf51822":
device_header = "nrf51.h"
elif device_name == "nrf52832":
device_header = "nrf52.h"
else:
device_header = "{}.h".format(device_name)

global pp
pp = {
"define": define,
"folder": family_folder,
"device_header": device_header,
}


def build(env):
global pp
env.collect(":build:path.include", "modm/ext/cmsis/device")

env.outbasepath = "modm/ext/cmsis/device"
files = [pp["device_header"], "system_"+pp["device_header"]]
for file in files:
env.copy(localpath(pp["folder"], file), file)

env.substitutions = {
"headers": [pp["device_header"]],
"defines": [pp["define"]],
}
env.outbasepath = "modm/src/modm/platform"
env.template("device.hpp.in")
1 change: 1 addition & 0 deletions ext/nordic/nrf
Submodule nrf added at 5972dc
1 change: 1 addition & 0 deletions repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class DevicesCache(dict):
"same70", "sams70", "samv70", "samv71",
"samd51", "same51", "same53", "same54",
"rp2040",
"nrf",
"hosted"]
device_file_names = [dfn for dfn in device_file_names if any(s in dfn for s in supported)]
# These files are ignored due to various issues
Expand Down
20 changes: 20 additions & 0 deletions src/modm/platform/clock/nrf/hfclk.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2013-2014, Kevin Läufer
* Copyright (c) 2014-2017, Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include "../device.hpp"
#include "hfclk.hpp"

namespace modm::platform
{
uint16_t modm_fastdata delay_fcpu_MHz(64);
uint16_t modm_fastdata delay_ns_per_loop({{ loops * 1000 / 64 }});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core runs at 64MHz right after boot? This should be set to the default clock frequency which is probably much less than 64MHz.

}
35 changes: 35 additions & 0 deletions src/modm/platform/clock/nrf/hfclk.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2019, Ethan Slattery
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#pragma once

#include <stdint.h>
#include "../device.hpp"

namespace modm::platform
{

/**
* Clock management
*
* \ingroup modm_platform_hfclk
*/
class HighFrequencyClockController
{
public:
template< uint32_t Core_Hz >
void
updateCoreFrequency();
};

}

#include "hfclk_impl.hpp"
30 changes: 30 additions & 0 deletions src/modm/platform/clock/nrf/hfclk_impl.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2019, Ethan Slattery
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <cmath>

namespace modm::platform
{
/// @cond
extern uint16_t delay_fcpu_MHz;
extern uint16_t delay_ns_per_loop;
/// @endcond

template< uint32_t Core_Hz >
void
HighFrequencyClockController::updateCoreFrequency()
{
delay_fcpu_MHz = Core_Hz / 64'000'000;
delay_ns_per_loop = ::round({{loops}}000.f / (Core_Hz / 64'000'000));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divide by 1MHz.

}

}

Loading
Loading