diff --git a/libraries/AP_HAL_ChibiOS/system.cpp b/libraries/AP_HAL_ChibiOS/system.cpp index 09cb666821500..6c3c9a686802a 100644 --- a/libraries/AP_HAL_ChibiOS/system.cpp +++ b/libraries/AP_HAL_ChibiOS/system.cpp @@ -330,16 +330,14 @@ void panic(const char *errormsg, ...) INTERNAL_ERROR(AP_InternalError::error_t::panic); va_list ap; - va_start(ap, errormsg); - vprintf(errormsg, ap); - va_end(ap); - - hal.scheduler->delay_microseconds(10000); + uint16_t delay_ms = 10000; while (1) { va_start(ap, errormsg); vprintf(errormsg, ap); va_end(ap); - hal.scheduler->delay(500); + printf("\n"); + hal.scheduler->delay(delay_ms); + delay_ms = 500; } #else // we don't support variable args in bootlaoder diff --git a/libraries/AP_HAL_ESP32/SdCard.cpp b/libraries/AP_HAL_ESP32/SdCard.cpp index 4644797cf32e3..2ad6f3a596cc7 100644 --- a/libraries/AP_HAL_ESP32/SdCard.cpp +++ b/libraries/AP_HAL_ESP32/SdCard.cpp @@ -207,7 +207,7 @@ void mount_sdcard_spi() ESP_LOGI(TAG, "Initializing SD card as SDSPI"); esp_vfs_fat_sdmmc_mount_config_t mount_config = { .format_if_mount_failed = false, - .max_files = 10, + .max_files = 5, .allocation_unit_size = 16 * 1024 }; diff --git a/libraries/AP_HAL_ESP32/targets/esp32/esp-idf/CMakeLists.txt b/libraries/AP_HAL_ESP32/targets/esp32/esp-idf/CMakeLists.txt index 32b77dd94fb90..7a202d769d894 100644 --- a/libraries/AP_HAL_ESP32/targets/esp32/esp-idf/CMakeLists.txt +++ b/libraries/AP_HAL_ESP32/targets/esp32/esp-idf/CMakeLists.txt @@ -123,3 +123,76 @@ idf_build_executable(${elf_file}) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) +# Additional targets for measuring RAM use: size, size-components, size-files +# - Adapted from ${IDF_PATH}/tools/cmake/project.cmake +# +# Reference: +# - https://docs.espressif.com/projects/esp-idf/en/v5.0/esp32s3/api-guides/performance/size.html#minimizing-binary-size +# +# Usage: +# cd ./build/esp32s3xxx/esp-idf_build +# ninja -v -v size +# +set(mapfile "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map") +# Add cross-reference table to the map file +target_link_options(${elf_file} PRIVATE "-Wl,--cref") +# Add this symbol as a hint for esp_idf_size to guess the target name +target_link_options(${elf_file} PRIVATE "-Wl,--defsym=IDF_TARGET_${idf_target}=0") +# Enable map file output +target_link_options(${elf_file} PRIVATE "-Wl,--Map=${mapfile}") +# Check if linker supports --no-warn-rwx-segments +execute_process(COMMAND ${CMAKE_LINKER} "--no-warn-rwx-segments" "--version" + RESULT_VARIABLE result + OUTPUT_QUIET + ERROR_QUIET) +if(${result} EQUAL 0) + # Do not print RWX segment warnings + target_link_options(${elf_file} PRIVATE "-Wl,--no-warn-rwx-segments") +endif() +if(CONFIG_ESP_ORPHAN_SECTION_WARNING) + # Print warnings if orphan sections are found + target_link_options(${elf_file} PRIVATE "-Wl,--orphan-handling=warn") +endif() + +idf_build_get_property(idf_path IDF_PATH) +idf_build_get_property(python PYTHON) + +set(idf_size ${python} -m esp_idf_size) + +# Add size targets, depend on map file, run esp_idf_size +# OUTPUT_JSON is passed for compatibility reasons, SIZE_OUTPUT_FORMAT +# environment variable is recommended and has higher priority +add_custom_target(size + COMMAND ${CMAKE_COMMAND} + -D "IDF_SIZE_TOOL=${idf_size}" + -D "MAP_FILE=${mapfile}" + -D "OUTPUT_JSON=${OUTPUT_JSON}" + -P "${idf_path}/tools/cmake/run_size_tool.cmake" + DEPENDS ${mapfile} + USES_TERMINAL + VERBATIM +) + +add_custom_target(size-files + COMMAND ${CMAKE_COMMAND} + -D "IDF_SIZE_TOOL=${idf_size}" + -D "IDF_SIZE_MODE=--files" + -D "MAP_FILE=${mapfile}" + -D "OUTPUT_JSON=${OUTPUT_JSON}" + -P "${idf_path}/tools/cmake/run_size_tool.cmake" + DEPENDS ${mapfile} + USES_TERMINAL + VERBATIM +) + +add_custom_target(size-components + COMMAND ${CMAKE_COMMAND} + -D "IDF_SIZE_TOOL=${idf_size}" + -D "IDF_SIZE_MODE=--archives" + -D "MAP_FILE=${mapfile}" + -D "OUTPUT_JSON=${OUTPUT_JSON}" + -P "${idf_path}/tools/cmake/run_size_tool.cmake" + DEPENDS ${mapfile} + USES_TERMINAL + VERBATIM +) diff --git a/libraries/AP_HAL_ESP32/targets/esp32s3/esp-idf/CMakeLists.txt b/libraries/AP_HAL_ESP32/targets/esp32s3/esp-idf/CMakeLists.txt index 8a63d422c509f..72a569eedeab0 100644 --- a/libraries/AP_HAL_ESP32/targets/esp32s3/esp-idf/CMakeLists.txt +++ b/libraries/AP_HAL_ESP32/targets/esp32s3/esp-idf/CMakeLists.txt @@ -122,3 +122,77 @@ target_link_libraries(${elf_file} idf_build_executable(${elf_file}) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + +# Additional targets for measuring RAM use: size, size-components, size-files +# - Adapted from ${IDF_PATH}/tools/cmake/project.cmake +# +# Reference: +# - https://docs.espressif.com/projects/esp-idf/en/v5.0/esp32s3/api-guides/performance/size.html#minimizing-binary-size +# +# Usage: +# cd ./build/esp32s3xxx/esp-idf_build +# ninja -v -v size +# +set(mapfile "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map") +# Add cross-reference table to the map file +target_link_options(${elf_file} PRIVATE "-Wl,--cref") +# Add this symbol as a hint for esp_idf_size to guess the target name +target_link_options(${elf_file} PRIVATE "-Wl,--defsym=IDF_TARGET_${idf_target}=0") +# Enable map file output +target_link_options(${elf_file} PRIVATE "-Wl,--Map=${mapfile}") +# Check if linker supports --no-warn-rwx-segments +execute_process(COMMAND ${CMAKE_LINKER} "--no-warn-rwx-segments" "--version" + RESULT_VARIABLE result + OUTPUT_QUIET + ERROR_QUIET) +if(${result} EQUAL 0) + # Do not print RWX segment warnings + target_link_options(${elf_file} PRIVATE "-Wl,--no-warn-rwx-segments") +endif() +if(CONFIG_ESP_ORPHAN_SECTION_WARNING) + # Print warnings if orphan sections are found + target_link_options(${elf_file} PRIVATE "-Wl,--orphan-handling=warn") +endif() + +idf_build_get_property(idf_path IDF_PATH) +idf_build_get_property(python PYTHON) + +set(idf_size ${python} -m esp_idf_size) + +# Add size targets, depend on map file, run esp_idf_size +# OUTPUT_JSON is passed for compatibility reasons, SIZE_OUTPUT_FORMAT +# environment variable is recommended and has higher priority +add_custom_target(size + COMMAND ${CMAKE_COMMAND} + -D "IDF_SIZE_TOOL=${idf_size}" + -D "MAP_FILE=${mapfile}" + -D "OUTPUT_JSON=${OUTPUT_JSON}" + -P "${idf_path}/tools/cmake/run_size_tool.cmake" + DEPENDS ${mapfile} + USES_TERMINAL + VERBATIM +) + +add_custom_target(size-files + COMMAND ${CMAKE_COMMAND} + -D "IDF_SIZE_TOOL=${idf_size}" + -D "IDF_SIZE_MODE=--files" + -D "MAP_FILE=${mapfile}" + -D "OUTPUT_JSON=${OUTPUT_JSON}" + -P "${idf_path}/tools/cmake/run_size_tool.cmake" + DEPENDS ${mapfile} + USES_TERMINAL + VERBATIM +) + +add_custom_target(size-components + COMMAND ${CMAKE_COMMAND} + -D "IDF_SIZE_TOOL=${idf_size}" + -D "IDF_SIZE_MODE=--archives" + -D "MAP_FILE=${mapfile}" + -D "OUTPUT_JSON=${OUTPUT_JSON}" + -P "${idf_path}/tools/cmake/run_size_tool.cmake" + DEPENDS ${mapfile} + USES_TERMINAL + VERBATIM +)