Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,7 @@ TAGS

# git-review-web outputs
.review

# Zephyr trace files
**/channel0_0
**/*.perfetto-trace
5 changes: 4 additions & 1 deletion locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2067,10 +2067,13 @@ msgstr ""

#: ports/espressif/common-hal/socketpool/SocketPool.c
#: ports/raspberrypi/common-hal/socketpool/SocketPool.c
#: ports/zephyr-cp/common-hal/socketpool/SocketPool.c
msgid "SocketPool can only be used with wifi.radio"
msgstr ""

#: ports/zephyr-cp/common-hal/socketpool/SocketPool.c
msgid "SocketPool can only be used with wifi.radio or hostnetwork.HostNetwork"
msgstr ""

#: shared-bindings/aesio/aes.c
msgid "Source and destination buffers must be the same length"
msgstr ""
Expand Down
13 changes: 11 additions & 2 deletions ports/zephyr-cp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ BUILD ?= build-$(BOARD)

TRANSLATION ?= en_US


.PHONY: $(BUILD)/zephyr-cp/zephyr/zephyr.elf flash recover debug run clean menuconfig all clean-all test fetch-port-submodules
.PHONY: $(BUILD)/zephyr-cp/zephyr/zephyr.elf flash recover debug run run-sim clean menuconfig all clean-all test fetch-port-submodules

$(BUILD)/zephyr-cp/zephyr/zephyr.elf:
python cptools/pre_zephyr_build_prep.py $(BOARD)
Expand All @@ -36,6 +35,16 @@ debug: $(BUILD)/zephyr-cp/zephyr/zephyr.elf
run: $(BUILD)/firmware.exe
$^

run-sim:
$(MAKE) BOARD=native_native_sim BUILD=build-native_native_sim build-native_native_sim/firmware.exe
truncate -s 2M build-native_native_sim/flash.bin
mformat -i build-native_native_sim/flash.bin ::
@if [ -d CIRCUITPY ] && [ -n "$$(find CIRCUITPY -mindepth 1 -print -quit)" ]; then \
echo "Populating build-native_native_sim/flash.bin from ./CIRCUITPY"; \
mcopy -s -i build-native_native_sim/flash.bin CIRCUITPY/* ::; \
fi
build-native_native_sim/firmware.exe --flash=build-native_native_sim/flash.bin --flash_rm -wait_uart -rt

menuconfig:
west build --sysbuild -d $(BUILD) -t menuconfig

Expand Down
14 changes: 14 additions & 0 deletions ports/zephyr-cp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ make BOARD=nordic_nrf7002dk
This uses Zephyr's cmake to generate Makefiles that then delegate to
`tools/cpbuild/build_circuitpython.py` to build the CircuitPython bits in parallel.

## Running the native simulator

From `ports/zephyr-cp`, run:

```sh
make run-sim
```

`run-sim` starts the native simulator in realtime.
It prints the PTY path to connect to the simulator REPL.
If a local `./CIRCUITPY/` folder exists, its files are used as the simulator's CIRCUITPY drive.

Edit files in `./CIRCUITPY` (for example `code.py`) and rerun `make run-sim` to test changes.

## Testing other boards

[Any Zephyr board](https://docs.zephyrproject.org/latest/boards/index.html#) can
Expand Down
37 changes: 37 additions & 0 deletions ports/zephyr-cp/bindings/hostnetwork/HostNetwork.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2026 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include "bindings/hostnetwork/HostNetwork.h"

#include "py/runtime.h"

//| class HostNetwork:
//| """Native networking for the host simulator."""
//|
//| def __init__(self) -> None:
//| """Create a HostNetwork instance."""
//| ...
//|
static mp_obj_t hostnetwork_hostnetwork_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);

hostnetwork_hostnetwork_obj_t *self = mp_obj_malloc(hostnetwork_hostnetwork_obj_t, &hostnetwork_hostnetwork_type);
common_hal_hostnetwork_hostnetwork_construct(self);
return MP_OBJ_FROM_PTR(self);
}

static const mp_rom_map_elem_t hostnetwork_hostnetwork_locals_dict_table[] = {
};
static MP_DEFINE_CONST_DICT(hostnetwork_hostnetwork_locals_dict, hostnetwork_hostnetwork_locals_dict_table);

MP_DEFINE_CONST_OBJ_TYPE(
hostnetwork_hostnetwork_type,
MP_QSTR_HostNetwork,
MP_TYPE_FLAG_NONE,
make_new, hostnetwork_hostnetwork_make_new,
locals_dict, &hostnetwork_hostnetwork_locals_dict
);
19 changes: 19 additions & 0 deletions ports/zephyr-cp/bindings/hostnetwork/HostNetwork.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2026 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#pragma once

#include <stdint.h>

#include "py/obj.h"

typedef struct {
mp_obj_base_t base;
} hostnetwork_hostnetwork_obj_t;

extern const mp_obj_type_t hostnetwork_hostnetwork_type;

void common_hal_hostnetwork_hostnetwork_construct(hostnetwork_hostnetwork_obj_t *self);
26 changes: 26 additions & 0 deletions ports/zephyr-cp/bindings/hostnetwork/__init__.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2026 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include "py/obj.h"

#include "bindings/hostnetwork/__init__.h"
#include "bindings/hostnetwork/HostNetwork.h"

//| """Host networking support for the native simulator."""
//|

static const mp_rom_map_elem_t hostnetwork_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hostnetwork) },
{ MP_ROM_QSTR(MP_QSTR_HostNetwork), MP_ROM_PTR(&hostnetwork_hostnetwork_type) },
};
static MP_DEFINE_CONST_DICT(hostnetwork_module_globals, hostnetwork_module_globals_table);

const mp_obj_module_t hostnetwork_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&hostnetwork_module_globals,
};

MP_REGISTER_MODULE(MP_QSTR_hostnetwork, hostnetwork_module);
11 changes: 11 additions & 0 deletions ports/zephyr-cp/bindings/hostnetwork/__init__.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2026 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#pragma once

#include "bindings/hostnetwork/HostNetwork.h"

extern hostnetwork_hostnetwork_obj_t common_hal_hostnetwork_obj;
1 change: 1 addition & 0 deletions ports/zephyr-cp/boards/frdm_rw612.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CONFIG_MBEDTLS_PKCS1_V15=y
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED=y
CONFIG_MBEDTLS_ENTROPY_C=y
CONFIG_MBEDTLS_CTR_DRBG_ENABLED=y
CONFIG_MBEDTLS_SHA1=y
CONFIG_MBEDTLS_USE_PSA_CRYPTO=n

CONFIG_BT=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ frequencyio = false
getpass = false
gifio = false
gnss = false
hashlib = false
hashlib = true # Zephyr networking enabled
hostnetwork = true # Zephyr board has hostnetwork
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down Expand Up @@ -87,7 +88,7 @@ rtc = false
sdcardio = true # Zephyr board has busio
sdioio = false
sharpdisplay = true # Zephyr board has busio
socketpool = false
socketpool = true # Zephyr networking enabled
spitarget = false
ssl = false
storage = true # Zephyr board has flash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
16 changes: 16 additions & 0 deletions ports/zephyr-cp/boards/native_sim.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@ CONFIG_I2C_EMUL=y
CONFIG_EEPROM=y
CONFIG_EEPROM_AT24=y
CONFIG_EEPROM_AT2X_EMUL=y

CONFIG_NETWORKING=y
CONFIG_NET_IPV4=y
CONFIG_NET_TCP=y
CONFIG_NET_SOCKETS=y
CONFIG_ETH_NATIVE_TAP=n
CONFIG_NET_DRIVERS=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_NATIVE_OFFLOADED_SOCKETS=y
CONFIG_HEAP_MEM_POOL_SIZE=1024

CONFIG_NET_LOG=y

CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_SHA1=y
CONFIG_MBEDTLS_SHA256=y
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ frequencyio = false
getpass = false
gifio = false
gnss = false
hashlib = false
hashlib = true # Zephyr networking enabled
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ frequencyio = false
getpass = false
gifio = false
gnss = false
hashlib = false
hashlib = true # Zephyr networking enabled
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ getpass = false
gifio = false
gnss = false
hashlib = false
hostnetwork = false
i2cdisplaybus = true # Zephyr board has busio
i2cioexpander = false
i2ctarget = false
Expand Down
15 changes: 15 additions & 0 deletions ports/zephyr-cp/common-hal/hostnetwork/HostNetwork.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2026 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include "bindings/hostnetwork/HostNetwork.h"

hostnetwork_hostnetwork_obj_t common_hal_hostnetwork_obj = {
.base = { &hostnetwork_hostnetwork_type },
};

void common_hal_hostnetwork_hostnetwork_construct(hostnetwork_hostnetwork_obj_t *self) {
(void)self;
}
11 changes: 11 additions & 0 deletions ports/zephyr-cp/common-hal/hostnetwork/HostNetwork.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2026 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#pragma once

#include "bindings/hostnetwork/HostNetwork.h"

extern hostnetwork_hostnetwork_obj_t common_hal_hostnetwork_obj;
Loading