Free custom Assembly for writing and debugging programs for microcontrollers based on the ARM core under Windows 10

the Idea to write an article (which will be included in a series of articles for beginners, desperately eager to create something on microcontrollers with almost zero knowledge in programming in principle) came to me after I had distracted them from their core duties to help the other to adjust the working environment for writing software for his small home project based on the board-and with the stm32f103 on the Board. I expected that it would take about half an hour to an hour, but the friend's laptop was on Windows 10 x64, which for me is unusual (he worked in Ubuntu). By the end, we spent almost 8 hours to setup and create a simple project, struggling with many not obvious things.

In parallel, I had to explain in detail what a item build for what is needed, and how these elements interact with each other, because each has previously microcontrollers faced (from "saw Arduino in the shop").

This material is designed to help beginners quickly and easily configure a completely free infrastructure for working with microcontrollers, as well as to understand how the build the final binary. The manufacturer and model of the microcontroller on the stage setting of this infrastructure is unimportant. Importantly, it was based on the ARM core.

the

table of contents

    the
  1. problem Statement.
  2. the
  3. the Choice of software implementation.
  4. the
  5. Put Eclipse Neon 3.
      the
    • Download the Eclipse installer.
    • the
    • Installed JRE.
    • the
    • Install Eclipse.
    • the
    • Install Eclipse with the GNU ARM Eclipse plugin.
    • the
    • Patchem JRE (in case of error when installing the plugin).
    • the
    • Install the Windows GNU ARM Eclipse Build Tools.
  6. the
  7. Download and install the GNU ARM Embedded Toolchain.
  8. the
  9. Install OpenOCD.
  10. the
  11. Install the drivers for st-link v2.
  12. the
  13. Understand how it all works.
  14. the
  15. Conclusion.

the

problem Statement

you want to configure the bundle so that you can:
    the
  1. to Compile a project consisting of C (C99), CPP (C++14) and ASM files.
  2. the
  3. to Assemble the compiled files from a single firmware file (".elf" and when necessary ".hex" and ".map" file for easy Assembly analysis).

the

the Choice of software implementation

To solve the set task we will need the following software:
    the
  1. Neon 3 Eclipse for C/C++ (the latest version at the time of writing). Will be used as an IDE (text editor with handy auto addition + convenience in the interaction with the debugging tools), which we write code.
  2. the
  3. JRE (at the time of this writing, the latest version is 1.8.0). Without it will not start the installer Eclipse (well, Eclipse itself).
  4. the
  5. the GNU ARM Embedded Toolchain (at the time of this writing, the latest version was 5_4-2016q3-20160926). It is a complex we need software solutions (such as compiler C code is "gcc" C++ code "g++" linker is "ld", a means to download and debug the final firmware "gdb" and many others), thanks to which we will receive from our files with a source code file ending in ".elf", represents the binary firmware file of the microcontroller, which will later be uploaded to the microcontroller (more on this below).
  6. the
  7. OpenOCD 0.10.0. With it, we'll upload our ".elf" program file into the microcontroller (in fact, OpenOCD provides the connection between the gdb from the above toolchain and debugger).
in Addition to these funds, we will need to put several small packets, which I will discuss as early in the installation process.

the

Put Eclipse Neon 3

As mentioned above, in order to write code, we need a text editor in which it would be convenient to write (different methods of auto-complete, search by project, file navigation etc). And after we wrote the code, it would be nice to its compilation, Assembly, and execution — would be a matter of a couple of keystrokes (or mouse clicks, whatever you like).
For these purposes, I use Eclipse. In addition to the editor, it presents another opportunity to connect various extensions, which greatly simplify the developer's life, bringing all the routine work (Assembly, linking, downloading program to controller) to a couple of clicks/taps.

Download installer from Eclipse

    the
  1. Go to the official website
  2. the
  3. top Right click download.
  4. the
  5. In the window that opens on the left select download (x64/x32 should be selected automatically).
  6. the
  7. and click download center, and then begin the download. If you want, you can about to sponsor the creators of the IDE...
Here is a more visual process of downloading.



Installed JRE

in order to run the installer, you need to first install a JRE. The latest version at the time of writing is 1.8.0.
    the
  1. Run the downloaded us installer. Get error that JRE is missing.
  2. the
  3. Press "no" and wait to go to the website.
  4. the
  5. select the "Oracle JRE 1.8.0".
  6. the
  7. Select "Accept License Agreement".
  8. the
  9. Downloadable Offline version according to the bitness of your Windows.
  10. the
  11. Run the downloaded file. Further installation does not cause problems.
Here is a good process of downloading and installing.








Install Eclipse

    the
  1. Run the downloaded us installer.
  2. the
  3. Select the version for C/C++.
  4. the
  5. Specify the installation path (I left the default you suggest).
  6. the
  7. Accept the agreement.
  8. the
  9. Wait for the installation to complete.
  10. the
  11. Click "LAUNCH" to run.
  12. the
  13. Specify the path to use Eclipse for your projects by default (I left the default) and put a checkmark next to this window never appeared.
  14. the
  15. make Sure that the IDE has started, close.
  16. the
  17. At closing time, you can tick the below alert window is closing more appeared.
Here is a good installation process.









Installed Eclipse with the GNU ARM Eclipse plug-in

As mentioned earlier, Eclipse will allow you to connect various plug-ins simplify the developer's life. One of such plugins is GNU ARM Eclipse. Thanks to him we get the opportunity to easily connect all software components used by us when creating a new project under our controller (how to do it, will be described below).
    the
  1. Go to the official website.
  2. the
  3. In the right column under "Downloads", select "plugins".
  4. the
  5. Then under the line "The GNU ARM Eclipse plugins update site URL is still on SourceForge:" copy the link to the plugin. At the time of this writing was: http://gnuarmeclipse.sourceforge.net/updates
  6. the
  7. Open the Eclipse.
  8. the
  9. Go to "Help" - > "Install New Software...".
  10. the
  11. In opened window click on "Add...".
  12. the
  13. In another opened window in the "Name:" write, for example, "ARM" (the name is not important), and in the "Location:" line paste the copied us with a website link.
  14. the
  15. Click OK
  16. the
  17. close the Window, and in the string list will appear empty the checkbox that says "Pending...".
    Further, in the case that you will meet the error presented below, then go to "Patchem JRE", and then go back and repeat everything from step 4.
    Unable to read repository at http://gnuarmeclipse.sourceforge.net/updates/content.xml.
    Received fatal alert: handshake_failure
    If there are no errors or you it is already fixed, we continue.
  18. the
  19. After you see the string "GNU ARM C/C++ Cross Development Tools", select the checkbox to the left of it and click "Next".
  20. the
  21. and then again "Next".
  22. the
  23. Next, accept the license agreement and click "Finish". Begin the installation process.
  24. the
  25. In the process, the installer displays a security warning. Click "OK".
  26. the
  27. after the installation, you will need to restart Eclipse to do this, click "Yes" in the popup window.
  28. the
  29. the installation of this plugin is complete.
plugin installation Process in pictures











Patchem JRE (if the above error occurred)

it So happens that JRE has a bug preventing us from properly install the plug-in. Without going into the nature of the spreading phenomenon, do the following steps.
    the
  1. Go to website patch.
  2. the
  3. Select "Accept License Agreement".
  4. the
  5. Downloadable ".zip" files.
  6. the
  7. Unpack. 2 the archive file ("local_policy.jar" and "US_export_policy.jar") patch and a text file. Copy these 2 files ending in ".jar" and replace them files at installed java. In the case of 64-bit windows 10, this is the way
    C:\Program Files\Java\jre1.8.0_121\lib\security
    The path may be different if we release a new version of the jre or you have a OS with a different bit width. The important thing is that you have to go to the folder "\lib\security" and there copy replace these 2 files. This patch can be considered completed. You can restart eclipse and install the plugin.
Image error and path replacement.





Installed Windows GNU ARM Eclipse Build Tools

the fact that windows by default, the command "make" at the command prompt does not work (although on linux, not all distributions have this app installed by default). Why do we need an app "make" we will talk later but for now we just need to put a plugin that adds the ability to use it. For this.
    the
  1. Go to official repository.
  2. the
  3. Downloadable ".exe" file under your platform. At the time of writing the most current version "gnuarmeclipse-build-tools-win64-2.8-201611221915-setup.exe".
  4. the
  5. Run the downloaded file and just click "Next", "A Agree", "Next", "Install", "Finish".

the

Download and install the GNU ARM Embedded Toolchain

    the
  1. Go to the official website
  2. the
  3. Download the latest version of the collected ".exe" file for Windows (in the column to the right).
  4. the
  5. Run the downloaded file.
  6. the
  7. Click "OK".
  8. the
  9. And Next
  10. the
  11. "Accept"
  12. the
  13. Install (here will explain that the folder can be any, but it is better to leave the one that is default, to avoid problems with registration of components during installation).
  14. the
  15. At the end of the installation remove the check mark from "Show the ReadMe file.". The rest leave default.
  16. the
  17. "Ready"

The following steps are informative and can be omitted. In this case, the opened command prompt can be closed.
the
  • In the opened command prompt write "cd bin" without the quotes (that are here ".exe" files of all components of the toolchain).
  • the
  • Recruit "arm-none-eabi-gcc --version" without the quotes.
  • the
  • after Making sure that gcc is answered, close the console.
  • the installation and check visually.









    the

    Install OpenOCD

    environment and toolchain-om clear. Next you need to install OpenOCD, which Eclipse, arm-none-eabi-gdb will steer controller. Everything is simple.
      the
    1. Go to official repository.
    2. the
    3. Downloadable ".exe" file under your OS. At the time of this writing, the latest version "gnuarmeclipse-openocd-win64-0.10.0-201701241841-setup.exe".
    4. the
    5. Run the downloaded ".exe". The installation produced without changing anything (including the path).

    the

    Install the drivers for st-link v2

    OpenOCD manages the controller, it is true, but for that he requires a driver for the debugger. In our case, it is st-link v2. If you have another debugger, then this part can be skipped.
    Regardless of the fake you have st-link or the original driver, same. Start.
      the
    1. Go to official page of st-link v2
    2. the
    3. at the Bottom of the page is a downloadable file "STSW-LINK009" with the description "ST-LINK, ST-LINK/V2, ST-LINK/V2-1 USB driver signed for Windows7, Windows8, Windows10".
    4. the
    5. When you navigate to another page, click "Download" at the bottom of the page. It is important to note that if you are on the Internet not through the VPN, you will have to register. How to do it, I will not describe. Then the file will be downloaded.
    6. the
    7. Rotaryforum archive select the file to install the driver according to the bitness of the OS. In my case, it "dpinst_amd64.exe".
    8. the
    9. During the installation, agree to all requirements. And select the checkbox "Always trust software from STMicroelectronics".
    the Process of downloading and installation in pictures.





    the

    Understand how it all works

    Here we have installed all prerequisites, created a project in Eclipse (how to create and configure the project, will be written in next article) and clicked "Ctrl+B". Get ready firmware file that by clicking on the icon "debug" can be downloaded to the controller and start debugging directly. But what is behind all these actions? And the following occurs:
      the
    1. After you hit "Ctrl+B" — analyzes the Eclipse project directory tree (all the folders and files in them). To do this, it uses the file paths that we specify when creating the project.
    2. the
    3. then Eclipse generates a makefile. This file contains instructions for the make utility what files need to be compiled (which we added to the project, specifying the path to the directories where they are), what parameters (here, Eclipse uses filled us settings in the tab "C/C++ Build") and how to link the final firmware file previously compiled files.
      Note: makefile has no extension.
    4. the
    5. Then Eclipse invokes the make program with the path to the generated makefile and build settings specified in the project setup (e.g. the number of processor threads used for compilation).
    6. the
    7. After creating all ".o" files from ".c", ".cpp", ".S" (please note, files with assembler code must have an extension of a capital letter "S", otherwise when you create the makefile, these files will be simply ignored, leading to subtle errors) make invokes the linker (arm-none-eabi-ld from the toolchain installed by us-a) with the path to the layout files from the project (files with the file extension ".ld", which we will add to the project). Here is the linker, based on the specified in the layout files with the extension ".ld" instructions (rules) is trying to collect from the pile ".o" file one object file ending in ".elf" (and if there are such instructions in the makefile, ".hex" and ".map"). It is important to note, that linker (linker) decides which pieces of code and data can be thrown out of the program (if they consider that they never used and just take up space). Thus, if we create 1000 global variables, of which we will use in the code only 2, the rest (unless you explicitly specify that they cannot be deleted from the draft the keyword "volatile" or the "put in the section from which nothing can be removed") will be excluded from the final object file, which will give us more memory.
    8. After we got the final object file, we can "sew" in the controller and to debug. This Eclipse calls OpenOCD with the path to the file "openocd.cfg" (the name can be any, with the extension ".cfg", but in case you ever have to debug from the command line and not from under IDE, you will feel that the properly named file to OpenOCD allows you to write the name of the configuration file (because if a configuration file was not specified, it automatically looks for a file with the same name)).
      If the specified file exists, OpenOCD, according to the parameters in the file will try to connect to a microcontroller. If the connection is correct, you will receive a notification that the connection is established, the debugger controller.
      In order to communicate with a controller, OpenOCD uses the driver for st-link-and set us in the beginning. the

    9. After OpenOCD was able to communicate with the controller, it opens the telnet connection. If you do not go into the details, it is necessary to arm-none-eabi-gdb can successfully manage the controller.
    10. the
    11. After the telnet connection is established, the Eclipse launches arm-none-eabi-gdb specifying the port to connect to (the one that opened OpenOCD).
    12. the
    13. Next Eclipse sends to gdb initialization commands (erase, flash, write firmware file, set a breakpoint on main, and several objazatelnaja parameters).
    14. the
    15. then in Eclipse we see a pointer to the first line of code in the main file and you can start debugging.
    technically, all done then the operation can be done manually every time, but agree, much easier to simply click on and enjoy running the debug.

    the

    Conclusion

    In this article I tried to describe in detail the process of the build configuration under Windows. If you have questions — write in lichku, I will try to help and add to the article the problem + the solution.
    In the next article I will tell how to configure Eclipse for a specific controller, to build the demo project and configure debugging.
    Article based on information from habrahabr.ru

    Комментарии

    Популярные сообщения из этого блога

    Automatically create Liquibase migrations for PostgreSQL

    Looking for books as you want

    Vkontakte sync with address book for iPhone. How it was done