Tutorial: Create a Blinky ARM test project(创建一个闪灯的arm测试项目)

Background 背景

ref : Tutorial: Create a Blinky ARM test project

如果你刚入门ARM开发, 建议你根据这份简短的教程进行操作,并学会如何构建一个简单可行的程序来点亮LED灯。
If you are new to ARM development, it is recommended to follow this short tutorial and learn how to build a simple test executable program that will blink a LED.

注意:这份教程是基于 嵌入式GNU 工具链构建的,只有使用这样的工具链才能确保成功。用其他的工具链也许可行,但在源码以及链接选项的小改动是必要的。
Note: this tutorial was created with the GNU Tools for ARM Embedded Processors toolchain in mind. Only when using this toolchain the build is guaranteed to succeed. Using other toolchains might be possible, but small changes might be necessary in the source code and in the linker options.

此外,需要一份不早于20150807的 STM32F4 工程摸板。
Note2: this tutorial requires a recent version of the STM32F4 template, not older than 20150807.

英语笔记: “not older than .. 不早于”

Prerequisites 前提

创建项目之前,请确保 所有 在How to install GNU MCU Eclipse?中描述的前提要求 都检查无误,尤其是若以Windows系统下作为开发平台的,则还需注意安装构建工具。
Before creating a new project, please be sure you checked all prerequisites described in the How to install GNU MCU Eclipse? page, especially the need to install the build tools if you use Windows as your development platform.

同样地,也建议 设置好 工作区偏好 并 装好 预先的 CMSIS包
It is also recommended to set the workspace preferences and to install the desired CMSIS packs.

注意: 多LED工程模板当前只适合STM32F4系列,且仅用C++,因为它允许我们很容易地初始化多LED闪灯的目标文件。
Note: the multi-LED template is currently available only for ST32F4, and only for C++, since it allows to easily instantiate multiple BlinkLed objects.

Create a new C++ project 创建一个新的C++项目

创建项目:运行Eclipse --> menu --> File --> New, 选择 "C++ Project"
To create a new project, go to Eclipse menu, FileNew (or the button in the upper left corner), and select the C++ Project:

Create a new C++ project

In the C++ Project window:

  • in the Project name: field enter the name of the new project, for example blinky
  • in the Project type: section expand the Executable type and select STM32F4xx C/C++ Project
  • in the Toolchains: section select Cross ARM GCC
  • click the Next > button

New C++ blinky project

In the Target processor settings window be sure to:

  • select the STM32F407xx chip family
  • set the Flash size (kB) field to 1024 kB
  • set the Clock (Hz): field to 8000000
  • for a more complete example, change the Use system calls: fields to Semihosting (POSIX system calls via host)
  • click the Next > button.

Blinky processor settings

In the Folders page leave the suggested folders unchanged and click the Next > button.

Blinky project folder settings

In the Select Configurations page leave the suggested Debug/Release configurations checked and click the Next > button.

Blinky project configurations

In the Cross GNU ARM Toolchain window:

  • select the Toolchain name: GNU Tools for ARM Embedded Processors (mandatory)
  • browse for the bin folder within the toolchain folder; don’t be afraid to use the absolute address, it is not stored in the project;
  • click the Finish button

Blinky toolchain and path selection

Note 1: when selecting the path, be sure you select the /bin folder where the programs with long, prefixed names are stored, and not the inner /bin folder where the short name programs may be available.

Note 2: DO NOT SKIP this step, it is mandatory to have a correct toolchain path defined in order for the build to complete correctly.

Toolchain path

The result of the wizard is a simple project, with a main() function printing a greeting on the standard output.

The new C++ project

Build the project

To start the build:

  • select the new project in the Project Explorer section
  • click the hammer icon

Hammer Build

The build process should leave in the Console window a listing like this:

The build console

The files created by the build process are left in a folder named by the name of the configuration, for example Debug or Release.

Blinky Build Result

As seen above, the Debug folder is populated with:

  • all make files required for the build (makefile and various *.mk files, generated by CDT),
  • the object files and dependency files generated during the build (main.o and main.d) and
  • the final executable file, with all debug symbols, useful for a debug session (blinky.elf)
  • the binary executable file, ready to be programmed in flash (blinky.hex)
  • a program map, with all symbols and their associated addresses (blinky.map)

Assign a board and device to the project

Although optional, it is highly recommended to assign a board and a device to the project, using the packs definitions. If you did not do it before, install the STM32F4 package, as explained in the Packs Manager page.

To assign the board and device:

  • select the project
  • either with right click or via Project menu, enter Properties
  • expand the C/C++ Build entry
  • select the Settings entry
  • select the Devices tab
  • in the Boards section, expand STMicroelectronics
  • expand STM32F4-Discovery
  • select STM32F407VG
  • click OK

BlinkyAssignDevice

Run the test with QEMU

The most convenient way to run this test is to use the QEMU Debugging plug-in. Actually, with the latest plug-ins, you can directly Run the application, you do not need to Debug it.

As for any debugging plug-in,

  • select the blinky.elf file
  • either with right click Run As… or in the Run menu, select Run Configurations
  • doble click the GDB QEMU Debugging
  • select the Debugger tab
  • check if the Board name: and Device name: are correctly filled-in; without assigning the board and device to the project, these fields must be filled in manually;
  • enable Extra verbose

The QEMU Debugger tab

When done, click the Run button.

If you did not disable the graphic windows, an animated image of the board is shown, with the 4 LEDs blinking.

The STM32F4-Discovery 4 LEDs

The QEMU process also displays some information in its console:

QEMU console with semihosting output

Semihosting

Contrary to usual POSIX environments, like GNU/Linux, embedded systems usually do not provide standard input/output devices. In the code generated by the template, the output of the printf() calls, including trace_printf(), is redirected to a special debugging channel implemented by most debuggers, using the semihosting protocol.

Next step

Once you checked the development environment to be functional, proceed with creating real projects using the STM32Fx templates, Freescale KLxx templates, or, if your target processor is not yet supported, using the Generic Cortex-M template.

Troubleshooting

The usual sources for build failures are:

  • a wrong or missing toolchain path; go to the project PropertiesC/C++ BuildSettings → the Toolchains tab and define the correct path;

Global Tools Path

Set the toolchain path for all projects and workspaces.

  • missing build tools (make & rm) on Windows; install the build tools;
  • a wrong or missing QEMU path; go to the project (Window →) PreferencesMCUGlobal QEMU Path (or Workspace QEMU Path) and define the correct path;

The QEMU path

Support

If something went wrong and you cannot build the project, please check the How to use, the FAQ and the Known issues pages. If you do not find the answer to your question, please read the Support page on how to record a support request in the Support tracker. Do not post comments on this page unless they are related to the text (the phrasing is not correct, you discovered typos, etc).


Last modified on Wed Apr 25 17:59:20 2018 UTC.

原文地址:https://www.cnblogs.com/schips/p/12375684.html