~berfr/stm32f4discovery

ref: 502314b1cfe40f0cc95285b16afa9eac41119768 stm32f4discovery/CMakeLists.txt -rw-r--r-- 1.5 KiB
502314b1 — berfr Add source, cmake config as well as readme file 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
cmake_minimum_required(VERSION 3.14)
set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
enable_language(ASM)

file(GLOB_RECURSE LIB_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} lib/*.c lib/*.s)

file(GLOB_RECURSE LIB_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} lib/*.h)
list(TRANSFORM LIB_HEADERS REPLACE "/[^/]+\.h$" "" OUTPUT_VARIABLE LIB_HEADERS_DIRS)
list(REMOVE_DUPLICATES LIB_HEADERS_DIRS)

file(GLOB SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.c)

include_directories(inc ${LIB_HEADERS_DIRS})

set(LINKER_SCRIPT_INPUT lib/stm32f4xx/Project/STM32F4xx_StdPeriph_Templates/TrueSTUDIO/STM32F40_41xxx/STM32F417IG_FLASH.ld)
set(LINKER_SCRIPT_OUTPUT stm32_flash.ld)
configure_file(${LINKER_SCRIPT_INPUT} ${LINKER_SCRIPT_OUTPUT} COPYONLY)

add_definitions(
    -DSTM32F40_41xxx
    -DHSE_VALUE=\(\(uint32_t\)8000000\)
    -DHSI_VALUE=\(\(uint32_t\)16000000\)
    -DUSE_STDPERIPH_DRIVER
)

set(
    CPU_FLAGS
    -mcpu=cortex-m4 -mlittle-endian -mthumb -mthumb-interwork
    -mfloat-abi=hard -mfpu=fpv4-sp-d16
    -g -O0
)

add_compile_options(
    ${CPU_FLAGS}
    -fdata-sections -ffunction-sections
)

add_link_options(
    ${CPU_FLAGS}
    --specs=nosys.specs
    -T${LINKER_SCRIPT_OUTPUT}
    -Wl,--gc-sections
)

add_executable(main.elf ${SOURCES} ${LIB_SOURCES})

add_custom_target(main.bin ALL arm-none-eabi-objcopy -O binary main.elf main.bin DEPENDS main.elf)
add_custom_target(size ALL arm-none-eabi-size -A main.elf DEPENDS main.elf)
add_custom_target(flash ALL st-flash --reset write main.bin 0x8000000 DEPENDS main.bin)