Windows10搭建STM32 GCC开源开发环境

KeiluVision5 MDK快到期了吧(雾),心想算啥?网上再搜一搜相应的破解工具。但是始终不是长期解决方法。别以为用破解版没啥问题。但是某一天你收到来自Keil公司的到律师函,估计就噩耗了。估计会给你的公司或者学校带来不小的麻烦。使用开源才是至上哈。咱们来搭建一个不会受到律师函的免费开发环境。

必备工具

  • Git-2.33.0.2-64-bit.exe 最新的版本你可以到Git官网下载。因为简化的MINGW64。
  • xpack-arm-none-eabi-gcc-10.2.1 支持Cortex arm的gcc编译器。
  • make 因为Git中简化的MINGW64,不含有make工具。所以我们需要make工具解析Makefile文件,最终实现直接make一键编译。
  • stlink-utility 开源的ST-LINK下载与调试工具windows版本。如果你有翻墙工具,你可以直接登录https://github.com/stlink-org/stlink查看其具体实现。
  • xpack-openocd-0.11.0-1.zip 开源的GDB工具,支持很多调试工具(ST-LINK,JLINK,DAP-LINK等等)在线调试。
  • STM32F4-FreeRTOS 支持STM32F4XX的GCC源码。

1. 安装Git

首先根据安装教程Windows系统Git安装教程(详解Git安装过程),安装好Git。

在你的windows某个盘符下创建一个workspace的目录。点击右键 → \rightarrow Git Bash Here进入到MINGW64命令行。
请添加图片描述
请添加图片描述

2.xpack-arm-none-eabi-gcc-10.2.1/stlink-utility/make/xpack-openocd-0.11.0-1

xpack-arm-none-eabi-gcc-10.2.1 下载

打开https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/tag/v10.3.1-2.3/链接。下载适用于windows的版本。
请添加图片描述

stlink-utility 下载

打开https://github.com/stlink-org/stlink/releases/tag/v1.7.0链接。下载适用于windows的版本。
请添加图片描述

make 下载

打开https://cfhcable.dl.sourceforge.net/project/gnuwin32/make/3.81/make-3.81.exe链接。下载并安装。

请添加图片描述

xpack-openocd-0.11.0-1 下载

打开https://github.com/xpack-dev-tools/openocd-xpack/releases/tag/v0.11.0-3/链接。下载适用于windows的版本。
请添加图片描述
创建一个toolchain目录,把xpack-arm-none-eabi-gcc-10.2.1/stlink-utility/xpack-openocd-0.11.0-1拷贝到目录并解压。
请添加图片描述

3. STM32F4-FreeRTOS源码

在workspace目录中下载STM32F4-FreeRTOS源码。

克隆Gitee的STM32F4-FreeRTOS源码
#
Weston@HingeTech-SH109 MINGW64 /d/workspace
$ git clone https://gitee.com/msntec/stm32-f4-free-rtos.git
Cloning into 'stm32-f4-free-rtos'...
remote: Enumerating objects: 529, done.
remote: Counting objects: 100% (529/529), done.
remote: Compressing objects: 100% (265/265), done.
remote: Total 529 (delta 242), reused 519 (delta 237), pack-reused 0
Receiving objects: 100% (529/529), 1.61 MiB | 1.30 MiB/s, done.
Resolving deltas: 100% (242/242), done.
查看是否已经设置GCC STLINK OPENOCD工具环境变量
Weston@HingeTech-SH109 MINGW64 /d/workspace
$ cd stm32-f4-free-rtos/

Weston@HingeTech-SH109 MINGW64 /d/workspace/stm32-f4-free-rtos (master)
$ echo $PATH
/c/Users/Administrator/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/Administrator/bin:/c/ProgramData/Oracle/Java/javapath:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/cmd:/c/HighTec/toolchains/tricore/v4.9.3.0-infineon-1.0/bin:/c/Users/Administrator/AppData/Local/Microsoft/WindowsApps:/c/Infineon/LauncherService:/d/toolchain/msys64/mingw32/gcc-arm-none-eabi-7-2017-q4-major-win32/bin:/usr/bin/vendor_perl:/usr/bin/core_perl
source GCC STLINK OPENOCD工具环境变量配置
Weston@HingeTech-SH109 MINGW64 /d/workspace/stm32-f4-free-rtos (master)
$ source env.config
There is no folder ""
Setting default toolchain path "../toolchain"
再次确认GCC STLINK OPENOCD工具环境变量配置
Weston@HingeTech-SH109 MINGW64 /d/workspace/stm32-f4-free-rtos (master)
$ echo $PATH
/c/Users/Administrator/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/Administrator/bin:/c/ProgramData/Oracle/Java/javapath:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/cmd:/c/HighTec/toolchains/tricore/v4.9.3.0-infineon-1.0/bin:/c/Users/Administrator/AppData/Local/Microsoft/WindowsApps:/c/Infineon/LauncherService:/d/toolchain/msys64/mingw32/gcc-arm-none-eabi-7-2017-q4-major-win32/bin:/usr/bin/vendor_perl:/usr/bin/core_perl:/d/workspace/toolchain/stlink-1.7.0-x86_64-w64-mingw32/bin:/d/workspace/toolchain/xpack-arm-none-eabi-gcc-10.3.1-2.3/bin:/d/workspace/toolchain/xpack-openocd-0.11.0-3/bin
编译STM32F4XX FreeRTOS工程文件
Weston@HingeTech-SH109 MINGW64 /d/workspace/stm32-f4-free-rtos (master)
$make
mkdir build
arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DSTM32F4XX -DSTM32F40_41xxx -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -D__FPU_PRESENT=1 -D__FPU_USED=1 -DARM_MATH_CM4  -I CORE -I FreeRTOS/include -I FreeRTOS/portable/GCC/ARM_CM4F -I hardware -I Libraries/CMSIS/Device/ST/STM32F4xx/Include -I Libraries/CMSIS/Include -I Libraries/STM32F4xx_StdPeriph_Driver/inc -I config  -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/croutine.d" -MT"build/croutine.d" -Wa,-a,-ad,-alms=build/croutine.lst FreeRTOS/croutine.c -o build/croutine.o
......
......
......
arm-none-eabi-gcc build/croutine.o build/event_groups.o build/list.o build/port.o build/heap_4.o build/queue.o build/tasks.o build/timers.o build/stm32f4xx_it.o build/system_stm32f4xx.o build/misc.o build/stm32f4xx_adc.o build/stm32f4xx_can.o build/stm32f4xx_cec.o build/stm32f4xx_crc.o build/stm32f4xx_dac.o build/stm32f4xx_dbgmcu.o build/stm32f4xx_dcmi.o build/stm32f4xx_dma.o build/stm32f4xx_dma2d.o build/stm32f4xx_dsi.o build/stm32f4xx_exti.o build/stm32f4xx_flash.o build/stm32f4xx_flash_ramfunc.o build/stm32f4xx_fmpi2c.o build/stm32f4xx_fsmc.o build/stm32f4xx_gpio.o build/stm32f4xx_i2c.o build/stm32f4xx_iwdg.o build/stm32f4xx_lptim.o build/stm32f4xx_ltdc.o build/stm32f4xx_pwr.o build/stm32f4xx_qspi.o build/stm32f4xx_rcc.o build/stm32f4xx_rng.o build/stm32f4xx_rtc.o build/stm32f4xx_sai.o build/stm32f4xx_sdio.o build/stm32f4xx_spdifrx.o build/stm32f4xx_spi.o build/stm32f4xx_syscfg.o build/stm32f4xx_tim.o build/stm32f4xx_usart.o build/stm32f4xx_wwdg.o build/syscalls.o build/main.o build/startup_stm32f4xx.o -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -specs=nano.specs -TUtilities/stm32_flash.ld  -lc -lm -lnosys  -Wl,-Map=build/FreeRTOS.map,--cref -Wl,--gc-sections -o build/FreeRTOS.elf
arm-none-eabi-size build/FreeRTOS.elf
   text    data     bss     dec     hex filename
  12312    1868   79000   93180   16bfc build/FreeRTOS.elf
mkdir binary
cp build/FreeRTOS.elf binary/FreeRTOS.elf
arm-none-eabi-objcopy -O ihex build/FreeRTOS.elf binary/FreeRTOS.hex
arm-none-eabi-objcopy -O binary -S build/FreeRTOS.elf binary/FreeRTOS.bin
st-flash flash擦除
Weston@HingeTech-SH109 MINGW64 /d/workspace/stm32-f4-free-rtos (master)
$ make erase
st-flash erase
st-flash 1.7.0
2022-01-06T17:10:17 INFO common.c: F4xx: 192 KiB SRAM, 1024 KiB flash in at least 16 KiB pages.
Mass erasing.....
st-flash firmware烧写后复位
Weston@HingeTech-SH109 MINGW64 /d/workspace/stm32-f4-free-rtos (master)
$ make flash
st-flash --connect-under-reset write binary/FreeRTOS.bin 0x08000000
st-flash 1.7.0
2022-01-06T17:11:19 WARN common.c: NRST is not connected
2022-01-06T17:11:19 INFO common.c: F4xx: 192 KiB SRAM, 1024 KiB flash in at least 16 KiB pages.
file binary/FreeRTOS.bin md5 checksum: b03f8cbd7b4a854e473f33359dff2a, stlink checksum: 0x0013d60f
2022-01-06T17:11:19 INFO common.c: Attempting to write 14188 (0x376c) bytes to stm32 address: 134217728 (0x8000000)
EraseFlash - Sector:0x0 Size:0x4000 2022-01-06T17:11:19 INFO common.c: Flash page at addr: 0x08000000 erased
2022-01-06T17:11:19 INFO common.c: Finished erasing 1 pages of 16384 (0x4000) bytes
2022-01-06T17:11:19 INFO common.c: Starting Flash write for F2/F4/F7/L4
2022-01-06T17:11:19 INFO flash_loader.c: Successfully loaded flash loader in sram
2022-01-06T17:11:19 INFO flash_loader.c: Clear DFSR
2022-01-06T17:11:19 INFO common.c: enabling 32-bit flash writes
2022-01-06T17:11:19 INFO common.c: Starting verification of write complete
2022-01-06T17:11:20 INFO common.c: Flash written and verified! jolly good!
st-util 在线调试
Weston@HingeTech-SH109 MINGW64 /d/workspace/stm32-f4-free-rtos (master)
$ st-util.exe
st-util
2022-01-06T17:19:20 WARN common.c: NRST is not connected
2022-01-06T17:19:20 INFO common.c: F4xx: 192 KiB SRAM, 1024 KiB flash in at least 16 KiB pages.
2022-01-06T17:19:20 INFO gdb-server.c: Listening at *:4242...
2022-01-06T17:20:31 WARN common.c: NRST is not connected
2022-01-06T17:20:31 INFO common.c: F4xx: 192 KiB SRAM, 1024 KiB flash in at least 16 KiB pages.
2022-01-06T17:20:31 INFO gdb-server.c: Found 6 hw breakpoint registers
2022-01-06T17:20:31 INFO gdb-server.c: GDB connected.
2022-01-06T17:21:05 ERROR gdb-server.c: cannot recv: -2
2022-01-06T17:21:05 INFO gdb-server.c: Listening at *:4242...
2022-01-06T17:21:14 WARN common.c: NRST is not connected
2022-01-06T17:21:14 INFO common.c: F4xx: 192 KiB SRAM, 1024 KiB flash in at least 16 KiB pages.
2022-01-06T17:21:14 INFO gdb-server.c: Found 6 hw breakpoint registers
2022-01-06T17:21:14 INFO gdb-server.c: GDB connected.
arm-none-eabi-gdb.exe 加载调试ELF文件, target extended localhost:4242命令远程登录调试
Weston@HingeTech-SH109 MINGW64 /d/workspace/stm32-f4-free-rtos (master)
$ arm-none-eabi-gdb.exe binary/FreeRTOS.elf
GNU gdb (xPack GNU Arm Embedded GCC x86_64) 10.2.90.20210621-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from binary/FreeRTOS.elf...
(gdb) target extended localhost:4242
Remote debugging using localhost:4242
Reset_Handler () at hardware/startup_stm32f4xx.s:94
94        movs  r3, #0
(gdb) b main
Breakpoint 1 at 0x8002408: file main.c, line 29.
Note: automatically using hardware breakpoints for read-only addresses.
(gdb) l
89        bcc  CopyDataInit
90        ldr  r2, =_sbss
91        b  LoopFillZerobss
92      /* Zero fill the bss segment. */
93      FillZerobss:
94        movs  r3, #0
95        str  r3, [r2], #4
96
97      LoopFillZerobss:
98        ldr  r3, = _ebss
(gdb) c
Continuing.

Breakpoint 1, main () at main.c:29
29      int main(void) {
(gdb) l
24              }
25      }
26
27
28
29      int main(void) {
30        GPIO_InitTypeDef GPIO_InitStruct;
31
32        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
33
(gdb)

GDB的命令大家可以看宋宝华的Linux gdb调试器用法全面解析和GDB GUI 工具Eclipse使用方法在如何结合Eclipse+OpenOCD+arm-none-eabi-gdb实现可视化在线调试ARM Cortex M7内核?文章中介绍。

由于大部分资源是gitub资源。国内访问github需要翻墙才能访问。大家可以直接加我的公众号“背包旅行码农”,输入关键字“STM32 GCC”获取。
请添加图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Ubuntu STM32 GCC开发环境是一种在Ubuntu操作系统上使用GCC编译器进行STM32芯片开发环境。它提供了一系列工具和库,使得开发者可以方便地进行STM32芯片的编程和调试。其中包括STM32CubeMX、OpenOCD、GDB等工具,以及STM32 HAL库和CMSIS库等开发库。使用这个开发环境开发者可以快速地开发出高质量的STM32应用程序。 ### 回答2: Ubuntu STM32 GCC开发环境是一个非常强大的平台,允许开发人员在Ubuntu下使用GCC编译器来开发STM32芯片的外围设备的软件应用程序。GNU Compiler Collection(GCC)是一种广泛使用的编译器,可用于许多编程语言,包括C、C++和Fortran等。开发者可以在Ubuntu中安装GCC编译器,并通过使用GNU Arm Embedded Toolchain to、GNU Make、OpenOCD JLink和STLink v2软件包来编写和调试STM32外围设备的软件应用程序。 安装GCC编译器首先要在Ubuntu中安装GCC编译器。可以使用命令sudo apt-get install build-essential来安装。接着可以下载和安装GNU Arm Embedded Toolchain,这是一个特定于ARM架构的工具链,可用于编译和链接STM32外围设备的软件应用程序。安装完成后,可以通过命令arm-none-eabi-gcc和arm-none-eabi-g++来访问GCC编译器。 接着要安装GNU Make,它是一个强大的工具,可用于自动化构建和测试STM32外围设备的软件应用程序。可通过命令sudo apt-get install make来安装。 安装OpenOCD JLink和STLink v2软件包,它们是用于在Ubuntu中连接和调试STM32外围设备的软件包。安装完成后,使用命令openocd启动OpenOCD守护程序,使其与STM32芯片连接。可以通过gdb调试器来调试STM32外围设备的软件应用程序。 这种环境下的STM32外围设备的软件应用程序可以在Ubuntu中编写和调试,然后重新编译为在目标环境中运行的二进制文件,并将其上传到STM32芯片上运行。这使得编程人员可以快速、灵活地创建、测试和调试STM32外围设备的软件应用程序,从而提高了开发速度和质量。 ### 回答3: Ubuntu是一个开源的操作系统,它非常适合程序员和开发人员使用。STM32是一种基于ARM架构的微控制器,常用于嵌入式系统中。因此,在Ubuntu系统下搭建STM32 GCC开发环境非常有必要。 首先,需要安装ARM的交叉编译器。在Ubuntu下,可以通过以下命令进行安装: sudo apt-get install gcc-arm-none-eabi 该命令可以自动安装ARM的交叉编译器,然后就可以在终端窗口中使用编译器了。 接着,需要安装STM32的开发工具。STMicroelectronics提供了一套非常好的开发工具,称为STM32CubeIDE。可以通过以下命令进行下载和安装: wget https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-ides/stm32-cubide.html#getsoftware-scroll 这个命令将下载STM32CubeIDE,并将其安装在你的Ubuntu系统中。安装完成后,就可以打开STM32CubeIDE,并开始在Ubuntu系统上开发STM32应用程序了。 在使用STM32CubeIDE时,需要选择合适的开发板,并按照开发板的手册进行配置和程序编写。编写完成后,可以利用ARM的交叉编译器将代码编译成适合STM32的二进制文件,并将其下载到开发板上进行测试和调试。 总的来说,Ubuntu STM32 GCC开发环境搭建比较简单,只需要安装ARM的交叉编译器和STM32的开发工具即可。安装完成后,开发人员可以使用Ubuntu系统来进行STM32应用程序的编写、编译、调试和测试工作,从而提高开发效率,降低开发成本。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值