Atmega32 usbasploader-3

December 15, 2013 § Leave a comment

Description about the hardware part:

DSC00629done

I’m sorry i can’t give you the exact circuit diagram because i have made this project before one year and that was a trial and error based project so no exact schematic had been made. After having success on this project, i was so excited that i had no time to draw a complete circuit diagram. But i will give you some clue and results. The main theory is just combine the usbasploader(here) hardware with my pinouts.

As written in the code,

#define USB_CFG_IOPORTNAME D
#define USB_CFG_DMINUS_BIT 1
#define USB_CFG_DPLUS_BIT  2

That means the D+ pin is PD2
And the D- pin is PD1 of the Atmega32 microcontroller.

And the board is made on a double layer veroboard ūüėÄ . Actually it is not a double layer veroboard. It is a bit made of two different slices of veroboard. And i have cut a big hole inside of the top layer to insert the crystal and other parts. I have cut it for my fun only, it’s not essential. ¬†If you can put the crystal and other things on the reverse side of the top layer, then it will be perfect. I have mounted the whole microcontroller circuit on the top layer and added the essential parts to able to run it without the bottom layer.

DSC00617done DSC00619done

The bottom layer has the USB voltage driver/dropper circuit from vusb with a couple of zener diodes, some resistors, a USB-B mini port and some resistors. I mean the USB-B female port is very much essential here. We know that the 4th pin of the USB-B mini port is unused. And we also know that we need a jumper for usbasploader. So,I have disassembled the USB data cable and shorted the 4th pin with the 5th pin or easily saying that 4th pin to ground and the 4th pin of the female jack of the USB-B mini on the circuit board is connected with PD0 as says the following line of the configuration code.

#define JUMPER_BIT 0

So, whenever you inserted the cable, after pressing the reset button, the microcontroller automatically goes to programming mode. Isn’t the feature beautiful and essential? And after removing the cable, the microcontroller always goes to run mode.

DSC00626done DSC00627done DSC00631done DSC00625done DSC00624done

Advertisements

Atmega32 usbasploader-2

December 14, 2013 § 1 Comment

Now I will describe the bootloader software part.

I have faced and i know that almost everyone faces problem with the boot-loader. The boot-loader/hardware miss-configuration makes it impossible to work and falls us into frustration. It takes 3 months for me to have a success.

I have compiled these with WINAVR in windows xp/7 successfully.

Download the Winavr from sourceforge, install it. Download the usbasp package, unzip it.

Then you only need to make the following files. The files will be exactly look like-

1. bootloaderconfig.h

</pre>
/* Name: bootloaderconfig.h
 * Project: USBaspLoader
 * Author: Christian Starkjohann
 * Creation Date: 2007-12-08
 * Tabsize: 4
 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
 * License: GNU GPL v2 (see License.txt)
 * This Revision: $Id: bootloaderconfig.h 729 2009-03-20 09:03:58Z cs $
 */

#ifndef __bootloaderconfig_h_included__
#define __bootloaderconfig_h_included__

/*
General Description:
This file (together with some settings in Makefile) configures the boot loader
according to the hardware.

This file contains (besides the hardware configuration normally found in
usbconfig.h) two functions or macros: bootLoaderInit() and
bootLoaderCondition(). Whether you implement them as macros or as static
inline functions is up to you, decide based on code size and convenience.

bootLoaderInit() is called as one of the first actions after reset. It should
be a minimum initialization of the hardware so that the boot loader condition
can be read. This will usually consist of activating a pull-up resistor for an
external jumper which selects boot loader mode.

bootLoaderCondition() is called immediately after initialization and in each
main loop iteration. If it returns TRUE, the boot loader will be active. If it
returns FALSE, the boot loader jumps to address 0 (the loaded application)
immediately.

For compatibility with Thomas Fischl's avrusbboot, we also support the macro
names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If
these macros are defined, the boot loader usees them.
*/

/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME D
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
 */
#define USB_CFG_DMINUS_BIT 1
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
 */
#define USB_CFG_DPLUS_BIT 2
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
 * This may be any bit in the port. Please note that D+ must also be connected
 * to interrupt pin INT0!
 */
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
 * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
 * deviation from the nominal frequency. All other rates require a precision
 * of 2000 ppm and thus a crystal!
 * Default if not specified: 12 MHz
 */

/* ----------------------- Optional Hardware Config ------------------------ */

/* #define USB_CFG_PULLUP_IOPORTNAME D */
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
 * V+, you can connect and disconnect the device from firmware by calling
 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
 * This constant defines the port on which the pullup resistor is connected.
 */
/* #define USB_CFG_PULLUP_BIT 4 */
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
 * above) where the 1.5k pullup resistor is connected. See description
 * above for details.
 */

/* ------------------------------------------------------------------------- */
/* ---------------------- feature / code size options ---------------------- */
/* ------------------------------------------------------------------------- */

#define HAVE_EEPROM_PAGED_ACCESS 1
/* If HAVE_EEPROM_PAGED_ACCESS is defined to 1, page mode access to EEPROM is
 * compiled in. Whether page mode or byte mode access is used by AVRDUDE
 * depends on the target device. Page mode is only used if the device supports
 * it, e.g. for the ATMega88, 168 etc. You can save quite a bit of memory by
 * disabling page mode EEPROM access. Costs ~ 138 bytes.
 */
#define HAVE_EEPROM_BYTE_ACCESS 1
/* If HAVE_EEPROM_BYTE_ACCESS is defined to 1, byte mode access to EEPROM is
 * compiled in. Byte mode is only used if the device (as identified by its
 * signature) does not support page mode for EEPROM. It is required for
 * accessing the EEPROM on the ATMega8. Costs ~54 bytes.
 */
#define BOOTLOADER_CAN_EXIT 1
/* If this macro is defined to 1, the boot loader will exit shortly after the
 * programmer closes the connection to the device. Costs ~36 bytes.
 */
#define HAVE_CHIP_ERASE 0
/* If this macro is defined to 1, the boot loader implements the Chip Erase
 * ISP command. Otherwise pages are erased on demand before they are written.
 */
//#define SIGNATURE_BYTES 0x1e, 0x93, 0x07, 0 /* ATMega8 */
/* This macro defines the signature bytes returned by the emulated USBasp to
 * the programmer software. They should match the actual device at least in
 * memory size and features. If you don't define this, values for ATMega8,
 * ATMega88, ATMega168 and ATMega328 are guessed correctly.
 */

/* The following block guesses feature options so that the resulting code
 * should fit into 2k bytes boot block with the given device and clock rate.
 * Activate by passing "-DUSE_AUTOCONFIG=1" to the compiler.
 * This requires gcc 3.4.6 for small enough code size!
 */
#if USE_AUTOCONFIG
# undef HAVE_EEPROM_PAGED_ACCESS
# define HAVE_EEPROM_PAGED_ACCESS (USB_CFG_CLOCK_KHZ >= 16000)
# undef HAVE_EEPROM_BYTE_ACCESS
# define HAVE_EEPROM_BYTE_ACCESS 1
# undef BOOTLOADER_CAN_EXIT
# define BOOTLOADER_CAN_EXIT 1
# undef SIGNATURE_BYTES
#endif /* USE_AUTOCONFIG */

/* ------------------------------------------------------------------------- */

/* Example configuration: Port D bit 3 is connected to a jumper which ties
 * this pin to GND if the boot loader is requested. Initialization allows
 * several clock cycles for the input voltage to stabilize before
 * bootLoaderCondition() samples the value.
 * We use a function for bootLoaderInit() for convenience and a macro for
 * bootLoaderCondition() for efficiency.
 */

#ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */

#define JUMPER_BIT 0 /* jumper is connected to this bit in port D, active low */

#ifndef MCUCSR /* compatibility between ATMega8 and ATMega88 */
# define MCUCSR MCUSR
#endif

static inline void bootLoaderInit(void)
{
 PORTD |= (1 << JUMPER_BIT); /* activate pull-up */
 if(!(MCUCSR & (1 << EXTRF))) /* If this was not an external reset, ignore */
 leaveBootloader();
 MCUCSR = 0; /* clear all reset flags for next time */
}

static inline void bootLoaderExit(void)
{
 PORTD = 0; /* undo bootLoaderInit() changes */
}

#define bootLoaderCondition() ((PIND & (1 << JUMPER_BIT)) == 0)

#endif /* __ASSEMBLER__ */

/* ------------------------------------------------------------------------- */

#endif /* __bootloader_h_included__ */
<pre>

2. Makefile

</pre>
/* Name: bootloaderconfig.h
 * Project: USBaspLoader
 * Author: Christian Starkjohann
 * Creation Date: 2007-12-08
 * Tabsize: 4
 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
 * License: GNU GPL v2 (see License.txt)
 * This Revision: $Id: bootloaderconfig.h 729 2009-03-20 09:03:58Z cs $
 */

#ifndef __bootloaderconfig_h_included__
#define __bootloaderconfig_h_included__

/*
General Description:
This file (together with some settings in Makefile) configures the boot loader
according to the hardware.

This file contains (besides the hardware configuration normally found in
usbconfig.h) two functions or macros: bootLoaderInit() and
bootLoaderCondition(). Whether you implement them as macros or as static
inline functions is up to you, decide based on code size and convenience.

bootLoaderInit() is called as one of the first actions after reset. It should
be a minimum initialization of the hardware so that the boot loader condition
can be read. This will usually consist of activating a pull-up resistor for an
external jumper which selects boot loader mode.

bootLoaderCondition() is called immediately after initialization and in each
main loop iteration. If it returns TRUE, the boot loader will be active. If it
returns FALSE, the boot loader jumps to address 0 (the loaded application)
immediately.

For compatibility with Thomas Fischl's avrusbboot, we also support the macro
names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If
these macros are defined, the boot loader usees them.
*/

/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME D
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
 */
#define USB_CFG_DMINUS_BIT 1
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
 */
#define USB_CFG_DPLUS_BIT 2
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
 * This may be any bit in the port. Please note that D+ must also be connected
 * to interrupt pin INT0!
 */
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
 * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
 * deviation from the nominal frequency. All other rates require a precision
 * of 2000 ppm and thus a crystal!
 * Default if not specified: 12 MHz
 */

/* ----------------------- Optional Hardware Config ------------------------ */

/* #define USB_CFG_PULLUP_IOPORTNAME D */
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
 * V+, you can connect and disconnect the device from firmware by calling
 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
 * This constant defines the port on which the pullup resistor is connected.
 */
/* #define USB_CFG_PULLUP_BIT 4 */
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
 * above) where the 1.5k pullup resistor is connected. See description
 * above for details.
 */

/* ------------------------------------------------------------------------- */
/* ---------------------- feature / code size options ---------------------- */
/* ------------------------------------------------------------------------- */

#define HAVE_EEPROM_PAGED_ACCESS 1
/* If HAVE_EEPROM_PAGED_ACCESS is defined to 1, page mode access to EEPROM is
 * compiled in. Whether page mode or byte mode access is used by AVRDUDE
 * depends on the target device. Page mode is only used if the device supports
 * it, e.g. for the ATMega88, 168 etc. You can save quite a bit of memory by
 * disabling page mode EEPROM access. Costs ~ 138 bytes.
 */
#define HAVE_EEPROM_BYTE_ACCESS 1
/* If HAVE_EEPROM_BYTE_ACCESS is defined to 1, byte mode access to EEPROM is
 * compiled in. Byte mode is only used if the device (as identified by its
 * signature) does not support page mode for EEPROM. It is required for
 * accessing the EEPROM on the ATMega8. Costs ~54 bytes.
 */
#define BOOTLOADER_CAN_EXIT 1
/* If this macro is defined to 1, the boot loader will exit shortly after the
 * programmer closes the connection to the device. Costs ~36 bytes.
 */
#define HAVE_CHIP_ERASE 0
/* If this macro is defined to 1, the boot loader implements the Chip Erase
 * ISP command. Otherwise pages are erased on demand before they are written.
 */
//#define SIGNATURE_BYTES 0x1e, 0x93, 0x07, 0 /* ATMega8 */
/* This macro defines the signature bytes returned by the emulated USBasp to
 * the programmer software. They should match the actual device at least in
 * memory size and features. If you don't define this, values for ATMega8,
 * ATMega88, ATMega168 and ATMega328 are guessed correctly.
 */

/* The following block guesses feature options so that the resulting code
 * should fit into 2k bytes boot block with the given device and clock rate.
 * Activate by passing "-DUSE_AUTOCONFIG=1" to the compiler.
 * This requires gcc 3.4.6 for small enough code size!
 */
#if USE_AUTOCONFIG
# undef HAVE_EEPROM_PAGED_ACCESS
# define HAVE_EEPROM_PAGED_ACCESS (USB_CFG_CLOCK_KHZ >= 16000)
# undef HAVE_EEPROM_BYTE_ACCESS
# define HAVE_EEPROM_BYTE_ACCESS 1
# undef BOOTLOADER_CAN_EXIT
# define BOOTLOADER_CAN_EXIT 1
# undef SIGNATURE_BYTES
#endif /* USE_AUTOCONFIG */

/* ------------------------------------------------------------------------- */

/* Example configuration: Port D bit 3 is connected to a jumper which ties
 * this pin to GND if the boot loader is requested. Initialization allows
 * several clock cycles for the input voltage to stabilize before
 * bootLoaderCondition() samples the value.
 * We use a function for bootLoaderInit() for convenience and a macro for
 * bootLoaderCondition() for efficiency.
 */

#ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */

#define JUMPER_BIT 0 /* jumper is connected to this bit in port D, active low */

#ifndef MCUCSR /* compatibility between ATMega8 and ATMega88 */
# define MCUCSR MCUSR
#endif

static inline void bootLoaderInit(void)
{
 PORTD |= (1 << JUMPER_BIT); /* activate pull-up */
 if(!(MCUCSR & (1 << EXTRF))) /* If this was not an external reset, ignore */
 leaveBootloader();
 MCUCSR = 0; /* clear all reset flags for next time */
}

static inline void bootLoaderExit(void)
{
 PORTD = 0; /* undo bootLoaderInit() changes */
}

#define bootLoaderCondition() ((PIND & (1 << JUMPER_BIT)) == 0)

#endif /* __ASSEMBLER__ */

/* ------------------------------------------------------------------------- */

#endif /* __bootloader_h_included__ */
<pre>

Then run command prompt, cd to the folder where you unzipped, then type the commands and press enter.
1. To Compile And Upload To Microcontroller-
make flash
2. To Set Fusebits
make fuse
3. To Set Lockbits.
make lock
Issue these commands and enjoy. I will come later with the circuit diagram. But it’s already written in the codes. ūüėÄ

Ok, And for better help(also less explaining for me :p ) I uploaded complete package zipped, Click here to download it. The .bat scripts helps to avoid the damn command prompt.  You can play with them but be careful(they can blow your PC off :p ).

Atmega32 usbasploader

July 31, 2012 § 1 Comment

I just finished the project of atmega32 and usbasploader with arduino 0022. After one week of¬†embarrassing¬†try and fail,¬†try and fail at last i have¬†succeeded¬†. i wanna tell details about later till then………

ok at last, i’ve some time lets roll………………

At first i have built a circuit of usbasploader with atmega 8.

Source

http://www.obdev.at/products/vusb/usbasploader.html

it needs winavr and avrdude to compile/flash the microcontroller

from here : winavr.sourceforge.net/
i’ve built usbasp programmer to program the microcontroller but that is another long story……………………

It takes the higher 2kb of memory for bootloader. I have 6kb of memory to run all of my arduino projects. I was happy with it. I have tested the ir remote, ds18b20, hd74480, analog, digital pins, 3310 lcd projects successfully within the 6kb of memory  but suddenly i ran out of memory when i have wanted to run sd card or other higher complex projects.

The atmega 328 or 168 is not available to my country so, i want to use atmega 16 or 32. But there is a problem they have not compiled or give support(pin out, fusebit settings) for this type of microcontrollers.

So, it seems that  i am alone on my own way.  I have already bricked 7 of atmega8 by trying usbasp and usbasploader and that is another tragic story. I have totally bricked 9 of them and sucessfully recovered 2 of them by avr fusebit doctor from here http://diy.elektroda.eu/atmega-fusebit-doctor-hvpp/?lang=en special thanks to manekinen for helping us with his projects.

Ok , moreabout this comes later, till then………….

Where Am I?

You are currently browsing the USBasploader category at khairulhasanmd.

%d bloggers like this: