Making EEPROM non-volatile on YUN

The Arduino YUN is one of my favorite prototyping platforms for Wi-Fi connected microcontroller applications, but for unclear reasons the originators felt that by default the EEPROM contents should be lost when reprogramming code images.  Let’s fix that.

I typically use EEPROM to store board-specific identification, configuration, and calibration information — things I’d rather not lose when updating the code.  And if you only update using the USB connection you’ll be fine.  But leverage one of the great features of the YUN — updates over Wi-Fi within the IDE — and say goodbye to your EEPROM.

It’s an easy fix, though, and you just need to ssh into the board, change two bytes, and EEPROM will then be preserved.

You’ll need to have your YUN connected to Wi-Fi, and you’ll need the IP address.  To find it, either use the IDE to select the Wi-Fi connected port, or use a Bonjour browser such as this one for Windows.

Once you have an IP address. ssh into the board using a tool such as Putty.  Then navigate to /usr/bin and edit (I use vi) run-avrdude, changing the 0xD8 after hfuse to be 0xD0.  Save the file and your Wi-Fi code updates will no longer clear out your EEPROM settings.

root@MyYunName:/usr/bin# cd /usr/bin
root@MyYunName:/usr/bin# vi run-avrdude
#!/bin/sh
echo 1 > /sys/class/gpio/gpio21/value
avrdude  -q -q -c linuxgpio -C /etc/avrdude.conf -p m32u4 -U efuse:r:/tmp/efuse:d
read EFUSE < /tmp/efuse
rm -f /tmp/efuse
if [ “x$EFUSE” = “x203” ] # 203 = 0xCB
then
        avrdude -c linuxgpio -C /etc/avrdude.conf -p m32u4 -U lfuse:w:0xFF:m -U hfuse:w:0xD0:m -U efuse:w:0xCB:m -Uflash:w:$1:i $2
else
        avrdude -c linuxgpio -C /etc/avrdude.conf -p m32u4 -U lfuse:w:0xFF:m -U hfuse:w:0xD0:m -U efuse:w:0xFB:m -Uflash:w:$1:i $2
fi
echo 0 > /sys/class/gpio/gpio21/value
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: