From 9fad8575343f3680ba8fbf5e7c35feff6c6328ac Mon Sep 17 00:00:00 2001 From: Federico Roux Date: Wed, 5 Nov 2025 12:43:24 +0000 Subject: [PATCH] Ocre containers: Adding support for NRF5340-DK board WIP: Using nordic NRF5340DK board for testing and leveraging Ocre containers. Currently adding minimal support to make it compile and run on the actual hardware. Will continue adding configs across with the functionalities Signed-off-by: Federico Roux --- boards/nrf5340dk_nrf5340_cpuapp.conf | 79 +++++++++++++++++++++++++ boards/nrf5340dk_nrf5340_cpuapp.overlay | 34 +++++++++++ build.sh | 5 ++ src/ocre/ocre_gpio/ocre_gpio.c | 8 +-- west.yml | 5 +- 5 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 boards/nrf5340dk_nrf5340_cpuapp.conf create mode 100644 boards/nrf5340dk_nrf5340_cpuapp.overlay diff --git a/boards/nrf5340dk_nrf5340_cpuapp.conf b/boards/nrf5340dk_nrf5340_cpuapp.conf new file mode 100644 index 00000000..501754d7 --- /dev/null +++ b/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -0,0 +1,79 @@ +CONFIG_ARM_MPU=y +CONFIG_MAIN_STACK_SIZE=4096 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 +CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=-1 +CONFIG_HEAP_MEM_POOL_SIZE=32768 + +# Container defaults - Reduced for nRF5340's limited RAM +CONFIG_MAX_CONTAINERS=2 +CONFIG_OCRE_WAMR_HEAP_BUFFER_SIZE=180000 +CONFIG_OCRE_CONTAINER_DEFAULT_HEAP_SIZE=4096 +CONFIG_OCRE_CONTAINER_DEFAULT_STACK_SIZE=4096 + +# DISABLE OCRE SHELL (this is what's causing the shell_fprintf errors!) +CONFIG_OCRE_SHELL=n + +# Disable the main Zephyr shell AND all shell subsystems +CONFIG_NET_SHELL=n +CONFIG_FILE_SYSTEM_SHELL=n +CONFIG_SENSOR_SHELL=n + +# Override shell-related configs from prj.conf since shell is disabled + +# Random number generator (REQUIRED by networking and RNG sensor) +CONFIG_ENTROPY_GENERATOR=y +CONFIG_TEST_RANDOM_GENERATOR=y + +# Reduce networking stack sizes to save RAM +CONFIG_NET_TX_STACK_SIZE=1024 +CONFIG_NET_RX_STACK_SIZE=2048 +CONFIG_NET_BUF_TX_COUNT=8 +CONFIG_NET_BUF_RX_COUNT=16 +CONFIG_NET_MGMT_EVENT_STACK_SIZE=1024 +CONFIG_NET_PKT_RX_COUNT=8 +CONFIG_NET_PKT_TX_COUNT=8 +CONFIG_NET_BUF_DATA_SIZE=128 + +# Bus interfaces +CONFIG_GPIO=y + +# Ocre Sensors support +CONFIG_SENSOR=y +CONFIG_OCRE_SENSORS=y +CONFIG_RNG_SENSOR=y + +# Ocre GPIO Support (minimal) +CONFIG_OCRE_GPIO=y +CONFIG_OCRE_GPIO_MAX_PORTS=4 +CONFIG_OCRE_GPIO_PINS_PER_PORT=8 +CONFIG_OCRE_GPIO_MAX_PINS=32 + +# Disable container messaging to save RAM +CONFIG_OCRE_CONTAINER_MESSAGING=y + +# Enable container filesystem for WASI stdio +CONFIG_OCRE_CONTAINER_FILESYSTEM=y + +# CONFIG_BOOTLOADER_MCUBOOT=n +# # CONFIG_IMG_MANAGER=n +# CONFIG_MCUBOOT_IMG_MANAGER=n +# CONFIG_STREAM_FLASH=n +# CONFIG_IMG_ERASE_PROGRESSIVELY=n + +# Flash settings +CONFIG_FLASH=y +CONFIG_FLASH_MAP=y +CONFIG_FLASH_PAGE_LAYOUT=y + +# Serial/UART +CONFIG_SERIAL=y +CONFIG_UART_CONSOLE=y +CONFIG_CONSOLE=y + +# Reduce other buffers +CONFIG_ZVFS_OPEN_MAX=8 +CONFIG_ZVFS_EVENTFD_MAX=5 + +CONFIG_LOG_TRACE_SHORT_TIMESTAMP=n + +CONFIG_SHELL_PROMPT_UART="" diff --git a/boards/nrf5340dk_nrf5340_cpuapp.overlay b/boards/nrf5340dk_nrf5340_cpuapp.overlay new file mode 100644 index 00000000..7d625007 --- /dev/null +++ b/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -0,0 +1,34 @@ +/ { + aliases { + rng0 = &rng_device; + led0 = &led0; + }; + + rng_device: rng_0 { + compatible = "custom,rng-sensor"; + label = "RNG Sensor"; + status = "okay"; + }; + + devices { + compatible = "custom,devices"; + status = "okay"; + device_list = <&rng_device>; + }; +}; + +/* Enable one LED for blinky */ +&led0 { + status = "okay"; +}; + +&flash0 { + partitions { + /delete-node/ partition@f8000; + + user_data_partition: partition@e0000 { + label = "user_data"; + reg = <0x000e0000 DT_SIZE_K(128)>; + }; + }; +}; diff --git a/build.sh b/build.sh index ac1da7b8..8432e0c4 100755 --- a/build.sh +++ b/build.sh @@ -91,6 +91,11 @@ if [[ "$TARGET" == "z" ]]; then -DDTC_OVERLAY_FILE=boards/${ZEPHYR_BOARD}.overlay\;boards/enc28j60.overlay" echo "Building for b_u585i_iot02a with ENC28J60 support" ;; + nrf5340) + ZEPHYR_BOARD="nrf5340dk/nrf5340/cpuapp" + CONF_EXTRA="" + echo "Building for nrf5340dk board: App CPU" + ;; *) ZEPHYR_BOARD="$BOARD_ARG" CONF_EXTRA="" diff --git a/src/ocre/ocre_gpio/ocre_gpio.c b/src/ocre/ocre_gpio/ocre_gpio.c index 63004048..1c4b71bf 100644 --- a/src/ocre/ocre_gpio/ocre_gpio.c +++ b/src/ocre/ocre_gpio/ocre_gpio.c @@ -384,7 +384,7 @@ static void gpio_callback_handler(const struct device *port, struct gpio_callbac } //======================================================================================================================================================================================================================================================================================================== -// By Name +// By Name //======================================================================================================================================================================================================================================================================================================== static int find_port_index(const struct device *port) { if (!port) { @@ -662,12 +662,12 @@ int ocre_gpio_wasm_register_callback_by_name(wasm_exec_env_t exec_env, const cha int global_pin = port_idx * CONFIG_OCRE_GPIO_PINS_PER_PORT + pin; LOG_INF("Registering callback by name: %s, global_pin=%d", name, global_pin); - + if (global_pin >= CONFIG_OCRE_GPIO_MAX_PINS) { LOG_ERR("Global pin %d exceeds max %d", global_pin, CONFIG_OCRE_GPIO_MAX_PINS); return -EINVAL; } - + return ocre_gpio_register_callback(global_pin); } @@ -686,6 +686,6 @@ int ocre_gpio_wasm_unregister_callback_by_name(wasm_exec_env_t exec_env, const c int global_pin = port_idx * CONFIG_OCRE_GPIO_PINS_PER_PORT + pin; LOG_INF("Unregistering callback by name: %s, global_pin=%d", name, global_pin); - + return ocre_gpio_unregister_callback(global_pin); } diff --git a/west.yml b/west.yml index cee4e7bb..3e8d71a1 100644 --- a/west.yml +++ b/west.yml @@ -14,6 +14,7 @@ manifest: - hal_st - mbedtls - cmsis_6 - + - hal_nordic + self: - path: application + path: application