diff --git a/.github/workflows/build_cmake.yml b/.github/workflows/build_cmake.yml new file mode 100644 index 000000000..ba086d0e0 --- /dev/null +++ b/.github/workflows/build_cmake.yml @@ -0,0 +1,56 @@ +name: Build ARM + +on: + pull_request: + push: + repository_dispatch: + release: + types: + - created + +jobs: + + # --------------------------------------- + # Build ARM family + # --------------------------------------- + ARM: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + board: + # Alphabetical order by family + - 'metro_m7_1011' + - 'stm32f303disco' + + steps: + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Checkout common submodules in lib + run: git submodule update --init lib/tinyusb lib/uf2 + + - name: Install ARM GCC + uses: carlosperate/arm-none-eabi-gcc-action@v1 + with: + release: '11.2-2022.02' + + - name: Build + run: | + cmake . -B _build -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DBOARD=${{ matrix.board }} + cmake --build _build + +# - uses: actions/upload-artifact@v3 +# with: +# name: ${{ matrix.board }} +# path: | +# _build/ports/*/tinyusb.bin +# _build/ports/*/tinyusb.hex +# _build/ports/*/apps/*/*.uf2 diff --git a/ports/CMakeLists.txt b/CMakeLists.txt similarity index 61% rename from ports/CMakeLists.txt rename to CMakeLists.txt index 6b0089722..a856425af 100644 --- a/ports/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,10 @@ -cmake_minimum_required(VERSION 3.17) - -include(${CMAKE_CURRENT_LIST_DIR}/family_support.cmake) - -# Espressif has its own build system -if(NOT FAMILY STREQUAL espressif) - project(tinyuf2_all C ASM) -endif () - -add_subdirectory(${FAMILY}) +cmake_minimum_required(VERSION 3.17) + +include(ports/family_support.cmake) + +# Espressif has its own build system +if(NOT FAMILY STREQUAL espressif) + project(tinyuf2_all C ASM) +endif () + +add_subdirectory(ports/${FAMILY}) diff --git a/ports/espressif/CMakeLists.txt b/ports/espressif/CMakeLists.txt index 7bd58e63e..3f2f49a92 100644 --- a/ports/espressif/CMakeLists.txt +++ b/ports/espressif/CMakeLists.txt @@ -34,3 +34,32 @@ project(tinyuf2) 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 ) + +# Post build: update arduino-esp32 bootloader for debug purpose +if (0) + +#set(ARDUINO_VARIANT_DIR /home/hathach/code/arduino-esp32/variants/${BOARD}) +set(ARDUINO_VARIANT_DIR /home/hathach/code/arduino-esp32/variants/adafruit_feather_esp32s3) + +add_custom_command(TARGET bootloader POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bootloader/bootloader.bin ${ARDUINO_VARIANT_DIR}/bootloader-tinyuf2.bin + ) + +add_custom_command(TARGET app POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/tinyuf2.bin ${ARDUINO_VARIANT_DIR}/tinyuf2.bin + ) + +file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/sdkconfig SDKCONFIG_CONTENTS) +foreach (line ${SDKCONFIG_CONTENTS}) + if (line MATCHES "CONFIG_PARTITION_TABLE_CUSTOM_FILENAME=\"(.*).csv\"") + set(PARTITION_TABLE_CSV ${CMAKE_MATCH_1}) + cmake_print_variables(PARTITION_TABLE_CSV) + break() + endif () +endforeach () + +add_custom_command(TARGET app POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/${PARTITION_TABLE_CSV}.csv ${ARDUINO_VARIANT_DIR}/${PARTITION_TABLE_CSV}-tinyuf2.csv + ) + +endif () diff --git a/ports/family_support.cmake b/ports/family_support.cmake index f96671492..a3204268b 100644 --- a/ports/family_support.cmake +++ b/ports/family_support.cmake @@ -44,6 +44,11 @@ endif () #------------------------------------ # Functions #------------------------------------ + +function(family_add_bin_hex TARGET) + # placeholder, will be override by family specific +endfunction() + function(family_add_default_example_warnings TARGET) # target_compile_options(${TARGET} PUBLIC # -Wall @@ -105,6 +110,10 @@ function(family_configure_common TARGET) # Generate map file target_link_options(${TARGET} PUBLIC "LINKER:-Map=$.map") + # All executable target linked with board target + family_add_board_target(board_${BOARD}) + target_link_libraries(${TARGET} PUBLIC board_${BOARD}) + # ETM Trace option if (TRACE_ETM STREQUAL "1") target_compile_definitions(${TARGET} PUBLIC TRACE_ETM) @@ -161,7 +170,6 @@ function(family_add_tinyusb TARGET OPT_MCU RTOS) target_link_libraries(${TARGET} PUBLIC ${TARGET}-tinyusb) endfunction() - function(family_add_uf2version TARGET DEPS_REPO) execute_process(COMMAND git describe --dirty --always --tags OUTPUT_VARIABLE GIT_VERSION) string(STRIP ${GIT_VERSION} GIT_VERSION) @@ -181,6 +189,18 @@ function(family_add_uf2version TARGET DEPS_REPO) ) endfunction() +function(family_configure_tinyuf2 TARGET OPT_MCU) + family_configure_common(${TARGET}) + family_add_bin_hex(${TARGET}) + + #target_include_directories(${TARGET} PUBLIC) + #target_compile_definitions(${TARGET} PUBLIC) + include(${TOP}/src/tinyuf2.cmake) + add_tinyuf2(${TARGET}) + + family_add_tinyusb(tinyuf2 ${OPT_MCU} none) +endfunction() + #---------------------------------- # Output #---------------------------------- @@ -308,8 +328,5 @@ function(family_flash_uf2 TARGET FAMILY_ID) ) endfunction() -#---------------------------------- # Family specific -#---------------------------------- - include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) diff --git a/ports/mimxrt10xx/CMakeLists.txt b/ports/mimxrt10xx/CMakeLists.txt index 9a64f7862..77a6fb515 100644 --- a/ports/mimxrt10xx/CMakeLists.txt +++ b/ports/mimxrt10xx/CMakeLists.txt @@ -7,9 +7,7 @@ project(tinyuf2 C ASM) #------------------------------------ # TinyUF2 #------------------------------------ - set(CMAKE_EXECUTABLE_SUFFIX .elf) - add_executable(tinyuf2 board_flash.c boards.c @@ -22,18 +20,7 @@ target_link_options(tinyuf2 PUBLIC "LINKER:--script=${CMAKE_CURRENT_LIST_DIR}/linker/common.ld" ) -family_configure_common(tinyuf2) - -# add board target -add_board_target(board_${BOARD}) -target_link_libraries(tinyuf2 PUBLIC board_${BOARD}) - -# Add tinyusb target -family_add_tinyusb(tinyuf2 OPT_MCU_MIMXRT1XXX none) - -# Add tinyuf2 -include(${TOP}/src/tinyuf2.cmake) -add_tinyuf2(tinyuf2) +family_configure_tinyuf2(tinyuf2 OPT_MCU_MIMXRT1XXX) family_flash_sdp(tinyuf2) family_flash_jlink(tinyuf2 hex) @@ -41,9 +28,8 @@ family_add_uf2(tinyuf2 ${UF2_FAMILY_ID} bin ${UF2_ADDR}) family_flash_uf2(tinyuf2 ${UF2_FAMILY_ID}) #------------------------------------ -# Application (including self update) +# Application (e.g self update) #------------------------------------ - add_subdirectory(apps/erase_firmware) if (BOARD STREQUAL metro_m7_1011) diff --git a/ports/mimxrt10xx/apps/app.cmake b/ports/mimxrt10xx/apps/app.cmake index 0ada9361d..b943d21ef 100644 --- a/ports/mimxrt10xx/apps/app.cmake +++ b/ports/mimxrt10xx/apps/app.cmake @@ -19,10 +19,8 @@ function(configure_app TARGET) "LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../linker/common.ld" ) - family_add_bin_hex(${TARGET}) family_add_uf2(${TARGET} ${UF2_FAMILY_ID}) - family_flash_uf2(${TARGET} ${UF2_FAMILY_ID}) - #family_flash_jlink(${TARGET} hex) - family_flash_pyocd(${TARGET} hex) + family_flash_jlink(${TARGET} hex) + #family_flash_pyocd(${TARGET} hex) endfunction() diff --git a/ports/mimxrt10xx/apps/erase_firmware/CMakeLists.txt b/ports/mimxrt10xx/apps/erase_firmware/CMakeLists.txt index 8d566dfcf..6b66b852f 100644 --- a/ports/mimxrt10xx/apps/erase_firmware/CMakeLists.txt +++ b/ports/mimxrt10xx/apps/erase_firmware/CMakeLists.txt @@ -11,10 +11,13 @@ include(${CMAKE_CURRENT_LIST_DIR}/../app.cmake) #------------------------------------ add_executable(erase_firmware ${TOP}/apps/erase_firmware/erase_firmware.c + ${CMAKE_CURRENT_LIST_DIR}/../../boards.c ) target_include_directories(erase_firmware PUBLIC ${TOP}/src ) +target_compile_definitions(erase_firmware PUBLIC + BUILD_NO_TINYUSB + ) configure_app(erase_firmware) -target_link_libraries(erase_firmware PUBLIC board_${BOARD}) diff --git a/ports/mimxrt10xx/apps/esp32programmer/CMakeLists.txt b/ports/mimxrt10xx/apps/esp32programmer/CMakeLists.txt index 59c414a5a..bfe5cc97c 100644 --- a/ports/mimxrt10xx/apps/esp32programmer/CMakeLists.txt +++ b/ports/mimxrt10xx/apps/esp32programmer/CMakeLists.txt @@ -21,6 +21,4 @@ target_include_directories(esp32programmer PUBLIC ) configure_app(esp32programmer) - -target_link_libraries(esp32programmer PUBLIC board_${BOARD}) family_add_tinyusb(esp32programmer OPT_MCU_MIMXRT1XXX none) diff --git a/ports/mimxrt10xx/apps/factory_test/CMakeLists.txt b/ports/mimxrt10xx/apps/factory_test/CMakeLists.txt index 0029fc7bf..71976e70a 100644 --- a/ports/mimxrt10xx/apps/factory_test/CMakeLists.txt +++ b/ports/mimxrt10xx/apps/factory_test/CMakeLists.txt @@ -22,6 +22,4 @@ target_include_directories(factory_test PUBLIC ) configure_app(factory_test) - -target_link_libraries(factory_test PUBLIC board_${BOARD}) family_add_tinyusb(factory_test OPT_MCU_MIMXRT1XXX none) diff --git a/ports/mimxrt10xx/apps/factory_test_metro_sd/CMakeLists.txt b/ports/mimxrt10xx/apps/factory_test_metro_sd/CMakeLists.txt index 8c926e15b..2aaf36ca2 100644 --- a/ports/mimxrt10xx/apps/factory_test_metro_sd/CMakeLists.txt +++ b/ports/mimxrt10xx/apps/factory_test_metro_sd/CMakeLists.txt @@ -28,11 +28,8 @@ include(middleware-sdmmc/CMakeLists.txt) add_sdmmc(factory_test_metro_sd) configure_app(factory_test_metro_sd) - -target_link_libraries(factory_test_metro_sd PUBLIC board_${BOARD}) family_add_tinyusb(factory_test_metro_sd OPT_MCU_MIMXRT1XXX none) - #------------------------------------ # #------------------------------------ diff --git a/ports/mimxrt10xx/family.cmake b/ports/mimxrt10xx/family.cmake index a008de621..64fc3a948 100644 --- a/ports/mimxrt10xx/family.cmake +++ b/ports/mimxrt10xx/family.cmake @@ -62,7 +62,7 @@ string(REGEX REPLACE ".*= *(0x[0-9a-fA-F]+).*" "\\1" IVT_ORIGIN ${IVT_ORIGIN}) # BOARD_TARGET #------------------------------------ # used by all executable targets -function(add_board_target BOARD_TARGET) +function(family_add_board_target BOARD_TARGET) if (TARGET ${BOARD_TARGET}) return() endif () @@ -113,8 +113,7 @@ function(add_board_target BOARD_TARGET) XIP_BOOT_HEADER_ENABLE=1 ) target_link_options(${BOARD_TARGET} PUBLIC - --specs=nosys.specs - --specs=nano.specs + --specs=nosys.specs --specs=nano.specs ) endfunction() diff --git a/ports/stm32f3/CMakeLists.txt b/ports/stm32f3/CMakeLists.txt index c090328f7..d2677218d 100644 --- a/ports/stm32f3/CMakeLists.txt +++ b/ports/stm32f3/CMakeLists.txt @@ -7,22 +7,22 @@ project(tinyuf2 C ASM) #------------------------------------ # TinyUF2 #------------------------------------ - set(CMAKE_EXECUTABLE_SUFFIX .elf) -add_executable(tinyuf2) - -target_sources(tinyuf2 PUBLIC +add_executable(tinyuf2 board_flash.c boards.c boards.h + ${TOP}/lib/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c ) #target_compile_options(tinyuf2 PUBLIC) -#target_link_options(tinyuf2 PUBLIC) - -family_configure_tinyuf2(tinyuf2) +target_link_options(tinyuf2 PUBLIC + "LINKER:--script=${CMAKE_CURRENT_LIST_DIR}/linker/stm32f3_boot.ld" + ) -family_add_bin_hex(tinyuf2) +family_configure_tinyuf2(tinyuf2 OPT_MCU_STM32F3) family_flash_jlink(tinyuf2) -# Self Update +#------------------------------------ +# Application (e.g self update) +#------------------------------------ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/self_update) diff --git a/ports/stm32f3/apps/self_update/CMakeLists.txt b/ports/stm32f3/apps/self_update/CMakeLists.txt index f53b010a3..53dd4827f 100644 --- a/ports/stm32f3/apps/self_update/CMakeLists.txt +++ b/ports/stm32f3/apps/self_update/CMakeLists.txt @@ -30,6 +30,4 @@ target_link_options(self_update PUBLIC ) family_configure_common(self_update) -target_link_libraries(self_update board_${BOARD}) -family_add_bin_hex(self_update) family_add_uf2(self_update ${UF2_FAMILY_ID}) diff --git a/ports/stm32f3/family.cmake b/ports/stm32f3/family.cmake index 98dacb934..bf1a04629 100644 --- a/ports/stm32f3/family.cmake +++ b/ports/stm32f3/family.cmake @@ -27,7 +27,7 @@ set(CMAKE_TOOLCHAIN_FILE ${TOP}/cmake/toolchain/arm_${TOOLCHAIN}.cmake) #------------------------------------ # used by all executable targets -function(add_board_target BOARD_TARGET) +function(family_add_board_target BOARD_TARGET) if (TARGET ${BOARD_TARGET}) return() endif () @@ -63,31 +63,10 @@ function(add_board_target BOARD_TARGET) ) target_link_options(${BOARD_TARGET} PUBLIC -nostartfiles - # nanolib - --specs=nosys.specs - --specs=nano.specs + --specs=nosys.specs --specs=nano.specs ) endfunction() #------------------------------------ # Main target #------------------------------------ -function(family_configure_tinyuf2 TARGET) - family_configure_common(${TARGET}) - add_board_target(board_${BOARD}) - - #---------- Port Specific ---------- - target_sources(${TARGET} PUBLIC - ${TOP}/lib/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c - ) - #target_include_directories(${TARGET} PUBLIC) - #target_compile_definitions(${TARGET} PUBLIC) - target_link_options(${TARGET} PUBLIC - "LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/stm32f3_boot.ld" - ) - - include(${TOP}/src/tinyuf2.cmake) - add_tinyuf2(${TARGET}) - - target_link_libraries(${TARGET} PUBLIC board_${BOARD}) -endfunction() diff --git a/tools/touch1200.py b/tools/touch1200.py index 63d39e44d..af98b8c4d 100644 --- a/tools/touch1200.py +++ b/tools/touch1200.py @@ -2,6 +2,7 @@ import serial import time + @click.command() @click.argument('port', default='/dev/ttyACM0') def connect_serial(port): @@ -29,5 +30,6 @@ def connect_serial(port): set.close() print(f"Disconnected from {port}.") + if __name__ == '__main__': connect_serial()