From b025bcfb3d169142f3080a021942a9aa73f1f68c Mon Sep 17 00:00:00 2001 From: Khoa Nguyen Date: Tue, 24 Jun 2025 09:14:15 +0700 Subject: [PATCH 1/3] modules: hal_ethos_u: Update ARM_ETHOS_U config - Update to use ETHOS_U config instead of ARM_ETHOS_U - Update prefix ETHOS_U_ for all configs that use ARM_ETHOS_U_ Signed-off-by: Khoa Nguyen --- doc/releases/migration-guide-4.2.rst | 3 + modules/hal_ethos_u/CMakeLists.txt | 10 +-- modules/hal_ethos_u/Kconfig | 94 ++++++++++++++-------------- modules/tflite-micro/CMakeLists.txt | 2 +- 4 files changed, 56 insertions(+), 53 deletions(-) diff --git a/doc/releases/migration-guide-4.2.rst b/doc/releases/migration-guide-4.2.rst index a05018c8bca2..d2605e6b0be1 100644 --- a/doc/releases/migration-guide-4.2.rst +++ b/doc/releases/migration-guide-4.2.rst @@ -409,6 +409,9 @@ Misc * All memc_flexram_* namespaced things including kconfigs and C API have been changed to just flexram_*. +* Select ``CONFIG_ETHOS_U`` instead ``CONFIG_ARM_ETHOS_U`` to enable Ethos-U NPU driver. +* Rename all configs that have prefix ``CONFIG_ARM_ETHOS_U_`` to ``CONFIG_ETHOS_U_``. + Bluetooth ********* diff --git a/modules/hal_ethos_u/CMakeLists.txt b/modules/hal_ethos_u/CMakeLists.txt index 94949bcd9b48..547e6e4f8ebc 100644 --- a/modules/hal_ethos_u/CMakeLists.txt +++ b/modules/hal_ethos_u/CMakeLists.txt @@ -2,23 +2,23 @@ # affiliates # SPDX-License-Identifier: Apache-2.0 -if(CONFIG_ARM_ETHOS_U AND CONFIG_MULTITHREADING) +if(CONFIG_ETHOS_U AND CONFIG_MULTITHREADING) # Due to CMP0126 not being NEW, ETHOSU_TARGET_NPU_CONFIG originally # as directory variable will fail to override that in ethos-u-core-driver # as cache variable. Fix by passing as cache variable. See: # https://cmake.org/cmake/help/latest/policy/CMP0126.html#policy:CMP0126 - set(ETHOSU_TARGET_NPU_CONFIG ${CONFIG_ARM_ETHOS_U_NPU_NAME} CACHE STRING "NPU configuration") + set(ETHOSU_TARGET_NPU_CONFIG ${CONFIG_ETHOS_U_NPU_NAME} CACHE STRING "NPU configuration") # Mapping log level from Zephyr (none=0, err=1, wrn=2, inf=3, dbg=4) to # Ethos-U driver (err=0, warn=1, info=2, debug=3) set(ETHOSU_LOG_SEVERITY_MAP err err warning info debug) list(LENGTH ETHOSU_LOG_SEVERITY_MAP ETHOSU_LOG_SEVERITY_MAP_LENGTH) - if (${CONFIG_ARM_ETHOS_U_LOG_LEVEL} EQUAL 0) + if (${CONFIG_ETHOS_U_LOG_LEVEL} EQUAL 0) # The Ethos-U driver does not have a corresponding "none" log level. Disable logging instead. set(ETHOSU_LOG_ENABLE OFF CACHE BOOL "") - elseif (${CONFIG_ARM_ETHOS_U_LOG_LEVEL} LESS "${ETHOSU_LOG_SEVERITY_MAP_LENGTH}") - list(GET ETHOSU_LOG_SEVERITY_MAP ${CONFIG_ARM_ETHOS_U_LOG_LEVEL} ETHOSU_LOG_SEVERITY) + elseif (${CONFIG_ETHOS_U_LOG_LEVEL} LESS "${ETHOSU_LOG_SEVERITY_MAP_LENGTH}") + list(GET ETHOSU_LOG_SEVERITY_MAP ${CONFIG_ETHOS_U_LOG_LEVEL} ETHOSU_LOG_SEVERITY) set(ETHOSU_LOG_SEVERITY ${ETHOSU_LOG_SEVERITY} CACHE STRING "") else() set(ETHOSU_LOG_SEVERITY debug CACHE STRING "") diff --git a/modules/hal_ethos_u/Kconfig b/modules/hal_ethos_u/Kconfig index 93715e6bcc65..3c384d74a228 100644 --- a/modules/hal_ethos_u/Kconfig +++ b/modules/hal_ethos_u/Kconfig @@ -2,93 +2,93 @@ # affiliates # SPDX-License-Identifier: Apache-2.0 -config ARM_ETHOS_U +config ETHOS_U bool "Ethos-U core driver" default n depends on MULTITHREADING help This option enables the Arm Ethos-U core driver. -if ARM_ETHOS_U -menu "Arm Ethos-U NPU configuration" -choice ARM_ETHOS_U_NPU_CONFIG - prompt "Arm Ethos-U NPU configuration" - default ARM_ETHOS_U55_128 if SOC_SERIES_MPS3 - default ARM_ETHOS_U65_256 if SOC_MPS4_CORSTONE315 - default ARM_ETHOS_U85_256 if SOC_MPS4_CORSTONE320 -config ARM_ETHOS_U55_64 +if ETHOS_U +menu "Ethos-U NPU configuration" +choice ETHOS_U_NPU_CONFIG + prompt "Ethos-U NPU configuration" + default ETHOS_U55_128 if SOC_SERIES_MPS3 + default ETHOS_U65_256 if SOC_MPS4_CORSTONE315 + default ETHOS_U85_256 if SOC_MPS4_CORSTONE320 +config ETHOS_U55_64 bool "using Ethos-U55 with 64 macs" -config ARM_ETHOS_U55_128 +config ETHOS_U55_128 bool "using Ethos-U55 with 128 macs" -config ARM_ETHOS_U55_256 +config ETHOS_U55_256 bool "using Ethos-U55 with 256 macs" -config ARM_ETHOS_U65_128 +config ETHOS_U65_128 bool "using Ethos-U65 with 128 macs" -config ARM_ETHOS_U65_256 +config ETHOS_U65_256 bool "using Ethos-U65 with 256 macs" -config ARM_ETHOS_U65_512 +config ETHOS_U65_512 bool "using Ethos-U65 with 512 macs" -config ARM_ETHOS_U85_128 +config ETHOS_U85_128 bool "using Ethos-U85 with 128 macs" -config ARM_ETHOS_U85_256 +config ETHOS_U85_256 bool "using Ethos-U85 with 256 macs" -config ARM_ETHOS_U85_512 +config ETHOS_U85_512 bool "using Ethos-U85 with 512 macs" -config ARM_ETHOS_U85_1024 +config ETHOS_U85_1024 bool "using Ethos-U85 with 1024 macs" -config ARM_ETHOS_U85_2048 +config ETHOS_U85_2048 bool "using Ethos-U85 with 2048 macs" endchoice endmenu -config ARM_ETHOS_U_NPU_NAME +config ETHOS_U_NPU_NAME string - default "ethos-u55-64" if ARM_ETHOS_U55_64 - default "ethos-u55-128" if ARM_ETHOS_U55_128 - default "ethos-u55-256" if ARM_ETHOS_U55_256 - default "ethos-u65-128" if ARM_ETHOS_U65_128 - default "ethos-u65-256" if ARM_ETHOS_U65_256 - default "ethos-u65-512" if ARM_ETHOS_U65_512 - default "ethos-u85-128" if ARM_ETHOS_U85_128 - default "ethos-u85-256" if ARM_ETHOS_U85_256 - default "ethos-u85-512" if ARM_ETHOS_U85_512 - default "ethos-u85-1024" if ARM_ETHOS_U85_1024 - default "ethos-u85-2048" if ARM_ETHOS_U85_2048 + default "ethos-u55-64" if ETHOS_U55_64 + default "ethos-u55-128" if ETHOS_U55_128 + default "ethos-u55-256" if ETHOS_U55_256 + default "ethos-u65-128" if ETHOS_U65_128 + default "ethos-u65-256" if ETHOS_U65_256 + default "ethos-u65-512" if ETHOS_U65_512 + default "ethos-u85-128" if ETHOS_U85_128 + default "ethos-u85-256" if ETHOS_U85_256 + default "ethos-u85-512" if ETHOS_U85_512 + default "ethos-u85-1024" if ETHOS_U85_1024 + default "ethos-u85-2048" if ETHOS_U85_2048 help - Name of the used Arm NPU + Name of the used Ethos-U NPU -choice "ARM_ETHOS_U_LOG_LEVEL_CHOICE" - prompt "Max compiled-in log level for arm_ethos_u" - default ARM_ETHOS_U_LOG_LEVEL_WRN +choice "ETHOS_U_LOG_LEVEL_CHOICE" + prompt "Max compiled-in log level for ETHOS_U" + default ETHOS_U_LOG_LEVEL_WRN depends on STDOUT_CONSOLE -config ARM_ETHOS_U_LOG_LEVEL_NONE +config ETHOS_U_LOG_LEVEL_NONE bool "None" -config ARM_ETHOS_U_LOG_LEVEL_ERR +config ETHOS_U_LOG_LEVEL_ERR bool "Error" -config ARM_ETHOS_U_LOG_LEVEL_WRN +config ETHOS_U_LOG_LEVEL_WRN bool "Warning" -config ARM_ETHOS_U_LOG_LEVEL_INF +config ETHOS_U_LOG_LEVEL_INF bool "Info" -config ARM_ETHOS_U_LOG_LEVEL_DBG +config ETHOS_U_LOG_LEVEL_DBG bool "Debug" -config ARM_ETHOS_U_LOG_LEVEL_DEFAULT +config ETHOS_U_LOG_LEVEL_DEFAULT bool "Default" endchoice -config ARM_ETHOS_U_LOG_LEVEL +config ETHOS_U_LOG_LEVEL int depends on STDOUT_CONSOLE - default 0 if ARM_ETHOS_U_LOG_LEVEL_NONE - default 1 if ARM_ETHOS_U_LOG_LEVEL_ERR - default 2 if ARM_ETHOS_U_LOG_LEVEL_WRN - default 3 if ARM_ETHOS_U_LOG_LEVEL_INF - default 4 if ARM_ETHOS_U_LOG_LEVEL_DBG + default 0 if ETHOS_U_LOG_LEVEL_NONE + default 1 if ETHOS_U_LOG_LEVEL_ERR + default 2 if ETHOS_U_LOG_LEVEL_WRN + default 3 if ETHOS_U_LOG_LEVEL_INF + default 4 if ETHOS_U_LOG_LEVEL_DBG endif diff --git a/modules/tflite-micro/CMakeLists.txt b/modules/tflite-micro/CMakeLists.txt index 95301b34c793..59990e1305f6 100644 --- a/modules/tflite-micro/CMakeLists.txt +++ b/modules/tflite-micro/CMakeLists.txt @@ -24,7 +24,7 @@ if(CONFIG_TENSORFLOW_LITE_MICRO) zephyr_library_compile_definitions(CMSIS_NN) endif() - if (CONFIG_ARM_ETHOS_U) + if (CONFIG_ETHOS_U) set(ETHOSU_CO_PROCESSOR ethos_u) endif() From 44e47442d37fcbda69e16e5b0f90a69203867e17 Mon Sep 17 00:00:00 2001 From: Khoa Nguyen Date: Thu, 29 May 2025 14:57:13 +0700 Subject: [PATCH 2/3] drivers: misc: ethos_u: Create the ethos_u_common for every vendor Seperate the ``ethos_u_common`` for every vendor and ``ethos_u_arm`` for sepcific Arm's boards. Enable vendors to self-configure the init flow and IRQ handler. Signed-off-by: Khoa Nguyen --- drivers/misc/CMakeLists.txt | 2 +- drivers/misc/Kconfig | 1 + drivers/misc/ethos_u/CMakeLists.txt | 3 +- drivers/misc/ethos_u/Kconfig | 14 +++ .../misc/ethos_u/{ethos_u.c => ethos_u_arm.c} | 110 +----------------- drivers/misc/ethos_u/ethos_u_common.c | 102 ++++++++++++++++ drivers/misc/ethos_u/ethos_u_common.h | 31 +++++ 7 files changed, 156 insertions(+), 107 deletions(-) create mode 100644 drivers/misc/ethos_u/Kconfig rename drivers/misc/ethos_u/{ethos_u.c => ethos_u_arm.c} (56%) create mode 100644 drivers/misc/ethos_u/ethos_u_common.c create mode 100644 drivers/misc/ethos_u/ethos_u_common.h diff --git a/drivers/misc/CMakeLists.txt b/drivers/misc/CMakeLists.txt index 107b6d218e25..5663d5cc9048 100644 --- a/drivers/misc/CMakeLists.txt +++ b/drivers/misc/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 -add_subdirectory_ifdef(CONFIG_ARM_ETHOS_U ethos_u) +add_subdirectory_ifdef(CONFIG_ETHOS_U ethos_u) add_subdirectory_ifdef(CONFIG_FT800 ft8xx) add_subdirectory_ifdef(CONFIG_GROVE_LCD_RGB grove_lcd_rgb) add_subdirectory_ifdef(CONFIG_PIO_RPI_PICO pio_rpi_pico) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 09d814f8024f..cb57bbaecf8a 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -5,6 +5,7 @@ menu "Miscellaneous Drivers" +source "drivers/misc/ethos_u/Kconfig" source "drivers/misc/ft8xx/Kconfig" source "drivers/misc/grove_lcd_rgb/Kconfig" source "drivers/misc/pio_rpi_pico/Kconfig" diff --git a/drivers/misc/ethos_u/CMakeLists.txt b/drivers/misc/ethos_u/CMakeLists.txt index c251488eb3cf..024c09eb3292 100644 --- a/drivers/misc/ethos_u/CMakeLists.txt +++ b/drivers/misc/ethos_u/CMakeLists.txt @@ -3,4 +3,5 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_library() -zephyr_library_sources(ethos_u.c) +zephyr_library_sources(ethos_u_common.c) +zephyr_library_sources_ifdef(CONFIG_ETHOS_U_ARM ethos_u_arm.c) diff --git a/drivers/misc/ethos_u/Kconfig b/drivers/misc/ethos_u/Kconfig new file mode 100644 index 000000000000..66d38ae6f5ea --- /dev/null +++ b/drivers/misc/ethos_u/Kconfig @@ -0,0 +1,14 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +choice + prompt "Select vendor Ethos-U NPU driver" + depends on ETHOS_U + default ETHOS_U_ARM if DT_HAS_ARM_ETHOS_U_ENABLED + +config ETHOS_U_ARM + bool "Arm Ethos-U NPU driver" + help + Enables Arm Ethos-U NPU driver. + +endchoice diff --git a/drivers/misc/ethos_u/ethos_u.c b/drivers/misc/ethos_u/ethos_u_arm.c similarity index 56% rename from drivers/misc/ethos_u/ethos_u.c rename to drivers/misc/ethos_u/ethos_u_arm.c index 308e689fe0fb..21278a82a063 100644 --- a/drivers/misc/ethos_u/ethos_u.c +++ b/drivers/misc/ethos_u/ethos_u_arm.c @@ -4,117 +4,17 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "zephyr/sys_clock.h" +#include +#include #include #include -#include -#include -#include -#include - +#include #include -#include -LOG_MODULE_REGISTER(ethos_u, CONFIG_ARM_ETHOS_U_LOG_LEVEL); +#include "ethos_u_common.h" #define DT_DRV_COMPAT arm_ethos_u - -/******************************************************************************* - * Re-implementation/Overrides __((weak)) symbol functions from ethosu_driver.c - * To handle mutex and semaphores - *******************************************************************************/ - -void *ethosu_mutex_create(void) -{ - struct k_mutex *mutex; - - mutex = k_malloc(sizeof(*mutex)); - if (mutex == NULL) { - LOG_ERR("Failed allocate mutex"); - return NULL; - } - - k_mutex_init(mutex); - - return (void *)mutex; -} - -int ethosu_mutex_lock(void *mutex) -{ - int status; - - status = k_mutex_lock((struct k_mutex *)mutex, K_FOREVER); - if (status != 0) { - LOG_ERR("Failed to lock mutex with error - %d", status); - return -1; - } - - return 0; -} - -int ethosu_mutex_unlock(void *mutex) -{ - k_mutex_unlock((struct k_mutex *)mutex); - return 0; -} - -void *ethosu_semaphore_create(void) -{ - struct k_sem *sem; - - sem = k_malloc(sizeof(*sem)); - if (sem == NULL) { - LOG_ERR("Failed to allocate semaphore"); - return NULL; - } - - k_sem_init(sem, 0, 100); - - return (void *)sem; -} - -int ethosu_semaphore_take(void *sem, uint64_t timeout) -{ - int status; - - status = k_sem_take((struct k_sem *)sem, (timeout == ETHOSU_SEMAPHORE_WAIT_FOREVER) - ? K_FOREVER - : Z_TIMEOUT_TICKS(timeout)); - - if (status != 0) { - /* The Ethos-U driver expects the semaphore implementation to never fail except for - * when a timeout occurs, and the current ethosu_semaphore_take implementation makes - * no distinction, in terms of return codes, between a timeout and other semaphore - * take failures. Also, note that a timeout is virtually indistinguishable from - * other failures if the driver logging is disabled. Handling errors other than a - * timeout is therefore not covered here and is deferred to the application - * developer if necessary. - */ - if (status != -EAGAIN) { - LOG_ERR("Failed to take semaphore with error - %d", status); - } - return -1; - } - - return 0; -} - -int ethosu_semaphore_give(void *sem) -{ - k_sem_give((struct k_sem *)sem); - return 0; -} - -struct ethosu_dts_info { - void *base_addr; - bool secure_enable; - bool privilege_enable; - void (*irq_config)(void); -}; - -struct ethosu_data { - struct ethosu_driver drv; -}; +LOG_MODULE_REGISTER(arm_ethos_u, CONFIG_ETHOS_U_LOG_LEVEL); void ethosu_zephyr_irq_handler(const struct device *dev) { diff --git a/drivers/misc/ethos_u/ethos_u_common.c b/drivers/misc/ethos_u/ethos_u_common.c new file mode 100644 index 000000000000..e71f236b7573 --- /dev/null +++ b/drivers/misc/ethos_u/ethos_u_common.c @@ -0,0 +1,102 @@ +/* + * SPDX-FileCopyrightText: Copyright 2021-2022, 2024 Arm Limited and/or its + * affiliates + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "zephyr/sys_clock.h" +#include +#include +#include +#include + +#include + +#include +LOG_MODULE_REGISTER(ethos_u, CONFIG_ETHOS_U_LOG_LEVEL); + +/******************************************************************************* + * Re-implementation/Overrides __((weak)) symbol functions from ethosu_driver.c + * To handle mutex and semaphores + *******************************************************************************/ + +void *ethosu_mutex_create(void) +{ + struct k_mutex *mutex; + + mutex = k_malloc(sizeof(*mutex)); + if (mutex == NULL) { + LOG_ERR("Failed allocate mutex"); + return NULL; + } + + k_mutex_init(mutex); + + return (void *)mutex; +} + +int ethosu_mutex_lock(void *mutex) +{ + int status; + + status = k_mutex_lock((struct k_mutex *)mutex, K_FOREVER); + if (status != 0) { + LOG_ERR("Failed to lock mutex with error - %d", status); + return -1; + } + + return 0; +} + +int ethosu_mutex_unlock(void *mutex) +{ + k_mutex_unlock((struct k_mutex *)mutex); + return 0; +} + +void *ethosu_semaphore_create(void) +{ + struct k_sem *sem; + + sem = k_malloc(sizeof(*sem)); + if (sem == NULL) { + LOG_ERR("Failed to allocate semaphore"); + return NULL; + } + + k_sem_init(sem, 0, 100); + + return (void *)sem; +} + +int ethosu_semaphore_take(void *sem, uint64_t timeout) +{ + int status; + + status = k_sem_take((struct k_sem *)sem, (timeout == ETHOSU_SEMAPHORE_WAIT_FOREVER) + ? K_FOREVER + : Z_TIMEOUT_TICKS(timeout)); + + if (status != 0) { + /* The Ethos-U driver expects the semaphore implementation to never fail except for + * when a timeout occurs, and the current ethosu_semaphore_take implementation makes + * no distinction, in terms of return codes, between a timeout and other semaphore + * take failures. Also, note that a timeout is virtually indistinguishable from + * other failures if the driver logging is disabled. Handling errors other than a + * timeout is therefore not covered here and is deferred to the application + * developer if necessary. + */ + if (status != -EAGAIN) { + LOG_ERR("Failed to take semaphore with error - %d", status); + } + return -1; + } + + return 0; +} + +int ethosu_semaphore_give(void *sem) +{ + k_sem_give((struct k_sem *)sem); + return 0; +} diff --git a/drivers/misc/ethos_u/ethos_u_common.h b/drivers/misc/ethos_u/ethos_u_common.h new file mode 100644 index 000000000000..b27cb132aeb9 --- /dev/null +++ b/drivers/misc/ethos_u/ethos_u_common.h @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: Copyright 2021-2022, 2024 Arm Limited and/or its + * affiliates + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_DRIVERS_MISC_ETHOS_U_ETHOS_U_COMMON_H_ +#define ZEPHYR_DRIVERS_MISC_ETHOS_U_ETHOS_U_COMMON_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct ethosu_dts_info { + void *base_addr; + bool secure_enable; + bool privilege_enable; + void (*irq_config)(void); +}; + +struct ethosu_data { + struct ethosu_driver drv; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_DRIVERS_MISC_ETHOS_U_ETHOS_U_COMMON_H_ */ From f10211de700779037c374ebeca6b2b71b71b48a4 Mon Sep 17 00:00:00 2001 From: Khoa Nguyen Date: Thu, 29 May 2025 19:43:31 +0700 Subject: [PATCH 3/3] samples: modules: tflite-micro: Update Ethos-U driver config Update Ethos-U driver config for sample app `tflm_ethosu` Signed-off-by: Khoa Nguyen --- samples/modules/tflite-micro/tflm_ethosu/prj.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/modules/tflite-micro/tflm_ethosu/prj.conf b/samples/modules/tflite-micro/tflm_ethosu/prj.conf index a1961668b0e5..c9a91f35aec7 100644 --- a/samples/modules/tflite-micro/tflm_ethosu/prj.conf +++ b/samples/modules/tflite-micro/tflm_ethosu/prj.conf @@ -3,7 +3,7 @@ CONFIG_CPP=y CONFIG_STD_CPP17=y CONFIG_TENSORFLOW_LITE_MICRO=y -CONFIG_ARM_ETHOS_U=y +CONFIG_ETHOS_U=y CONFIG_HEAP_MEM_POOL_SIZE=16384 CONFIG_LOG=y CONFIG_REQUIRES_FLOAT_PRINTF=y