2022-05-27 08:10:51 +00:00
|
|
|
cmake_minimum_required(VERSION 3.16)
|
2018-09-13 06:54:59 +00:00
|
|
|
|
2022-08-31 20:59:15 +00:00
|
|
|
include(${IDF_PATH}/tools/cmake/idf.cmake)
|
2018-09-13 06:54:59 +00:00
|
|
|
project(${ULP_APP_NAME} ASM C)
|
2022-08-28 11:55:49 +00:00
|
|
|
add_executable(${ULP_APP_NAME})
|
2023-02-17 09:22:34 +00:00
|
|
|
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
|
2018-09-13 06:54:59 +00:00
|
|
|
|
2020-04-17 19:34:56 +00:00
|
|
|
option(ULP_COCPU_IS_RISCV "Use RISC-V based ULP" OFF)
|
2023-02-27 09:03:42 +00:00
|
|
|
option(ULP_COCPU_IS_LP_CORE "Use RISC-V based LP Core" OFF)
|
2020-04-17 19:34:56 +00:00
|
|
|
|
2022-01-21 09:13:48 +00:00
|
|
|
message(STATUS "Building ULP app ${ULP_APP_NAME}")
|
2018-11-27 11:31:46 +00:00
|
|
|
|
2022-08-28 11:47:12 +00:00
|
|
|
# Check the supported assembler version
|
2023-02-27 09:03:42 +00:00
|
|
|
if(NOT (ULP_COCPU_IS_RISCV OR ULP_COCPU_IS_LP_CORE))
|
2022-08-31 20:59:15 +00:00
|
|
|
check_expected_tool_version("esp32ulp-elf" ${CMAKE_ASM_COMPILER})
|
2022-08-28 11:47:12 +00:00
|
|
|
endif()
|
2018-08-31 09:32:24 +00:00
|
|
|
|
2018-09-13 06:54:59 +00:00
|
|
|
|
2020-04-17 19:34:56 +00:00
|
|
|
set(ULP_MAP_GEN ${PYTHON} ${IDF_PATH}/components/ulp/esp32ulp_mapgen.py)
|
2021-03-31 08:25:35 +00:00
|
|
|
get_filename_component(sdkconfig_dir ${SDKCONFIG_HEADER} DIRECTORY)
|
2018-09-13 06:54:59 +00:00
|
|
|
|
|
|
|
foreach(include ${COMPONENT_INCLUDES})
|
|
|
|
list(APPEND component_includes -I${include})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS ${component_includes})
|
2019-05-10 02:53:08 +00:00
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS -I${COMPONENT_DIR})
|
2018-09-13 06:54:59 +00:00
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS -I${sdkconfig_dir})
|
|
|
|
|
2022-08-28 11:55:49 +00:00
|
|
|
target_include_directories(${ULP_APP_NAME} PRIVATE ${COMPONENT_INCLUDES})
|
2018-09-13 06:54:59 +00:00
|
|
|
|
|
|
|
list(APPEND ULP_PREPROCESSOR_ARGS -D__ASSEMBLER__)
|
|
|
|
|
2022-08-28 12:00:20 +00: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 09:03:42 +00:00
|
|
|
elseif(ULP_COCPU_IS_LP_CORE)
|
|
|
|
set(ULP_LD_TEMPLATE ${IDF_PATH}/components/ulp/ld/lp_core_riscv.ld)
|
2022-08-28 12:00:20 +00:00
|
|
|
else()
|
|
|
|
set(ULP_LD_TEMPLATE ${IDF_PATH}/components/ulp/ld/ulp_fsm.ld)
|
|
|
|
endif()
|
2023-02-27 09:03:42 +00:00
|
|
|
|
2018-09-13 06:54:59 +00:00
|
|
|
get_filename_component(ULP_LD_SCRIPT ${ULP_LD_TEMPLATE} NAME)
|
2020-11-10 06:51:08 +00: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 12:00:20 +00:00
|
|
|
MAIN_DEPENDENCY ${ULP_LD_TEMPLATE}
|
|
|
|
DEPENDS ${SDKCONFIG_HEADER}
|
|
|
|
COMMENT "Generating ${ULP_LD_SCRIPT} linker script..."
|
2020-11-10 06:51:08 +00:00
|
|
|
VERBATIM)
|
2022-08-28 12:00:20 +00: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 06:54:59 +00:00
|
|
|
|
2022-07-13 03:11:19 +00:00
|
|
|
# To avoid warning "Manually-specified variables were not used by the project"
|
|
|
|
set(bypassWarning "${IDF_TARGET}")
|
2020-04-17 19:34:56 +00:00
|
|
|
if(ULP_COCPU_IS_RISCV)
|
|
|
|
#risc-v ulp uses extra files for building:
|
2020-11-10 07:40:01 +00:00
|
|
|
list(APPEND ULP_S_SOURCES
|
2022-02-28 10:12:28 +00: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 05:59:44 +00:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_lock.c"
|
2022-07-25 06:04:08 +00: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 13:46:14 +00:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_i2c.c"
|
2023-05-19 13:34:44 +00:00
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_utils.c"
|
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/ulp_riscv_touch.c")
|
2020-04-17 19:34:56 +00:00
|
|
|
|
2022-08-28 11:55:49 +00: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 19:34:56 +00:00
|
|
|
#Makes the csr utillies for riscv visible:
|
2022-08-03 05:59:44 +00:00
|
|
|
target_include_directories(${ULP_APP_NAME} PRIVATE "${IDF_PATH}/components/ulp/ulp_riscv/ulp_core/include"
|
|
|
|
"${IDF_PATH}/components/ulp/ulp_riscv/shared/include")
|
2022-08-28 12:13:15 +00:00
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE SHELL:-T ${IDF_PATH}/components/ulp/ld/${IDF_TARGET}.peripherals.ld)
|
2022-10-10 14:16:45 +00:00
|
|
|
target_link_options(${ULP_APP_NAME} PRIVATE "-Wl,--no-warn-rwx-segments")
|
2022-02-28 10:12:28 +00:00
|
|
|
target_compile_definitions(${ULP_APP_NAME} PRIVATE IS_ULP_COCPU)
|
2023-08-28 09:39:48 +00:00
|
|
|
target_compile_definitions(${ULP_APP_NAME} PRIVATE ULP_RISCV_REGISTER_OPS)
|
2020-04-17 19:34:56 +00:00
|
|
|
|
2023-02-27 09:03:42 +00: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 06:14:09 +00:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/vector.S"
|
2023-04-26 05:58:19 +00: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 06:14:09 +00:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_startup.c"
|
2023-03-20 15:08:38 +00:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_utils.c"
|
2023-05-22 12:48:15 +00:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_i2c.c"
|
|
|
|
"${IDF_PATH}/components/hal/uart_hal_iram.c"
|
|
|
|
"${IDF_PATH}/components/hal/uart_hal.c"
|
2023-05-30 15:42:19 +00:00
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_uart.c"
|
|
|
|
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_print.c")
|
2023-02-27 09:03:42 +00: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)
|
2023-04-26 05:58:19 +00:00
|
|
|
target_link_options(${ULP_APP_NAME}
|
|
|
|
PRIVATE SHELL:-T ${IDF_PATH}/components/soc/${IDF_TARGET}/ld/${IDF_TARGET}.peripherals.ld)
|
2023-02-27 09:03:42 +00:00
|
|
|
target_sources(${ULP_APP_NAME} PRIVATE ${ULP_S_SOURCES})
|
2023-04-26 05:58:19 +00: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 12:48:15 +00:00
|
|
|
target_compile_definitions(${ULP_APP_NAME} PRIVATE IS_ULP_COCPU)
|
2020-04-17 19:34:56 +00:00
|
|
|
|
2023-02-27 09:03:42 +00:00
|
|
|
else()
|
2020-04-17 19:34:56 +00: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 06:51:08 +00: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 12:00:20 +00:00
|
|
|
DEPENDS ${ulp_s_source}
|
2020-11-10 06:51:08 +00:00
|
|
|
VERBATIM)
|
2020-04-17 19:34:56 +00: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 07:40:01 +00:00
|
|
|
|
2022-08-28 11:55:49 +00: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 06:54:59 +00:00
|
|
|
|
2020-04-17 19:34:56 +00:00
|
|
|
endif()
|
2018-09-13 06:54:59 +00:00
|
|
|
|
2023-02-27 09:03:42 +00:00
|
|
|
if(ULP_COCPU_IS_LP_CORE)
|
|
|
|
set(ULP_BASE_ADDR "0x0")
|
|
|
|
else()
|
|
|
|
set(ULP_BASE_ADDR "0x50000000")
|
|
|
|
endif()
|
2022-08-28 12:11:46 +00:00
|
|
|
|
2018-09-13 06:54:59 +00:00
|
|
|
# Dump the list of global symbols in a convenient format
|
2020-11-10 06:51:08 +00:00
|
|
|
add_custom_command(OUTPUT ${ULP_APP_NAME}.sym
|
2022-08-28 12:11:46 +00:00
|
|
|
COMMAND ${CMAKE_NM} -f posix -g $<TARGET_FILE:${ULP_APP_NAME}> > ${ULP_APP_NAME}.sym
|
2020-11-10 06:51:08 +00:00
|
|
|
DEPENDS ${ULP_APP_NAME}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
2018-09-13 06:54:59 +00:00
|
|
|
|
|
|
|
# Dump the binary for inclusion into the project
|
2020-11-10 06:51:08 +00: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 12:11:46 +00:00
|
|
|
COMMAND ${ULP_MAP_GEN} -s ${ULP_APP_NAME}.sym -o ${ULP_APP_NAME} --base ${ULP_BASE_ADDR}
|
2020-11-10 06:51:08 +00:00
|
|
|
DEPENDS ${ULP_APP_NAME}.sym
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
2018-09-13 06:54:59 +00: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 09:32:24 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.ld
|
2018-09-13 06:54:59 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.h
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|