Programming ARM Controllers in Eclipse on Ubuntu: How to Do It

At work, I encountered programming of the AT91SA7A3 controller, IAR is used for this. But since I am too lazy to keep the second system, an attempt was made to provide the ability to program, debug and flash under my favorite Ubuntu. And so, after two weeks of communicating with the wall through obscene vocabulary (as much as the wallpaper began to move), it was possible to set up all this economy. And since, perhaps, I will not be the only one, I will write how this is done.

So, I had one: AT91SAM7A3-EK board, Atmel SAM-ICE JTAG adapter, a computer with Ubuntu 11.04, half a pack of cigarettes and a couple of coffee mugs. Nice kit. Go!

1) We go to the Eclipse website (http://www.eclipse.org) and download the Eclipse IDE for C / C ++ Developers for our system. The latest version of this is Eclipse 3.7 Indigo.
2) We go to the OpenOCD project website (http://developer.berlios.de/projects/openocd/) and pump out the OpenOCD 0.5.0 source code.
3) We follow the compiler. I chose Sourcery G ++, as it is being updated, unlike ARMGCC. Download IA32 GNU / Linux TAR.
4) Optional: while all this is pumped out, you can go for a smoke.
5) Unpack the Eclipse archive into the directory we need (I have it / home / user / arm, the eclipse folder will appear).
6) Unpack the compiler archive into the desired directory (I have it / home / user / arm, the arm-2011.03 folder will appear or something similar, the numbers may differ).
7) We go to Synaptic, install the usb-dev package, we will need it later.
8) Unpack the archive with OpenOCD, preferably in the home folder, it will be a little easier with the paths.
9) Run the terminal, jump to the OpenOCD source folder (the one you just unpacked) and write the following commands:

./configure --enable-jlink
sudo make
sudo make install The

key --enable-jlink is needed to enable support for our SAM- ICE, for this, we installed the usb-dev bag.
10) Optional: while all this is going, you can go have a drink of coffee.
11) Now also in the console we write the following: sudo gedit / etc / environment.
In the file that opens, add the path to our compiler, you should get something like the following:
PATH = "/ usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / sbin: / bin: / usr / games: /home/user/arm/arm-2011.03/bin "We
reboot the car and (optionally) go to smoke.
12) The machine rebooted, start Eclipse from the folder, select the workspace and check the box so that it no longer crawls. Go to Help-> Install New Software, click on the Add button, write the name Zylincdt, the address opensource.zylin.com/zylincdt , click OK, check the only package in the Zylin Embedded CDT window, and follow the instructions of the installer. After installing Eclipse will restart. Now create a new project: go to File-> New-> C Project, select Makefile project-> Empty project, Toolchain-Other Toolchain, give the project a name and click Finish. Now temporarily minimize Eclipse.
13) We go to the folder / usr / local / share / openocd / scripts / target and look for the configuration file with our controller in the name there. Mine (AT91SAM7A3) was not there, but it was quickly found in Google and a little tweaked with handles. If there is, fine. We connect SAM-ICE to the computer and the board, apply power to the board. We launch the terminal and write the following:

sudo openocd -f interface / jlink.cfg -c "jtag_rclk 30; gdb_flash_program enable; gdb_memory_map disable" -f target / at91sam7a3.cfg

Attention! If you have another adapter or another board, replace jlink.cfg and at91sam7a3.cfg with the files you need.
OpenOCD should start and show us a bunch of information, among which there will be a chip model. Turn off the terminal window.
14) We go to the Atmel website and look for a trial project. There is a somewhat crooked system, so I will immediately give a direct link to the project for our AT91SAM7A3-EK board : www.atmel.com/dyn/resources/...ing_started.zip . Download, unpack, remember where unpacked. We return to Eclipse, right-click on our project, select Import, there General-File System. We point him to the folder where the freshly downloaded project was unpacked, indicate what files are needed (you can just select everything and not be tormented), and click Finish.
15) We go to the Makefile of the project, find the line CROSS_COMPILE = arm-elf- and replace it with CROSS_COMPILE = arm-none-eabi-Save the Makefile, go to Project-> Build Project and watch how everything compiles and compiles. If everything is done correctly, the output will be two files * .elf and * .bin.
16) Create the gdbinit_sram and gdbinit_flash files in the home folder (or somewhere else), in which we write the following:
gdbinit_sram:

target remote localhost: 3333
monitor reset init
monitor halt
printf "____Target halted ____ \ n"
set $ mem_a = * 0x00000000
set $ mem_c = $ mem_a
set $ mem_a = $ mem_a + 1
set * 0x00000000 = $ mem_a
set $ mem_b = * 0x00000000
if ($ mem_a == $ mem_b)
set * 0x00000000 = $ mem_c
printf "____ Remap_is_Done ____ \ n"
else
printf "____ Remap_is_Not ____ \ n "
set * 0xFFFFFF00 = 1
printf" ____ Remap_is_Done ____ \ n "
end
monitor reg pc 0x00000000
monitor arm7_9 dbgrq enable
monitor gdb_breakpoint_override hard
load
hbreak / * here specify the breakpoint * *
continue
condition 1

gdbinit_flash:

target remote localhost: 3333
monitor reset init
monitor halt
printf "____Target halted ____ \ n"
set $ mem_a = * 0x00000000
set $ mem_c = $ mem_a
set $ mem_a = $ mem_a + 1
set * 0x00000000 = $ mem_a
set $ mem_b = * 0x00000000
if ($ mem_a == $ mem_b)
printf "____ Remap_is_Not ____ \ n"
set * 0x00000000 = $ mem_c
set * 0xFFFFFF00 = 1
printf "____ Remap_is_Done ____ \ n"
else
printf "____ Remap_is_Done ____ \ n"
end
monitor arm7_9 dcc_downloads enable
monitor arm7_9 fast_memory_access enable
monitor flash erase_sector 0 0 15
monitor flash probe 0
monitor flash write_bank 0 / * here we indicate the path to the firmware file * / 0
monitor reset run
kill

17) Now configure the debugger. Go to Run-> Debug Configuration, there we create 2 new configurations: Zylin Embedded Debug (Native) sram (for debugging) and Zylin Embedded Debug (Native) flash (for firmware). Now tabbed.
Main: C / C ++ Application specify the path and file name, the one that * .elf is needed for debugging, * .bin- for firmware.
Debugger: GDB Debuger - specify the path to our debugger, in our case it will be like home / user / arm / arm-2011.03 / bin / arm-none-eabi-gdb,
GDB Command File - here we specify the path to the corresponding gdbinit file.
Commands: in the Initialze Command field is empty.
Common tab: check the Debug box under Display in favorites menu.
Click Apply, make sure that OpenOCD is running, click Debug. A window with debugging information should appear if the sram configuration is running. Optionally, you can add windows with an overview of variables, memory, disassembly, and so on.
Voila, everything works.
Now a small addition. It’s better not to delete the downloaded project - there is a header file describing a bunch of constants for easier work with registers, there are Startup files, there is a linker script (which is important) and the most important thing is a Makefile that describes how memory will be allocated in files for the debugger and programmer. For me, it's better to transfer them to each new project and edit the Makefile a bit. And life will be beautiful.

PS A little later, I realized that if you move your brains a little, the same thing can be done using the toolchain for ARM, but the need is gone and I didn’t do it.

Also popular now: