-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
58 lines (51 loc) · 2.24 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
cmake_minimum_required(VERSION 3.16)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain-ch32v30x.cmake)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(firmware)
set(TARGET_ELF ${PROJECT_NAME}.elf)
add_executable(${TARGET_ELF} src/main.c src/donut.c src/cdc_acm_template.c src/cxx_test.cpp src/Pin.hpp)
enable_language(C CXX ASM)
target_compile_features(${TARGET_ELF} PRIVATE cxx_std_17)
set(PKG_CHERRYUSB_DEVICE_CDC ON)
set(PKG_CHERRYUSB_DEVICE_CH32VXXX ON)
set(PKG_CHERRYUSB_RTTHREAD ON)
set(RT_USING_DFS ON)
set(RT_USING_DFS_DEVFS ON)
set(RT_USING_DFS_ROMFS ON)
set(RT_USING_PIN ON)
set(RT_USING_ADC ON)
set(RT_USING_DAC ON)
set(RT_USING_I2C ON)
set(RT_USING_I2C_BITOPS ON)
set(RT_USING_RTC ON)
set(RT_DFS_ROMFS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/rootfs)
add_subdirectory(wch)
target_link_libraries(${TARGET_ELF} m)
add_custom_target(generate_romfs
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/wch/rtthread/tools/mkromfs.py ${RT_DFS_ROMFS_PATH} ${CMAKE_CURRENT_BINARY_DIR}/romfs.c
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/romfs.c
COMMENT "Generate romfs file")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/romfs.c
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/wch/rtthread/tools/mkromfs.py ${RT_DFS_ROMFS_PATH} ${CMAKE_CURRENT_BINARY_DIR}/romfs.c)
add_custom_command(TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CROSS_OBJDUMP} "-CdSx" $<TARGET_FILE:${TARGET_ELF}> > $<TARGET_FILE:${TARGET_ELF}>.lst
COMMENT "Generating disassembler file")
add_custom_command(TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CROSS_OBJCOPY} "-Obinary" $<TARGET_FILE:${TARGET_ELF}> $<TARGET_FILE:${TARGET_ELF}>.bin
COMMENT "Generating bin file")
add_custom_command(TARGET ${TARGET_ELF} POST_BUILD
COMMAND ${CROSS_OBJCOPY} "-Oihex" $<TARGET_FILE:${TARGET_ELF}> $<TARGET_FILE:${TARGET_ELF}>.hex
COMMENT "Generating hex file")
add_custom_target(flash
COMMAND openocd -f ${CMAKE_CURRENT_SOURCE_DIR}/wch/wch-riscv.cfg
-c init
-c halt
-c "flash erase_sector wch_riscv 0 last"
-c "program ${TARGET_ELF} verify"
-c wlink_reset_resume
-c exit
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${tgt}
COMMENT "Running openocd ${tgt_name}"
USES_TERMINAL)