The conditions of the problem on the one hand are complex, on the other hand they are very simply formulated. There is a server very, very far away, the Arduino is connected to it via FTDI converter. Server access - SSH. But it is necessary to correct, compile and upload the firmware to the board. A classic example is wallpapering a locked room through a keyhole. Obviously there can be no talk of any Arduino IDE, Eclipse, or other beautiful programming environments.
On the other hand, that we should build a house, we will draw, we will live.So the goal is to create an environment on the remote system that is sufficient for Arduino programming. Speech about possible serious debugging of course does not go, and I write and debug the sketches themselves on the desktop machine in the Eclipse environment, using all the comfort that gives me a cozy chair and a big beautiful monitor. Accordingly, one board is mounted on a circuit board for rapid prototyping, and the other on a far server, one can say production in all its glory.
For reference, the target system is:X86 architecture, kernel 3.7.5-hardened-r1
Installed stable packages of the latest versions.
Arduino Pro Mini 328p 16MHz 5V board and USB converter to it on FTDI chip
')
Installation of USB converter into the kernel
How to add support for the module for the FTDI converter to the kernel is described in my previous
article , I refer to it for details, and here I’ll just indicate what needs to be added to the kernel config:
Device Drivers --->
[*] USB support --->
<M> USB Serial Converter support --->
<M> USB FTDI Single Port Serial Driver
After connecting the converter to USB, the following device should appear:
# ls -l / dev / ttyUSB0
crw-rw ---- 1 root uucp, 0 March 9 13:04 / dev / ttyUSB0
Setting the toolchain environment to compile
In general, everything is similar to what I wrote
earlier , but, as they say, there is a nuance. The target system uses the hardened kernel and the corresponding portage keys, so a simple toolchain build will fail with an error:
configure: error: *** --enable-esp is not supported on this XXXX target.
To fix this problem, you need to disable the keys that are not relevant for the target assembly; to do this, the command changes as follows:
# USE = "nopie nossp -hardened -pic -openmp" crossdev -S -t avr
Incidental solution of problems with incorrect paths
As I already
wrote , the paths may be incorrect, so you need to create symbolic links:
# find / usr / -name avr5.x
/usr/lib64/binutils/avr/2.23.1/ldscripts/avr5.x
# ln -s /usr/lib64/binutils/avr/2.23.1/ldscripts / usr / avr / lib / ldscripts
# find / usr / -name crtm328p.o
/usr/avr/lib/avr5/crtm328p.o
# ln -s /usr/avr/lib/avr5/crtm328p.o / usr / avr / lib /
Install at the same time programmer and minicom
# emerge dev-embedded / avrdude net-dialup / minicom
Create user
We have nothing more to do in the root environment, so we create for ourselves a simple user, if he is still not there, and continue everything else in his environment. Do not forget to add your user to the uucp group.
# useradd -G uucp -m -U arduino
# passwd arduino
# su arduino
Arduino sources, nothing personal
If you install arduino from portage, it will pull up a bunch of packages and dependencies, the same Java VM, and so on and so forth. I see no reason to install all this, especially if we recall that the target system is a server, where, by definition, there should be nothing superfluous.
So download and unpack the source, for this we go here
arduino.cc/en/Main/Software and see what is fresh from the tin. At the time of this writing, release 1.0.4 has been released. In your case, the version may be different, so that further steps do not depend on the version, simply rename the directory.
$ wget http://arduino.googlecode.com/files/arduino-1.0.4-linux32.tgz
$ tar -xzvf arduino-1.0.4-linux32.tgz
$ mv arduino-1.0.4 arduino
Compiling a static library
There are three options for obtaining a static library for subsequent linking with future projects.
- Install somewhere a complete Arduino IDE, create any sketch in it, compile it, find the file you need and drag it out. Maybe it works, I have not tried. It seems to me that the degree of identity of the systems must be high. In general, this is not our way.
- Compile it within each project. Also a dubious event, because, see the following. paragraph...
- You can make the library once, and then link it with each new project. This is exactly what fits into our gentoo-way.
Create a folder for the library and connect the source
$ cd ~
$ mkdir ArduinoCore
$ cd ArduinoCore
$ mkdir src
$ ln -s ~ / arduino / hardware / arduino / cores / arduino / * src /
If you have problems with this, then this is the folder where the Arduino.h file is located and the other headers and sources, you can find it with the command
$ find ~ / arduino -name Arduino.h
/home/arduino/arduino/hardware/arduino/cores/arduino/Arduino.h
In addition, we will need the pins_arduino.h header file specific to your version of the board. In my case there are the following files:
$ find ~ / arduino -name pins_arduino.h
/home/arduino/arduino/hardware/arduino/variants/micro/pins_arduino.h
/home/arduino/arduino/hardware/arduino/variants/standard/pins_arduino.h
/home/arduino/arduino/hardware/arduino/variants/leonardo/pins_arduino.h
/home/arduino/arduino/hardware/arduino/variants/mega/pins_arduino.h
/home/arduino/arduino/hardware/arduino/variants/eightanaloginputs/pins_arduino.h
I fit the standard, and you choose your:
$ ln -s ~ / arduino / hardware / arduino / variants / standard / pins_arduino.h src /
Compile library
I honestly took the Makefile from Eclipse and corrected only two lines in which there were absolute paths instead of relative ones. In fact, the whole ideology is taken from there and implemented in the console. We take
328P_16MHz.tgz and unpack it into the ~ / ArduinoCore folder, the following should turn out:
$ cd ~ / ArduinoCore /
$ wget https://github.com/madixi/ArduinoCore/blob/master/ArduinoCore/328P_16MHz.tgz?raw=true \
-O 328P_16MHz.tgz
$ tar -xzvf 328P_16MHz.tgz
$ ls -R ~ / ArduinoCore
/ home / arduino / ArduinoCore:
328P_16MHz 328P_16MHz.tgz src
/ home / arduino / ArduinoCore / 328P_16MHz:
makefile objects.mk sources.mk src
/ home / arduino / ArduinoCore / 328P_16MHz / src:
subdir.mk
/ home / arduino / ArduinoCore / src:
Arduino.h IPAddress.h Stream.h WCharacter.h malloc.c wiring_private.h
CDC.cpp Platform.h Tone.cpp WInterrupts.c new.cpp wiring_pulse.c
Client.h Print.cpp USBAPI.h WMath.cpp new.h wiring_shift.c
HID.cpp Print.h USBCore.cpp WString.cpp pins_arduino.h
HardwareSerial.cpp Printable.h USBCore.h WString.h wiring.c
HardwareSerial.h Server.h USBDesc.h binary.h wiring_analog.c
IPAddress.cpp Stream.cpp Udp.h main.cpp wiring_digital.c
If you have another board (another chip) and / or another frequency, then it is enough to fix the compiler keys in the file:
~ / ArduinoCore / 328P_16MHz / src / subdir.mk
-mmcu = atmega328p
-DF_CPU = 16000000UL
The last thing left to do is to compile the static library:
$ cd 328P_16MHz
$ make
you end up with something like:
$ ls -l ~ / ArduinoCore / 328P_16MHz
total 592
-rw-r - r-- 1 arduino arduino 187186 Mar 18 10:18 libArduinoCore.a
-rw-r - r-- 1 arduino arduino 327022 Mar 18 10:18 libArduinoCore.lss
-rw-r - r-- 1 arduino arduino 2021 Mar 17 14:46 makefile
-rw-r - r-- 1 arduino arduino 231 Mar 17 14:46 objects.mk
-rw-r - r-- 1 arduino arduino 599 Mar 17 14:46 sources.mk
drwxr-xr-x 2 arduino arduino 4096 Mar 18 10:17 src
For the sake of what we did it all - this is the static library
libArduinoCore.a , which we link with future projects.
First project
Each programming language has its own Hello world, in Arduino it is Blink, blinking with an LED that is soldered directly on the board and connected to the 13th output of the chip. His merry twinkle will eventually tell you that everything worked out.
$ cd ~
$ mkdir BlinkA
$ cd BlinkA
We create the main.cpp file
#include <Arduino.h> int led = 13; void setup() { pinMode(led, OUTPUT); Serial.begin(9600); Serial.println("Example: Blink 'A'-letter Morse code '.-'"); } void loop() { digitalWrite(led, HIGH); delay(200); digitalWrite(led, LOW); delay(200); digitalWrite(led, HIGH); delay(600); digitalWrite(led, LOW); delay(200); Serial.println("._"); } int main(void) { init(); setup(); for (;;) { loop(); } }
As you can see, it differs slightly from the sketch. At the beginning, the connection of the Arduino.h header file is added, and at the end, the main function body. All this Arduino IDE adds seamlessly from you. Do not modify the main () function unless you know exactly why you need it.
Compile the first project
As in the previous case, the Makefile was taken from Eclipse, and the changes touched solely on replacing absolute paths with relative ones. We take the
ArduinoBuild.tgz file and unpack it in the project folder. You should have the following:
$ cd ~ / BlinkA
$ wget https://github.com/madixi/BlinkA/blob/master/BlinkA/ArduinoBuild.tgz?raw=true -O ArduinoBuild.tgz
$ tar -xzvf ArduinoBuild.tgz
$ ls -lR ~ / BlinkA /
/ home / arduino / BlinkA /:
total 8
-rw-r - r-- 1 arduino arduino 1430 Mar 18 10:20 ArduinoBuild.tgz
drwxr-xr-x 2 arduino arduino 71 Mar 17 21:06 Debug
-rw-r - r-- 1 arduino arduino 563 Mar 17 19:45 main.cpp
/ home / arduino / BlinkA / Debug:
total 16
-rw-r - r-- 1 arduino arduino 2314 Mar 17 21:06 makefile
-rw-r - r-- 1 arduino arduino 249 Mar 17 21:06 objects.mk
-rw-r - r-- 1 arduino arduino 609 Mar 17 21:06 sources.mk
-rw-r - r-- 1 arduino arduino 761 Mar 17 21:06 subdir.mk
Next, we collect the project:
cd ~ / BlinkA / Debug
make
If everything went well, then you should have something like this:
$ ls -lR ~ / BlinkA /
/ home / arduino / BlinkA /:
total 12
-rw-r - r-- 1 arduino arduino 1430 Mar 18 10:20 ArduinoBuild.tgz
drwxr-xr-x 2 arduino arduino 4096 Mar 18 10:23 Debug
-rw-r - r-- 1 arduino arduino 563 Mar 17 19:45 main.cpp
/ home / arduino / BlinkA / Debug:
total 216
-rwxr-xr-x 1 arduino arduino 29271 Mar 18 10:23 BlinkA.elf
-rw-r - r-- 1 arduino arduino 7078 Mar 18 10:23 BlinkA.hex
-rw-r - r-- 1 arduino arduino 41490 Mar 18 10:23 BlinkA.lss
-rw-r - r-- 1 arduino arduino 98309 Mar 18 10:23 BlinkA.map
-rw-r - r-- 1 arduino arduino 2994 Mar 18 10:23 BlinkA.symbol
-rw-r - r-- 1 arduino arduino 713 Mar 18 10:23 main.d
-rw-r - r-- 1 arduino arduino 6588 Mar 18 10:23 main.o
-rw-r - r-- 1 arduino arduino 2314 Mar 17 21:06 makefile
-rw-r - r-- 1 arduino arduino 249 Mar 17 21:06 objects.mk
-rw-r - r-- 1 arduino arduino 609 Mar 17 21:06 sources.mk
-rw-r - r-- 1 arduino arduino 761 Mar 17 21:06 subdir.mk
Actually, the
BlinkA.hex file is a ready-made firmware, which we will upload to the controller.
Firmware
The firmware command is simple:
/ usr / bin / avrdude -pm328p -carduino -P / dev / ttyUSB0 -b57600 -D -Uflash: w: BlinkA.hex: a
In this case, your controller type may differ, the -p parameter, the full list can be viewed in man.
You can add the firmware process to the makefile, in this case the firmware will occur at the end of each build. To do this, instead of the
ArduinoBuild.tgz file,
you should take
ArduinoBuildBuild.tgz .
How to check what worked
In the sketch above, there is not only a cheerful LED flashing, but also a display of messages to the serial port. In this case, using the output as a means of control is quite convenient, you can even screw the daemon, which will land all messages on the board in the syslog, but now I will not dwell on this.
To look into the serial port you will need minicom
$ minicom -b 9600 -D / dev / ttyUSB0
If everything works, then you will see a “pulse” in the form of a dot-dash '.–'
Instead of conclusion
In the next article I plan to uncover the issue of using external libraries, of which there are a lot at the moment.
Content
- Programming Arduino from Linux, gentoo-way, quick start
- Programming Arduino from the console, gentoo-way, nothing more
Used sources:
- playground.arduino.cc/linux/gentoo
- playground.arduino.cc/code/eclipse
- forums.gentoo.org/viewtopic-p-6971658.html