From 12bb41bbd38dc2b12098e5850674ed6c966de9c5 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Thu, 30 Sep 2021 20:46:53 +0200 Subject: [PATCH] [cmsis] Update CMSIS-DSP to v5.8.0 Introduces config file. --- .../nucleo_f429zi/cmsis_dsp/bayes/main.cpp | 22 +++ .../nucleo_f429zi/cmsis_dsp/bayes/project.xml | 10 ++ .../cmsis_dsp/linear_interp/main.cpp | 1 - .../cmsis_dsp/linear_interp/project.xml | 5 +- examples/nucleo_f429zi/cmsis_dsp/svm/main.cpp | 22 +++ .../nucleo_f429zi/cmsis_dsp/svm/project.xml | 10 ++ ext/arm/arm_math.h.in | 48 +++++++ ext/arm/arm_math_f16.h.in | 51 +++++++ ext/arm/arm_math_types.h.in | 30 ++++ ext/arm/cmsis | 2 +- ext/arm/dsp.lb | 130 ++++++++---------- ext/arm/dsp.md | 23 ++++ 12 files changed, 276 insertions(+), 78 deletions(-) create mode 100644 examples/nucleo_f429zi/cmsis_dsp/bayes/main.cpp create mode 100644 examples/nucleo_f429zi/cmsis_dsp/bayes/project.xml create mode 100644 examples/nucleo_f429zi/cmsis_dsp/svm/main.cpp create mode 100644 examples/nucleo_f429zi/cmsis_dsp/svm/project.xml create mode 100644 ext/arm/arm_math.h.in create mode 100644 ext/arm/arm_math_f16.h.in create mode 100644 ext/arm/arm_math_types.h.in diff --git a/examples/nucleo_f429zi/cmsis_dsp/bayes/main.cpp b/examples/nucleo_f429zi/cmsis_dsp/bayes/main.cpp new file mode 100644 index 0000000000..7f3def2325 --- /dev/null +++ b/examples/nucleo_f429zi/cmsis_dsp/bayes/main.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2019, Niklas Hauser + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +#include +#include + +#define main arm_cmsis_dsp_example +#define while return index; void +#include "../../../../ext/arm/cmsis/CMSIS/DSP/Examples/ARM/arm_bayes_example/arm_bayes_example_f32.c" +#undef while +#undef main + +#define example_name "bayes" +#include "../runner.cpp" diff --git a/examples/nucleo_f429zi/cmsis_dsp/bayes/project.xml b/examples/nucleo_f429zi/cmsis_dsp/bayes/project.xml new file mode 100644 index 0000000000..998cc284f6 --- /dev/null +++ b/examples/nucleo_f429zi/cmsis_dsp/bayes/project.xml @@ -0,0 +1,10 @@ + + modm:nucleo-f429zi + + + + + modm:build:scons + modm:cmsis:dsp:bayes + + diff --git a/examples/nucleo_f429zi/cmsis_dsp/linear_interp/main.cpp b/examples/nucleo_f429zi/cmsis_dsp/linear_interp/main.cpp index ce22a0931e..0e68654622 100644 --- a/examples/nucleo_f429zi/cmsis_dsp/linear_interp/main.cpp +++ b/examples/nucleo_f429zi/cmsis_dsp/linear_interp/main.cpp @@ -21,7 +21,6 @@ #define while return status; void #include "../../../../ext/arm/cmsis/CMSIS/DSP/Examples/ARM/arm_linear_interp_example/arm_linear_interp_example_f32.c" #undef while -#undef float #undef main #pragma GCC diagnostic pop diff --git a/examples/nucleo_f429zi/cmsis_dsp/linear_interp/project.xml b/examples/nucleo_f429zi/cmsis_dsp/linear_interp/project.xml index 8260089534..4a0c8fbe2f 100644 --- a/examples/nucleo_f429zi/cmsis_dsp/linear_interp/project.xml +++ b/examples/nucleo_f429zi/cmsis_dsp/linear_interp/project.xml @@ -3,13 +3,10 @@ - - - -fpermissive - modm:build:scons modm:build:make modm:cmsis:dsp:fast_math + modm:cmsis:dsp:interpolation diff --git a/examples/nucleo_f429zi/cmsis_dsp/svm/main.cpp b/examples/nucleo_f429zi/cmsis_dsp/svm/main.cpp new file mode 100644 index 0000000000..6c752d16d0 --- /dev/null +++ b/examples/nucleo_f429zi/cmsis_dsp/svm/main.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2019, Niklas Hauser + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +#include +#include + +#define main arm_cmsis_dsp_example +#define while return result; void +#include "../../../../ext/arm/cmsis/CMSIS/DSP/Examples/ARM/arm_svm_example/arm_svm_example_f32.c" +#undef while +#undef main + +#define example_name "svm" +#include "../runner.cpp" diff --git a/examples/nucleo_f429zi/cmsis_dsp/svm/project.xml b/examples/nucleo_f429zi/cmsis_dsp/svm/project.xml new file mode 100644 index 0000000000..38b0a20647 --- /dev/null +++ b/examples/nucleo_f429zi/cmsis_dsp/svm/project.xml @@ -0,0 +1,10 @@ + + modm:nucleo-f429zi + + + + + modm:build:scons + modm:cmsis:dsp:svm + + diff --git a/ext/arm/arm_math.h.in b/ext/arm/arm_math.h.in new file mode 100644 index 0000000000..704f49d023 --- /dev/null +++ b/ext/arm/arm_math.h.in @@ -0,0 +1,48 @@ +/****************************************************************************** + * @file arm_math.h + * @brief Public header file for CMSIS DSP Library + * @version V1.9.0 + * @date 23 April 2021 + * Target Processor: Cortex-M and Cortex-A cores + ******************************************************************************/ +/* + * Copyright (c) 2010-2021 Arm Limited or its affiliates. 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 + * + * 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 _ARM_MATH_H +#define _ARM_MATH_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "arm_math_types.h" +#include "arm_math_memory.h" + +#include "dsp/none.h" +#include "dsp/utils.h" + +%% for include in includes | sort +#include "dsp/{{include}}_functions.h" +%% endfor + +#ifdef __cplusplus +} +#endif + +#endif /* _ARM_MATH_H */ diff --git a/ext/arm/arm_math_f16.h.in b/ext/arm/arm_math_f16.h.in new file mode 100644 index 0000000000..2e2118ee90 --- /dev/null +++ b/ext/arm/arm_math_f16.h.in @@ -0,0 +1,51 @@ +/****************************************************************************** + * @file arm_math_f16.h + * @brief Public header file for f16 function of the CMSIS DSP Library + * @version V1.9.0 + * @date 23 April 2021 + * Target Processor: Cortex-M and Cortex-A cores + ******************************************************************************/ +/* + * Copyright (c) 2010-2021 Arm Limited or its affiliates. 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 + * + * 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 _ARM_MATH_F16_H +#define _ARM_MATH_F16_H + +#include "arm_math.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "arm_math_types_f16.h" + +#include "dsp/none.h" +#include "dsp/utils.h" + +%% for include in includes | sort +#include "dsp/{{include}}_functions_f16.h" +%% endfor + +#ifdef __cplusplus +} +#endif + +#endif /* _ARM_MATH_F16_H */ + + diff --git a/ext/arm/arm_math_types.h.in b/ext/arm/arm_math_types.h.in new file mode 100644 index 0000000000..7a00b8b4a9 --- /dev/null +++ b/ext/arm/arm_math_types.h.in @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021, Niklas Hauser + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _ARM_MATH_TYPES_WRAPPER_H_ +#define _ARM_MATH_TYPES_WRAPPER_H_ + +#define ARM_MATH_CM{{core}} +#define __ARM_FEATURE_MVE 0 + +%% if with_fpu +#ifndef __FPU_PRESENT +#define __FPU_PRESENT 1 +#endif +%% endif + +/* Local configuration file */ +#if __has_include() +# include +#endif + +#include "arm_math_types_internal.h" + +#endif /* ifndef _ARM_MATH_TYPES_WRAPPER_H_ */ diff --git a/ext/arm/cmsis b/ext/arm/cmsis index 177c5e4652..aa99c5bc64 160000 --- a/ext/arm/cmsis +++ b/ext/arm/cmsis @@ -1 +1 @@ -Subproject commit 177c5e4652780c1db686cf6c054692d850cb33e9 +Subproject commit aa99c5bc640b471d7391e8153ddf05de2e80fcc1 diff --git a/ext/arm/dsp.lb b/ext/arm/dsp.lb index 70b629b99d..bccc800d96 100644 --- a/ext/arm/dsp.lb +++ b/ext/arm/dsp.lb @@ -14,6 +14,8 @@ from collections import defaultdict from pathlib import Path +includes = [] + class CmsisDspModule(Module): def __init__(self, path): @@ -32,15 +34,18 @@ class CmsisDspModule(Module): "bayes": [":cmsis:dsp:statistics"], "complex_math": [":cmsis:dsp:fast_math"], "controller": [":cmsis:dsp:tables"], - "distance": [":cmsis:dsp:basic_math", ":cmsis:dsp:statistics"], + "distance": [":cmsis:dsp:statistics", ":cmsis:dsp:basic_math", + ":cmsis:dsp:fast_math", ":cmsis:dsp:tables"], "fast_math": [":cmsis:dsp:tables"], - "filtering": [":cmsis:dsp:tables", ":cmsis:dsp:support"], + "filtering": [":cmsis:dsp:fast_math", ":cmsis:dsp:tables", ":cmsis:dsp:support"], + "interpolation": [], "matrix": [], - "statistics": [":cmsis:dsp:fast_math"], + "quaternion_math": [], + "statistics": [":cmsis:dsp:basic_math", ":cmsis:dsp:fast_math"], "support": [], "svm": [], - "tables": [], - "transform": [":cmsis:dsp:tables"], + "tables": [":cmsis:dsp:transform"], + "transform": [":cmsis:dsp:basic_math", ":cmsis:dsp:complex_math", ":cmsis:dsp:tables"], } module.depends(*dependencies[self.name]) return True @@ -51,34 +56,29 @@ class CmsisDspModule(Module): metadata[":build:ccflags"].append("-Wno-sign-compare") metadata[":build:ccflags"].append("-Wno-double-promotion") - core = env[":target"].get_driver("core")["type"] - if "f" in core: - metadata[":build:cppdefines"].append("__FPU_PRESENT=1") - - if env[":cmsis:dsp:check_matrix_sizes"]: - metadata[":build:cppdefines"].append("ARM_MATH_MATRIX_CHECK") - else: - metadata[":build:cppdefines.debug"].append("ARM_MATH_MATRIX_CHECK") - - if env[":cmsis:dsp:round_float_inputs"]: - metadata[":build:cppdefines"].append("ARM_MATH_ROUNDING") - - if not env.get(":cmsis:dsp:unaligned_data", False): - metadata[":build:cppdefines"].append("UNALIGNED_SUPPORT_DISABLE") - - if env.get(":cmsis:dsp:loop_unroll", False): - metadata[":build:cppdefines"].append("ARM_MATH_LOOPUNROLL") - + operations = set() env.outbasepath = "modm/ext/cmsis/dsp" - - if "tables" in self.name: - env.copy("cmsis/CMSIS/DSP/Include/arm_common_tables.h", "arm_common_tables.h") - env.copy("cmsis/CMSIS/DSP/Include/arm_const_structs.h", "arm_const_structs.h") if "support" in self.name: env.copy("cmsis/CMSIS/DSP/PrivateInclude/arm_sorting.h", "arm_sorting.h") - - operations = env.copy("cmsis/CMSIS/DSP/Source/{}".format(self.path), "{}".format(self.path), - ignore=env.ignore_files("arm_bitreversal2.c")) + if "transform" in self.name: + env.copy("cmsis/CMSIS/DSP/PrivateInclude/arm_vec_fft.h", "arm_vec_fft.h") + if "filtering" in self.name: + env.copy("cmsis/CMSIS/DSP/PrivateInclude/arm_vec_filtering.h", "arm_vec_filtering.h") + if "svm" in self.name: + env.copy("cmsis/CMSIS/DSP/Include/dsp/svm_defines.h", "dsp/svm_defines.h") + + if "tables" not in self.name: + global includes + includes.append(self.name) + operations |= env.copy("cmsis/CMSIS/DSP/Include/dsp/{}_functions.h".format(self.name), + "dsp/{}_functions.h".format(self.name)) + if env[":cmsis:dsp:with_f16"]: + operations |= env.copy("cmsis/CMSIS/DSP/Include/dsp/{}_functions_f16.h".format(self.name), + "dsp/{}_functions_f16.h".format(self.name)) + + operations |= env.copy("cmsis/CMSIS/DSP/Source/{}".format(self.path), self.path, + ignore=env.ignore_files("arm_bitreversal2.c", + "" if env[":cmsis:dsp:with_f16"] else "*_f16*")) # For all sources add these compile flags for key, values in metadata.items(): @@ -95,27 +95,11 @@ def prepare(module, options): if not device.has_driver("core:cortex-m*"): return False - if not device.has_driver("core:cortex-m0*"): - module.add_option( - BooleanOption( - name="unaligned_data", - description=descr_unaligned_data, - default=False)) module.add_option( BooleanOption( - name="check_matrix_sizes", - description=descr_matrix_sizes, + name="with_f16", + description=descr_f16, default=False)) - module.add_option( - BooleanOption( - name="round_float_inputs", - description=descr_round_floats, - default=True)) - module.add_option( - BooleanOption( - name="loop_unroll", - description=descr_loop_unroll, - default=True)) for path in Path(localpath("cmsis/CMSIS/DSP/Source")).iterdir(): if path.is_dir(): @@ -124,34 +108,36 @@ def prepare(module, options): return True def build(env): - core = env[":target"].get_driver("core")["type"] - core = core.replace("cortex-m", "CM").replace("+", "PLUS").replace("f", "").replace("d", "") - env.collect(":build:cppdefines", "ARM_MATH_{}".format(core)) - env.collect(":build:path.include", "modm/ext/cmsis/dsp") - + env.collect(":build:path.include", "modm/ext/cmsis/dsp/") env.outbasepath = "modm/ext/cmsis/dsp" - env.copy("cmsis/CMSIS/DSP/Include/arm_math.h", "arm_math.h") - -# ============================ Option Descriptions ============================ -descr_unaligned_data = """# Allow unaligned data storage - -If the core supports it, this options enables storing data in unaligned memory. -This may reduce data size, but cost some speed. -""" + for path in Path(localpath("cmsis/CMSIS/DSP/Include/")).iterdir(): + if path.is_file() and not ("_f16" in path.name and not env["with_f16"]): + # We need to replace this file to include the + if path.name in ["arm_math_types.h", "arm_math.h", "arm_math_f16.h"]: continue; + env.copy(path, path.name) + + env.copy("cmsis/CMSIS/DSP/Include/dsp/none.h", "dsp/none.h") + env.copy("cmsis/CMSIS/DSP/Include/dsp/utils.h", "dsp/utils.h") + env.copy("cmsis/CMSIS/DSP/Include/arm_math_types.h", "arm_math_types_internal.h") + + core = env[":target"].get_driver("core")["type"][8:] + core = core.replace("+", "PLUS").replace("f", "").replace("d", "") + global includes + env.substitutions = { + "core": core, + "includes": includes, + "with_fpu": env.get(":platform:cortex-m:float-abi", "soft") != "soft", + } + env.template("arm_math_types.h.in") + env.template("arm_math.h.in") + if env["with_f16"]: env.template("arm_math_f16.h.in") -descr_matrix_sizes = """# Check input/output matrix size -Check the input and output sizes of matrices and return -`ARM_MATH_SIZE_MISMATCH` on failure. -""" - -descr_round_floats = """# Round float inputs +# ============================ Option Descriptions ============================ +descr_f16 = """# Include f16 format functions -Rounds float inputs properly during all conversions. +16-bit floating point is only used for storage, since the Cortex-M FPU does not +support the format in hardware. """ -descr_loop_unroll = """# Loop Unroll - -Enables manual loop unrolling in DSP functions. -""" diff --git a/ext/arm/dsp.md b/ext/arm/dsp.md index cd6817197e..b1304393fb 100644 --- a/ext/arm/dsp.md +++ b/ext/arm/dsp.md @@ -3,4 +3,27 @@ This module provides the CMSIS-DSP library. Please [see the API documentation][docs] for details. +Note that this module splits up the library into submodule to speed up +compilation by only including the math functions you really need. +You can enable 16-bit floating point support separately via option. + + +## Configuration + +You can define your own configuration in the `` file which +will automatically be included at the *beginning* of the `arm_math_types.h` file +which is included by all CMSIS-DSP source files. This way changes to your +CMSIS-DSP configuration will only affect its source files and not recompile your +whole project. + +Example `` configuration: + +```c +// Check the input and output sizes of matrices +#define ARM_MATH_MATRIX_CHECK 1 +// enable manual loop unrolling in DSP functions +#define ARM_MATH_LOOPUNROLL 1 +``` + + [docs]: http://arm-software.github.io/CMSIS_5/DSP/html/modules.html