开发环境:ubuntu22.04 + stm32CubeMX + gcc-arm-none-eabi
1,经过前面三篇博客,已经有了stm32工程,也有了编译环境,那么这篇博客的任务就是把stm32软件编译成一个固件。
2,安装 cmake 软件,$ sudo apt install cmake
4,检查软件 cmake / arm-none-eabi-gcc 是否准备就绪: $ cmake -version,$ arm-none-eabi-gcc --version,打印信息如下:
#=======
cmake version 3.22.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
#=======
arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10) 10.3.1 20210824 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5,根据前面博客 https://blog.csdn.net/cutelily2014/article/details/117415949 的信息,我已经有了一份工程示例,位于路径: “/home/lily/Documents/Project_ST/test0”。因为我打算在终端使用指令的办法编译 stm32 项目软件,所以在制作 stm32 工程示例的时候,选择的编译工具是 "Makefile"。
6,进入文件夹 "test0",可以看到一个小文件 "Makefile",它是 CubeMX 自动导出的编译配置文件,特别棒的功能。打开一个新的终端并输入指令:$ make,随后看到工程示例已经运行成功,在最后输出以下几行信息:
arm-none-eabi-size build/test0.elf
text data bss dec hex filename
3584 20 1572 5176 1438 build/test0.elf
arm-none-eabi-objcopy -O ihex build/test0.elf build/test0.hex
arm-none-eabi-objcopy -O binary -S build/test0.elf build/test0.bin
7,以上信息提示我们,工程代码已经编译通过,且生成了文件 test0.elf,另外给出两个固件:test0.hex 和 test0.bin
8,打开工程示例文件夹 "test0",看到它下面多出来一个编译文件 "build",打开这个新的编译文件,能看到编译过程中产生的许多中间文件,和我们最终想要的固件,后缀是 test0.hex 和 test0.bin