|
| 1 | +cmake_minimum_required(VERSION 3.5) |
| 2 | + |
| 3 | +# List of sub-applications |
| 4 | +set(SUB_APP_NAMES |
| 5 | + tic_tac_toe |
| 6 | + wifi_list |
| 7 | + calculator |
| 8 | + synth_piano |
| 9 | + game_of_life |
| 10 | +) |
| 11 | + |
| 12 | +# List of corresponding flash addresses |
| 13 | +set(SUB_APP_ADDRS |
| 14 | + 0x220000 |
| 15 | + 0x4E0000 |
| 16 | + 0x7A0000 |
| 17 | + 0xA60000 |
| 18 | + 0xD20000 |
| 19 | +) |
| 20 | + |
| 21 | +# Get the length of each list |
| 22 | +list(LENGTH SUB_APP_NAMES LENGTH_SUB_APP_NAMES) |
| 23 | +list(LENGTH SUB_APP_ADDRS LENGTH_SUB_APP_ADDRS) |
| 24 | + |
| 25 | +# Ensure both lists have the same length |
| 26 | +if(NOT LENGTH_SUB_APP_NAMES EQUAL LENGTH_SUB_APP_ADDRS) |
| 27 | + message(FATAL_ERROR "The number of applications does not match the number of addresses.") |
| 28 | +endif() |
| 29 | + |
| 30 | +# Function to build and flash each sub-application |
| 31 | +function(build_and_flash_app APP ADDR) |
| 32 | + message(STATUS "Building ${APP}") |
| 33 | + execute_process( |
| 34 | + COMMAND idf.py build |
| 35 | + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/apps/${APP} |
| 36 | + RESULT_VARIABLE build_result |
| 37 | + ) |
| 38 | + if(NOT build_result EQUAL 0) |
| 39 | + message(FATAL_ERROR "Failed to build ${APP}") |
| 40 | + endif() |
| 41 | + |
| 42 | + message(STATUS "Flashing ${APP} to address ${ADDR}") |
| 43 | + execute_process( |
| 44 | + COMMAND esptool.py --chip esp32s3 --baud 921600 --before default_reset --after hard_reset write_flash ${ADDR} ${CMAKE_SOURCE_DIR}/apps/${APP}/build/${APP}.bin |
| 45 | + RESULT_VARIABLE flash_result |
| 46 | + ) |
| 47 | + if(NOT flash_result EQUAL 0) |
| 48 | + message(FATAL_ERROR "Failed to flash ${APP}") |
| 49 | + endif() |
| 50 | +endfunction() |
| 51 | + |
| 52 | +# Iterate through each sub-application and build/flash them |
| 53 | +foreach(APP_IDX RANGE 0 ${LENGTH_SUB_APP_NAMES}-1) |
| 54 | + list(GET SUB_APP_NAMES ${APP_IDX} APP) |
| 55 | + list(GET SUB_APP_ADDRS ${APP_IDX} ADDR) |
| 56 | + build_and_flash_app(${APP} ${ADDR}) |
| 57 | +endforeach() |
0 commit comments