Skip to content

sys/nrf_sf_radio: Add new module - #22447

Open
merlins123 wants to merge 4 commits into
RIOT-OS:masterfrom
merlins123:add-nrf-sf-radio-module
Open

sys/nrf_sf_radio: Add new module#22447
merlins123 wants to merge 4 commits into
RIOT-OS:masterfrom
merlins123:add-nrf-sf-radio-module

Conversation

@merlins123

Copy link
Copy Markdown

Contribution description

Added a new module, sys/nrf_sf_radio. This module encapsulates the common physical-layer and link-layer radio control functions used for synchronous flooding.

This module is designed for BLE flooding and for development boards such as the nRF51 and nRF52 that support the NRF_PPI peripheral.

By introducing this module, developers can focus on implementing higher-layer flooding protocols without having to rebuild the low-level precise radio control mechanisms from scratch.

Testing procedure

run

make -C tests/sys/nrf_sf_radio   BOARD=adafruit-feather-nrf52840-sense   UF2_SOFTDEV=DROP   clean all flash test

to test the module.

UF2_SOFTDEV=DROPwas used because the tested board does not have a SoftDevice installed. The test does not require SoftDevice functionality.

The expected output is

nrf_sf_radio test start
SUCCESS

Issues/PRs references

None.

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • Codex for test script build, with user review
  • ChatGPT for Git/GitHub workflow guidance.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Hey @merlins123, thank you for your first contribution! We really appreciate it! If you haven't already, please take a look at our contributing guidelines before the review process starts. Also, due to how the GitHub review system works, please avoid force-pushing or squashing your commits unless asked to by a maintainer (or unless your commit is still in "draft commit" stage). Lastly, make sure to comply with our AI Policy when using AI. Your pull request will be reviewed as soon as possible.

@github-actions github-actions Bot added Area: tests Area: tests and testing framework Area: sys Area: System labels Jul 6, 2026
@merlins123 merlins123 changed the title Add nrf sf radio module sys/nrf_sf_radio: Add new module Jul 6, 2026
@AnnsAnns AnnsAnns added AI: Code AI: Helped PR/Issue uses AI sparingly, e.g. code inline assistant, debugging with AI, etc. AI: Co-Authored PR/Issue relies on AI. Documentation / Code was partly generated by AI. and removed AI: Helped PR/Issue uses AI sparingly, e.g. code inline assistant, debugging with AI, etc. AI: Code labels Jul 6, 2026
@merlins123
merlins123 force-pushed the add-nrf-sf-radio-module branch from 92c089f to 523e151 Compare July 6, 2026 17:12
sys/nrf_sf_radio: add synchronous flooding physical layer and link layer module

tests/nrf_sf_radio/: add test for sys/nrf_sf_radio

tests/sys/nrf_sf_radio: move test module

refresh
@merlins123
merlins123 force-pushed the add-nrf-sf-radio-module branch from 523e151 to c77657e Compare July 6, 2026 17:23

@crasbe crasbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To be honest I'm not quite sure I see the point of this module. It is highly specific to the nRF52 (which means it should probably not be placed in sys) and pretty specific in the configuration options that are preset.

The model lacks general documentation about how it should be used and what it can be used for, what configuration options exist and the fact that it allocates two of the hardware timers.

Especially considering this is about BLE, I wonder if there aren't some initialization functions from NimBLE that could be reused instead.

Comment on lines +1 to +7
/*
* Copyright (C) 2026 Xin He
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/*
* Copyright (C) 2026 Xin He
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/*
* SPDX-FileCopyrightText: 2026 Xin He
* SPDX-License-Identifier: LGPL-2.1-only
*/

The copyright headers should be in SPDX format, see #21515 and https://github.com/RIOT-OS/RIOT/blob/master/CODING_CONVENTIONS.md#documentation for more information.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please adapt the other files accordingly.

Comment thread sys/include/nrf_sf_radio/link_radio.h Outdated
Comment on lines +21 to +22
#ifndef NRF_SF_RADIO_LINK_RADIO_H
#define NRF_SF_RADIO_LINK_RADIO_H

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The old style header guards should not be used anymore, use #pragma once instead.

See also: https://github.com/RIOT-OS/RIOT/blob/master/CODING_CONVENTIONS.md#header-guards

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please adapt the other files accordingly.

Comment thread sys/include/nrf_sf_radio/link_radio.h Outdated
* @ingroup sys_nrf_sf_radio
* @{
*
* @file link_radio.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @file link_radio.h
* @file

It's not necessary to specify the actual file name. This will just cause issues when/if the file is renamed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please adapt the other files accordingly.

Comment thread sys/include/nrf_sf_radio/link_radio.h Outdated
Comment on lines +77 to +78
* @return true if the transmission completed before the end time
* @return false if the transmission failed or timed out

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @return true if the transmission completed before the end time
* @return false if the transmission failed or timed out
* @retval true if the transmission completed before the end time
* @retval false if the transmission failed or timed out

For discrete return values, the @retval command can and should be used.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please adapt the other function documentation headers accordingly.

Comment thread sys/include/nrf_sf_radio/link_radio.h Outdated
Comment on lines +106 to +107
* @return Corrected ADDRESS timestamp in timer ticks on success
* @return 0 on timeout or CRC failure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @return Corrected ADDRESS timestamp in timer ticks on success
* @return 0 on timeout or CRC failure
* @return Corrected ADDRESS timestamp in timer ticks on success
* @retval 0 on timeout or CRC failure

It is also possible to use both @return and @retval.

Comment thread sys/include/nrf_sf_radio/link_radio.h Outdated
Comment on lines +92 to +93
* @return true if a valid packet was received before the end time
* @return false if no valid packet was received or reception timed out

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not what the function actually returns. It returns numeric values.

Comment thread sys/include/nrf_sf_radio/link_radio.h Outdated
Comment on lines +96 to +97
uint32_t rx_window_end_ticks,
uint32_t rx_end_ticks);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
uint32_t rx_window_end_ticks,
uint32_t rx_end_ticks);
uint32_t rx_window_end_ticks,
uint32_t rx_end_ticks);

Comment on lines +38 to +40
#ifndef NRF_SF_RADIO_ACCESS_ADDRESS
# define NRF_SF_RADIO_ACCESS_ADDRESS (0x8367BED6u)
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is that address something that would be expected to change or is that the address of the internal peripheral?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It should be the standard ble advertising access address. I changed it for test to to avoid environmental interference. I will change it back.

Comment on lines +250 to +261
NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_1Mbit;
uint32_t modecnf0 = (RADIO_MODECNF0_DTX_Center << RADIO_MODECNF0_DTX_Pos);
#if NRF_SF_RADIO_FAST_RAMPUP
modecnf0 |= (RADIO_MODECNF0_RU_Fast << RADIO_MODECNF0_RU_Pos);
#else
modecnf0 |= (RADIO_MODECNF0_RU_Default << RADIO_MODECNF0_RU_Pos);
#endif
NRF_RADIO->MODECNF0 = modecnf0;

NRF_RADIO->TXPOWER = (RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos);
NRF_RADIO->FREQUENCY = ble_hw_frequency_channels[37];
NRF_RADIO->DATAWHITEIV = 37;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The mode, TX power and frequency would be something worth having adjustable, wouldn't it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That's true. I'll add this part.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That test has rather... little coverage of the module 🤔

Also it is missing the copyright and doxgen header.

@mguetschow mguetschow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for your PR!

I agree with @crasbe here, your PR is lacking documentation and a rationale why this is a fitting addition for RIOT.

Wouldn't it make sense to design a hardware-independant API (or reuse / extend one of the available BLE-ones) for your use-case, and then just implement it for the different hardware? (Why) is it not possible to build on top of existing BLE APIs like nimble?

@merlins123

merlins123 commented Jul 8, 2026 via email

Copy link
Copy Markdown
Author

@mguetschow

Copy link
Copy Markdown
Contributor

I considered using NimBLE, but NimBLE abstracts packet transmission and reception through the BLE stack and controller. This means the application cannot precisely control radio state transitions and transmission timing at the level required for synchronized flooding. For this reason, the timing-critical part of the module is implemented below the BLE stack and directly controls the nRF radio peripherals.

Have you had a look at https://github.com/RIOT-OS/RIOT/tree/master/cpu/nrf5x_common/radio/nrfble?

@merlins123

merlins123 commented Jul 8, 2026 via email

Copy link
Copy Markdown
Author

@merlins123
merlins123 requested a review from jia200x as a code owner July 11, 2026 14:52
@github-actions github-actions Bot added the Area: doc Area: Documentation label Jul 11, 2026
@merlins123
merlins123 force-pushed the add-nrf-sf-radio-module branch from aabe6bf to aa0fc46 Compare July 11, 2026 15:03
@merlins123
merlins123 requested a review from mguetschow July 11, 2026 15:04
@merlins123
merlins123 force-pushed the add-nrf-sf-radio-module branch from aa0fc46 to de386e5 Compare July 12, 2026 16:05
@merlins123

Copy link
Copy Markdown
Author

After checking the radio support currently available in RIOT, I could not
find a non-nRF cpu for this BLE-based, hardware-timed synchronous flooding
implementation.

CC26x2 does not currently have a BLE radio backend in RIOT. The existing
KW41Z and CC2538 radio drivers implement IEEE 802.15.4 only. ESP32 exposes
BLE through the vendor controller/HCI interface and does not provide the
deterministic low-level radio control required here.

Therefore, with the interfaces currently available in RIOT, this
implementation is specific to nRF52. It currently uses nRF52-specific
resources such as TIMER3 and PPI, so nRF51 would require an additional
port.

Given your feedback, I agree that this hardware-specific implementation
does not belong in sys. Would cpu/nrf52/radio/ be the appropriate location
for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Co-Authored PR/Issue relies on AI. Documentation / Code was partly generated by AI. Area: doc Area: Documentation Area: sys Area: System Area: tests Area: tests and testing framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants