I've done many attempts to build and execute my own C program on the atmel sama5d4 xplained ultra board. And today is the big day. Thanks to the tutorial on mikrocontroller-software.de, I was able to cross-compile and run my first binary.
Hooray! |
Was it difficult?
No. Once I found the how-to guide, I greased up my German language skills. I had everything running in less than 20 minutes.
That's always how things happen. You chase your tail for a good month. Then you find that gem on the internet that walks you through the steps.
And it turned out to be not difficult at all.
Hindsight is a %*$§.
Step-by-Step
I can't explain it better than mikrocontroller-software.de. But I've made screenshots along the way, so it would be a shame not to share them.
Step 1: Start Eclipse for DS-5 and create a new C++ Project
Step 2: name the project, type = Executable : Empty Project, Toolchains: GCC 4.x built-in (or another one, I wasn't adventurous enough yet to try a different one then that of the how-to guide )
Next and Finish
Step 3: create the main.cpp file by right clicking on the project and adding a new C++ source file
Step 4: Enter the source lines. I stayed faithful to the example and kept the word A7 in there.
#include <iostream> int main() { std::cout << "Hello World! Cortex A7 Atmel\r\n"; return 0; }
Step 5: inform the toolchain about the target platform. You do that by setting additional flags on the command lines.
The following flag needs to be added (see the original how-to to check why ARM5 needs v7):
-marm -march=armv7-a
a:
b:
c:
Step 6: build the program
Step 7: review the console output:
12:21:50 **** Build of configuration Debug for project HelloARMWorld **** make all 'Building file: ../main.cpp' 'Invoking: GCC C++ Compiler 4 [arm-linux-gnueabihf]' arm-linux-gnueabihf-g++ -O0 -g3 -Wall -c -fmessage-length=0 -marm -march=armv7-a -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp" 'Finished building: ../main.cpp' ' ' 'Building target: HelloARMWorld' 'Invoking: GCC C++ Linker 4 [arm-linux-gnueabihf]' arm-linux-gnueabihf-g++ -marm -march=armv7-a -o "HelloARMWorld" ./main.o 'Finished building target: HelloARMWorld' ' ' 12:21:54 Build Finished (took 3s.862ms)
Step 8: load the program and set it as executable
a: load the program, in binary mode, with your favorite SCP tool (I use WinSCP)
b: start your favorite terminal (I use PuTTY) and set the executable flag and verify that all is ok
chmod +x HelloARMWorld ls -l
Step 9: execute the program, sit back and enjoy your success
./HelloARMWorld
A big thank you to http://www.mikrocontroller-software.de/
Summary
Is this what I wanted to do? No, not 100%. But very very close. My goal was to be able to build bare-metal application for the board , load and execute it. I'm currently able to build an application, and run it on Linux. That is a good situation to be in. It unlocks a multitude of possibilities that I wasn't able to investigate earlier. If time allows, I will step deeper into the bare metal. But now I'm first going to enjoy my newly gained access to those new possibilities. |
Top Comments