Skip to content

Commit

Permalink
Add CMSIS-DSP
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Gloor <code@stefan-gloor.ch>
  • Loading branch information
stgloorious committed Jun 9, 2024
1 parent 89fb273 commit 03d84da
Show file tree
Hide file tree
Showing 6 changed files with 69,109 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
[submodule "third_party/CMSIS-NN"]
path = third_party/CMSIS-NN
url = https://github.com/ARM-software/CMSIS-NN.git
[submodule "third_party/CMSIS-DSP"]
path = third_party/CMSIS-DSP
url = https://github.com/ARM-software/CMSIS-DSP.git
[submodule "third_party/CMSIS_5"]
path = third_party/CMSIS_5
url = https://github.com/ARM-software/CMSIS_5.git
32 changes: 30 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ include_directories(${CMAKE_SOURCE_DIR}/third_party/libcrc/include)

# CMSIS includes
include_directories(${CMAKE_SOURCE_DIR}/third_party/CMSIS_NN)
include_directories(${CMAKE_SOURCE_DIR}/third_party/CMSIS-DSP/Include)
include_directories(${CMAKE_SOURCE_DIR}/third_party/CMSIS_5/CMSIS/Core/Include)

# Link
FILE(GLOB linker_script ld/*.ld)
Expand All @@ -90,7 +92,9 @@ add_library(hal STATIC ${hal_srcs})

# CMSIS-NN
set(LIBCMSISNN_PATH ${CMAKE_BINARY_DIR}/cmsis-nn-prefix/src/cmsis-nn-build/libcmsis-nn.a)
set(LIBCMSISNN_CXXFLAGS "-mthumb -mcpu=${CMAKE_SYSTEM_PROCESSOR} -mfpu=fpv4-sp-d16 -mfloat-abi=hard -nostdlib")
set(LIBCMSISNN_CXXFLAGS "-mthumb -mcpu=${CMAKE_SYSTEM_PROCESSOR} \
-mfpu=fpv4-sp-d16 -mfloat-abi=hard -nostdlib -s \
-ffunction-sections -s -Wl,gc-sections")

ExternalProject_Add(cmsis-nn
SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/CMSIS-NN
Expand All @@ -106,6 +110,30 @@ ExternalProject_Add(cmsis-nn
add_library(cmsisnn SHARED IMPORTED)
set_target_properties(cmsisnn PROPERTIES IMPORTED_LOCATION ${LIBCMSISNN_PATH})

# CMSIS-DSP
set(LIBCMSISDSP_PATH
${CMAKE_BINARY_DIR}/cmsis-dsp-prefix/src/cmsis-dsp-build/libCMSISDSP.a)
set(LIBCMSISDSP_CXXFLAGS "-mthumb -mcpu=${CMAKE_SYSTEM_PROCESSOR} \
-mfpu=fpv4-sp-d16 -mfloat-abi=hard -nostdlib \
-iquote ${CMAKE_SOURCE_DIR}/third_party/CMSIS_5/CMSIS/Core/Include \
-ffunction-sections -fdata-sections -s \
")

ExternalProject_Add(cmsis-dsp
SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/CMSIS-DSP/Source
PATCH_COMMAND git restore . && git apply ${CMAKE_SOURCE_DIR}/third_party/patches/cmsis-dsp-remove-tables.patch
INSTALL_COMMAND ""
CMAKE_ARGS
-DCMAKE_CXX_FLAGS=${LIBCMSISDSP_CXXFLAGS}
-DCMAKE_C_FLAGS=${LIBCMSISDSP_CXXFLAGS}
-DCMAKE_STATIC_LINKER_FLAGS=
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
)
add_library(cmsisdsp SHARED IMPORTED)
set_target_properties(cmsisdsp PROPERTIES IMPORTED_LOCATION ${LIBCMSISDSP_PATH})
add_dependencies(cmsisdsp cmsis-dsp)

# Project sources
FILE(GLOB demo_srcs src/*.c
src/*.cc
Expand Down Expand Up @@ -162,7 +190,7 @@ add_library(crc32 STATIC ${CMAKE_SOURCE_DIR}/third_party/libcrc/src/crc32.c)
add_dependencies(crc32 gentab32)

add_executable(demo.elf ${demo_srcs})
target_link_libraries(demo.elf hal tflm crc32 cmsisnn)
target_link_libraries(demo.elf hal tflm crc32 cmsisnn cmsisdsp)

# st-util wants a binary-only format, not an ELF
add_custom_target(bin ALL DEPENDS demo.elf
Expand Down
14 changes: 14 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ limitations under the License.
#include <tensorflow/lite/micro/system_setup.h>
#include <tensorflow/lite/schema/schema_generated.h>

#include <dsp/transform_functions.h>
#include <dsp/window_functions.h>
#include <dsp/fast_math_functions.h>
#include <math.h>

#include <serial.h>

#include "mic.h"
Expand Down Expand Up @@ -126,6 +131,15 @@ int main(int argc, char *argv[])
microphone.dump_recording();
*/

arm_rfft_instance_q15 fft;
if (arm_rfft_init_256_q15(&fft, 0, 0) != ARM_MATH_SUCCESS){
assert(!"Failed to perform RFFT");
}

float* hanning = NULL;
uint32_t window_size = 255;
arm_hanning_f32(hanning, window_size);

const tflite::Model *model = tflite::GetModel(model_tflite);
DEBUG_PRINTF("Model architecture:\n");
DEBUG_PRINTF("==============================================\n");
Expand Down
1 change: 1 addition & 0 deletions third_party/CMSIS-DSP
Submodule CMSIS-DSP added at 03fa0e
1 change: 1 addition & 0 deletions third_party/CMSIS_5
Submodule CMSIS_5 added at 51f8f8
Loading

0 comments on commit 03d84da

Please sign in to comment.