I once wrote an article
about programming controllers in Eclipse , but this was done under Ubuntu and without the help of toolchain. Now I will tell you how to do this using the toolchain and under Windows.
So, I had: Eclipse installed for Java, a board with an AT91SAM7X512 controller, Atmel's SAM-ICE module, and evil bosses as motivation.
Install / reinstall Eclipse IDE
The first thing we do is install Eclipse and everything you need into it. The latest current version is Eclipse Kepler. If it is not installed, go
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 launch it, choose a convenient place for us to workpace, where all the projects will lie, go to the
Help ⇒ Install New Software menu and in the "
Work with ... "choose" Kepler -
download.eclipse.org/releases/kepler ". We will open a list of what is on this source. Expand the "
Programming language " node, tick the "
C / C ++ Development Tools ", then expand the "
Mobile and Device Development " node, tick the "
C / C ++ GDB Hardware Debugging ", click "
Next " and "
Finish ". After installation, Eclipse will restart.
')
In case you downloaded the Eclipse IDE for C / C ++ Developers, reinstall the C / C ++ GDB Hardware Debugging plugin. We will need it when debugging, but for now we will install another plugin to support the toolchain.
Go back to the
Help ⇒ Install New Software menu, click the "
Add " button. In the window that appears, specify any name in the string "
Name ", and in the string "
Location " indicate the following:
gnuarmeclipse.sourceforge.net/updates
Click "
OK ". We will be shown a huge list of what is in this source from a whole one component - the "
CDT GNU Cross Development Tools ". We put a tick on it, click "
Next " and "
Finish ". During installation, do not pay attention to Warning and feel free to click on OK. After installation, Eclipse will restart.
Voila, that's all. Go ahead.
Install the compiler
Go
here and download the Sourcery CodeBench Lite Edition installer. At the moment, the latest version 2013.11-24. The installation is simple, the only thing to focus on - be sure to check the box “
Change PATH variable ”. After installation, restart the machine.
To verify the installation, in the command line, execute the command:
arm-none-eabi-gcc -v
.
It should show us a detailed description of the entire toolkit and a version of the compiler. On this with the compiler everything.
Create a skeleton project
Run Eclipse, go to the menu "
File-> New-> C Project ". A project creation window will appear. We give it a name, in the “
Project type ” tree, select the project type “
ARM Cross Target Application -> Empty Project ”, and select Sourcery from the toolchains. Click Finish.
There is a project, now we need a Startup file and linker scripts for debug configuration and for flashing to the controller.
Go
here and download the archive "AT91SAM7X-EK Software Package for IAR 5.2, Keil and GNU". In it, we go along the path / at91sam7x-ek / packages / and choose any project whose name ends in gnu. We follow this path / project_name / at91lib / boards / at91sam7x-ek,
pick up the file
board_cstartup.S from here,
pick the files
AT91sam7x512.h ,
sram.lds ,
flash.lds from the folder
at91sam7x512 and copy all this. in one folder.
Go to Eclipse again. There we right-click on our project and select "
Import ", in the window that appears, select
General-> File System , click Next. Select the folder where you copied the files board_cstartup, sram and flash, put a tick on these files and click
Finish . Voila, the files appeared in our project.
Now you need a little fix .lds files. Bring them to this form:
sram.ldsOUTPUT_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.ldsOUTPUT_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 =.;
Skeleton design is ready.
Now you can write code by adding new files through
File-> New-> C / C ++ Source File . I had a project and I just imported it.
Project Setup
Now you need to configure the project, for which we go to the
Project-> Properties menu or right-click on our project and select
Properties there.
In the window that appears, select the item “
C / C ++ Build-> Setting ”. Select the item Configuration in the Configuration field. Now go through all the settings.
Target processor
- Processor - arm7tdmi
- Architecture - armv4t
- Thumb - disabled
- Thumb interwork - enabled
- Endianness - Little Endian
- Float ABI - Library
- Other target flags: -marm - mlong-calls
ARM Windows GCC C Compiler - Optimization
- Pack structure - disabled
- Short enumeration - disabled
- Function sections - enabled
- Data sections - disabled
ARM Windows GCC C Compiler - Miscellaneous
- Language Standart - ISO C99 with GNU Extensions
The remaining items here do not touch
ARM Windows GCC C Linker
In paragraph General:
- Script File - do not touch yet
- Do not use standart start files - enabled
- Do not use default libraries - enabled
- Remove unused section - enabled
The rest - disable
In the item Miscellaneous: put a tick on Cross Refereinse.
ARM Windows GNU Create Flash Image - Output
- Output file format - ihex
Go back to the Debugging tab, and in the Configuration field, select Debug. We set the Debug level to Maximum, and the Debug format to gdb, click Apply. Now we switch the configuration to Release, set the Debug level - None and click Apply.
Now we’ll go back to ARM Windows GCC C Linker - General, select Debug in the Configuration field, and specify our sram.lds file as the Script file. Click Apply. Now we switch the configuration to Release, and we specify the flash.lds file as the Script file and click Apply again. Everything, project setup is complete. Now we can enable the required build configuration and build the firmware.
We 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 here - GDB Server, which is very useful to us for debugging. Another important thing is JFlash, which allows you to flash our controller without any problems.
Create a configuration for running the debug server, for which in Eclipse we go to the menu
Run-> External Tools-> External Tools Configurations and double-click on the Program item. Customize, newly created configuration.
Main tab:
- Name - let's call it something, for example GDB Server
- Location - specify the path to the recently installed JLink GDB Server, in my case it is C: \ Program Files (x86) \ SEGGER \ JLinkARM_V412 \ JLinkGDBServerCL.exe
- Working Directory - specify the path to the folder of our project
- Arguments - we don’t need any arguments, the JTAG interface is used by default.
Common tab:
- We tick the Display in the favorites menu and Launch in background.
Now create a configuration for running debugging. Go to the menu
Run-> Debug Configurations , in the window that opens, double-click on the
GDB Hardware Debugging , which will create a new debugging configuration. Customizable.
Main tab:
- C / C ++ Application - specify our application from the Debug folder with the .elf extension
- Project - we indicate our project.
- At the bottom of the window, at the level of the Apply and Revert buttons, another hidden setting is hidden, you need to open it before going to the next tab and select " Legacy GDB Hardware Debugging Launcher "
Debugger tab:
- GDB Command - specify our debugger arm-none-eabi-gdb.exe
- Command Set - Standart Windows
- Protocol Version - mi
- Use remote target - enabled
- JTAG Device - Generic TCP / IP
- Host name or IP adress - localhost
- Port number - 2331
Startup tab:
- Reset and Delay - disabled
- Halt - disabled
- This is followed by a window in which we specify the following initialization script:
# connect to the J-Link gdb server
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
break main
load
- Load image - enabled, use project binary
- Load symbols - enabled, use project binary
- Symbol offset - do not set
- Set program counter at - disabled
- Set breakpoint at - disabled
- Resume - disabled
- Run command - empty
Common tab:
- We tick the Display in the favorites menu, Allocate console and Launch in background.
All is ready. Now, for debugging, we connect SAM-ICE to the USB port of our machine and to the board with the controller, build our project, start the GDB server, and then launch the debug configuration itself.
As a result, we received a free IDE for programming and debugging applications for ARM controllers, to replace, say, the same IAR. Our Eclipse, of course, is somewhat inferior in terms of debugging - it is not possible to view the register values of peripheral devices, such as SPI or timers-counters.
On the
SEGGER website,
you can see that there is a version of the GDB server for Linux. I suspect that in the same simple way with some changes you can organize and debugging, for example, under Ubuntu.
Good luck to everyone in programming matters!
PS If you have noticed an inaccuracy or know a way to improve this technique - write in the comments, I will be glad to advice and constructive criticism.