Skip to content

Commit cf23839

Browse files
committed
softdevice: add babblesim support
Add SoftDevice babblesim support. Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
1 parent 69e5188 commit cf23839

11 files changed

Lines changed: 102 additions & 26 deletions

File tree

samples/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# All these samples shall run without multithreading
1010
config MULTITHREADING
11-
default n if (!UNITY && !(ZTEST && BOARD_NATIVE_SIM))
11+
default n if (!UNITY && !(ZTEST && BOARD_NATIVE_SIM) && !SOC_SERIES_BSIM_NRF54LX)
1212

1313
# Software ISR table is not needed if multithreading is not used
1414
config GEN_SW_ISR_TABLE

subsys/softdevice/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@
77
if(CONFIG_SOFTDEVICE_S115 OR CONFIG_SOFTDEVICE_S145)
88
zephyr_include_directories("${ZEPHYR_NRF_BM_MODULE_DIR}/components/softdevice/${CONFIG_SOFTDEVICE_SOC_VARIANT_STR}/${CONFIG_SOFTDEVICE_VARIANT_STR}/${CONFIG_SOFTDEVICE_VARIANT_STR}_API/include")
99
endif()
10+
11+
# SVCALL_AS_NORMAL_FUNCTION makes BLE API headers declare normal functions (no ARM SVC asm).
12+
if(CONFIG_SOFTDEVICE_BSIM)
13+
zephyr_compile_definitions(SVCALL_AS_NORMAL_FUNCTION)
14+
endif()

subsys/softdevice/Kconfig

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ menu "SoftDevice"
77

88
config SOFTDEVICE
99
bool "SoftDevice is present"
10-
depends on ZERO_LATENCY_IRQS
10+
depends on ZERO_LATENCY_IRQS || SOC_SERIES_BSIM_NRF54LX
1111
imply NRF_SDH
1212

1313
config SOFTDEVICE_PERIPHERAL
@@ -32,20 +32,26 @@ choice SOFTDEVICE_VARIANT
3232

3333
config SOFTDEVICE_S115
3434
bool "s115 SoftDevice"
35-
depends on SOC_SERIES_NRF54L
35+
depends on SOC_SERIES_NRF54L || SOC_SERIES_BSIM_NRF54LX
3636
select SOFTDEVICE_PERIPHERAL
3737
select SOFTDEVICE_DATA_LENGTH_UPDATE
3838

3939
config SOFTDEVICE_S145
4040
bool "s145 SoftDevice"
41-
depends on SOC_SERIES_NRF54L
41+
depends on SOC_SERIES_NRF54L || SOC_SERIES_BSIM_NRF54LX
4242
select SOFTDEVICE_PERIPHERAL
4343
select SOFTDEVICE_CENTRAL
4444
select SOFTDEVICE_EXTENDED_ADVERTISING
4545
select SOFTDEVICE_DATA_LENGTH_UPDATE
4646

4747
endchoice # SOFTDEVICE_VARIANT
4848

49+
config SOFTDEVICE_BSIM
50+
bool "Use linkable SoftDevice for Babblesim"
51+
depends on SOC_SERIES_BSIM_NRF54LX
52+
help
53+
Link with the SoftDevice library instead of using the separate SoftDevice hex image.
54+
4955
config SOFTDEVICE_VARIANT_STR
5056
string
5157
default "s115" if SOFTDEVICE_S115
@@ -56,7 +62,7 @@ config SOFTDEVICE_VARIANT_STR
5662

5763
config SOFTDEVICE_SOC_VARIANT_STR
5864
string
59-
default "nrf54l" if SOC_NRF54L15 || SOC_NRF54L10 || SOC_NRF54L05
65+
default "nrf54l" if SOC_NRF54L15 || SOC_NRF54L10 || SOC_NRF54L05 || SOC_SERIES_BSIM_NRF54LX
6066
default "nrf54lm" if SOC_NRF54LM20A
6167
default "nrf54ls" if SOC_NRF54LS05B
6268
default "nrf54lv" if SOC_NRF54LV10A

subsys/softdevice_handler/CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@
66
zephyr_library()
77
zephyr_linker_sources(SECTIONS sdh.ld)
88
zephyr_linker_sources(DATA_SECTIONS sdh_ram.ld)
9+
910
zephyr_library_sources(
1011
nrf_sdh.c
1112
nrf_sdh_info.c
1213
nrf_sdh_soc.c
13-
irq_connect.c
1414
)
1515

16+
zephyr_library_sources_ifdef(CONFIG_NRF_SDH_BLE nrf_sdh_ble.c)
1617
zephyr_library_sources_ifdef(CONFIG_NRF_SDH_SOC_RAND_SEED rand_seed.c)
1718

18-
if(CONFIG_SOFTDEVICE_S115 OR CONFIG_SOFTDEVICE_S145)
19-
zephyr_library_sources(irq_forward.s)
19+
# IRQ setup
20+
if(CONFIG_SOFTDEVICE_BSIM)
21+
zephyr_library_sources(irq_connect_bsim.c)
22+
else()
23+
# ARM-only: IRQ connection, SVC forwarding and swap_helper suppression
2024
# Suppress the swap_helper.S file so that z_arm_svc can be defined manually
25+
zephyr_library_sources(irq_connect.c)
26+
zephyr_library_sources(irq_forward.s)
2127
set(cortex_m_dir ${ZEPHYR_BASE}/arch/arm/core/cortex_m)
2228
set_property(
2329
SOURCE ${cortex_m_dir}/swap_helper.S
@@ -26,7 +32,3 @@ if(CONFIG_SOFTDEVICE_S115 OR CONFIG_SOFTDEVICE_S145)
2632
)
2733
target_link_options(app PUBLIC "-Wl,--defsym=z_arm_svc=SVC_Handler")
2834
endif()
29-
30-
if(CONFIG_NRF_SDH_BLE)
31-
zephyr_library_sources(nrf_sdh_ble.c)
32-
endif()

subsys/softdevice_handler/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ endif # NRF_SDH_BLE
237237

238238
config NRF_SDH_SOC_RAND_SEED
239239
bool "Automatically seed SoftDevice random"
240-
depends on NRF_SECURITY
241-
depends on MBEDTLS_PSA_CRYPTO_C
240+
depends on (NRF_SECURITY && MBEDTLS_PSA_CRYPTO_C) || SOC_SERIES_BSIM_NRF54LX
242241
default y
243242
help
244243
Automatically seed SoftDevice using CRACEN to generate the random seed.

subsys/softdevice_handler/irq_connect.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
LOG_MODULE_DECLARE(nrf_sdh, CONFIG_NRF_SDH_LOG_LEVEL);
1616

17-
#if CONFIG_SOC_SERIES_NRF54L
1817
#include "irq_connect.h"
1918

19+
/* Handlers provided by the SoftDevice */
2020
extern void CLOCK_POWER_SD_IRQHandler(void);
2121
extern void RADIO_0_IRQHandler(void);
2222
extern void TIMER10_IRQHandler(void);
@@ -121,6 +121,4 @@ __attribute__((weak)) void C_CLOCK_POWER_SD_Handler(void)
121121
#endif
122122
}
123123

124-
#endif /* CONFIG_SOC_SERIES_NRF54L */
125-
126124
SYS_INIT(irq_init, APPLICATION, 0);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*
6+
* Register all SoftDevice IRQ handlers with the native simulator.
7+
* SD_EVT_IRQn (SWI01) is connected in nrf_sdh.c (sd_irq_init), same as on ARM.
8+
*/
9+
10+
#include <nrfx.h>
11+
#include <zephyr/init.h>
12+
#include <zephyr/irq.h>
13+
14+
/* Handlers provided by the linked SoftDevice library */
15+
extern void C_RTC0_Handler(void);
16+
extern void C_SIGNALLING_Handler(void);
17+
extern void C_RADIO_Handler(void);
18+
extern void C_POWER_CLOCK_Handler(void);
19+
extern void C_TIMER0_Handler(void);
20+
extern void C_ECB_Handler(void);
21+
extern void C_CCM_Handler(void);
22+
23+
#define SD_IRQ_PRIO_HIGH 0
24+
#define SD_IRQ_PRIO_LOW 4
25+
26+
#define IRQ_WRAPPER(name, handler) \
27+
static void name##_wrapper(const void *arg) { ARG_UNUSED(arg); handler(); }
28+
29+
IRQ_WRAPPER(grtc3, C_RTC0_Handler);
30+
IRQ_WRAPPER(swi00, C_SIGNALLING_Handler);
31+
IRQ_WRAPPER(radio0, C_RADIO_Handler);
32+
33+
IRQ_WRAPPER(clock_power, C_POWER_CLOCK_Handler);
34+
IRQ_WRAPPER(timer10, C_TIMER0_Handler);
35+
IRQ_WRAPPER(ecb00, C_ECB_Handler);
36+
IRQ_WRAPPER(aar00_ccm00, C_CCM_Handler);
37+
38+
#define REGISTER(irqn, irqp, wrapper) do { \
39+
(void)irq_connect_dynamic(irqn, irqp, wrapper##_wrapper, NULL, 0); \
40+
irq_enable(irqn); \
41+
} while (0)
42+
43+
static int softdevice_bsim_irq_init(void)
44+
{
45+
REGISTER(GRTC_3_IRQn, SD_IRQ_PRIO_HIGH, grtc3);
46+
REGISTER(TIMER10_IRQn, SD_IRQ_PRIO_HIGH, timer10);
47+
REGISTER(RADIO_0_IRQn, SD_IRQ_PRIO_HIGH, radio0);
48+
49+
REGISTER(SWI00_IRQn, SD_IRQ_PRIO_LOW, swi00);
50+
REGISTER(CLOCK_POWER_IRQn, SD_IRQ_PRIO_LOW, clock_power);
51+
REGISTER(ECB00_IRQn, SD_IRQ_PRIO_LOW, ecb00);
52+
REGISTER(AAR00_CCM00_IRQn, SD_IRQ_PRIO_LOW, aar00_ccm00);
53+
54+
return 0;
55+
}
56+
57+
SYS_INIT(softdevice_bsim_irq_init, APPLICATION, 0);

subsys/softdevice_handler/nrf_sdh.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdint.h>
77
#include <nrf_sdm.h>
88
#include <nrf_soc.h>
9+
#include <nrfx.h>
910
#include <bm/softdevice_handler/nrf_sdh.h>
1011
#include <bm/softdevice_handler/nrf_sdh_info.h>
1112
#include <bm/bm_irq.h>
@@ -131,7 +132,8 @@ static int nrf_sdh_enable(void)
131132
.hfint_ctiv = CONFIG_NRF_SDH_CLOCK_HFINT_CALIBRATION_INTERVAL,
132133
};
133134

134-
if (IS_ENABLED(CONFIG_NRF_SDH_LOG_SD_INFO)) {
135+
#if defined(CONFIG_NRF_SDH_LOG_SD_INFO) && !defined(CONFIG_SOFTDEVICE_BSIM)
136+
{
135137
const uint32_t base = FIXED_PARTITION_OFFSET(softdevice_partition);
136138
const struct nrf_sdh_info_version sd_ver = nrf_sdh_info_version_get(base);
137139
const struct nrf_sdh_info_unique_str sd_unique = nrf_sdh_info_unique_str_get(base);
@@ -149,6 +151,7 @@ static int nrf_sdh_enable(void)
149151
sd_ver.bugfix);
150152
}
151153
}
154+
#endif
152155

153156
err = sd_softdevice_enable(&clock_lf_cfg, softdevice_fault_handler);
154157
if (err) {
@@ -392,8 +395,7 @@ ISR_DIRECT_DECLARE(sd_direct_isr)
392395

393396
static int sd_irq_init(void)
394397
{
395-
BM_IRQ_DIRECT_CONNECT(SD_EVT_IRQn, SD_EVT_IRQ_PRI,
396-
sd_direct_isr, 0);
398+
BM_IRQ_DIRECT_CONNECT(SD_EVT_IRQn, SD_EVT_IRQ_PRI, sd_direct_isr, 0);
397399
irq_enable(SD_EVT_IRQn);
398400

399401
return 0;

subsys/softdevice_handler/nrf_sdh_ble.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
#include <bm/softdevice_handler/nrf_sdh_ble.h>
1313
#include <zephyr/logging/log.h>
1414

15+
#if defined(CONFIG_SOFTDEVICE_BSIM)
16+
extern uint32_t g_app_ram_base;
17+
extern uint32_t bsim_softdevice_ram_end;
18+
#define APP_RAM_START (bsim_softdevice_ram_end)
19+
#define SD_RAM_START (g_app_ram_base)
20+
#else
1521
#define APP_RAM_START DT_REG_ADDR(DT_CHOSEN(zephyr_sram))
1622
#define SD_RAM_START DT_REG_ADDR(DT_NODELABEL(cpuapp_sram))
23+
#endif
1724

1825
LOG_MODULE_DECLARE(nrf_sdh, CONFIG_NRF_SDH_LOG_LEVEL);
1926

subsys/softdevice_handler/rand_seed.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
#include <nrf_soc.h>
88
#include <bm/softdevice_handler/nrf_sdh_soc.h>
99
#include <zephyr/logging/log.h>
10-
#include <psa/crypto.h>
1110
#if CONFIG_HAS_HW_NRF_CRACEN
11+
#include <psa/crypto.h>
1212
#include <cracen_psa.h>
13-
#else
13+
#elif CONFIG_NRFX_CRACEN
1414
#include <nrfx_cracen.h>
1515
#endif
1616

1717
LOG_MODULE_DECLARE(nrf_sdh, CONFIG_NRF_SDH_LOG_LEVEL);
1818

19-
/* Extern in nrf_sdh.c */
20-
void sdh_soc_rand_seed(uint32_t evt, void *ctx)
19+
static void sdh_soc_rand_seed(uint32_t evt, void *ctx)
2120
{
2221
uint32_t nrf_err;
2322
uint8_t seed[SD_RAND_SEED_SIZE];
@@ -37,7 +36,7 @@ void sdh_soc_rand_seed(uint32_t evt, void *ctx)
3736
LOG_ERR("Failed to generate true random number, psa_status %d", status);
3837
return;
3938
}
40-
#else
39+
#elif CONFIG_NRFX_CRACEN && !CONFIG_SOFTDEVICE_BSIM
4140
/* Selected when we don't have CRACEN Crypto HW available, like for nRF54LS05B
4241
* In this case the cracen_psa api isn't available and we should use nrfx api
4342
*/
@@ -47,6 +46,8 @@ void sdh_soc_rand_seed(uint32_t evt, void *ctx)
4746
LOG_ERR("Failed to generate true random number, err %d", err);
4847
return;
4948
}
49+
#elif CONFIG_SOFTDEVICE_BSIM
50+
/* Seed with heap garbage */
5051
#endif
5152

5253
nrf_err = sd_rand_seed_set(seed);

0 commit comments

Comments
 (0)