EE 109 - Spring 2024 Introduction to Embedded Systems

Toolchain

The following is to help students install a workable AVR toolchain suite on the own computers, and to help resolve some issues that occur when using the software.

MacOS

Full instructions for installing an AVR toolchain for Mac is available on this web page.

It should not be necessary to also install Apple’s Xcode development software but if it is installed (or installed later) it should not affect the AVR toolchain.

Text Editors for the Mac

The following are links to text editors that Mac users may find useful.

Editing can also be done with editors that work within the command-line interface window. A couple command-line interface editors that are popular with programmers are “vim” and “emacs”. If you wish to learn to use “vim” there are several “vim” tutorials available on web sites. If you want to learn how to use the Emacs text editor, open a Terminal window and enter the command “emacs” by itself. This will start the editor and put some up an empty window. Then type “ESC x help-with-tutorial Return”. That’s an Escape, an ‘x’, then the string “help-with-tutorial” followed by a return key. This will load a tutorial file into the editor. Start reading it and follow the instructions.

Compiling results in “make: avr-gcc: No such file or directory”

This error message results from the “make” program not being able to find the “avr-gcc” program that compiles your program. To resolve this try following the steps below

  1. Type printenv PATH and see what directories will be searched to find programs like “avr-gcc” that are needed for the compiling. If you followed the steps in Lab 0 to install the toolchain, the list should be something like this.

     $ printenv PATH
     /usr/local/bin:/usr/local/avr/bin:/usr/bin:/bin:/usr/sbin:/sbin
    

    If the output does not contain both the “/usr/local/bin” and “/usr/local/avr/bin” directories, this means the PATH has been modified and will need to be fixed. Follow the instructions in Lab 0 section on “Adjust the PATH Variable” to fix it.

  2. Type ls /usr/local/avr/bin to see if the compiler files are present and accessible. This command should result in this.

     $ ls /usr/local/avr/bin
     avr-addr2line	avr-elfedit	avr-gcc-ranlib	avr-ld.bfd	avr-readelf
     avr-ar		avr-g++		avr-gcov	avr-man		avr-size
     avr-as		avr-gcc		avr-gcov-dump	avr-nm		avr-strings
     avr-c++		avr-gcc-7.3.0	avr-gcov-tool	avr-objcopy	avr-strip
     avr-c++filt	avr-gcc-ar	avr-gprof	avr-objdump
     avr-cpp		avr-gcc-nm	avr-ld		avr-ranlib
    

    This shows that all the compiler files are accessible in the directory we expect to have them. If instead you get this

     $ ls /usr/local/avr/bin
     ls: /usr/local/avr/bin: No such file or directory
    

    that means the files are not where they are supposed to be. This could be due to the Arduino application being deleted or moved to some locataion different from where it was during the initial installation.

    To solve this go back through the Lab 0 installation instruction and confirm that the Arduino application is in the correct location. Also check the link that was installed in Step 3 of the installion is still there.

Compiling results in “make: *** No rule to make target ‘file.o’

This error message is caused by the “make” program not being able to find the program file that it has been asked to compile. To solve this follow the steps below.

  1. Check that you are in the correct directory when typing the “make” command. For example, if you are working on Lab 4, make sure you are in the “ee109/lab4” directory when you type “make”.

  2. Check that the Makefile you edited to be correct for this lab assignment is the one in the directory you are in.

  3. In the Makefile, check that the name of the file(s) listed on the OBJECTS line are all correct. If you copied the Makefile from a previous lab, you need to change the file names to match what is being compiled for this lab.

  4. Check that the files that are named on the OBJECTS line are in the same directory the Makefile is in. For example, if the OBJECTS line lists “lab4.o” then the lab4.c file must be in the same directory as the Makefile.

Downloading Issues for Macs (and Linux)

The program that downloads the binary data to the Arduino (“avrdude”) needs to be told the name of the USB interface to use when contacting the Arduino. On Mac, Linux and other Unix-like systems, the USB interface is represented by a device file in the “/dev” directory, and the name of that file has to be listed on a line in the Makefile used to build and download the data. Unfortunately, the name of the device file can change depending on system’s hardware and the OS being used. So it’s usually necessary to look for it at least once to find the correct name. With the Arduino not plugged into the system, open a Terminal window and get a list of all the files in the /dev directory that start with “cu.usb”

    $ ls /dev/cu.usb*
    /dev/cu.usbserial-A90123ML
    $

In this case it found one file which must belong to some other device. Now plug the Arduino into a USB port and repeat the above search to find any differences in the list.

    $ ls /dev/cu.usb*
    /dev/cu.usbmodem141301		/dev/cu.usbserial-A90123ML
    $

Now there are two files, and the new one /dev/cu.usbmodem141301 must be the one for the Arduino. While this device name can be used as is, it’s very possible that the name will change the next time the Arduino is plugged in. On the Mac, the first part of the name /dev/cu.usbmodem remains the same but the characters after that (“141301”) may change. To avoid having to check the name each time and keep modifying the Makefile, replace the characters in the device name that may change with the ‘*’ wild card character so the name will match anything that starts with /dev/cu.usbmodem. As long as there is only one Arduino plugged into a USB port on the system this method should work fine.

Edit the “PROGRAMMER” line in the Makefile to have the correct device name just after the “-P”.

    PROGRAMMER = -c arduino -b 115200 -P /dev/cu.usbmodem*

Downloading results in “No AVR part has been specified” message

It was all working before but now when you do a “make flash” on a Mac, it responds with a message about “No AVR part has been specified” and then give a very long list of all the AVR microcontrollers that is should be able to program, including the ATmega328P that is on your Arduino.

$ make flash
avrdude -c arduino -b 115200 -P /dev/cu.usbmodem* -p atmega328p -U flash:w:main.hex:i
avrdude: No AVR part has been specified, use "-p Part"

Valid parts are:
  uc3a0512 = AT32UC3A0512
  c128     = AT90CAN128
  c32      = AT90CAN32
  c64      = AT90CAN64
  pwm2     = AT90PWM2
  pwm2b    = AT90PWM2B
  pwm3     = AT90PWM3
  pwm316   = AT90PWM316
  pwm3b    = AT90PWM3B
  1200     = AT90S1200
  2313     = AT90S2313
  2333     = AT90S2333
  2343     = AT90S2343
   .
   .
   .

From the Terminal window type the command below that lists what Arduino-like devices are connected to the computer.

$ ls /dev/cu.usbmodem*
/dev/cu.usbmodemFA1221		/dev/cu.usbmodemFA12421

In this case it shows that the system thinks there are TWO Arduino-like device connected to the computer, but you probably only have one connected. The bogus Arduino is probably something left over from when the computer went to sleep with the Arduino plugged in, and now it thinks it’s still there along with the real one. The easiest solution to this it to unplug the Arduino and restart the system. When the Mac reboots it will clean up things so the bogus Arduino is no longer there.

Other Mac Issues

The “Makefile” has to be named just that. It can’t be “Makefile.txt”. The Mac sometimes hides the extensions on files so the filename on the screen may be Makefile but it’s really Makefile.txt. The best way to fix this is from a Terminal windows. Find the files and do mv Makefile.txt Makefile.

Windows

Instructions for installing an AVR toolchain for Windows is available on this web page.

Windows Text Editors

The following are links to text editors that Windows users may find useful.

Other Windows Issues

The “Makefile” has to be named just that. It can’t be “Makefile.txt”. Windows sometimes hides the extensions on files so the filename on the screen may be Makefile but it’s really Makefile.txt. The best way to fix this is from a “Command Prompt” window. Find the files and do rename Makefile.txt Makefile.

Linux

The AVR-gcc software used for EE109 labs has been used successfully on both Debian and Ubuntu Linux system. It should also work when run as a virtual machine on a Mac or Windows system although there may be issues with getting the VM to recognize USB devices.

Installing the Software

Instructions for installing an AVR toolchain for Linux is available on this web page.

Linux Downloading Issues

Linux systems work about the same as Macs when it comes to finding the name of the device file associated with the USB interface to the Arduino. It seems to use the device /dev/ttyACM0 for the Arduino Unos, but this may not always be the case. See the information above in the Mac section for more details.

Protection Issues

Note: The following describes an issue with the file protection settings that may affect downloading to the Arduino. If the downloading works fine without having to make the changes shown below then these can be ignored.

When the Arduino is connected, the device file for the Arduino is created with file protection setting that make it necessary to be the root user in order to write files to it. You can run the “make flash” command as the root user, but if this is not preferred, a configuration file can be installed that causes the protection to be set lower to where a normal user can run “make flash”.

As the root user, create a text file with the following lines in it.

#Arduino UNO R3 from Arduino.cc
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0043", MODE:="0666"
#Arduino UNO R3 from Arduino.org
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2a03", ATTRS{idProduct}=="0043", MODE:="0666"

Save the file with a name like 42-arduino-uno-r3.rules. The leading “42” can be changed to any other number, it just determines the order that these configuration rules are applied on system boot up.

Copy the file to the directoery /etc/udev/rules.d, and then run the command “udevadm control --reload” to cause the system to reload the rules and make your new one take effect. Once that is done, when an Arduino is plugged in, it should have protections so “make flash” can be done.