Wednesday, October 15, 2014

Xmega DFU Programming in Linux

I'm using elementary OS 0.2 and have an MT-DB-X4 development board from MattairTech with an ATxmega32A4U — so you may need to adjust the following commands to suit your particular setup.

Install dfu-programmer

First we need to install some prerequisites:

$> sudo aptitude install libusb-1.0-0 libusb-1.0-0-dev

Then, download and extract the source:

$> wget -qO-  "http://sourceforge.net/projects/dfu-programmer/files/dfu-programmer/0.7.0/dfu-programmer-0.7.0.tar.gz/download" | tar xvz

Now configure, make, make install:
#!/bin/bash

cd dfu-programmer-0.7.0
./configure --prefix=$HOME/.local  # This will install to your home
make                               # Compile
make install                       # Install

Now we can test it out. Plug in your device and run the following (change the device to match your chip):

$> sudo ~/.local/bin/dfu-programmer atxmega32a4u get
Bootloader Version: 0x04 (4)

Finally, we need to add ~/.local/bin to our PATH so we can just type dfu-programmer:

#!/bin/bash

# check to see if it's already in PATH
echo $PATH | grep -v "$HOME/\.local/bin" > /dev/null &&
cat << EOF >>~/.profile

# set PATH so it includes user's private .local/bin if it exists
if [ -d "\$HOME/.local/bin" ] ; then
    PATH="\$HOME/.local/bin:\$PATH"
fi
EOF

Remember, you need to logout and back in before the changes to your groups and .profile take effect.

Setup udev rules and permissions

When you first plug the device in, udev will only allow access to the root user by default. To change this we need to let udev know that we want to give access to the device to users in a certain group — plugdev in this case.

To start, check to see if you're already in the plugdev group:

$> groups
If not, you'll need to add yourself:
$> sudo usermod -a -G plugdev $USER

Next, we need to add a rules file to tell udev which group to add the device to. To get the device info, run lsusp to get the vendor and product IDs:

$> lsusb | grep Atmel
This should output something like the following:
Bus 005 Device 003: ID 03eb:2fe4 Atmel Corp.
Note the first and second parts of the ID

Now that we have the IDs, we can make the udev rule file and restart udev:

#!/bin/bash

sudo bash -c 'cat << EOF >/lib/udev/rules.d/12-atmel.rules
# atxmega32a4u with DFU Bootloader
SUBSYSTEM=="usb", ACTION=="add", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2fe4", GROUP="plugdev"
EOF
service udev restart'

Now just unplug and replug your device and you should be able to access it without root:

$> dfu-programmer atxmega32a4u get
Bootloader Version: 0x04 (4)

Tuesday, October 14, 2014

Installing HL2270-DW on Ubuntu / elementary Linux

Download and install these packages:

#!/bin/bash

wget --output-document=cupswrapperHL2270DW-2.0.4-2.i386.deb 'http://goo.gl/mw87o6' && wget --output-document=hl2270dwlpr-2.1.0-1.i386.deb 'http://goo.gl/8ixmvt'

sudo dpkg -i cupswrapperHL2270DW-2.0.4-2.i386.deb hl2270dwlpr-2.1.0-1.i386.deb

Follow the instructions from the Archwiki Page:

  • Open a web browser to http://localhost:631/
  • Click the Administration tab then click the Add Printer button. The username is "root" and the password is the root password of the user's computer.
  • Select IPP from the list.
  • In the 'Connection' field, type ipp://THE_PRINTER_IP/ipp/port1
  • In the next form, give the printer a unique name (no spaces and the name be must unique from any identical printers), and select "Brother" from the printer make field.
  • Select "Brother HL2270DW for CUPS (en)" from the list of drivers (it is not in numerical order and is toward the bottom of the list).
  • Configure the default options on the next page to your liking

Monday, October 13, 2014

Adjusting the system time in a VirtualBox Guest

This is only useful in a couple situations, but very handy if you need it. The guest OS must be unlocked, so you'll need to shut it down before you do this.
#/bin/bash

# First get the name of the vm you need to adjust:
VBoxManage list vms

# Then, adjust the time in milliseconds (neg nums go back in time):
VBoxManage modifyvm $MY_VM --biossystemtimeoffset -32000000000  # about a year

# To get it back on current time, just set it to zero:
VBoxManage modifyvm $MY_VM --biossystemtimeoffset 0

Wednesday, October 1, 2014

Setting Up the AVR Toolchain for Linux for AVR Development

Since I'm running an old version of Ubuntu (12.04), the AVR development tools in the repository are too old to handle the new ATxmega chips. So here's how to get up and running super quick with the AVR dev toolchain without reinstalling linux or compiling them yourself...
  1. Download the Atmel AVR Toolchain 3.4.x for Linux
  2. Extract it to either /usr/local/avr or ~/local/avr
    #!/bin/bash
    
    mkdir -p ~/local/avr
    cd ~/local/avr
    tar zxvf ~/Downloads/avr8-gnu-toolchain-*.tar.gz
    mv avr8-gnu-toolchain-* avr
    
  3. Add the path to your ~/.profile:
    # add avr toolchain to path (search ~/local/avr then /usr/local/avr)
    if [ -d "$HOME/local/avr/bin" ] ; then
        PATH="$HOME/local/avr/bin:$PATH"
    fi
    if [ -d "/usr/local/avr/bin" ] ; then
        PATH="/usr/local/avr/bin:$PATH"
    fi
    
    This will look for avr commands in your home first and then in /usr/local/avr, and only if they exist.
  4. Now logout, login and then check to see if its working:
    $ which avr-gcc
    This should output /home/$USER/local/avr/bin/avr-gcc, or wherever you put it.