diff --git a/.github/actions/setup_toolchain/action.yml b/.github/actions/setup_toolchain/action.yml index b8bf6e1cc..e969303b6 100644 --- a/.github/actions/setup_toolchain/action.yml +++ b/.github/actions/setup_toolchain/action.yml @@ -32,18 +32,10 @@ runs: - name: Get Toolchain URL if: >- inputs.toolchain != 'arm-gcc' && - inputs.toolchain != 'arm-iar' && inputs.toolchain != 'esp-idf' id: set-toolchain-url run: | - TOOLCHAIN_JSON='{ - "aarch64-gcc": "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz", - "arm-clang": "https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-17.0.1/LLVMEmbeddedToolchainForArm-17.0.1-Linux-x86_64.tar.xz", - "msp430-gcc": "http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2", - "riscv-gcc": "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-linux-x64.tar.gz", - "rx-gcc": "http://gcc-renesas.com/downloads/get.php?f=rx/8.3.0.202004-gnurx/gcc-8.3.0.202004-GNURX-ELF.run" - }' - TOOLCHAIN_URL=$(echo $TOOLCHAIN_JSON | jq -r '.["${{ inputs.toolchain }}"]') + TOOLCHAIN_URL=$(jq -r '."${{ inputs.toolchain }}"' .github/actions/setup_toolchain/toolchain.json) echo "toolchain_url=$TOOLCHAIN_URL" echo "toolchain_url=$TOOLCHAIN_URL" >> $GITHUB_OUTPUT shell: bash @@ -51,9 +43,21 @@ runs: - name: Download Toolchain if: >- inputs.toolchain != 'arm-gcc' && - inputs.toolchain != 'arm-iar' && inputs.toolchain != 'esp-idf' uses: ./.github/actions/setup_toolchain/download with: toolchain: ${{ inputs.toolchain }} toolchain_url: ${{ steps.set-toolchain-url.outputs.toolchain_url }} + + - name: Set toolchain option + id: set-toolchain-option + run: | + BUILD_OPTION="" + if [[ "${{ inputs.toolchain }}" == *"clang"* ]]; then + BUILD_OPTION="--toolchain clang" + elif [[ "${{ inputs.toolchain }}" == "arm-iar" ]]; then + BUILD_OPTION="--toolchain iar" + fi + echo "build_option=$BUILD_OPTION" + echo "build_option=$BUILD_OPTION" >> $GITHUB_OUTPUT + shell: bash diff --git a/.github/actions/setup_toolchain/download/action.yml b/.github/actions/setup_toolchain/download/action.yml index 2af456ef8..ce9643010 100644 --- a/.github/actions/setup_toolchain/download/action.yml +++ b/.github/actions/setup_toolchain/download/action.yml @@ -23,11 +23,25 @@ runs: if: steps.cache-toolchain-download.outputs.cache-hit != 'true' run: | mkdir -p ~/cache/${{ inputs.toolchain }} - wget --progress=dot:giga ${{ inputs.toolchain_url }} -O toolchain.tar.gz - tar -C ~/cache/${{ inputs.toolchain }} -xaf toolchain.tar.gz + + if [[ ${{ inputs.toolchain }} == rx-gcc ]]; then + wget --progress=dot:giga ${{ inputs.toolchain_url }} -O toolchain.run + chmod +x toolchain.run + ./toolchain.run -p ~/cache/${{ inputs.toolchain }}/gnurx -y + elif [[ ${{ inputs.toolchain }} == arm-iar ]]; then + wget --progress=dot:giga ${{ inputs.toolchain_url }} -O ~/cache/${{ inputs.toolchain }}/cxarm.deb + else + wget --progress=dot:giga ${{ inputs.toolchain_url }} -O toolchain.tar.gz + tar -C ~/cache/${{ inputs.toolchain }} -xaf toolchain.tar.gz + fi shell: bash - - name: Set Toolchain Path + - name: Setup Toolchain run: | - echo >> $GITHUB_PATH `echo ~/cache/${{ inputs.toolchain }}/*/bin` + if [[ ${{ inputs.toolchain }} == arm-iar ]]; then + sudo apt-get install -y ~/cache/${{ inputs.toolchain }}/cxarm.deb + echo >> $GITHUB_PATH "/opt/iar/cxarm/arm/bin" + else + echo >> $GITHUB_PATH `echo ~/cache/${{ inputs.toolchain }}/*/bin` + fi shell: bash diff --git a/.github/actions/setup_toolchain/toolchain.json b/.github/actions/setup_toolchain/toolchain.json new file mode 100644 index 000000000..f7123ef11 --- /dev/null +++ b/.github/actions/setup_toolchain/toolchain.json @@ -0,0 +1,9 @@ +{ + "aarch64-gcc": "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz", + "arm-clang": "https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-19.1.1/LLVM-ET-Arm-19.1.1-Linux-x86_64.tar.xz", + "arm-gcc": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v14.2.1-1.1/xpack-arm-none-eabi-gcc-14.2.1-1.1-linux-x64.tar.gz", + "msp430-gcc": "http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2", + "riscv-gcc": "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-linux-x64.tar.gz", + "rx-gcc": "https://github.com/hathach/rx_device/releases/download/0.0.1/gcc-8.3.0.202411-GNURX-ELF.run", + "arm-iar": "https://netstorage.iar.com/FileStore/STANDARD/001/003/583/cxarm-9.60.4.deb" +} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9ed9bad39..921df4199 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,7 +53,7 @@ jobs: # --------------------------------------- # Build ARM # --------------------------------------- - arm: + arm-make: needs: set-matrix uses: ./.github/workflows/build_util.yml strategy: @@ -65,8 +65,6 @@ jobs: - 'lpc55' - 'mimxrt10xx' - 'stm32f3' - - 'stm32f4' - - 'stm32h5' - 'stm32l4' with: port: ${{ matrix.port }} @@ -74,6 +72,27 @@ jobs: build-system: 'make' toolchain: 'arm-gcc' + # --------------------------------------- + # Build ARM with CMake + # --------------------------------------- + arm-cmake: + needs: set-matrix + uses: ./.github/workflows/build_util.yml + strategy: + fail-fast: false + matrix: + port: + # Alphabetical order by family + # - 'stm32f303disco' # overflows flash + - 'stm32f4' + - 'stm32h5' + with: + port: ${{ matrix.port }} + boards: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.port].board) }} + build-system: 'cmake' + toolchain: 'arm-gcc' + + # --------------------------------------- # Build ESP # --------------------------------------- @@ -115,41 +134,3 @@ jobs: uses: ./.github/workflows/build_ghostfat.yml with: boards: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)['test_ghostfat'].board) }} - - # --------------------------------------- - # Build ARM with CMake - # --------------------------------------- - arm-cmake: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - board: - # Alphabetical order by family - #- 'metro_m7_1011' - # - 'stm32f303disco' # overflows flash - - 'stm32f411ve_discovery' - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: true - - - name: Fetch tags - run: git fetch --tags - - - name: Install ARM GCC - uses: carlosperate/arm-none-eabi-gcc-action@v1 - with: - release: '11.2-2022.02' - - - name: Get Dependencies - run: | - sudo apt install -y ninja-build - python tools/get_deps.py --board ${{ matrix.board }} - - - name: Build - run: | - cmake . -B _build -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DBOARD=${{ matrix.board }} - cmake --build _build diff --git a/.github/workflows/build_util.yml b/.github/workflows/build_util.yml index 1555ef171..962482f23 100644 --- a/.github/workflows/build_util.yml +++ b/.github/workflows/build_util.yml @@ -51,9 +51,14 @@ jobs: - name: Build if: inputs.toolchain != 'esp-idf' run: | - make -C ports/${{ inputs.port }} BOARD=${{ matrix.board }} all self-update copy-artifact - if [ -d "ports/${{ inputs.port }}/apps" ]; then - for app in ports/${{ inputs.port }}/apps/*/; do if [ $app != 'apps/self_update/' ]; then make -C $app BOARD=${{ matrix.board }} all; fi done + if [[ ${{ inputs.build-system }} == cmake ]]; then + cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DBOARD=${{ matrix.board }} ports/${{ inputs.port }} + cmake --build build + else + make -C ports/${{ inputs.port }} BOARD=${{ matrix.board }} all self-update copy-artifact + if [ -d "ports/${{ inputs.port }}/apps" ]; then + for app in ports/${{ inputs.port }}/apps/*/; do if [ $app != 'apps/self_update/' ]; then make -C $app BOARD=${{ matrix.board }} all; fi done + fi fi - name: Build using ESP-IDF docker @@ -70,9 +75,13 @@ jobs: run: | if [ ${{ inputs.toolchain }} == 'esp-idf' ]; then zip -jr tinyuf2-${{ matrix.board }}-${{ github.event.release.tag_name }}.zip ${{ env.BIN_PATH }} - cp ${{ env.BIN_PATH }}/update-tinyuf2.uf2 update-tinyuf2-${{ matrix.board }}-${{ github.event.release.tag_name }}.uf2 + cp ${{ env.BIN_PATH }}/apps/update-tinyuf2.uf2 update-tinyuf2-${{ matrix.board }}-${{ github.event.release.tag_name }}.uf2 else - for f in ${{ env.BIN_PATH }}/*; do mv $f ${f%.*}-${{ github.event.release.tag_name }}."${f#*.}"; done + if [[ ${{ inputs.build-system }} == cmake ]]; then + cp ${{ env.BIN_PATH }}/apps/update-tinyuf2.uf2 update-tinyuf2-${{ matrix.board }}-${{ github.event.release.tag_name }}.uf2 + else + cp ${{ env.BIN_PATH }}/apps/update-tinyuf2-${{ matrix.board }}.uf2 update-tinyuf2-${{ matrix.board }}-${{ github.event.release.tag_name }}.uf2 + fi zip -jr tinyuf2-${{ matrix.board }}-${{ github.event.release.tag_name }}.zip ${{ env.BIN_PATH }} fi @@ -82,7 +91,7 @@ jobs: with: files: | tinyuf2-${{ matrix.board }}-*.zip - ${{ env.BIN_PATH }}/update-tinyuf2-${{ matrix.board }}-*.uf2 + update-tinyuf2-${{ matrix.board }}-${{ github.event.release.tag_name }}.uf2 - name: Upload Release Assets To AWS S3 env: diff --git a/.idea/debugServers/imxrt1011.xml b/.idea/debugServers/imxrt1011.xml new file mode 100644 index 000000000..780a9825d --- /dev/null +++ b/.idea/debugServers/imxrt1011.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/debugServers/stm32f411.xml b/.idea/debugServers/stm32f411.xml new file mode 100644 index 000000000..0abcfb1b3 --- /dev/null +++ b/.idea/debugServers/stm32f411.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/ports/stm32h5/apps/blinky/CMakeLists.txt b/apps/blinky/CMakeLists.txt similarity index 53% rename from ports/stm32h5/apps/blinky/CMakeLists.txt rename to apps/blinky/CMakeLists.txt index 59c204276..c3af77ca1 100644 --- a/ports/stm32h5/apps/blinky/CMakeLists.txt +++ b/apps/blinky/CMakeLists.txt @@ -1,24 +1,24 @@ #------------------------------------ +# Application # This file is meant to be include by add_subdirectory() in the root CMakeLists.txt #------------------------------------ +cmake_minimum_required(VERSION 3.17) + +include(${FAMILY_PATH}/app.cmake) -# self_update target add_executable(blinky - ${TOP}/apps/blinky/blinky.c - ${CMAKE_CURRENT_LIST_DIR}/../../boards.c - ${CMAKE_CURRENT_LIST_DIR}/../../board_flash.c + src/blinky.c + ${FAMILY_PATH}/boards.c +# ${FAMILY_PATH}/board_flash.c ) target_include_directories(blinky PUBLIC ${TOP}/src ) target_compile_definitions(blinky PUBLIC - BUILD_NO_TINYUSB BUILD_APPLICATION - ) -target_link_options(blinky PUBLIC - "LINKER:--script=${CMAKE_CURRENT_LIST_DIR}/../../linker/stm32h5_app.ld" + BUILD_NO_TINYUSB ) -family_configure_common(blinky) -family_add_uf2(blinky ${UF2_FAMILY_ID}) +family_configure_app(blinky) +family_gen_uf2(blinky ${UF2_FAMILY_ID}) family_flash_uf2(blinky ${UF2_FAMILY_ID}) diff --git a/apps/blinky/blinky.c b/apps/blinky/src/blinky.c similarity index 83% rename from apps/blinky/blinky.c rename to apps/blinky/src/blinky.c index bd4a48928..db279d738 100644 --- a/apps/blinky/blinky.c +++ b/apps/blinky/src/blinky.c @@ -32,14 +32,12 @@ //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM DECLARATION //--------------------------------------------------------------------+ -uint8_t const RGB_WRITING[] = { 0xcc, 0x66, 0x00 }; -uint8_t const RGB_OFF[] = { 0x00, 0x00, 0x00 }; +uint8_t const RGB_WRITING[] = { 0xcc, 0x66, 0x00 }; +uint8_t const RGB_OFF[] = { 0x00, 0x00, 0x00 }; static volatile uint32_t _timer_count = 0; int main(void) { - TUF2_LOG1_LOCATION(); board_init(); - TUF2_LOG1_LOCATION(); board_timer_start(1); while (1) { @@ -47,19 +45,12 @@ int main(void) { } } -void board_timer_handler(void) -{ +void board_timer_handler(void) { _timer_count++; - if ((_timer_count & 0xfful) == 0) { - // Fast toggle with both LED and RGB - static bool is_on = false; - is_on = !is_on; + const uint32_t is_on = (_timer_count >> 8) & 0x1u; - // fast blink LED if available board_led_write(is_on ? 0xff : 0x000); - - // blink RGB if available board_rgb_write(is_on ? RGB_WRITING : RGB_OFF); } } @@ -75,9 +66,8 @@ void board_timer_handler(void) #include "SEGGER_RTT.h" #endif -__attribute__ ((used)) int _write (int fhdl, const void *buf, size_t count) -{ - (void) fhdl; +__attribute__ ((used)) int _write(int fhdl, const void* buf, size_t count) { + (void)fhdl; #if defined(LOGGER_RTT) SEGGER_RTT_Write(0, (char*) buf, (int) count); diff --git a/ports/mimxrt10xx/apps/erase_firmware/CMakeLists.txt b/apps/erase_firmware/CMakeLists.txt similarity index 60% rename from ports/mimxrt10xx/apps/erase_firmware/CMakeLists.txt rename to apps/erase_firmware/CMakeLists.txt index 6b66b852f..3d636c26a 100644 --- a/ports/mimxrt10xx/apps/erase_firmware/CMakeLists.txt +++ b/apps/erase_firmware/CMakeLists.txt @@ -4,20 +4,20 @@ #------------------------------------ cmake_minimum_required(VERSION 3.17) -include(${CMAKE_CURRENT_LIST_DIR}/../app.cmake) +include(${FAMILY_PATH}/app.cmake) -#------------------------------------ -# Application -#------------------------------------ add_executable(erase_firmware - ${TOP}/apps/erase_firmware/erase_firmware.c - ${CMAKE_CURRENT_LIST_DIR}/../../boards.c + src/erase_firmware.c + ${FAMILY_PATH}/boards.c ) target_include_directories(erase_firmware PUBLIC ${TOP}/src ) target_compile_definitions(erase_firmware PUBLIC + BUILD_APPLICATION BUILD_NO_TINYUSB ) -configure_app(erase_firmware) +family_configure_app(erase_firmware) +family_gen_uf2(erase_firmware ${UF2_FAMILY_ID}) +family_flash_uf2(erase_firmware ${UF2_FAMILY_ID}) diff --git a/apps/erase_firmware/erase_firmware.c b/apps/erase_firmware/src/erase_firmware.c similarity index 100% rename from apps/erase_firmware/erase_firmware.c rename to apps/erase_firmware/src/erase_firmware.c diff --git a/apps/self_update/CMakeLists.txt b/apps/self_update/CMakeLists.txt new file mode 100644 index 000000000..baef9e0c3 --- /dev/null +++ b/apps/self_update/CMakeLists.txt @@ -0,0 +1,33 @@ +#------------------------------------ +# Application +# This file is meant to be include by add_subdirectory() in the root CMakeLists.txt +#------------------------------------ +cmake_minimum_required(VERSION 3.17) + +include(${FAMILY_PATH}/app.cmake) + +# Generate bootloader_bin.c +add_custom_command(OUTPUT bootloader_bin.c + COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} --carray -o ${CMAKE_CURRENT_BINARY_DIR}/bootloader_bin.c $/tinyuf2.bin + DEPENDS tinyuf2 + ) + +add_executable(update-tinyuf2 + self_update.c + ${FAMILY_PATH}/boards.c + ${FAMILY_PATH}/board_flash.c + ${CMAKE_CURRENT_BINARY_DIR}/bootloader_bin.c + ) + +target_include_directories(update-tinyuf2 PUBLIC + ${TOP}/src + ) +target_compile_definitions(update-tinyuf2 PUBLIC + TINYUF2_SELF_UPDATE + BUILD_NO_TINYUSB + BUILD_APPLICATION + ) + +family_configure_app(update-tinyuf2) +family_gen_uf2(update-tinyuf2 ${UF2_FAMILY_ID}) +family_flash_uf2(update-tinyuf2 ${UF2_FAMILY_ID}) diff --git a/ports/ch32v20x/family.cmake b/ports/ch32v20x/family.cmake index 4f22dfc97..14e9c47b1 100644 --- a/ports/ch32v20x/family.cmake +++ b/ports/ch32v20x/family.cmake @@ -1,4 +1,4 @@ -include_guard() +include_guard(GLOBAL) set(UF2_FAMILY_ID 0x699b62ec) set(CH32_FAMILY ch32v20x) diff --git a/ports/espressif/CMakeLists.txt b/ports/espressif/CMakeLists.txt index 2e847ec0c..5a8fc015b 100644 --- a/ports/espressif/CMakeLists.txt +++ b/ports/espressif/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.17) include(${CMAKE_CURRENT_LIST_DIR}/../family_support.cmake) -include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) # Must be set before including IDF project.cmake set(EXTRA_COMPONENT_DIRS ${TOP}/src ${CMAKE_CURRENT_LIST_DIR}/boards) @@ -32,9 +31,6 @@ cmake_print_variables(GIT_VERSION GIT_SUBMODULE_VERSIONS) project(tinyuf2) -set(ARTIFACT_PATH ${CMAKE_CURRENT_LIST_DIR}/_bin/${BOARD}) -execute_process(COMMAND mkdir -p ${ARTIFACT_PATH}) - # Create post-build script for combined.bin / combined-ota.bin file(WRITE ${CMAKE_BINARY_DIR}/tinyuf2.postbuild.sh "#!/bin/bash\n" @@ -73,15 +69,26 @@ add_custom_command(TARGET app POST_BUILD VERBATIM ) -# External project for self-update -# Post build: generate bootloader_bin.c for self-update and combined.bin +# flash combined.bin +add_custom_target(combined-flash + DEPENDS tinyuf2.elf + COMMAND ${CMAKE_COMMAND} -E echo "Flashing combined.bin" + COMMAND esptool.py --chip ${IDF_TARGET} write_flash 0x0 combined.bin + VERBATIM + ) + +#------------------------------ +# External project (update_tinyuf2, blinky etc ...) +#------------------------------ + +# Post build: generate bootloader_bin.c for update-tinyuf2 and combined.bin add_custom_command(TARGET app POST_BUILD - COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} --carray -o ${CMAKE_CURRENT_LIST_DIR}/apps/self_update/main/bootloader_bin.c ${CMAKE_BINARY_DIR}/tinyuf2.bin + COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} --carray -o ${CMAKE_CURRENT_LIST_DIR}/apps/update_tinyuf2/main/bootloader_bin.c ${CMAKE_BINARY_DIR}/tinyuf2.bin ) -externalproject_add(self_update - SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/apps/self_update - BINARY_DIR ${CMAKE_BINARY_DIR}/self_update +externalproject_add(update-tinyuf2 + SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/apps/update_tinyuf2 + BINARY_DIR ${CMAKE_BINARY_DIR}/apps/update_tinyuf2 # Modifying the list separator for the arguments, as such, we won't need to manually # replace the new separator by the default ';' in the subproject CMAKE_ARGS -DBOARD=${BOARD} @@ -90,14 +97,27 @@ externalproject_add(self_update DEPENDS tinyuf2.elf ) -# flash combined.bin -add_custom_target(combined-flash - DEPENDS tinyuf2.elf - COMMAND ${CMAKE_COMMAND} -E echo "Flashing combined.bin" - COMMAND esptool.py --chip ${IDF_TARGET} write_flash 0x0 combined.bin - VERBATIM +externalproject_add(blinky + SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/apps/blinky + BINARY_DIR ${CMAKE_BINARY_DIR}/apps/blinky + # Modifying the list separator for the arguments, as such, we won't need to manually + # replace the new separator by the default ';' in the subproject + CMAKE_ARGS -DBOARD=${BOARD} + INSTALL_COMMAND "" + BUILD_ALWAYS 1 ) +# erase firmware need to use reset reason, not implemented yet +#externalproject_add(erase_firmware +# SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/apps/erase_firmware +# BINARY_DIR ${CMAKE_BINARY_DIR}/apps/erase_firmware +# # Modifying the list separator for the arguments, as such, we won't need to manually +# # replace the new separator by the default ';' in the subproject +# CMAKE_ARGS -DBOARD=${BOARD} +# INSTALL_COMMAND "" +# BUILD_ALWAYS 1 +# ) + # ------------------------------------------------------------- # Post build: update arduino-esp32 bootloader for debug purpose # ------------------------------------------------------------- diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index 21898e65f..f7841b73d 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -7,6 +7,7 @@ BUILD = _build/$(BOARD) BIN = _bin/$(BOARD) TOP = ../.. +SELF_BUILD = ${BUILD}/update_tinyuf2 ifdef SERIAL SERIAL_OPT = --port $(SERIAL) @@ -38,8 +39,3 @@ app bootloader clean flash bootloader-flash app-flash erase-flash monitor dfu-fl $(BUILD)/combined.bin: app combined-flash: $(BUILD)/combined.bin esptool.py --chip $(IDF_TARGET) write_flash 0x0 $< - -# Self_update is a sub/external project, will be built by cmake's all target -SELF_BUILD = ${BUILD}/self_update - -# Artifacts is generated as Cmake post build diff --git a/ports/espressif/README.md b/ports/espressif/README.md index f67e94495..a296ee88c 100644 --- a/ports/espressif/README.md +++ b/ports/espressif/README.md @@ -39,7 +39,7 @@ Following boards are supported: Once installed and setup ESP-IDF, you can build with all target ``` -make BOARD=adafruit_feather_esp32s2 all +idf.py -DBOARD=adafruit_feather_esp32s2 build ``` ### Flash @@ -47,7 +47,7 @@ make BOARD=adafruit_feather_esp32s2 all You could flash it with flash target ``` -make BOARD=adafruit_feather_esp32s2 flash +idf.py -DBOARD=adafruit_feather_esp32s2 flash ``` or you could also use pre-built binaries from [release page](https://github.com/adafruit/tinyuf2/releases). Extract and run following esptool commands @@ -115,17 +115,4 @@ NOTE: uf2 bootloader, customized 2nd bootloader and partition table can be overw ## Partition -Following is typical partition for 4MB flash, check out the `partition-xMB.csv` for details. - -``` -# Name, Type, SubType, Offset, Size, Flags -# bootloader.bin,, 0x1000, 32K -# partition table, 0x8000, 4K - -nvs, data, nvs, 0x9000, 20K, -otadata, data, ota, 0xe000, 8K, -ota_0, 0, ota_0, 0x10000, 1408K, -ota_1, 0, ota_1, 0x170000, 1408K, -uf2, app, factory,0x2d0000, 256K, -ffat, data, fat, 0x310000, 960K, -``` +Each board has its own flash size and partition table. check out the one in `boards/BOARD/sdkconfig` and `partition-xMB.csv` for details diff --git a/ports/espressif/apps/blinky/CMakeLists.txt b/ports/espressif/apps/blinky/CMakeLists.txt new file mode 100644 index 000000000..967dd8df7 --- /dev/null +++ b/ports/espressif/apps/blinky/CMakeLists.txt @@ -0,0 +1,19 @@ +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.17) + +include(${CMAKE_CURRENT_LIST_DIR}/../../../family_support.cmake) + +# Must be set before including IDF project.cmake +set(EXTRA_COMPONENT_DIRS "../../boards" "../../components") +set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +add_compile_definitions( + BUILD_APPLICATION + BUILD_NO_TINYUSB + ) + +project(blinky) +family_gen_uf2(blinky ${UF2_FAMILY_ID}) diff --git a/ports/espressif/apps/blinky/main/CMakeLists.txt b/ports/espressif/apps/blinky/main/CMakeLists.txt new file mode 100644 index 000000000..15356ffec --- /dev/null +++ b/ports/espressif/apps/blinky/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS ${TOP}/apps/blinky/src/blinky.c + INCLUDE_DIRS ${TOP}/src + REQUIRES boards) diff --git a/ports/espressif/apps/self_update/sdkconfig.defaults b/ports/espressif/apps/blinky/sdkconfig.defaults similarity index 100% rename from ports/espressif/apps/self_update/sdkconfig.defaults rename to ports/espressif/apps/blinky/sdkconfig.defaults diff --git a/ports/espressif/apps/erase_firmware/CMakeLists.txt b/ports/espressif/apps/erase_firmware/CMakeLists.txt new file mode 100644 index 000000000..0e63666a1 --- /dev/null +++ b/ports/espressif/apps/erase_firmware/CMakeLists.txt @@ -0,0 +1,19 @@ +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.17) + +include(${CMAKE_CURRENT_LIST_DIR}/../../../family_support.cmake) + +# Must be set before including IDF project.cmake +set(EXTRA_COMPONENT_DIRS "../../boards" "../../components") +set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +add_compile_definitions( + BUILD_APPLICATION + BUILD_NO_TINYUSB + ) + +project(erase_firmware) +family_gen_uf2(erase_firmware ${UF2_FAMILY_ID}) diff --git a/ports/espressif/apps/erase_firmware/main/CMakeLists.txt b/ports/espressif/apps/erase_firmware/main/CMakeLists.txt new file mode 100644 index 000000000..9663c9b4f --- /dev/null +++ b/ports/espressif/apps/erase_firmware/main/CMakeLists.txt @@ -0,0 +1,6 @@ +# Note: bootloader_bin.c is generated by tinyuf2 app target +idf_component_register( + SRCS ${TOP}/apps/erase_firmware/src/erase_firmware.c + INCLUDE_DIRS ${TOP}/src + REQUIRES boards + ) diff --git a/ports/espressif/apps/erase_firmware/sdkconfig.defaults b/ports/espressif/apps/erase_firmware/sdkconfig.defaults new file mode 100644 index 000000000..9d26177ac --- /dev/null +++ b/ports/espressif/apps/erase_firmware/sdkconfig.defaults @@ -0,0 +1,16 @@ +CONFIG_IDF_CMAKE=y +CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y +CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION=y + +# Compiler options +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y + +# Newlib +CONFIG_NEWLIB_NANO_FORMAT=y + +# Virtual file system +CONFIG_VFS_SUPPORT_IO=n + +# Compatibility options +CONFIG_FLASHMODE_QIO=y diff --git a/ports/espressif/apps/self_update/CMakeLists.txt b/ports/espressif/apps/self_update/CMakeLists.txt deleted file mode 100644 index f48078de9..000000000 --- a/ports/espressif/apps/self_update/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# The following five lines of boilerplate have to be in your project's -# CMakeLists in this exact order for cmake to work correctly -cmake_minimum_required(VERSION 3.17) - -include(${CMAKE_CURRENT_LIST_DIR}/../../../family_support.cmake) -include(${CMAKE_CURRENT_LIST_DIR}/../../boards/${BOARD}/board.cmake) - -# Must be set before including IDF project.cmake -set(EXTRA_COMPONENT_DIRS "../../boards" "../../components") -set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) - -set(SELFUPDATE_BUILD 1) -include($ENV{IDF_PATH}/tools/cmake/project.cmake) - -add_compile_definitions(TINYUF2_SELF_UPDATE) - -project(update-tinyuf2) - -set(ARTIFACT_PATH ${CMAKE_CURRENT_LIST_DIR}/../../_bin/${BOARD}) -add_custom_command(TARGET app POST_BUILD - COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${UF2_FAMILY_ID_${IDF_TARGET}} -b 0x0 -c -o ${CMAKE_BINARY_DIR}/update-tinyuf2.uf2 ${CMAKE_BINARY_DIR}/update-tinyuf2.bin - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/update-tinyuf2.uf2 ${ARTIFACT_PATH}/update-tinyuf2.uf2 - VERBATIM - ) - -add_custom_target(flash-update-tinyuf2 - DEPENDS app - COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${UF2_FAMILY_ID_${IDF_TARGET}} --deploy ${CMAKE_BINARY_DIR}/update-tinyuf2.uf2 - VERBATIM - ) diff --git a/ports/espressif/apps/update_tinyuf2/CMakeLists.txt b/ports/espressif/apps/update_tinyuf2/CMakeLists.txt new file mode 100644 index 000000000..625ba6072 --- /dev/null +++ b/ports/espressif/apps/update_tinyuf2/CMakeLists.txt @@ -0,0 +1,20 @@ +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.17) + +include(${CMAKE_CURRENT_LIST_DIR}/../../../family_support.cmake) + +# Must be set before including IDF project.cmake +set(EXTRA_COMPONENT_DIRS "../../boards" "../../components") +set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +add_compile_definitions( + TINYUF2_SELF_UPDATE + BUILD_APPLICATION + BUILD_NO_TINYUSB + ) + +project(update-tinyuf2) +family_gen_uf2(update-tinyuf2 ${UF2_FAMILY_ID}) diff --git a/ports/espressif/apps/self_update/main/CMakeLists.txt b/ports/espressif/apps/update_tinyuf2/main/CMakeLists.txt similarity index 100% rename from ports/espressif/apps/self_update/main/CMakeLists.txt rename to ports/espressif/apps/update_tinyuf2/main/CMakeLists.txt diff --git a/ports/espressif/apps/update_tinyuf2/sdkconfig.defaults b/ports/espressif/apps/update_tinyuf2/sdkconfig.defaults new file mode 100644 index 000000000..9d26177ac --- /dev/null +++ b/ports/espressif/apps/update_tinyuf2/sdkconfig.defaults @@ -0,0 +1,16 @@ +CONFIG_IDF_CMAKE=y +CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y +CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION=y + +# Compiler options +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y + +# Newlib +CONFIG_NEWLIB_NANO_FORMAT=y + +# Virtual file system +CONFIG_VFS_SUPPORT_IO=n + +# Compatibility options +CONFIG_FLASHMODE_QIO=y diff --git a/ports/espressif/boards/boards.c b/ports/espressif/boards/boards.c index 5e8c761ce..4f596c33f 100644 --- a/ports/espressif/boards/boards.c +++ b/ports/espressif/boards/boards.c @@ -44,7 +44,7 @@ #include "board_api.h" -#ifndef TINYUF2_SELF_UPDATE +#ifndef BUILD_NO_TINYUSB #include "tusb.h" #endif @@ -98,7 +98,7 @@ static void internal_timer_cb(void* arg); // TinyUSB thread //--------------------------------------------------------------------+ -#ifdef TINYUF2_SELF_UPDATE +#ifdef BUILD_NO_TINYUSB void app_main(void) { main(); } @@ -346,7 +346,7 @@ void board_timer_stop(void) { //--------------------------------------------------------------------+ // CDC Touch1200 //--------------------------------------------------------------------+ -#ifndef TINYUF2_SELF_UPDATE +#ifndef BUILD_NO_TINYUSB #if CONFIG_IDF_TARGET_ESP32S3 #include "hal/usb_serial_jtag_ll.h" @@ -458,7 +458,7 @@ void tud_cdc_line_state_cb(uint8_t instance, bool dtr, bool rts) { } } } -#endif // TINYUF2_SELF_UPDATE +#endif //--------------------------------------------------------------------+ // Display diff --git a/ports/espressif/family.cmake b/ports/espressif/family.cmake index 80b8dfbe9..97fb4a5d0 100644 --- a/ports/espressif/family.cmake +++ b/ports/espressif/family.cmake @@ -1,2 +1,14 @@ +include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) + set(UF2_FAMILY_ID_esp32s2 0xbfdd4eee) set(UF2_FAMILY_ID_esp32s3 0xc47e5767) +set(UF2_FAMILY_ID ${UF2_FAMILY_ID_${IDF_TARGET}}) + +# override default family_gen_uf2 +function(family_gen_uf2 TARGET FAMILY_ID) + add_custom_command(TARGET app POST_BUILD + COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${FAMILY_ID} -b 0x0 -c -o ${CMAKE_BINARY_DIR}/${TARGET}.uf2 ${CMAKE_BINARY_DIR}/${TARGET}.bin + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${TARGET}.uf2 ${ARTIFACT_PATH}/apps/${TARGET}.uf2 + VERBATIM + ) +endfunction() diff --git a/ports/family_support.cmake b/ports/family_support.cmake index e54cf9c52..a29d2d88f 100644 --- a/ports/family_support.cmake +++ b/ports/family_support.cmake @@ -56,6 +56,13 @@ if (NOT DEFINED FAMILY) list(GET BOARD_PATH 0 FAMILY) endif () +set(FAMILY_PATH ${TOP}/ports/${FAMILY} CACHE INTERNAL "FAMILY_PATH") +set(BOARD_PATH ${TOP}/ports/${FAMILY}/boards/${BOARD} CACHE INTERNAL "BOARD_PATH") + +set(ARTIFACT_PATH ${FAMILY_PATH}/_bin/${BOARD}) +execute_process(COMMAND mkdir -p ${ARTIFACT_PATH}) +execute_process(COMMAND mkdir -p ${ARTIFACT_PATH}/apps) + # enable LTO if supported include(CheckIPOSupported) check_ipo_supported(RESULT IPO_SUPPORTED) @@ -67,8 +74,12 @@ endif () # Functions #------------------------------------ -function(family_add_bin_hex TARGET) - # placeholder, will be override by family specific +# Generate bin/hex output, can be override by family specific +function(family_gen_bin_hex TARGET) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -Obinary $ $/${TARGET}.bin + COMMAND ${CMAKE_OBJCOPY} -Oihex $ $/${TARGET}.hex + VERBATIM) endfunction() function(family_add_default_warnings TARGET) @@ -104,25 +115,9 @@ function(family_add_default_warnings TARGET) if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0) target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments") endif () - - # GCC 10 - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0) - target_compile_options(${TARGET} PUBLIC -Wconversion) - endif () - - # GCC 8 - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - target_compile_options(${TARGET} PUBLIC -Wcast-function-type -Wstrict-overflow) - endif () - - # GCC 6 - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) - target_compile_options(${TARGET} PUBLIC -Wno-strict-aliasing) - endif () endif () endfunction() - function(family_configure_common TARGET) # Add BOARD_${BOARD} define string(TOUPPER ${BOARD} BOARD_UPPER) @@ -167,11 +162,9 @@ function(family_configure_common TARGET) ) # add hex, bin and uf2 targets - family_add_bin_hex(${TARGET}) - + family_gen_bin_hex(${TARGET}) endfunction() - # Add tinyusb to example function(family_add_tinyusb TARGET OPT_MCU) # tinyusb's CMakeList.txt @@ -192,7 +185,7 @@ function(family_configure_tinyuf2 TARGET OPT_MCU) family_configure_common(${TARGET}) include(${TOP}/src/tinyuf2.cmake) - add_tinyuf2(${TARGET}) + add_tinyuf2_src(${TARGET}) family_add_tinyusb(${TARGET} ${OPT_MCU}) @@ -204,35 +197,27 @@ function(family_configure_tinyuf2 TARGET OPT_MCU) UF2_VERSION_BASE="${GIT_VERSION}" UF2_VERSION="${GIT_VERSION}" ) -endfunction() - -# Add bin/hex output -function(family_add_bin_hex TARGET) + # copy bin,hex to ARTIFACT_PATH add_custom_command(TARGET ${TARGET} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -Obinary $ $/${TARGET}.bin - COMMAND ${CMAKE_OBJCOPY} -Oihex $ $/${TARGET}.hex + COMMAND ${CMAKE_COMMAND} -E copy $/${TARGET}.bin ${ARTIFACT_PATH}/${TARGET}.bin + COMMAND ${CMAKE_COMMAND} -E copy $/${TARGET}.hex ${ARTIFACT_PATH}/${TARGET}.hex VERBATIM) -endfunction() - -# Add uf2 target, optional parameter is the extension of the binary file (default is hex) -# If bin file is used, address is also required -function(family_add_uf2 TARGET FAMILY_ID) - set(BIN_EXT hex) - set(ADDR_OPT "") - if (ARGC GREATER 2) - set(BIN_EXT ${ARGV2}) - if (BIN_EXT STREQUAL bin) - set(ADDR_OPT "-b ${ARGV3}") - endif () - endif () +endfunction() - set(BIN_FILE $/${TARGET}.${BIN_EXT}) +# generate .uf2 file from hex +function(family_gen_uf2 TARGET FAMILY_ID) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${FAMILY_ID} -c -o $/${TARGET}.uf2 $/${TARGET}.hex + COMMAND ${CMAKE_COMMAND} -E copy $/${TARGET}.uf2 ${ARTIFACT_PATH}/apps/${TARGET}.uf2 + VERBATIM) +endfunction() +# generate .uf2 file from bin with address +function(family_gen_uf2_from_bin TARGET FAMILY_ID BIN_ADDR) add_custom_command(TARGET ${TARGET} POST_BUILD - COMMAND echo ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${FAMILY_ID} ${ADDR_OPT} -c -o $/${TARGET}.uf2 ${BIN_FILE} - COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${FAMILY_ID} ${ADDR_OPT} -c -o $/${TARGET}.uf2 ${BIN_FILE} + COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${FAMILY_ID} -b ${BIN_ADDR} -c -o $/${TARGET}.uf2 $/${TARGET}.bin VERBATIM) endfunction() diff --git a/ports/mimxrt10xx/CMakeLists.txt b/ports/mimxrt10xx/CMakeLists.txt index 6874101e4..a1b8f6f99 100644 --- a/ports/mimxrt10xx/CMakeLists.txt +++ b/ports/mimxrt10xx/CMakeLists.txt @@ -24,13 +24,21 @@ family_configure_tinyuf2(tinyuf2 OPT_MCU_MIMXRT1XXX) family_flash_sdp(tinyuf2) family_flash_jlink(tinyuf2 hex) -family_add_uf2(tinyuf2 ${UF2_FAMILY_ID} bin ${UF2_ADDR}) + +# imxrt run entirely on SRAM and can update its self using uf2 +family_gen_uf2_from_bin(tinyuf2 ${UF2_FAMILY_ID} ${UF2_ADDR}) family_flash_uf2(tinyuf2 ${UF2_FAMILY_ID}) +# copy to ARTIFACT_PATH +add_custom_command(TARGET tinyuf2 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $/tinyuf2.uf2 ${ARTIFACT_PATH}/apps/update-tinyuf2.uf2 + VERBATIM) + #------------------------------------ -# Application (e.g self update) +# Application #------------------------------------ -add_subdirectory(apps/erase_firmware) +add_subdirectory(${TOP}/apps/blinky ${CMAKE_BINARY_DIR}/apps/blinky) +add_subdirectory(${TOP}/apps/erase_firmware ${CMAKE_BINARY_DIR}/apps/erase_firmware) if (BOARD STREQUAL metro_m7_1011) add_subdirectory(apps/esp32programmer) diff --git a/ports/mimxrt10xx/app.cmake b/ports/mimxrt10xx/app.cmake new file mode 100644 index 000000000..c7ae0f024 --- /dev/null +++ b/ports/mimxrt10xx/app.cmake @@ -0,0 +1,18 @@ +include_guard(GLOBAL) + +# override bin hex output +function(family_gen_bin_hex TARGET) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary -R .flash_config -R .ivt $ $/${TARGET}.bin + COMMAND ${CMAKE_OBJCOPY} -Oihex $ $/${TARGET}.hex + VERBATIM) +endfunction() + +function(family_configure_app TARGET) + family_configure_common(${TARGET}) + target_link_options(${TARGET} PUBLIC + "LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/${MCU_VARIANT}_ram.ld" + "LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/app.ld" + "LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/common.ld" + ) +endfunction() diff --git a/ports/mimxrt10xx/apps/app.cmake b/ports/mimxrt10xx/apps/app.cmake deleted file mode 100644 index 7a3bbb1de..000000000 --- a/ports/mimxrt10xx/apps/app.cmake +++ /dev/null @@ -1,25 +0,0 @@ -include_guard() - -# override bin hex output -function(family_add_bin_hex TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary -R .flash_config -R .ivt $ $/${TARGET}.bin - COMMAND ${CMAKE_OBJCOPY} -Oihex $ $/${TARGET}.hex - VERBATIM) -endfunction() - -function(configure_app TARGET) - family_configure_common(${TARGET}) - target_compile_definitions(${TARGET} PUBLIC - BUILD_APPLICATION - ) - target_link_options(${TARGET} PUBLIC - "LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../linker/${MCU_VARIANT}_ram.ld" - "LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/memory.ld" - "LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../linker/common.ld" - ) - - family_add_uf2(${TARGET} ${UF2_FAMILY_ID}) - family_flash_uf2(${TARGET} ${UF2_FAMILY_ID}) - family_flash_jlink(${TARGET} hex) -endfunction() diff --git a/ports/mimxrt10xx/apps/app.mk b/ports/mimxrt10xx/apps/app.mk index 9f648ee43..a8e899803 100644 --- a/ports/mimxrt10xx/apps/app.mk +++ b/ports/mimxrt10xx/apps/app.mk @@ -6,7 +6,7 @@ BUILD_APPLICATION = 1 include ../../../make.mk include $(TOP)/$(PORT_DIR)/port.mk -LD_FILES ?= $(PORT_DIR)/linker/$(MCU)_ram.ld $(PORT_DIR)/apps/memory.ld $(PORT_DIR)/linker/common.ld +LD_FILES ?= $(PORT_DIR)/linker/$(MCU)_ram.ld $(PORT_DIR)/linker/app.ld $(PORT_DIR)/linker/common.ld include $(TOP)/ports/rules.mk diff --git a/ports/mimxrt10xx/apps/erase_firmware/Makefile b/ports/mimxrt10xx/apps/erase_firmware/Makefile deleted file mode 100644 index 4080f9f5f..000000000 --- a/ports/mimxrt10xx/apps/erase_firmware/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -OUTNAME = erase_firmware-$(BOARD) - -# skip tinyusb -BUILD_NO_TINYUSB = 1 - -SRC_C += \ - $(PORT_DIR)/boards.c \ - apps/erase_firmware/erase_firmware.c - -INC += $(TOP)/src - -include ../app.mk diff --git a/ports/mimxrt10xx/apps/esp32programmer/CMakeLists.txt b/ports/mimxrt10xx/apps/esp32programmer/CMakeLists.txt index d8a621059..0f5ecb73f 100644 --- a/ports/mimxrt10xx/apps/esp32programmer/CMakeLists.txt +++ b/ports/mimxrt10xx/apps/esp32programmer/CMakeLists.txt @@ -4,11 +4,8 @@ #------------------------------------ cmake_minimum_required(VERSION 3.17) -include(${CMAKE_CURRENT_LIST_DIR}/../app.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/../../app.cmake) -#------------------------------------ -# Application -#------------------------------------ add_executable(esp32programmer main.c usb_descriptors.c @@ -20,5 +17,5 @@ target_include_directories(esp32programmer PUBLIC ${TOP}/src ) -configure_app(esp32programmer) +family_configure_app(esp32programmer) family_add_tinyusb(esp32programmer OPT_MCU_MIMXRT1XXX) diff --git a/ports/mimxrt10xx/apps/factory_test/CMakeLists.txt b/ports/mimxrt10xx/apps/factory_test/CMakeLists.txt index eaa480dd1..cd77ecfbc 100644 --- a/ports/mimxrt10xx/apps/factory_test/CMakeLists.txt +++ b/ports/mimxrt10xx/apps/factory_test/CMakeLists.txt @@ -4,7 +4,7 @@ #------------------------------------ cmake_minimum_required(VERSION 3.17) -include(${CMAKE_CURRENT_LIST_DIR}/../app.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/../../app.cmake) #------------------------------------ # Application @@ -21,5 +21,5 @@ target_include_directories(factory_test PUBLIC ${TOP}/src ) -configure_app(factory_test) +family_configure_app(factory_test) family_add_tinyusb(factory_test OPT_MCU_MIMXRT1XXX) diff --git a/ports/mimxrt10xx/apps/factory_test_metro_sd/CMakeLists.txt b/ports/mimxrt10xx/apps/factory_test_metro_sd/CMakeLists.txt index a023e9b89..a67fcbcfc 100644 --- a/ports/mimxrt10xx/apps/factory_test_metro_sd/CMakeLists.txt +++ b/ports/mimxrt10xx/apps/factory_test_metro_sd/CMakeLists.txt @@ -4,7 +4,7 @@ #------------------------------------ cmake_minimum_required(VERSION 3.17) -include(${CMAKE_CURRENT_LIST_DIR}/../app.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/../../app.cmake) #------------------------------------ # Application @@ -27,7 +27,7 @@ target_include_directories(factory_test_metro_sd PUBLIC include(middleware-sdmmc/CMakeLists.txt) add_sdmmc(factory_test_metro_sd) -configure_app(factory_test_metro_sd) +family_configure_app(factory_test_metro_sd) family_add_tinyusb(factory_test_metro_sd OPT_MCU_MIMXRT1XXX) #------------------------------------ diff --git a/ports/mimxrt10xx/apps/factory_test_metro_sd/middleware-sdmmc/CMakeLists.txt b/ports/mimxrt10xx/apps/factory_test_metro_sd/middleware-sdmmc/CMakeLists.txt index 05b6bb0bc..b4ae85016 100644 --- a/ports/mimxrt10xx/apps/factory_test_metro_sd/middleware-sdmmc/CMakeLists.txt +++ b/ports/mimxrt10xx/apps/factory_test_metro_sd/middleware-sdmmc/CMakeLists.txt @@ -1,4 +1,4 @@ -include_guard() +include_guard(GLOBAL) function(add_sdmmc TARGET) target_sources(${TARGET} PUBLIC diff --git a/ports/mimxrt10xx/family.cmake b/ports/mimxrt10xx/family.cmake index 1bbaf0eec..4701c501a 100644 --- a/ports/mimxrt10xx/family.cmake +++ b/ports/mimxrt10xx/family.cmake @@ -1,4 +1,4 @@ -include_guard() +include_guard(GLOBAL) #------------------------------------ # Config @@ -98,7 +98,6 @@ function(family_add_board_target BOARD_TARGET) ${SDK_DIR}/drivers/xbara ${SDK_DIR}/drivers/wdog01 ) - update_board(${BOARD_TARGET}) target_compile_definitions(${BOARD_TARGET} PUBLIC @@ -117,7 +116,7 @@ endfunction() # override one in family_supoort.cmake #------------------------------------ -function(family_add_bin_hex TARGET) +function(family_gen_bin_hex TARGET) math(EXPR HEX_OFFSET "${UF2_ADDR} - ${FCFB_ORIGIN}") add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary $ $/${TARGET}.bin diff --git a/ports/mimxrt10xx/apps/memory.ld b/ports/mimxrt10xx/linker/app.ld similarity index 100% rename from ports/mimxrt10xx/apps/memory.ld rename to ports/mimxrt10xx/linker/app.ld diff --git a/ports/rules.mk b/ports/rules.mk index 942831968..a0712e2b4 100644 --- a/ports/rules.mk +++ b/ports/rules.mk @@ -74,12 +74,13 @@ SELF_UF2 ?= apps/self_update/$(BUILD)/update-$(OUTNAME).uf2 $(BIN): @$(MKDIR) -p $@ + @$(MKDIR) -p $@/apps copy-artifact: $(BIN) copy-artifact: $(BUILD)/$(OUTNAME).bin $(BUILD)/$(OUTNAME).hex @$(CP) $(BUILD)/$(OUTNAME).bin $(BIN) @$(CP) $(BUILD)/$(OUTNAME).hex $(BIN) - @if [ -f "$(SELF_UF2)" ]; then $(CP) $(SELF_UF2) $(BIN); fi + @if [ -f "$(SELF_UF2)" ]; then $(CP) $(SELF_UF2) $(BIN)/apps; fi #-------------- Compile Rules -------------- @@ -211,4 +212,4 @@ flash-openocd-wch: $(BUILD)/$(OUTNAME).elf #-------------------- Flash with uf2 ----------------- UF2CONV_PY = $(TOP)/lib/uf2/utils/uf2conv.py flash-uf2: $(BUILD)/$(OUTNAME).uf2 - python ${UF2CONV_PY} -f ${UF2_FAMILY_ID} --deploy $^ + python ${UF2CONV_PY} -f ${UF2_FAMILY_ID} --deploy $^ diff --git a/ports/stm32f3/apps/self_update/CMakeLists.txt b/ports/stm32f3/apps/self_update/CMakeLists.txt index 94c615018..333cbd875 100644 --- a/ports/stm32f3/apps/self_update/CMakeLists.txt +++ b/ports/stm32f3/apps/self_update/CMakeLists.txt @@ -30,4 +30,4 @@ target_link_options(self_update PUBLIC ) family_configure_common(self_update) -family_add_uf2(self_update ${UF2_FAMILY_ID}) +family_gen_uf2(self_update ${UF2_FAMILY_ID}) diff --git a/ports/stm32f3/family.cmake b/ports/stm32f3/family.cmake index 0d213459d..230bddbe6 100644 --- a/ports/stm32f3/family.cmake +++ b/ports/stm32f3/family.cmake @@ -1,4 +1,4 @@ -include_guard() +include_guard(GLOBAL) #------------------------------------ # Config diff --git a/ports/stm32f4/CMakeLists.txt b/ports/stm32f4/CMakeLists.txt index 244994130..aef63fbfe 100644 --- a/ports/stm32f4/CMakeLists.txt +++ b/ports/stm32f4/CMakeLists.txt @@ -20,8 +20,11 @@ target_link_options(tinyuf2 PUBLIC family_configure_tinyuf2(tinyuf2 OPT_MCU_STM32F4) family_flash_jlink(tinyuf2) +family_flash_stlink(tinyuf2) #------------------------------------ -# Application (e.g self update) +# Application #------------------------------------ -add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/apps/self_update) +add_subdirectory(${TOP}/apps/self_update ${CMAKE_BINARY_DIR}/apps/self_update) +add_subdirectory(${TOP}/apps/blinky ${CMAKE_BINARY_DIR}/apps/blinky) +add_subdirectory(${TOP}/apps/erase_firmware ${CMAKE_BINARY_DIR}/apps/erase_firmware) diff --git a/ports/stm32f4/app.cmake b/ports/stm32f4/app.cmake new file mode 100644 index 000000000..9f5ea35ec --- /dev/null +++ b/ports/stm32f4/app.cmake @@ -0,0 +1,8 @@ +include_guard(GLOBAL) + +function(family_configure_app TARGET) + family_configure_common(${TARGET}) + target_link_options(${TARGET} PUBLIC + "LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/stm32f4_app.ld" + ) +endfunction() diff --git a/ports/stm32f4/apps/erase_firmware/Makefile b/ports/stm32f4/apps/erase_firmware/Makefile deleted file mode 100644 index 8624cdf54..000000000 --- a/ports/stm32f4/apps/erase_firmware/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - @echo "not implemented yet" diff --git a/ports/stm32f4/apps/self_update/CMakeLists.txt b/ports/stm32f4/apps/self_update/CMakeLists.txt deleted file mode 100644 index 1a1d54c4f..000000000 --- a/ports/stm32f4/apps/self_update/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -#------------------------------------ -# Self Update -# This file is meant to be include by add_subdirectory() in the root CMakeLists.txt -#------------------------------------ - -# Generate bootloader_bin.c -add_custom_command(OUTPUT bootloader_bin.c - COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} --carray -o bootloader_bin.c $/tinyuf2.bin - DEPENDS tinyuf2 - ) - -# self_update target -add_executable(self_update - ${TOP}/apps/self_update/self_update.c - ${CMAKE_CURRENT_LIST_DIR}/../../boards.c - ${CMAKE_CURRENT_LIST_DIR}/../../board_flash.c - ${CMAKE_CURRENT_BINARY_DIR}/bootloader_bin.c - ) - -target_include_directories(self_update PUBLIC - ${TOP}/src - ) -target_compile_definitions(self_update PUBLIC - TINYUF2_SELF_UPDATE - BUILD_NO_TINYUSB - BUILD_APPLICATION - ) -target_link_options(self_update PUBLIC - "LINKER:--script=${CMAKE_CURRENT_LIST_DIR}/../../linker/stm32f4_app.ld" - ) - -family_configure_common(self_update) -family_add_uf2(self_update ${UF2_FAMILY_ID}) diff --git a/ports/stm32f4/boards.c b/ports/stm32f4/boards.c index f0723e863..fbe65aea4 100644 --- a/ports/stm32f4/boards.c +++ b/ports/stm32f4/boards.c @@ -36,8 +36,12 @@ UART_HandleTypeDef UartHandle; -void board_init(void) -{ +void board_init(void) { +#ifdef BUILD_APPLICATION + // system_stm32h5xx.c: SystemInit() will reset vector table, set it here if we are building application + SCB->VTOR = (uint32_t) BOARD_FLASH_APP_START; +#endif + clock_init(); SystemCoreClockUpdate(); @@ -80,7 +84,7 @@ void board_init(void) HAL_GPIO_Init(NEOPIXEL_PORT, &GPIO_InitStruct); #endif -#if defined(UART_DEV) && CFG_TUSB_DEBUG +#if defined(UART_DEV) && defined(CFG_TUSB_DEBUG) && CFG_TUSB_DEBUG UART_CLOCK_ENABLE(); GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN; @@ -215,7 +219,7 @@ void board_app_jump(void) HAL_GPIO_DeInit(NEOPIXEL_PORT, NEOPIXEL_PIN); #endif -#if defined(UART_DEV) && CFG_TUSB_DEBUG +#if defined(UART_DEV) && defined(CFG_TUSB_DEBUG) && CFG_TUSB_DEBUG HAL_UART_DeInit(&UartHandle); HAL_GPIO_DeInit(UART_GPIO_PORT, UART_TX_PIN | UART_RX_PIN); UART_CLOCK_DISABLE(); @@ -366,7 +370,7 @@ void SysTick_Handler(void) int board_uart_write(void const * buf, int len) { -#if defined(UART_DEV) && CFG_TUSB_DEBUG +#if defined(UART_DEV) && defined(CFG_TUSB_DEBUG) && CFG_TUSB_DEBUG HAL_UART_Transmit(&UartHandle, (uint8_t*) buf, len, 0xffff); return len; #else diff --git a/ports/stm32f4/boards/feather_stm32f405_express/board.cmake b/ports/stm32f4/boards/feather_stm32f405_express/board.cmake new file mode 100644 index 000000000..86beb0203 --- /dev/null +++ b/ports/stm32f4/boards/feather_stm32f405_express/board.cmake @@ -0,0 +1,11 @@ +set(JLINK_DEVICE stm32f405rg) + +function(update_board TARGET) + target_sources(${TARGET} PUBLIC + ${ST_CMSIS}/Source/Templates/gcc/startup_stm32f405xx.s + ) + target_compile_definitions(${TARGET} PUBLIC + STM32F405xx + HSE_VALUE=12000000U + ) +endfunction() diff --git a/ports/stm32f4/boards/sparkfun_micromod_stm32/board.cmake b/ports/stm32f4/boards/sparkfun_micromod_stm32/board.cmake new file mode 100644 index 000000000..86beb0203 --- /dev/null +++ b/ports/stm32f4/boards/sparkfun_micromod_stm32/board.cmake @@ -0,0 +1,11 @@ +set(JLINK_DEVICE stm32f405rg) + +function(update_board TARGET) + target_sources(${TARGET} PUBLIC + ${ST_CMSIS}/Source/Templates/gcc/startup_stm32f405xx.s + ) + target_compile_definitions(${TARGET} PUBLIC + STM32F405xx + HSE_VALUE=12000000U + ) +endfunction() diff --git a/ports/stm32f4/boards/sparkfun_stm32_thing_plus/board.cmake b/ports/stm32f4/boards/sparkfun_stm32_thing_plus/board.cmake new file mode 100644 index 000000000..86beb0203 --- /dev/null +++ b/ports/stm32f4/boards/sparkfun_stm32_thing_plus/board.cmake @@ -0,0 +1,11 @@ +set(JLINK_DEVICE stm32f405rg) + +function(update_board TARGET) + target_sources(${TARGET} PUBLIC + ${ST_CMSIS}/Source/Templates/gcc/startup_stm32f405xx.s + ) + target_compile_definitions(${TARGET} PUBLIC + STM32F405xx + HSE_VALUE=12000000U + ) +endfunction() diff --git a/ports/stm32f4/boards/stm32f401_blackpill/board.cmake b/ports/stm32f4/boards/stm32f401_blackpill/board.cmake new file mode 100644 index 000000000..b6270d8d3 --- /dev/null +++ b/ports/stm32f4/boards/stm32f401_blackpill/board.cmake @@ -0,0 +1,11 @@ +set(JLINK_DEVICE stm32f411ce) + +function(update_board TARGET) + target_sources(${TARGET} PUBLIC + ${ST_CMSIS}/Source/Templates/gcc/startup_stm32f411xe.s + ) + target_compile_definitions(${TARGET} PUBLIC + STM32F411xE + HSE_VALUE=25000000U + ) +endfunction() diff --git a/ports/stm32f4/boards/stm32f411ce_blackpill/board.cmake b/ports/stm32f4/boards/stm32f411ce_blackpill/board.cmake new file mode 100644 index 000000000..c5233cee9 --- /dev/null +++ b/ports/stm32f4/boards/stm32f411ce_blackpill/board.cmake @@ -0,0 +1,11 @@ +set(JLINK_DEVICE stm32f401cc) + +function(update_board TARGET) + target_sources(${TARGET} PUBLIC + ${ST_CMSIS}/Source/Templates/gcc/startup_stm32f401xc.s + ) + target_compile_definitions(${TARGET} PUBLIC + STM32F401xC + HSE_VALUE=25000000U + ) +endfunction() diff --git a/ports/stm32f4/family.cmake b/ports/stm32f4/family.cmake index 2caaedd10..4f83d0781 100644 --- a/ports/stm32f4/family.cmake +++ b/ports/stm32f4/family.cmake @@ -1,4 +1,4 @@ -include_guard() +include_guard(GLOBAL) #------------------------------------ # Config @@ -21,8 +21,6 @@ set(CMAKE_TOOLCHAIN_FILE ${TOP}/cmake/toolchain/arm_${TOOLCHAIN}.cmake) #------------------------------------ # BOARD_TARGET #------------------------------------ -# used by all executable targets - function(family_add_board_target BOARD_TARGET) if (TARGET ${BOARD_TARGET}) return() @@ -61,7 +59,3 @@ function(family_add_board_target BOARD_TARGET) --specs=nosys.specs --specs=nano.specs ) endfunction() - -#------------------------------------ -# Main target -#------------------------------------ diff --git a/ports/stm32h5/CMakeLists.txt b/ports/stm32h5/CMakeLists.txt index d9d74183c..f71678d18 100644 --- a/ports/stm32h5/CMakeLists.txt +++ b/ports/stm32h5/CMakeLists.txt @@ -22,7 +22,8 @@ family_flash_jlink(tinyuf2) family_flash_stlink(tinyuf2) #------------------------------------ -# Application (e.g self update) +# Application #------------------------------------ -add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/apps/self_update) -add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/apps/blinky) +add_subdirectory(${TOP}/apps/self_update ${CMAKE_BINARY_DIR}/apps/self_update) +add_subdirectory(${TOP}/apps/blinky ${CMAKE_BINARY_DIR}/apps/blinky) +add_subdirectory(${TOP}/apps/erase_firmware ${CMAKE_BINARY_DIR}/apps/erase_firmware) diff --git a/ports/stm32h5/app.cmake b/ports/stm32h5/app.cmake new file mode 100644 index 000000000..c3103515d --- /dev/null +++ b/ports/stm32h5/app.cmake @@ -0,0 +1,8 @@ +include_guard(GLOBAL) + +function(family_configure_app TARGET) + family_configure_common(${TARGET}) + target_link_options(${TARGET} PUBLIC + "LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/stm32h5_app.ld" + ) +endfunction() diff --git a/ports/stm32h5/apps/blinky/Makefile b/ports/stm32h5/apps/blinky/Makefile deleted file mode 100644 index 4e9393e8a..000000000 --- a/ports/stm32h5/apps/blinky/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -PORT = stm32h5 -OUTNAME = blinky-$(BOARD) - -BUILD_APPLICATION = 1 -BUILD_NO_TINYUSB = 1 - -include ../../../make.mk -include ../../port.mk - -SRC_C += \ - apps/blinky/blinky.c \ - -include ../../../rules.mk - -uf2: $(BUILD)/$(OUTNAME).uf2 - -$(BUILD)/$(OUTNAME).uf2: $(BUILD)/$(OUTNAME).hex - @echo CREATE $@ - $(PYTHON3) $(TOP)/lib/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -c -o $@ $^ diff --git a/ports/stm32h5/apps/erase_firmware/Makefile b/ports/stm32h5/apps/erase_firmware/Makefile deleted file mode 100644 index 8624cdf54..000000000 --- a/ports/stm32h5/apps/erase_firmware/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - @echo "not implemented yet" diff --git a/ports/stm32h5/apps/self_update/CMakeLists.txt b/ports/stm32h5/apps/self_update/CMakeLists.txt deleted file mode 100644 index daa554ba9..000000000 --- a/ports/stm32h5/apps/self_update/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -#------------------------------------ -# Self Update -# This file is meant to be include by add_subdirectory() in the root CMakeLists.txt -#------------------------------------ - -# Generate bootloader_bin.c -add_custom_command(OUTPUT bootloader_bin.c - COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} --carray -o bootloader_bin.c $/tinyuf2.bin - DEPENDS tinyuf2 - ) - -# self_update target -add_executable(self_update - ${TOP}/apps/self_update/self_update.c - ${CMAKE_CURRENT_LIST_DIR}/../../boards.c - ${CMAKE_CURRENT_LIST_DIR}/../../board_flash.c - ${CMAKE_CURRENT_BINARY_DIR}/bootloader_bin.c - ) - -target_include_directories(self_update PUBLIC - ${TOP}/src - ) -target_compile_definitions(self_update PUBLIC - TINYUF2_SELF_UPDATE - BUILD_NO_TINYUSB - BUILD_APPLICATION - ) -target_link_options(self_update PUBLIC - "LINKER:--script=${CMAKE_CURRENT_LIST_DIR}/../../linker/stm32h5_app.ld" - ) - -family_configure_common(self_update) -family_add_uf2(self_update ${UF2_FAMILY_ID}) -family_flash_uf2(self_update ${UF2_FAMILY_ID}) diff --git a/ports/stm32h5/board_flash.c b/ports/stm32h5/board_flash.c index 557e1c856..4011b7b20 100644 --- a/ports/stm32h5/board_flash.c +++ b/ports/stm32h5/board_flash.c @@ -201,7 +201,7 @@ bool is_new_bootloader_valid(const uint8_t* bootloader_bin, uint32_t bootloader_ if (bootloader_len < 1024) return false; // similar to board_app_valid() check - uint32_t const* app_vector = (uint32_t const*)bootloader_bin; + uint32_t const* app_vector = (uint32_t const*) (uintptr_t) bootloader_bin; uint32_t sp = app_vector[0]; uint32_t boot_entry = app_vector[1]; diff --git a/ports/stm32h5/family.cmake b/ports/stm32h5/family.cmake index fce6d3f13..abb5485ca 100644 --- a/ports/stm32h5/family.cmake +++ b/ports/stm32h5/family.cmake @@ -1,4 +1,4 @@ -include_guard() +include_guard(GLOBAL) #------------------------------------ # Config diff --git a/src/tinyuf2.cmake b/src/tinyuf2.cmake index e36f01121..7fc12af93 100644 --- a/src/tinyuf2.cmake +++ b/src/tinyuf2.cmake @@ -4,7 +4,7 @@ # The intention is to provide greater flexibility to users to # create their own targets using the set variables. -function (add_tinyuf2 TARGET) +function (add_tinyuf2_src TARGET) target_sources(${TARGET} PUBLIC ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ghostfat.c ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/images.c