From bd13385c823b6777d7f3c0a90c488a345409175c Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Fri, 18 Oct 2024 18:07:37 -0400 Subject: [PATCH] CMake Improvements (#615) * Fix builds on native Windows Previously, builds would fail with a message stating that there's no such command "true". CMAKE_C[XX]_ARCHIVE_FINISH is not a boolean option, but instead should be a string for how to run ranlib. This simply sets that to the default, but it could instead be removed in the future now that GCC binutils has lto automatically loading. * Add CMake toolchain file for LLVMEmbeddedToolchainForArm * Update linker arguments of both base and GCC-specific toolchain setups This removes the arguments that LLD cannot receive from the base default_build file, and moves them to the GCC-specific toolchain setup. This reformats all linker arguments to allow for CMake to auto-format them depending on the toolchain (clang uses -Xlinker instead of -Wl). * Remove illegal constexpr definitions constexpr cannot take the result of a cast that is equivalent to a reinterpret_cast, as defined by the C++ standard. GCC may allow it, but it's technically illegal and clang errors. * Remove attribute naked Naked is not allowed for functions that contain bodies other than asm functions. Per the GCC docs: "The only statements that can be safely included in naked functions are asm statements that do not have operands. All other statements, including declarations of local variables, if statements, and so forth, should be avoided." GCC silently allows this, but Clang notes this as a hard failure. Instead, the Default_Handler is marked as a generic interrupt, and the Reset_Handler is unmarked due to acting as the executable entrypoint. * Add DAISY_STORAGE configure option This allows for configure-time selection of the linker script used by CMake, either at the command like with -DDAISY_STORAGE=qspi or in libraries that use libDaisy (by defining DAISY_STORAGE before inclusion). * Remove unused variable Squashes 7+ warnings of this due to inclusion by other files. * Splits the monolithic CMakeLists.txt file into a semi-proper structure This separates the massive root CMakeLists.txt file into libraries and places the respective configuration files closer to their source. * Split toolchain into architecture and GNU This ensures that we have architecture-specific configurations in a dedicated file while the LLVM and GNU toolchain files deal with their respective compilers only * Remove unnecessary comparison config_ is never nullptr as it is initialized with the instantiation of a SaiHandle::Impl This allows -Werror to work on GCC. * Fix complications of rebase * Update linkerscripts * Add DaisyProject cmake file and use for default_build * Add missing libraries and source files to CMakeLists * Add CMakeLists for examples * Add CMake config for tests * Fix issues from merge * add toolchain auto-detection * Add patch requirements to .gitattributes * Fix some problems with the autodetection * Add extra tools to GNU toolchain * Work on github actions a bit * Better bin/hex generation (multi-config) * Store TOOLCHAIN_PREFIX in the CMake cache * Change cross-compiling mechanism * Fix SAI warnings * Formatting * Add some comments, move module path adjustment * Build examples as part of CMake CI Build job * Enable verbose build in GitHub Action * Fix silly mistake with missing the GCC config * group examples, add sane optimization defaults * remove weird naming from example targets now that they're grouped * move NDEBUG to standalone and DaisyProject * Separate tests CMake project * Fix merge resolution, toolchain integration * Move system_stm32h7xx.c to static CMSIS Device library * Fix strequal comparison * Fix cmake/DaisyProject.cmake Co-authored-by: Aleksei Savartsov * Fix compile option propagation; remove semihost * add `-fno-finite-loops` to LLVM toolchain file * Remove hal_map.c from CMakeLists.txt * Update llvm toolchains (ubuntu-latest no longer has libtinfo.so) * Change runtime lib arch for LLVM (see ARM-software/LLVM-embedded-toolchain-for-Arm#482) * Remove support for older LLVM Embedded toolchains * remove -fno-builtin * Update examples CMakeLists.txt, reduce Clang CI expectations --------- Co-authored-by: Aleksei Savartsov --- .gitattributes | 1 + .github/workflows/build.yml | 64 +++- .github/workflows/unit_tests.yaml | 26 +- .gitignore | 4 +- .vscode/extensions.json | 9 +- .vscode/launch.json | 5 +- .vscode/settings.json | 9 +- CMakeLists.txt | 294 ++++++------------ Drivers/CMakeLists.txt | 162 ++++++++++ Middlewares/ST/CMakeLists.txt | 39 +++ Middlewares/Third_Party/FatFs/CMakeLists.txt | 14 + cmake/DaisyDefaultBuild.cmake | 7 + cmake/DaisyProject.cmake | 118 +++++++ cmake/default_build.cmake | 52 ---- cmake/internal/tools.cmake | 15 + cmake/toolchains/ArmGNUToolchain.cmake | 80 +++++ .../LLVMEmbeddedToolchainForArm.cmake | 77 +++++ cmake/toolchains/autodetect.cmake | 30 ++ cmake/toolchains/stm32h750xx.cmake | 111 ++----- core/STM32H750IB_flash.lds | 19 +- core/STM32H750IB_qspi.lds | 19 +- core/STM32H750IB_sram.lds | 19 +- core/startup_stm32h750xx.c | 4 +- examples/ADCMulti/CMakeLists.txt | 3 + examples/ADCMux/CMakeLists.txt | 3 + examples/AudioOutput/CMakeLists.txt | 3 + examples/AudioPassthru/CMakeLists.txt | 3 + examples/BootloaderBlink/CMakeLists.txt | 3 + examples/CMakeLists.txt | 31 ++ examples/CopyingWavs/CMakeLists.txt | 3 + examples/DAC_Polling_Output/CMakeLists.txt | 3 + examples/Encoder/CMakeLists.txt | 3 + examples/ExternalCodec/CMakeLists.txt | 3 + examples/GPIO_Input/CMakeLists.txt | 3 + examples/GPIO_Output/CMakeLists.txt | 3 + examples/GateInput/CMakeLists.txt | 3 + examples/MIDI_UART_Input/CMakeLists.txt | 3 + examples/MIDI_USBH_Input/CMakeLists.txt | 3 + examples/OLED_SPI/CMakeLists.txt | 3 + examples/OLED_SSD130x4WireSPI/CMakeLists.txt | 3 + examples/OLED_SoftSPI/CMakeLists.txt | 3 + examples/SDMMC_HelloWorld/CMakeLists.txt | 3 + examples/SPI/CMakeLists.txt | 2 + .../SPI/SpiBlockingTransmit/CMakeLists.txt | 3 + examples/SPI/SpiDmaTransmit/CMakeLists.txt | 3 + examples/SR_4021/CMakeLists.txt | 3 + examples/SerialPrint/CMakeLists.txt | 3 + examples/SerialRead/CMakeLists.txt | 3 + examples/Switch/CMakeLists.txt | 3 + examples/Switch3/CMakeLists.txt | 3 + examples/TIM_SingleCallback/CMakeLists.txt | 3 + examples/uart/Blocking_Receive/CMakeLists.txt | 3 + .../uart/Blocking_Transmit/CMakeLists.txt | 3 + .../CMakeLists.txt | 3 + .../CMakeLists.txt | 3 + examples/uart/CMakeLists.txt | 9 + examples/uart/Dma_Fifo_Receive/CMakeLists.txt | 3 + examples/uart/Dma_Receive/CMakeLists.txt | 3 + examples/uart/Dma_Transmit/CMakeLists.txt | 3 + .../CMakeLists.txt | 3 + .../Dma_Transmit_Dma_Receive/CMakeLists.txt | 3 + src/dev/icm20948.h | 2 - src/per/i2c.cpp | 7 +- src/per/qspi.cpp | 2 +- src/per/sai.cpp | 9 +- src/per/spi.cpp | 2 +- src/per/tim.cpp | 4 +- src/per/uart.cpp | 18 +- tests/CMakeLists.txt | 72 +++++ tests/googletest | 2 +- 70 files changed, 1015 insertions(+), 428 deletions(-) create mode 100644 Drivers/CMakeLists.txt create mode 100644 Middlewares/ST/CMakeLists.txt create mode 100644 Middlewares/Third_Party/FatFs/CMakeLists.txt create mode 100644 cmake/DaisyDefaultBuild.cmake create mode 100644 cmake/DaisyProject.cmake delete mode 100644 cmake/default_build.cmake create mode 100644 cmake/internal/tools.cmake create mode 100644 cmake/toolchains/ArmGNUToolchain.cmake create mode 100644 cmake/toolchains/LLVMEmbeddedToolchainForArm.cmake create mode 100644 cmake/toolchains/autodetect.cmake create mode 100644 examples/ADCMulti/CMakeLists.txt create mode 100644 examples/ADCMux/CMakeLists.txt create mode 100644 examples/AudioOutput/CMakeLists.txt create mode 100644 examples/AudioPassthru/CMakeLists.txt create mode 100644 examples/BootloaderBlink/CMakeLists.txt create mode 100644 examples/CMakeLists.txt create mode 100644 examples/CopyingWavs/CMakeLists.txt create mode 100644 examples/DAC_Polling_Output/CMakeLists.txt create mode 100644 examples/Encoder/CMakeLists.txt create mode 100644 examples/ExternalCodec/CMakeLists.txt create mode 100644 examples/GPIO_Input/CMakeLists.txt create mode 100644 examples/GPIO_Output/CMakeLists.txt create mode 100644 examples/GateInput/CMakeLists.txt create mode 100644 examples/MIDI_UART_Input/CMakeLists.txt create mode 100644 examples/MIDI_USBH_Input/CMakeLists.txt create mode 100644 examples/OLED_SPI/CMakeLists.txt create mode 100644 examples/OLED_SSD130x4WireSPI/CMakeLists.txt create mode 100644 examples/OLED_SoftSPI/CMakeLists.txt create mode 100644 examples/SDMMC_HelloWorld/CMakeLists.txt create mode 100644 examples/SPI/CMakeLists.txt create mode 100644 examples/SPI/SpiBlockingTransmit/CMakeLists.txt create mode 100644 examples/SPI/SpiDmaTransmit/CMakeLists.txt create mode 100644 examples/SR_4021/CMakeLists.txt create mode 100644 examples/SerialPrint/CMakeLists.txt create mode 100644 examples/SerialRead/CMakeLists.txt create mode 100644 examples/Switch/CMakeLists.txt create mode 100644 examples/Switch3/CMakeLists.txt create mode 100644 examples/TIM_SingleCallback/CMakeLists.txt create mode 100644 examples/uart/Blocking_Receive/CMakeLists.txt create mode 100644 examples/uart/Blocking_Transmit/CMakeLists.txt create mode 100644 examples/uart/Blocking_Transmit_Dma_Receive/CMakeLists.txt create mode 100644 examples/uart/Blocking_Transmit_Fifo_Receive/CMakeLists.txt create mode 100644 examples/uart/CMakeLists.txt create mode 100644 examples/uart/Dma_Fifo_Receive/CMakeLists.txt create mode 100644 examples/uart/Dma_Receive/CMakeLists.txt create mode 100644 examples/uart/Dma_Transmit/CMakeLists.txt create mode 100644 examples/uart/Dma_Transmit_Blocking_Receive/CMakeLists.txt create mode 100644 examples/uart/Dma_Transmit_Dma_Receive/CMakeLists.txt create mode 100644 tests/CMakeLists.txt diff --git a/.gitattributes b/.gitattributes index 4720b94d9..a6830391c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,3 +9,4 @@ *.filters text eol=crlf *.props text eol=crlf *.xml text eol=crlf +*.patch text eol=lf \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 33d6255f4..136f19218 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,11 +31,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: - submodules: recursive + submodules: recursive - name: Setup arm-none-eabi-gcc - uses: fiam/arm-none-eabi-gcc@v1 + uses: carlosperate/arm-none-eabi-gcc-action@v1 with: release: '9-2019-q4' - name: Setup python @@ -47,22 +47,56 @@ jobs: - name: Build Examples run: ./ci/build_examples.py -f core doc src tests Drivers - build-cmake: + build-cmake-gcc: runs-on: ubuntu-latest + + strategy: + matrix: + version: [latest, '13.3.Rel1', '12.3.Rel1', '11.3.Rel1', '10.3-2021.10', '9-2020-q2'] + steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive + - name: Setup arm-none-eabi-gcc - uses: fiam/arm-none-eabi-gcc@v1 + uses: carlosperate/arm-none-eabi-gcc-action@v1 with: - release: '9-2019-q4' - - name: Setup cmake - uses: jwlawson/actions-setup-cmake@v1.9 - with: - cmake-version: '3.20.x' - - name: Configure Library - run: cmake -S . -B build -G "Unix Makefiles" -D CMAKE_TOOLCHAIN_FILE=cmake/toolchains/stm32h750xx.cmake -D TOOLCHAIN_PREFIX=$(which arm-none-eabi-gcc | sed -e "s/bin\/arm-none-eabi-gcc//") - - name: Build Library - run: cmake --build build + release: ${{ matrix.version }} + + - name: Setup CMake + uses: lukka/get-cmake@latest + + - name: Configure + run: cmake -B build -G Ninja -D CMAKE_BUILD_TYPE=Release + + - name: Build All + run: cmake --build build --target examples --verbose + + build-cmake-llvm: + runs-on: ubuntu-latest + + strategy: + matrix: + version: [latest, '19.1.1'] + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install LLVM Embedded Toolchain for Arm + uses: stellar-aria/llvm-embedded-toolchain-for-arm-action@latest + with: + release: ${{ matrix.version }} + + - name: Setup CMake + uses: lukka/get-cmake@latest + + - name: Configure + run: cmake -B build -G Ninja -D CMAKE_BUILD_TYPE=Release + + - name: Build All + run: cmake --build build --target BootloaderBlink --verbose # TODO: make this build all examples diff --git a/.github/workflows/unit_tests.yaml b/.github/workflows/unit_tests.yaml index e00b73d58..6fa96d678 100644 --- a/.github/workflows/unit_tests.yaml +++ b/.github/workflows/unit_tests.yaml @@ -12,7 +12,7 @@ on: - 'src/**' - 'tests/**' - '.github/workflows/**' -jobs: +jobs: ############################################################################### # builds the automated tests with clang; runs tests and exports results googleTest: @@ -24,23 +24,25 @@ jobs: with: submodules: recursive - - name: Build - run: | - cd tests - make release - + - name: Setup CMake + uses: lukka/get-cmake@latest + + - name: Configure CMake + run: cmake -B build -S tests + + - name: Build Tests + run: cmake --build build + - name: Run Tests - run: | - cd tests/build/bin - ./libDaisy_gtest --gtest_output=xml:gtestresults.xml - + run: ctest --test-dir build --output-junit results/gtestresults.xml + - name: Upload Test Results uses: actions/upload-artifact@v4 if: always() with: name: Test Results - path: tests/build/bin/**/*.xml - + path: build/results/*.xml + event_file: name: "Event File" runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index e0386f705..d550932f2 100644 --- a/.gitignore +++ b/.gitignore @@ -118,7 +118,7 @@ LLVM/ transcode report.txt /examples/*/build /example_projects/*/build -/build +/build* /doc/*.md /core/build /doc/html @@ -129,6 +129,6 @@ VisualGDBCache vs/*.log tests/libDaisy_gtest -tests/build/bin/ +tests/build/ examples/**/build/ diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 108f9380e..436d6f560 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,8 +1,9 @@ { "recommendations": [ - "ms-vscode.cpptools", + "ms-vscode.cpptools", "xaver.clang-format", - "davidschuldenfrei.gtest-adapter", - "vadimcn.vscode-lldb" + "vadimcn.vscode-lldb", + "ms-vscode.cmake-tools", + "matepek.vscode-catch2-test-adapter", ] -} \ No newline at end of file +} diff --git a/.vscode/launch.json b/.vscode/launch.json index b913734c5..bc4953826 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,7 +15,6 @@ }, "preLaunchTask": "build-libDaisy-tests", "osx": { - "type": "lldb", "MIMode": "lldb", }, "windows": { @@ -48,9 +47,9 @@ "monitor reset" ], "request": "launch", - "runToMain": true, + "runToEntryPoint": "true", "servertype": "openocd", - "showDevDebugOutput": true, + "showDevDebugOutput": "none", "svdFile": "${workspaceRoot}/.vscode/STM32H750x.svd", "type": "cortex-debug" } diff --git a/.vscode/settings.json b/.vscode/settings.json index 17c705b44..91dffeaa8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -87,8 +87,9 @@ ] }, "testMate.cpp.test.executables": "tests/build/bin/*", - "gtest-adapter.debugConfig": [ - "Launch Tests Locally" + "cmake.sourceDirectory": [ + "${workspaceFolder}", + "${workspaceFolder}/tests", ], - "gtest-adapter.supportLocation": true, -} \ No newline at end of file + "cmake.buildDirectory": "${sourceDirectory}/build", +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 129b36998..f282769e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,233 +1,141 @@ -cmake_policy(SET CMP0048 NEW) -project (libdaisy VERSION 1.0.0) cmake_minimum_required(VERSION 3.20) +cmake_policy(SET CMP0048 NEW) +cmake_policy(SET CMP0135 NEW) -set(TARGET daisy) +# Set up our toolchain for cross-compilation if that's happening +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) + include(${CMAKE_CURRENT_LIST_DIR}/cmake/toolchains/autodetect.cmake) +endif() +# Declare our project +project(libDaisy VERSION 7.0.1) -set(MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}/src") +# Append our /cmake to the module path +# This allows us to use DaisyProject as `include(DaisyProject)` +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") -add_library(${TARGET} STATIC - ${MODULE_DIR}/sys/dma.c - ${MODULE_DIR}/hid/audio.cpp - ${MODULE_DIR}/sys/fatfs.cpp - ${MODULE_DIR}/per/gpio.cpp - ${MODULE_DIR}/per/rng.cpp - ${MODULE_DIR}/per/sai.cpp - ${MODULE_DIR}/per/sdmmc.cpp - ${MODULE_DIR}/util/bsp_sd_diskio.c - ${MODULE_DIR}/util/oled_fonts.c - ${MODULE_DIR}/util/sd_diskio.c - ${MODULE_DIR}/util/usbh_diskio.c - ${MODULE_DIR}/util/unique_id.c - ${MODULE_DIR}/sys/system_stm32h7xx.c - ${MODULE_DIR}/usbd/usbd_cdc_if.c - ${MODULE_DIR}/usbd/usbd_desc.c - ${MODULE_DIR}/usbd/usbd_conf.c - ${MODULE_DIR}/usbh/usbh_conf.c - ${MODULE_DIR}/daisy_seed.cpp - ${MODULE_DIR}/daisy_pod.cpp - ${MODULE_DIR}/daisy_patch.cpp - ${MODULE_DIR}/daisy_petal.cpp +if(NOT PROJECT_IS_TOP_LEVEL) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) +else() + # Need to set sane default compile options for standalone library build + add_compile_options( + $<$:-ggdb3> + $<$:-Og> + $<$:-O3> + $<$:-Os> + ) + add_compile_options($<$:-flto>) + add_link_options($<$:-flto>) + + # Define NDEBUG when not compiling with debug flags + add_compile_definitions($<$:NDEBUG>) +endif() + +cmake_path(SET MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}/src") + +include(${CMAKE_CURRENT_LIST_DIR}/cmake/internal/tools.cmake) + +add_subdirectory(Drivers) +add_subdirectory(Middlewares/ST) +add_subdirectory(Middlewares/Third_Party/FatFs) + +add_library(daisy STATIC ${MODULE_DIR}/daisy_field.cpp - ${MODULE_DIR}/daisy_versio.cpp ${MODULE_DIR}/daisy_legio.cpp ${MODULE_DIR}/daisy_patch_sm.cpp - ${MODULE_DIR}/sys/system.cpp - ${MODULE_DIR}/dev/sr_595.cpp + ${MODULE_DIR}/daisy_patch.cpp + ${MODULE_DIR}/daisy_petal.cpp + ${MODULE_DIR}/daisy_pod.cpp + ${MODULE_DIR}/daisy_seed.cpp + ${MODULE_DIR}/daisy_versio.cpp ${MODULE_DIR}/dev/codec_ak4556.cpp ${MODULE_DIR}/dev/codec_pcm3060.cpp ${MODULE_DIR}/dev/codec_wm8731.cpp ${MODULE_DIR}/dev/lcd_hd44780.cpp + ${MODULE_DIR}/dev/sdram.cpp + ${MODULE_DIR}/dev/sr_595.cpp + ${MODULE_DIR}/hid/audio.cpp ${MODULE_DIR}/hid/ctrl.cpp ${MODULE_DIR}/hid/encoder.cpp ${MODULE_DIR}/hid/gatein.cpp ${MODULE_DIR}/hid/led.cpp - ${MODULE_DIR}/hid/midi.cpp + ${MODULE_DIR}/hid/logger.cpp ${MODULE_DIR}/hid/midi_parser.cpp + ${MODULE_DIR}/hid/midi.cpp ${MODULE_DIR}/hid/parameter.cpp ${MODULE_DIR}/hid/rgb_led.cpp ${MODULE_DIR}/hid/switch.cpp - ${MODULE_DIR}/hid/usb.cpp ${MODULE_DIR}/hid/usb_host.cpp ${MODULE_DIR}/hid/usb_midi.cpp + ${MODULE_DIR}/hid/usb.cpp ${MODULE_DIR}/hid/wavplayer.cpp - ${MODULE_DIR}/hid/logger.cpp ${MODULE_DIR}/per/adc.cpp ${MODULE_DIR}/per/dac.cpp + ${MODULE_DIR}/per/gpio.cpp ${MODULE_DIR}/per/i2c.cpp ${MODULE_DIR}/per/qspi.cpp - ${MODULE_DIR}/dev/sdram.cpp + ${MODULE_DIR}/per/rng.cpp + ${MODULE_DIR}/per/sai.cpp + ${MODULE_DIR}/per/sdmmc.cpp ${MODULE_DIR}/per/spi.cpp ${MODULE_DIR}/per/spiMultislave.cpp ${MODULE_DIR}/per/tim.cpp ${MODULE_DIR}/per/uart.cpp + ${MODULE_DIR}/sys/dma.c + ${MODULE_DIR}/sys/fatfs.cpp + ${MODULE_DIR}/sys/system.cpp ${MODULE_DIR}/ui/AbstractMenu.cpp ${MODULE_DIR}/ui/FullScreenItemMenu.cpp ${MODULE_DIR}/ui/UI.cpp + ${MODULE_DIR}/usbd/usbd_cdc_if.c + ${MODULE_DIR}/usbd/usbd_conf.c + ${MODULE_DIR}/usbd/usbd_desc.c + ${MODULE_DIR}/usbh/usbh_conf.c + ${MODULE_DIR}/util/bsp_sd_diskio.c ${MODULE_DIR}/util/color.cpp + ${MODULE_DIR}/util/MappedValue.cpp + ${MODULE_DIR}/util/oled_fonts.c + ${MODULE_DIR}/util/sd_diskio.c + ${MODULE_DIR}/util/unique_id.c + ${MODULE_DIR}/util/usbh_diskio.c ${MODULE_DIR}/util/WaveTableLoader.cpp - - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cec.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_comp.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cordic.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dac.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dac_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dcmi.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dfsdm.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dfsdm_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma2d.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dsi.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dts.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_eth.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_eth_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_fdcan.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_fmac.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gfxmmu.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hash.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hash_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hcd.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hrtim.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2s.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2s_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_irda.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_iwdg.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_jpeg.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_lptim.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdios.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mmc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mmc_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_nand.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_nor.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_opamp.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_opamp_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ospi.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_otfdec.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pcd.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pcd_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pssi.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ramecc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rng.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rng_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sai.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sai_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sd.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sd_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sdram.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_smartcard.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_smartcard_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_smbus.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_smbus_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spdifrx.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sram.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_swpmi.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_usart.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_usart_ex.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_wwdg.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_adc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_bdma.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_comp.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_cordic.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_crc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_crs.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_dac.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_delayblock.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_dma.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_dma2d.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_exti.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_fmac.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_fmc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_gpio.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_hrtim.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_i2c.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_lptim.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_lpuart.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_mdma.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_opamp.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_pwr.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_rcc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_rng.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_rtc.c - Drivers/Patched/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_sdmmc.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_spi.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_swpmi.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_tim.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_usart.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_usb.c - Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_utils.c - - Middlewares/Patched/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c - Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c - Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c - Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c - Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c - Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c - Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ioreq.c - Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_pipes.c - Middlewares/ST/STM32_USB_Host_Library/Class/MIDI/Src/usbh_midi.c - Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c - Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c - Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c - Middlewares/Third_Party/FatFs/src/diskio.c - Middlewares/Third_Party/FatFs/src/ff.c - Middlewares/Third_Party/FatFs/src/ff_gen_drv.c core/startup_stm32h750xx.c - ) +) -target_include_directories(${TARGET} PUBLIC +target_include_directories(daisy PUBLIC ${MODULE_DIR} - Drivers/CMSIS_5/CMSIS/Core/Include - Drivers/CMSIS-Device/ST/STM32H7xx/Include - Drivers/STM32H7xx_HAL_Driver/Inc - Drivers/STM32H7xx_HAL_Driver/Inc/Legacy - Middlewares/ST/STM32_USB_Device_Library/Core/Inc - Middlewares/Patched/ST/STM32_USB_Device_Library/Class/CDC/Inc - Middlewares/ST/STM32_USB_Host_Library/Core/Inc - Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc - Middlewares/ST/STM32_USB_Host_Library/Class/MIDI/Inc - Middlewares/Third_Party/FatFs/src - src - src/sys - src/usbd - src/usbh - ) +) + +target_link_libraries(daisy PUBLIC + CMSIS_CORE + CMSIS_DEVICE_H7 + STM32H7XX_HAL_DRIVER + STM32_USB_DEVICE_LIBRARY + STM32_USB_HOST_LIBRARY + FatFs +) + +target_compile_options(daisy PRIVATE + -Wall + + # At same point this generator should be removed, but the clang build isn't there yet + $<$:-Werror> + + # These are explicitly for startup_stm32h750xx.c + $<$:-Wno-attributes> + $<$:-Wno-missing-attributes> +) + +set_target_properties(daisy PROPERTIES + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED + C_STANDARD 11 + C_STANDARD_REQUIRED +) -set_target_properties(${TARGET} PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED - C_STANDARD 11 - C_STANDARD_REQUIRED - ) +# Don't add examples if we're being included in another project +if(PROJECT_IS_TOP_LEVEL) + add_subdirectory(examples EXCLUDE_FROM_ALL) + get_all_targets(example_targets examples) + add_custom_target(examples DEPENDS ${example_targets}) +endif() diff --git a/Drivers/CMakeLists.txt b/Drivers/CMakeLists.txt new file mode 100644 index 000000000..77fd3ce80 --- /dev/null +++ b/Drivers/CMakeLists.txt @@ -0,0 +1,162 @@ +# CMSIS Core +add_library(CMSIS_CORE INTERFACE) +target_include_directories(CMSIS_CORE INTERFACE + CMSIS_5/CMSIS/Core/Include +) + +# CMSIS Device +add_library(CMSIS_DEVICE_H7 STATIC) +target_include_directories(CMSIS_DEVICE_H7 PUBLIC + CMSIS-Device/ST/STM32H7xx/Include +) +target_sources(CMSIS_DEVICE_H7 PRIVATE + ${MODULE_DIR}/sys/system_stm32h7xx.c +) +target_link_libraries(CMSIS_DEVICE_H7 PUBLIC + CMSIS_CORE + STM32H7XX_HAL_DRIVER +) + +# STM32H7xx HAL Driver +add_library(STM32H7XX_HAL_DRIVER STATIC + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cec.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_comp.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cordic.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dac.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dac_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dcmi.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dfsdm.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dfsdm_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma2d.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dsi.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dts.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_eth.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_eth_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_fdcan.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_fmac.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gfxmmu.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hash.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hash_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hcd.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hrtim.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2s.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2s_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_irda.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_iwdg.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_jpeg.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_lptim.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdios.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mmc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mmc_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_nand.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_nor.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_opamp.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_opamp_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ospi.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_otfdec.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pcd.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pcd_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pssi.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ramecc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rng.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rng_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sai.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sai_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sd.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sd_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sdram.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_smartcard.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_smartcard_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_smbus.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_smbus_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spdifrx.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sram.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_swpmi.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_usart.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_usart_ex.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_wwdg.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_adc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_bdma.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_comp.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_cordic.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_crc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_crs.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_dac.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_delayblock.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_dma.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_dma2d.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_exti.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_fmac.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_fmc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_gpio.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_hrtim.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_i2c.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_lptim.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_lpuart.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_mdma.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_opamp.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_pwr.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_rcc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_rng.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_rtc.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_spi.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_swpmi.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_tim.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_usart.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_usb.c + STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_utils.c + + # NOTE: In-tree source patch until fixed upstream (volatile counters/loop unrolling) + Patched/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_sdmmc.c +) + +target_include_directories(STM32H7XX_HAL_DRIVER PUBLIC + STM32H7xx_HAL_Driver/Inc + STM32H7xx_HAL_Driver/Inc/Legacy + ${MODULE_DIR}/sys # for stm32h7xx_hal_conf.h +) + +# Weird Circular dependency (HAL -> CMSIS-Device -> HAL) +target_link_libraries(STM32H7XX_HAL_DRIVER PUBLIC CMSIS_DEVICE_H7) + +target_compile_options(STM32H7XX_HAL_DRIVER PRIVATE + -Wno-unused-but-set-variable +) + +target_compile_definitions(STM32H7XX_HAL_DRIVER PRIVATE + USE_HAL_DRIVER + USE_FULL_LL_DRIVER +) diff --git a/Middlewares/ST/CMakeLists.txt b/Middlewares/ST/CMakeLists.txt new file mode 100644 index 000000000..d4c1a17c3 --- /dev/null +++ b/Middlewares/ST/CMakeLists.txt @@ -0,0 +1,39 @@ +# USB Device Library +add_library(STM32_USB_DEVICE_LIBRARY STATIC + ../Patched/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c + STM32_USB_Device_Library/Core/Src/usbd_core.c + STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c + STM32_USB_Device_Library/Core/Src/usbd_ioreq.c +) +target_include_directories(STM32_USB_DEVICE_LIBRARY PUBLIC + STM32_USB_Device_Library/Core/Inc + ../Patched/ST/STM32_USB_Device_Library/Class/CDC/Inc + ${MODULE_DIR}/usbd # for conf +) +target_link_libraries(STM32_USB_DEVICE_LIBRARY PUBLIC + CMSIS_DEVICE_H7 + STM32H7XX_HAL_DRIVER +) + +# USB Host Library +add_library(STM32_USB_HOST_LIBRARY STATIC + STM32_USB_Host_Library/Core/Src/usbh_core.c + STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c + STM32_USB_Host_Library/Core/Src/usbh_ioreq.c + STM32_USB_Host_Library/Core/Src/usbh_pipes.c + STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c + STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c + STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c + STM32_USB_Host_Library/Class/MIDI/Src/usbh_midi.c +) +target_include_directories(STM32_USB_HOST_LIBRARY PUBLIC + STM32_USB_Host_Library/Core/Inc + STM32_USB_Host_Library/Class/MSC/Inc + STM32_USB_Host_Library/Class/MIDI/Inc + ${MODULE_DIR}/usbh # for conf + ${MODULE_DIR} # for daisy_core.h +) +target_link_libraries(STM32_USB_HOST_LIBRARY PUBLIC + CMSIS_DEVICE_H7 + STM32H7XX_HAL_DRIVER +) diff --git a/Middlewares/Third_Party/FatFs/CMakeLists.txt b/Middlewares/Third_Party/FatFs/CMakeLists.txt new file mode 100644 index 000000000..d69ad35b2 --- /dev/null +++ b/Middlewares/Third_Party/FatFs/CMakeLists.txt @@ -0,0 +1,14 @@ +add_library(FatFs STATIC + src/diskio.c + src/ff.c + src/ff_gen_drv.c + + # due to config (in src/sys) which has _USE_LFN = 1 + src/option/unicode.c +) + +target_include_directories(FatFs PUBLIC + src + ${MODULE_DIR}/sys + ${MODULE_DIR} # for util/bsp_sd_diskio.h +) \ No newline at end of file diff --git a/cmake/DaisyDefaultBuild.cmake b/cmake/DaisyDefaultBuild.cmake new file mode 100644 index 000000000..4e40d7ea7 --- /dev/null +++ b/cmake/DaisyDefaultBuild.cmake @@ -0,0 +1,7 @@ +add_subdirectory(${LIBDAISY_DIR} libdaisy) +if (DEFINED DAISYSP_DIR) + add_subdirectory(${DAISYSP_DIR} DaisySP) + set(DAISYSP_LIB DaisySP) +endif() + +include(DaisyProject) \ No newline at end of file diff --git a/cmake/DaisyProject.cmake b/cmake/DaisyProject.cmake new file mode 100644 index 000000000..17ea6c9da --- /dev/null +++ b/cmake/DaisyProject.cmake @@ -0,0 +1,118 @@ +set(DAISY_STORAGE flash CACHE STRING "Select the storage destination of the executable.") + +if(DEFINED CUSTOM_LINKER_SCRIPT) + set(LINKER_SCRIPT ${CUSTOM_LINKER_SCRIPT}) +else() + cmake_path(SET LINKER_SCRIPT NORMALIZE ${CMAKE_CURRENT_LIST_DIR}/../core/STM32H750IB_${DAISY_STORAGE}.lds) + + if(NOT DAISY_STORAGE STREQUAL "flash") + target_compile_definitions(daisy PRIVATE BOOT_APP) + endif() +endif() + +function(daisy_targets func options) + get_target_property(target_list daisy LINK_LIBRARIES) + + foreach(target IN LISTS target_list) + get_target_property(type ${target} TYPE) + + if(type STREQUAL "INTERFACE_LIBRARY") + cmake_language(CALL target_${func} ${target} INTERFACE ${options}) + else() + cmake_language(CALL target_${func} ${target} PRIVATE ${options}) + endif() + endforeach() + + cmake_language(CALL target_${func} daisy PRIVATE ${options}) +endfunction(daisy_targets) + +# Global optimization options +if(NOT DEFINED FIRMWARE_DEBUG_OPT_LEVEL) + set(FIRMWARE_DEBUG_OPT_LEVEL -Og) +endif() + +add_compile_options($<$:${FIRMWARE_DEBUG_OPT_LEVEL}>) +daisy_targets(compile_options $<$:${FIRMWARE_DEBUG_OPT_LEVEL}>) + +if(NOT DEFINED FIRMWARE_RELEASE_OPT_LEVEL) + set(FIRMWARE_RELEASE_OPT_LEVEL -O3) +endif() + +add_compile_options($<$:${FIRMWARE_RELEASE_OPT_LEVEL}>) +daisy_targets(compile_options $<$:${FIRMWARE_RELEASE_OPT_LEVEL}>) + +if(NOT DEFINED FIRMWARE_MINSIZEREL_OPT_LEVEL) + # Optimize for size. -Os enables all -O2 optimizations. + set(FIRMWARE_MINSIZE_REL_OPT_LEVEL -Os) +endif() + +add_compile_options($<$:${FIRMWARE_MINSIZEREL_OPT_LEVEL}>) +daisy_targets(compile_options $<$:${FIRMWARE_MINSIZEREL_OPT_LEVEL}>) + +# Always use LTO on Release +add_compile_options($<$:-flto>) +daisy_targets(compile_options $<$:-flto>) + +add_link_options($<$:-flto>) +daisy_targets(link_options $<$:-flto>) + +# Include debug symbols when compiling with debug flags +add_compile_options($<$:-ggdb3>) +daisy_targets(compile_options $<$:-ggdb3>) + +# Define NDEBUG when not compiling with debug flags +add_compile_definitions($<$:NDEBUG>) +daisy_targets(compile_definitions $<$:NDEBUG>) + +add_executable(${FIRMWARE_NAME} ${FIRMWARE_SOURCES}) + +target_link_libraries(${FIRMWARE_NAME} + PRIVATE + daisy + ${DAISYSP_LIB} +) + +set_target_properties(${FIRMWARE_NAME} PROPERTIES + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED YES + SUFFIX ".elf" + LINK_DEPENDS ${LINKER_SCRIPT} +) + +target_compile_options(${FIRMWARE_NAME} PUBLIC + $<$:-flto> +) + +target_link_options(${FIRMWARE_NAME} PUBLIC + LINKER:-T,${LINKER_SCRIPT} + $<$:LINKER:-Map=${FIRMWARE_NAME}.map> + $<$:LINKER:--cref> + LINKER:--gc-sections + LINKER:--check-sections + LINKER:--unresolved-symbols=report-all + LINKER:--warn-common + $<$:LINKER:--warn-section-align> + + # Currently a GSoC project to port this to LLD + $<$:LINKER:--print-memory-usage> +) + +add_custom_command(TARGET ${FIRMWARE_NAME} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O ihex -S $ $/${FIRMWARE_NAME}.hex + BYPRODUCTS ${FIRMWARE_NAME}.hex + DEPENDS ${FIRMWARE_NAME} + COMMENT "Generating HEX image" + VERBATIM +) + +option(DAISY_GENERATE_BIN "Sets whether or not to generate a raw binary image using objcopy (warning this is a very large file, as it is a representation of the *full memory space*.)") + +if(DAISY_GENERATE_BIN) + add_custom_command(TARGET ${FIRMWARE_NAME} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary -S $ $/${FIRMWARE_NAME}.bin + BYPRODUCTS ${FIRMWARE_NAME}.bin + DEPENDS ${FIRMWARE_NAME} + COMMENT "Generating binary image" + VERBATIM + ) +endif() diff --git a/cmake/default_build.cmake b/cmake/default_build.cmake deleted file mode 100644 index e46592e40..000000000 --- a/cmake/default_build.cmake +++ /dev/null @@ -1,52 +0,0 @@ -add_subdirectory(${LIBDAISY_DIR} libdaisy) -if (${DAISYSP_DIR}) - add_subdirectory(${DAISYSP_DIR} DaisySP) - set(DAISYSP_LIB DaisySP) -endif() - -set(LINKER_SCRIPT ${LIBDAISY_DIR}/core/STM32H750IB_flash.lds) - -add_executable(${FIRMWARE_NAME} ${FIRMWARE_SOURCES}) - -target_link_libraries(${FIRMWARE_NAME} - PRIVATE - daisy - ${DAISYSP_LIB} - ) - -set_target_properties(${FIRMWARE_NAME} PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED YES - SUFFIX ".elf" - LINK_DEPENDS ${LINKER_SCRIPT} -) - -target_link_options(${FIRMWARE_NAME} PUBLIC - -T ${LINKER_SCRIPT} - -Wl,-Map=${FIRMWARE_NAME}.map,--cref - -Wl,--check-sections - -Wl,--unresolved-symbols=report-all - -Wl,--warn-common - -Wl,--warn-section-align - -Wl,--print-memory-usage -) - -add_custom_command(TARGET ${FIRMWARE_NAME} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} - ARGS -O ihex - -S ${FIRMWARE_NAME}.elf - ${FIRMWARE_NAME}.hex - BYPRODUCTS - ${FIRMWARE_NAME}.hex - COMMENT "Generating HEX image" -VERBATIM) - -add_custom_command(TARGET ${FIRMWARE_NAME} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} - ARGS -O binary - -S ${FIRMWARE_NAME}.elf - ${FIRMWARE_NAME}.bin - BYPRODUCTS - ${FIRMWARE_NAME}.bin - COMMENT "Generating binary image" -VERBATIM) diff --git a/cmake/internal/tools.cmake b/cmake/internal/tools.cmake new file mode 100644 index 000000000..8f111c9f6 --- /dev/null +++ b/cmake/internal/tools.cmake @@ -0,0 +1,15 @@ +# Function to collect all currently added targets in all subdirectories +# +# Parameters: +# - result the list containing all found targets +# - dir root directory to start looking from +function(get_all_targets result dir) + get_property(subdirs DIRECTORY "${dir}" PROPERTY SUBDIRECTORIES) + + foreach(subdir IN LISTS subdirs) + get_all_targets(${result} "${subdir}") + endforeach() + + get_directory_property(sub_targets DIRECTORY "${dir}" BUILDSYSTEM_TARGETS) + set(${result} ${${result}} ${sub_targets} PARENT_SCOPE) +endfunction() diff --git a/cmake/toolchains/ArmGNUToolchain.cmake b/cmake/toolchains/ArmGNUToolchain.cmake new file mode 100644 index 000000000..8b2d153e6 --- /dev/null +++ b/cmake/toolchains/ArmGNUToolchain.cmake @@ -0,0 +1,80 @@ +# adapted from https://github.com/jobroe/cmake-arm-embedded/blob/master/toolchain-arm-none-eabi.cmake + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR ARM) + +list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}") + +set(TOOLCHAIN arm-none-eabi) + +if(NOT DEFINED CMAKE_C_COMPILER) + if(NOT DEFINED ENV{CMAKE_C_COMPILER}) + message(FATAL_ERROR "Please provide CMAKE_C_COMPILER at configuration if not using autodetection") + endif() + + set(CMAKE_C_COMPILER $ENV{CMAKE_C_COMPILER}) +endif() + +cmake_path(GET CMAKE_C_COMPILER PARENT_PATH TOOLCHAIN_BIN_DIR) +cmake_path(GET TOOLCHAIN_BIN_DIR PARENT_PATH TOOLCHAIN_PREFIX) + +if(WIN32) + set(TOOLCHAIN_EXT ".exe") +else() + set(TOOLCHAIN_EXT "") +endif() + +# Common flags in OBJECT_GEN_FLAGS, architecture flags in MCU +include(stm32h750xx) + +set(CMAKE_ASM_FLAGS "-x assembler-with-cpp" CACHE INTERNAL "ASM Compiler options") + +# Ensure the ar plugin is loaded (needed for LTO) +set(CMAKE_AR ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc-ar${TOOLCHAIN_EXT} CACHE INTERNAL "Archiving tool") +set(CMAKE_RANLIB ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc-ranlib${TOOLCHAIN_EXT} CACHE INTERNAL "Indexing tool") +set(CMAKE_C_ARCHIVE_CREATE " qcs ") +set(CMAKE_C_ARCHIVE_FINISH " ") +set(CMAKE_CXX_ARCHIVE_CREATE " qcs ") +set(CMAKE_CXX_ARCHIVE_FINISH " ") + +# -Wl,--gc-sections Perform the dead code elimination. +# --specs=nano.specs Link with newlib-nano. +# --specs=nosys.specs No syscalls, provide empty implementations for the POSIX system calls. +set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs --specs=nosys.specs" CACHE INTERNAL "Linker options") + +# --------------------------------------------------------------------------------------- +# Set debug/release build configuration Options +# --------------------------------------------------------------------------------------- + +# Options for DEBUG build +set(CMAKE_C_FLAGS_DEBUG "" CACHE INTERNAL "C Compiler options for debug build type") +set(CMAKE_CXX_FLAGS_DEBUG "" CACHE INTERNAL "C++ Compiler options for debug build type") +set(CMAKE_ASM_FLAGS_DEBUG "" CACHE INTERNAL "ASM Compiler options for debug build type") +set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type") + +# Options for RELEASE build +set(CMAKE_C_FLAGS_RELEASE "" CACHE INTERNAL "C Compiler options for release build type") +set(CMAKE_CXX_FLAGS_RELEASE "" CACHE INTERNAL "C++ Compiler options for release build type") +set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE INTERNAL "Linker options for release build type") + +# --------------------------------------------------------------------------------------- +# Set compilers +# --------------------------------------------------------------------------------------- +set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "C Compiler") +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler") +set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler") + +set(CMAKE_LINKER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-ld${TOOLCHAIN_EXT} CACHE FILEPATH "Path to linker.") +set(CMAKE_NM ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-nm${TOOLCHAIN_EXT} CACHE FILEPATH "Path to list symbols.") +set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objcopy${TOOLCHAIN_EXT} CACHE FILEPATH "Path to objcopy.") +set(CMAKE_OBJDUMP ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objdump${TOOLCHAIN_EXT} CACHE FILEPATH "Path to dump objects.") +set(CMAKE_RANLIB ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-ranlib${TOOLCHAIN_EXT} CACHE FILEPATH "Path to ranlib.") +set(CMAKE_SIZE ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-size${TOOLCHAIN_EXT} CACHE FILEPATH "Path to size.") +set(CMAKE_STRIP ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-strip${TOOLCHAIN_EXT} CACHE FILEPATH "Path to strip.") + +set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${${TOOLCHAIN}} ${CMAKE_PREFIX_PATH}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/cmake/toolchains/LLVMEmbeddedToolchainForArm.cmake b/cmake/toolchains/LLVMEmbeddedToolchainForArm.cmake new file mode 100644 index 000000000..c79cff0a3 --- /dev/null +++ b/cmake/toolchains/LLVMEmbeddedToolchainForArm.cmake @@ -0,0 +1,77 @@ +# adapted from https://github.com/jobroe/cmake-arm-embedded/blob/master/toolchain-arm-none-eabi.cmake + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR ARM) + +list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}") + +set(TOOLCHAIN arm-none-eabi) + +if(NOT DEFINED CMAKE_C_COMPILER) + if(NOT DEFINED ENV{CMAKE_C_COMPILER}) + message(FATAL_ERROR "Please provide CMAKE_C_COMPILER at configuration if not using autodetection") + endif() + + set(CMAKE_C_COMPILER $ENV{CMAKE_C_COMPILER}) +endif() + +cmake_path(GET CMAKE_C_COMPILER PARENT_PATH TOOLCHAIN_BIN_DIR) +cmake_path(GET TOOLCHAIN_BIN_DIR PARENT_PATH TOOLCHAIN_PREFIX) + +if(WIN32) + set(TOOLCHAIN_EXT ".exe") +else() + set(TOOLCHAIN_EXT "") +endif() + +include(stm32h750xx) + +set(CMAKE_ASM_FLAGS "-x assembler-with-cpp" CACHE INTERNAL "ASM Compiler options") + +# --------------------------------------------------------------------------------------- +# Set debug/release build configuration Options +# --------------------------------------------------------------------------------------- + +# Options for DEBUG build +set(CMAKE_C_FLAGS_DEBUG "-fno-finite-loops" CACHE INTERNAL "C Compiler options for debug build type") +set(CMAKE_CXX_FLAGS_DEBUG "-fno-finite-loops" CACHE INTERNAL "C++ Compiler options for debug build type") +set(CMAKE_ASM_FLAGS_DEBUG "" CACHE INTERNAL "ASM Compiler options for debug build type") +set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type") + +# Options for RELEASE build +set(CMAKE_C_FLAGS_RELEASE "-fno-finite-loops" CACHE INTERNAL "C Compiler options for release build type") +set(CMAKE_CXX_FLAGS_RELEASE "-fno-finite-loops" CACHE INTERNAL "C++ Compiler options for release build type") +set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE INTERNAL "Linker options for release build type") + +# --------------------------------------------------------------------------------------- +# Set compilers +# --------------------------------------------------------------------------------------- +set(CLANG_TARGET_TRIPLE thumbv7em-none-eabihf) +set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/clang${TOOLCHAIN_EXT} CACHE FILEPATH "C Compiler") +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/clang++${TOOLCHAIN_EXT} CACHE FILEPATH "C++ Compiler") +set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/clang${TOOLCHAIN_EXT} CACHE FILEPATH "ASM Compiler") + +set(CMAKE_AR ${TOOLCHAIN_BIN_DIR}/llvm-ar${TOOLCHAIN_EXT} CACHE FILEPATH "Path to archiver.") +set(CMAKE_LINKER ${TOOLCHAIN_BIN_DIR}/llvm-ld${TOOLCHAIN_EXT} CACHE FILEPATH "Path to linker.") +set(CMAKE_NM ${TOOLCHAIN_BIN_DIR}/llvm-nm${TOOLCHAIN_EXT} CACHE FILEPATH "Path to list symbols.") +set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/llvm-objcopy${TOOLCHAIN_EXT} CACHE FILEPATH "Path to objcopy.") +set(CMAKE_OBJDUMP ${TOOLCHAIN_BIN_DIR}/llvm-objdump${TOOLCHAIN_EXT} CACHE FILEPATH "Path to dump objects.") +set(CMAKE_RANLIB ${TOOLCHAIN_BIN_DIR}/llvm-ranlib${TOOLCHAIN_EXT} CACHE FILEPATH "Path to ranlib.") +set(CMAKE_SIZE ${TOOLCHAIN_BIN_DIR}/llvm-size${TOOLCHAIN_EXT} CACHE FILEPATH "Path to size.") +set(CMAKE_STRIP ${TOOLCHAIN_BIN_DIR}/llvm-strip${TOOLCHAIN_EXT} CACHE FILEPATH "Path to strip.") + +set(CMAKE_C_COMPILER_TARGET ${CLANG_TARGET_TRIPLE}) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/clang++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler") +set(CMAKE_CXX_COMPILER_TARGET ${CLANG_TARGET_TRIPLE}) +set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/clang${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler") +set(CMAKE_ASM_COMPILER_TARGET ${CLANG_TARGET_TRIPLE}) + +set(CMAKE_SYSROOT ${TOOLCHAIN_PREFIX}/lib/clang-runtimes/${TOOLCHAIN}/${ARCH_COMBO}) +set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${TOOLCHAIN} ${CMAKE_PREFIX_PATH}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +include_directories(SYSTEM ${TOOLCHAIN_PREFIX}/lib/clang-runtimes/${TOOLCHAIN}/${ARCH_COMBO}/include/c++/v1) diff --git a/cmake/toolchains/autodetect.cmake b/cmake/toolchains/autodetect.cmake new file mode 100644 index 000000000..19ae563f9 --- /dev/null +++ b/cmake/toolchains/autodetect.cmake @@ -0,0 +1,30 @@ +# Try to find/detect a valid embedded toolchain + +if(NOT DEFINED CMAKE_C_COMPILER) + message(NOTICE "No compiler specified. Falling back to searching PATH...") + find_program(CMAKE_C_COMPILER "arm-none-eabi-gcc") + find_program(CMAKE_CXX_COMPILER "arm-none-eabi-g++") + + if(${CMAKE_C_COMPILER} STREQUAL CMAKE_C_COMPILER-NOTFOUND) + message(NOTICE "Could not find arm-none-eabi-gcc. Assuming clang is part of embedded toolchain...") + find_program(CMAKE_C_COMPILER "clang" REQUIRED) + find_program(CMAKE_CXX_COMPILER "clang++" REQUIRED) + else() + message(STATUS "Found ${CMAKE_C_COMPILER}") + endif() +endif() + +cmake_path(GET CMAKE_C_COMPILER STEM CMAKE_C_COMPILER_STEM) +cmake_path(GET CMAKE_C_COMPILER PARENT_PATH CMAKE_C_COMPILER_BIN) +cmake_path(GET CMAKE_C_COMPILER_BIN PARENT_PATH TOOLCHAIN_PREFIX) + +set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER} CACHE INTERNAL "Path to the C compiler") + +# Used to propagate the discovered/set compiler to the ABI tests +set(ENV{CMAKE_C_COMPILER} ${CMAKE_C_COMPILER}) + +if(${CMAKE_C_COMPILER_STEM} STREQUAL arm-none-eabi-gcc) + set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/ArmGNUToolchain.cmake) +elseif(${CMAKE_C_COMPILER_STEM} STREQUAL clang) + set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/LLVMEmbeddedToolchainForArm.cmake) +endif() diff --git a/cmake/toolchains/stm32h750xx.cmake b/cmake/toolchains/stm32h750xx.cmake index 91f52c392..92d0de16a 100644 --- a/cmake/toolchains/stm32h750xx.cmake +++ b/cmake/toolchains/stm32h750xx.cmake @@ -1,92 +1,31 @@ -# adapted from https://github.com/jobroe/cmake-arm-embedded/blob/master/toolchain-arm-none-eabi.cmake - -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR ARM) - -set(TOOLCHAIN arm-none-eabi) -if(NOT DEFINED TOOLCHAIN_PREFIX) - if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) - set(TOOLCHAIN_PREFIX "/usr") - elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) - set(TOOLCHAIN_PREFIX "/usr/local") - elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) - message(STATUS "Please specify the TOOLCHAIN_PREFIX !\n For example: -DTOOLCHAIN_PREFIX=\"C:/Program Files/GNU Tools ARM Embedded\" ") - else() - set(TOOLCHAIN_PREFIX "/usr") - message(STATUS "No TOOLCHAIN_PREFIX specified, using default: " ${TOOLCHAIN_PREFIX}) - endif() -endif() -set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) -set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include) -set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib) - -if(WIN32) - set(TOOLCHAIN_EXT ".exe" ) -else() - set(TOOLCHAIN_EXT "" ) -endif() +set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) -set(MCU "-mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb") -set(OBJECT_GEN_FLAGS "${MCU} -fno-builtin -fno-exceptions -Wall -Werror -ffunction-sections -fdata-sections -fomit-frame-pointer -finline-functions -Wno-attributes -Wno-strict-aliasing -Wno-maybe-uninitialized -Wno-missing-attributes -Wno-stringop-overflow") -set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") -set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -Wno-register" CACHE INTERNAL "C++ Compiler options") -set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") -# Ensure the ar plugin is loaded (needed for LTO) -set(CMAKE_AR ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc-ar) -set(CMAKE_C_ARCHIVE_CREATE " qcs ") -set(CMAKE_C_ARCHIVE_FINISH true) -set(CMAKE_CXX_ARCHIVE_CREATE " qcs ") -set(CMAKE_CXX_ARCHIVE_FINISH true) +# Architucture flags +set(ARCH_COMBO armv7m_hard_fpv5_d16) +set(MCU + -mcpu=cortex-m7 + -mfpu=fpv5-d16 + -mfloat-abi=hard + -mthumb +) +add_compile_options(${MCU}) +add_link_options(${MCU}) + +add_compile_options( + -fno-exceptions + -ffunction-sections + -fdata-sections + -fomit-frame-pointer + -finline-functions + $<$:-fno-rtti> +) add_compile_definitions( - CORE_CM7 - STM32H750xx - STM32H750IB - ARM_MATH_CM7 - flash_layout - HSE_VALUE=16000000 - USE_HAL_DRIVER - USE_FULL_LL_DRIVER + CORE_CM7 + STM32H750xx + STM32H750IB + ARM_MATH_CM7 + HSE_VALUE=16000000 ) - - -# -Wl,--gc-sections Perform the dead code elimination. -# --specs=nano.specs Link with newlib-nano. -# --specs=nosys.specs No syscalls, provide empty implementations for the POSIX system calls. -set(CMAKE_EXE_LINKER_FLAGS "${MCU} -Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options") - -#--------------------------------------------------------------------------------------- -# Set debug/release build configuration Options -#--------------------------------------------------------------------------------------- - -# Options for DEBUG build -# -Og Enables optimizations that do not interfere with debugging. -# -g Produce debugging information in the operating system’s native format. -set(CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE INTERNAL "C Compiler options for debug build type") -set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE INTERNAL "C++ Compiler options for debug build type") -set(CMAKE_ASM_FLAGS_DEBUG "-g" CACHE INTERNAL "ASM Compiler options for debug build type") -set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type") - -# Options for RELEASE build -# -Os Optimize for size. -Os enables all -O2 optimizations. -# -flto Runs the standard link-time optimizer. -set(CMAKE_C_FLAGS_RELEASE "-Os -flto" CACHE INTERNAL "C Compiler options for release build type") -set(CMAKE_CXX_FLAGS_RELEASE "-Os -flto" CACHE INTERNAL "C++ Compiler options for release build type") -set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") -set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-flto" CACHE INTERNAL "Linker options for release build type") - - -#--------------------------------------------------------------------------------------- -# Set compilers -#--------------------------------------------------------------------------------------- -set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "C Compiler") -set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler") -set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler") - -set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${${TOOLCHAIN}} ${CMAKE_PREFIX_PATH}) -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/core/STM32H750IB_flash.lds b/core/STM32H750IB_flash.lds index 0756574af..6d8e6a439 100644 --- a/core/STM32H750IB_flash.lds +++ b/core/STM32H750IB_flash.lds @@ -64,32 +64,29 @@ SECTIONS PROVIDE(__exidx_end = .); } > FLASH - .ARM.attributes : - { - *(.ARM.attributes) - } > FLASH + .ARM.attributes 0 : { *(.ARM.attributes) } .preinit_array : { - PROVIDE(__preinit_array_start = .); + PROVIDE_HIDDEN(__preinit_array_start = .); KEEP(*(.preinit_array*)) - PROVIDE(__preinit_array_end = .); + PROVIDE_HIDDEN(__preinit_array_end = .); } > FLASH .init_array : { - PROVIDE(__init_array_start = .); + PROVIDE_HIDDEN(__init_array_start = .); KEEP(*(SORT(.init_array.*))) KEEP(*(.init_array*)) - PROVIDE(__init_array_end = .); + PROVIDE_HIDDEN(__init_array_end = .); } > FLASH .fini_array : { - PROVIDE(__fini_array_start = .); + PROVIDE_HIDDEN(__fini_array_start = .); KEEP(*(.fini_array*)) KEEP(*(SORT(.fini_array.*))) - PROVIDE(__fini_array_end = .); + PROVIDE_HIDDEN(__fini_array_end = .); } > FLASH .data : @@ -244,8 +241,10 @@ SECTIONS { . = ALIGN(4); PROVIDE(__heap_start__ = .); + PROVIDE(__heap_start = .); KEEP(*(.heap)) . = ALIGN(4); + PROVIDE(__heap_end = .); PROVIDE(__heap_end__ = .); } > SRAM diff --git a/core/STM32H750IB_qspi.lds b/core/STM32H750IB_qspi.lds index d772e9f32..8e3eb1311 100644 --- a/core/STM32H750IB_qspi.lds +++ b/core/STM32H750IB_qspi.lds @@ -66,32 +66,29 @@ SECTIONS PROVIDE(__exidx_end = .); } > QSPIFLASH - .ARM.attributes : - { - *(.ARM.attributes) - } > QSPIFLASH + .ARM.attributes 0 : { *(.ARM.attributes) } .preinit_array : { - PROVIDE(__preinit_array_start = .); + PROVIDE_HIDDEN(__preinit_array_start = .); KEEP(*(.preinit_array*)) - PROVIDE(__preinit_array_end = .); + PROVIDE_HIDDEN(__preinit_array_end = .); } > QSPIFLASH .init_array : { - PROVIDE(__init_array_start = .); + PROVIDE_HIDDEN(__init_array_start = .); KEEP(*(SORT(.init_array.*))) KEEP(*(.init_array*)) - PROVIDE(__init_array_end = .); + PROVIDE_HIDDEN(__init_array_end = .); } > QSPIFLASH .fini_array : { - PROVIDE(__fini_array_start = .); + PROVIDE_HIDDEN(__fini_array_start = .); KEEP(*(.fini_array*)) KEEP(*(SORT(.fini_array.*))) - PROVIDE(__fini_array_end = .); + PROVIDE_HIDDEN(__fini_array_end = .); } > QSPIFLASH .sram1_bss (NOLOAD) : @@ -245,8 +242,10 @@ SECTIONS { . = ALIGN(4); PROVIDE(__heap_start__ = .); + PROVIDE(__heap_start = .); KEEP(*(.heap)) . = ALIGN(4); + PROVIDE(__heap_end = .); PROVIDE(__heap_end__ = .); } > SRAM diff --git a/core/STM32H750IB_sram.lds b/core/STM32H750IB_sram.lds index 2e711ec97..d080f30e9 100644 --- a/core/STM32H750IB_sram.lds +++ b/core/STM32H750IB_sram.lds @@ -65,32 +65,29 @@ SECTIONS PROVIDE(__exidx_end = .); } > SRAM - .ARM.attributes : - { - *(.ARM.attributes) - } > SRAM + .ARM.attributes 0 : { *(.ARM.attributes) } .preinit_array : { - PROVIDE(__preinit_array_start = .); + PROVIDE_HIDDEN(__preinit_array_start = .); KEEP(*(.preinit_array*)) - PROVIDE(__preinit_array_end = .); + PROVIDE_HIDDEN(__preinit_array_end = .); } > SRAM .init_array : { - PROVIDE(__init_array_start = .); + PROVIDE_HIDDEN(__init_array_start = .); KEEP(*(SORT(.init_array.*))) KEEP(*(.init_array*)) - PROVIDE(__init_array_end = .); + PROVIDE_HIDDEN(__init_array_end = .); } > SRAM .fini_array : { - PROVIDE(__fini_array_start = .); + PROVIDE_HIDDEN(__fini_array_start = .); KEEP(*(.fini_array*)) KEEP(*(SORT(.fini_array.*))) - PROVIDE(__fini_array_end = .); + PROVIDE_HIDDEN(__fini_array_end = .); } > SRAM .sram1_bss (NOLOAD) : @@ -243,8 +240,10 @@ SECTIONS { . = ALIGN(4); PROVIDE(__heap_start__ = .); + PROVIDE(__heap_start = .); KEEP(*(.heap)) . = ALIGN(4); + PROVIDE(__heap_end = .); PROVIDE(__heap_end__ = .); } > RAM_D2 diff --git a/core/startup_stm32h750xx.c b/core/startup_stm32h750xx.c index d51028089..c2a3f4c5c 100644 --- a/core/startup_stm32h750xx.c +++ b/core/startup_stm32h750xx.c @@ -1532,7 +1532,7 @@ int main(); extern void *_sidata, *_sdata, *_edata; extern void *_sbss, *_ebss; -void __attribute__((naked, noreturn)) Reset_Handler() +void __attribute__((noreturn)) Reset_Handler() { //Normally the CPU should will setup the based on the value from the first entry in the vector table. //If you encounter problems with accessing stack variables during initialization, ensure the line below is enabled. @@ -1557,7 +1557,7 @@ void __attribute__((naked, noreturn)) Reset_Handler() for (;;) ; } -void __attribute__((naked, noreturn)) Default_Handler() +void __attribute__((interrupt ("UNDEF"), noreturn)) Default_Handler() { //If you get stuck here, your code is missing a handler for some interrupt. //Define a 'DEBUG_DEFAULT_INTERRUPT_HANDLERS' macro via VisualGDB Project Properties and rebuild your project. diff --git a/examples/ADCMulti/CMakeLists.txt b/examples/ADCMulti/CMakeLists.txt new file mode 100644 index 000000000..d12cc9ee9 --- /dev/null +++ b/examples/ADCMulti/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME ADCMulti) +set(FIRMWARE_SOURCES ADCMulti.cpp) +include(DaisyProject) diff --git a/examples/ADCMux/CMakeLists.txt b/examples/ADCMux/CMakeLists.txt new file mode 100644 index 000000000..63f8b57f5 --- /dev/null +++ b/examples/ADCMux/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME ADCMux) +set(FIRMWARE_SOURCES ADCMux.cpp) +include(DaisyProject) diff --git a/examples/AudioOutput/CMakeLists.txt b/examples/AudioOutput/CMakeLists.txt new file mode 100644 index 000000000..d26cc2a86 --- /dev/null +++ b/examples/AudioOutput/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME AudioOutput) +set(FIRMWARE_SOURCES AudioOutput.cpp) +include(DaisyProject) diff --git a/examples/AudioPassthru/CMakeLists.txt b/examples/AudioPassthru/CMakeLists.txt new file mode 100644 index 000000000..8f4a30fb8 --- /dev/null +++ b/examples/AudioPassthru/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME AudioPassthru) +set(FIRMWARE_SOURCES AudioPassthru.cpp) +include(DaisyProject) diff --git a/examples/BootloaderBlink/CMakeLists.txt b/examples/BootloaderBlink/CMakeLists.txt new file mode 100644 index 000000000..d95522524 --- /dev/null +++ b/examples/BootloaderBlink/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME BootloaderBlink) +set(FIRMWARE_SOURCES main.cpp) +include(DaisyProject) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 000000000..ee6d8878e --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_path(SET LOCAL_CMAKE_PATH "../cmake") +cmake_path(ABSOLUTE_PATH LOCAL_CMAKE_PATH) + +list(APPEND CMAKE_MODULE_PATH ${LOCAL_CMAKE_PATH}) + +add_subdirectory(ADCMulti) +add_subdirectory(ADCMux) +add_subdirectory(AudioOutput) +add_subdirectory(AudioPassthru) +add_subdirectory(BootloaderBlink) +add_subdirectory(CopyingWavs) +add_subdirectory(DAC_Polling_Output) +add_subdirectory(Encoder) +add_subdirectory(ExternalCodec) +add_subdirectory(GateInput) +add_subdirectory(GPIO_Input) +add_subdirectory(GPIO_Output) +add_subdirectory(MIDI_UART_Input) +add_subdirectory(MIDI_USBH_Input) +add_subdirectory(OLED_SSD130x4WireSPI) +add_subdirectory(SDMMC_HelloWorld) +add_subdirectory(SerialPrint) +add_subdirectory(SerialRead) +add_subdirectory(SR_4021) +add_subdirectory(Switch) +add_subdirectory(Switch3) +add_subdirectory(TIM_SingleCallback) + +# Folders +add_subdirectory(uart) +add_subdirectory(SPI) diff --git a/examples/CopyingWavs/CMakeLists.txt b/examples/CopyingWavs/CMakeLists.txt new file mode 100644 index 000000000..57d25b357 --- /dev/null +++ b/examples/CopyingWavs/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME CopyingWavs) +set(FIRMWARE_SOURCES CopyingWavs.cpp) +include(DaisyProject) diff --git a/examples/DAC_Polling_Output/CMakeLists.txt b/examples/DAC_Polling_Output/CMakeLists.txt new file mode 100644 index 000000000..a29136ba6 --- /dev/null +++ b/examples/DAC_Polling_Output/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME DAC_Polling_Output) +set(FIRMWARE_SOURCES DAC_Polling_Output.cpp) +include(DaisyProject) diff --git a/examples/Encoder/CMakeLists.txt b/examples/Encoder/CMakeLists.txt new file mode 100644 index 000000000..acab7ace4 --- /dev/null +++ b/examples/Encoder/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Encoder) +set(FIRMWARE_SOURCES Encoder.cpp) +include(DaisyProject) diff --git a/examples/ExternalCodec/CMakeLists.txt b/examples/ExternalCodec/CMakeLists.txt new file mode 100644 index 000000000..7fbe6772d --- /dev/null +++ b/examples/ExternalCodec/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME ExternalCodec) +set(FIRMWARE_SOURCES ExternalCodec.cpp) +include(DaisyProject) diff --git a/examples/GPIO_Input/CMakeLists.txt b/examples/GPIO_Input/CMakeLists.txt new file mode 100644 index 000000000..0ae6a0477 --- /dev/null +++ b/examples/GPIO_Input/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME GPIO_Input) +set(FIRMWARE_SOURCES GPIO_Input.cpp) +include(DaisyProject) diff --git a/examples/GPIO_Output/CMakeLists.txt b/examples/GPIO_Output/CMakeLists.txt new file mode 100644 index 000000000..097bbe60d --- /dev/null +++ b/examples/GPIO_Output/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME GPIO_Output) +set(FIRMWARE_SOURCES GPIO_Output.cpp) +include(DaisyProject) diff --git a/examples/GateInput/CMakeLists.txt b/examples/GateInput/CMakeLists.txt new file mode 100644 index 000000000..3accefe9f --- /dev/null +++ b/examples/GateInput/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME GateInput) +set(FIRMWARE_SOURCES GateInput.cpp) +include(DaisyProject) diff --git a/examples/MIDI_UART_Input/CMakeLists.txt b/examples/MIDI_UART_Input/CMakeLists.txt new file mode 100644 index 000000000..5aa83081d --- /dev/null +++ b/examples/MIDI_UART_Input/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME MIDI_UART_Input) +set(FIRMWARE_SOURCES MIDI_UART_Input.cpp) +include(DaisyProject) diff --git a/examples/MIDI_USBH_Input/CMakeLists.txt b/examples/MIDI_USBH_Input/CMakeLists.txt new file mode 100644 index 000000000..b14dfaa3d --- /dev/null +++ b/examples/MIDI_USBH_Input/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME MIDI_USBH_Input) +set(FIRMWARE_SOURCES MIDI_USBH_Input.cpp) +include(DaisyProject) diff --git a/examples/OLED_SPI/CMakeLists.txt b/examples/OLED_SPI/CMakeLists.txt new file mode 100644 index 000000000..6eba82e20 --- /dev/null +++ b/examples/OLED_SPI/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME OLED_SPI) +set(FIRMWARE_SOURCES OledSPI.cpp) +include(DaisyProject) diff --git a/examples/OLED_SSD130x4WireSPI/CMakeLists.txt b/examples/OLED_SSD130x4WireSPI/CMakeLists.txt new file mode 100644 index 000000000..ad8b37485 --- /dev/null +++ b/examples/OLED_SSD130x4WireSPI/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME OLED_SSD130x4WireSPI) +set(FIRMWARE_SOURCES OLED_SSD130x4WireSPI.cpp) +include(DaisyProject) diff --git a/examples/OLED_SoftSPI/CMakeLists.txt b/examples/OLED_SoftSPI/CMakeLists.txt new file mode 100644 index 000000000..a5aaf5ead --- /dev/null +++ b/examples/OLED_SoftSPI/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME OLED_SoftSPI) +set(FIRMWARE_SOURCES OledSoftSPI.cpp) +include(DaisyProject) diff --git a/examples/SDMMC_HelloWorld/CMakeLists.txt b/examples/SDMMC_HelloWorld/CMakeLists.txt new file mode 100644 index 000000000..81e3ecff3 --- /dev/null +++ b/examples/SDMMC_HelloWorld/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME SDMMC_HelloWorld) +set(FIRMWARE_SOURCES SDMMC_HelloWorld.cpp) +include(DaisyProject) diff --git a/examples/SPI/CMakeLists.txt b/examples/SPI/CMakeLists.txt new file mode 100644 index 000000000..7d43e15d1 --- /dev/null +++ b/examples/SPI/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(SpiBlockingTransmit) +add_subdirectory(SpiDmaTransmit) diff --git a/examples/SPI/SpiBlockingTransmit/CMakeLists.txt b/examples/SPI/SpiBlockingTransmit/CMakeLists.txt new file mode 100644 index 000000000..85de74c0c --- /dev/null +++ b/examples/SPI/SpiBlockingTransmit/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME SpiBlockingTransmit) +set(FIRMWARE_SOURCES SpiBlockingTransmit.cpp) +include(DaisyProject) diff --git a/examples/SPI/SpiDmaTransmit/CMakeLists.txt b/examples/SPI/SpiDmaTransmit/CMakeLists.txt new file mode 100644 index 000000000..5ff53f74b --- /dev/null +++ b/examples/SPI/SpiDmaTransmit/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME SpiDmaTransmit) +set(FIRMWARE_SOURCES SpiDmaTransmit.cpp) +include(DaisyProject) diff --git a/examples/SR_4021/CMakeLists.txt b/examples/SR_4021/CMakeLists.txt new file mode 100644 index 000000000..ee99373b2 --- /dev/null +++ b/examples/SR_4021/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME SR_4021) +set(FIRMWARE_SOURCES SR_4021.cpp) +include(DaisyProject) diff --git a/examples/SerialPrint/CMakeLists.txt b/examples/SerialPrint/CMakeLists.txt new file mode 100644 index 000000000..6b73edb4d --- /dev/null +++ b/examples/SerialPrint/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME SerialPrint) +set(FIRMWARE_SOURCES SerialPrint.cpp) +include(DaisyProject) diff --git a/examples/SerialRead/CMakeLists.txt b/examples/SerialRead/CMakeLists.txt new file mode 100644 index 000000000..e3e2e0962 --- /dev/null +++ b/examples/SerialRead/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME SerialRead) +set(FIRMWARE_SOURCES SerialRead.cpp) +include(DaisyProject) diff --git a/examples/Switch/CMakeLists.txt b/examples/Switch/CMakeLists.txt new file mode 100644 index 000000000..f081de65e --- /dev/null +++ b/examples/Switch/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Switch) +set(FIRMWARE_SOURCES Switch.cpp) +include(DaisyProject) diff --git a/examples/Switch3/CMakeLists.txt b/examples/Switch3/CMakeLists.txt new file mode 100644 index 000000000..7fe62be3a --- /dev/null +++ b/examples/Switch3/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Switch3) +set(FIRMWARE_SOURCES Switch3.cpp) +include(DaisyProject) diff --git a/examples/TIM_SingleCallback/CMakeLists.txt b/examples/TIM_SingleCallback/CMakeLists.txt new file mode 100644 index 000000000..3755891f1 --- /dev/null +++ b/examples/TIM_SingleCallback/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME TIM_SingleCallback) +set(FIRMWARE_SOURCES TIM_SingleCallback.cpp) +include(DaisyProject) diff --git a/examples/uart/Blocking_Receive/CMakeLists.txt b/examples/uart/Blocking_Receive/CMakeLists.txt new file mode 100644 index 000000000..066276b32 --- /dev/null +++ b/examples/uart/Blocking_Receive/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Blocking_Receive) +set(FIRMWARE_SOURCES Blocking_Receive.cpp) +include(DaisyProject) diff --git a/examples/uart/Blocking_Transmit/CMakeLists.txt b/examples/uart/Blocking_Transmit/CMakeLists.txt new file mode 100644 index 000000000..77dc319e0 --- /dev/null +++ b/examples/uart/Blocking_Transmit/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Blocking_Transmit) +set(FIRMWARE_SOURCES Blocking_Transmit.cpp) +include(DaisyProject) diff --git a/examples/uart/Blocking_Transmit_Dma_Receive/CMakeLists.txt b/examples/uart/Blocking_Transmit_Dma_Receive/CMakeLists.txt new file mode 100644 index 000000000..cb0d1458e --- /dev/null +++ b/examples/uart/Blocking_Transmit_Dma_Receive/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Blocking_Transmit_Dma_Receive) +set(FIRMWARE_SOURCES Blocking_Transmit_Dma_Receive.cpp) +include(DaisyProject) diff --git a/examples/uart/Blocking_Transmit_Fifo_Receive/CMakeLists.txt b/examples/uart/Blocking_Transmit_Fifo_Receive/CMakeLists.txt new file mode 100644 index 000000000..ecbca9f23 --- /dev/null +++ b/examples/uart/Blocking_Transmit_Fifo_Receive/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Blocking_Transmit_Fifo_Receive) +set(FIRMWARE_SOURCES Blocking_Transmit_Fifo_Receive.cpp) +include(DaisyProject) diff --git a/examples/uart/CMakeLists.txt b/examples/uart/CMakeLists.txt new file mode 100644 index 000000000..27a87fba1 --- /dev/null +++ b/examples/uart/CMakeLists.txt @@ -0,0 +1,9 @@ +add_subdirectory(Blocking_Receive) +add_subdirectory(Blocking_Transmit) +add_subdirectory(Blocking_Transmit_Dma_Receive) +add_subdirectory(Blocking_Transmit_Fifo_Receive) +add_subdirectory(Dma_Fifo_Receive) +add_subdirectory(Dma_Receive) +add_subdirectory(Dma_Transmit) +add_subdirectory(Dma_Transmit_Blocking_Receive) +add_subdirectory(Dma_Transmit_Dma_Receive) diff --git a/examples/uart/Dma_Fifo_Receive/CMakeLists.txt b/examples/uart/Dma_Fifo_Receive/CMakeLists.txt new file mode 100644 index 000000000..5530d4d18 --- /dev/null +++ b/examples/uart/Dma_Fifo_Receive/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Dma_Fifo_Receive) +set(FIRMWARE_SOURCES Dma_Fifo_Receive.cpp) +include(DaisyProject) diff --git a/examples/uart/Dma_Receive/CMakeLists.txt b/examples/uart/Dma_Receive/CMakeLists.txt new file mode 100644 index 000000000..976638e7f --- /dev/null +++ b/examples/uart/Dma_Receive/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Dma_Receive) +set(FIRMWARE_SOURCES Dma_Receive.cpp) +include(DaisyProject) diff --git a/examples/uart/Dma_Transmit/CMakeLists.txt b/examples/uart/Dma_Transmit/CMakeLists.txt new file mode 100644 index 000000000..22a227da4 --- /dev/null +++ b/examples/uart/Dma_Transmit/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Dma_Transmit) +set(FIRMWARE_SOURCES Dma_Transmit.cpp) +include(DaisyProject) diff --git a/examples/uart/Dma_Transmit_Blocking_Receive/CMakeLists.txt b/examples/uart/Dma_Transmit_Blocking_Receive/CMakeLists.txt new file mode 100644 index 000000000..28e4968ac --- /dev/null +++ b/examples/uart/Dma_Transmit_Blocking_Receive/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Dma_Transmit_Blocking_Receive) +set(FIRMWARE_SOURCES Dma_Transmit_Blocking_Receive.cpp) +include(DaisyProject) diff --git a/examples/uart/Dma_Transmit_Dma_Receive/CMakeLists.txt b/examples/uart/Dma_Transmit_Dma_Receive/CMakeLists.txt new file mode 100644 index 000000000..644eb4025 --- /dev/null +++ b/examples/uart/Dma_Transmit_Dma_Receive/CMakeLists.txt @@ -0,0 +1,3 @@ +set(FIRMWARE_NAME Dma_Transmit_Dma_Receive) +set(FIRMWARE_SOURCES Dma_Transmit_Dma_Receive.cpp) +include(DaisyProject) diff --git a/src/dev/icm20948.h b/src/dev/icm20948.h index c782e35d1..d814a6e03 100644 --- a/src/dev/icm20948.h +++ b/src/dev/icm20948.h @@ -437,8 +437,6 @@ class Icm20948 Result SetupMag() { - uint8_t buffer[2]; - SetI2CBypass(false); ConfigureI2CMaster(); diff --git a/src/per/i2c.cpp b/src/per/i2c.cpp index 45eb4d230..8055a87ec 100644 --- a/src/per/i2c.cpp +++ b/src/per/i2c.cpp @@ -223,10 +223,9 @@ I2CHandle::Result I2CHandle::Impl::Init(const I2CHandle::Config& config) && (config.address > 127 || config.address < 16 || config.address > 119)) return I2CHandle::Result::ERR; - config_ = config; - constexpr I2C_TypeDef* instances[4] - = {I2C1, I2C2, I2C3, I2C4}; // map HAL instances - i2c_hal_handle_.Instance = instances[i2cIdx]; + config_ = config; + I2C_TypeDef* instances[4] = {I2C1, I2C2, I2C3, I2C4}; // map HAL instances + i2c_hal_handle_.Instance = instances[i2cIdx]; // Set Generic Parameters // Configure Speed diff --git a/src/per/qspi.cpp b/src/per/qspi.cpp index 970a6a4f4..0dd51e45e 100644 --- a/src/per/qspi.cpp +++ b/src/per/qspi.cpp @@ -53,7 +53,7 @@ class QSPIHandle::Impl QSPI_HandleTypeDef* GetHalHandle(); - size_t GetNumPins() { return pin_count_; } + constexpr size_t GetNumPins() { return pin_count_; } Status GetStatus() { return status_; } diff --git a/src/per/sai.cpp b/src/per/sai.cpp index d581f99c5..f8cc2848d 100644 --- a/src/per/sai.cpp +++ b/src/per/sai.cpp @@ -84,8 +84,8 @@ SaiHandle::Result SaiHandle::Impl::Init(const SaiHandle::Config& config) buff_size_ = 0; config_ = config; - constexpr SAI_Block_TypeDef* a_instances[2] = {SAI1_Block_A, SAI2_Block_A}; - constexpr SAI_Block_TypeDef* b_instances[2] = {SAI1_Block_B, SAI2_Block_B}; + SAI_Block_TypeDef* a_instances[2] = {SAI1_Block_A, SAI2_Block_A}; + SAI_Block_TypeDef* b_instances[2] = {SAI1_Block_B, SAI2_Block_B}; sai_a_handle_.Instance = a_instances[sai_idx]; sai_b_handle_.Instance = b_instances[sai_idx]; @@ -148,8 +148,8 @@ SaiHandle::Result SaiHandle::Impl::Init(const SaiHandle::Config& config) // Bitdepth / protocol (currently based on bitdepth..) // TODO probably split these up for better flexibility.. // These are also currently fixed to be the same per block. - uint8_t bd; - uint32_t protocol; + uint8_t bd = SAI_PROTOCOL_DATASIZE_16BIT; + uint32_t protocol = SAI_I2S_STANDARD; switch(config.bit_depth) { case Config::BitDepth::SAI_16BIT: @@ -165,7 +165,6 @@ SaiHandle::Result SaiHandle::Impl::Init(const SaiHandle::Config& config) bd = SAI_PROTOCOL_DATASIZE_32BIT; protocol = SAI_I2S_STANDARD; break; - default: break; } // Generic Inits that we don't have API control over. diff --git a/src/per/spi.cpp b/src/per/spi.cpp index 2b56034c9..03844599a 100644 --- a/src/per/spi.cpp +++ b/src/per/spi.cpp @@ -115,7 +115,7 @@ static SpiHandle::Impl spi_handles[6]; SpiHandle::Impl* MapInstanceToHandle(SPI_TypeDef* instance) { // map HAL instances - constexpr SPI_TypeDef* instances[6] = {SPI1, SPI2, SPI3, SPI4, SPI5, SPI6}; + SPI_TypeDef* instances[6] = {SPI1, SPI2, SPI3, SPI4, SPI5, SPI6}; for(int i = 0; i < 6; i++) { diff --git a/src/per/tim.cpp b/src/per/tim.cpp index 6c593452b..0a3fa8544 100644 --- a/src/per/tim.cpp +++ b/src/per/tim.cpp @@ -93,8 +93,8 @@ TimerHandle::Result TimerHandle::Impl::Init(const TimerHandle::Config& config) const int tim_idx = int(config.periph); if(tim_idx >= 4) return TimerHandle::Result::ERR; - config_ = config; - constexpr TIM_TypeDef* instances[4] = {TIM2, TIM3, TIM4, TIM5}; + config_ = config; + TIM_TypeDef* instances[4] = {TIM2, TIM3, TIM4, TIM5}; // HAL Initialization tim_hal_handle_.Instance = instances[tim_idx]; diff --git a/src/per/uart.cpp b/src/per/uart.cpp index 4d0658a16..eaa5d5ac5 100644 --- a/src/per/uart.cpp +++ b/src/per/uart.cpp @@ -158,15 +158,15 @@ static UartHandler::Impl uart_handles[9]; UartHandler::Impl* MapInstanceToHandle(USART_TypeDef* instance) { - constexpr USART_TypeDef* instances[9] = {USART1, - USART2, - USART3, - UART4, - UART5, - USART6, - UART7, - UART8, - LPUART1}; // map HAL instances + USART_TypeDef* instances[9] = {USART1, + USART2, + USART3, + UART4, + UART5, + USART6, + UART7, + UART8, + LPUART1}; // map HAL instances for(int i = 0; i < 9; i++) { if(instance == instances[i]) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..cfdd48850 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,72 @@ +cmake_minimum_required(VERSION 3.16) +project(daisy-test) + +find_package(Threads REQUIRED) +add_subdirectory(googletest) +include(GoogleTest) + +set(MODULE_DIR ../src) + +# if we're not cross-compiling, we can do unit tests +add_library(daisy STATIC + ${MODULE_DIR}/hid/midi_parser.cpp + ${MODULE_DIR}/per/qspi.cpp + ${MODULE_DIR}/sys/system.cpp + ${MODULE_DIR}/ui/AbstractMenu.cpp + ${MODULE_DIR}/ui/UI.cpp + ${MODULE_DIR}/util/MappedValue.cpp + ${MODULE_DIR}/util/oled_fonts.c +) +target_include_directories(daisy PUBLIC ${MODULE_DIR}) +target_compile_definitions(daisy PUBLIC UNIT_TEST) + +# needed because some internal libDaisy testing stuff includes gtest +target_link_libraries(daisy PUBLIC GTest::gtest_main) + +enable_testing() + +# Add a gtest +function(add_gtest source_file) + cmake_path(GET source_file STEM test_name) + + # Create the target + add_executable(${test_name} ${source_file}) + + # Link it against the required libraries + target_link_libraries(${test_name} PUBLIC + daisy + Threads::Threads + GTest::gtest_main + ) + + # Set any compile definitions + target_compile_definitions(${test_name} PRIVATE + UNIT_TEST + ) + + # Set the properties + set_target_properties(${test_name} PROPERTIES + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED YES + C_STANDARD 11 + C_STANDARD_REQUIRED YES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + ) + + # Add the target as a test + #add_test(NAME ${test_name} COMMAND ${test_name} --verbose) + + # Discover unit tests inside it + gtest_discover_tests(${test_name}) +endfunction(add_gtest) + +# Generate test executables from files ending in *_gtest.cpp +function(autogen_gtests test_folder) + file(GLOB_RECURSE specs ${test_folder}/*_gtest.cpp) + + foreach(spec IN LISTS specs) + add_gtest(${spec}) + endforeach() +endfunction() + +autogen_gtests(${CMAKE_CURRENT_LIST_DIR} daisy) diff --git a/tests/googletest b/tests/googletest index f5e592d8e..9d43b27f7 160000 --- a/tests/googletest +++ b/tests/googletest @@ -1 +1 @@ -Subproject commit f5e592d8ee5ffb1d9af5be7f715ce3576b8bf9c4 +Subproject commit 9d43b27f7a873596496a2ea70721b3f9eb82df01