diff --git a/tensorflow/lite/micro/cortex_m_corstone_300/README.md b/tensorflow/lite/micro/cortex_m_corstone_300/README.md index d7b9e77d2ac..f5ad46929b3 100644 --- a/tensorflow/lite/micro/cortex_m_corstone_300/README.md +++ b/tensorflow/lite/micro/cortex_m_corstone_300/README.md @@ -1,24 +1,25 @@ + # Running a fixed virtual platform based on Corstone-300 software -This target makes use of a fixed virtual platform (FVP) based on Arm Cortex-300 based software. -More info about Arm Corstone-300 software: https://developer.arm.com/ip-products/subsystem/corstone/corstone-300 -More info about FVPs: https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms +This target makes use of a fixed virtual platform (FVP) based on Arm Cortex-300 based software. More info about Arm Corstone-300 software: https://developer.arm.com/ip-products/subsystem/corstone/corstone-300. More info about FVPs: https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms. To fullfill the needed requirements it is depending the following projects: -* Arm Ethos-U Core Platform: https://review.mlplatform.org/admin/repos/ml/ethos-u/ethos-u-core-platform -* CMSIS: https://github.com/ARM-software/CMSIS_5 + + - Arm Ethos-U Core Platform: https://review.mlplatform.org/admin/repos/ml/ethos-u/ethos-u-core-platform. + - Arm Ethos-U Core Platform provides the linker file as well as UART and retarget functions. + - CMSIS: https://github.com/ARM-software/CMSIS_5. + - CMSIS provides startup functionality, e.g. for setting up interrupt handlers and clock speed. # General build info -This target is based on the cortex_m_generic target and except that for now the only supported toolchain is GCC, the same general build info applies: tensorflow/lite/micro/cortex_m_generic/README.md +This target is based on the cortex_m_generic target and except that for now the only supported toolchain is GCC, the same general build info applies: tensorflow/lite/micro/cortex_m_generic/README.md. Required parameters: - TARGET: cortex_m_corstone_300 - TARGET_ARCH: cortex-mXX (For all options see: tensorflow/lite/micro/tools/make/targets/cortex_m_corstone_300_makefile.inc) - # How to run Note that Corstone-300 is targetted for Cortex-M55 but it is backwards compatible. This means one could potentially run it for example with a Cortex-M7. diff --git a/tensorflow/lite/micro/cortex_m_corstone_300/system_setup.cc b/tensorflow/lite/micro/cortex_m_corstone_300/system_setup.cc new file mode 100644 index 00000000000..cc8cbebad29 --- /dev/null +++ b/tensorflow/lite/micro/cortex_m_corstone_300/system_setup.cc @@ -0,0 +1,26 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +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. +==============================================================================*/ + +#include "tensorflow/lite/micro/system_setup.h" + +namespace system_setup { + +extern "C" { +void uart_init(void); +} + +void Initialize() {uart_init();} + +}; // namespace system_setup diff --git a/tensorflow/lite/micro/system_setup.cc b/tensorflow/lite/micro/system_setup.cc new file mode 100644 index 00000000000..2aeac627d97 --- /dev/null +++ b/tensorflow/lite/micro/system_setup.cc @@ -0,0 +1,26 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +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. +==============================================================================*/ + +#include "tensorflow/lite/micro/system_setup.h" + +namespace system_setup { + +// To add an equivalent function for your own platform, create your own +// implementation file, and place it in a subfolder named after the OS +// you're targeting. See tensorflow/lite/micro/debug_log.cc for a similar +// example. +void Initialize() {} + +} // namespace system_setup diff --git a/tensorflow/lite/micro/system_setup.h b/tensorflow/lite/micro/system_setup.h new file mode 100644 index 00000000000..a408d3f4d63 --- /dev/null +++ b/tensorflow/lite/micro/system_setup.h @@ -0,0 +1,31 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +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. +==============================================================================*/ + +// This is part of the ultra-lightweight testing framework designed for use with +// microcontroller applications. See tensorflow/lite/micro/testing/micro_test.h. + +#ifndef TENSORFLOW_LITE_MICRO_TESTING_SYSTEM_SETUP_H_ +#define TENSORFLOW_LITE_MICRO_TESTING_SYSTEM_SETUP_H_ + +namespace system_setup { + +// This is called during initialization of testing framework. It can be +// implemented by each target platform. For more information, see +// tensorflow/lite/micro/system_setup.cc. +void Initialize(); + +} // namespace system_setup + +#endif // TENSORFLOW_LITE_MICRO_TESTING_SYSTEM_SETUP_H_ diff --git a/tensorflow/lite/micro/testing/micro_test.h b/tensorflow/lite/micro/testing/micro_test.h index eaf3181bcd7..ad399169780 100644 --- a/tensorflow/lite/micro/testing/micro_test.h +++ b/tensorflow/lite/micro/testing/micro_test.h @@ -56,6 +56,7 @@ limitations under the License. #include "tensorflow/lite/c/common.h" #include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/system_setup.h" namespace micro_test { extern int tests_passed; @@ -63,21 +64,8 @@ extern int tests_failed; extern bool is_test_complete; extern bool did_test_fail; extern tflite::ErrorReporter* reporter; - -#if defined(CORTEX_M_CORSTONE_300) -extern "C" { -void uart_init(void); -} -#endif - } // namespace micro_test -#if defined(CORTEX_M_CORSTONE_300) -#define TF_LITE_MICRO_INIT_UART_FOR_CORSTONE_300 micro_test::uart_init(); -#else -#define TF_LITE_MICRO_INIT_UART_FOR_CORSTONE_300 -#endif - #define TF_LITE_MICRO_TESTS_BEGIN \ namespace micro_test { \ int tests_passed; \ @@ -92,7 +80,7 @@ void uart_init(void); micro_test::tests_failed = 0; \ tflite::MicroErrorReporter error_reporter; \ micro_test::reporter = &error_reporter; \ - TF_LITE_MICRO_INIT_UART_FOR_CORSTONE_300 + system_setup::Initialize(); #define TF_LITE_MICRO_TESTS_END \ micro_test::reporter->Report( \ diff --git a/tensorflow/lite/micro/testing/test_with_arm_corstone_300.sh b/tensorflow/lite/micro/testing/test_with_arm_corstone_300.sh index 3fba0c3f615..c5293e56b83 100755 --- a/tensorflow/lite/micro/testing/test_with_arm_corstone_300.sh +++ b/tensorflow/lite/micro/testing/test_with_arm_corstone_300.sh @@ -31,7 +31,7 @@ MICRO_LOG_FILENAME=${RESULTS_DIRECTORY}/logs.txt mkdir -p ${RESULTS_DIRECTORY} FVP="FVP_Corstone_SSE-300_Ethos-U55 " -FVP+="--cpulimit 2 " +FVP+="--cpulimit 1 " FVP+="-C mps3_board.visualisation.disable-visualisation=1 " FVP+="-C mps3_board.telnetterminal0.start_telnet=0 " FVP+='-C mps3_board.uart0.out_file="-" ' diff --git a/tensorflow/lite/micro/tools/ci_build/test_all.sh b/tensorflow/lite/micro/tools/ci_build/test_all.sh index 967a9dd9660..eee224282c1 100755 --- a/tensorflow/lite/micro/tools/ci_build/test_all.sh +++ b/tensorflow/lite/micro/tools/ci_build/test_all.sh @@ -80,7 +80,4 @@ tensorflow/lite/micro/tools/ci_build/test_arduino.sh echo "Running cortex_m_generic tests at `date`" tensorflow/lite/micro/tools/ci_build/test_cortex_m_generic.sh -echo "Running cortex_m_corstone_300 tests at `date`" -tensorflow/lite/micro/tools/ci_build/test_cortex_m_corstone_300.sh - echo "Finished all micro tests at `date`" diff --git a/tensorflow/lite/micro/tools/make/ethos_u_core_platform_download.sh b/tensorflow/lite/micro/tools/make/ethos_u_core_platform_download.sh index f15c9d81cef..d00800af28a 100755 --- a/tensorflow/lite/micro/tools/make/ethos_u_core_platform_download.sh +++ b/tensorflow/lite/micro/tools/make/ethos_u_core_platform_download.sh @@ -63,6 +63,18 @@ else mkdir ${DOWNLOADED_ETHOS_U_CORE_PLATFORM_PATH} tar xzf ${TEMPFILE} --strip-components=1 -C ${DOWNLOADED_ETHOS_U_CORE_PLATFORM_PATH} >&2 + + # Run C preprocessor on linker file to get rid of ifdefs and make sure compiler is downloaded first. + COMPILER=${DOWNLOADS_DIR}/gcc_embedded/bin/arm-none-eabi-gcc + if [ ! -f ${COMPILER} ]; then + RETURN_VALUE=`./tensorflow/lite/micro/tools/make/arm_gcc_download.sh ${DOWNLOADS_DIR}` + if [ "SUCCESS" != "${RETURN_VALUE}" ]; then + echo "The script ./tensorflow/lite/micro/tools/make/arm_gcc_download.sh failed." + exit 1 + fi + fi + LINKER_PATH=${DOWNLOADED_ETHOS_U_CORE_PLATFORM_PATH}/targets/corstone-300 + ${COMPILER} -E -x c -P -o ${LINKER_PATH}/platform_parsed.ld ${LINKER_PATH}/platform.ld fi echo "SUCCESS" diff --git a/tensorflow/lite/micro/tools/make/targets/cortex_m_corstone_300_makefile.inc b/tensorflow/lite/micro/tools/make/targets/cortex_m_corstone_300_makefile.inc index 7d1a8eccc88..48dcd1719bb 100644 --- a/tensorflow/lite/micro/tools/make/targets/cortex_m_corstone_300_makefile.inc +++ b/tensorflow/lite/micro/tools/make/targets/cortex_m_corstone_300_makefile.inc @@ -93,15 +93,6 @@ ifeq ($(TOOLCHAIN), gcc) CXXFLAGS += $(FLAGS_GCC) CCFLAGS += $(FLAGS_GCC) - # Run C preprocessor on linker file to get rid of ifdefs. - ifeq (,$(wildcard $(ETHOS_U_CORE_PLATFORM)/platform_parsed.ld)) - RESULT := $(shell arm-none-eabi-gcc -E -x c -P -o $(ETHOS_U_CORE_PLATFORM)/platform_parsed.ld \ - $(ETHOS_U_CORE_PLATFORM)/platform.ld) - ifneq ($(RESULT),) - $(error Something went wrong when parsing linker file: $(RESULT)) - endif - endif - LDFLAGS += \ --specs=nosys.specs \ -T $(ETHOS_U_CORE_PLATFORM)/platform_parsed.ld \ @@ -141,9 +132,9 @@ CCFLAGS += -D$(ARM_CPU)$(CMSIS_ARM_FEATURES) THIRD_PARTY_CC_SRCS += \ $(wildcard $(ETHOS_U_CORE_PLATFORM)/*.c) -EXCLUDED_SRCS := \ - $(ETHOS_U_CORE_PLATFORM)/main.c -THIRD_PARTY_CC_SRCS := $(filter-out $(EXCLUDED_SRCS), $(THIRD_PARTY_CC_SRCS)) +THIRD_PARTY_CC_SRCS += \ + $(ETHOS_U_CORE_PLATFORM)/retarget.c \ + $(ETHOS_U_CORE_PLATFORM)/uart.c CMSIS_DEFAULT_DOWNLOAD_PATH := $(MAKEFILE_DIR)/downloads/cmsis CMSIS_PATH := $(CMSIS_DEFAULT_DOWNLOAD_PATH)