-
Notifications
You must be signed in to change notification settings - Fork 3
/
STM32F042K6_CMakeLists.txt
79 lines (68 loc) · 2.96 KB
/
STM32F042K6_CMakeLists.txt
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Brief: Builds firmware source generated by STM32CubeMX.
#
# Author: Windsor Schmidt. | https://github.com/windsorschmidt
# License: MIT License. Contributions welcome.
cmake_minimum_required (VERSION 3.6)
set(PROJ "firmware")
project (${PROJ})
# All relative to project root, as generated by STM32CubeMX.
set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/Src)
set(CMSIS_DIR ${CMAKE_SOURCE_DIR}/Drivers/CMSIS)
set(DEVICE_DIR ${CMAKE_SOURCE_DIR}/Drivers/CMSIS/Device/ST/STM32F0xx)
set(HAL_DIR ${CMAKE_SOURCE_DIR}/Drivers/STM32F0xx_HAL_Driver)
# Look here for header files.
include_directories(${CMAKE_SOURCE_DIR}/Inc)
include_directories(${CMSIS_DIR}/Include)
include_directories(${DEVICE_DIR}/Include)
include_directories(${HAL_DIR}/Inc)
# For diagnostic tools like rtags.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# As of late 2016 we can get the GNU ARM Embedded Toolchain from:
# https://developer.arm.com/open-source/gnu-toolchain/gnu-rm.
set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
# Some parts (e.g. Cortex-M4) have a FPU, but with F0 parts we're stuck with VFP.
set(CMAKE_C_FLAGS "-O0 -g -Wall -ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTM32F042x6 -mcpu=cortex-m0 -mthumb")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mno-thumb-interwork -mfpu=vfp -msoft-float")
set(CMAKE_EXE_LINKER_FLAGS "-T../STM32F042K6Tx_FLASH.ld -Wl,--gc-section")
# Some trickery to get CMake to deal with our assembler code.
set_property(SOURCE ${DEVICE_DIR}/Source/Templates/gcc/startup_stm32f042x6.s PROPERTY LANGUAGE C)
# The linker flag --gc-section keeps unused object code here from being linked.
add_executable(${PROJ}.elf
${SOURCE_DIR}/main.c
${SOURCE_DIR}/stm32f0xx_it.c
${DEVICE_DIR}/Source/Templates/system_stm32f0xx.c
${DEVICE_DIR}/Source/Templates/gcc/startup_stm32f042x6.s
${HAL_DIR}/Src/stm32f0xx_hal.c
${HAL_DIR}/Src/stm32f0xx_hal_cortex.c
${HAL_DIR}/Src/stm32f0xx_hal_dma.c
${HAL_DIR}/Src/stm32f0xx_hal_flash.c
${HAL_DIR}/Src/stm32f0xx_hal_flash_ex.c
${HAL_DIR}/Src/stm32f0xx_hal_gpio.c
${HAL_DIR}/Src/stm32f0xx_hal_i2c.c
${HAL_DIR}/Src/stm32f0xx_hal_i2c_ex.c
${HAL_DIR}/Src/stm32f0xx_hal_pwr.c
${HAL_DIR}/Src/stm32f0xx_hal_pwr_ex.c
${HAL_DIR}/Src/stm32f0xx_hal_rcc.c
${HAL_DIR}/Src/stm32f0xx_hal_rcc_ex.c
${HAL_DIR}/Src/stm32f0xx_hal_tim.c
${HAL_DIR}/Src/stm32f0xx_hal_tim_ex.c
)
# Generate assembly listing.
add_custom_command(
TARGET ${PROJ}.elf
COMMAND "arm-none-eabi-objdump"
ARGS "-S" "${PROJ}.elf" ">>" "${PROJ}.lst")
# Flash firmware to target.
add_custom_target(flash
openocd -f interface/stlink-v2-1.cfg -c "transport select hla_swd"
-f target/stm32f0x.cfg -c "init" -c "reset halt"
-c "flash write_image erase ${PROJ}.elf" -c "reset run" -c "shutdown"
DEPENDS ${PROJ}.elf
COMMENT "Flashing target hardware")
# Run OpenOCD as a GDB host.
add_custom_target(gdbhost
openocd -f interface/stlink-v2-1.cfg -c "transport select hla_swd"
-f target/stm32f0x.cfg -c "init" -c "reset halt"
DEPENDS ${PROJ}.elf
COMMENT "Running OpenOCD as a GDB host.")