project(updater-ram-code) set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_CROSSCOMPILING 1) cmake_minimum_required(VERSION 3.0) set(CMAKE_TOOLCHAIN_FILE "arm-none-eabi-gcc.cmake") find_package(Python COMPONENTS Interpreter) if (Python_FOUND) message("Python interpreter used for converting updater RAM code: ${Python_EXECUTABLE}") else (Python_FOUND) message(FATAL_ERROR "${BoldRed}Python interpreter not found! Please install python 3.${ColorReset}") endif (Python_FOUND) set(ELFFILE ${PROJECT_NAME}.elf) set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/ram-link.ld) set(ELFFILE "${PROJECT_NAME}.elf") aux_source_directory("." SRCS) aux_source_directory("fatfs" FATFS_SRCS) aux_source_directory("3rd-party/sha256" SHA256_SRCS) aux_source_directory("fatfs/shimatta_sdio_driver" SDIO_SRCS) set(STM_PERIPH_SRCS "../../stm-periph/backup-ram.c" "../../stm-periph/rcc-manager.c" "../../stm-periph/crc-unit.c") set(SAFETY_MEMORY_SRCS "../../safety/safety-memory.c") add_executable(${ELFFILE} ${SRCS} ${FATFS_SRCS} ${SDIO_SRCS} ${STM_PERIPH_SRCS} ${SAFETY_MEMORY_SRCS} ${SHA256_SRCS}) target_include_directories(${ELFFILE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ../../include ${CMAKE_CURRENT_SOURCE_DIR}/3rd-party) target_compile_options(${ELFFILE} PRIVATE -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) target_compile_options(${ELFFILE} PRIVATE -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -Wimplicit-fallthrough=3 -Wsign-compare -Os -g3) target_compile_definitions(${ELFFILE} PRIVATE -DGIT_VER=${GIT_DESCRIBE} -DHSE_VALUE=8000000UL -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4 -DSAFETY_MEMORY_STRIPOUT_DUMP) target_link_options(${ELFFILE} PRIVATE -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 --disable-newlib-supplied-syscalls -nostartfiles -T${LINKER_SCRIPT} -Wl,--print-memory-usage) set(GEN_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/include/generated") set(GEN_HEADER_FILE "${GEN_HEADER_PATH}/${PROJECT_NAME}.bin.h") target_include_directories(${ELFFILE} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/") set(GEN_HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/include/generated/${PROJECT_NAME}.bin.h") add_custom_target(updater-ram-code-header-blob DEPENDS ${GEN_HEADER_FILE}) add_custom_command(DEPENDS ${ELFFILE} OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin" COMMAND ${CMAKE_OBJCOPY} -O binary ${ELFFILE} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin" ) add_custom_command(DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin" OUTPUT ${GEN_HEADER_FILE} COMMAND mkdir -p ${GEN_HEADER_PATH} && ${Python_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/bin2carray.py" "${GEN_HEADER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin" )