cmake_minimum_required(VERSION 3.5) project(refOvenTest) enable_language(C ASM) set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_CROSSCOMPILING TRUE) #define th global variables for CMAKE to use for this project. set(LINKER startup/STM32F042K6Tx_FLASH.ld) set(STARTUP startup/startup_stm32f042x6.s) set(CPU_MCU "-mcpu=cortex-m0") set(CMAKE_C_COMPILER "/usr/bin/arm-none-eabi-gcc") #The reason that we use arm-none-eabi-gcc is that we will invoke c before hte assemly. #Check $<$:-x assembler-with-cpp ${ASM_FLAGS}> set(CMAKE_ASM_COMPILER "/usr/bin/arm-none-eabi-gcc") set(CMAKE_OBJCOPY "usr/bin/arm-none-eabi-objcopy") set(EXECUTABLE ${PROJECT_NAME}.out) set(C_SOURCES Src/main.c Src/stm32f0xx_it.c Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_exti.c Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_rcc.c Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_utils.c Src/system_stm32f0xx.c Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_gpio.c Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_pwr.c) set(C_HEADERS Inc/main.h Inc/stm32_assert.h Inc/stm32f0xx_it.h) set(ASM_SOURCES ${STARTUP}) add_executable(${EXECUTABLE} ${C_SOURCES} ${C_HEADERS} ${ASM_SOURCES}) #This is the whol tick to handle the assenbl compiling. #We can't use arm-non-eabi-as because it can onaly hande macros. #So this Varible makes that whne the asembly compiling is called the -x assembler-with-cpp flag is used target_compile_options(${EXECUTABLE} PRIVATE $<$:-x assembler-with-cpp ${ASM_FLAGS}> ) target_compile_options(${EXECUTABLE} PRIVATE ${CPU_MCU} -mthumb -Wall -fdata-sections -ffunction-sections $<$:-O -g -gdwarf-2>) target_compile_definitions(${EXECUTABLE} PRIVATE -DUSE_FULL_LL_DRIVER -DSTM32F042x6 -DHSE_VALUE=8000000 -DHSE_STARTUP_TIMEOUT=100 -DLSE_STARTUP_TIMEOUT=5000 -DLSE_VALUE=32768 -DHSI_VALUE=8000000 -DLSI_VALUE=40000 -DVDD_VALUE=3300 -DPREFETCH_ENABLE=1 -DINSTRUCTION_CACHE_ENABLE=0 -DDATA_CACHE_ENABLE=0) target_include_directories(${EXECUTABLE} PRIVATE Inc Drivers/STM32F0xx_HAL_Driver/Inc Drivers/CMSIS/Device/ST/STM32F0xx/Include Drivers/CMSIS/Include) target_link_options(${EXECUTABLE} PRIVATE ${CPU_MCU} -mthumb -specs=nano.specs -T${CMAKE_SOURCE_DIR}/${LINKER} -lc -lm -lnosys -Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,--gc-sections) add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND arm-none-eabi-size ${EXECUTABLE}) add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin)