Skip to content

Commit e785bac

Browse files
authored
Merge pull request adafruit#10795 from tannewt/zephyr_native_sim
Add Zephyr native_sim tests
2 parents 4b7b098 + f8c06e3 commit e785bac

File tree

46 files changed

+2264
-256
lines changed

Some content is hidden

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

46 files changed

+2264
-256
lines changed

.github/actions/deps/ports/zephyr-cp/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: Fetch Zephyr port deps
33
runs:
44
using: composite
55
steps:
6-
- name: Get libusb
6+
- name: Get libusb and mtools
77
if: runner.os == 'Linux'
88
run: |
99
sudo apt-get update
10-
sudo apt-get install -y libusb-1.0-0-dev libudev-dev
10+
sudo apt-get install -y libusb-1.0-0-dev libudev-dev mtools
1111
shell: bash
1212
- name: Setup Zephyr project
1313
uses: zephyrproject-rtos/action-zephyr-setup@v1

.github/workflows/run-tests.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ jobs:
8686
python-version: 3.13
8787
- name: Set up Zephyr
8888
uses: ./.github/actions/deps/ports/zephyr-cp
89+
- name: Set up submodules
90+
id: set-up-submodules
91+
uses: ./.github/actions/deps/submodules
92+
with:
93+
target: zephyr-cp
8994
- name: Set up external
9095
uses: ./.github/actions/deps/external
91-
- name: Run Zephyr build tests
96+
- name: Build native sim target
97+
run: make -C ports/zephyr-cp -j2 BOARD=native_native_sim
98+
- name: Run Zephyr tests
9299
run: make -C ports/zephyr-cp test

main.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "py/stackctrl.h"
2222

2323
#include "shared/readline/readline.h"
24+
#include "shared/runtime/gchelper.h"
2425
#include "shared/runtime/pyexec.h"
2526

2627
#include "background.h"
@@ -30,7 +31,6 @@
3031
#include "supervisor/cpu.h"
3132
#include "supervisor/filesystem.h"
3233
#include "supervisor/port.h"
33-
#include "supervisor/shared/cpu_regs.h"
3434
#include "supervisor/shared/reload.h"
3535
#include "supervisor/shared/safe_mode.h"
3636
#include "supervisor/shared/serial.h"
@@ -1161,13 +1161,7 @@ int __attribute__((used)) main(void) {
11611161
void gc_collect(void) {
11621162
gc_collect_start();
11631163

1164-
// Load register values onto the stack. They get collected below with the rest of the stack.
1165-
size_t regs[SAVED_REGISTER_COUNT];
1166-
mp_uint_t sp = cpu_get_regs_and_sp(regs);
1167-
1168-
// This naively collects all object references from an approximate stack
1169-
// range.
1170-
gc_collect_root((void **)sp, ((mp_uint_t)port_stack_get_top() - sp) / sizeof(mp_uint_t));
1164+
gc_helper_collect_regs_and_stack();
11711165

11721166
// This collects root pointers from the VFS mount table. Some of them may
11731167
// have lost their references in the VM even though they are mounted.

ports/analog/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ LINKERFILE = linking/$(MCU_VARIANT_LOWER)_cktpy.ld
154154
LDFLAGS += -nostartfiles -specs=nano.specs
155155
endif
156156

157-
SRC_S_UPPER = supervisor/shared/cpu_regs.S
158157
SRC_S += $(STARTUPFILE)
158+
SRC_S += shared/runtime/gchelper_thumb2.s
159+
160+
SRC_C += shared/runtime/gchelper_native.c
159161

160162
# Needed to compile some MAX32 headers
161163
CFLAGS += -D$(MCU_VARIANT_UPPER) \
@@ -252,7 +254,6 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
252254
endif
253255
OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o))
254256
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
255-
OBJ += $(addprefix $(BUILD)/, $(SRC_S_UPPER:.S=.o))
256257
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
257258

258259
# List of sources for qstr extraction

ports/atmel-samd/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ SRC_C += \
284284
lib/tinyusb/src/portable/microchip/samd/dcd_samd.c \
285285
mphalport.c \
286286
reset.c \
287+
shared/runtime/gchelper_native.c \
287288
timer_handler.c \
288289
$(SRC_PERIPHERALS) \
289290

@@ -308,7 +309,11 @@ ifeq ($(CIRCUITPY_AUDIOBUSIO),1)
308309
SRC_C += peripherals/samd/i2s.c peripherals/samd/$(PERIPHERALS_CHIP_FAMILY)/i2s.c
309310
endif
310311

311-
SRC_S_UPPER = supervisor/shared/cpu_regs.S
312+
ifeq ($(CHIP_FAMILY), samd21)
313+
SRC_S += shared/runtime/gchelper_thumb1.s
314+
else
315+
SRC_S += shared/runtime/gchelper_thumb2.s
316+
endif
312317

313318
OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
314319
OBJ += $(addprefix $(BUILD)/, $(SRC_ASF:.c=.o))
@@ -317,7 +322,7 @@ ifeq ($(INTERNAL_LIBM),1)
317322
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
318323
endif
319324
OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o))
320-
OBJ += $(addprefix $(BUILD)/, $(SRC_S_UPPER:.S=.o))
325+
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
321326
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
322327

323328
QSTR_GLOBAL_REQUIREMENTS += $(HEADER_BUILD)/sdiodata.h

ports/broadcom/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ SRC_C += bindings/videocore/__init__.c \
5959

6060
SRC_S = peripherals/broadcom/boot$(SUFFIX).s
6161

62+
SRC_C += shared/runtime/gchelper_generic.c
63+
6264
OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
6365
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o))
6466
ifeq ($(INTERNAL_LIBM),1)

ports/cxd56/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ LDFLAGS = \
110110

111111
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_CXD56 -DCFG_TUD_MIDI_RX_BUFSIZE=512 -DCFG_TUD_CDC_RX_BUFSIZE=1024 -DCFG_TUD_MIDI_TX_BUFSIZE=512 -DCFG_TUD_CDC_TX_BUFSIZE=1024 -DCFG_TUD_MSC_BUFSIZE=512 $(CFLAGS_MOD)
112112

113-
SRC_S_UPPER = supervisor/shared/cpu_regs.S
113+
SRC_S = shared/runtime/gchelper_thumb2.s
114+
115+
SRC_C += shared/runtime/gchelper_native.c
114116

115117
SRC_C += \
116118
background.c \
@@ -120,7 +122,7 @@ SRC_C += \
120122
lib/tinyusb/src/portable/sony/cxd56/dcd_cxd56.c \
121123

122124
OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
123-
OBJ += $(addprefix $(BUILD)/, $(SRC_S_UPPER:.S=.o))
125+
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
124126
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o))
125127
ifeq ($(INTERNAL_LIBM),1)
126128
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))

ports/espressif/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,12 @@ ifeq ($(IDF_TARGET_ARCH),xtensa)
216216
# `#include "xtensa/xtensa_api.h"`.
217217

218218
CFLAGS += -mlongcalls -isystem esp-idf/components/xtensa/deprecated_include/ -Wno-error=cpp
219+
CFLAGS += -DMICROPY_GCREGS_SETJMP=1
219220

220221
# Wrap longjmp with a patched version that protects register window update with a critical section
221222
LDFLAGS += -Wl,--wrap=longjmp
223+
224+
SRC_C += shared/runtime/gchelper_generic.c
222225
else ifeq ($(IDF_TARGET_ARCH),riscv)
223226

224227
ifeq ($(IDF_TARGET),esp32p4)
@@ -230,6 +233,9 @@ else ifeq ($(IDF_TARGET_ARCH),riscv)
230233
LDFLAGS += \
231234
-Lesp-idf/components/riscv/ld \
232235
-Trom.api.ld
236+
237+
SRC_C += shared/runtime/gchelper_native.c
238+
SRC_S = shared/runtime/gchelper_rv32i.s
233239
endif
234240

235241

@@ -585,16 +591,14 @@ FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
585591
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
586592
endif
587593

588-
SRC_S_UPPER = supervisor/shared/cpu_regs.S
589-
590594
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
591595
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o))
592596
ifeq ($(INTERNAL_LIBM),1)
593597
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
594598
endif
595599
OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o))
596600
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
597-
OBJ += $(addprefix $(BUILD)/, $(SRC_S_UPPER:.S=.o))
601+
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
598602

599603
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
600604
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os

ports/espressif/boards/m5stack_cores3_se/board.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ static bool display_init(void) {
4646
common_hal_fourwire_fourwire_construct(
4747
bus,
4848
spi,
49-
&pin_GPIO35, // DC
50-
&pin_GPIO3, // CS
49+
MP_OBJ_FROM_PTR(&pin_GPIO35), // DC
50+
MP_OBJ_FROM_PTR(&pin_GPIO3), // CS
5151
NULL, // RST
5252
40000000, // baudrate
5353
0, // polarity

ports/litex/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ SRC_C += lib/tinyusb/src/portable/valentyusb/eptri/dcd_eptri.c
7878
endif
7979

8080
SRC_S_UPPER = \
81-
crt0-vexriscv.S \
82-
supervisor/shared/cpu_regs.S
81+
crt0-vexriscv.S
82+
83+
SRC_S = shared/runtime/gchelper_rv32i.s
84+
85+
SRC_C += shared/runtime/gchelper_native.c
8386

8487
$(BUILD)/lib/tlsf/tlsf.o: CFLAGS += -Wno-cast-align
8588

@@ -94,6 +97,7 @@ ifeq ($(INTERNAL_LIBM),1)
9497
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
9598
endif
9699
OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o))
100+
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
97101
OBJ += $(addprefix $(BUILD)/, $(SRC_S_UPPER:.S=.o))
98102
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
99103

0 commit comments

Comments
 (0)