Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit 71a8a9e

Browse files
rugeGerritsenaescolar
authored andcommitted
nrfx: Use actual nrfx instead of manually modified files
Warning. This commit breaks backwards compatibility with Zephyr <= 2.4.0. With nrfx 2.3.0 it is possible to include the MDK files on non-ARM platforms. As the MDK has a depenency to cmsis core files, a simple mocked core_cm4.h has been provided. By defining NRF_DECLARE_ONLY and NRF_STATIC_INLINE to nothing, no functions are inlined. This ensures that it is possible to mock the peripherals. For a non-zephyr build, the application must provide the environment varianble NRFX_BASE. The user of the nRF MDK or nrfx must ensure that the peripheral pointers are redefined before they are used. This is done in nrfx_bsim_redef.h. Include this header after including nrf.h or similar. When using nrfx, this inclusion can be placed in nrfx_glue.h For non-zephyr builds, a nrfx_config and nrfx_glue is provided. Other builds should include nrfx_config_bsim.h and nrfx_glue_bsim.h in their config and glue files. The original implementation of the HAL APIs from the real nrfx is included in `nrf_hal_originals.c`. All these functions are labelled as weak, so they can be replaced as needed with new definition in `src/nrfx/hal/` This removes the need for duplicating code. Signed-off-by: Rubin Gerritsen <[email protected]>
1 parent 401fa4f commit 71a8a9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+665
-5512
lines changed

CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ if(CONFIG_BOARD_NRF52_BSIM)
2222
# module, so that the local modified versions of nrfx files are used instead
2323
# of those from the original nrfx.
2424
target_include_directories(zephyr_interface BEFORE INTERFACE
25-
${CMAKE_CURRENT_SOURCE_DIR}/src/
26-
${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/
27-
${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/hal/
28-
${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/mdk/
25+
${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/mdk_replacements
2926
)
3027

3128
zephyr_include_directories(
3229
src/HW_models/
30+
src/nrfx/nrfx_replacements
3331
)
3432

3533
zephyr_library()
@@ -44,7 +42,6 @@ if(CONFIG_BOARD_NRF52_BSIM)
4442
$ENV{BSIM_COMPONENTS_PATH}/ext_2G4_libPhyComv1/src/
4543
$ENV{BSIM_COMPONENTS_PATH}/libRandv2/src/
4644
src/HW_models/
47-
src/nrfx/
4845
)
4946

5047
endif()

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ include ${BSIM_BASE_PATH}/common/pre.make.inc
88

99
SRCS:=$(shell find src/ -name "*.c")
1010

11+
ifndef NRFX_BASE
12+
$(error NRFX_BASE must be set to the nrfx checkout folder)
13+
endif
14+
1115
INCLUDES:=-I${libUtilv1_COMP_PATH}/src/ \
1216
-I${libPhyComv1_COMP_PATH}/src/ \
1317
-I${2G4_libPhyComv1_COMP_PATH}/src \
1418
-I${libRandv2_COMP_PATH}/src/ \
19+
-Isrc/nrfx/mdk_replacements \
1520
-Isrc/HW_models/ \
16-
-Isrc/nrfx/
21+
-Isrc/nrfx_config \
22+
-Isrc/nrfx/nrfx_replacements \
23+
-I${NRFX_BASE} \
24+
-I${NRFX_BASE}/mdk
25+
1726

1827
LIB_NAME:=libNRF52_hw_models.32
1928
A_LIBS:=
@@ -25,7 +34,8 @@ ARCH:=-m32
2534
WARNINGS:=-Wall -pedantic
2635
COVERAGE:=
2736
CFLAGS:=${ARCH} ${DEBUG} ${OPT} ${WARNINGS} -MMD -MP -std=c11 \
28-
${INCLUDES} -fdata-sections -ffunction-sections
37+
${INCLUDES} -fdata-sections -ffunction-sections \
38+
-DNRF52832_XXAA
2939
LDFLAGS:=${ARCH} ${COVERAGE}
3040
CPPFLAGS:=
3141

docs/README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
**Models of some of the HW present in a NRF52xxx.**<br>
22
Where relevant differences exist, these models try to align with a NRF52382.
33

4-
This repo contains both models of the NRF52 HW as well as a replacement nRFx
5-
HAL.<br>
6-
This replacement HAL is a modified version of the real nRFx to be used with
7-
these models.
8-
With it, the Zephyr SW should work without needing further changes.
4+
This repo contains both models of the NRF52 HW as well as some replacement nrfx
5+
HAL functions. When used in combination with the real nrfx, these should enable code
6+
meant for the nrfx to run without needing further changes.
7+
This includes Zephyr SW.
8+
9+
When compiling this component using the provided Makefile (not with Zephyr's build system),
10+
the environment variable `NRFX_BASE` must be set to the path where a nrfx has been cloned.
11+
The nrfx must be at least version 2.3.0.
12+
So for example, if the nrfx has been cloned as:
13+
14+
```
15+
cd /some_path/nrfx/
16+
git clone [email protected]:NordicSemiconductor/nrfx.git .
17+
```
18+
`NRFX_BASE` must be set as:
19+
20+
```
21+
export NRFX_BASE=/some_path/nrfx/
22+
```
23+
924
See the [nrfx/hal/README.md](../src/nrfx/hal/README.md) for more details.
1025

1126
This models can be used directly with

docs/README_HW_models.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ thread into the HW models thread.
8686

8787
### The SW registers IF
8888

89-
Each perihperal model which has HW registers accessible by SW, presents
89+
Each peripheral model which has HW registers accessible by SW, presents
9090
a structure which matches those registers' layout.
9191
This structure will be allocated somewhere in the process memory, but certainly
9292
not in the same address as in the real HW.

src/HW_models/NRF_AAR.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef _NRF_HW_MODEL_AAR_H
77
#define _NRF_HW_MODEL_AAR_H
88

9-
#include "NRF_regs.h"
9+
#include "nrfx.h"
1010

1111
#ifdef __cplusplus
1212
extern "C"{

src/HW_models/NRF_AES_CCM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef _NRF_HW_MODEL_AES_CCM_H
77
#define _NRF_HW_MODEL_AES_CCM_H
88

9-
#include "NRF_regs.h"
9+
#include "nrfx.h"
1010
#include <stdbool.h>
1111

1212
#ifdef __cplusplus

src/HW_models/NRF_AES_ECB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef _NRF_HW_MODEL_AES_ECB_H
77
#define _NRF_HW_MODEL_AES_ECB_H
88

9-
#include "NRF_regs.h"
9+
#include "nrfx.h"
1010

1111
#ifdef __cplusplus
1212
extern "C"{

src/HW_models/NRF_CLOCK.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef _NRF_HW_MODEL_CLOCK_H
77
#define _NRF_HW_MODEL_CLOCK_H
88

9-
#include "NRF_regs.h"
9+
#include "nrfx.h"
1010

1111
#ifdef __cplusplus
1212
extern "C"{

src/HW_models/NRF_FICR.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef _NRF_HW_MODEL_FICR_H
77
#define _NRF_HW_MODEL_FICR_H
88

9-
#include "NRF_regs.h"
9+
#include "nrfx.h"
1010

1111
#ifdef __cplusplus
1212
extern "C"{

src/HW_models/NRF_GPIO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef _NRF_HW_MODEL_GPIO_H
77
#define _NRF_HW_MODEL_GPIO_H
88

9-
#include "NRF_regs.h"
9+
#include "nrfx.h"
1010

1111
#ifdef __cplusplus
1212
extern "C"{

0 commit comments

Comments
 (0)