2022-05-27 04:10:51 -04:00
|
|
|
cmake_minimum_required(VERSION 3.16)
|
2018-09-13 02:54:59 -04:00
|
|
|
|
2022-08-31 16:59:15 -04:00
|
|
|
include(${IDF_PATH}/tools/cmake/idf.cmake)
|
2018-09-13 02:54:59 -04:00
|
|
|
project(${ULP_APP_NAME} ASM C)
|
2022-08-28 07:55:49 -04:00
|
|
|
add_executable(${ULP_APP_NAME})
|
2023-02-17 04:22:34 -05:00
|
|
|
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
|
2018-09-13 02:54:59 -04:00
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
option(ULP_COCPU_IS_RISCV "Use RISC-V based ULP" OFF)
|
2023-02-27 04:03:42 -05:00
|
|
|
option(ULP_COCPU_IS_LP_CORE "Use RISC-V based LP Core" OFF)
|
2020-04-17 15:34:56 -04:00
|
|
|
|
2022-01-21 04:13:48 -05:00
|
|
|
message(STATUS "Building ULP app ${ULP_APP_NAME}")
|
2018-11-27 06:31:46 -05:00
|
|
|
|
2022-08-28 07:47:12 -04:00
|
|
|
# Check the supported assembler version
|
2023-02-27 04:03:42 -05:00
|
|
|
if(NOT (ULP_COCPU_IS_RISCV OR ULP_COCPU_IS_LP_CORE))
|
2022-08-31 16:59:15 -04:00
|
|
|
check_expected_tool_version("esp32ulp-elf" ${CMAKE_ASM_COMPILER})
|
2022-08-28 07:47:12 -04:00
|
|
|
endif()
|
2018-08-31 05:32:24 -04:00
|
|
|
|
2018-09-13 02:54:59 -04:00
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
set(ULP_MAP_GEN ${PYTHON} ${IDF_PATH}/components/ulp/esp32ulp_mapgen.py)
|
2021-03-31 04:25:35 -04:00
|
|
|
get_filename_component(sdkconfig_dir ${SDKCONFIG_HEADER} DIRECTORY)
|
2018-09-13 02:54:59 -04:00
|
|
|
|
|
|
|
foreach(include ${COMPONENT_INCLUDES})
|
|
|
|
list(APPEND component_includes -I${include})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS ${component_includes})
|
2019-05-09 22:53:08 -04:00
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS -I${COMPONENT_DIR})
|
2018-09-13 02:54:59 -04:00
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS -I${sdkconfig_dir})
|
|
|
|
|
2022-08-28 07:55:49 -04:00
|
|
|
target_include_directories(${ULP_APP_NAME} PRIVATE ${COMPONENT_INCLUDES})
|
2018-09-13 02:54:59 -04:00
|
|
|
|
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS -D__ASSEMBLER__)
|
|
|
|
|
2022-08-28 08:00:20 -04:00
|
|
|
# Pre-process the linker script
|
|
|
|
if(ULP_COCPU_IS_RISCV)
|
|
|
|
set(ULP_LD_TEMPLATE ${IDF_PATH}/components/ulp/ld/ulp_riscv.ld)
|
2023-02-27 04:03:42 -05:00
|
|
|
elseif(ULP_COCPU_IS_LP_CORE)
|
|
|
|
set(ULP_LD_TEMPLATE ${IDF_PATH}/components/ulp/ld/lp_core_riscv.ld)
|
2022-08-28 08:00:20 -04:00
|
|
|
else()
|
|
|
|
set(ULP_LD_TEMPLATE ${IDF_PATH}/components/ulp/ld/ulp_fsm.ld)
|
|
|
|
endif()
|
2023-02-27 04:03:42 -05:00
|
|
|
|
2018-09-13 02:54:59 -04:00
|
|
|
get_filename_component(ULP_LD_SCRIPT ${ULP_LD_TEMPLATE} NAME)
|
2020-11-10 01:51:08 -05:00
|
|
|
add_custom_command(OUTPUT ${ULP_LD_SCRIPT}
|
|
|
|
COMMAND ${CMAKE_C_COMPILER} -E -P -xc -o ${ULP_LD_SCRIPT} ${ULP_PREPROCESSOR_ARGS} ${ULP_LD_TEMPLATE}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
2022-08-28 08:00:20 -04:00
|
|
|
MAIN_DEPENDENCY ${ULP_LD_TEMPLATE}
|
|
|
|
DEPENDS ${SDKCONFIG_HEADER}
|
|
|
|
COMMENT "Generating ${ULP_LD_SCRIPT} linker script..."
|
2020-11-10 01:51:08 -05:00
|
|
|
VERBATIM)
|
2022-08-28 08:00:20 -04:00
|
|
|
add_custom_target(ld_script DEPENDS ${ULP_LD_SCRIPT})
|
|
|
|
add_dependencies(${ULP_APP_NAME} ld_script)
|
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE SHELL:-T ${CMAKE_CURRENT_BINARY_DIR}/${ULP_LD_SCRIPT})
|
2018-09-13 02:54:59 -04:00
|
|
|
|
2022-07-12 23:11:19 -04:00
|
|
|
# To avoid warning "Manually-specified variables were not used by the project"
|
|
|
|
set(bypassWarning "${IDF_TARGET}")
|
2024-03-11 07:15:09 -04:00
|
|
|
set(bypassWarning "${CONFIG_ESP_ROM_HAS_LP_ROM}")
|
2020-04-17 15:34:56 -04:00
|
|
|
if(ULP_COCPU_IS_RISCV)
|
|
|
|
#risc-v ulp uses extra files for building:
|
2020-11-10 02:40:01 -05:00
|
|
|
list(APPEND ULP_S_SOURCES
|
2023-12-08 08:09:39 -05:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_vectors.S"
|
2022-02-28 05:12:28 -05:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/start.S"
|
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_adc.c"
|
2022-08-03 01:59:44 -04:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_lock.c"
|
2022-07-25 02:04:08 -04:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_uart.c"
|
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_print.c"
|
2022-08-09 09:46:14 -04:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_i2c.c"
|
2023-05-19 09:34:44 -04:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_utils.c"
|
2023-12-08 08:09:39 -05:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_touch.c"
|
2023-12-14 07:26:00 -05:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_gpio.c"
|
2023-12-08 08:09:39 -05:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_interrupt.c")
|
2020-04-17 15:34:56 -04:00
|
|
|
|
2022-08-28 07:55:49 -04:00
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE "-nostartfiles")
|
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE -Wl,--gc-sections)
|
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.map)
|
|
|
|
target_sources(${ULP_APP_NAME} PRIVATE ${ULP_S_SOURCES})
|
2020-04-17 15:34:56 -04:00
|
|
|
#Makes the csr utillies for riscv visible:
|
2022-08-03 01:59:44 -04:00
|
|
|
target_include_directories(${ULP_APP_NAME} PRIVATE "${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/include"
|
2023-12-08 08:09:39 -05:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/shared/include"
|
|
|
|
"${IDF_PATH}/components/riscv/include")
|
2022-08-28 08:13:15 -04:00
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE SHELL:-T ${IDF_PATH}/components/ulp/ld/${IDF_TARGET}.peripherals.ld)
|
2022-10-10 10:16:45 -04:00
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE "-Wl,--no-warn-rwx-segments")
|
2022-02-28 05:12:28 -05:00
|
|
|
target_compile_definitions(${ULP_APP_NAME} PRIVATE IS_ULP_COCPU)
|
2023-08-28 05:39:48 -04:00
|
|
|
target_compile_definitions(${ULP_APP_NAME} PRIVATE ULP_RISCV_REGISTER_OPS)
|
2020-04-17 15:34:56 -04:00
|
|
|
|
2023-02-27 04:03:42 -05:00
|
|
|
elseif(ULP_COCPU_IS_LP_CORE)
|
|
|
|
list(APPEND ULP_S_SOURCES
|
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/start.S"
|
2023-03-09 01:14:09 -05:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/vector.S"
|
2023-04-26 01:58:19 -04:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/shared/ulp_lp_core_memory_shared.c"
|
|
|
|
"${IDF_PATH}/components/ulp/lp_core/shared/ulp_lp_core_lp_timer_shared.c"
|
2023-03-09 01:14:09 -05:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_startup.c"
|
2023-03-20 11:08:38 -04:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_utils.c"
|
2023-11-02 04:34:40 -04:00
|
|
|
|
2023-05-22 08:48:15 -04:00
|
|
|
"${IDF_PATH}/components/hal/uart_hal_iram.c"
|
|
|
|
"${IDF_PATH}/components/hal/uart_hal.c"
|
2023-05-30 11:42:19 -04:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_uart.c"
|
2023-11-02 04:34:40 -04:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_print.c"
|
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_i2c.c")
|
2023-02-27 04:03:42 -05:00
|
|
|
|
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE "-nostartfiles")
|
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE "-Wl,--no-warn-rwx-segments")
|
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE -Wl,--gc-sections)
|
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.map)
|
2024-03-08 01:22:07 -05:00
|
|
|
|
|
|
|
if(${IDF_TARGET} STREQUAL "esp32c5")
|
|
|
|
set(target_folder "esp32c5/mp")
|
|
|
|
else()
|
|
|
|
set(target_folder ${IDF_TARGET})
|
|
|
|
endif()
|
|
|
|
|
2023-04-26 01:58:19 -04:00
|
|
|
target_link_options(${ULP_APP_NAME}
|
2024-03-08 01:22:07 -05:00
|
|
|
PRIVATE SHELL:-T ${IDF_PATH}/components/soc/${target_folder}/ld/${IDF_TARGET}.peripherals.ld)
|
2023-11-02 04:34:40 -04:00
|
|
|
|
|
|
|
if(CONFIG_ESP_ROM_HAS_LP_ROM)
|
|
|
|
target_link_options(${ULP_APP_NAME}
|
|
|
|
PRIVATE SHELL:-T ${IDF_PATH}/components/esp_rom/${IDF_TARGET}/ld/${IDF_TARGET}lp.rom.ld)
|
|
|
|
target_link_options(${ULP_APP_NAME}
|
|
|
|
PRIVATE SHELL:-T ${IDF_PATH}/components/esp_rom/${IDF_TARGET}/ld/${IDF_TARGET}lp.rom.newlib.ld)
|
|
|
|
target_link_options(${ULP_APP_NAME}
|
|
|
|
PRIVATE SHELL:-T ${IDF_PATH}/components/esp_rom/${IDF_TARGET}/ld/${IDF_TARGET}lp.rom.version.ld)
|
|
|
|
endif()
|
|
|
|
|
2023-02-27 04:03:42 -05:00
|
|
|
target_sources(${ULP_APP_NAME} PRIVATE ${ULP_S_SOURCES})
|
2023-04-26 01:58:19 -04:00
|
|
|
target_include_directories(${ULP_APP_NAME} PRIVATE "${IDF_PATH}/components/ulp/lp_core/lp_core/include"
|
|
|
|
"${IDF_PATH}/components/ulp/lp_core/shared/include")
|
2023-05-22 08:48:15 -04:00
|
|
|
target_compile_definitions(${ULP_APP_NAME} PRIVATE IS_ULP_COCPU)
|
2020-04-17 15:34:56 -04:00
|
|
|
|
2023-02-27 04:03:42 -05:00
|
|
|
else()
|
2020-04-17 15:34:56 -04:00
|
|
|
foreach(ulp_s_source ${ULP_S_SOURCES})
|
|
|
|
get_filename_component(ulp_ps_source ${ulp_s_source} NAME_WE)
|
|
|
|
set(ulp_ps_output ${CMAKE_CURRENT_BINARY_DIR}/${ulp_ps_source}.ulp.S)
|
|
|
|
# Generate preprocessed assembly files.
|
2020-11-10 01:51:08 -05:00
|
|
|
add_custom_command(OUTPUT ${ulp_ps_output}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
COMMAND ${CMAKE_C_COMPILER} -E -P -xc ${ULP_PREPROCESSOR_ARGS}
|
|
|
|
-o ${ulp_ps_output} ${ulp_s_source}
|
2022-08-28 08:00:20 -04:00
|
|
|
DEPENDS ${ulp_s_source}
|
2020-11-10 01:51:08 -05:00
|
|
|
VERBATIM)
|
2020-04-17 15:34:56 -04:00
|
|
|
# During assembly file compilation, output listing files as well.
|
|
|
|
set_source_files_properties(${ulp_ps_output}
|
|
|
|
PROPERTIES COMPILE_FLAGS
|
|
|
|
"-al=${CMAKE_CURRENT_BINARY_DIR}/${ulp_ps_source}.lst")
|
|
|
|
list(APPEND ULP_PS_SOURCES ${ulp_ps_output})
|
|
|
|
endforeach()
|
2020-11-10 02:40:01 -05:00
|
|
|
|
2022-08-28 07:55:49 -04:00
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE -Map=${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.map)
|
|
|
|
target_sources(${ULP_APP_NAME} PRIVATE ${ULP_PS_SOURCES})
|
2018-09-13 02:54:59 -04:00
|
|
|
|
2020-04-17 15:34:56 -04:00
|
|
|
endif()
|
2018-09-13 02:54:59 -04:00
|
|
|
|
2023-02-27 04:03:42 -05:00
|
|
|
if(ULP_COCPU_IS_LP_CORE)
|
|
|
|
set(ULP_BASE_ADDR "0x0")
|
|
|
|
else()
|
|
|
|
set(ULP_BASE_ADDR "0x50000000")
|
|
|
|
endif()
|
2022-08-28 08:11:46 -04:00
|
|
|
|
2018-09-13 02:54:59 -04:00
|
|
|
# Dump the list of global symbols in a convenient format
|
2020-11-10 01:51:08 -05:00
|
|
|
add_custom_command(OUTPUT ${ULP_APP_NAME}.sym
|
2022-08-28 08:11:46 -04:00
|
|
|
COMMAND ${CMAKE_NM} -f posix -g $<TARGET_FILE:${ULP_APP_NAME}> > ${ULP_APP_NAME}.sym
|
2020-11-10 01:51:08 -05:00
|
|
|
DEPENDS ${ULP_APP_NAME}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
2018-09-13 02:54:59 -04:00
|
|
|
|
|
|
|
# Dump the binary for inclusion into the project
|
2020-11-10 01:51:08 -05:00
|
|
|
add_custom_command(OUTPUT ${ULP_APP_NAME}.bin
|
|
|
|
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${ULP_APP_NAME}> ${ULP_APP_NAME}.bin
|
|
|
|
DEPENDS ${ULP_APP_NAME}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${ULP_APP_NAME}.ld ${ULP_APP_NAME}.h
|
2022-08-28 08:11:46 -04:00
|
|
|
COMMAND ${ULP_MAP_GEN} -s ${ULP_APP_NAME}.sym -o ${ULP_APP_NAME} --base ${ULP_BASE_ADDR}
|
2020-11-10 01:51:08 -05:00
|
|
|
DEPENDS ${ULP_APP_NAME}.sym
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
2018-09-13 02:54:59 -04:00
|
|
|
|
|
|
|
# Building the component separately from the project should result in
|
|
|
|
# ULP files being built.
|
|
|
|
add_custom_target(build
|
|
|
|
DEPENDS ${ULP_APP_NAME} ${ULP_APP_NAME}.bin ${ULP_APP_NAME}.sym
|
2018-08-31 05:32:24 -04:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.ld
|
2018-09-13 02:54:59 -04:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.h
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|