-
Notifications
You must be signed in to change notification settings - Fork 3
/
STM32L432KC_CMakeLists.txt
129 lines (118 loc) · 4.71 KB
/
STM32L432KC_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Brief: Builds firmware source code generated by STM32CubeMX (SW4STM32 toolchain)
# targeting the STM32L432KC microcontroller (as used in the NUCLEO-L432KC).
#
# 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/STM32L4xx)
set(HAL_DIR ${CMAKE_SOURCE_DIR}/Drivers/STM32L4xx_HAL_Driver)
set(RTOS_DIR ${CMAKE_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source)
set(USB_DIR ${CMAKE_SOURCE_DIR}/Middlewares/ST/STM32_USB_Device_Library/)
# 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)
include_directories(${RTOS_DIR}/include)
include_directories(${RTOS_DIR}/CMSIS_RTOS)
include_directories(${RTOS_DIR}/CMSIS_RTOS/include)
include_directories(${RTOS_DIR}/portable/GCC/ARM_CM4F)
include_directories(${USB_DIR}/Core/Inc)
include_directories(${USB_DIR}/Class/CDC/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")
set(CMAKE_C_FLAGS "-O0 -g -Wall -Werror -Wno-pointer-sign -ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTM32L432xx -mtune=cortex-m4 -mcpu=cortex-m4 -mthumb")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=fpv4-sp-d16 -mfloat-abi=hard")
set(CMAKE_EXE_LINKER_FLAGS "-T../STM32L432KCUx_FLASH.ld -Wl,--gc-section")
# Some trickery to get CMake to deal with our assembler code.
set_property(SOURCE ${CMAKE_SOURCE_DIR}/startup/startup_stm32l432xx.s PROPERTY LANGUAGE C)
# The linker flag --gc-section keeps unused object code here from being linked.
add_executable(${PROJ}.elf
${SOURCE_DIR}/adc.c
${SOURCE_DIR}/crc.c
${SOURCE_DIR}/dac.c
${SOURCE_DIR}/dma.c
${SOURCE_DIR}/freertos.c
${SOURCE_DIR}/gpio.c
${SOURCE_DIR}/i2c.c
${SOURCE_DIR}/iwdg.c
${SOURCE_DIR}/main.c
${SOURCE_DIR}/rng.c
${SOURCE_DIR}/sai.c
${SOURCE_DIR}/stm32l4xx_hal_msp.c
${SOURCE_DIR}/stm32l4xx_hal_timebase_TIM.c
${SOURCE_DIR}/stm32l4xx_it.c
${SOURCE_DIR}/system_stm32l4xx.c
${SOURCE_DIR}/usbd_cdc_if.c
${SOURCE_DIR}/usbd_conf.c
${SOURCE_DIR}/usbd_desc.c
${SOURCE_DIR}/usb_device.c
${SOURCE_DIR}/wwdg.c
${CMAKE_SOURCE_DIR}/startup/startup_stm32l432xx.s
${HAL_DIR}/Src/stm32l4xx_hal_adc.c
${HAL_DIR}/Src/stm32l4xx_hal_adc_ex.c
${HAL_DIR}/Src/stm32l4xx_hal.c
${HAL_DIR}/Src/stm32l4xx_hal_cortex.c
${HAL_DIR}/Src/stm32l4xx_hal_crc.c
${HAL_DIR}/Src/stm32l4xx_hal_crc_ex.c
${HAL_DIR}/Src/stm32l4xx_hal_dac.c
${HAL_DIR}/Src/stm32l4xx_hal_dac_ex.c
${HAL_DIR}/Src/stm32l4xx_hal_dma.c
${HAL_DIR}/Src/stm32l4xx_hal_flash.c
${HAL_DIR}/Src/stm32l4xx_hal_flash_ex.c
${HAL_DIR}/Src/stm32l4xx_hal_flash_ramfunc.c
${HAL_DIR}/Src/stm32l4xx_hal_gpio.c
${HAL_DIR}/Src/stm32l4xx_hal_i2c.c
${HAL_DIR}/Src/stm32l4xx_hal_i2c_ex.c
${HAL_DIR}/Src/stm32l4xx_hal_iwdg.c
${HAL_DIR}/Src/stm32l4xx_hal_pcd.c
${HAL_DIR}/Src/stm32l4xx_hal_pcd_ex.c
${HAL_DIR}/Src/stm32l4xx_hal_pwr.c
${HAL_DIR}/Src/stm32l4xx_hal_pwr_ex.c
${HAL_DIR}/Src/stm32l4xx_hal_rcc.c
${HAL_DIR}/Src/stm32l4xx_hal_rcc_ex.c
${HAL_DIR}/Src/stm32l4xx_hal_rng.c
${HAL_DIR}/Src/stm32l4xx_hal_sai.c
${HAL_DIR}/Src/stm32l4xx_hal_tim.c
${HAL_DIR}/Src/stm32l4xx_hal_tim_ex.c
${HAL_DIR}/Src/stm32l4xx_hal_wwdg.c
${HAL_DIR}/Src/stm32l4xx_ll_usb.c
${RTOS_DIR}/CMSIS_RTOS/cmsis_os.c
${RTOS_DIR}/list.c
${RTOS_DIR}/queue.c
${RTOS_DIR}/tasks.c
${RTOS_DIR}/timers.c
${RTOS_DIR}/portable/MemMang/heap_4.c
${RTOS_DIR}/portable/GCC/ARM_CM4F/port.c
${USB_DIR}/Class/CDC/Src/usbd_cdc.c
${USB_DIR}/Core/Src/usbd_core.c
${USB_DIR}/Core/Src/usbd_ctlreq.c
${USB_DIR}/Core/Src/usbd_ioreq.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/stm32l4x.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/stm32l4x.cfg -c "init" -c "reset halt"
DEPENDS ${PROJ}.elf
COMMENT "Running OpenOCD as a GDB host.")