Programming of ARM7 controllers in Eclipse: how it's done. v2.0

once I wrote an article about programming controllers in Eclipse, but this was done under Ubuntu without the help tulchan. Now I will tell you how to do it using toolchain under Windows.
So, I had: installed Eclipse for Java, Board with AT91SAM7X512 controller module SAM-ICE from Atmel, and the evil bosses as motivation.


Set/ostanavlivaet Eclipse IDE

The first thing we do is install Eclipse and everything you need in it. The latest version is Eclipse Kepler. If it is not installed go to here and download the Eclipse IDE for C/C++ Developers, then unpack it in a convenient place.

If Eclipse is already installed(in my case Eclipse IDE for Java Developers), then run it, choose a convenient place for us to workspace, where will lie all the projects, go to menu Help ⇒ Install New Software "Work with..." select "Kepler — download.eclipse.org/releases/kepler". We will have a list of what is on this source. Expand the node "Programming language", put a check on "C/C++ Development Tools", then expand the node “Mobile and Device Development“, put a check on “C/C++ GDB Hardware Debugging” click "Next" and "Finish". After the installation Eclipse will restart.

If you downloaded Eclipse IDE for C/C++ Developers, doustanovit plugin C/C++ GDB Hardware Debugging. We need it for debugging, and yet put another plugin to support toolchain.

Again, go to menu Help ⇒ Install New Software, click "Add". In the window that appears, specify any name in the line "Name" and the string "Location" specify the following:
gnuarmeclipse.sourceforge.net/updates
Click "OK". We will show a huge list of what is in the source of one component of the whole — "CDT GNU Cross Development Tools". Put a tick on it, click "Next" and "Finish". During the installation do not pay attention to Warning and feel free to click on OK. After the installation Eclipse will restart.
Voila, here are all. Go ahead.

Set the compiler

Go Suda installer and download Sourcery CodeBench Lite Edition. At the moment the latest version 2013.11-24. Installation is simple, the only thing you need to focus, be sure to check the "Change the PATH variable". After installation, reboot the machine.
To verify the installation at a command prompt, run the command:
arm-none-eabi-gcc -v.
She should show us detailed description of all the tools and compiler. The compiler.

Creates a skeleton project

Run Eclipse, go to menu "File->New->C Project". A window will appear creating the project. Give it a name in the tree “Project type” select project type “ARM Cross Target Application - > Empty Project” and Molchanov select Sourcery. Click Finish.

The project, now we need a Startup file and linker scripts for debug configuration and for firmware in the controller.
Go here and download the archive "AT91SAM7X-EK Software Package for IAR 5.2, Keil and GNU". In this way is /at91sam7x-ek/packages/ and choose any project whose name ends with gnu. It go on this way /projectname/at91lib/boards/at91sam7x-ek, taking out the file board_cstartup.S, and from lying in the same folder at91sam7x512 pick up the file AT91SAM7X512.h, sram.lds, flash.lds and copy all that stuff somewhere in a folder.

Again, go into Eclipse. There, right-click poke on our project and select "Import", in the opened window, select the General->File System, click "Next". Select the folder where you copied the files board_cstartup, sram and flash, put a check mark on those files and click Finish. Voila, the file appeared in our project.

Now we need to improve a little bit the files .lds. Bring them to this:

sram.lds
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(entry)
MEMORY
{
sram (W!RX): ORIGIN = 0x200000, LENGTH = 0x20000
flash (RX): ORIGIN = 0x000000, LENGTH = 0x80000
}

SECTIONS
{
. = ALIGN(4);
.fixed:
{
_sfixed = .;
*(.vectors)
*(.ramfunc)
*(.text*)
*(.rodata*)
*(.data)
. = ALIGN(4);
_efixed = .;
} >sram

.relocate: AT (_efixed)
{
. = ALIGN(4);
_srelocate = .;
. = ALIGN(4);
_erelocate = .;
}

.bss: {
_szero = .;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ezero = .;
} >sram

_sstack = 0x220000;
}
end = .;


flash.lds
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(entry)

MEMORY
{
sram (RWX): ORIGIN = 0x200000, LENGTH = 0x20000
flash (RX): ORIGIN = 0x100000, LENGTH = 0x80000
}

SECTIONS
{
.fixed:
{
. = ALIGN(4);
_sfixed = .;
*(.vectors)
*(.text*);
*(.rodata*)
_efixed = .;
} >flash

.relocate: AT (_efixed)
{
_srelocate = .;
*(.data)
*(.data*)
. = ALIGN(4);
_erelocate = .;
} >sram

.bss: {
_szero = .;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ezero = .;
} >sram

_sstack = 0x220000;
}
end = .;

The skeleton project is ready.
Now you can write code, adding new files via File->New-> C/C++ Source File. I have a project were I just imported.

project setup

Now we need to configure the project for which go to menu Project->Properties or do a right click on our project and there select Properties.
In the window that appears, select the item “C/C++ Build->Setting”. We choose the field Configuration items for All configuration. Now go through all the items>.

Target processor

    the
  1. Processor — arm7tdmi
  2. the
  3. Architecture — armv4t
  4. the
  5. Thumb — disabled
  6. the
  7. Thumb-interwork — enabled
  8. the
  9. Endianness — Little Endian
  10. the
  11. Float ABI — Library
  12. the
  13. Other target flags: -marm — mlong-calls


ARM Windows GCC C Compiler — Optimization

    the
  1. Pack structure — disabled
  2. the
  3. Short enumeration is disabled
  4. the
  5. Function sections are enabled
  6. the
  7. Data sections are disabled


ARM Windows GCC C Compiler — Miscellaneous

    the
  1. Language standard is ISO C99 with GNU Extensions

The rest of the items here do not touch

ARM Windows GCC C Linker

In paragraph General:
    the
  1. Script File — not yet touch
  2. the
  3. Do not use standart start files is enabled
  4. the
  5. Do not use default libraries — enabled
  6. the
  7. Remove the unused section — enabled

Rest — disable

In the paragraph Miscellaneous: put a check on Cross Refereinse.

ARM Windows GNU Create Flash Image — Output

    the
  1. Output file format — ihex


We go back to the Debugging tab, and then under Configuration choose Debug. Put Debug level to Maximum and Debug format — gdb, click Apply. Now switch the configuration to Release, set Debug level to None and click Apply.

Now back on ARM Windows GCC C Linker — General, in the field Configuration choose Debug as Script file, specify the file sram.lds. Click Apply. Now switch the configuration to Release, and as the Script file specify flash file.lds and then click Apply. All project setup is finished. Can now include configuration, build and assemble the firmware.

Fasten debugging

Go here, enter the serial number of our SAM-ICE, download and install the software package for J-Link. There is a very important thing — GDB Server, which is very useful to us for debugging. Another important thing JFlash, which allows you to flash our controller.

Creating the configuration to launch the debug server, which in Eclipse go to menu Run>External Tools- > External Tools Configurations and double-click on the Program item. Custom, newly created configuration.

Main tab:
    the
  1. Name — call how for example GDB Server
  2. the
  3. Location — specify the path to an installed recently JLink GDB Server, in my case it C:\Program Files (x86)\SEGGER\JLinkARM_V412\JLinkGDBServerCL.exe
  4. the
  5. Working Directory — specify the path to the folder of our project
  6. the
  7. Arguments — any arguments we do not need the JTAG interface is used by default


Tab Common:
    the
  1. Put the tick in the Display in favorites menu and Launch in background.


Now create a configuration to start debugging. Go to menu Run>Debug Configurations, in the opened window, double-click on GDB Hardware Debugging that will create a new debug configuration. Custom.
Main tab:
    the
  1. C/C++ Application — specify our app from the Debug folder with the extension .elf
  2. the
  3. Project — referred to our project.


The Debugger tab:
    the
  1. GDB Command — specify our debugger arm-none-eabi-gdb.exe
  2. the
  3. Command Set — standard Windows
  4. the
  5. Protocol Version.
  6. the
  7. Use target remote — enabled
  8. the
  9. JTAG Device to Generic TCP/IP
  10. the
  11. Host name or IP adress — localhost
  12. the
  13. Port number — 2331


Startup tab:
    the
  1. Reset and Delay — disabled
  2. the
  3. Halt — disabled
  4. the
  5. followed by a window where you can specify the following initialization script:
    # connect to the J-Link gdb server
    the target remote localhost:2331
    # Set JTAG speed to 30 kHz
    monitor endian little
    monitor speed 30
    # Reset the target
    monitor reset 8
    monitor sleep 10
    # Change mapping, putting RAM at addr. 0
    monitor long 0xFFFFFF00 = 0x00000001
    # Setup GDB for faster downloads
    set remote memory-write-packet-size 1024
    set remote memory-write-packet-size fixed
    monitor speed 12000
    the break main
    the load
  6. the
  7. Load image — enabled, use project binary
  8. the
  9. Load symbols — enabled, use project binary
  10. the
  11. the Symbol offset is not set
  12. the
  13. Set program counter at — disabled
  14. the
  15. Set breakpoint at — disabled
  16. the
  17. Resume — disabled
  18. the
  19. Run command — empty


Tab Common:
    the
  1. Put the tick in the Display in favorites menu, Allocate console and Launch in background.


Everything is ready. Now for debugging the connected SAM-ICE to the USB port of our machine and to the Board by the controller, collected by our project, run the GDB server, and then run the debug configuration.

In the end we got a free IDE for programming and debug applications for ARM-controllers, to replace, say, the same IAR. Our Eclipse, of course, is slightly inferior in fixing parts — it is impossible to see the values of registers of peripherals such as SPI, timers or counters.

On SEGGER you may notice that there is a version of GDB server for Linux. I suspect that the same simple way, with some modifications, you can organize and debug, for example, under Ubuntu.
Good luck in programming!
PS If you spot an inaccuracy or know of a way to improve this method please write in comments, I will be glad to advice and constructive criticism.
Article based on information from habrahabr.ru

Комментарии

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

March Habrameeting in Kiev

PostgreSQL load testing using JMeter, Yandex.Tank and Overload

Monitoring PostgreSQL with Zabbix