Sunday, April 21, 2013

DIY Arduino Uno on Breadboard and programmed with BusPirate

This is based on the blog on Programming AVR with AVR-GCC and AVR Programming with BusPirate

Instead of pin 13 (PB5) for LED blinking test, I use pin 8 (PB0) because PB5 is shared with SCK which we're going to use for ICSP (connected to BusPirate's SCK)

To test whether avrdude and BusPirate can communicate as well as to see if the chip is readable (so the connections are correct):

bash-4.2$ avrdude -c buspirate -P /dev/ttyUSB0 -p atmega328p -v

avrdude: Version 5.10, compiled on Mar  2 2011 at 21:55:09
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude/avrdude.conf"
         User configuration file is "/home/mlutfi/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : buspirate
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : BusPirate
         Description     : The Bus Pirate

Detecting BusPirate...
avrdude: buspirate_readline(): #
avrdude: buspirate_readline(): RESET
avrdude: buspirate_readline():
** 
avrdude: buspirate_readline(): Bus Pirate v3a
**  Bus Pirate v3a
avrdude: buspirate_readline(): Firmware v5.10 (r559)  Bootloader v4.4
**  Firmware v5.10 (r559)  Bootloader v4.4
avrdude: buspirate_readline(): DEVID:0x0447 REVID:0x3046 (24FJ64GA002 B8)
**  DEVID:0x0447 REVID:0x3046 (24FJ64GA002 B8)
avrdude: buspirate_readline(): http://dangerousprototypes.com
**  http://dangerousprototypes.com
avrdude: buspirate_readline(): HiZ>
**
BusPirate: using BINARY mode
BusPirate binmode version: 1
BusPirate SPI version: 1
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as 7

avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as 7
avrdude: safemode: Fuses OK
BusPirate is back in the text mode

avrdude done.  Thank you.

bash-4.2$




Now we can deploy this command into Makefile I have posted before.
For example, the following lines can be inserted at the very bottom of Makefie:


install: $(PRG).hex
    avrdude -c buspirate -P /dev/ttyUSB0 -p $(MCU_TARGET) -v -U flash:w:$(PRG).hex

To compile:

bash-4.2$ make
avr-objdump -h -S blink.elf > blink.lst
avr-objcopy -j .text -j .data -O binary blink.elf blink.bin
avr-objcopy -j .text -j .data -O srec blink.elf blink.srec
avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O ihex blink.elf blink_eeprom.hex \
|| { echo empty blink_eeprom.hex not generated; exit 0; }
avr-objcopy: --change-section-lma .eeprom=0x0000000000000000 never used
avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O binary blink.elf blink_eeprom.bin \
|| { echo empty blink_eeprom.bin not generated; exit 0; }
avr-objcopy: --change-section-lma .eeprom=0x0000000000000000 never used
avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O srec blink.elf blink_eeprom.srec \
|| { echo empty blink_eeprom.srec not generated; exit 0; }
avr-objcopy: --change-section-lma .eeprom=0x0000000000000000 never used
bash-4.2$


To install/program it to the target (ATMega328P on the breadboard):

bash-4.2$ make install
avr-c++ -c -g -Wall -O2 -mmcu=atmega328p -D__AVR_ATmega328P__ -DF_CPU=16000000UL -I /home/mlutfi/src/arduino/include -I /home/mlutfi/src/arduino/include/arduino -I /home/mlutfi/src/arduino/include/variants -I /home/mlutfi/src/arduino/include/variants/standard -I /opt/arduino-1.0.4/libraries/LiquidCrystal  blink.cpp -o blink.o
***********************************************************
Compiling blink.o
***********************************************************
avr-c++ -g -Wall -O2 -mmcu=atmega328p -D__AVR_ATmega328P__ -DF_CPU=16000000UL -I /home/mlutfi/src/arduino/include -I /home/mlutfi/src/arduino/include/arduino -I /home/mlutfi/src/arduino/include/variants -I /home/mlutfi/src/arduino/include/variants/standard -I /opt/arduino-1.0.4/libraries/LiquidCrystal  -Wl,-Map,blink.map -o blink.elf -L /home/mlutfi/src/arduino/include -lm -lc  blink.o /home/mlutfi/src/arduino/include/libatmega328p.a
avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex
avrdude -c buspirate -P /dev/ttyUSB0 -p atmega328p -v -U flash:w:blink.hex

avrdude: Version 5.11, compiled on Sep  9 2011 at 16:00:41
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/local/etc/avrdude.conf"
         User configuration file is "/home/mlutfi/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : buspirate
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : BusPirate
         Description     : The Bus Pirate

Detecting BusPirate...
avrdude: buspirate_readline(): #
avrdude: buspirate_readline(): RESET
avrdude: buspirate_readline():
** 
avrdude: buspirate_readline(): Bus Pirate v3a
**  Bus Pirate v3a
avrdude: buspirate_readline(): Firmware v5.10 (r559)  Bootloader v4.4
**  Firmware v5.10 (r559)  Bootloader v4.4
avrdude: buspirate_readline(): DEVID:0x0447 REVID:0x3046 (24FJ64GA002 B8)
**  DEVID:0x0447 REVID:0x3046 (24FJ64GA002 B8)
avrdude: buspirate_readline(): http://dangerousprototypes.com
**  http://dangerousprototypes.com
avrdude: buspirate_readline(): HiZ>
**
BusPirate: using BINARY mode
BusPirate binmode version: 1
BusPirate SPI version: 1
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as 7
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 (1444 bytes):

Writing | ################################################## | 100% 4.46s

avrdude: 1444 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 1444 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 4.37s

avrdude: verifying ...
avrdude: 1444 bytes of flash verified

avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as 7
avrdude: safemode: Fuses OK
BusPirate is back in the text mode

avrdude done.  Thank you.

bash-4.2$

The code "blink.cpp" itself as below:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.


  According to UNO schematic:
    pin 13 = PB5 (19)
    pin 12 = PB4 (18)
    pin 11 = PB3 (17)
    pin 10 = PB2 (16)
    pin 9 = PB1 (15)
    pin 8 = PB0 (14)
    pin 7 = PD7 (13)
    pin 6 = PD6 (12)
    pin 5 = PD5 (11)
    pin 4 = PD4 (6)
    pin 3 = PD3 (5)
    pin 2 = PD2 (4)
    pin 1 = PD1 (3)
    pin 0 = PD0 (2)
 */
#include <arduino/Arduino.h>

#define LED     8

void setup() {               
  // initialize the digital pin as an output.
  // Pin 13 (has an LED connected on most Arduino boards:
  // but myproto on breadboand uses PB0 (14) = pin 8 as LED output
  pinMode(LED, OUTPUT);    
}

void loop() {
  digitalWrite(LED, HIGH);   // set the LED on
  delay(25);              // wait for a second
  digitalWrite(LED, LOW);    // set the LED off
  delay(25);              // wait for a second
}

No comments:

Post a Comment