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
18 changes: 18 additions & 0 deletions boards/arm/mps3_an547/mps3_an547.dts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2021 Linaro Limited
* Copyright 2022 Arm Limited and/or its affiliates <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -85,6 +86,21 @@
};
};

ethosu {
#address-cells = <1>;
#size-cells = <0>;
interrupt-parent = <&nvic>;

ethosu0: ethosu@48102000 {
compatible = "arm,ethos-u";
reg = <0x48102000>;
interrupts = <56 3>;
secure-enable;
privilege-enable;
status = "okay";
};
};

cpus {
#address-cells = <1>;
#size-cells = <0>;
Expand Down Expand Up @@ -132,6 +148,7 @@
/* DDR4 - 2G, alternates non-secure/secure every 256M */
ddr4: memory@60000000 {
device_type = "memory";
compatible = "zephyr,memory-region";
reg = <0x60000000 DT_SIZE_M(256)
0x70000000 DT_SIZE_M(256)
0x80000000 DT_SIZE_M(256)
Expand All @@ -140,6 +157,7 @@
0xb0000000 DT_SIZE_M(256)
0xc0000000 DT_SIZE_M(256)
0xd0000000 DT_SIZE_M(256)>;
zephyr,memory-region = "DDR4";
};

soc {
Expand Down
1 change: 1 addition & 0 deletions drivers/misc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

add_subdirectory_ifdef(CONFIG_ARM_ETHOS_U ethos_u)
add_subdirectory_ifdef(CONFIG_FT800 ft8xx)
add_subdirectory_ifdef(CONFIG_GROVE_LCD_RGB grove_lcd_rgb)
6 changes: 6 additions & 0 deletions drivers/misc/ethos_u/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2022 Arm Limited and/or its affiliates <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

zephyr_library()
zephyr_library_sources(init.c)
158 changes: 158 additions & 0 deletions drivers/misc/ethos_u/init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* Copyright 2021-2022 Arm Limited and/or its affiliates <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/irq.h>
#include <zephyr/sys/util.h>

#include <ethosu_driver.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(ethos_u, CONFIG_ARM_ETHOS_U_LOG_LEVEL);

#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)
{
int status;

status = k_sem_take((struct k_sem *)sem, K_FOREVER);
if (status != 0) {
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;
};

static int ethosu_zephyr_init(const struct device *dev)
{
const struct ethosu_dts_info *config = dev->config;
struct ethosu_data *data = dev->data;
struct ethosu_driver *drv = &data->drv;
struct ethosu_driver_version version;

LOG_DBG("Ethos-U DTS info. base_address=0x%p, secure_enable=%u, privilege_enable=%u",
config->base_addr, config->secure_enable, config->privilege_enable);

ethosu_get_driver_version(&version);

LOG_DBG("Version. major=%u, minor=%u, patch=%u", version.major, version.minor,
version.patch);

if (ethosu_init(drv, config->base_addr, NULL, 0, config->secure_enable,
config->privilege_enable)) {
LOG_ERR("Failed to initialize NPU with ethosu_init().");
return -EINVAL;
}

config->irq_config();

return 0;
}

#define ETHOSU_DEVICE_INIT(n) \
static struct ethosu_data ethosu_data_##n; \
\
static void ethosu_zephyr_irq_handler_##n(void) \
{ \
struct ethosu_driver *drv = &ethosu_data_##n.drv; \
ethosu_irq_handler(drv); \
} \
\
static void ethosu_zephyr_irq_config_##n(void) \
{ \
IRQ_DIRECT_CONNECT(DT_INST_IRQN(n), \
DT_INST_IRQ(n, priority), \
ethosu_zephyr_irq_handler_##n, 0); \
irq_enable(DT_INST_IRQN(n)); \
} \
\
static const struct ethosu_dts_info ethosu_dts_info_##n = { \
.base_addr = (void *)DT_INST_REG_ADDR(n), \
.secure_enable = DT_INST_PROP(n, secure_enable), \
.privilege_enable = DT_INST_PROP(n, privilege_enable), \
.irq_config = &ethosu_zephyr_irq_config_##n, \
}; \
\
DEVICE_DT_INST_DEFINE(n, ethosu_zephyr_init, NULL, &ethosu_data_##n, &ethosu_dts_info_##n, \
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);

DT_INST_FOREACH_STATUS_OKAY(ETHOSU_DEVICE_INIT);
32 changes: 32 additions & 0 deletions dts/bindings/arm/arm,ethos-u.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2022 Arm Limited and/or its affiliates <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

description: |
The Arm Ethos-U is a micro NPU that enables neural networks to be hardware
accelerated on embedded devices. The Ethos-U NPU driver is provided as a
Zephyr module that is hooked up into the Tensorflow Lite Micro framework
as a 'TFLM custom operation'.

This device tree entry defines board specific properties like the register
map address and interrupt line, and is therefore expected to be included
into the device specific device tree file.

compatible: "arm,ethos-u"

include: base.yaml

properties:
reg:
required: true

interrupts:
required: true

secure-enable:
type: boolean
description: Configure Ethos-U NPU to operate in secure- or non-secure mode

privilege-enable:
type: boolean
description: Configure Ethos-U NPU to operate in privileged- or non-privileged mode
25 changes: 25 additions & 0 deletions modules/hal_ethos_u/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2022 Arm Limited and/or its affiliates <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_ARM_ETHOS_U AND CONFIG_MULTITHREADING)
set(ETHOSU_TARGET_NPU_CONFIG ${CONFIG_ARM_ETHOS_U_NPU_NAME})

# 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}" LESS_EQUAL "${ETHOSU_LOG_SEVERITY_MAP_LENGTH}")
list(GET ETHOSU_LOG_SEVERITY_MAP ${CONFIG_ARM_ETHOS_U_LOG_LEVEL} ETHOSU_LOG_SEVERITY)
else()
set(ETHOSU_LOG_SEVERITY debug)
endif()

add_subdirectory(${ZEPHYR_CURRENT_MODULE_DIR} ethos-u-core-driver)

target_link_libraries(ethosu_core_driver PUBLIC
zephyr_interface)

zephyr_link_libraries(ethosu_core_driver)
endif()
45 changes: 45 additions & 0 deletions modules/hal_ethos_u/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2021-2022 Arm Limited and/or its affiliates <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

config ARM_ETHOS_U
bool "Ethos-U core driver"
default n
depends on MULTITHREADING
help
This option enables the Arm Ethos-U core driver.

menu "Arm Ethos-U NPU configuration"
choice ARM_ETHOS_U_NPU_CONFIG
prompt "Arm Ethos-U NPU configuration"
depends on ARM_ETHOS_U
default ARM_ETHOS_U55_128
config ARM_ETHOS_U55_64
bool "using Ethos-U55 with 64 macs"
config ARM_ETHOS_U55_128
bool "using Ethos-U55 with 128 macs"
config ARM_ETHOS_U55_256
bool "using Ethos-U55 with 256 macs"
config ARM_ETHOS_U65_128
bool "using Ethos-U65 with 128 macs"
config ARM_ETHOS_U65_256
bool "using Ethos-U65 with 256 macs"
config ARM_ETHOS_U65_512
bool "using Ethos-U65 with 512 macs"
endchoice
endmenu

config ARM_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
help
Name of the used Arm NPU

module = ARM_ETHOS_U
module-str = arm_ethos_u
source "subsys/logging/Kconfig.template.log_config"
6 changes: 5 additions & 1 deletion modules/tflite-micro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ if(CONFIG_TENSORFLOW_LITE_MICRO)
zephyr_library_compile_definitions(CMSIS_NN)
endif()

if (CONFIG_ARM_ETHOS_U)
set(ETHOSU_CO_PROCESSOR ethos_u)
endif()

zephyr_library_sources(
${TENSORFLOW_LITE_MICRO_DIR}/tensorflow/lite/micro/simple_memory_allocator.cc
${TENSORFLOW_LITE_MICRO_DIR}/tensorflow/lite/micro/debug_log.cc
Expand Down Expand Up @@ -73,7 +77,7 @@ if(CONFIG_TENSORFLOW_LITE_MICRO)
${TENSORFLOW_LITE_MICRO_DIR}/tensorflow/lite/micro/kernels/detection_postprocess.cc
${TENSORFLOW_LITE_MICRO_DIR}/tensorflow/lite/micro/kernels/elementwise.cc
${TENSORFLOW_LITE_MICRO_DIR}/tensorflow/lite/micro/kernels/elu.cc
${TENSORFLOW_LITE_MICRO_DIR}/tensorflow/lite/micro/kernels/ethosu.cc
${TENSORFLOW_LITE_MICRO_DIR}/tensorflow/lite/micro/kernels/${ETHOSU_CO_PROCESSOR}/ethosu.cc
${TENSORFLOW_LITE_MICRO_DIR}/tensorflow/lite/micro/kernels/exp.cc
${TENSORFLOW_LITE_MICRO_DIR}/tensorflow/lite/micro/kernels/expand_dims.cc
${TENSORFLOW_LITE_MICRO_DIR}/tensorflow/lite/micro/kernels/fill.cc
Expand Down
15 changes: 15 additions & 0 deletions samples/modules/tflite-micro/tflm_ethosu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2021-2022 Arm Limited and/or its affiliates <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project(tflm_ethosu_app)

target_include_directories(app PRIVATE src/models/keyword_spotting_cnn_small_int8)

target_sources(app PRIVATE src/main.cpp src/inference_process.cpp)

zephyr_linker_sources(SECTIONS linker.ld)
9 changes: 9 additions & 0 deletions samples/modules/tflite-micro/tflm_ethosu/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2022 Arm Limited and/or its affiliates <[email protected]>
# SPDX-License-Identifier: Apache-2.0

config TFLM_ETHOSU_TAINT_BLOBS
bool
default y
select TAINT_BLOBS

source "Kconfig.zephyr"
Loading