📜 ⬆️ ⬇️

Programming Arduino from Linux, gentoo-way, quick start

Unfortunately, the information needed to connect the Arduino to a computer turned out to be scattered across sources in different languages. As you know, gentoo is a linux distribution with continuous development, in fact there’s no such thing as a “distribution”. Because of this, the solution to the problem found on the Internet may not work because the target system has a different set of packages and settings.

In addition, the authors, as a rule, give commands and solutions specific to a particular system at a specific point in time. Some time passes, product versions change, some paths and files change. This is an attempt not only to consolidate information, but also to present it in such a way that the information becomes obsolete as little as possible, and it was easy to modify the commands for your system. Perhaps this will be useful in other distributions.


For reference, the target system
Architecture amd64, kernel x86_64 3.7.10-gentoo
Installed stable packages of the latest versions.
At the ebay auction, the Arduino Pro Mini 328p 16MHz 5V board was purchased and a USB converter to it on an FTDI chip.

')

Install USB converter support into the kernel.


After connecting the converter to the USB port, we see the following:

 # tail / var / log / messages
 my-pc kernel: usb 6-1: new full-speed USB device number 2 using uhci_hcd
 my-pc kernel: usb 6-1: New USB device found, idVendor = 0403, idProduct = 6001
 my-pc kernel: usb 6-1: New USB device strings: Mfr = 1, Product = 2, SerialNumber = 3
 my-pc kernel: usb 6-1: Product: FT232R USB UART
 my-pc kernel: usb 6-1: Manufacturer: FTDI
 my-pc kernel: usb 6-1: SerialNumber: A900eYdz

This converter requires the ftdi_sio driver, I prefer not to add to the kernel what is not needed when booting the system, but to compile as a module. I do not use Genkernel, and you can compile the kernel in a way that is convenient for you.

 Device Drivers --->
     [*] USB support ---> 
         <M> USB Serial Converter support --->
             <M> USB FTDI Single Port Serial Driver

Compile the module and load:

 # make && make modules_install
 # modprobe ftdi_sio


 #tail -f / var / log / messages
 my-pc kernel: usbcore: registered new interface driver usbserial
 my-pc kernel: usbcore: registered new interface driver usbserial_generic
 my-pc kernel: usbserial: USB Serial support registered for generic
 my-pc kernel: usbcore: registered new interface driver ftdi_sio
 my-pc kernel: usbserial: USB Serial support registered for FTDI USB Serial Device
 my-pc kernel: ftdi_sio 6-1: 1.0: FTDI USB Serial Device converter detected
 my-pc kernel: usb 6-1: Detected FT232RL
 my-pc kernel: usb 6-1: Number of endpoints 2
 my-pc kernel: usb 6-1: Endpoint 1 MaxPacketSize 64
 my-pc kernel: usb 6-1: Endpoint 2 MaxPacketSize 64
 my-pc kernel: usb 6-1: Setting MaxPacketSize 64
 my-pc kernel: usb 6-1: FTDI USB Serial Device Converter now attached to ttyUSB0

We have an interface:

 # ls -l / dev / ttyUSB0
 crw-rw ---- 1 root uucp, 0 March 9 13:04 / dev / ttyUSB0

Pay attention to the rights. You must add your user to the uucp group.
  # usermod -aG uucp <user> 

If you use another converter, add its support to the kernel, otherwise everything should be the same.

Install or update rxtx package


  emerge dev-java / rxtx 

Only relevant for 64-bit systems:
At the time of writing, the stable version of the package is dev-java / rxtx-2.1.7.2-r3 , but the Arduino firmware will not work with it, you must install dev-java / rxtx-2.2_pre2 . Probably when a new stable version appears, the problem will be fixed.
  # echo = dev-java / rxtx-2.2_pre2 ~ amd64 >> /etc/portage/package.keywords 

Installation:
  emerge = dev-java / rxtx-2.2_pre2 


Installing the java virtual machine sun


You can use the SDK or JRE, if you do not know if you need the SDK, then you do not need it, and choose sun-jre-bin:
  # emerge dev-java / sun-jdk
     or
 # emerge dev-java / sun-jre-bin 

Due to license restrictions, you will have to manually download the corresponding source file and copy it into / usr / portage / distfiles. In addition, VM is distributed under a separate license, so you need to add it to the make.conf file:
  ACCEPT_LICENSE = "Oracle-BCLA-JavaSE" 


Make sure the correct VM is selected:
 # eselect java-vm list
 Available Java Virtual Machines:
   [1] sun-jre-bin-1.6 system-vm


Setting the toolchain environment to compile


  # emerge sys-devel / crossdev app-portage / layman 

Add a line to the /etc/make.conf file, if it does not already exist, and create a directory:
 # echo source /var/lib/layman/make.conf >> /etc/make.conf
 # mkdir -pv / usr / local / portage

Compile the toolchain, the default options correspond to stage4 and the use of stable packages:
  # crossdev -t avr 


Installing the IDE itself for programming


Since there is no stabilized version, then most likely it will not appear soon. So just install the latest version. You need to unlock the following packages by adding the following lines to the /etc/portage/package.keywords file:
 dev-embedded / arduino ~ amd64
 dev-embedded / uisp ~ amd64

You can add flags to install examples and documentation:
  echo dev-embedded / arduino doc examples >> /etc/portage/package.use 

Installation:
  # emerge arduino 


Run arduino


We select in the menu Service -> Board your version of Arduino and Service -> Serial port - the port that appeared after connecting the converter, usually / dev / ttyUSB0. The simplest Blink sketch was already loaded into my board by the manufacturer, so in order to check how everything works, I modified it: now the LED blinks alternately with a short and long flash:
/* Blink A Morse code Turns on an LED on adruino 'Dot - Dash - Pause' */ // Pin 13 has an LED connected on most Arduino boards. int led = 13; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); } void loop() { digitalWrite(led, HIGH); delay(200); digitalWrite(led, LOW); delay(200); digitalWrite(led, HIGH); delay(500); digitalWrite(led, LOW); delay(500); } 

Click the checkmark "Check" and the arrow "Download" and you will be happy. In fact, it may not be, because it is necessary to fix some more problems and about it below.

Problems:


If the item for selecting the serial port is deactivated, then you need to return to the beginning of the article and


If everything is checked, try to reboot the system, in one of the cases it helped me.

When compiling, an error is displayed:

 / usr / libexec / gcc / avr / ld: cannot open linker script file ldscripts / avr5.x: No such file or directory
 collect2: error: ld execution completed with return code 1

The reason is that the paths on which the toolchain is installed do not correspond to the paths where the arduino is looking for it. We find first where the desired file:
 # find / usr / -name avr5.x
 /usr/lib64/binutils/avr/2.23.1/ldscripts/avr5.x

then create a symbolic link:
  # ln -s /usr/lib64/binutils/avr/2.23.1/ldscripts / usr / avr / lib / ldscripts 


When compiling, an error is displayed:

 / usr / libexec / gcc / avr / ld: cannot find crtm328p.o: No such file or directory
 collect2: error: ld execution completed with return code 1

For your board, the file name may be different, but the solution is the same; you must create the corresponding symbolic link. We are looking for a file:
 # find / usr / -name crtm328p.o
 /usr/avr/lib/avr5/crtm328p.o

create link:
  # ln -s /usr/avr/lib/avr5/crtm328p.o / usr / avr / lib / 


UPDATE: 03/28/2013

There is a problem with the binutils version above 2.19

The problem is that all the above works, everything is compiled, assembled and loaded into the board without the slightest error. But the firmware does not work. In my case, the board just blinks with an LED, the second is on, it goes off for a second, that is, the classic Blink.

The solution is described here , the bug is registered on Gentoo's Bugzilla .

To solve the problem, reinstall the toolchain as follows:
crossdev -C avr
USE = "multilib -cxx" crossdev - b 2.19.1-r1 -S -s1 --target avr
USE = "multilib cxx" crossdev - b 2.19.1-r1 -S -s4 --target avr

Everything written above regarding incorrect paths remains valid.

UPDATE: 04/13/2013
For systems with a hardened kernel:

USE = "multilib -cxx nopie nossp -hardened -pic -openmp" crossdev - b 2.19.1-r1 -S -s1 --target avr
USE = "multilib cxx nopie nossp -hardened -pic -openmp" crossdev - b 2.19.1-r1 -S -s4 --target avr


Instead of conclusion


The board itself and the ways to use it interested me in the context of building the Smart Home system. Now I have a major overhaul of the apartment in full swing, and I can lay any cables, place any switching boxes, etc.

Content


  1. Programming Arduino from Linux, gentoo-way, quick start
  2. Programming Arduino from the console, gentoo-way, nothing more


Used sources


  1. playground.arduino.cc/linux/gentoo
  2. forums.gentoo.org/viewtopic-t-907860.html
  3. arduino.cc/en/Tutorial/blink
  4. forums.gentoo.org/viewtopic-t-834097.html
  5. bugs.gentoo.org/show_bug.cgi?id=147155
  6. lpig.wordpress.com/2011/09/28/arduino-and-gentoo
  7. en.gentoo-wiki.com/wiki/Crossdev
  8. bugs.gentoo.org/show_bug.cgi?id=378387

Source: https://habr.com/ru/post/172215/


All Articles