Skip to content

All In Tech

Providing IT Tutorials, Scripts, and Much More!!

Archive

Category: Ubuntu

Here is a quick and dirty tutorial for writing data and setting fuse bits on an AVR microcontroler using Ubuntu. All details in this post are related to the Atmega8-16PU, for other versions you should relate to the data sheets for the relevant specifications. First we need to get the necessary development tools:

# sudo  apt-get install gcc-avr avr-libc gdb-avr avrdude

Now we need to create a cable to go between the LPT port on your PC and the AVR micro-controller:

DB25 Male AVR
Pin 1 SCK
Pin 2 MOSI
Pin 11 MISO
Pin 16 RESET
Pin 21 GND

*Warning: The data pins (1,2) should have a 1k resister in line, this is to stop you from killing either your LPT port, AVR, or both. It will work without just make sure you have it wired 100% correct. d9-f1 atmega8-1 Run the following to test the connection:

# sudo avrdude -p m8 -P /dev/parport0 -c dapa

You should receive back:

avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9307
avrdude: safemode: Fuses OK
avrdude done.  Thank you.

If you receive:

avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

Then something is wrong and you should check all your connections. Now to Test out some code you can try this example:

/*
 * blink.c
 */

#include <avr/io.h>
#include <util/delay.h>
#define LED PD4

int main(void) {
  // define pd4 as output
  DDRD |= (1 << LED);
  while (1) {
    PORTD |= (1 << LED);    // switch on
    _delay_ms(1000);
    PORTD &= ~(1 << LED);    // switch off
    _delay_ms(1000);
  }
return 0;
}

Save as blink.c Now in the same directory save the following Makefile:

MCU=atmega8
AVRDUDEMCU=m8
CC=/usr/bin/avr-gcc
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=$(MCU)
OBJ2HEX=/usr/bin/avr-objcopy
AVRDUDE=/usr/bin/avrdude
TARGET=blink

program : $(TARGET).hex
	$(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/parport0 -c dapa -U flash:w:$(TARGET).hex

%.obj : %.o
	$(CC) $(CFLAGS) $< -o $@

%.hex : %.obj
	$(OBJ2HEX) -R .eeprom -O ihex $< $@

clean :
	rm -f *.hex *.obj *.o

So now using the makefile we are going to create a .hex file of the c code above and write it onto our chip:

# sudo make

sucessful output:

/usr/bin/avr-gcc -g -Os -Wall -mcall-prologues -mmcu=atmega8   -c -o blink.o blink.c
/usr/bin/avr-gcc -g -Os -Wall -mcall-prologues -mmcu=atmega8 blink.o -o blink.obj
/usr/bin/avr-objcopy -R .eeprom -O ihex blink.obj blink.hex
/usr/bin/avrdude -p m8 -P /dev/parport0 -c dapa -U flash:w:blink.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9307
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "blink.hex"
avrdude: input file blink.hex auto detected as Intel Hex
avrdude: writing flash (138 bytes):
Writing | ################################################## | 100% 0.05s
avrdude: 138 bytes of flash written
avrdude: verifying flash memory against blink.hex:
avrdude: load data flash data from input file blink.hex:
avrdude: input file blink.hex auto detected as Intel Hex
avrdude: input file blink.hex contains 138 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.03s
avrdude: verifying ...
avrdude: 138 bytes of flash verified
avrdude: safemode: Fuses OK
avrdude done.  Thank you.

rm blink.obj blink.o

Attach a LED to PD4 with a resister in line and the LED should light up and flash. Written by: Jason Smith

3 people like this post.

Distributive computing has been around for a long time and there are many different ways of doing it. Today i will be looking at the Message Passing Interface (MPI) standard and will be using the MPICH2 sources provided from http://www.mcs.anl.gov/research/projects/mpich2/

On such a cluster you can run any application that has been designed for MPI, for some benchmarks i ran John The Ripper. (you can get the MPI version here: http://www.bindshell.net/tools/johntheripper/john-1.7.3.1-all-2-mpi8.tar.gz)

Results of the benchmark

No MPI:

Benchmarking: Traditional DES [128/128 BS SSE2]… DONE
Many salts: 1986K c/s real, 1982K c/s virtual

MPI (4 cores over 2 machines)

Benchmarking: Traditional DES [128/128 BS SSE2]… DONE
Many salts: 5151K c/s real, 5151K c/s virtual

As you can see its about a 3 fold improvement.

I have decided to go with Ubuntu for the base system as I’m most familiar with this distro.

Configure the Head Node:

Download the necessary packages

sudo apt-get install nfs-kernel-server openssh-server build-essential

Create the share for NFS

sudo mkdir /mirror
sudo mkdir /mirror/mpiu

run the following to add “/mirror *(rw,sync)” to /etc/exports

echo /mirror *(rw,sync) >> /etc/exports

restart NFS

sudo /etc/init.d/nfs-kernel-server restart

Create a user for the cluster

sudo useradd -d /mirror/mpiu
sudo passwd mpiu
su mpiu
sudo chown mpiu /mirror

Now we setup SSH

ssh-keygen -t dsa

*Don’t set a passphrase

Add the key to Authoirzed keys

cd ~/.ssh

cat id_dsa.pub >> authorized_keys

Download MPICH2

wget http://www.mcs.anl.gov/research/projects/mpich2/downloads/tarballs/1.0.7/mpich2-1.0.7.tar.gz

mkdir /mirror/mpich2

tar -xvf mpich2-1.0.7.tar.gz

cd mpich2-1.0.7

./configure --prefix=/mirror/mpich2

make

sudo make install

Now add the following lines to /mirror/mpiu/.bashrc

export PATH=/mirror/mpich2/bin:$PATH

export PATH

LD_LIBRARY_PATH="/mirror/mpich2/lib:$LD_LIBRARY_PATH"

export LD_LIBRARY_PATH

Now edit /etc/environment and add the following

/mirror/mpich2/bin

Add the hostnames of the machines which are in the cluster into ~/mpd.hosts (currently there will be none if this is your server)

And then run the following commands

 echo secretword=password >> ~/.mpd.conf
sudo chmod 600 ~/.mpd.conf

And there you go, a MPI server running on ubuntu 8.04

A Ubuntu MPI Cluster (PART 2 – client setup) (coming soon!)

7 people like this post.

While setting up my latest server i encounter an issue i have never come across before, in my VMware guest machine the time was flying very quickly into the future. Could this be time travel?

Unfortunately not, its caused by the CPU frequency scaling on a multi-core processor and by default VMware doesn’t quite no how to deal with it yet.

To rectify this issue you have to set your CPU’s max frequency into /etc/vmware/config.

To find your cpu’s frequency you have two options, the first:

$ cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq 

2000000

The second:

$ cpufreq-info

cpufrequtils 002: cpufreq-info (C) Dominik Brodowski 2004-2006

Report errors and bugs to linux@brodo.de, please.

analyzing CPU 0:

  driver: centrino

  CPUs which need to switch frequency at the same time: 0

  hardware limits: 1000 MHz - 2.00 GHz

  available frequency steps: 2.00 GHz, 1.33 GHz, 1000 MHz

  available cpufreq governors: userspace, powersave, ondemand, conservative, performance

  current policy: frequency should be within 1000 MHz and 2.00 GHz.

                  The governor "ondemand" may decide which speed to use

                  within this range.

  current CPU frequency is 1000 MHz.

analyzing CPU 1:

  driver: centrino

  CPUs which need to switch frequency at the same time: 1

  hardware limits: 1000 MHz - 2.00 GHz

  available frequency steps: 2.00 GHz, 1.33 GHz, 1000 MHz

  available cpufreq governors: userspace, powersave, ondemand, conservative, performance

  current policy: frequency should be within 1000 MHz and 2.00 GHz.

                  The governor "ondemand" may decide which speed to use

                  within this range.

  current CPU frequency is 1000 MHz.

As my MAX CPU frequency is 2.00GHz i added these lines to /etc/vmware/config

host.cpukHz = 2000000

host.noTSC = TRUE

ptsc.noTSC = TRUE

All that is left to do now is restart VMware and test the results.

The above commands where performed on:

Host: VMware Server 1.5.0 running on a 2.6 kernel

Guest: Ubuntu 8.04 Hardy Heron

Please post any comments or suggestions.

Be the first to like.