WINDOWS系统下使用GCC+MAKE开发MCU

WINDOWS系统下使用GCC+MAKE开发MCU

嵌入式单片机开发时,在WINDOWS下使用GCC编译器开发往往有很大的的局限性。因为WINDOWS下并没有MAKE,造成我们所写的MAKEFILE没法被识别,想要在WINDOWS下使用MAKEFILE又必须去装MAKE的操作环境。但是随着开源代码的不断普及,目前已经有了在WINDOWS系统下的GUN make工具,这让我们开发难度大大降低,部分厂家如果对于编译器的付费比较烦恼的话可以考虑一下GCC。

编译过程

这里简单介绍一下GCC+MAKE的编译过程,因为我也不太清楚,哈哈,见笑。首先需要我们搭建好开发环境,MAKEFILE文件(一种类似于脚本文件的辅助编译文件,本来是用于linux下编译开发软件的,但是强大的开源团队已经将这个MAKEFILE的方法拿到了WINDOWS上,用来开发不同平台的应用,例如GNU MCU Eclipse)构建了我们工程结构,GCC则对我们的代码进行编译,和我们使用的ARMCC编译器是不同的编译器。简单地说我们在开发MCU的程序时候,GUN MAKE负责识别工程中的MAKEFILE文件,进而调用编译器来编译程序。

GUN MAKE安装

下载:GUN MAKE在Github上有开源代码,我们使用的话直接下载就可以了,下载完后直接将文件解压,得到“GNU MCU Eclipse”文件,我们将文件直接复制到C:\Program Files (x86)文件夹下,然后设置好环境变量,我这里将用户和管理员的环境改变量Path都添加了一个C:\Program Files (x86)\GNU MCU Eclipse\Build Tools\2.12-20190422-1053\bin\的值。

然后调出命令行测试是否设置好了环境变量:

>>C:\Users\xxx>make --version
>>GNU Make 4.2.1
>>Built for x86_64-w64-mingw32<br/>
>>Copyright (C) 1988-2016 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.

如果命令正常回复的话则代表已经设置好了环境变量。这里说一下,虽然这个软件只是个eclipse的插件,但是可以用来当作make工具,不管是否安装eclipse。

GNU Tools ARM Embedded安装

下载:接下来我们安装GCC编译器,GNU Tools ARM Embedded不止包含编译器功能,同时包含GDB debugger功能。下载完毕后进行安装,然后设置环境变量(在软件安装之后也有提示是否设置全局环境变量),我这里也同样给Path添加了一个C:\Program Files (x86)\GNU Tools ARM Embedded\8 2019-q3-update\bin\的值。

然后我们调用命令行进行测试是否设置好了环境变量:

arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 8-2019-q3-update) 8.3.1 20190703 (release) [gcc-8-branch revision 273027]
Copyright (C) 2018 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.

到这里两个工具已经安装好,接下来就可以使用MAKE+GCC来开发我们的代码。

实例

我们以Nordic的nRF5_SDK_15.3.0_59ac345\examples\peripheral\blinky例程来做下示例:

1.首先按照官方的说明将代码包中的与MAKE有关的文件修改一下,即将nRF5_SDK_15.3.0_59ac345\components\toolchain\gcc\Makefile.windows文件改下编译器的版本号,因为例程中的MAKEFILE会用到,修改为刚才测试打印的版本号:

GNU_INSTALL_ROOT := C:/Program Files (x86)/GNU Tools ARM Embedded/8 2019-q3-update/bin/
GNU_VERSION := 8.3.1
GNU_PREFIX := arm-none-eabi

2.打开例程文件夹,调出终端shift+右键,输入make即可开始编译。

PS F:\nordic\nordic52832\nRF5_SDK_15.3.0_59ac345\examples\peripheral\blinky\pca10040\blank\armgcc> make
mkdir _build
cd _build && mkdir nrf52832_xxaa
Assembling file: gcc_startup_nrf52.S
Compiling file: nrf_log_frontend.c
Compiling file: nrf_log_str_formatter.c
Compiling file: boards.c
Compiling file: app_error.c
Compiling file: app_error_handler_gcc.c
Compiling file: app_error_weak.c
Compiling file: app_util_platform.c
Compiling file: nrf_assert.c
Compiling file: nrf_atomic.c
Compiling file: nrf_balloc.c
Compiling file: nrf_fprintf.c
Compiling file: nrf_fprintf_format.c
Compiling file: nrf_memobj.c
Compiling file: nrf_ringbuf.c
Compiling file: nrf_strerror.c
Compiling file: nrfx_atomic.c
Compiling file: main.c
Compiling file: system_nrf52.c
Linking target: _build/nrf52832_xxaa.out
text    data     bss     dec     hex filename
2072     108      28    2208     8a0 _build/nrf52832_xxaa.out
Preparing: _build/nrf52832_xxaa.hex
Preparing: _build/nrf52832_xxaa.bin
DONE nrf52832_xxaa

至此已经将工程编译,至于下载的话可以使用J-Link来下载调试,由于是在终端下做的开发,不太直观,所以一般借助eclipse来开发,这里不再做介绍。

最后使用J-Link来测试以下代码:

PS F:\nordic\nordic52832\nRF5_SDK_15.3.0_59ac345\examples\peripheral\blinky\pca10040\blank\armgcc> JLink.exe
SEGGER J-Link Commander V6.16c (Compiled Jun 16 2017 18:15:26)
DLL version V6.16c, compiled Jun 16 2017 18:14:49

Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jan 12 2018 16:05:20
Hardware version: V1.00
S/N: 682795959
VTref = 3.300V


Type "connect" to establish a target connection, '?' for help
J-Link>connect
Please specify device / core. <Default>: NRF52832_XXAA
Type '?' for selection dialog
Device>
Please specify target interface:
J) JTAG (Default)
S) SWD
TIF>S
Specify target interface speed [kHz]. <Default>: 4000 kHz
Speed>
Device "NRF52832_XXAA" selected.


Connecting to target via SWD
Found SW-DP with ID 0x2BA01477
Found SW-DP with ID 0x2BA01477
Scanning APs, stopping at first AHB-AP found.
AP[0] IDR: 0x24770011 (AHB-AP)
AHB-AP ROM: 0xE00FF000 (Base addr. of first ROM table)
CPUID reg: 0x410FC241. Implementer code: 0x41 (ARM)
Found Cortex-M4 r0p1, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM
Cortex-M4 identified.
J-Link>erase
Erasing device (nRF52832_xxAA)...
J-Link: Flash download: Total time needed: 0.323s (Prepare: 0.054s, Compare: 0.000s, Erase: 0.261s, Program: 0.000s, Verify: 0.000s, Restore: 0.008s)
Erasing done.
J-Link>loadfile F:\nordic\nordic52832\nRF5_SDK_15.3.0_59ac345\examples\peripheral\blinky\pca10040\blank\armgcc\_build\nrf52832_xxaa.hex
Downloading file [F:\nordic\nordic52832\nRF5_SDK_15.3.0_59ac345\examples\peripheral\blinky\pca10040\blank\armgcc\_build\nrf52832_xxaa.hex]...
J-Link: Flash download: Flash programming performed for 1 range (4096 bytes)
J-Link: Flash download: Total time needed: 0.476s (Prepare: 0.135s, Compare: 0.150s, Erase: 0.030s, Program: 0.069s, Verify: 0.001s, Restore: 0.088s)
O.K.
J-Link>R
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Setting AIRCR.SYSRESETREQ
J-Link>G
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值