diff options
author | alexander <alexander.efremov@arm.com> | 2022-02-10 16:15:54 +0000 |
---|---|---|
committer | alexander <alexander.efremov@arm.com> | 2022-02-10 18:04:42 +0000 |
commit | 31ae9f09bb3535975595e999fbc7baca889e46e8 (patch) | |
tree | 71f0cadc2620b9d18e474e5d40eda7b3d30a8ce4 | |
parent | 3107aa2152de9be8317e62da1d0327bcad6552e2 (diff) | |
download | ml-embedded-evaluation-kit-31ae9f09bb3535975595e999fbc7baca889e46e8.tar.gz |
MLECO-2682: CMake and source refactoring.
MLECO-2930: logging macros were extracted from hal.h and used separately around the code.
MLECO-2931: arm_math lib introduced, cmsis-dsp removed from top level linkage.
MLECO-2915: platform related post-build steps.
Change-Id: Id718884e22f262a5c070ded3f3f5d4b048820147
Signed-off-by: alexander <alexander.efremov@arm.com>
153 files changed, 1515 insertions, 1057 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2743066..5a7f1f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,9 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. #---------------------------------------------------------------------------- -# minimum version of cmake = 3.15 for legit reason: -# armclang support doesn't work work in previous releases -cmake_minimum_required(VERSION 3.15.0) +cmake_minimum_required(VERSION 3.15.6) +include(ExternalProject) # Build in release mode by default if (NOT CMAKE_BUILD_TYPE STREQUAL Debug) @@ -25,8 +24,7 @@ endif() message(STATUS "Build type is set to ${CMAKE_BUILD_TYPE}") -# Set language standards. TensorFlow Lite requires -# std=c++11. +# Set language standards. set(CMAKE_C_STANDARD 99) set(CMAKE_CXX_STANDARD 14) @@ -39,11 +37,15 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake) +set(SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts) +set(CMAKE_SCRIPTS_DIR ${SCRIPTS_DIR}/cmake) +set(CMAKE_TOOLCHAIN_DIR ${CMAKE_SCRIPTS_DIR}/toolchains) set(DOWNLOAD_DEP_DIR ${CMAKE_BINARY_DIR}/dependencies) +set(DEPENDENCY_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dependencies) set(RESOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources_downloaded CACHE PATH "Resources directory") +set(HAL_PLATFORM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source/hal/platform) include(${CMAKE_SCRIPTS_DIR}/source_gen_utils.cmake) @@ -55,6 +57,11 @@ else() endif() include(${CMAKE_SCRIPTS_DIR}/common_user_options.cmake) +include(${CMAKE_SCRIPTS_DIR}/platforms/${TARGET_PLATFORM}/build_configuration.cmake) + +set_platform_global_defaults() + +message(STATUS "Using CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") # Make sure the following options are defined before proceeding: assert_defined(LOG_LEVEL) @@ -67,8 +74,9 @@ assert_defined(CPU_PROFILE_ENABLED) assert_defined(CMAKE_TOOLCHAIN_FILE) project(arm_ml_embedded_evaluation_kit - VERSION 21.11 - DESCRIPTION "ARM ML Embedded Evaluation Kit for MPS3 FPGA and FastModel") + VERSION 21.11.1 + DESCRIPTION "ARM ML Embedded Evaluation Kit" + LANGUAGES C CXX ASM) enforce_compiler_version() setup_source_generator() @@ -83,107 +91,30 @@ list(APPEND USE_CASES_TESTS_SEARCH_DIR_LIST ${TEST_SRCS}/use_case) if (CPU_PROFILE_ENABLED) set(PROFILING_OPT "${PROFILING_OPT} -DCPU_PROFILE_ENABLED") endif() +# We include log target +add_subdirectory(${SRC_PATH}/log ${CMAKE_BINARY_DIR}/log) -# Include platform specific sources -if (TARGET_PLATFORM STREQUAL native) - set(PLATFORM_SOURCES_CMAKE_FILE ${CMAKE_SCRIPTS_DIR}/${TARGET_PLATFORM}-sources.cmake) -else () - set(PLATFORM_SOURCES_CMAKE_FILE ${CMAKE_SCRIPTS_DIR}/bare-metal-sources.cmake) - - assert_defined(CMSIS_SRC_PATH) +# We include arm_math target +add_subdirectory(${SRC_PATH}/math ${CMAKE_BINARY_DIR}/math) - if (CMAKE_BUILD_TYPE STREQUAL Debug AND CMAKE_CXX_COMPILER_ID STREQUAL ARMClang) - assert_defined(ARMCLANG_DEBUG_DWARF_LEVEL) - endif() -endif () - -message(STATUS "Including ${PLATFORM_SOURCES_CMAKE_FILE}") -include(${PLATFORM_SOURCES_CMAKE_FILE}) - -if (${CMAKE_CROSSCOMPILING}) - enable_language(ASM) - - # For non-native builds, we build with CMSIS-DSP support. - include(${CMAKE_SCRIPTS_DIR}/cmsis-dsp.cmake) - - # All CMSIS headers to be used: - set(CMSIS_HEADERS - ${CMSIS_DSP_INC_DIR} - ${CMSIS_CORE_INC_DIR} - ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Include - ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Include/Template) -endif () - -# If we need NPU libraries: -if (ETHOS_U_NPU_ENABLED) - - message(STATUS "Using ARM Ethos-U NPU - adding core-driver and timing-adapter-driver includes and libraries") - - assert_defined(ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH) - assert_defined(ETHOS_U_NPU_DRIVER_SRC_PATH) - - include_directories("${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH}/include/") - - add_subdirectory("${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH}" ${CMAKE_BINARY_DIR}/timing-adapter) - - set(ETHOSU_INCLUDES ${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH}/include - ${ETHOS_U_NPU_DRIVER_SRC_PATH}/include) - - list(APPEND ETHOS_U_NPU_LIBS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libtiming_adapter.a) -endif () +# We include the hal target +add_subdirectory(${SRC_PATH}/hal ${CMAKE_BINARY_DIR}/hal) +# Include the tensorflow build target include(${CMAKE_SCRIPTS_DIR}/tensorflow.cmake) -set(DEP_TENSORFLOW_LITE_MICRO_SUB_DIR ${TENSORFLOW_SRC_PATH}/tensorflow/lite/micro) -set(DEP_TENSORFLOW_LITE_MICRO_MAKE_DIR ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}/tools/make/targets) -set(DEP_FLATBUF_INCLUDE ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}/tools/make/downloads/flatbuffers/include) - -set(TENSORFLOW_LIBRARY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME}) - -set(DEP_TF_INCLUDE_DIRS - ${TENSORFLOW_SRC_PATH} - ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR} - ${ETHOSU_INCLUDES} - ${CMSIS_HEADERS} - ) - -## All TPIP includes -set(DEP_RUNTIME_INCLUDE_DIRS - ${DEP_TF_INCLUDE_DIRS} - ${DEP_FLATBUF_INCLUDE} - ) - -# Our entry point into tensorflow world: -file(GLOB_RECURSE SRC_TENSORFLOW_LITE_MICRO - ${SRC_PATH}/application/tensorflow-lite-micro/**/*.cc - ${SRC_PATH}/application/tensorflow-lite-micro/*.cc - ) - -set(HAL_DIR ${SRC_PATH}/application/hal) - -# HAL API sources -file(GLOB_RECURSE SRC_HAL - "${HAL_DIR}/hal.c" - ) - -# Set platform specific HAL sources; these should be provided -# by each platform's cmake include file -list(APPEND SRC_HAL ${SRC_PLAT_HAL}) - # Profiler if (NOT DEFINED PROFILER_DIR) set(PROFILER_DIR ${SRC_PATH}/application/profiler) endif () -# Include directories: -list(APPEND APPLICATION_INCLUDE_DIRS - ${HAL_DIR}/include +# Include directories for application module: +set(APPLICATION_INCLUDE_DIRS ${SRC_PATH}/application/tensorflow-lite-micro/include ${SRC_PATH}/application/main/include - ${PLAT_INCLUDE_DIRS} - ${PROFILER_DIR}/include - ) + ${PROFILER_DIR}/include) +# Source files for application module: file(GLOB_RECURSE SRC_APPLICATION "${SRC_PATH}/application/main/*.cc" "${SRC_PATH}/application/main/*.cpp" @@ -191,15 +122,22 @@ file(GLOB_RECURSE SRC_APPLICATION "${SRC_PATH}/application/main/**/*.cc" "${SRC_PATH}/application/main/**/*.cpp" "${SRC_PATH}/application/main/**/*.c" + "${SRC_PATH}/application/tensorflow-lite-micro/**/*.cc" + "${SRC_PATH}/application/tensorflow-lite-micro/*.cc" "${PROFILER_DIR}/*.cc" "${PROFILER_DIR}/*.cpp" "${PROFILER_DIR}/*.c" ) list(FILTER SRC_APPLICATION EXCLUDE REGEX ".*main\\.c.*$") +set(SRC_MAIN "${SRC_PATH}/application/main/Main.cc") +set_source_files_properties(${SRC_MAIN} + PROPERTIES COMPILE_DEFINITIONS + "PRJ_VER_STR=\"${PROJECT_VERSION}\";PRJ_DES_STR=\"${PROJECT_DESCRIPTION}\"") list(JOIN USE_CASE_BUILD "" USE_CASE_BUILD_STR) list(APPEND USE_CASES_SEARCH_DIR_LIST ${SRC_PATH}/use_case) message(STATUS "Use-cases source paths: ${USE_CASES_SEARCH_DIR_LIST}.") + if (${USE_CASE_BUILD_STR} STREQUAL all) foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST}) SUBDIRLIST(USE_CASES_SUBDIRS ${USE_CASES_SEARCH_DIR}) @@ -209,30 +147,6 @@ else() set(USE_CASES ${USE_CASE_BUILD}) endif() -if (NOT ${CMAKE_CROSSCOMPILING}) - - #Test TPIP - set(TEST_TPIP ${DOWNLOAD_DEP_DIR}/test) - file(MAKE_DIRECTORY ${TEST_TPIP}) - set(TEST_TPIP_INCLUDE ${TEST_TPIP}/include) - file(MAKE_DIRECTORY ${TEST_TPIP_INCLUDE}) - - include(ExternalProject) - - ExternalProject_Add(catch2-headers - URL https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp - DOWNLOAD_NO_EXTRACT 1 - CONFIGURE_COMMAND "" - BUILD_COMMAND bash -c "cp -R <DOWNLOAD_DIR>/catch.hpp ${TEST_TPIP_INCLUDE}" - INSTALL_COMMAND "" - ) -endif () - -list(APPEND APPLICATION_LIBS - ${TENSORFLOW_LIBRARY} - $<$<BOOL:${ETHOS_U_NPU_ENABLED}>:${ETHOS_U_NPU_LIBS}> - $<$<BOOL:${CMSIS_DSP_LIB}>:${CMSIS_DSP_LIB}>) - message(STATUS "Building use-cases: ${USE_CASES}.") foreach(use_case ${USE_CASES}) @@ -252,8 +166,8 @@ foreach(use_case ${USE_CASES}) # Executable application: set(TARGET_NAME "ethos-u-${use_case}") - set(DEFAULT_MODEL_DIR ${RESOURCES_DIR}/${use_case}) - set(DEFAULT_TEST_DATA_DIR ${DEFAULT_MODEL_DIR}) + set(DEFAULT_MODEL_DIR ${RESOURCES_DIR}/${use_case}) + set(DEFAULT_TEST_DATA_DIR ${DEFAULT_MODEL_DIR}) set(SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/src) set(INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/include) @@ -261,36 +175,25 @@ foreach(use_case ${USE_CASES}) file(REMOVE_RECURSE ${SRC_GEN_DIR} ${INC_GEN_DIR}) file(MAKE_DIRECTORY ${SRC_GEN_DIR} ${INC_GEN_DIR}) + file(GLOB UC_CMAKE_FILE + "${SRC_USE_CASE}/${use_case}/*.cmake") + + include(${UC_CMAKE_FILE}) + file(GLOB_RECURSE UC_SRC "${SRC_USE_CASE}/${use_case}/src/*.cpp" "${SRC_USE_CASE}/${use_case}/src/*.cc" "${SRC_USE_CASE}/${use_case}/src/*.c" "${SRC_USE_CASE}/${use_case}/src/**/*.cpp" "${SRC_USE_CASE}/${use_case}/src/**/*.cc" - "${SRC_USE_CASE}/${use_case}/src/**/*.c" - ) - - set(UC_INCLUDE - ${SRC_USE_CASE}/${use_case}/include - ) - - file(GLOB UC_CMAKE_FILE - "${SRC_USE_CASE}/${use_case}/*.cmake" - ) - - include(${UC_CMAKE_FILE}) + "${SRC_USE_CASE}/${use_case}/src/**/*.c") file(GLOB_RECURSE SRC_GEN "${SRC_GEN_DIR}/*.cc" "${SRC_GEN_DIR}/*.cpp" - "${SRC_GEN_DIR}/*.c" - ) - - set(SRC_MAIN "${SRC_PATH}/application/main/Main.cc") + "${SRC_GEN_DIR}/*.c") - set_source_files_properties(${SRC_MAIN} - PROPERTIES COMPILE_DEFINITIONS - "PRJ_VER_STR=\"${PROJECT_VERSION}\";PRJ_DES_STR=\"${PROJECT_DESCRIPTION}\"") + set(UC_INCLUDE ${SRC_USE_CASE}/${use_case}/include) if (DEFINED ${use_case}_COMPILE_DEFS) message(STATUS "Additional compilation flags for ${use_case}: ${${use_case}_COMPILE_DEFS}") @@ -304,140 +207,33 @@ foreach(use_case ${USE_CASES}) # Consolidated application static lib: add_library(${UC_LIB_NAME} STATIC ${SRC_APPLICATION} - ${SRC_TENSORFLOW_LITE_MICRO} - ${SRC_HAL} ${UC_SRC} - ${SRC_GEN} - ) + ${SRC_GEN}) + target_include_directories(${UC_LIB_NAME} PUBLIC ${APPLICATION_INCLUDE_DIRS} - ${DEP_RUNTIME_INCLUDE_DIRS} ${UC_INCLUDE} ${INC_GEN_DIR} - ) + ${TENSORFLOW_SRC_PATH}/tensorflow/lite/micro/tools/make/downloads/flatbuffers/include) # Set the activation buffer size target_compile_definitions(${UC_LIB_NAME} PUBLIC "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}") - add_dependencies(${UC_LIB_NAME} tensorflow-lite-micro) - - if (${CMAKE_CROSSCOMPILING}) - # If we are building timing adapter, set the dependency: - if (ETHOS_U_NPU_ENABLED) - message(STATUS "Adding timing_adapter as a dependency to ${UC_LIB_NAME}") - add_dependencies(${UC_LIB_NAME} timing_adapter) - endif() - - # If building with CMSIS-DSP support: - if (DEFINED CMSIS_DSP_TARGET) - message(STATUS "Adding ${CMSIS_DSP_TARGET} as a dependency to ${UC_LIB_NAME}") - add_dependencies(${UC_LIB_NAME} ${CMSIS_DSP_TARGET}) - endif() - endif() - - target_link_libraries(${UC_LIB_NAME} PUBLIC ${APPLICATION_LIBS}) - - add_executable(${TARGET_NAME} ${SRC_MAIN} ${PLAT_RETARGET_SOURCE}) + target_link_libraries(${UC_LIB_NAME} PUBLIC + log + arm_math + hal + tensorflow-lite-micro + $<$<BOOL:${APPLICATION_EXTRA_LIBS}>:${APPLICATION_EXTRA_LIBS}> + ) - target_link_libraries(${TARGET_NAME} ${UC_LIB_NAME}) + add_executable(${TARGET_NAME} ${SRC_MAIN}) - if (${CMAKE_CROSSCOMPILING}) - set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".axf") - add_target_map_file(${TARGET_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.map) - endif() + target_link_libraries(${TARGET_NAME} PUBLIC ${UC_LIB_NAME}) - if (${TARGET_PLATFORM} STREQUAL mps3 OR ${TARGET_PLATFORM} STREQUAL simple_platform) - - set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors) - set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case}) - - file(REMOVE_RECURSE ${SECTORS_BIN_DIR}) - file(MAKE_DIRECTORY ${SECTORS_BIN_DIR}) - - add_bin_generation_command( - TARGET_NAME ${TARGET_NAME} - OUTPUT_DIR ${SECTORS_BIN_DIR} - AXF_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.axf - SECTION_PATTERNS "${LINKER_SECTION_TAGS}" - OUTPUT_BIN_NAMES "${LINKER_OUTPUT_BIN_TAGS}") - - if (${TARGET_PLATFORM} STREQUAL mps3) - file(COPY ${MPS3_FPGA_CONFIG} DESTINATION ${SECTORS_DIR}) - endif() - - elseif (${TARGET_PLATFORM} STREQUAL native) - - # If native build tests - set(TEST_SRC_USE_CASE "") - foreach(USE_CASES_TESTS_SEARCH_DIR ${USE_CASES_TESTS_SEARCH_DIR_LIST}) - - if (EXISTS ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}) - message(STATUS "Found tests for use-case ${use_case} at ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}.") - set(TEST_SRC_USE_CASE ${USE_CASES_TESTS_SEARCH_DIR}) - break() - endif () - endforeach() - - # Add tests only if they exists for the usecase - if (NOT ${TEST_SRC_USE_CASE} STREQUAL "") - - set(TEST_RESOURCES_INCLUDE - "${TEST_SRCS}/utils/" - "${TEST_SRC_USE_CASE}/${use_case}/include/" - ) - - # Define Test sources and new target to run unit tests - file(GLOB_RECURSE TEST_SOURCES - "${TEST_SRCS}/common/*.cpp" - "${TEST_SRCS}/common/*.cc" - "${TEST_SRCS}/utils/*.cc" - "${TEST_SRCS}/utils/*.cpp" - "${TEST_SRC_USE_CASE}/${use_case}/*.cpp" - "${TEST_SRC_USE_CASE}/${use_case}/*.cc" - "${TEST_SRC_USE_CASE}/${use_case}/*.c" - "${TEST_SRC_USE_CASE}/${use_case}/**/*.cpp" - "${TEST_SRC_USE_CASE}/${use_case}/**/*.cc" - "${TEST_SRC_USE_CASE}/${use_case}/**/*.c" - ) - - set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src) - set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include) - file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR}) - - set(${use_case}_DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR} CACHE PATH "") - # Generate test data files to be included in x86 tests - generate_test_data_code( - INPUT_DIR "${${use_case}_DEFAULT_TEST_DATA_DIR}" - DESTINATION_SRC ${TEST_SRC_GEN_DIR} - DESTINATION_HDR ${TEST_INC_GEN_DIR} - NAMESPACE "test" - ) - - file(GLOB_RECURSE TEST_SOURCES_GEN - "${TEST_SRC_GEN_DIR}/*.cc" - "${TEST_SRC_GEN_DIR}/**/*.cc" - ) - message(STATUS "Adding ${TEST_SOURCES_GEN} to test sources") - list(APPEND TEST_SOURCES ${TEST_SOURCES_GEN}) - list(APPEND TEST_RESOURCES_INCLUDE ${TEST_INC_GEN_DIR}) - - set(TEST_TARGET_NAME "${CMAKE_PROJECT_NAME}-${use_case}-tests") - add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES}) - target_include_directories(${TEST_TARGET_NAME} PUBLIC - ${TEST_TPIP_INCLUDE} ${TEST_RESOURCES_INCLUDE}) - target_link_libraries(${TEST_TARGET_NAME} ${UC_LIB_NAME}) - target_compile_definitions(${TEST_TARGET_NAME} PRIVATE - "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}" - TESTS) - - add_dependencies( - "${TEST_TARGET_NAME}" - "catch2-headers" - ) + platform_custom_post_build(TARGET_NAME ${TARGET_NAME}) - endif () - endif () endforeach() -print_useroptions() +print_useroptions()
\ No newline at end of file diff --git a/scripts/cmake/bare-metal-sources.cmake b/scripts/cmake/bare-metal-sources.cmake deleted file mode 100644 index abca622..0000000 --- a/scripts/cmake/bare-metal-sources.cmake +++ /dev/null @@ -1,206 +0,0 @@ -#---------------------------------------------------------------------------- -# Copyright (c) 2021 Arm Limited. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#---------------------------------------------------------------------------- -set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build_baremetal) -set(PLAT_HAL ${CMAKE_CURRENT_SOURCE_DIR}/source/application/hal/platforms/bare-metal) - -# If target platform not defined raise an error -# TARGET_PLATFORM either should have been defined by the user or set to default value mps3 -if (NOT DEFINED TARGET_PLATFORM) - message(FATAL_ERROR "Invalid target platform, specify TARGET_PLATFORM=mps3") -endif () -message(STATUS "target platform ${TARGET_PLATFORM}") - -set(SOURCE_GEN_DIR ${CMAKE_BINARY_DIR}/generated/bsp) -if (NOT DEFINED MEM_PROFILES_SRC_DIR) - set(MEM_PROFILES_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/subsystem-profiles) -endif() - -set(MEM_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_memmap.h.template) -set(IRQ_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_irqs.h.template) -set(MEM_REGIONS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/mem_regions.h.template) -set(TA_SETTINGS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/timing_adapter_settings.template) -set(LINKER_SCRIPT_DIR "${PLAT_HAL}/bsp/mem_layout") -set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME "libtensorflow-microlite.a") -set(TENSORFLOW_LITE_MICRO_FLAG "-DTF_LITE_STATIC_MEMORY") -set(ETHOS_U_NPU_FLAG "-DARM_NPU=1") - -if (ETHOS_U_NPU_ENABLED) - - assert_defined(ETHOS_U_NPU_ID) - assert_defined(ETHOS_U_NPU_MEMORY_MODE) - assert_defined(ETHOS_U_NPU_CONFIG_ID) - - if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only) - - if (ETHOS_U_NPU_ID STREQUAL U55) - set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY") - else () - message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `sram_only` can be used only for Ethos-U55.") - endif () - - elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram) - # Shared Sram can be used for Ethos-U55 and Ethos-U65 - set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM") - - elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram) - # Dedicated Sram is used only for Ethos-U65 - if (ETHOS_U_NPU_ID STREQUAL U65) - set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM") - else () - message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `dedicated_sram` can be used only for Ethos-U65.") - endif () - - else () - message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}") - endif () - - set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} ${ETHOS_U_NPU_FLAG} ${ETHOS_U_NPU_MEMORY_MODE_FLAG}") -endif () - -# Set specific flags depending on target platform and subsystem -if (TARGET_PLATFORM STREQUAL mps3) - set(MPS3_PLATFORM_FLAG "-DMPS3_PLATFORM=1") - - # If target platform is mps3 and subsystem not defined raise an error, - # TARGET_SUBSYSTEM either should have been defined by the user or set to a default value - if (NOT DEFINED TARGET_SUBSYSTEM) - message(FATAL_ERROR "Target subsystem for mps3 undefined, " - "specify -DTARGET_SUBSYSTEM=<sse-300>") - endif () - - if (TARGET_SUBSYSTEM STREQUAL sse-300) - message(STATUS "target subsystem is ${TARGET_SUBSYSTEM}") - set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/mps3") - set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}-${TARGET_SUBSYSTEM}") - - # Include the mem profile definitions specific to our target subsystem - include(${MEM_PROFILES_SRC_DIR}/corstone-${TARGET_SUBSYSTEM}.cmake) - set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} ${MPS3_PLATFORM_FLAG}") - - # For deployment on the MPS3 FPGA platform, we need to produce - # two bin files - one that is loaded into the ITCM, and another - # that is loaded into the DDR region. - set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr") - set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin") - set(MPS3_FPGA_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/scripts/${TARGET_PLATFORM}/${TARGET_SUBSYSTEM}/images.txt") - else () - message(FATAL_ERROR "Non compatible target subsystem: ${TARGET_SUBSYSTEM}") - endif () -elseif (TARGET_PLATFORM STREQUAL simple_platform) - set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/${TARGET_PLATFORM}") - set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}") - include(${MEM_PROFILES_SRC_DIR}/${TARGET_PLATFORM}.cmake) - set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS}") - set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr") - set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin") -else () - message(FATAL_ERROR "Non compatible target platform ${TARGET_PLATFORM}") -endif () - -# Add link options for the linker script to be used: -add_linker_script(${LINKER_SCRIPT_DIR} ${LINKER_SCRIPT_NAME}) - -if (ETHOS_U_NPU_ENABLED) - if (ETHOS_U_NPU_ID STREQUAL U55) - set(DEFAULT_TA_CONFIG_FILE_PATH "${CMAKE_SCRIPTS_DIR}/timing_adapter/ta_config_u55_high_end.cmake") - else () - set(DEFAULT_TA_CONFIG_FILE_PATH "${CMAKE_SCRIPTS_DIR}/timing_adapter/ta_config_u65_high_end.cmake") - endif () - - # must be included after target subsystem CMake file - assert_defined(TA_CONFIG_FILE) - include(${TA_CONFIG_FILE}) -endif() - -# Generate the memory map header file from the mem profile cmake included in one of -# the previous sections -message(STATUS "Configuring file from ${MEM_PROFILE_TEMPLATE}" - ", ${IRQ_PROFILE_TEMPLATE}" - " and ${MEM_REGIONS_TEMPLATE}") - -configure_file("${MEM_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_memmap.h") -configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h") -configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h") -configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h") - -message(STATUS "Using BSP package from: ${BSP_PACKAGE_DIR}") - -if (DEFINED VERIFY_TEST_OUTPUT) - message(STATUS "Test output verification flag is: ${VERIFY_TEST_OUTPUT}") - set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DVERIFY_TEST_OUTPUT=${VERIFY_TEST_OUTPUT}") -endif () - -if (DEFINED LOG_LEVEL) - message(STATUS "Setting log level to ${LOG_LEVEL}") - set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DLOG_LEVEL=${LOG_LEVEL}") -endif() - -if (DEFINED ACTIVATION_BUF_SRAM_SZ) - message(STATUS "Maximum SRAM space for activations buffers for this system: ${ACTIVATION_BUF_SRAM_SZ}") - set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DACTIVATION_BUF_SRAM_SZ=${ACTIVATION_BUF_SRAM_SZ}") -endif() - -if (DEFINED ARMCLANG_DEBUG_DWARF_LEVEL) - message(STATUS "setting dwarf conformance level to gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}") - set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}") -endif() - -set(COMPILER_FLAGS "${TENSORFLOW_LITE_MICRO_FLAG} ${PROFILING_OPT} ${OPTIONAL_FLAGS}") -# For some reason, cmake doesn't pass the c++ standard flag, adding it manually -set(CMAKE_CXX_FLAGS "${COMPILER_FLAGS}" CACHE INTERNAL "") -set(CMAKE_C_FLAGS "${COMPILER_FLAGS}" CACHE INTERNAL "") -set(CMAKE_ASM_COMPILE_OBJECT ${CMAKE_CXX_FLAGS}) - -# Tell linker that reset interrupt handler is our entry point -add_link_options(--entry Reset_Handler) - -set(PLAT_BSP_INCLUDES - ${PLAT_HAL}/bsp/cmsis-device/include - ${PLAT_HAL}/bsp/include/ - ${PLAT_HAL}/bsp/bsp-core/include - ${BSP_PACKAGE_DIR}/include -) - -# Include directories: -set(PLAT_INCLUDE_DIRS - ${PLAT_BSP_INCLUDES} - ${PLAT_HAL}/utils/include - ${PLAT_HAL}/images/include - ${PLAT_HAL}/data_presentation/lcd/include - ${PLAT_HAL}/timer/include - ${SOURCE_GEN_DIR} - ) - -# Source files -file(GLOB_RECURSE SRC_PLAT_HAL - - # Higher level HAL sources - software logic implementations - "${PLAT_HAL}/data_*/*.c" - "${PLAT_HAL}/images/*.c" - "${PLAT_HAL}/timer/*.c" - "${PLAT_HAL}/utils/*.c" - - # Low level HAL sources - these enable interaction with - # the actual hardware - "${PLAT_HAL}/bsp/cmsis-device/*.c" - "${PLAT_HAL}/bsp/bsp-core/*.c" - "${BSP_PACKAGE_DIR}/*.c" - ) - -# Special retarget source to direct stdin, stdout and stderr streams to the -# UART block. -set(PLAT_RETARGET_SOURCE "${PLAT_HAL}/bsp/bsp-core/retarget.c") diff --git a/scripts/cmake/cmsis-dsp.cmake b/scripts/cmake/cmsis-dsp.cmake index ab2b0f9..f2de158 100644 --- a/scripts/cmake/cmsis-dsp.cmake +++ b/scripts/cmake/cmsis-dsp.cmake @@ -17,12 +17,7 @@ # CMSIS-DSP library CMake helper script. -# 1. We should be cross-compiling (non-native target) -if (TARGET_PLATFORM STREQUAL native) - message(FATAL_ERROR "No CMSIS-DSP support for native target.") -endif() - -# 2. Check if CMSIS sources have been defined +# Check if CMSIS sources have been defined if (NOT DEFINED CMSIS_SRC_PATH) message(FATAL_ERROR "CMSIS path should be defined for CMSIS-DSP library to be built") endif() diff --git a/scripts/cmake/common_user_options.cmake b/scripts/cmake/common_user_options.cmake index 13c88d2..afc5386 100644 --- a/scripts/cmake/common_user_options.cmake +++ b/scripts/cmake/common_user_options.cmake @@ -29,8 +29,6 @@ endif() message(STATUS "Assessing common user options...") -set(CMAKE_TOOLCHAIN_DIR ${CMAKE_CURRENT_LIST_DIR}/toolchains) -set(DEPENDENCY_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../dependencies) include(${CMAKE_CURRENT_LIST_DIR}/util_functions.cmake) USER_OPTION(LOG_LEVEL "Log level for the application" @@ -143,22 +141,3 @@ if (NOT TARGET_PLATFORM STREQUAL native) FILEPATH) endif() endif() - -if (TARGET_PLATFORM STREQUAL mps3) - message(STATUS "Platform: MPS3 FPGA Prototyping Board or FVP") - set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake) -elseif (TARGET_PLATFORM STREQUAL simple_platform) - message(STATUS "Platform: Simple platform with minimal peripherals") - set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake) -elseif (TARGET_PLATFORM STREQUAL native) - message(STATUS "Platform: Native (Linux based x86_64/aarch64 system)") - set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/native-gcc.cmake) -else () - message(FATAL_ERROR "Invalid platform specified: ${TARGET_PLATFORM}") -endif () - -if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) - set(CMAKE_TOOLCHAIN_FILE ${DEFAULT_TOOLCHAIN_FILE} - CACHE FILEPATH "Toolchain file") -endif() -message(STATUS "Using CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") diff --git a/scripts/cmake/native-sources.cmake b/scripts/cmake/native-sources.cmake deleted file mode 100644 index 6ebf435..0000000 --- a/scripts/cmake/native-sources.cmake +++ /dev/null @@ -1,61 +0,0 @@ -#---------------------------------------------------------------------------- -# Copyright (c) 2021 Arm Limited. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#---------------------------------------------------------------------------- -# Set the install prefix -set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build_native) -set(PLAT_HAL ${CMAKE_CURRENT_SOURCE_DIR}/source/application/hal/platforms/native) - -if (ETHOS_U_NPU_ENABLED) - message(WARNING "EthosU can't be enabled for native builds." - "Use -DETHOS_U_NPU_ENABLED=OFF flag for this target platform." - "Overriding, disabling use of EthosU...") - set(ETHOS_U_NPU_ENABLED OFF) -endif() - -if (DEFINED LOG_LEVEL) - message(STATUS "Setting log level to ${LOG_LEVEL}") - set (LOG_FLAG "-DLOG_LEVEL=${LOG_LEVEL}") -endif() - -set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME "libtensorflow-microlite.a") -set(TENSORFLOW_LITE_MICRO_FLAGS "-DTF_LITE_STATIC_MEMORY -DACTIVATION_BUF_SRAM_SZ=0") - -if (DEFINED VERIFY_TEST_OUTPUT) - message(STATUS "Test output verification flag is: ${VERIFY_TEST_OUTPUT}") - set(PROFILING_OPT "${PROFILING_OPT} -DVERIFY_TEST_OUTPUT=${VERIFY_TEST_OUTPUT}") -endif () - -set(CMAKE_C_FLAGS - "${PROFILING_OPT} ${LOG_FLAG} ${TENSORFLOW_LITE_MICRO_FLAGS}" - CACHE INTERNAL "") - -set(CMAKE_CXX_FLAGS - "${PROFILING_OPT} ${LOG_FLAG} ${TENSORFLOW_LITE_MICRO_FLAGS}" - CACHE INTERNAL "") - -# Include directories: -set(PLAT_INCLUDE_DIRS - ${PLAT_HAL}/utils/include - ${PLAT_HAL}/images/include - ${PLAT_HAL}/data_presentation/log/include - ${PLAT_HAL}/timer/include - ) - -# Source files -file(GLOB_RECURSE SRC_PLAT_HAL - "${PLAT_HAL}/**/*.c" - "${PLAT_HAL}/**/*.cc" - ) diff --git a/scripts/cmake/platforms/mps3/build_configuration.cmake b/scripts/cmake/platforms/mps3/build_configuration.cmake new file mode 100644 index 0000000..76c9e78 --- /dev/null +++ b/scripts/cmake/platforms/mps3/build_configuration.cmake @@ -0,0 +1,67 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2022 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#---------------------------------------------------------------------------- + +function(set_platform_global_defaults) + message(STATUS "Platform: MPS3 FPGA Prototyping Board or FVP") + if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake + CACHE FILEPATH "Toolchain file") + endif() + + set(LINKER_SCRIPT_NAME "mps3-${TARGET_SUBSYSTEM}" PARENT_SCOPE) + set(PLATFORM_DRIVERS_DIR "${HAL_PLATFORM_DIR}/mps3" PARENT_SCOPE) + +endfunction() + +function(platform_custom_post_build) + set(oneValueArgs TARGET_NAME) + cmake_parse_arguments(PARSED "" "${oneValueArgs}" "" ${ARGN} ) + + set_target_properties(${PARSED_TARGET_NAME} PROPERTIES SUFFIX ".axf") + # Add link options for the linker script to be used: + add_linker_script( + ${PARSED_TARGET_NAME} # Target + ${CMAKE_SCRIPTS_DIR}/platforms/mps3 # Directory path + ${LINKER_SCRIPT_NAME}) # Name of the file without suffix + + add_target_map_file( + ${PARSED_TARGET_NAME} + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.map) + + set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors) + set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case}) + + file(REMOVE_RECURSE ${SECTORS_BIN_DIR}) + file(MAKE_DIRECTORY ${SECTORS_BIN_DIR}) + + set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr") + set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin") + + add_bin_generation_command( + TARGET_NAME ${PARSED_TARGET_NAME} + OUTPUT_DIR ${SECTORS_BIN_DIR} + AXF_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.axf + SECTION_PATTERNS "${LINKER_SECTION_TAGS}" + OUTPUT_BIN_NAMES "${LINKER_OUTPUT_BIN_TAGS}") + + set(MPS3_FPGA_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/scripts/mps3/${TARGET_SUBSYSTEM}/images.txt") + + add_custom_command(TARGET ${PARSED_TARGET_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${MPS3_FPGA_CONFIG} ${SECTORS_DIR}) + +endfunction()
\ No newline at end of file diff --git a/source/application/hal/platforms/bare-metal/bsp/mem_layout/mps3-sse-300.ld b/scripts/cmake/platforms/mps3/mps3-sse-300.ld index d369fa7..d369fa7 100644 --- a/source/application/hal/platforms/bare-metal/bsp/mem_layout/mps3-sse-300.ld +++ b/scripts/cmake/platforms/mps3/mps3-sse-300.ld diff --git a/source/application/hal/platforms/bare-metal/bsp/mem_layout/mps3-sse-300.sct b/scripts/cmake/platforms/mps3/mps3-sse-300.sct index f78dc25..f78dc25 100644 --- a/source/application/hal/platforms/bare-metal/bsp/mem_layout/mps3-sse-300.sct +++ b/scripts/cmake/platforms/mps3/mps3-sse-300.sct diff --git a/scripts/cmake/platforms/native/build_configuration.cmake b/scripts/cmake/platforms/native/build_configuration.cmake new file mode 100644 index 0000000..c87ac89 --- /dev/null +++ b/scripts/cmake/platforms/native/build_configuration.cmake @@ -0,0 +1,113 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2022 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#---------------------------------------------------------------------------- + +set(TEST_TPIP ${DOWNLOAD_DEP_DIR}/test) + +file(MAKE_DIRECTORY ${TEST_TPIP}) +set(TEST_TPIP_INCLUDE ${TEST_TPIP}/include) +file(MAKE_DIRECTORY ${TEST_TPIP_INCLUDE}) + +ExternalProject_Add(catch2-headers + URL https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp + DOWNLOAD_NO_EXTRACT 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND bash -c "cp -R <DOWNLOAD_DIR>/catch.hpp ${TEST_TPIP_INCLUDE}" + INSTALL_COMMAND "") + +function(set_platform_global_defaults) + message(STATUS "Platform: Native (Linux based x86_64/aarch64 system)") + if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/native-gcc.cmake + CACHE FILEPATH "Toolchain file") + endif() + +endfunction() + +function(platform_custom_post_build) + set(oneValueArgs TARGET_NAME) + cmake_parse_arguments(PARSED "" "${oneValueArgs}" "" ${ARGN} ) + + + # If native build tests + set(TEST_SRC_USE_CASE "") + foreach(USE_CASES_TESTS_SEARCH_DIR ${USE_CASES_TESTS_SEARCH_DIR_LIST}) + + if (EXISTS ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}) + message(STATUS "Found tests for use-case ${use_case} at ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}.") + set(TEST_SRC_USE_CASE ${USE_CASES_TESTS_SEARCH_DIR}) + break() + endif () + endforeach() + + # Add tests only if they exists for the usecase + if (NOT ${TEST_SRC_USE_CASE} STREQUAL "") + + set(TEST_RESOURCES_INCLUDE + "${TEST_SRCS}/utils/" + "${TEST_SRC_USE_CASE}/${use_case}/include/" + ) + + # Define Test sources and new target to run unit tests + file(GLOB_RECURSE TEST_SOURCES + "${TEST_SRCS}/common/*.cpp" + "${TEST_SRCS}/common/*.cc" + "${TEST_SRCS}/utils/*.cc" + "${TEST_SRCS}/utils/*.cpp" + "${TEST_SRC_USE_CASE}/${use_case}/*.cpp" + "${TEST_SRC_USE_CASE}/${use_case}/*.cc" + "${TEST_SRC_USE_CASE}/${use_case}/*.c" + "${TEST_SRC_USE_CASE}/${use_case}/**/*.cpp" + "${TEST_SRC_USE_CASE}/${use_case}/**/*.cc" + "${TEST_SRC_USE_CASE}/${use_case}/**/*.c" + ) + + set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src) + set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include) + file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR}) + + set(${use_case}_DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR} CACHE PATH "") + # Generate test data files to be included in x86 tests + generate_test_data_code( + INPUT_DIR "${${use_case}_DEFAULT_TEST_DATA_DIR}" + DESTINATION_SRC ${TEST_SRC_GEN_DIR} + DESTINATION_HDR ${TEST_INC_GEN_DIR} + NAMESPACE "test" + ) + + file(GLOB_RECURSE TEST_SOURCES_GEN + "${TEST_SRC_GEN_DIR}/*.cc" + "${TEST_SRC_GEN_DIR}/**/*.cc" + ) + message(STATUS "Adding ${TEST_SOURCES_GEN} to test sources") + list(APPEND TEST_SOURCES ${TEST_SOURCES_GEN}) + list(APPEND TEST_RESOURCES_INCLUDE ${TEST_INC_GEN_DIR}) + + set(TEST_TARGET_NAME "${CMAKE_PROJECT_NAME}-${use_case}-tests") + add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES}) + target_include_directories(${TEST_TARGET_NAME} PUBLIC + ${TEST_TPIP_INCLUDE} ${TEST_RESOURCES_INCLUDE}) + target_link_libraries(${TEST_TARGET_NAME} PUBLIC ${UC_LIB_NAME}) + target_compile_definitions(${TEST_TARGET_NAME} PRIVATE + "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}" + TESTS) + + add_dependencies( + "${TEST_TARGET_NAME}" + "catch2-headers" + ) + endif () +endfunction()
\ No newline at end of file diff --git a/scripts/cmake/platforms/simple_platform/build_configuration.cmake b/scripts/cmake/platforms/simple_platform/build_configuration.cmake new file mode 100644 index 0000000..3d46884 --- /dev/null +++ b/scripts/cmake/platforms/simple_platform/build_configuration.cmake @@ -0,0 +1,59 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2022 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#---------------------------------------------------------------------------- + +function(set_platform_global_defaults) + message(STATUS "Platform: Simple platform with minimal peripherals") + if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake + CACHE FILEPATH "Toolchain file") + endif() + set(LINKER_SCRIPT_NAME "simple_platform" PARENT_SCOPE) + set(PLATFORM_DRIVERS_DIR "${HAL_PLATFORM_DIR}/simple" PARENT_SCOPE) +endfunction() + +function(platform_custom_post_build) + set(oneValueArgs TARGET_NAME) + cmake_parse_arguments(PARSED "" "${oneValueArgs}" "" ${ARGN} ) + + set_target_properties(${PARSED_TARGET_NAME} PROPERTIES SUFFIX ".axf") + # Add link options for the linker script to be used: + + add_linker_script( + ${PARSED_TARGET_NAME} # Target + ${CMAKE_SCRIPTS_DIR}/platforms/simple_platform # Directory path + ${LINKER_SCRIPT_NAME}) # Name of the file without suffix + + add_target_map_file( + ${PARSED_TARGET_NAME} + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.map) + + set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors) + set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case}) + + file(REMOVE_RECURSE ${SECTORS_BIN_DIR}) + file(MAKE_DIRECTORY ${SECTORS_BIN_DIR}) + + set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr") + set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin") + + add_bin_generation_command( + TARGET_NAME ${PARSED_TARGET_NAME} + OUTPUT_DIR ${SECTORS_BIN_DIR} + AXF_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.axf + SECTION_PATTERNS "${LINKER_SECTION_TAGS}" + OUTPUT_BIN_NAMES "${LINKER_OUTPUT_BIN_TAGS}") +endfunction()
\ No newline at end of file diff --git a/source/application/hal/platforms/bare-metal/bsp/mem_layout/simple_platform.ld b/scripts/cmake/platforms/simple_platform/simple_platform.ld index 82cb18e..82cb18e 100644 --- a/source/application/hal/platforms/bare-metal/bsp/mem_layout/simple_platform.ld +++ b/scripts/cmake/platforms/simple_platform/simple_platform.ld diff --git a/source/application/hal/platforms/bare-metal/bsp/mem_layout/simple_platform.sct b/scripts/cmake/platforms/simple_platform/simple_platform.sct index 5825d47..5825d47 100644 --- a/source/application/hal/platforms/bare-metal/bsp/mem_layout/simple_platform.sct +++ b/scripts/cmake/platforms/simple_platform/simple_platform.sct diff --git a/scripts/cmake/tensorflow.cmake b/scripts/cmake/tensorflow.cmake index 43fbb5c..9a4066d 100644 --- a/scripts/cmake/tensorflow.cmake +++ b/scripts/cmake/tensorflow.cmake @@ -43,7 +43,7 @@ set(TENSORFLOW_LITE_MICRO_TARGET_TOOLCHAIN_ROOT "${TENSORFLOW_LITE_MICRO_TARGET_ set(TENSORFLOW_LITE_MICRO_PATH "${TENSORFLOW_SRC_PATH}/tensorflow/lite/micro") set(TENSORFLOW_LITE_MICRO_GENDIR ${CMAKE_CURRENT_BINARY_DIR}/tensorflow/) - +set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME "libtensorflow-microlite.a") set(ETHOS_EVAL_TARGET_MAKEFILE_INC ${CMAKE_CURRENT_SOURCE_DIR}/scripts/make/cortex_m_ethos_eval_makefile.inc) @@ -65,6 +65,22 @@ else() DESTINATION ${TENSORFLOW_LITE_MICRO_PATH}/tools/make/targets/) endif() +#TODO: this thing fails the TF build, when the driver is compiled, fatal error: 'ethosETHOSU_ARCH_interface.h' file not found +#if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m55) +# set(TENSORFLOW_LITE_MICRO_TARGET "cortex_m_generic") +# set(TENSORFLOW_LITE_MICRO_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR}${CPU_FEATURES}) +# if(ETHOS_U_NPU_ENABLED) +# # Arm Ethos-U55 NPU is the co-processor for ML workload: +# set(TENSORFLOW_LITE_MICRO_CO_PROCESSOR "ethos_u") +# endif() +# +# set(TENSORFLOW_LITE_MICRO_OPTIMIZED_KERNEL "cmsis_nn") +# +#else() +# set(TENSORFLOW_LITE_MICRO_TARGET "linux") +# set(TENSORFLOW_LITE_MICRO_TARGET_ARCH x86_64) +#endif() + if (TENSORFLOW_LITE_MICRO_CLEAN_DOWNLOADS) list(APPEND MAKE_TARGETS_LIST "clean_downloads") endif() @@ -93,10 +109,9 @@ add_custom_target(tensorflow_build ALL TARGET_ARCH=${TENSORFLOW_LITE_MICRO_TARGET_ARCH} BUILD_TYPE=${TENSORFLOW_LITE_MICRO_BUILD_TYPE} ETHOSU_ARCH=${ETHOSU_ARCH} - + ETHOSU_DRIVER_PATH=${ETHOS_U_NPU_DRIVER_SRC_PATH} + CMSIS_PATH=${CMSIS_SRC_PATH} # Conditional arguments - $<$<NOT:$<STREQUAL:${TARGET_PLATFORM},"native">>:ETHOSU_DRIVER_PATH=${ETHOS_U_NPU_DRIVER_SRC_PATH}> - $<$<NOT:$<STREQUAL:${TARGET_PLATFORM},"native">>:CMSIS_PATH=${CMSIS_SRC_PATH}> $<$<BOOL:${ARMCLANG_DEBUG_DWARF_LEVEL}>:ARMCLANG_DEBUG_DWARF_LEVEL=${ARMCLANG_DEBUG_DWARF_LEVEL}> $<$<BOOL:${TENSORFLOW_LITE_MICRO_CORE_OPTIMIZATION_LEVEL}>:CORE_OPTIMIZATION_LEVEL=${TENSORFLOW_LITE_MICRO_CORE_OPTIMIZATION_LEVEL}> $<$<BOOL:${TENSORFLOW_LITE_MICRO_KERNEL_OPTIMIZATION_LEVEL}>:KERNEL_OPTIMIZATION_LEVEL=${TENSORFLOW_LITE_MICRO_KERNEL_OPTIMIZATION_LEVEL}> @@ -116,7 +131,18 @@ add_custom_target(tensorflow_build ALL WORKING_DIRECTORY ${TENSORFLOW_SRC_PATH}) # Create library + add_library(tensorflow-lite-micro STATIC IMPORTED) + add_dependencies(tensorflow-lite-micro tensorflow_build) + set_property(TARGET tensorflow-lite-micro PROPERTY IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME}") + +target_include_directories(tensorflow-lite-micro + INTERFACE + ${TENSORFLOW_SRC_PATH}) + +target_compile_definitions(tensorflow-lite-micro + INTERFACE + TF_LITE_STATIC_MEMORY) diff --git a/scripts/cmake/toolchains/bare-metal-armclang.cmake b/scripts/cmake/toolchains/bare-metal-armclang.cmake index afe6e66..065395b 100644 --- a/scripts/cmake/toolchains/bare-metal-armclang.cmake +++ b/scripts/cmake/toolchains/bare-metal-armclang.cmake @@ -30,7 +30,6 @@ set(MIN_ARM_CLANG_VERSION 6.16) # Skip compiler test execution set(CMAKE_C_COMPILER_WORKS 1) set(CMAKE_CXX_COMPILER_WORKS 1) -set(PLATFORM_HAL 1) if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) set(CMAKE_SYSTEM_PROCESSOR cortex-m55) @@ -76,7 +75,6 @@ add_compile_options( # Compile definitions: add_compile_definitions( - PLATFORM_HAL=${PLATFORM_HAL} CPU_HEADER_FILE=\"${CPU_HEADER_FILE}\" $<$<BOOL:${CPU_COMPILE_DEF}>:${CPU_COMPILE_DEF}> $<$<BOOL:${ARM_MATH_DSP}>:ARM_MATH_DSP> @@ -105,14 +103,14 @@ function(add_target_map_file TARGET_NAME MAP_FILE_PATH) endfunction() # Function to add linker option to use the chosen linker script (scatter file). -function(add_linker_script SCRIPT_DIR SCRIPT_NAME) - set(LINKER_SCRIPT_PATH ${SCRIPT_DIR}/${SCRIPT_NAME}.sct - CACHE STRING "Linker script path") +function(add_linker_script TARGET_NAME SCRIPT_DIR SCRIPT_NAME) + set(LINKER_SCRIPT_PATH ${SCRIPT_DIR}/${SCRIPT_NAME}.sct) if (NOT EXISTS ${LINKER_SCRIPT_PATH}) message(FATAL_ERROR "Scatter file not found: ${LINKER_SCRIPT_PATH}") endif() message(STATUS "Using linker script: ${LINKER_SCRIPT_PATH}") - add_link_options(--scatter=${LINKER_SCRIPT_PATH}) + target_link_options(${TARGET_NAME} PUBLIC + --scatter=${LINKER_SCRIPT_PATH}) endfunction() # Function to set the command to copy/extract contents from an elf diff --git a/scripts/cmake/toolchains/bare-metal-gcc.cmake b/scripts/cmake/toolchains/bare-metal-gcc.cmake index 1ddfb44..89201fb 100644 --- a/scripts/cmake/toolchains/bare-metal-gcc.cmake +++ b/scripts/cmake/toolchains/bare-metal-gcc.cmake @@ -28,7 +28,6 @@ set(MIN_GCC_VERSION 10.2.1) # Skip compiler test execution set(CMAKE_C_COMPILER_WORKS 1) set(CMAKE_CXX_COMPILER_WORKS 1) -set(PLATFORM_HAL 1) if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) set(CMAKE_SYSTEM_PROCESSOR cortex-m55) @@ -75,7 +74,6 @@ add_compile_options( # Compile definitions: add_compile_definitions( - PLATFORM_HAL=${PLATFORM_HAL} CPU_HEADER_FILE=\"${CPU_HEADER_FILE}\" $<$<BOOL:${CPU_COMPILE_DEF}>:${CPU_COMPILE_DEF}> $<$<BOOL:${ARM_MATH_DSP}>:ARM_MATH_DSP> @@ -99,14 +97,15 @@ function(add_target_map_file TARGET_NAME MAP_FILE_PATH) endfunction() # Function to add linker option to use the chosen linker script. -function(add_linker_script SCRIPT_DIR SCRIPT_NAME) +function(add_linker_script TARGET_NAME SCRIPT_DIR SCRIPT_NAME) set(LINKER_SCRIPT_PATH ${SCRIPT_DIR}/${SCRIPT_NAME}.ld CACHE STRING "Linker script path") if (NOT EXISTS ${LINKER_SCRIPT_PATH}) message(FATAL_ERROR "Linker script not found: ${LINKER_SCRIPT_PATH}") endif() message(STATUS "Using linker script: ${LINKER_SCRIPT_PATH}") - add_link_options("SHELL:-T ${LINKER_SCRIPT_PATH}") + target_link_options(${TARGET_NAME} PUBLIC + "SHELL:-T ${LINKER_SCRIPT_PATH}") endfunction() # Function to set the command to copy/extract contents from an elf diff --git a/scripts/cmake/toolchains/native-gcc.cmake b/scripts/cmake/toolchains/native-gcc.cmake index 4b5a62b..150a59b 100644 --- a/scripts/cmake/toolchains/native-gcc.cmake +++ b/scripts/cmake/toolchains/native-gcc.cmake @@ -19,9 +19,6 @@ set(CMAKE_C_COMPILER gcc) set(CMAKE_C_LINKER_PREFERENCE gcc) set(CMAKE_CXX_LINKER_PREFERENCE gcc) -# Platform specific directory: -set(PLATFORM_HAL 3) - # Warning compiler definitions: add_compile_options( -Wsign-compare @@ -38,7 +35,6 @@ add_compile_options( add_compile_options( -fPIC -pthread - -DPLATFORM_HAL=${PLATFORM_HAL} "$<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>") # Linker options diff --git a/set_up_default_resources.py b/set_up_default_resources.py index 5ff829e..32c4506 100755 --- a/set_up_default_resources.py +++ b/set_up_default_resources.py @@ -204,18 +204,18 @@ def get_default_npu_config_from_name(config_name: str, arena_cache_size: int = 0 for i in range(len(strings_ids)): if config_name.startswith(strings_ids[i]): npu_config_id = config_name.replace(strings_ids[i], prefix_ids[i]) - return NPUConfig(config_name=config_name, - memory_mode=memory_modes[i], - system_config=system_configs[i], - ethos_u_npu_id=processor_ids[i], - ethos_u_config_id=npu_config_id, - arena_cache_size=memory_modes_arena[memory_modes[i]]) + return NPUConfig(config_name=config_name, + memory_mode=memory_modes[i], + system_config=system_configs[i], + ethos_u_npu_id=processor_ids[i], + ethos_u_config_id=npu_config_id, + arena_cache_size=memory_modes_arena[memory_modes[i]]) return None def set_up_resources(run_vela_on_models: bool = False, - additional_npu_config_names: list = [], + additional_npu_config_names: list = (), arena_cache_size: int = 0): """ Helpers function that retrieve the output from a command. diff --git a/source/application/hal/platforms/native/utils/include/dummy_log.h b/source/application/hal/platforms/native/utils/include/dummy_log.h deleted file mode 100644 index 3df5c5c..0000000 --- a/source/application/hal/platforms/native/utils/include/dummy_log.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021 Arm Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef DUMMY_LOG_H -#define DUMMY_LOG_H - -#include <stdio.h> - -#define LOG_LEVEL_TRACE 0 -#define LOG_LEVEL_DEBUG 1 -#define LOG_LEVEL_INFO 2 -#define LOG_LEVEL_WARN 3 -#define LOG_LEVEL_ERROR 4 - -#ifndef LOG_LEVEL -#define LOG_LEVEL LOG_LEVEL_INFO -#endif /*LOG_LEVEL*/ - -#define UNUSED(x) ((void)(x)) - -#if (LOG_LEVEL == LOG_LEVEL_TRACE) - #define trace(...) printf("TRACE - "); printf(__VA_ARGS__) -#else - #define trace(...) -#endif /* LOG_LEVEL == LOG_LEVEL_TRACE */ - -#if (LOG_LEVEL <= LOG_LEVEL_DEBUG) - #define debug(...) printf("DEBUG - "); printf(__VA_ARGS__) -#else - #define debug(...) -#endif /* LOG_LEVEL > LOG_LEVEL_TRACE */ - -#if (LOG_LEVEL <= LOG_LEVEL_INFO) - #define info(...) printf("INFO - "); printf(__VA_ARGS__) -#else - #define info(...) -#endif /* LOG_LEVEL > LOG_LEVEL_DEBUG */ - -#if (LOG_LEVEL <= LOG_LEVEL_WARN) - #define warn(...) printf("WARN - "); printf(__VA_ARGS__) -#else - #define warn(...) -#endif /* LOG_LEVEL > LOG_LEVEL_INFO */ - -#if (LOG_LEVEL <= LOG_LEVEL_ERROR) - #define printf_err(...) printf("ERROR - "); printf(__VA_ARGS__) -#else - #define printf_err(...) -#endif /* LOG_LEVEL > LOG_LEVEL_INFO */ - -#endif /* DUMMY_LOG_H */
\ No newline at end of file diff --git a/source/application/main/Classifier.cc b/source/application/main/Classifier.cc index a6ff532..6fabebe 100644 --- a/source/application/main/Classifier.cc +++ b/source/application/main/Classifier.cc @@ -16,15 +16,16 @@ */ #include "Classifier.hpp" -#include "hal.h" #include "TensorFlowLiteMicro.hpp" +#include "PlatformMath.hpp" +#include "log_macros.h" #include <vector> #include <string> #include <set> #include <cstdint> -#include <inttypes.h> -#include "PlatformMath.hpp" +#include <cinttypes> + namespace arm { namespace app { diff --git a/source/application/main/Main.cc b/source/application/main/Main.cc index 9622566..3a1c110 100644 --- a/source/application/main/Main.cc +++ b/source/application/main/Main.cc @@ -20,6 +20,7 @@ \****************************************************************************/ #include "hal.h" /* our hardware abstraction api */ +#include "log_macros.h" #include "TensorFlowLiteMicro.hpp" /* our inference logic api */ #include <cstdio> diff --git a/source/application/main/Mfcc.cc b/source/application/main/Mfcc.cc index 2d697ee..3bf5eb3 100644 --- a/source/application/main/Mfcc.cc +++ b/source/application/main/Mfcc.cc @@ -15,11 +15,11 @@ * limitations under the License. */ #include "Mfcc.hpp" - #include "PlatformMath.hpp" +#include "log_macros.h" #include <cfloat> -#include <inttypes.h> +#include <cinttypes> namespace arm { namespace app { diff --git a/source/application/main/UseCaseCommonUtils.cc b/source/application/main/UseCaseCommonUtils.cc index 67e784b..dd9a32d 100644 --- a/source/application/main/UseCaseCommonUtils.cc +++ b/source/application/main/UseCaseCommonUtils.cc @@ -16,7 +16,9 @@ */ #include "UseCaseCommonUtils.hpp" #include "InputFiles.hpp" -#include <inttypes.h> +#include "log_macros.h" + +#include <cinttypes> void DisplayCommonMenu() @@ -74,7 +76,7 @@ bool image::PresentInferenceResult( platform.data_psn->present_data_text( resultStr.c_str(), resultStr.size(), - dataPsnTxtStartX1, rowIdx1, 0); + dataPsnTxtStartX1, rowIdx1, false); rowIdx1 += dataPsnTxtYIncr; resultStr = std::to_string(i + 1) + ") " + results[i].m_label; @@ -105,7 +107,7 @@ void image::RgbToGrayscale(const uint8_t *srcPtr, uint8_t *dstPtr, const size_t } } -void IncrementAppCtxIfmIdx(arm::app::ApplicationContext& ctx, std::string useCase) +void IncrementAppCtxIfmIdx(arm::app::ApplicationContext& ctx, const std::string& useCase) { #if NUMBER_OF_FILES > 0 auto curImIdx = ctx.Get<uint32_t>(useCase); @@ -122,7 +124,7 @@ void IncrementAppCtxIfmIdx(arm::app::ApplicationContext& ctx, std::string useCas #endif /* NUMBER_OF_FILES > 0 */ } -bool SetAppCtxIfmIdx(arm::app::ApplicationContext& ctx, uint32_t idx, std::string ctxIfmName) +bool SetAppCtxIfmIdx(arm::app::ApplicationContext& ctx, uint32_t idx, const std::string& ctxIfmName) { #if NUMBER_OF_FILES > 0 if (idx >= NUMBER_OF_FILES) { @@ -192,7 +194,7 @@ void DumpTensor(const TfLiteTensor* tensor, const size_t lineBreakForNumElements } const uint32_t tensorSz = tensor->bytes; - const uint8_t* tensorData = tflite::GetTensorData<uint8_t>(tensor); + const auto* tensorData = tflite::GetTensorData<uint8_t>(tensor); DumpTensorData(tensorData, tensorSz, lineBreakForNumElements); } diff --git a/source/application/main/include/Classifier.hpp b/source/application/main/include/Classifier.hpp index d899e8e..d641c22 100644 --- a/source/application/main/include/Classifier.hpp +++ b/source/application/main/include/Classifier.hpp @@ -50,7 +50,7 @@ namespace app { TfLiteTensor* outputTensor, std::vector<ClassificationResult>& vecResults, const std::vector <std::string>& labels, uint32_t topNCount, - bool use_softmax = false); + bool use_softmax); /** * @brief Populate the elements of the Classification Result object. diff --git a/source/application/main/include/DataStructures.hpp b/source/application/main/include/DataStructures.hpp index d369cb6..0616839 100644 --- a/source/application/main/include/DataStructures.hpp +++ b/source/application/main/include/DataStructures.hpp @@ -17,8 +17,6 @@ #ifndef DATA_STRUCTURES_HPP #define DATA_STRUCTURES_HPP -#include "hal.h" - #include <iterator> namespace arm { @@ -50,7 +48,7 @@ namespace app { Array2d(unsigned rows, unsigned cols): m_rows(rows), m_cols(cols) { if (rows == 0 || cols == 0) { - printf_err("Array2d constructor has 0 size.\n"); + printf("Array2d constructor has 0 size.\n"); m_data = nullptr; return; } diff --git a/source/application/main/include/UseCaseCommonUtils.hpp b/source/application/main/include/UseCaseCommonUtils.hpp index 84b5de3..cd0cb69 100644 --- a/source/application/main/include/UseCaseCommonUtils.hpp +++ b/source/application/main/include/UseCaseCommonUtils.hpp @@ -24,7 +24,7 @@ #include "UseCaseHandler.hpp" /* Handlers for different user options. */ #include "Classifier.hpp" /* Classifier. */ #include "InputFiles.hpp" -#include <inttypes.h> +#include <cinttypes> /* Helper macro to convert RGB888 to RGB565 format. */ @@ -33,8 +33,8 @@ ((B8>>3) & 0x1F)) constexpr uint16_t COLOR_BLACK = 0; -constexpr uint16_t COLOR_GREEN = RGB888_TO_RGB565( 0, 255, 0); // 2016; -constexpr uint16_t COLOR_YELLOW = RGB888_TO_RGB565(255, 255, 0); // 65504; +constexpr uint16_t COLOR_GREEN = RGB888_TO_RGB565( 0u, 255u, 0u); // 2016; +constexpr uint16_t COLOR_YELLOW = RGB888_TO_RGB565(255u, 255u, 0u); // 65504; void DisplayCommonMenu(); @@ -72,7 +72,7 @@ namespace image{ * @param[in,out] ctx Pointer to the application context object. * @param[in] useCase Use case name **/ -void IncrementAppCtxIfmIdx(arm::app::ApplicationContext& ctx, std::string useCase); +void IncrementAppCtxIfmIdx(arm::app::ApplicationContext& ctx, const std::string& useCase); /** * @brief Helper function to set the input feature map index. @@ -81,7 +81,7 @@ void IncrementAppCtxIfmIdx(arm::app::ApplicationContext& ctx, std::string useCas * @param[in] ctxIfmName Input Feature Map name * @return true if index is set, false otherwise. **/ -bool SetAppCtxIfmIdx(arm::app::ApplicationContext& ctx, uint32_t idx, std::string ctxIfmName); +bool SetAppCtxIfmIdx(arm::app::ApplicationContext& ctx, uint32_t idx, const std::string& ctxIfmName); namespace common { diff --git a/source/application/profiler/Profiler.cc b/source/application/profiler/Profiler.cc index c2b8f2a..efbc64d 100644 --- a/source/application/profiler/Profiler.cc +++ b/source/application/profiler/Profiler.cc @@ -15,9 +15,9 @@ * limitations under the License. */ #include "Profiler.hpp" +#include "log_macros.h" #include <cstring> -#include <iomanip> namespace arm { namespace app { diff --git a/source/application/tensorflow-lite-micro/Model.cc b/source/application/tensorflow-lite-micro/Model.cc index acc2f0e..adcf8d7 100644 --- a/source/application/tensorflow-lite-micro/Model.cc +++ b/source/application/tensorflow-lite-micro/Model.cc @@ -15,19 +15,14 @@ * limitations under the License. */ #include "Model.hpp" +#include "log_macros.h" -#include "hal.h" - -#include <cstdint> -#include <inttypes.h> +#include <cinttypes> /* Initialise the model */ arm::app::Model::~Model() { - if (this->m_pInterpreter) { - delete this->m_pInterpreter; - } - + delete this->m_pInterpreter; /** * No clean-up function available for allocator in TensorFlow Lite Micro yet. **/ @@ -222,7 +217,7 @@ void arm::app::Model::LogInterpreterInfo() tflite::GetRegistrationFromOpCode(opcode, this->GetOpResolver(), this->m_pErrorReporter, ®); - std::string opName{""}; + std::string opName; if (reg) { if (tflite::BuiltinOperator_CUSTOM == reg->builtin_code) { @@ -262,7 +257,7 @@ bool arm::app::Model::ContainsEthosUOperator() const auto builtin_code = tflite::GetBuiltinCode(opcode); if ((builtin_code == tflite::BuiltinOperator_CUSTOM) && ( nullptr != opcode->custom_code()) && - ( 0 == std::string(opcode->custom_code()->c_str()).compare("ethos-u"))) + ( "ethos-u" == std::string(opcode->custom_code()->c_str()))) { return true; } @@ -350,11 +345,7 @@ bool arm::app::Model::ShowModelInfoHandler() info("Model info:\n"); this->LogInterpreterInfo(); -#if defined(ARM_NPU) - info("Use of Arm uNPU is enabled\n"); -#else /* ARM_NPU */ - info("Use of Arm uNPU is disabled\n"); -#endif /* ARM_NPU */ + info("The model is optimised for Ethos-U NPU: %s.\n", this->ContainsEthosUOperator()? "yes": "no"); return true; } diff --git a/source/application/tensorflow-lite-micro/TensorFlowLiteMicro.cc b/source/application/tensorflow-lite-micro/TensorFlowLiteMicro.cc index 0b08513..e82e9b5 100644 --- a/source/application/tensorflow-lite-micro/TensorFlowLiteMicro.cc +++ b/source/application/tensorflow-lite-micro/TensorFlowLiteMicro.cc @@ -16,8 +16,6 @@ */ #include "TensorFlowLiteMicro.hpp" -#include "hal.h" - void PrintTensorFlowVersion() {} diff --git a/source/hal/CMakeLists.txt b/source/hal/CMakeLists.txt new file mode 100644 index 0000000..ea19de5 --- /dev/null +++ b/source/hal/CMakeLists.txt @@ -0,0 +1,202 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2022 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#---------------------------------------------------------------------------- + +######################################################### +# HAL library # +######################################################### + +cmake_minimum_required(VERSION 3.15.6) + +set(HAL_TARGET hal) + +project(${HAL_TARGET} + DESCRIPTION "HAL library" + LANGUAGES C CXX) + +# Create static library +add_library(${HAL_TARGET} STATIC) + +# Select which profile needs to be used: +if (${CMAKE_CROSSCOMPILING}) + set(PLATFORM_PROFILE bare-metal) +else() + set(PLATFORM_PROFILE native) +endif() + +set(PLATFORM_PROFILE_DIR profiles/${PLATFORM_PROFILE}) + +## Common include directories - public +target_include_directories(${HAL_TARGET} + PUBLIC + include + ${PLATFORM_PROFILE_DIR}/timer/include + ${PLATFORM_PROFILE_DIR}/utils/include) + +## Common sources for all profiles +target_sources(${HAL_TARGET} + PRIVATE + hal.c + ${PLATFORM_PROFILE_DIR}/data_presentation/data_psn.c + ${PLATFORM_PROFILE_DIR}/data_acquisition/data_acq.c + ${PLATFORM_PROFILE_DIR}/timer/platform_timer.c + ${PLATFORM_PROFILE_DIR}/utils/system_init.c) + +if (DEFINED VERIFY_TEST_OUTPUT) + message(STATUS "Test output verification flag is: ${VERIFY_TEST_OUTPUT}") + target_compile_definitions(${HAL_TARGET} PUBLIC + VERIFY_TEST_OUTPUT=${VERIFY_TEST_OUTPUT}) +endif () + +############################ bare-metal profile ############################# +if (PLATFORM_PROFILE STREQUAL bare-metal) + + if (NOT DEFINED PLATFORM_DRIVERS_DIR) + message(FATAL_ERROR "PLATFORM_DRIVERS_DIR need to be defined for this target") + endif() + + ## Additional include directories - public + target_include_directories(${HAL_TARGET} + PUBLIC + ${PLATFORM_PROFILE_DIR}/bsp/include) + + ## Additional include directories - private + target_include_directories(${HAL_TARGET} + PRIVATE + ${PLATFORM_PROFILE_DIR}/data_presentation/lcd/include) + + ## Additional sources - public + target_sources(${HAL_TARGET} + PUBLIC + ${PLATFORM_PROFILE_DIR}/bsp/retarget.c) + + ## Additional sources - private + target_sources(${HAL_TARGET} + PRIVATE + ${PLATFORM_PROFILE_DIR}/data_presentation/lcd/lcd_img.c) + + ## Compile definition: + target_compile_definitions(${HAL_TARGET} + PUBLIC + PLATFORM_HAL=PLATFORM_CORTEX_M_BAREMETAL) + + # Add dependencies for platform_driver first, in case they are needed by it. + add_subdirectory(cmsis_device ${CMAKE_BINARY_DIR}/cmsis_device) + + # Add platform-drivers target + add_subdirectory(${PLATFORM_DRIVERS_DIR} ${CMAKE_BINARY_DIR}/platform_driver) + + # Link time library targets: + target_link_libraries(${HAL_TARGET} + PUBLIC + log + platform-drivers) + + # If Ethos-U is enabled, we need the driver library too + if (ETHOS_U_NPU_ENABLED) + + if (NOT DEFINED ETHOS_U_NPU_DRIVER_SRC_PATH) + message(FATAL_ERROR "ETHOS_U_NPU_DRIVER_SRC_PATH should" + " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}") + endif() + + # Timing adapter, should, in theory be part of platform-drivers. For now + # limiting the scope of refactoring - but in future, TA should not be + # needed if not available on the target platform. + if (NOT DEFINED ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH) + message(FATAL_ERROR "ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH should" + " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}") + endif() + + target_compile_definitions(${HAL_TARGET} + PUBLIC + ARM_NPU) + + # For the driver, we need to provide the CMSIS_PATH variable + set(CMSIS_PATH ${CMSIS_SRC_PATH} CACHE PATH "Path to CMSIS directory") + add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver) + add_subdirectory(${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH} ${CMAKE_BINARY_DIR}/timing-adapter) + + target_link_libraries(${HAL_TARGET} + PUBLIC + ethosu_core_driver + timing_adapter) + + if (NOT DEFINED ETHOS_U_NPU_ID) + set(ETHOS_U_NPU_ID U55) + endif() + + if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE) + set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram) + endif() + + if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only) + if (ETHOS_U_NPU_ID STREQUAL U55) + set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY") + else () + message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `sram_only` can be used only for Ethos-U55.") + endif () + + elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram) + # Shared Sram can be used for Ethos-U55 and Ethos-U65 + set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM") + + elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram) + # Dedicated Sram is used only for Ethos-U65 + if (ETHOS_U_NPU_ID STREQUAL U65) + set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM") + else () + message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `dedicated_sram` can be used only for Ethos-U65.") + endif () + else () + message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}") + endif () + + target_compile_definitions(${HAL_TARGET} + PUBLIC + ${ETHOS_U_NPU_MEMORY_MODE_FLAG}) + endif() + +############################ native profile ############################# +elseif (PLATFORM_PROFILE STREQUAL native) + ## Additional include directories - private + target_include_directories(${HAL_TARGET} + PRIVATE + ${PLATFORM_PROFILE_DIR}/data_presentation/log/include) + + ## Additional sources - private + target_sources(${HAL_TARGET} + PRIVATE + ${PLATFORM_PROFILE_DIR}/data_presentation/log/log.c) + + ## Compile definition: + target_compile_definitions(${HAL_TARGET} + PUBLIC + PLATFORM_HAL=PLATFORM_UNKNOWN_LINUX_OS + ACTIVATION_BUF_SRAM_SZ=0) + + target_link_libraries(${HAL_TARGET} + PUBLIC + log) + +endif() + +# Display status: +message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) +message(STATUS "*******************************************************") +message(STATUS "Library : " ${HAL_TARGET}) +message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) +message(STATUS "*******************************************************") diff --git a/source/hal/cmsis_device/CMakeLists.txt b/source/hal/cmsis_device/CMakeLists.txt new file mode 100644 index 0000000..9f834d5 --- /dev/null +++ b/source/hal/cmsis_device/CMakeLists.txt @@ -0,0 +1,67 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2022 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#---------------------------------------------------------------------------- + +######################################################### +# Generic CMSIS Start up library for Cortex-M targets # +######################################################### +cmake_minimum_required(VERSION 3.15.6) + +set(CMSIS_DEVICE_TARGET cmsis_device) + +project(${CMSIS_DEVICE_TARGET} + DESCRIPTION "Generic CMSIS start up file for Cortex-M targets" + LANGUAGES C CXX ASM) + +# 1. We should be cross-compiling (non-native target) +if (NOT ${CMAKE_CROSSCOMPILING}) + message(FATAL_ERROR "No ${CMSIS_DEVICE_TARGET} support for this target.") +endif() + +# 2. Check if CMSIS sources have been defined +if (NOT DEFINED CMSIS_SRC_PATH) + message(FATAL_ERROR "CMSIS_SRC_PATH path should be defined for ${CMSIS_DEVICE_TARGET}.") +endif() + +# 3. Create static library +add_library(${CMSIS_DEVICE_TARGET} STATIC) + +## Include directories - public +target_include_directories(${CMSIS_DEVICE_TARGET} + PUBLIC + include + ${CMSIS_SRC_PATH}/CMSIS/Core/Include + ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Include + ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Include/Template) + +## Sources +target_sources(${CMSIS_DEVICE_TARGET} + PRIVATE + source/cmsis.c + source/irqs.c) + +# Tell linker that reset interrupt handler is our entry point +target_link_options( + ${CMSIS_DEVICE_TARGET} + INTERFACE + --entry Reset_Handler) + +# 4 Display status: +message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) +message(STATUS "*******************************************************") +message(STATUS "Library : " ${CMSIS_DEVICE_TARGET}) +message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) +message(STATUS "*******************************************************") diff --git a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/include/cmsis.h b/source/hal/cmsis_device/include/cmsis.h index 9d6326a..9d6326a 100644 --- a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/include/cmsis.h +++ b/source/hal/cmsis_device/include/cmsis.h diff --git a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/include/irqs.h b/source/hal/cmsis_device/include/irqs.h index 0d8dec6..5ddda97 100644 --- a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/include/irqs.h +++ b/source/hal/cmsis_device/include/irqs.h @@ -21,8 +21,6 @@ extern "C" { #endif -#include "peripheral_irqs.h" - #include <stdint.h> /* Interrupt handler function type. */ diff --git a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/cmsis.c b/source/hal/cmsis_device/source/cmsis.c index 9cf6213..9cf6213 100644 --- a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/cmsis.c +++ b/source/hal/cmsis_device/source/cmsis.c diff --git a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/irqs.c b/source/hal/cmsis_device/source/irqs.c index 7d8aa06..7d8aa06 100644 --- a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/irqs.c +++ b/source/hal/cmsis_device/source/irqs.c diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/glcd_mps3.c b/source/hal/components/lcd_mps3/glcd_mps3.c index 530be4f..08d4c5e 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/glcd_mps3.c +++ b/source/hal/components/lcd_mps3/glcd_mps3.c @@ -16,7 +16,7 @@ */ #include "glcd_mps3.h" -#include "bsp_core_log.h" +#include "log_macros.h" #include "font_9x15_h.h" #include "smm_mps3.h" diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/include/font_9x15_h.h b/source/hal/components/lcd_mps3/include/font_9x15_h.h index b8b6bdc..b8b6bdc 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/include/font_9x15_h.h +++ b/source/hal/components/lcd_mps3/include/font_9x15_h.h diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/include/glcd_mps3.h b/source/hal/components/lcd_mps3/include/glcd_mps3.h index c2810c0..c2810c0 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/include/glcd_mps3.h +++ b/source/hal/components/lcd_mps3/include/glcd_mps3.h diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-core/include/uart_stdout.h b/source/hal/components/uart_cmsdk/include/uart_stdout.h index 9c5fbcf..9c5fbcf 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-core/include/uart_stdout.h +++ b/source/hal/components/uart_cmsdk/include/uart_stdout.h diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/uart_stdout.c b/source/hal/components/uart_cmsdk/uart_cmsdk.c index 35d4160..35d4160 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/uart_stdout.c +++ b/source/hal/components/uart_cmsdk/uart_cmsdk.c diff --git a/source/hal/components/uart_pl011/include/uart_stdout.h b/source/hal/components/uart_pl011/include/uart_stdout.h new file mode 100644 index 0000000..9c5fbcf --- /dev/null +++ b/source/hal/components/uart_pl011/include/uart_stdout.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef UART_STDOUT_H +#define UART_STDOUT_H + +#include <stdbool.h> + +/** + * @brief Initialised the UART block. + **/ +extern void UartStdOutInit(void); + +/** + * @brief Transmits a character over UART (blocking call). + * @param[in] my_ch Character to be transmitted. + * @return Character transmitted. + **/ +extern unsigned char UartPutc(unsigned char my_ch); + +/** + * @brief Receives a character from the UART block (blocking call). + * @return Character received. + **/ +extern unsigned char UartGetc(void); + +/** + * @brief Reads characters from the UART block until a line feed or + * carriage return terminates the function. NULL character + * also terminates the function, error is returned. + * @param[out] lp Characters read from the UART block. + * @param[in] len Character to be transmitted. + * @return true if successful, false otherwise. + **/ +extern bool GetLine(char *lp, unsigned int len); + +/** + * @brief Terminates UART simulation. This is useful when a Fixed + * Virtual Platform's session needs to be gracefully terminated. + * @param[in] code Terminating code displayed on the UART before the end of the simulation. + **/ +extern void UartEndSimulation(int code); + +#endif /* UART_STDOUT_H */ diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/simple_platform/uart_pl011.c b/source/hal/components/uart_pl011/uart_pl011.c index 1cbf70c..1cbf70c 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/simple_platform/uart_pl011.c +++ b/source/hal/components/uart_pl011/uart_pl011.c diff --git a/source/application/hal/hal.c b/source/hal/hal.c index c067ba2..ff470d5 100644 --- a/source/application/hal/hal.c +++ b/source/hal/hal.c @@ -18,6 +18,7 @@ #include "hal_config.h" /* HAL configuration */ #include "system_init.h" +#include "log_macros.h" #include <stdio.h> #include <assert.h> @@ -27,7 +28,10 @@ #include "ethosu_mem_config.h" /* Arm Ethos-U memory config */ #include "ethosu_driver.h" /* Arm Ethos-U driver header */ #include "timing_adapter.h" /* Arm Ethos-U timing adapter driver header */ + +#if defined(TIMING_ADAPTER_AVAILABLE) #include "timing_adapter_settings.h" /* Arm Ethos-U timing adapter settings */ +#endif /* defined(TIMING_ADAPTER_AVAILABLE) */ struct ethosu_driver ethosu_drv; /* Default Ethos-U device driver */ @@ -177,64 +181,66 @@ static void arm_npu_irq_init(void) ethosu_irqnum, arm_npu_irq_handler); } -static int _arm_npu_timing_adapter_init(void) -{ -#if defined (TA0_BASE) - struct timing_adapter ta_0; - struct timing_adapter_settings ta_0_settings = { - .maxr = TA0_MAXR, - .maxw = TA0_MAXW, - .maxrw = TA0_MAXRW, - .rlatency = TA0_RLATENCY, - .wlatency = TA0_WLATENCY, - .pulse_on = TA0_PULSE_ON, - .pulse_off = TA0_PULSE_OFF, - .bwcap = TA0_BWCAP, - .perfctrl = TA0_PERFCTRL, - .perfcnt = TA0_PERFCNT, - .mode = TA0_MODE, - .maxpending = 0, /* This is a read-only parameter */ - .histbin = TA0_HISTBIN, - .histcnt = TA0_HISTCNT - }; - - if (0 != ta_init(&ta_0, TA0_BASE)) { - printf_err("TA0 initialisation failed\n"); - return 1; - } +#if defined(TIMING_ADAPTER_AVAILABLE) + static int _arm_npu_timing_adapter_init(void) + { + #if defined (TA0_BASE) + struct timing_adapter ta_0; + struct timing_adapter_settings ta_0_settings = { + .maxr = TA0_MAXR, + .maxw = TA0_MAXW, + .maxrw = TA0_MAXRW, + .rlatency = TA0_RLATENCY, + .wlatency = TA0_WLATENCY, + .pulse_on = TA0_PULSE_ON, + .pulse_off = TA0_PULSE_OFF, + .bwcap = TA0_BWCAP, + .perfctrl = TA0_PERFCTRL, + .perfcnt = TA0_PERFCNT, + .mode = TA0_MODE, + .maxpending = 0, /* This is a read-only parameter */ + .histbin = TA0_HISTBIN, + .histcnt = TA0_HISTCNT + }; + + if (0 != ta_init(&ta_0, TA0_BASE)) { + printf_err("TA0 initialisation failed\n"); + return 1; + } - ta_set_all(&ta_0, &ta_0_settings); -#endif /* defined (TA0_BASE) */ - -#if defined (TA1_BASE) - struct timing_adapter ta_1; - struct timing_adapter_settings ta_1_settings = { - .maxr = TA1_MAXR, - .maxw = TA1_MAXW, - .maxrw = TA1_MAXRW, - .rlatency = TA1_RLATENCY, - .wlatency = TA1_WLATENCY, - .pulse_on = TA1_PULSE_ON, - .pulse_off = TA1_PULSE_OFF, - .bwcap = TA1_BWCAP, - .perfctrl = TA1_PERFCTRL, - .perfcnt = TA1_PERFCNT, - .mode = TA1_MODE, - .maxpending = 0, /* This is a read-only parameter */ - .histbin = TA1_HISTBIN, - .histcnt = TA1_HISTCNT - }; - - if (0 != ta_init(&ta_1, TA1_BASE)) { - printf_err("TA1 initialisation failed\n"); - return 1; - } + ta_set_all(&ta_0, &ta_0_settings); + #endif /* defined (TA0_BASE) */ + + #if defined (TA1_BASE) + struct timing_adapter ta_1; + struct timing_adapter_settings ta_1_settings = { + .maxr = TA1_MAXR, + .maxw = TA1_MAXW, + .maxrw = TA1_MAXRW, + .rlatency = TA1_RLATENCY, + .wlatency = TA1_WLATENCY, + .pulse_on = TA1_PULSE_ON, + .pulse_off = TA1_PULSE_OFF, + .bwcap = TA1_BWCAP, + .perfctrl = TA1_PERFCTRL, + .perfcnt = TA1_PERFCNT, + .mode = TA1_MODE, + .maxpending = 0, /* This is a read-only parameter */ + .histbin = TA1_HISTBIN, + .histcnt = TA1_HISTCNT + }; + + if (0 != ta_init(&ta_1, TA1_BASE)) { + printf_err("TA1 initialisation failed\n"); + return 1; + } - ta_set_all(&ta_1, &ta_1_settings); -#endif /* defined (TA1_BASE) */ + ta_set_all(&ta_1, &ta_1_settings); + #endif /* defined (TA1_BASE) */ - return 0; -} + return 0; + } +#endif /* defined(TIMING_ADAPTER_AVAILABLE) */ static int arm_npu_init(void) { @@ -242,9 +248,11 @@ static int arm_npu_init(void) /* If the platform has timing adapter blocks along with Ethos-U core * block, initialise them here. */ +#if defined(TIMING_ADAPTER_AVAILABLE) if (0 != (err = _arm_npu_timing_adapter_init())) { return err; } +#endif /* defined(TIMING_ADAPTER_AVAILABLE) */ /* Initialise the IRQ */ arm_npu_irq_init(); @@ -268,16 +276,16 @@ static int arm_npu_init(void) /* Get Ethos-U version */ struct ethosu_driver_version driver_version; struct ethosu_hw_info hw_info; - + ethosu_get_driver_version(&driver_version); ethosu_get_hw_info(ðosu_drv, &hw_info); info("Ethos-U version info:\n"); - info("\tArch: v%"PRIu32".%"PRIu32".%"PRIu32"\n", + info("\tArch: v%"PRIu32".%"PRIu32".%"PRIu32"\n", hw_info.version.arch_major_rev, hw_info.version.arch_minor_rev, hw_info.version.arch_patch_rev); - info("\tDriver: v%"PRIu8".%"PRIu8".%"PRIu8"\n", + info("\tDriver: v%"PRIu8".%"PRIu8".%"PRIu8"\n", driver_version.major, driver_version.minor, driver_version.patch); diff --git a/source/application/hal/include/data_acq.h b/source/hal/include/data_acq.h index 965fbe5..965fbe5 100644 --- a/source/application/hal/include/data_acq.h +++ b/source/hal/include/data_acq.h diff --git a/source/application/hal/include/data_psn.h b/source/hal/include/data_psn.h index 8c14c77..8c14c77 100644 --- a/source/application/hal/include/data_psn.h +++ b/source/hal/include/data_psn.h diff --git a/source/application/hal/include/hal.h b/source/hal/include/hal.h index a192ea7..a192ea7 100644 --- a/source/application/hal/include/hal.h +++ b/source/hal/include/hal.h diff --git a/source/application/hal/include/hal_config.h b/source/hal/include/hal_config.h index 55db973..ca32f4e 100644 --- a/source/application/hal/include/hal_config.h +++ b/source/hal/include/hal_config.h @@ -30,11 +30,7 @@ #if ((PLATFORM_HAL) == PLATFORM_CORTEX_M_BAREMETAL) #include "bsp.h" -#elif ((PLATFORM_HAL) == PLATFORM_UNKNOWN_LINUX_OS) - #include "dummy_log.h" -#else - #error "Invalid platform!" -#endif /* PLATFORM_HAL==PLATFORM_CORTEX_M_BAREMETAL */ +#endif #if !defined (DESIGN_NAME) #define DESIGN_NAME ("N/A") diff --git a/source/application/hal/include/timer.h b/source/hal/include/timer.h index 426a42f..56aad5b 100644 --- a/source/application/hal/include/timer.h +++ b/source/hal/include/timer.h @@ -18,14 +18,7 @@ #define HAL_TIMER_H #include "hal_config.h" - -#if ((PLATFORM_HAL) == PLATFORM_CORTEX_M_BAREMETAL) -#include "baremetal_timer.h" -#elif ((PLATFORM_HAL) == PLATFORM_UNKNOWN_LINUX_OS) -#include "native_timer.h" -#else -#error "Platform does not support a timer API" -#endif /* PLATFORM_HAL */ +#include "platform_timer.h" /** Struct for describing the capabilities available for * the timer provided by HAL */ diff --git a/source/hal/platform/mps3/CMakeLists.txt b/source/hal/platform/mps3/CMakeLists.txt new file mode 100644 index 0000000..ad510ee --- /dev/null +++ b/source/hal/platform/mps3/CMakeLists.txt @@ -0,0 +1,114 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2022 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#---------------------------------------------------------------------------- + +######################################################### +# MPS3 platform support library # +######################################################### + +cmake_minimum_required(VERSION 3.15.6) +set(PLATFORM_DRIVERS_TARGET platform-drivers) +project(${PLATFORM_DRIVERS_TARGET} + DESCRIPTION "Platform drivers library for MPS3 FPGA/FVP targets" + LANGUAGES C CXX ASM) + +# 1. We should be cross-compiling (MPS3 taregt only runs Cortex-M targets) +if (NOT ${CMAKE_CROSSCOMPILING}) + message(FATAL_ERROR "No ${PLATFORM_DRIVERS_TARGET} support for this target.") +endif() + +# 2. Set the platform cmake descriptor file +if (NOT DEFINED PLATFORM_CMAKE_DESCRIPTOR_FILE) + set(PLATFORM_CMAKE_DESCRIPTOR_FILE + cmake/subsystem-profiles/corstone-sse-300.cmake + CACHE PATH + "Platform's CMake descriptor file path") +endif() + +## Include the platform cmake descriptor file +include(${PLATFORM_CMAKE_DESCRIPTOR_FILE}) + +# 3. Generate sources: +if (NOT DEFINED SOURCE_GEN_DIR) + set(SOURCE_GEN_DIR ${CMAKE_BINARY_DIR}/generated/bsp) +endif() + +set(MEM_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/peripheral_memmap.h.template) +set(IRQ_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/peripheral_irqs.h.template) +set(MEM_REGIONS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/mem_regions.h.template) + +configure_file("${MEM_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_memmap.h") +configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h") +configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h") + +# If a TA config file is provided, we generate a settings file +if (DEFINED TA_CONFIG_FILE) + include(${TA_CONFIG_FILE}) + set(TA_SETTINGS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/timing_adapter_settings.template) + configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h") +endif() + +# 4. Create static library +add_library(${PLATFORM_DRIVERS_TARGET} STATIC) + +## Include directories - public +target_include_directories(${PLATFORM_DRIVERS_TARGET} + PUBLIC + include + ${SOURCE_GEN_DIR}) + +## Platform sources +target_sources(${PLATFORM_DRIVERS_TARGET} + PRIVATE + source/device_mps3.c + source/timer_mps3.c) + +## Platform component: uart +target_sources(${PLATFORM_DRIVERS_TARGET} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/../../components/uart_cmsdk/uart_cmsdk.c) +target_include_directories(${PLATFORM_DRIVERS_TARGET} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/../../components/uart_cmsdk/include) + +## Platform component: LCD +target_sources(${PLATFORM_DRIVERS_TARGET} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/../../components/lcd_mps3/glcd_mps3.c) +target_include_directories(${PLATFORM_DRIVERS_TARGET} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/../../components/lcd_mps3/include) + +## This target provides the following definitions for MPS3 specific behaviour +## TODO: We should aim to remove this now with platform refactoring.. +target_compile_definitions(${PLATFORM_DRIVERS_TARGET} + PUBLIC + MPS3_PLATFORM + ACTIVATION_BUF_SRAM_SZ=${ACTIVATION_BUF_SRAM_SZ} + $<$<BOOL:TA_CONFIG_FILE>:TIMING_ADAPTER_AVAILABLE>) + +# 5. Add dependencies: + +target_link_libraries(${PLATFORM_DRIVERS_TARGET} PUBLIC + cmsis_device + log) + +# 6 Display status: +message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) +message(STATUS "*******************************************************") +message(STATUS "Library : " ${PLATFORM_DRIVERS_TARGET}) +message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) +message(STATUS "*******************************************************") diff --git a/scripts/cmake/subsystem-profiles/corstone-sse-300.cmake b/source/hal/platform/mps3/cmake/subsystem-profiles/corstone-sse-300.cmake index eec6fde..eec6fde 100644 --- a/scripts/cmake/subsystem-profiles/corstone-sse-300.cmake +++ b/source/hal/platform/mps3/cmake/subsystem-profiles/corstone-sse-300.cmake diff --git a/scripts/cmake/templates/mem_regions.h.template b/source/hal/platform/mps3/cmake/templates/mem_regions.h.template index 72978ce..72978ce 100644 --- a/scripts/cmake/templates/mem_regions.h.template +++ b/source/hal/platform/mps3/cmake/templates/mem_regions.h.template diff --git a/scripts/cmake/templates/peripheral_irqs.h.template b/source/hal/platform/mps3/cmake/templates/peripheral_irqs.h.template index 7696e13..7696e13 100644 --- a/scripts/cmake/templates/peripheral_irqs.h.template +++ b/source/hal/platform/mps3/cmake/templates/peripheral_irqs.h.template diff --git a/scripts/cmake/templates/peripheral_memmap.h.template b/source/hal/platform/mps3/cmake/templates/peripheral_memmap.h.template index d7f0b3a..d7f0b3a 100644 --- a/scripts/cmake/templates/peripheral_memmap.h.template +++ b/source/hal/platform/mps3/cmake/templates/peripheral_memmap.h.template diff --git a/scripts/cmake/templates/timing_adapter_settings.template b/source/hal/platform/mps3/cmake/templates/timing_adapter_settings.template index d5e202a..d5e202a 100644 --- a/scripts/cmake/templates/timing_adapter_settings.template +++ b/source/hal/platform/mps3/cmake/templates/timing_adapter_settings.template diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/include/device_mps3.h b/source/hal/platform/mps3/include/device_mps3.h index e0dea1b..e0dea1b 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/include/device_mps3.h +++ b/source/hal/platform/mps3/include/device_mps3.h diff --git a/source/application/hal/platforms/bare-metal/bsp/include/bsp.h b/source/hal/platform/mps3/include/platform_drivers.h index 2bd4fa1..c5ed561 100644 --- a/source/application/hal/platforms/bare-metal/bsp/include/bsp.h +++ b/source/hal/platform/mps3/include/platform_drivers.h @@ -14,29 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef BSP_H -#define BSP_H -/* Core modules - these are common */ -#include "bsp_core_log.h" /* Logging related helpers. */ -#include "uart_stdout.h" /* stdout over UART. */ - -#if defined(MPS3_PLATFORM) /* If running on MPS3 platform. */ +#ifndef PLATFORM_DRIVER_H +#define PLATFORM_DRIVER_H +#include "log_macros.h" /* Logging related helpers. */ +#include "uart_stdout.h" /* stdout over UART. */ #include "smm_mps3.h" /* Mem map for MPS3 peripherals. */ #include "glcd_mps3.h" /* LCD functions. */ #include "timer_mps3.h" /* Timer functions. */ #include "device_mps3.h" /* FPGA level definitions and functions. */ +#include "peripheral_irqs.h"/* IRQ numbers for this platform */ -#else /* MPS3_PLATFORM */ - -#include "stubs_simple_platform.h" /* Stubs for simple_platform. */ -#include "timer_simple_platform.h" /* Timer API for simple_platform. */ - -#endif /* MPS3_PLATFORM */ - -#if defined(ARM_NPU) -#include "ethosu_mem_config.h" -#endif /* defined(ARM_NPU) */ - -#endif /* BSP_H */ +#endif /* PLATFORM_DRIVER_H */ diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/include/smm_mps3.h b/source/hal/platform/mps3/include/smm_mps3.h index 1c0e0f2..1c0e0f2 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/include/smm_mps3.h +++ b/source/hal/platform/mps3/include/smm_mps3.h diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/include/timer_mps3.h b/source/hal/platform/mps3/include/timer_mps3.h index 14d64e5..70d059c 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/include/timer_mps3.h +++ b/source/hal/platform/mps3/include/timer_mps3.h @@ -30,7 +30,7 @@ typedef struct _mps3_time_counter { /* Running at processor core's internal clock rate, triggered by SysTick. */ uint64_t counter_systick; -} mps3_time_counter; +} base_time_counter; /** * @brief Resets the counters. @@ -41,36 +41,36 @@ void timer_reset(void); * @brief Gets the current counter values. * @returns Mps3 timer counter. **/ -mps3_time_counter get_time_counter(void); +base_time_counter get_time_counter(void); /** * @brief Gets the duration elapsed between two counters in milliseconds. - * @param[in] start Pointer to mps3_time_counter value at start time. - * @param[in] end Pointer to mps3_time_counter value at end. + * @param[in] start Pointer to base_time_counter value at start time. + * @param[in] end Pointer to base_time_counter value at end. * @returns Difference in milliseconds between the two give counters * expressed as an unsigned integer. **/ -uint32_t get_duration_milliseconds(mps3_time_counter *start, - mps3_time_counter *end); +uint32_t get_duration_milliseconds(base_time_counter *start, + base_time_counter *end); /** * @brief Gets the duration elapsed between two counters in microseconds. - * @param[in] start Pointer to mps3_time_counter value at start time. - * @param[in] end Pointer to mps3_time_counter value at end. + * @param[in] start Pointer to base_time_counter value at start time. + * @param[in] end Pointer to base_time_counter value at end. * @returns Difference in microseconds between the two give counters * expressed as an unsigned integer. **/ -uint32_t get_duration_microseconds(mps3_time_counter *start, - mps3_time_counter *end); +uint32_t get_duration_microseconds(base_time_counter *start, + base_time_counter *end); /** * @brief Gets the cycle counts elapsed between start and end. - * @param[in] start Pointer to mps3_time_counter value at start time. - * @param[in] end Pointer to mps3_time_counter value at end. + * @param[in] start Pointer to base_time_counter value at start time. + * @param[in] end Pointer to base_time_counter value at end. * @return Difference in counter values as 32 bit unsigned integer. **/ -uint64_t get_cycle_count_diff(mps3_time_counter *start, - mps3_time_counter *end); +uint64_t get_cycle_count_diff(base_time_counter *start, + base_time_counter *end); /** * @brief Enables or triggers cycle counting mechanism, if required diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/device_mps3.c b/source/hal/platform/mps3/source/device_mps3.c index 9a923c7..fa57c2e 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/device_mps3.c +++ b/source/hal/platform/mps3/source/device_mps3.c @@ -16,7 +16,7 @@ */ #include "device_mps3.h" -#include "bsp_core_log.h" +#include "log_macros.h" #include "smm_mps3.h" #include <inttypes.h> diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/timer_mps3.c b/source/hal/platform/mps3/source/timer_mps3.c index c0c3bdf..9b8914c 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/timer_mps3.c +++ b/source/hal/platform/mps3/source/timer_mps3.c @@ -16,7 +16,7 @@ */ #include "timer_mps3.h" -#include "bsp_core_log.h" +#include "log_macros.h" #include "device_mps3.h" #include <inttypes.h> @@ -33,9 +33,9 @@ void timer_reset(void) debug("system tick config ready\n"); } -mps3_time_counter get_time_counter(void) +base_time_counter get_time_counter(void) { - mps3_time_counter t = { + base_time_counter t = { .counter_1Hz = MPS3_FPGAIO->CLK1HZ, .counter_100Hz = MPS3_FPGAIO->CLK100HZ, .counter_fpga = MPS3_FPGAIO->COUNTER, @@ -54,8 +54,8 @@ mps3_time_counter get_time_counter(void) * the time elapsed has been big (in days) this could happen and is currently * not handled. **/ -uint32_t get_duration_milliseconds(mps3_time_counter *start, - mps3_time_counter *end) +uint32_t get_duration_milliseconds(base_time_counter *start, + base_time_counter *end) { uint32_t time_elapsed = 0; if (end->counter_100Hz > start->counter_100Hz) { @@ -79,8 +79,8 @@ uint32_t get_duration_milliseconds(mps3_time_counter *start, * Like the microsecond counterpart, this function could return wrong results when * the counter (MAINCLK) overflows. There are no overflow counters available. **/ -uint32_t get_duration_microseconds(mps3_time_counter *start, - mps3_time_counter *end) +uint32_t get_duration_microseconds(base_time_counter *start, + base_time_counter *end) { const int divisor = GetMPS3CoreClock()/1000000; uint32_t time_elapsed = 0; @@ -93,8 +93,8 @@ uint32_t get_duration_microseconds(mps3_time_counter *start, return time_elapsed; } -uint64_t get_cycle_count_diff(mps3_time_counter *start, - mps3_time_counter *end) +uint64_t get_cycle_count_diff(base_time_counter *start, + base_time_counter *end) { if (start->counter_systick > end->counter_systick) { warn("start > end; counter might have overflown\n"); diff --git a/source/hal/platform/simple/CMakeLists.txt b/source/hal/platform/simple/CMakeLists.txt new file mode 100644 index 0000000..cd3a2bc --- /dev/null +++ b/source/hal/platform/simple/CMakeLists.txt @@ -0,0 +1,100 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2022 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#---------------------------------------------------------------------------- + +######################################################### +# A generic (simple) platform support library # +######################################################### + +cmake_minimum_required(VERSION 3.15.6) +set(PLATFORM_DRIVERS_TARGET platform-drivers) +project(${PLATFORM_DRIVERS_TARGET} + DESCRIPTION "Platform drivers library for a generic target" + LANGUAGES C CXX ASM) + +# 1. We should be cross-compiling (MPS3 taregt only runs Cortex-M targets) +if (NOT ${CMAKE_CROSSCOMPILING}) + message(FATAL_ERROR "No ${PLATFORM_DRIVERS_TARGET} support for this target.") +endif() + +# 2. Set the platform cmake descriptor file +if (NOT DEFINED PLATFORM_CMAKE_DESCRIPTOR_FILE) + set(PLATFORM_CMAKE_DESCRIPTOR_FILE + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/subsystem-profiles/simple_platform.cmake) +endif() + +## Include the platform cmake descriptor file +include(${PLATFORM_CMAKE_DESCRIPTOR_FILE}) + +# 3. Generate sources: +if (NOT DEFINED SOURCE_GEN_DIR) + set(SOURCE_GEN_DIR ${CMAKE_BINARY_DIR}/generated/bsp) +endif() + +set(MEM_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/peripheral_memmap.h.template) +set(IRQ_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/peripheral_irqs.h.template) +set(MEM_REGIONS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/mem_regions.h.template) + +configure_file("${MEM_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_memmap.h") +configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h") +configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h") + +# If a TA config file is provided, we generate a settings file +if (DEFINED TA_CONFIG_FILE) + include(${TA_CONFIG_FILE}) + set(TA_SETTINGS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/timing_adapter_settings.template) + configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h") +endif() + +# 4. Create static library +add_library(${PLATFORM_DRIVERS_TARGET} STATIC) + +## Include directories - public +target_include_directories(${PLATFORM_DRIVERS_TARGET} + PUBLIC + include + ${SOURCE_GEN_DIR}) + +## Platform sources +target_sources(${PLATFORM_DRIVERS_TARGET} + PRIVATE + source/stubs_glcd.c + source/timer_simple_platform.c) + +## Platform component: uart +target_sources(${PLATFORM_DRIVERS_TARGET} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/../../components/uart_pl011/uart_pl011.c) +target_include_directories(${PLATFORM_DRIVERS_TARGET} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/../../components/uart_pl011/include) + +## Compile defs +target_compile_definitions(${PLATFORM_DRIVERS_TARGET} + PUBLIC + ACTIVATION_BUF_SRAM_SZ=${ACTIVATION_BUF_SRAM_SZ} + $<$<BOOL:TA_CONFIG_FILE>:TIMING_ADAPTER_AVAILABLE>) + +target_link_libraries(${PLATFORM_DRIVERS_TARGET} PUBLIC + cmsis_device + log) + +# 6 Display status: +message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) +message(STATUS "*******************************************************") +message(STATUS "Library : " ${PLATFORM_DRIVERS_TARGET}) +message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) +message(STATUS "*******************************************************") diff --git a/scripts/cmake/subsystem-profiles/simple_platform.cmake b/source/hal/platform/simple/cmake/subsystem-profiles/simple_platform.cmake index e6cfef3..e6cfef3 100644 --- a/scripts/cmake/subsystem-profiles/simple_platform.cmake +++ b/source/hal/platform/simple/cmake/subsystem-profiles/simple_platform.cmake diff --git a/source/hal/platform/simple/cmake/templates/mem_regions.h.template b/source/hal/platform/simple/cmake/templates/mem_regions.h.template new file mode 100644 index 0000000..72978ce --- /dev/null +++ b/source/hal/platform/simple/cmake/templates/mem_regions.h.template @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Auto-generated file +// ** DO NOT EDIT ** + +#ifndef MEM_REGION_DEFS_H +#define MEM_REGION_DEFS_H + +#cmakedefine ITCM_SIZE (@ITCM_SIZE@) /* ITCM size */ +#cmakedefine DTCM_BLK_SIZE (@DTCM_BLK_SIZE@) /* DTCM size, 4 banks of this size available */ +#cmakedefine BRAM_SIZE (@BRAM_SIZE@) /* BRAM size */ +#cmakedefine ISRAM0_SIZE (@ISRAM0_SIZE@) /* ISRAM0 size */ +#cmakedefine ISRAM1_SIZE (@ISRAM1_SIZE@) /* ISRAM1 size */ +#cmakedefine QSPI_SRAM_SIZE (@QSPI_SRAM_SIZE@) /* QSPI Flash size */ +#cmakedefine DDR4_BLK_SIZE (@DDR4_BLK_SIZE@) /* DDR4 block size */ + +#cmakedefine ITCM_BASE_NS (@ITCM_BASE_NS@) /* Instruction TCM Non-Secure base address */ +#cmakedefine BRAM_BASE_NS (@BRAM_BASE_NS@) /* CODE SRAM Non-Secure base address */ +#cmakedefine DTCM0_BASE_NS (@DTCM0_BASE_NS@) /* Data TCM block 0 Non-Secure base address */ +#cmakedefine DTCM1_BASE_NS (@DTCM1_BASE_NS@) /* Data TCM block 1 Non-Secure base address */ +#cmakedefine DTCM2_BASE_NS (@DTCM2_BASE_NS@) /* Data TCM block 2 Non-Secure base address */ +#cmakedefine DTCM3_BASE_NS (@DTCM3_BASE_NS@) /* Data TCM block 3 Non-Secure base address */ +#cmakedefine ISRAM0_BASE_NS (@ISRAM0_BASE_NS@) /* Internal SRAM Area Non-Secure base address */ +#cmakedefine ISRAM1_BASE_NS (@ISRAM1_BASE_NS@) /* Internal SRAM Area Non-Secure base address */ +#cmakedefine QSPI_SRAM_BASE_NS (@QSPI_SRAM_BASE_NS@) /* QSPI SRAM Non-Secure base address */ +#cmakedefine DDR4_BLK0_BASE_NS (@DDR4_BLK0_BASE_NS@) /* DDR4 block 0 Non-Secure base address */ +#cmakedefine DDR4_BLK1_BASE_NS (@DDR4_BLK1_BASE_NS@) /* DDR4 block 1 Non-Secure base address */ +#cmakedefine DDR4_BLK2_BASE_NS (@DDR4_BLK2_BASE_NS@) /* DDR4 block 2 Non-Secure base address */ +#cmakedefine DDR4_BLK3_BASE_NS (@DDR4_BLK3_BASE_NS@) /* DDR4 block 3 Non-Secure base address */ + +#cmakedefine ITCM_BASE_S (@ITCM_BASE_S@) /* Instruction TCM Secure base address */ +#cmakedefine BRAM_BASE_S (@BRAM_BASE_S@) /* CODE SRAM Secure base address */ +#cmakedefine DTCM0_BASE_S (@DTCM0_BASE_S@) /* Data TCM block 0 Secure base address */ +#cmakedefine DTCM1_BASE_S (@DTCM1_BASE_S@) /* Data TCM block 1 Secure base address */ +#cmakedefine DTCM2_BASE_S (@DTCM2_BASE_S@) /* Data TCM block 2 Secure base address */ +#cmakedefine DTCM3_BASE_S (@DTCM3_BASE_S@) /* Data TCM block 3 Secure base address */ +#cmakedefine ISRAM0_BASE_S (@ISRAM0_BASE_S@) /* Internal SRAM Area Secure base address */ +#cmakedefine ISRAM1_BASE_S (@ISRAM1_BASE_S@) /* Internal SRAM Area Secure base address */ +#cmakedefine DDR4_BLK0_BASE_S (@DDR4_BLK0_BASE_S@) /* DDR4 block 0 Secure base address */ +#cmakedefine DDR4_BLK1_BASE_S (@DDR4_BLK1_BASE_S@) /* DDR4 block 1 Secure base address */ +#cmakedefine DDR4_BLK2_BASE_S (@DDR4_BLK2_BASE_S@) /* DDR4 block 2 Secure base address */ +#cmakedefine DDR4_BLK3_BASE_S (@DDR4_BLK3_BASE_S@) /* DDR4 block 3 Secure base address */ + +#endif /* MEM_REGION_DEFS_H */ diff --git a/source/hal/platform/simple/cmake/templates/peripheral_irqs.h.template b/source/hal/platform/simple/cmake/templates/peripheral_irqs.h.template new file mode 100644 index 0000000..8126cb4 --- /dev/null +++ b/source/hal/platform/simple/cmake/templates/peripheral_irqs.h.template @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Auto-generated file +// ** DO NOT EDIT ** + +#ifndef PERIPHERAL_IRQS_H +#define PERIPHERAL_IRQS_H + +/******************************************************************************/ +/* Peripheral interrupt numbers */ +/******************************************************************************/ + +#cmakedefine EthosU_IRQn (@EthosU_IRQn@) /* Ethos-Uxx Interrupt */ + +#endif /* PERIPHERAL_IRQS_H */ diff --git a/source/hal/platform/simple/cmake/templates/peripheral_memmap.h.template b/source/hal/platform/simple/cmake/templates/peripheral_memmap.h.template new file mode 100644 index 0000000..2bfaafc --- /dev/null +++ b/source/hal/platform/simple/cmake/templates/peripheral_memmap.h.template @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Auto-generated file +// ** DO NOT EDIT ** + +#ifndef PERIPHERAL_MEMMAP_H +#define PERIPHERAL_MEMMAP_H + +#cmakedefine DESIGN_NAME "@DESIGN_NAME@" + +/******************************************************************************/ +/* Peripheral memory map */ +/******************************************************************************/ +#cmakedefine PL011_UART0_BASE (@PL011_UART0_BASE@) /* PL011 UART0 Base Address */ + +#cmakedefine ETHOS_U_NPU_BASE (@ETHOS_U_NPU_BASE@) /* Ethos-U NPU base address*/ +#cmakedefine ETHOS_U_NPU_TA0_BASE (@ETHOS_U_NPU_TA0_BASE@) /* Ethos-U NPU's timing adapter 0 base address */ +#cmakedefine ETHOS_U_NPU_TA1_BASE (@ETHOS_U_NPU_TA1_BASE@) /* Ethos-U NPU's timing adapter 1 base address */ + +/******************************************************************************/ +/* Secure Peripheral memory map */ +/******************************************************************************/ + +#cmakedefine SEC_ETHOS_U_NPU_BASE (@SEC_ETHOS_U_NPU_BASE@) /* Ethos-U NPU base address*/ +#cmakedefine SEC_ETHOS_U_NPU_TA0_BASE (@SEC_ETHOS_U_NPU_TA0_BASE@) /* Ethos-U NPU's timing adapter 0 base address */ +#cmakedefine SEC_ETHOS_U_NPU_TA1_BASE (@SEC_ETHOS_U_NPU_TA1_BASE@) /* Ethos-U NPU's timing adapter 1 base address */ + +#endif /* PERIPHERAL_MEMMAP_H */ diff --git a/source/hal/platform/simple/cmake/templates/timing_adapter_settings.template b/source/hal/platform/simple/cmake/templates/timing_adapter_settings.template new file mode 100644 index 0000000..d5e202a --- /dev/null +++ b/source/hal/platform/simple/cmake/templates/timing_adapter_settings.template @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Auto-generated file +// ** DO NOT EDIT ** + +#ifndef TIMING_ADAPTER_SETTINGS_H +#define TIMING_ADAPTER_SETTINGS_H + +#cmakedefine TA0_BASE (@TA0_BASE@) +#cmakedefine TA1_BASE (@TA1_BASE@) + +/* Timing adapter settings for AXI0 */ +#if defined(TA0_BASE) + +#define TA0_MAXR (@TA0_MAXR@) +#define TA0_MAXW (@TA0_MAXW@) +#define TA0_MAXRW (@TA0_MAXRW@) +#define TA0_RLATENCY (@TA0_RLATENCY@) +#define TA0_WLATENCY (@TA0_WLATENCY@) +#define TA0_PULSE_ON (@TA0_PULSE_ON@) +#define TA0_PULSE_OFF (@TA0_PULSE_OFF@) +#define TA0_BWCAP (@TA0_BWCAP@) +#define TA0_PERFCTRL (@TA0_PERFCTRL@) +#define TA0_PERFCNT (@TA0_PERFCNT@) +#define TA0_MODE (@TA0_MODE@) +#define TA0_HISTBIN (@TA0_HISTBIN@) +#define TA0_HISTCNT (@TA0_HISTCNT@) + +#endif /* defined(TA0_BASE) */ + +/* Timing adapter settings for AXI1 */ +#if defined(TA1_BASE) + +#define TA1_MAXR (@TA1_MAXR@) +#define TA1_MAXW (@TA1_MAXW@) +#define TA1_MAXRW (@TA1_MAXRW@) +#define TA1_RLATENCY (@TA1_RLATENCY@) +#define TA1_WLATENCY (@TA1_WLATENCY@) +#define TA1_PULSE_ON (@TA1_PULSE_ON@) +#define TA1_PULSE_OFF (@TA1_PULSE_OFF@) +#define TA1_BWCAP (@TA1_BWCAP@) +#define TA1_PERFCTRL (@TA1_PERFCTRL@) +#define TA1_PERFCNT (@TA1_PERFCNT@) +#define TA1_MODE (@TA1_MODE@) +#define TA1_HISTBIN (@TA1_HISTBIN@) +#define TA1_HISTCNT (@TA1_HISTCNT@) + +#endif /* defined(TA1_BASE) */ + +#endif /* TIMING_ADAPTER_SETTINGS_H */
\ No newline at end of file diff --git a/source/hal/platform/simple/include/platform_drivers.h b/source/hal/platform/simple/include/platform_drivers.h new file mode 100644 index 0000000..0fb092e --- /dev/null +++ b/source/hal/platform/simple/include/platform_drivers.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PLATFORM_DRIVER_H +#define PLATFORM_DRIVER_H + +#include "log_macros.h" /* Logging related helpers. */ + +/* Platform components */ +#include "uart_stdout.h" /* stdout over UART. */ +#include "stubs/glcd.h" /* LCD stubs to support use cases that use LCD */ +#include "timer_simple_platform.h" /* timer implementation */ + +#include "cmsis.h" /* CPU device specific header file */ +#include "peripheral_memmap.h" /* peripheral memory map definitions */ +#include "peripheral_irqs.h" /* IRQ numbers for the platform */ + +#endif /* PLATFORM_DRIVER_H */ diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/simple_platform/include/stubs_simple_platform.h b/source/hal/platform/simple/include/stubs/glcd.h index 9977cd2..5915f7d 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/simple_platform/include/stubs_simple_platform.h +++ b/source/hal/platform/simple/include/stubs/glcd.h @@ -17,9 +17,6 @@ #ifndef STUBS_SIMPLE_PLATFORM_H #define STUBS_SIMPLE_PLATFORM_H -#include "cmsis.h" /* device specific header file */ -#include "peripheral_memmap.h" /* peripheral memory map definitions */ - /****************************************************************************/ /* Definitions and stub functions for modules currently */ /* unavailable on this target platform */ @@ -29,9 +26,6 @@ #define Black 0x0000 /* 0, 0, 0 */ #define White 0xFFFF /* 255, 255, 255 */ -/*********************** Clock related functions *****************************/ -uint32_t GetCoreClock(void); - /************************ GLCD related functions ****************************/ /** * @brief Initialize the Himax LCD with HX8347-D LCD Controller @@ -64,10 +58,10 @@ void GLCD_Bitmap(unsigned int x, unsigned int y, * @param[in] downsample_factor factor by which the image * is downsampled by. */ -void GLCD_Image(void *data, const uint32_t width, - const uint32_t height, const uint32_t channels, - const uint32_t pos_x, const uint32_t pos_y, - const uint32_t downsample_factor); +void GLCD_Image(void *data, const unsigned int width, + const unsigned int height, const unsigned int channels, + const unsigned int pos_x, const unsigned int pos_y, + const unsigned int downsample_factor); /** * @brief Clear display diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/simple_platform/include/timer_simple_platform.h b/source/hal/platform/simple/include/timer_simple_platform.h index 320a57a..03d8245 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/simple_platform/include/timer_simple_platform.h +++ b/source/hal/platform/simple/include/timer_simple_platform.h @@ -16,13 +16,12 @@ */ #ifndef TIMER_SIMPLE_PLATFORM_H #define TIMER_SIMPLE_PLATFORM_H - -#include "stubs_simple_platform.h" +#include <stdint.h> /* Container for timestamp for simple platform. */ typedef struct _generic_time_counter { uint64_t counter_systick; -} generic_time_counter; +} base_time_counter; /** * @brief Resets the counters. @@ -33,13 +32,13 @@ void timer_reset(void); * @brief Gets the current counter values. * @returns counter struct. **/ -generic_time_counter get_time_counter(void); +base_time_counter get_time_counter(void); /** * @brief Gets the cycle counts elapsed between start and end. * @return difference in counter values as 32 bit unsigned integer. */ -uint64_t get_cycle_count_diff(generic_time_counter *start, generic_time_counter *end); +uint64_t get_cycle_count_diff(base_time_counter *start, base_time_counter *end); /** * @brief Enables or triggers cycle counting mechanism, if required diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/simple_platform/stubs_simple_platform.c b/source/hal/platform/simple/source/stubs_glcd.c index df11adb..6b60dcd 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/simple_platform/stubs_simple_platform.c +++ b/source/hal/platform/simple/source/stubs_glcd.c @@ -14,17 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "stubs_simple_platform.h" - -#include "bsp_core_log.h" +#include "stubs/glcd.h" +#include "log_macros.h" #include <inttypes.h> -uint32_t GetCoreClock(void) -{ - return 1; -} - void GLCD_Initialize(void) {} void GLCD_Bitmap(unsigned int x, unsigned int y, @@ -37,9 +31,9 @@ void GLCD_Bitmap(unsigned int x, unsigned int y, UNUSED(bitmap); } -void GLCD_Image(void *data, const uint32_t width, const uint32_t height, - const uint32_t channels, const uint32_t pos_x, - const uint32_t pos_y, const uint32_t downsample_factor) +void GLCD_Image(void *data, const unsigned int width, const unsigned int height, + const unsigned int channels, const unsigned int pos_x, + const unsigned int pos_y, const unsigned int downsample_factor) { UNUSED(data); UNUSED(pos_x); @@ -93,22 +87,3 @@ void GLCD_Box(unsigned int x, unsigned int y, unsigned int w, unsigned int h, UNUSED(h); UNUSED(color); } - -void LED_Initialize(uint32_t port) -{ - UNUSED(port); -} - -void LED_On(uint32_t num, uint32_t port) -{ - UNUSED(num); - UNUSED(port); - debug("LED %" PRIu32 " ON\n", num); -} - -void LED_Off(uint32_t num, uint32_t port) -{ - UNUSED(num); - UNUSED(port); - debug("LED %" PRIu32 " OFF\n", num); -} diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/simple_platform/timer_simple_platform.c b/source/hal/platform/simple/source/timer_simple_platform.c index 6914209..4bcd07b 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/simple_platform/timer_simple_platform.c +++ b/source/hal/platform/simple/source/timer_simple_platform.c @@ -17,13 +17,13 @@ #include "timer_simple_platform.h" #include "irqs.h" -#include "bsp_core_log.h" +#include "log_macros.h" #include <inttypes.h> -generic_time_counter get_time_counter(void) +base_time_counter get_time_counter(void) { - generic_time_counter t = { + base_time_counter t = { .counter_systick = Get_SysTick_Cycle_Count() }; debug("counter_systick: %" PRIu64 "\n", t.counter_systick); @@ -38,8 +38,8 @@ void timer_reset(void) debug("system tick config ready\n"); } -uint64_t get_cycle_count_diff(generic_time_counter *start, - generic_time_counter *end) +uint64_t get_cycle_count_diff(base_time_counter *start, + base_time_counter *end) { if (start->counter_systick > end->counter_systick) { warn("start > end; counter might have overflown\n"); diff --git a/source/hal/profiles/bare-metal/bsp/include/bsp.h b/source/hal/profiles/bare-metal/bsp/include/bsp.h new file mode 100644 index 0000000..e6dd0b5 --- /dev/null +++ b/source/hal/profiles/bare-metal/bsp/include/bsp.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef BSP_H +#define BSP_H + +#include "platform_drivers.h" + +#if defined(ARM_NPU) +#include "ethosu_mem_config.h" +#endif /* defined(ARM_NPU) */ + +#endif /* BSP_H */ diff --git a/source/application/hal/platforms/bare-metal/bsp/include/ethosu_mem_config.h b/source/hal/profiles/bare-metal/bsp/include/ethosu_mem_config.h index b393a03..b393a03 100644 --- a/source/application/hal/platforms/bare-metal/bsp/include/ethosu_mem_config.h +++ b/source/hal/profiles/bare-metal/bsp/include/ethosu_mem_config.h diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-core/retarget.c b/source/hal/profiles/bare-metal/bsp/retarget.c index 29c2023..dfef62c 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-core/retarget.c +++ b/source/hal/profiles/bare-metal/bsp/retarget.c @@ -16,7 +16,6 @@ */ #include "uart_stdout.h" -#include "bsp_core_log.h" #include <stdio.h> #include <string.h> @@ -70,7 +69,7 @@ void _ttywrch(int ch) { FILEHANDLE RETARGET(_open)(const char *name, int openmode) { - UNUSED(openmode); + (void)(openmode); if (strcmp(name, __stdin_name) == 0) { return (STDIN); @@ -89,7 +88,7 @@ FILEHANDLE RETARGET(_open)(const char *name, int openmode) int RETARGET(_write)(FILEHANDLE fh, const unsigned char *buf, unsigned int len, int mode) { - UNUSED(mode); + (void)(mode); switch (fh) { case STDOUT: @@ -112,7 +111,7 @@ int RETARGET(_write)(FILEHANDLE fh, const unsigned char *buf, unsigned int len, int RETARGET(_read)(FILEHANDLE fh, unsigned char *buf, unsigned int len, int mode) { - UNUSED(mode); + (void)(mode); switch (fh) { case STDIN: { @@ -157,15 +156,15 @@ int RETARGET(_close)(FILEHANDLE fh) int RETARGET(_seek)(FILEHANDLE fh, long pos) { - UNUSED(fh); - UNUSED(pos); + (void)(fh); + (void)(pos); return -1; } int RETARGET(_ensure)(FILEHANDLE fh) { - UNUSED(fh); + (void)(fh); return -1; } @@ -181,16 +180,16 @@ long RETARGET(_flen)(FILEHANDLE fh) int RETARGET(_tmpnam)(char *name, int sig, unsigned int maxlen) { - UNUSED(name); - UNUSED(sig); - UNUSED(maxlen); + (void)(name); + (void)(sig); + (void)(maxlen); return 1; } char *RETARGET(_command_string)(char *cmd, int len) { - UNUSED(len); + (void)(len); return cmd; } @@ -198,11 +197,12 @@ char *RETARGET(_command_string)(char *cmd, int len) void RETARGET(_exit)(int return_code) { UartEndSimulation(return_code); + while(1); } int system(const char *cmd) { - UNUSED(cmd); + (void)(cmd); return 0; } @@ -228,29 +228,29 @@ clock_t clock(void) } int remove(const char *arg) { - UNUSED(arg); + (void)(arg); return 0; } int rename(const char *oldn, const char *newn) { - UNUSED(oldn); - UNUSED(newn); + (void)(oldn); + (void)(newn); return 0; } int fputc(int ch, FILE *f) { - UNUSED(f); + (void)(f); return UartPutc(ch); } int fgetc(FILE *f) { - UNUSED(f); + (void)(f); return UartPutc(UartGetc()); } @@ -260,7 +260,7 @@ int fgetc(FILE *f) /* arm-none-eabi-gcc with newlib uses a define for ferror */ int ferror(FILE *f) { - UNUSED(f); + (void)(f); return EOF; } diff --git a/source/application/hal/platforms/bare-metal/data_acquisition/data_acq.c b/source/hal/profiles/bare-metal/data_acquisition/data_acq.c index 1e40b02..1e40b02 100644 --- a/source/application/hal/platforms/bare-metal/data_acquisition/data_acq.c +++ b/source/hal/profiles/bare-metal/data_acquisition/data_acq.c diff --git a/source/application/hal/platforms/bare-metal/data_presentation/data_psn.c b/source/hal/profiles/bare-metal/data_presentation/data_psn.c index 474d552..474d552 100644 --- a/source/application/hal/platforms/bare-metal/data_presentation/data_psn.c +++ b/source/hal/profiles/bare-metal/data_presentation/data_psn.c diff --git a/source/application/hal/platforms/bare-metal/data_presentation/lcd/include/lcd_img.h b/source/hal/profiles/bare-metal/data_presentation/lcd/include/lcd_img.h index e4ad791..e4ad791 100644 --- a/source/application/hal/platforms/bare-metal/data_presentation/lcd/include/lcd_img.h +++ b/source/hal/profiles/bare-metal/data_presentation/lcd/include/lcd_img.h diff --git a/source/application/hal/platforms/bare-metal/data_presentation/lcd/lcd_img.c b/source/hal/profiles/bare-metal/data_presentation/lcd/lcd_img.c index f03566f..f03566f 100644 --- a/source/application/hal/platforms/bare-metal/data_presentation/lcd/lcd_img.c +++ b/source/hal/profiles/bare-metal/data_presentation/lcd/lcd_img.c diff --git a/source/application/hal/platforms/bare-metal/timer/include/baremetal_timer.h b/source/hal/profiles/bare-metal/timer/include/platform_timer.h index 0d23a05..6338e0b 100644 --- a/source/application/hal/platforms/bare-metal/timer/include/baremetal_timer.h +++ b/source/hal/profiles/bare-metal/timer/include/platform_timer.h @@ -17,17 +17,11 @@ #ifndef BAREMETAL_TIMER_H #define BAREMETAL_TIMER_H +#include "bsp.h" + #include <stdint.h> #include <time.h> -#if defined (MPS3_PLATFORM) - #include "timer_mps3.h" - typedef mps3_time_counter base_time_counter; -#else /* defined (MPS3_PLATFORM) */ - #include "timer_simple_platform.h" - typedef generic_time_counter base_time_counter; -#endif /* defined (MPS3_PLATFORM) */ - typedef struct bm_time_counter { base_time_counter counter; diff --git a/source/application/hal/platforms/bare-metal/timer/baremetal_timer.c b/source/hal/profiles/bare-metal/timer/platform_timer.c index c8e7252..c8e7252 100644 --- a/source/application/hal/platforms/bare-metal/timer/baremetal_timer.c +++ b/source/hal/profiles/bare-metal/timer/platform_timer.c diff --git a/source/application/hal/platforms/bare-metal/utils/include/system_init.h b/source/hal/profiles/bare-metal/utils/include/system_init.h index 84e0305..84e0305 100644 --- a/source/application/hal/platforms/bare-metal/utils/include/system_init.h +++ b/source/hal/profiles/bare-metal/utils/include/system_init.h diff --git a/source/application/hal/platforms/bare-metal/utils/system_init.c b/source/hal/profiles/bare-metal/utils/system_init.c index 376f08b..23af14f 100644 --- a/source/application/hal/platforms/bare-metal/utils/system_init.c +++ b/source/hal/profiles/bare-metal/utils/system_init.c @@ -16,8 +16,6 @@ */ #include "system_init.h" -#include "uart_stdout.h" - #include <string.h> #include <inttypes.h> diff --git a/source/application/hal/platforms/native/data_acquisition/data_acq.c b/source/hal/profiles/native/data_acquisition/data_acq.c index 9b6815b..9b6815b 100644 --- a/source/application/hal/platforms/native/data_acquisition/data_acq.c +++ b/source/hal/profiles/native/data_acquisition/data_acq.c diff --git a/source/application/hal/platforms/native/data_presentation/data_psn.c b/source/hal/profiles/native/data_presentation/data_psn.c index fe4bcfa..fe4bcfa 100644 --- a/source/application/hal/platforms/native/data_presentation/data_psn.c +++ b/source/hal/profiles/native/data_presentation/data_psn.c diff --git a/source/application/hal/platforms/native/data_presentation/log/include/log.h b/source/hal/profiles/native/data_presentation/log/include/log.h index 9b9928f..9b9928f 100644 --- a/source/application/hal/platforms/native/data_presentation/log/include/log.h +++ b/source/hal/profiles/native/data_presentation/log/include/log.h diff --git a/source/application/hal/platforms/native/data_presentation/log/log.c b/source/hal/profiles/native/data_presentation/log/log.c index 8dffba9..1673af1 100644 --- a/source/application/hal/platforms/native/data_presentation/log/log.c +++ b/source/hal/profiles/native/data_presentation/log/log.c @@ -15,8 +15,7 @@ * limitations under the License. */ #include "log.h" - -#include "dummy_log.h" +#include "log_macros.h" #include <stdint.h> diff --git a/source/application/hal/platforms/native/timer/include/native_timer.h b/source/hal/profiles/native/timer/include/platform_timer.h index df7b493..df7b493 100644 --- a/source/application/hal/platforms/native/timer/include/native_timer.h +++ b/source/hal/profiles/native/timer/include/platform_timer.h diff --git a/source/application/hal/platforms/native/timer/native_timer.cc b/source/hal/profiles/native/timer/platform_timer.c index c115f4d..c311125 100644 --- a/source/application/hal/platforms/native/timer/native_timer.cc +++ b/source/hal/profiles/native/timer/platform_timer.c @@ -20,9 +20,9 @@ extern "C" { #include "timer.h" -#include <cassert> -#include <ctime> -#include <cstring> +#include <assert.h> +#include <time.h> +#include <string.h> #define MILLISECONDS_IN_SECOND 1000 #define MICROSECONDS_IN_SECOND 1000000 @@ -35,7 +35,7 @@ extern "C" { **/ static time_counter get_time_counter(void) { - struct timespec current_time{}; + struct timespec current_time; clock_gettime(1, ¤t_time); time_counter t = { .current_secs = current_time.tv_sec, diff --git a/source/application/hal/platforms/native/utils/include/system_init.h b/source/hal/profiles/native/utils/include/system_init.h index 80b1bb2..5d3fcd0 100644 --- a/source/application/hal/platforms/native/utils/include/system_init.h +++ b/source/hal/profiles/native/utils/include/system_init.h @@ -17,8 +17,7 @@ #ifndef NATIVE_SYSTEM_INIT_H #define NATIVE_SYSTEM_INIT_H -#include "dummy_log.h" - +#include <stddef.h> /** * @brief Platform initialisation for native platform. **/ diff --git a/source/application/hal/platforms/native/utils/system_init.c b/source/hal/profiles/native/utils/system_init.c index 8e0b768..8e0b768 100644 --- a/source/application/hal/platforms/native/utils/system_init.c +++ b/source/hal/profiles/native/utils/system_init.c diff --git a/source/log/CMakeLists.txt b/source/log/CMakeLists.txt new file mode 100644 index 0000000..1de737e --- /dev/null +++ b/source/log/CMakeLists.txt @@ -0,0 +1,43 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2022 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#---------------------------------------------------------------------------- + +####################################################### +# Header-only logging definitions as an interface lib.# +####################################################### +cmake_minimum_required(VERSION 3.15.6) + +set(BSP_LOGGING_TARGET log) + +project(${BSP_LOGGING_TARGET} + DESCRIPTION "Generic logging formatting header-only interface lib." + LANGUAGES C) + +add_library(${BSP_LOGGING_TARGET} INTERFACE) + +if (DEFINED LOG_LEVEL) + message(STATUS "Setting log level to ${LOG_LEVEL}") + target_compile_definitions(${BSP_LOGGING_TARGET} + INTERFACE + LOG_LEVEL=${LOG_LEVEL}) +endif() + +target_include_directories(${BSP_LOGGING_TARGET} INTERFACE include) + +message(STATUS "*******************************************************") +message(STATUS "Library : " ${BSP_LOGGING_TARGET}) +message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) +message(STATUS "*******************************************************") diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-core/include/bsp_core_log.h b/source/log/include/log_macros.h index ffb55e7..15f4dd5 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-core/include/bsp_core_log.h +++ b/source/log/include/log_macros.h @@ -14,12 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef BSP_CORE_LOG_H -#define BSP_CORE_LOG_H +#ifndef ML_EMBEDDED_CORE_LOG_H +#define ML_EMBEDDED_CORE_LOG_H -#include "uart_stdout.h" /* UART for logging */ +#ifdef __cplusplus +extern "C" { +#endif #include <stdio.h> +#include <inttypes.h> #define LOG_LEVEL_TRACE 0 #define LOG_LEVEL_DEBUG 1 @@ -31,6 +34,8 @@ #define LOG_LEVEL LOG_LEVEL_INFO #endif /*LOG_LEVEL*/ +#define UNUSED(x) ((void)(x)) + #if (LOG_LEVEL == LOG_LEVEL_TRACE) #define trace(...) printf("TRACE - "); printf(__VA_ARGS__) #else @@ -61,6 +66,8 @@ #define printf_err(...) #endif /* LOG_LEVEL > LOG_LEVEL_INFO */ -#define UNUSED(x) ((void)(x)) +#ifdef __cplusplus +} +#endif -#endif /* BSP_CORE_LOG_H */ +#endif /* ML_EMBEDDED_CORE_LOG_H */
\ No newline at end of file diff --git a/source/math/CMakeLists.txt b/source/math/CMakeLists.txt new file mode 100644 index 0000000..eab6622 --- /dev/null +++ b/source/math/CMakeLists.txt @@ -0,0 +1,44 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2022 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#---------------------------------------------------------------------------- + +####################################################### +# Math functions for ML pipelines. # +####################################################### + +project(arm_math + DESCRIPTION "Collection of the optimised math functions for ML pipelines" + LANGUAGES C CXX) + +add_library(arm_math STATIC) + +target_sources(arm_math + PRIVATE + PlatformMath.cc) + +target_include_directories(arm_math PUBLIC include) + +target_link_libraries(arm_math PRIVATE log) + +if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL cortex-m55) + include(${CMAKE_SCRIPTS_DIR}/cmsis-dsp.cmake) + target_link_libraries(arm_math PUBLIC cmsis-dsp) +endif () + +message(STATUS "*******************************************************") +message(STATUS "Library : " arm_math) +message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) +message(STATUS "*******************************************************") diff --git a/source/application/main/PlatformMath.cc b/source/math/PlatformMath.cc index 26b4b72..cc603f3 100644 --- a/source/application/main/PlatformMath.cc +++ b/source/math/PlatformMath.cc @@ -15,13 +15,8 @@ * limitations under the License. */ #include "PlatformMath.hpp" +#include "log_macros.h" #include <algorithm> -#include <numeric> - -#if 0 == ARM_DSP_AVAILABLE - #include <cmath> - #include <numeric> -#endif /* 0 == ARM_DSP_AVAILABLE */ namespace arm { namespace app { @@ -29,31 +24,31 @@ namespace math { float MathUtils::CosineF32(float radians) { -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP return arm_cos_f32(radians); -#else /* ARM_DSP_AVAILABLE */ - return cos(radians); -#endif /* ARM_DSP_AVAILABLE */ +#else /* ARM_MATH_DSP */ + return cosf(radians); +#endif /* ARM_MATH_DSP */ } float MathUtils::SineF32(float radians) { -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP return arm_sin_f32(radians); -#else /* ARM_DSP_AVAILABLE */ - return sin(radians); -#endif /* ARM_DSP_AVAILABLE */ +#else /* ARM_MATH_DSP */ + return sinf(radians); +#endif /* ARM_MATH_DSP */ } float MathUtils::SqrtF32(float input) { -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP float output = 0.f; arm_sqrt_f32(input, &output); return output; -#else /* ARM_DSP_AVAILABLE */ +#else /* ARM_MATH_DSP */ return sqrtf(input); -#endif /* ARM_DSP_AVAILABLE */ +#endif /* ARM_MATH_DSP */ } float MathUtils::MeanF32(float* ptrSrc, const uint32_t srcLen) @@ -62,14 +57,14 @@ namespace math { return 0.f; } -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP float result = 0.f; arm_mean_f32(ptrSrc, srcLen, &result); return result; -#else /* ARM_DSP_AVAILABLE */ +#else /* ARM_MATH_DSP */ float acc = std::accumulate(ptrSrc, ptrSrc + srcLen, 0.0); return acc/srcLen; -#endif /* ARM_DSP_AVAILABLE */ +#endif /* ARM_MATH_DSP */ } float MathUtils::StdDevF32(float* ptrSrc, const uint32_t srcLen, @@ -78,7 +73,7 @@ namespace math { if (!srcLen) { return 0.f; } -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP /** * Note Standard deviation calculation can be off * by > 0.01 but less than < 0.1, according to @@ -88,7 +83,7 @@ namespace math { float stdDev = 0; arm_std_f32(ptrSrc, srcLen, &stdDev); return stdDev; -#else /* ARM_DSP_AVAILABLE */ +#else /* ARM_MATH_DSP */ auto VarianceFunction = [=](float acc, const float value) { return acc + (((value - mean) * (value - mean))/ srcLen); }; @@ -97,7 +92,7 @@ namespace math { VarianceFunction); return sqrtf(acc); -#endif /* ARM_DSP_AVAILABLE */ +#endif /* ARM_MATH_DSP */ } void MathUtils::FftInitF32(const uint16_t fftLen, @@ -109,7 +104,7 @@ namespace math { fftInstance.m_optimisedOptionAvailable = false; fftInstance.m_type = type; -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP arm_status status = ARM_MATH_ARGUMENT_ERROR; switch (fftInstance.m_type) { case FftType::real: @@ -130,11 +125,9 @@ namespace math { } else { fftInstance.m_optimisedOptionAvailable = true; } -#endif /* ARM_DSP_AVAILABLE */ +#endif /* ARM_MATH_DSP */ - if (!fftInstance.m_optimisedOptionAvailable) { - debug("Non optimised FFT will be used\n."); - } + debug("Optimised FFT will be used: %s.\n", fftInstance.m_optimisedOptionAvailable? "yes": "no"); fftInstance.m_initialised = true; } @@ -157,7 +150,7 @@ namespace math { float sumReal = 0; float sumImag = 0; - const float theta = static_cast<float>(2 * M_PI * k / inputLength); + const auto theta = static_cast<float>(2 * M_PI * k / inputLength); for (size_t t = 0; t < inputLength; t++) { const auto angle = static_cast<float>(t * theta); @@ -210,12 +203,12 @@ namespace math { switch (fftInstance.m_type) { case FftType::real: -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP if (fftInstance.m_optimisedOptionAvailable) { arm_rfft_fast_f32(&fftInstance.m_instanceReal, input.data(), fftOutput.data(), 0); return; } -#endif /* ARM_DSP_AVAILABLE */ +#endif /* ARM_MATH_DSP */ FftRealF32(input, fftOutput); return; @@ -224,13 +217,13 @@ namespace math { printf_err("Complex FFT instance should have input size >= (FFT len x 2)"); return; } -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP if (fftInstance.m_optimisedOptionAvailable) { fftOutput = input; /* Complex function works in-place */ arm_cfft_f32(&fftInstance.m_instanceComplex, fftOutput.data(), 0, 1); return; } -#endif /* ARM_DSP_AVAILABLE */ +#endif /* ARM_MATH_DSP */ FftComplexF32(input, fftOutput); return; @@ -243,15 +236,15 @@ namespace math { void MathUtils::VecLogarithmF32(std::vector <float>& input, std::vector <float>& output) { -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP arm_vlog_f32(input.data(), output.data(), output.size()); -#else /* ARM_DSP_AVAILABLE */ +#else /* ARM_MATH_DSP */ for (auto in = input.begin(), out = output.begin(); in != input.end() && out != output.end(); ++in, ++out) { *out = logf(*in); } -#endif /* ARM_DSP_AVAILABLE */ +#endif /* ARM_MATH_DSP */ } float MathUtils::DotProductF32(float* srcPtrA, float* srcPtrB, @@ -259,13 +252,13 @@ namespace math { { float output = 0.f; -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP arm_dot_prod_f32(srcPtrA, srcPtrB, srcLen, &output); -#else /* ARM_DSP_AVAILABLE */ +#else /* ARM_MATH_DSP */ for (uint32_t i = 0; i < srcLen; ++i) { output += *srcPtrA++ * *srcPtrB++; } -#endif /* ARM_DSP_AVAILABLE */ +#endif /* ARM_MATH_DSP */ return output; } @@ -280,15 +273,15 @@ namespace math { return false; } -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP arm_cmplx_mag_squared_f32(ptrSrc, ptrDst, srcLen/2); -#else /* ARM_DSP_AVAILABLE */ +#else /* ARM_MATH_DSP */ for (uint32_t j = 0; j < srcLen/2; ++j) { const float real = *ptrSrc++; const float im = *ptrSrc++; *ptrDst++ = real*real + im*im; } -#endif /* ARM_DSP_AVAILABLE */ +#endif /* ARM_MATH_DSP */ return true; } diff --git a/source/application/main/include/PlatformMath.hpp b/source/math/include/PlatformMath.hpp index fdb51b2..5ac10de 100644 --- a/source/application/main/include/PlatformMath.hpp +++ b/source/math/include/PlatformMath.hpp @@ -17,20 +17,18 @@ #ifndef PLATFORM_MATH_HPP #define PLATFORM_MATH_HPP -#include "hal.h" - /* See if ARM DSP functions can be used. */ -#if PLATFORM_HAL == PLATFORM_CORTEX_M_BAREMETAL - #if defined(__DSP_PRESENT) && (__DSP_PRESENT == 1U) - - #define ARM_DSP_AVAILABLE (1U) - #include "arm_math.h" - #define M_PI (PI) +#if defined(ARM_MATH_DSP) - #endif /* defined(__DSP_PRESENT) && (__DSP_PRESENT == 1U) */ -#endif /* PLATFORM_HAL == PLATFORM_CORTEX_M_BAREMETAL */ + #include "arm_math.h" + #define M_PI (PI) +#else + #include <cmath> +#endif #include <vector> +#include <cstdint> +#include <numeric> namespace arm { namespace app { @@ -42,12 +40,12 @@ namespace math { }; struct FftInstance { -#if ARM_DSP_AVAILABLE +#if ARM_MATH_DSP arm_rfft_fast_instance_f32 m_instanceReal; arm_cfft_instance_f32 m_instanceComplex; #endif uint16_t m_fftLen{0}; - FftType m_type; + FftType m_type{FftType::real}; bool m_optimisedOptionAvailable{false}; bool m_initialised{false}; }; @@ -108,9 +106,9 @@ namespace math { * @param[in] fftInstance FFT instance struct to use. * @param[in] type FFT type (real or complex) */ - static void FftInitF32(const uint16_t fftLen, + static void FftInitF32(uint16_t fftLen, FftInstance& fftInstance, - const FftType type = FftType::real); + FftType type = FftType::real); /** * @brief Computes the FFT for the input vector. @@ -144,7 +142,7 @@ namespace math { * @return Dot product. */ static float DotProductF32(float* srcPtrA, float* srcPtrB, - const uint32_t srcLen); + uint32_t srcLen); /** * @brief Computes the squared magnitude of floating point @@ -157,9 +155,9 @@ namespace math { * @return true if successful, false otherwise. */ static bool ComplexMagnitudeSquaredF32(float* ptrSrc, - const uint32_t srcLen, + uint32_t srcLen, float* ptrDst, - const uint32_t dstLen); + uint32_t dstLen); /** * @brief Scales output scores for an arbitrary number of classes so diff --git a/source/use_case/ad/src/AdMelSpectrogram.cc b/source/use_case/ad/src/AdMelSpectrogram.cc index e070eb8..14b9323 100644 --- a/source/use_case/ad/src/AdMelSpectrogram.cc +++ b/source/use_case/ad/src/AdMelSpectrogram.cc @@ -15,8 +15,8 @@ * limitations under the License. */ #include "AdMelSpectrogram.hpp" - #include "PlatformMath.hpp" +#include "log_macros.h" #include <cfloat> diff --git a/source/use_case/ad/src/AdModel.cc b/source/use_case/ad/src/AdModel.cc index 82ad822..a2ef260 100644 --- a/source/use_case/ad/src/AdModel.cc +++ b/source/use_case/ad/src/AdModel.cc @@ -15,8 +15,7 @@ * limitations under the License. */ #include "AdModel.hpp" - -#include "hal.h" +#include "log_macros.h" const tflite::MicroOpResolver& arm::app::AdModel::GetOpResolver() { diff --git a/source/use_case/ad/src/AdPostProcessing.cc b/source/use_case/ad/src/AdPostProcessing.cc index 157784b..c461875 100644 --- a/source/use_case/ad/src/AdPostProcessing.cc +++ b/source/use_case/ad/src/AdPostProcessing.cc @@ -15,8 +15,7 @@ * limitations under the License. */ #include "AdPostProcessing.hpp" - -#include "hal.h" +#include "log_macros.h" #include <numeric> #include <cmath> diff --git a/source/use_case/ad/src/MainLoop.cc b/source/use_case/ad/src/MainLoop.cc index a323610..5a289bf 100644 --- a/source/use_case/ad/src/MainLoop.cc +++ b/source/use_case/ad/src/MainLoop.cc @@ -19,6 +19,7 @@ #include "AdModel.hpp" /* Model class for running inference */ #include "UseCaseCommonUtils.hpp" /* Utils functions */ #include "UseCaseHandler.hpp" /* Handlers for different user options */ +#include "log_macros.h" enum opcodes { diff --git a/source/use_case/ad/src/MelSpectrogram.cc b/source/use_case/ad/src/MelSpectrogram.cc index fa7714a..ff0c536 100644 --- a/source/use_case/ad/src/MelSpectrogram.cc +++ b/source/use_case/ad/src/MelSpectrogram.cc @@ -17,9 +17,10 @@ #include "MelSpectrogram.hpp" #include "PlatformMath.hpp" +#include "log_macros.h" #include <cfloat> -#include <inttypes.h> +#include <cinttypes> namespace arm { namespace app { diff --git a/source/use_case/ad/src/UseCaseHandler.cc b/source/use_case/ad/src/UseCaseHandler.cc index bc6ec7a..420e6d4 100644 --- a/source/use_case/ad/src/UseCaseHandler.cc +++ b/source/use_case/ad/src/UseCaseHandler.cc @@ -24,6 +24,7 @@ #include "AudioUtils.hpp" #include "UseCaseCommonUtils.hpp" #include "AdPostProcessing.hpp" +#include "log_macros.h" namespace arm { namespace app { diff --git a/source/use_case/asr/include/Wav2LetterPostprocess.hpp b/source/use_case/asr/include/Wav2LetterPostprocess.hpp index a744e0f..29eb548 100644 --- a/source/use_case/asr/include/Wav2LetterPostprocess.hpp +++ b/source/use_case/asr/include/Wav2LetterPostprocess.hpp @@ -18,7 +18,7 @@ #define ASR_WAV2LETTER_POSTPROCESS_HPP #include "TensorFlowLiteMicro.hpp" /* TensorFlow headers. */ -#include "hal.h" /* stdout facility. */ +#include "log_macros.h" namespace arm { namespace app { diff --git a/source/use_case/asr/include/Wav2LetterPreprocess.hpp b/source/use_case/asr/include/Wav2LetterPreprocess.hpp index b0e0c67..13d1589 100644 --- a/source/use_case/asr/include/Wav2LetterPreprocess.hpp +++ b/source/use_case/asr/include/Wav2LetterPreprocess.hpp @@ -21,6 +21,7 @@ #include "Wav2LetterMfcc.hpp" #include "AudioUtils.hpp" #include "DataStructures.hpp" +#include "log_macros.h" namespace arm { namespace app { diff --git a/source/use_case/asr/src/AsrClassifier.cc b/source/use_case/asr/src/AsrClassifier.cc index a715068..84e66b7 100644 --- a/source/use_case/asr/src/AsrClassifier.cc +++ b/source/use_case/asr/src/AsrClassifier.cc @@ -16,7 +16,7 @@ */ #include "AsrClassifier.hpp" -#include "hal.h" +#include "log_macros.h" #include "TensorFlowLiteMicro.hpp" #include "Wav2LetterModel.hpp" diff --git a/source/use_case/asr/src/MainLoop.cc b/source/use_case/asr/src/MainLoop.cc index 87145f4..40624f3 100644 --- a/source/use_case/asr/src/MainLoop.cc +++ b/source/use_case/asr/src/MainLoop.cc @@ -23,6 +23,7 @@ #include "InputFiles.hpp" /* Generated audio clip header. */ #include "Wav2LetterPreprocess.hpp" /* Pre-processing class. */ #include "Wav2LetterPostprocess.hpp" /* Post-processing class. */ +#include "log_macros.h" enum opcodes { diff --git a/source/use_case/asr/src/UseCaseHandler.cc b/source/use_case/asr/src/UseCaseHandler.cc index f13de0d..afcb6e4 100644 --- a/source/use_case/asr/src/UseCaseHandler.cc +++ b/source/use_case/asr/src/UseCaseHandler.cc @@ -27,6 +27,7 @@ #include "Wav2LetterPreprocess.hpp" #include "Wav2LetterPostprocess.hpp" #include "OutputDecode.hpp" +#include "log_macros.h" namespace arm { namespace app { diff --git a/source/use_case/asr/src/Wav2LetterMfcc.cc b/source/use_case/asr/src/Wav2LetterMfcc.cc index 0eb152a..1bcaa66 100644 --- a/source/use_case/asr/src/Wav2LetterMfcc.cc +++ b/source/use_case/asr/src/Wav2LetterMfcc.cc @@ -15,8 +15,8 @@ * limitations under the License. */ #include "Wav2LetterMfcc.hpp" - #include "PlatformMath.hpp" +#include "log_macros.h" #include <cfloat> diff --git a/source/use_case/asr/src/Wav2LetterModel.cc b/source/use_case/asr/src/Wav2LetterModel.cc index a22dc55..766bce9 100644 --- a/source/use_case/asr/src/Wav2LetterModel.cc +++ b/source/use_case/asr/src/Wav2LetterModel.cc @@ -15,8 +15,8 @@ * limitations under the License. */ #include "Wav2LetterModel.hpp" +#include "log_macros.h" -#include "hal.h" const tflite::MicroOpResolver& arm::app::Wav2LetterModel::GetOpResolver() { diff --git a/source/use_case/asr/src/Wav2LetterPostprocess.cc b/source/use_case/asr/src/Wav2LetterPostprocess.cc index fd11eef..0392061 100644 --- a/source/use_case/asr/src/Wav2LetterPostprocess.cc +++ b/source/use_case/asr/src/Wav2LetterPostprocess.cc @@ -15,9 +15,8 @@ * limitations under the License. */ #include "Wav2LetterPostprocess.hpp" - #include "Wav2LetterModel.hpp" - +#include "log_macros.h" namespace arm { namespace app { diff --git a/source/use_case/img_class/src/MainLoop.cc b/source/use_case/img_class/src/MainLoop.cc index cab360b..05322d1 100644 --- a/source/use_case/img_class/src/MainLoop.cc +++ b/source/use_case/img_class/src/MainLoop.cc @@ -21,6 +21,7 @@ #include "MobileNetModel.hpp" /* Model class for running inference. */ #include "UseCaseHandler.hpp" /* Handlers for different user options. */ #include "UseCaseCommonUtils.hpp" /* Utils functions. */ +#include "log_macros.h" using ImgClassClassifier = arm::app::Classifier; diff --git a/source/use_case/img_class/src/MobileNetModel.cc b/source/use_case/img_class/src/MobileNetModel.cc index b937382..2e48f3b 100644 --- a/source/use_case/img_class/src/MobileNetModel.cc +++ b/source/use_case/img_class/src/MobileNetModel.cc @@ -15,8 +15,7 @@ * limitations under the License. */ #include "MobileNetModel.hpp" - -#include "hal.h" +#include "log_macros.h" const tflite::MicroOpResolver& arm::app::MobileNetModel::GetOpResolver() { diff --git a/source/use_case/img_class/src/UseCaseHandler.cc b/source/use_case/img_class/src/UseCaseHandler.cc index 3812d81..fafc6b9 100644 --- a/source/use_case/img_class/src/UseCaseHandler.cc +++ b/source/use_case/img_class/src/UseCaseHandler.cc @@ -21,8 +21,9 @@ #include "MobileNetModel.hpp" #include "UseCaseCommonUtils.hpp" #include "hal.h" +#include "log_macros.h" -#include <inttypes.h> +#include <cinttypes> using ImgClassClassifier = arm::app::Classifier; @@ -108,7 +109,7 @@ namespace app { /* Display message on the LCD - inference running. */ platform.data_psn->present_data_text(str_inf.c_str(), str_inf.size(), - dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); + dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); /* Run inference over this image. */ info("Running inference on image %" PRIu32 " => %s\n", ctx.Get<uint32_t>("imgIndex"), @@ -121,12 +122,12 @@ namespace app { /* Erase. */ str_inf = std::string(str_inf.size(), ' '); platform.data_psn->present_data_text(str_inf.c_str(), str_inf.size(), - dataPsnTxtInfStartX, dataPsnTxtInfStartY, 0); + dataPsnTxtInfStartX, dataPsnTxtInfStartY, false); auto& classifier = ctx.Get<ImgClassClassifier&>("classifier"); classifier.GetClassificationResults(outputTensor, results, ctx.Get<std::vector <std::string>&>("labels"), - 5); + 5, false); /* Add results to context for access outside handler. */ ctx.Set<std::vector<ClassificationResult>>("results", results); diff --git a/source/use_case/inference_runner/src/MainLoop.cc b/source/use_case/inference_runner/src/MainLoop.cc index 26a20de..cfdc520 100644 --- a/source/use_case/inference_runner/src/MainLoop.cc +++ b/source/use_case/inference_runner/src/MainLoop.cc @@ -18,6 +18,7 @@ #include "TestModel.hpp" /* Model class for running inference. */ #include "UseCaseHandler.hpp" /* Handlers for different user options. */ #include "UseCaseCommonUtils.hpp" /* Utils functions. */ +#include "log_macros.h" enum opcodes { diff --git a/source/use_case/inference_runner/src/TestModel.cc b/source/use_case/inference_runner/src/TestModel.cc index 274790f..3e72119 100644 --- a/source/use_case/inference_runner/src/TestModel.cc +++ b/source/use_case/inference_runner/src/TestModel.cc @@ -15,8 +15,7 @@ * limitations under the License. */ #include "TestModel.hpp" - -#include "hal.h" +#include "log_macros.h" const tflite::AllOpsResolver& arm::app::TestModel::GetOpResolver() { diff --git a/source/use_case/inference_runner/src/UseCaseHandler.cc b/source/use_case/inference_runner/src/UseCaseHandler.cc index 78d99b0..1125830 100644 --- a/source/use_case/inference_runner/src/UseCaseHandler.cc +++ b/source/use_case/inference_runner/src/UseCaseHandler.cc @@ -19,6 +19,7 @@ #include "TestModel.hpp" #include "UseCaseCommonUtils.hpp" #include "hal.h" +#include "log_macros.h" #include <cstdlib> diff --git a/source/use_case/kws/src/MainLoop.cc b/source/use_case/kws/src/MainLoop.cc index bde246b..044c957 100644 --- a/source/use_case/kws/src/MainLoop.cc +++ b/source/use_case/kws/src/MainLoop.cc @@ -21,6 +21,7 @@ #include "Labels.hpp" /* For label strings. */ #include "UseCaseHandler.hpp" /* Handlers for different user options. */ #include "UseCaseCommonUtils.hpp" /* Utils functions. */ +#include "log_macros.h" using KwsClassifier = arm::app::Classifier; diff --git a/source/use_case/kws/src/MicroNetKwsModel.cc b/source/use_case/kws/src/MicroNetKwsModel.cc index 48a9b8c..1c38525 100644 --- a/source/use_case/kws/src/MicroNetKwsModel.cc +++ b/source/use_case/kws/src/MicroNetKwsModel.cc @@ -15,8 +15,7 @@ * limitations under the License. */ #include "MicroNetKwsModel.hpp" - -#include "hal.h" +#include "log_macros.h" const tflite::MicroOpResolver& arm::app::MicroNetKwsModel::GetOpResolver() { diff --git a/source/use_case/kws/src/UseCaseHandler.cc b/source/use_case/kws/src/UseCaseHandler.cc index 8085af7..c2d2ea4 100644 --- a/source/use_case/kws/src/UseCaseHandler.cc +++ b/source/use_case/kws/src/UseCaseHandler.cc @@ -24,6 +24,7 @@ #include "AudioUtils.hpp" #include "UseCaseCommonUtils.hpp" #include "KwsResult.hpp" +#include "log_macros.h" #include <vector> #include <functional> diff --git a/source/use_case/kws_asr/include/Wav2LetterPostprocess.hpp b/source/use_case/kws_asr/include/Wav2LetterPostprocess.hpp index 5c11412..029a641 100644 --- a/source/use_case/kws_asr/include/Wav2LetterPostprocess.hpp +++ b/source/use_case/kws_asr/include/Wav2LetterPostprocess.hpp @@ -18,7 +18,6 @@ #define KWS_ASR_WAV2LET_POSTPROC_HPP #include "TensorFlowLiteMicro.hpp" /* TensorFlow headers */ -#include "hal.h" /* stdout facility */ namespace arm { namespace app { diff --git a/source/use_case/kws_asr/include/Wav2LetterPreprocess.hpp b/source/use_case/kws_asr/include/Wav2LetterPreprocess.hpp index 66d19d3..3609c49 100644 --- a/source/use_case/kws_asr/include/Wav2LetterPreprocess.hpp +++ b/source/use_case/kws_asr/include/Wav2LetterPreprocess.hpp @@ -21,6 +21,7 @@ #include "Wav2LetterMfcc.hpp" #include "AudioUtils.hpp" #include "DataStructures.hpp" +#include "log_macros.h" namespace arm { namespace app { diff --git a/source/use_case/kws_asr/src/AsrClassifier.cc b/source/use_case/kws_asr/src/AsrClassifier.cc index 3f9cd7b..9c18b14 100644 --- a/source/use_case/kws_asr/src/AsrClassifier.cc +++ b/source/use_case/kws_asr/src/AsrClassifier.cc @@ -16,7 +16,7 @@ */ #include "AsrClassifier.hpp" -#include "hal.h" +#include "log_macros.h" #include "TensorFlowLiteMicro.hpp" #include "Wav2LetterModel.hpp" diff --git a/source/use_case/kws_asr/src/MainLoop.cc b/source/use_case/kws_asr/src/MainLoop.cc index c7e977f..a2beab3 100644 --- a/source/use_case/kws_asr/src/MainLoop.cc +++ b/source/use_case/kws_asr/src/MainLoop.cc @@ -26,6 +26,7 @@ #include "UseCaseHandler.hpp" /* Handlers for different user options. */ #include "Wav2LetterPreprocess.hpp" /* ASR pre-processing class. */ #include "Wav2LetterPostprocess.hpp"/* ASR post-processing class. */ +#include "log_macros.h" using KwsClassifier = arm::app::Classifier; diff --git a/source/use_case/kws_asr/src/MicroNetKwsModel.cc b/source/use_case/kws_asr/src/MicroNetKwsModel.cc index 4b44580..663faa0 100644 --- a/source/use_case/kws_asr/src/MicroNetKwsModel.cc +++ b/source/use_case/kws_asr/src/MicroNetKwsModel.cc @@ -15,8 +15,7 @@ * limitations under the License. */ #include "MicroNetKwsModel.hpp" - -#include "hal.h" +#include "log_macros.h" namespace arm { namespace app { diff --git a/source/use_case/kws_asr/src/UseCaseHandler.cc b/source/use_case/kws_asr/src/UseCaseHandler.cc index a3ebdb1..bfc1d25 100644 --- a/source/use_case/kws_asr/src/UseCaseHandler.cc +++ b/source/use_case/kws_asr/src/UseCaseHandler.cc @@ -30,6 +30,7 @@ #include "AsrResult.hpp" #include "AsrClassifier.hpp" #include "OutputDecode.hpp" +#include "log_macros.h" using KwsClassifier = arm::app::Classifier; diff --git a/source/use_case/kws_asr/src/Wav2LetterMfcc.cc b/source/use_case/kws_asr/src/Wav2LetterMfcc.cc index ae9e57a..f2c50f3 100644 --- a/source/use_case/kws_asr/src/Wav2LetterMfcc.cc +++ b/source/use_case/kws_asr/src/Wav2LetterMfcc.cc @@ -17,6 +17,7 @@ #include "Wav2LetterMfcc.hpp" #include "PlatformMath.hpp" +#include "log_macros.h" #include <cfloat> diff --git a/source/use_case/kws_asr/src/Wav2LetterModel.cc b/source/use_case/kws_asr/src/Wav2LetterModel.cc index affa1a6..52bd23a 100644 --- a/source/use_case/kws_asr/src/Wav2LetterModel.cc +++ b/source/use_case/kws_asr/src/Wav2LetterModel.cc @@ -15,8 +15,7 @@ * limitations under the License. */ #include "Wav2LetterModel.hpp" - -#include "hal.h" +#include "log_macros.h" namespace arm { namespace app { diff --git a/source/use_case/kws_asr/src/Wav2LetterPostprocess.cc b/source/use_case/kws_asr/src/Wav2LetterPostprocess.cc index f2d9357..2a76b1b 100644 --- a/source/use_case/kws_asr/src/Wav2LetterPostprocess.cc +++ b/source/use_case/kws_asr/src/Wav2LetterPostprocess.cc @@ -15,8 +15,8 @@ * limitations under the License. */ #include "Wav2LetterPostprocess.hpp" - #include "Wav2LetterModel.hpp" +#include "log_macros.h" namespace arm { namespace app { diff --git a/source/use_case/noise_reduction/src/MainLoop.cc b/source/use_case/noise_reduction/src/MainLoop.cc index 7d814a8..c6214e3 100644 --- a/source/use_case/noise_reduction/src/MainLoop.cc +++ b/source/use_case/noise_reduction/src/MainLoop.cc @@ -20,6 +20,7 @@ #include "RNNoiseModel.hpp" /* Model class for running inference. */ #include "InputFiles.hpp" /* For input audio clips. */ #include "RNNoiseProcess.hpp" /* Pre-processing class */ +#include "log_macros.h" enum opcodes { diff --git a/source/use_case/noise_reduction/src/RNNoiseModel.cc b/source/use_case/noise_reduction/src/RNNoiseModel.cc index be0f369..244fa1a 100644 --- a/source/use_case/noise_reduction/src/RNNoiseModel.cc +++ b/source/use_case/noise_reduction/src/RNNoiseModel.cc @@ -15,8 +15,7 @@ * limitations under the License. */ #include "RNNoiseModel.hpp" - -#include "hal.h" +#include "log_macros.h" const tflite::MicroOpResolver& arm::app::RNNoiseModel::GetOpResolver() { diff --git a/source/use_case/noise_reduction/src/RNNoiseProcess.cc b/source/use_case/noise_reduction/src/RNNoiseProcess.cc index d5b577e..4c568fa 100644 --- a/source/use_case/noise_reduction/src/RNNoiseProcess.cc +++ b/source/use_case/noise_reduction/src/RNNoiseProcess.cc @@ -15,6 +15,8 @@ * limitations under the License. */ #include "RNNoiseProcess.hpp" +#include "log_macros.h" + #include <algorithm> #include <cmath> #include <cstring> diff --git a/source/use_case/noise_reduction/src/UseCaseHandler.cc b/source/use_case/noise_reduction/src/UseCaseHandler.cc index 12b4ab3..0c5984c 100644 --- a/source/use_case/noise_reduction/src/UseCaseHandler.cc +++ b/source/use_case/noise_reduction/src/UseCaseHandler.cc @@ -14,16 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <cmath> -#include <algorithm> - -#include "UseCaseHandler.hpp" #include "hal.h" +#include "UseCaseHandler.hpp" #include "UseCaseCommonUtils.hpp" #include "AudioUtils.hpp" #include "InputFiles.hpp" #include "RNNoiseModel.hpp" #include "RNNoiseProcess.hpp" +#include "log_macros.h" + +#include <cmath> +#include <algorithm> namespace arm { namespace app { diff --git a/source/use_case/object_detection/src/MainLoop.cc b/source/use_case/object_detection/src/MainLoop.cc index d8fc7f5..4bec357 100644 --- a/source/use_case/object_detection/src/MainLoop.cc +++ b/source/use_case/object_detection/src/MainLoop.cc @@ -20,7 +20,7 @@ #include "UseCaseHandler.hpp" /* Handlers for different user options. */ #include "UseCaseCommonUtils.hpp" /* Utils functions. */ #include "DetectorPostProcessing.hpp" /* Post-processing class. */ - +#include "log_macros.h" static void DisplayDetectionMenu() { diff --git a/source/use_case/object_detection/src/UseCaseHandler.cc b/source/use_case/object_detection/src/UseCaseHandler.cc index ce3ef06..620ce6c 100644 --- a/source/use_case/object_detection/src/UseCaseHandler.cc +++ b/source/use_case/object_detection/src/UseCaseHandler.cc @@ -20,8 +20,9 @@ #include "UseCaseCommonUtils.hpp" #include "DetectorPostProcessing.hpp" #include "hal.h" +#include "log_macros.h" -#include <inttypes.h> +#include <cinttypes> namespace arm { namespace app { @@ -151,7 +152,8 @@ namespace app { dataPsnImgStartX, dataPsnImgStartY, dataPsnImgDownscaleFactor); #if VERIFY_TEST_OUTPUT - arm::app::DumpTensor(outputTensor); + arm::app::DumpTensor(modelOutput0); + arm::app::DumpTensor(modelOutput1); #endif /* VERIFY_TEST_OUTPUT */ if (!PresentInferenceResult(platform, results)) { diff --git a/source/use_case/object_detection/src/YoloFastestModel.cc b/source/use_case/object_detection/src/YoloFastestModel.cc index a8afd59..b1fd776 100644 --- a/source/use_case/object_detection/src/YoloFastestModel.cc +++ b/source/use_case/object_detection/src/YoloFastestModel.cc @@ -16,7 +16,7 @@ */ #include "YoloFastestModel.hpp" -#include "hal.h" +#include "log_macros.h" const tflite::MicroOpResolver& arm::app::YoloFastestModel::GetOpResolver() { diff --git a/source/use_case/vww/src/MainLoop.cc b/source/use_case/vww/src/MainLoop.cc index b29238c..30e85bf 100644 --- a/source/use_case/vww/src/MainLoop.cc +++ b/source/use_case/vww/src/MainLoop.cc @@ -21,6 +21,7 @@ #include "VisualWakeWordModel.hpp" /* Model class for running inference. */ #include "UseCaseHandler.hpp" /* Handlers for different user options. */ #include "UseCaseCommonUtils.hpp" /* Utils functions. */ +#include "log_macros.h" using ViusalWakeWordClassifier = arm::app::Classifier; diff --git a/source/use_case/vww/src/UseCaseHandler.cc b/source/use_case/vww/src/UseCaseHandler.cc index e4dc479..01011e2 100644 --- a/source/use_case/vww/src/UseCaseHandler.cc +++ b/source/use_case/vww/src/UseCaseHandler.cc @@ -20,6 +20,7 @@ #include "InputFiles.hpp" #include "UseCaseCommonUtils.hpp" #include "hal.h" +#include "log_macros.h" #include <algorithm> @@ -133,7 +134,8 @@ namespace app { auto& classifier = ctx.Get<Classifier&>("classifier"); classifier.GetClassificationResults(outputTensor, results, - ctx.Get<std::vector <std::string>&>("labels"), 1); + ctx.Get<std::vector <std::string>&>("labels"), 1, + false); /* Add results to context for access outside handler. */ ctx.Set<std::vector<ClassificationResult>>("results", results); diff --git a/source/use_case/vww/src/VisualWakeWordModel.cc b/source/use_case/vww/src/VisualWakeWordModel.cc index 3067c7a..59beccc 100644 --- a/source/use_case/vww/src/VisualWakeWordModel.cc +++ b/source/use_case/vww/src/VisualWakeWordModel.cc @@ -15,8 +15,7 @@ * limitations under the License. */ #include "VisualWakeWordModel.hpp" - -#include "hal.h" +#include "log_macros.h" const tflite::MicroOpResolver& arm::app::VisualWakeWordModel::GetOpResolver() { diff --git a/tests/use_case/ad/InferenceTestAD.cc b/tests/use_case/ad/InferenceTestAD.cc index 2933fbe..6a1813f 100644 --- a/tests/use_case/ad/InferenceTestAD.cc +++ b/tests/use_case/ad/InferenceTestAD.cc @@ -20,7 +20,7 @@ #include "AdModel.hpp" #include "TestData_ad.hpp" -#include "hal.h" +#include "log_macros.h" #include "TensorFlowLiteMicro.hpp" #ifndef AD_FEATURE_VEC_DATA_SIZE diff --git a/tests/use_case/ad/MelSpecTests.cc b/tests/use_case/ad/MelSpecTests.cc index affc67a..59a0b97 100644 --- a/tests/use_case/ad/MelSpecTests.cc +++ b/tests/use_case/ad/MelSpecTests.cc @@ -198,15 +198,6 @@ template void TestQuntisedMelSpec<int16_t>(); TEST_CASE("Mel Spec calculation") { - hal_platform platform; - data_acq_module dataAcq; - data_psn_module dataPsn; - platform_timer timer; - - /* Initialise the HAL and platform */ - hal_init(&platform, &dataAcq, &dataPsn, &timer); - hal_platform_init(&platform); - SECTION("FP32") { auto melSpecOutput = GetMelSpecInstance().ComputeMelSpec(testWav1); REQUIRE_THAT( melSpecOutput, Catch::Approx( testWavMelSpec ).margin(0.1) ); diff --git a/tests/use_case/asr/AsrFeaturesTests.cc b/tests/use_case/asr/AsrFeaturesTests.cc index 59fe29b..940c25f 100644 --- a/tests/use_case/asr/AsrFeaturesTests.cc +++ b/tests/use_case/asr/AsrFeaturesTests.cc @@ -16,10 +16,10 @@ */ #include "DataStructures.hpp" #include "AsrGoldenFeatures.hpp" -#include "hal.h" -#include "TensorFlowLiteMicro.hpp" #include "Wav2LetterPreprocess.hpp" +#include "log_macros.h" + #include <catch.hpp> #include <random> diff --git a/tests/use_case/asr/InferenceTestWav2Letter.cc b/tests/use_case/asr/InferenceTestWav2Letter.cc index 3e30bd2..53c92ab 100644 --- a/tests/use_case/asr/InferenceTestWav2Letter.cc +++ b/tests/use_case/asr/InferenceTestWav2Letter.cc @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "hal.h" #include "TensorFlowLiteMicro.hpp" #include "Wav2LetterModel.hpp" #include "TestData_asr.hpp" diff --git a/tests/use_case/asr/MfccTests.cc b/tests/use_case/asr/MfccTests.cc index c70e53e..7568661 100644 --- a/tests/use_case/asr/MfccTests.cc +++ b/tests/use_case/asr/MfccTests.cc @@ -135,15 +135,6 @@ template void TestQuantisedMFCC<int16_t>(); TEST_CASE("MFCC calculation") { - hal_platform platform; - data_acq_module dataAcq; - data_psn_module dataPsn; - platform_timer timer; - - /* Initialise the HAL and platform. */ - hal_init(&platform, &dataAcq, &dataPsn, &timer); - hal_platform_init(&platform); - SECTION("FP32") { auto mfccOutput = GetMFCCInstance().MfccCompute(testWav1); diff --git a/tests/use_case/asr/Wav2LetterPreprocessingTest.cc b/tests/use_case/asr/Wav2LetterPreprocessingTest.cc index 8af9014..457257f 100644 --- a/tests/use_case/asr/Wav2LetterPreprocessingTest.cc +++ b/tests/use_case/asr/Wav2LetterPreprocessingTest.cc @@ -17,7 +17,6 @@ #include "Wav2LetterPreprocess.hpp" #include <limits> -#include <algorithm> #include <catch.hpp> constexpr uint32_t numMfccFeatures = 13; @@ -97,14 +96,6 @@ void PopulateTestWavVector(std::vector<int16_t>& vec) TEST_CASE("Preprocessing calculation INT8") { - /* Initialise the HAL and platform. */ - hal_platform platform; - data_acq_module data_acq; - data_psn_module data_psn; - platform_timer timer; - hal_init(&platform, &data_acq, &data_psn, &timer); - hal_platform_init(&platform); - /* Constants. */ const uint32_t windowLen = 512; const uint32_t windowStride = 160; @@ -135,7 +126,7 @@ TEST_CASE("Preprocessing calculation INT8") REQUIRE(prep.Invoke(testWav.data(), testWav.size(), &tensor)); /* Wrap the tensor with a std::vector for ease. */ - int8_t * tensorData = tflite::GetTensorData<int8_t>(&tensor); + auto* tensorData = tflite::GetTensorData<int8_t>(&tensor); std::vector <int8_t> vecResults = std::vector<int8_t>(tensorData, tensorData + tensor.bytes); diff --git a/tests/use_case/img_class/InferenceTestMobilenetV2.cc b/tests/use_case/img_class/InferenceTestMobilenetV2.cc index 07bd78f..294215f 100644 --- a/tests/use_case/img_class/InferenceTestMobilenetV2.cc +++ b/tests/use_case/img_class/InferenceTestMobilenetV2.cc @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "hal.h" #include "ImageUtils.hpp" #include "MobileNetModel.hpp" #include "TensorFlowLiteMicro.hpp" diff --git a/tests/use_case/kws/InferenceTestMicroNetKws.cc b/tests/use_case/kws/InferenceTestMicroNetKws.cc index e6e7753..41ecc3c 100644 --- a/tests/use_case/kws/InferenceTestMicroNetKws.cc +++ b/tests/use_case/kws/InferenceTestMicroNetKws.cc @@ -15,7 +15,6 @@ * limitations under the License. */ #include "MicroNetKwsModel.hpp" -#include "hal.h" #include "TestData_kws.hpp" #include "TensorFlowLiteMicro.hpp" @@ -92,7 +91,7 @@ TEST_CASE("Running inference with TensorFlow Lite Micro and MicroNetKwsModel int const int8_t* input_goldenFV = get_ifm_data_array(i);; const int8_t* output_goldenFV = get_ofm_data_array(i); - DYNAMIC_SECTION("Executing inference with re-init") + DYNAMIC_SECTION("Executing inference with re-init " << i) { arm::app::MicroNetKwsModel model{}; diff --git a/tests/use_case/kws/MfccTests.cc b/tests/use_case/kws/MfccTests.cc index 1d30ef4..1f5e321 100644 --- a/tests/use_case/kws/MfccTests.cc +++ b/tests/use_case/kws/MfccTests.cc @@ -124,15 +124,6 @@ template void TestQuantisedMFCC<int16_t>(); TEST_CASE("MFCC calculation test") { - hal_platform platform; - data_acq_module dataAcq; - data_psn_module dataPsn; - platform_timer timer; - - /* Initialise the HAL and platform. */ - hal_init(&platform, &dataAcq, &dataPsn, &timer); - hal_platform_init(&platform); - SECTION("FP32") { auto mfccOutput = GetMFCCInstance().MfccCompute(testWav); diff --git a/tests/use_case/kws_asr/InferenceTestMicroNetKws.cc b/tests/use_case/kws_asr/InferenceTestMicroNetKws.cc index fd379b6..a493021 100644 --- a/tests/use_case/kws_asr/InferenceTestMicroNetKws.cc +++ b/tests/use_case/kws_asr/InferenceTestMicroNetKws.cc @@ -15,7 +15,6 @@ * limitations under the License. */ #include "MicroNetKwsModel.hpp" -#include "hal.h" #include "TestData_kws.hpp" #include "TensorFlowLiteMicro.hpp" diff --git a/tests/use_case/kws_asr/InferenceTestWav2Letter.cc b/tests/use_case/kws_asr/InferenceTestWav2Letter.cc index 477a1dd..1c5f20a 100644 --- a/tests/use_case/kws_asr/InferenceTestWav2Letter.cc +++ b/tests/use_case/kws_asr/InferenceTestWav2Letter.cc @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "hal.h" #include "TensorFlowLiteMicro.hpp" #include "Wav2LetterModel.hpp" #include "TestData_asr.hpp" diff --git a/tests/use_case/kws_asr/MfccTests.cc b/tests/use_case/kws_asr/MfccTests.cc index c0fb723..3ebdcf4 100644 --- a/tests/use_case/kws_asr/MfccTests.cc +++ b/tests/use_case/kws_asr/MfccTests.cc @@ -124,15 +124,6 @@ template void TestQuantisedMFCC<int16_t>(); TEST_CASE("MFCC calculation test") { - hal_platform platform; - data_acq_module dataAcq; - data_psn_module dataPsn; - platform_timer timer; - - /* Initialise the HAL and platform. */ - hal_init(&platform, &dataAcq, &dataPsn, &timer); - hal_platform_init(&platform); - SECTION("FP32") { auto mfccOutput = GetMFCCInstance().MfccCompute(testWav); diff --git a/tests/use_case/kws_asr/Wav2LetterPreprocessingTest.cc b/tests/use_case/kws_asr/Wav2LetterPreprocessingTest.cc index 16dbea2..26ddb24 100644 --- a/tests/use_case/kws_asr/Wav2LetterPreprocessingTest.cc +++ b/tests/use_case/kws_asr/Wav2LetterPreprocessingTest.cc @@ -97,13 +97,6 @@ void PopulateTestWavVector(std::vector<int16_t>& vec) TEST_CASE("Preprocessing calculation INT8") { - /* Initialise the HAL and platform. */ - hal_platform platform; - data_acq_module data_acq; - data_psn_module data_psn; - platform_timer timer; - hal_init(&platform, &data_acq, &data_psn, &timer); - hal_platform_init(&platform); /* Constants. */ const uint32_t windowLen = 512; diff --git a/tests/use_case/noise_reduction/InferenceTestRNNoise.cc b/tests/use_case/noise_reduction/InferenceTestRNNoise.cc index f32a460..4c9786f 100644 --- a/tests/use_case/noise_reduction/InferenceTestRNNoise.cc +++ b/tests/use_case/noise_reduction/InferenceTestRNNoise.cc @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "hal.h" #include "TensorFlowLiteMicro.hpp" #include "RNNoiseModel.hpp" #include "TestData_noise_reduction.hpp" diff --git a/tests/use_case/noise_reduction/RNNoiseModelTests.cc b/tests/use_case/noise_reduction/RNNoiseModelTests.cc index 705c41a..7798975 100644 --- a/tests/use_case/noise_reduction/RNNoiseModelTests.cc +++ b/tests/use_case/noise_reduction/RNNoiseModelTests.cc @@ -15,7 +15,6 @@ * limitations under the License. */ #include "RNNoiseModel.hpp" -#include "hal.h" #include "TensorFlowLiteMicro.hpp" #include "TestData_noise_reduction.hpp" diff --git a/tests/use_case/object_detection/InferenceTestYoloFastest.cc b/tests/use_case/object_detection/InferenceTestYoloFastest.cc index e5a5efe..d9cabbd 100644 --- a/tests/use_case/object_detection/InferenceTestYoloFastest.cc +++ b/tests/use_case/object_detection/InferenceTestYoloFastest.cc @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "hal.h" +#include "log_macros.h" #include "ImageUtils.hpp" #include "YoloFastestModel.hpp" #include "TensorFlowLiteMicro.hpp" diff --git a/tests/use_case/vww/InferenceVisualWakeWordModelTests.cc b/tests/use_case/vww/InferenceVisualWakeWordModelTests.cc index 82fea9f..04dce0d 100644 --- a/tests/use_case/vww/InferenceVisualWakeWordModelTests.cc +++ b/tests/use_case/vww/InferenceVisualWakeWordModelTests.cc @@ -15,7 +15,6 @@ * limitations under the License. */ -#include "hal.h" #include "ImageUtils.hpp" #include "TestData_vww.hpp" #include "VisualWakeWordModel.hpp" |