-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project(HELLO C ASM) | ||
|
||
|
||
# 启用命令输出,Vim/NeoVim 安装 LSP 时, LSP 可以正常工作:w | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) | ||
|
||
# 源文件 | ||
file(GLOB_RECURSE C_SOURCES | ||
Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/*.c | ||
Libraries/CMSIS/CM3/CoreSupport/*.c | ||
User/*.c | ||
Libraries/STM32F10x_StdPeriph_Driver/src/*.c | ||
EVAL/*.c | ||
System/*.c | ||
) | ||
|
||
|
||
# 汇编源文件 | ||
file(GLOB ASM_SOURCES | ||
Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_md.s | ||
) | ||
|
||
|
||
|
||
# 添加头文件目录 | ||
include_directories( | ||
Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x | ||
User | ||
Libraries/CMSIS/CM3/CoreSupport | ||
Libraries/STM32F10x_StdPeriph_Driver/inc | ||
EVAL | ||
System | ||
) | ||
|
||
|
||
|
||
add_executable(${PROJECT_NAME}) | ||
|
||
|
||
target_link_directories( | ||
${PROJECT_NAME} PRIVATE | ||
) | ||
|
||
|
||
target_compile_definitions( | ||
${PROJECT_NAME} PRIVATE | ||
STM32F10X_MD | ||
USE_STDPERIPH_DRIVER | ||
|
||
) | ||
|
||
target_compile_options( | ||
${PROJECT_NAME} PRIVATE | ||
"$<$<CONFIG:Debug>:-Og>" | ||
"$<$<CONFIG:Debug>:-g2>" | ||
"$<$<NOT:$<CONFIG:Debug>>:-Os>" | ||
"$<$<NOT:$<CONFIG:Debug>>:-g0>" | ||
-mcpu=cortex-m3 | ||
) | ||
|
||
target_link_options( | ||
${PROJECT_NAME} PRIVATE | ||
-mcpu=cortex-m3 | ||
-T | ||
${PROJECT_SOURCE_DIR}/Libraries/LinkScript/stm32f103c8t6.ld | ||
) | ||
target_sources( | ||
${PROJECT_NAME} PRIVATE | ||
${C_SOURCES} | ||
${ASM_SOURCES} | ||
) | ||
|
||
|
||
add_custom_command( | ||
TARGET ${PROJECT_NAME} POST_BUILD | ||
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${PROJECT_NAME}> | ||
) | ||
|
||
|
||
add_custom_command( | ||
TARGET ${PROJECT_NAME} POST_BUILD | ||
COMMAND ${CMAKE_OBJCOPY} -O ihex | ||
$<TARGET_FILE:${PROJECT_NAME}> ${PROJECT_NAME}.hex | ||
) | ||
|
||
add_custom_command( | ||
TARGET ${PROJECT_NAME} POST_BUILD | ||
COMMAND ${CMAKE_OBJCOPY} -O binary | ||
$<TARGET_FILE:${PROJECT_NAME}> ${PROJECT_NAME}.bin | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
set(WINDOWS_ST_CLT_PATH "C:/ST/STM32CubeCLT/STM32CubeCLT/GNU-tools-for-STM32/bin/") | ||
set(MAC_ST_CLT_PATH "/opt/ST/STM32CubeCLT/GNU-tools-for-STM32/bin/") | ||
if(EXISTS "${WINDOWS_ST_CLT_PATH}") | ||
set(TOOLCHAIN_DIRECTORIES ${WINDOWS_ST_CLT_PATH}) | ||
elseif(EXISTS "${MAC_ST_CLT_PATH}") | ||
set(TOOLCHAIN_DIRECTORIES ${MAC_ST_CLT_PATH}) | ||
else() | ||
# Try to find an STM32CubeIDE installation to use for the toolchain. | ||
file(GLOB TOOLCHAIN_DIRECTORIES | ||
"C:/ST/STM32CubeIDE_*/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.*/tools/bin/" | ||
"/opt/st/stm32cubeide_*/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.*/tools/bin/" | ||
"/Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.*/tools/bin/" | ||
) | ||
endif() | ||
list(LENGTH TOOLCHAIN_DIRECTORIES TOOLCHAIN_DIRECTORIES_COUNT) | ||
|
||
|
||
if(WIN32) | ||
set(TOOLCHAIN_SUFFIX ".exe") | ||
endif() | ||
|
||
set(CMAKE_SYSTEM_NAME Generic) | ||
set(CMAKE_SYSTEM_PROCESSOR arm) | ||
|
||
set(TOOLCHAIN_PREFIX "arm-none-eabi-") | ||
if(DEFINED TOOLCHAIN_DIRECTORY) | ||
set(TOOLCHAIN_PREFIX "${TOOLCHAIN_DIRECTORY}/${TOOLCHAIN_PREFIX}") | ||
endif() | ||
set(FLAGS "-fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections") | ||
set(ASM_FLAGS "-x assembler-with-cpp") | ||
set(CPP_FLAGS "-fno-rtti -fno-exceptions -fno-threadsafe-statics") | ||
|
||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc${TOOLCHAIN_SUFFIX} ${FLAGS}) | ||
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER} ${ASM_FLAGS}) | ||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++${TOOLCHAIN_SUFFIX} ${FLAGS} ${CPP_FLAGS}) | ||
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy${TOOLCHAIN_SUFFIX}) | ||
set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size${TOOLCHAIN_SUFFIX}) | ||
|
||
set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") | ||
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") | ||
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") | ||
|
||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# 环境配置 | ||
|
||
## ## Linux | ||
|
||
### OpenOCD | ||
|
||
这是一款开源的调试软件工具,可以用于芯片烧录和调试 | ||
|
||
```Bash | ||
# ArchLinux | ||
sudo pacman -S openocd | ||
# Ubuntu/Debian | ||
sudo apt-get intstall openocd | ||
|
||
``` | ||
|
||
其他发行版可以自行搜素是否官方库纳入 `OpenOCD` | ||
|
||
[**SourceForge**](https://sourceforge.net/p/openocd/code/ci/master/tree/) | ||
|
||
其中 Github 提供 Mingw32 版本 [Github](https://github.com/openocd-org/openocd) | ||
|
||
非官方 [Github](https://github.com/xpack-dev-tools/openocd-xpack/releases) | ||
|
||
### arm-none-eabi | ||
|
||
[GNU Arm Embedded Toolchain](https://developer.arm.com/downloads/-/gnu-rm) | ||
|
||
为 Arm 设备的 GNU 嵌入式工具链 | ||
|
||
```bash | ||
# ArchLinux | ||
sudo pacman -S arm-none-eabi-gcc arm-none-eabi-gdb | ||
# Ubuntu/Debian | ||
sudo apt-get install gcc-arm-none-eabi | ||
``` | ||
|
||
可移步至[官方下载](https://developer.arm.com/downloads/-/gnu-rm) | ||
|
||
|
||
|
||
### CMake & Make | ||
|
||
- CMake 是开源的构建系统生成工具 | ||
|
||
- Make 一款构建工具, 通过 `Makefile` 文件执行构建 | ||
|
||
正常系统都会存在 `make` , `cmake` 需要安装 | ||
|
||
```bash | ||
sudo pacman -S make cmake # 根据自己系统包管理器, 这两一般都可以通过包管理器直接安装 | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
## Window | ||
|
||
|
||
|
||
### OpenOCD | ||
|
||
可以通过 `MSYS2` 安装, 但是会比较麻烦 | ||
|
||
官方提供 [Getting OpenOCD](https://openocd.org/pages/getting-openocd.html) | ||
|
||
这里以 [openocd-xpack](https://github.com/xpack-dev-tools/openocd-xpack/releases) 为例, 进入页面下载如下安装包 | ||
|
||
 | ||
|
||
|
||
|
||
自己选择解压到的目录, 解压 | ||
|
||
我解压在 C 盘根目录, 打开解压文件夹, 内容如下 | ||
|
||
 | ||
|
||
按 `Win` 键输入 `环境` | ||
|
||
 | ||
|
||
打开面板, 点击环境变量 | ||
|
||
 | ||
|
||
双击 `Path` , 一般选择上面那个。上面是用户变量, 下面是系统变量, 修改用户变量只会对用户生效, 修改系统变量对所有用户生效 | ||
|
||
 | ||
|
||
依次 `新建` -> `浏览` 选择解压 openocd-xpack 下的 `bin` 目录 | ||
|
||
 | ||
|
||
确定保存 | ||
|
||
`Win` + `R` 打开命令提示符输入 `openocd --version` | ||
|
||
有如下输出即可 | ||
|
||
 | ||
|
||
|
||
|
||
### arm-none-eabi | ||
|
||
来[这里](https://developer.arm.com/downloads/-/gnu-rm)下载, 根据 `OpenOCD` 安装方式就好,也是配置环境变量 | ||
|
||
|
||
|
||
### CMake 和 Make | ||
|
||
CMake 直接去官网下载即可 , [链接在此](https://cmake.org/) | ||
|
||
Make 在 Windows 上有 MingW提供, 这个是在电脑配置 `C/C++`环境时, 如果你用的不是 VSCode 或者 CLion, 那么请移步配置 `C/C++` 环境 | ||
|
||
Make 的命令默认为 `mingw32-make` 注意!!!! | ||
|
||
|
||
|
||
|
||
|
||
现在基本环境就OK了 |