-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
141 lines (117 loc) · 6.03 KB
/
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
130
131
132
133
134
135
136
137
138
139
140
141
##############################################################################
# CMAKE CONFIGURATION
##############################################################################
cmake_minimum_required(VERSION 3.15)
project(ble_app_uart_central C ASM)
# set build type = Debug mode
set(CMAKE_BUILD_TYPE Debug)
message("\n" "=========================================")
message("Project: ${PROJECT_NAME} ")
message("=========================================")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)
# You must set these variables with your own path
set(NRF_TARGET "nrf52" ) # nrf51 or nrf52
set(ARM_NONE_EABI_TOOLCHAIN_PATH "/opt/SEGGER/gcc-arm-none-eabi-9-2019-q4-major" ) # Path to root folder
set(NRF5_SDK_PATH "/opt/SEGGER/nRF5SDK" ) # Path to root folder
set(NRFJPROG "/opt/SEGGER/Toolchain/nrfjprog/nrfjprog" ) # Path to .bin file
#set(MERGE_HEX "/opt/SEGGER/Toolchain/mergehex/mergehex" )
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/nRF5x.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/arm-gcc-toolchain.cmake")
##############################################################################
# nRF5x standard setup
##############################################################################
nRF5x_setup()
# nRF5x_addAppScheduler()
nRF5x_addAppFIFO()
nRF5x_addAppTimer()
nRF5x_addAppUART()
nRF5x_addAppButton()
nRF5x_addBSP(TRUE FALSE FALSE) # (btn atn_btn nfc)
nRF5x_addBLEGATT()
#nRF5x_addBLEService(ble_bas) #ble_ancs_c;ble_ans_c;ble_bas;ble_bas_c;ble_bps;ble_cscs...
nRF5x_addBLEService(ble_nus_c)
nRF5x_addBLEService(ble_lbs_c)
# nRF5x_addNFC()
nRF5x_addAppFDS()
nRF5x_addBLEPeerManager()
nRF5x_addBLEAdvertising()
# nRF5x_addAppFIFO()
add_definitions(-DCONFIG_GPIO_AS_PINRESET)
##############################################################################
# INCLUDE CONFIG FILE: sdk_config.h
##############################################################################
include_directories("${CMAKE_SOURCE_DIR}/config")
##############################################################################
# ERASE BOARD AND FLASH SOFTDEVICE
##############################################################################
# adds target for erasing and flashing the board with a softdevice
# add_custom_target(FLASH_ERASE ALL
# COMMAND ${NRFJPROG} --family ${NRF_TARGET} --eraseall
# COMMENT "erasing flashing"
# )
add_custom_target(FLASH_SOFTDEVICE ALL
COMMAND ${NRFJPROG} --program ${SOFTDEVICE_PATH} -f ${NRF_TARGET} --sectorerase --log
COMMAND sleep 0.5s
COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET}
COMMENT "flashing SoftDevice"
)
##############################################################################
# NEW SDK LIBRARIES
##############################################################################
include_directories(
"${NRF5_SDK_PATH}/components/libraries/sensorsim"
"${NRF5_SDK_PATH}/components/ble/ble_db_discovery"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_gq"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_scan"
"${NRF5_SDK_PATH}/components/libraries/serial"
"${NRF5_SDK_PATH}/integration/nrfx/legacy"
"${NRF5_SDK_PATH}/modules/nrfx/drivers"
"${CMAKE_CURRENT_LIST_DIR}/include"
"${NRF5_SDK_PATH}/components/libraries/scheduler"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/sensorsim/sensorsim.c"
"${NRF5_SDK_PATH}/components/ble/ble_db_discovery/ble_db_discovery.c"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_gq/nrf_ble_gq.c"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_scan/nrf_ble_scan.c"
"${NRF5_SDK_PATH}/components/libraries/serial/nrf_serial.c"
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_timer.c"
"${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_clock.c"
"${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_power.c"
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_power.c"
"${CMAKE_CURRENT_LIST_DIR}/include/RFIDRW_E_TTL.c"
"${NRF5_SDK_PATH}/components/libraries/scheduler/app_scheduler.c"
)
##############################################################################
# SOURCE CODE
##############################################################################
list(APPEND SOURCE_FILES "src/main.c")
##############################################################################
# EXECUTABLES
##############################################################################
nRF5x_addExecutable(${PROJECT_NAME} "${SOURCE_FILES}")
##############################################################################
# .hex, .map and .bin file
##############################################################################
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_SIZE_UTIL} ${PROJECT_NAME}.out
COMMAND ${CMAKE_OBJCOPY} -O binary ${PROJECT_NAME}.out "${PROJECT_NAME}.bin"
COMMAND ${CMAKE_OBJCOPY} -O ihex ${PROJECT_NAME}.out "${PROJECT_NAME}.hex"
COMMENT "post build steps for ${PROJECT_NAME}")
##############################################################################
# FLASHING PROGRAM TO BOARD
##############################################################################
add_custom_target("FLASH_${PROJECT_NAME}" ALL
DEPENDS ${PROJECT_NAME}
COMMAND ${NRFJPROG} --program ${PROJECT_NAME}.hex -f ${NRF_TARGET} --sectorerase
COMMAND sleep 0.5s
COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET}
COMMENT "flashing ${PROJECT_NAME}.hex"
)
message("=========================================")
message("Project: ${PROJECT_NAME} COMPILED WITH CMAKE " ${CMAKE_VERSION})
message("=========================================")