Skip to content

Commit 44f3816

Browse files
committed
Fixes for native sim
1 parent 47990e3 commit 44f3816

18 files changed

Lines changed: 243 additions & 34 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repos:
2828
lib/mbedtls_errors/generate_errors.diff
2929
)
3030
- repo: https://github.com/codespell-project/codespell
31-
rev: v2.2.4
31+
rev: v2.4.1
3232
hooks:
3333
- id: codespell
3434
args: [-w]

main.c

Lines changed: 2 additions & 7 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"
@@ -1161,13 +1162,7 @@ int __attribute__((used)) main(void) {
11611162
void gc_collect(void) {
11621163
gc_collect_start();
11631164

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));
1165+
gc_helper_collect_regs_and_stack();
11711166

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

ports/zephyr-cp/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ BUILD ?= build-$(BOARD)
88

99
TRANSLATION ?= en_US
1010

11-
.PHONY: $(BUILD)/zephyr-cp/zephyr/zephyr.elf flash debug clean menuconfig all clean-all test
11+
.PHONY: $(BUILD)/zephyr-cp/zephyr/zephyr.elf flash debug run clean menuconfig all clean-all test
1212

1313
$(BUILD)/zephyr-cp/zephyr/zephyr.elf:
1414
python cptools/pre_zephyr_build_prep.py $(BOARD)
@@ -20,12 +20,18 @@ $(BUILD)/firmware.elf: $(BUILD)/zephyr-cp/zephyr/zephyr.elf
2020
$(BUILD)/firmware.hex: $(BUILD)/zephyr-cp/zephyr/zephyr.elf
2121
cp $(BUILD)/zephyr-cp/zephyr/zephyr.hex $@
2222

23+
$(BUILD)/firmware.exe: $(BUILD)/zephyr-cp/zephyr/zephyr.elf
24+
cp $(BUILD)/zephyr-cp/zephyr/zephyr.exe $@
25+
2326
flash: $(BUILD)/zephyr-cp/zephyr/zephyr.elf
2427
west flash -d $(BUILD)
2528

2629
debug: $(BUILD)/zephyr-cp/zephyr/zephyr.elf
2730
west debug -d $(BUILD)
2831

32+
run: $(BUILD)/firmware.exe
33+
$^
34+
2935
menuconfig:
3036
west build --sysbuild -d $(BUILD) -t menuconfig
3137

ports/zephyr-cp/boards/board_aliases.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(pca10056_BOARD_ALIAS nrf52840dk/nrf52840)
22
set(renesas_ek_ra6m5_BOARD_ALIAS ek_ra6m5)
33
set(renesas_ek_ra8d1_BOARD_ALIAS ek_ra8d1)
4+
set(native_native_sim_BOARD_ALIAS native_sim)
45
set(nordic_nrf54l15dk_BOARD_ALIAS nrf54l15dk/nrf54l15/cpuapp)
56
set(nordic_nrf54h20dk_BOARD_ALIAS nrf54h20dk/nrf54h20/cpuapp)
67
set(nordic_nrf5340dk_BOARD_ALIAS nrf5340dk/nrf5340/cpuapp)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# This file is autogenerated when a board is built. Do not edit. Do commit it to git. Other scripts use its info.
2+
name = "POSIX/Native Boards Native simulator - native_sim"
3+
4+
[modules]
5+
__future__ = false
6+
_bleio = false
7+
_eve = false
8+
_pew = false
9+
_pixelmap = false
10+
_stage = false
11+
adafruit_bus_device = false
12+
adafruit_pixelbuf = false
13+
aesio = false
14+
alarm = false
15+
analogbufio = false
16+
analogio = false
17+
atexit = false
18+
audiobusio = false
19+
audiocore = false
20+
audiodelays = false
21+
audiofilters = false
22+
audiofreeverb = false
23+
audioio = false
24+
audiomixer = false
25+
audiomp3 = false
26+
audiopwmio = false
27+
aurora_epaper = false
28+
bitbangio = false
29+
bitmapfilter = true # Zephyr board has busio
30+
bitmaptools = true # Zephyr board has busio
31+
bitops = false
32+
board = false
33+
busdisplay = true # Zephyr board has busio
34+
busio = true # Zephyr board has busio
35+
camera = false
36+
canio = false
37+
codeop = false
38+
countio = false
39+
digitalio = true
40+
displayio = true # Zephyr board has busio
41+
dotclockframebuffer = false
42+
dualbank = false
43+
epaperdisplay = true # Zephyr board has busio
44+
floppyio = false
45+
fontio = true # Zephyr board has busio
46+
fourwire = true # Zephyr board has busio
47+
framebufferio = true # Zephyr board has busio
48+
frequencyio = false
49+
getpass = false
50+
gifio = false
51+
gnss = false
52+
hashlib = false
53+
i2cdisplaybus = true # Zephyr board has busio
54+
i2ctarget = false
55+
imagecapture = false
56+
ipaddress = false
57+
is31fl3741 = false
58+
jpegio = false
59+
keypad = false
60+
keypad_demux = false
61+
locale = false
62+
lvfontio = true # Zephyr board has busio
63+
math = false
64+
max3421e = false
65+
mdns = false
66+
memorymap = false
67+
memorymonitor = false
68+
microcontroller = true
69+
mipidsi = false
70+
msgpack = false
71+
neopixel_write = false
72+
nvm = false
73+
onewireio = false
74+
os = true
75+
paralleldisplaybus = false
76+
ps2io = false
77+
pulseio = false
78+
pwmio = false
79+
qrio = false
80+
rainbowio = true
81+
random = true
82+
rclcpy = false
83+
rgbmatrix = false
84+
rotaryio = false
85+
rtc = false
86+
sdcardio = true # Zephyr board has busio
87+
sdioio = false
88+
sharpdisplay = true # Zephyr board has busio
89+
socketpool = false
90+
spitarget = false
91+
ssl = false
92+
storage = true # Zephyr board has flash
93+
struct = true
94+
supervisor = true
95+
synthio = false
96+
terminalio = true # Zephyr board has busio
97+
tilepalettemapper = true # Zephyr board has busio
98+
time = true
99+
touchio = false
100+
traceback = true
101+
uheap = false
102+
usb = false
103+
usb_cdc = false
104+
usb_hid = false
105+
usb_host = false
106+
usb_midi = false
107+
usb_video = false
108+
ustack = false
109+
vectorio = true # Zephyr board has busio
110+
warnings = true
111+
watchdog = false
112+
wifi = false
113+
zephyr_kernel = false
114+
zlib = false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CIRCUITPY_BUILD_EXTENSIONS = ["elf"]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_EMUL=y
2+
CONFIG_GPIO=y
3+
CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=n
4+
5+
# So we can test safe mode
6+
CONFIG_NATIVE_SIM_REBOOT=y
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Device tree overlay for CircuitPython on native_sim.
5+
* Adds simulated SRAM region required by CircuitPython build system.
6+
*/
7+
8+
#include <zephyr/dt-bindings/memory-attr/memory-attr-arm.h>
9+
10+
/ {
11+
sram0: memory@20000000 {
12+
device_type = "memory";
13+
compatible = "zephyr,memory-region", "mmio-sram";
14+
reg = <0x20000000 DT_SIZE_M(1)>;
15+
zephyr,memory-region = "SRAM";
16+
};
17+
18+
chosen {
19+
zephyr,sram = &sram0;
20+
/delete-property/ zephyr,flash;
21+
/delete-property/ zephyr,code-partition;
22+
};
23+
};
24+
25+
&flash0 {
26+
/delete-node/ partitions;
27+
partitions {
28+
compatible = "fixed-partitions";
29+
#address-cells = <1>;
30+
#size-cells = <1>;
31+
32+
circuitpy_partition: partition@0 {
33+
label = "circuitpy";
34+
reg = <0x00000000 DT_SIZE_K(2048)>;
35+
};
36+
};
37+
};
38+
39+
#include "../app.overlay"

ports/zephyr-cp/common-hal/busio/UART.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrat
126126
struct uart_config config;
127127
uart_config_get(self->uart_device, &config);
128128
config.baudrate = baudrate;
129-
uart_config_set(self->uart_device, &config);
129+
uart_configure(self->uart_device, &config);
130130
}
131131

132132
mp_float_t common_hal_busio_uart_get_timeout(busio_uart_obj_t *self) {

ports/zephyr-cp/common-hal/microcontroller/Processor.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ float common_hal_mcu_processor_get_temperature(void) {
2121

2222
extern uint32_t SystemCoreClock;
2323
uint32_t common_hal_mcu_processor_get_frequency(void) {
24+
#ifdef __ARM__
2425
return SystemCoreClock;
26+
#else
27+
return CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
28+
#endif
2529
}
2630

2731
float common_hal_mcu_processor_get_voltage(void) {

0 commit comments

Comments
 (0)