Standalone AVR programmer for Attiny?

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
aspro648
 
Posts: 43
Joined: Sat Feb 16, 2008 3:06 pm

Standalone AVR programmer for Attiny?

Post by aspro648 »

I need to program 100 Attiny45 for a soft circuit workshop and would love to use the adaLoader to do it. I've got the hex file, the device signature, and the fuses figured out, but the I don't know about the "prot/lock", the "post program fuses", or the "fuse mask". Can anyone help me figure out how to modify the adaLoader:

image_t PROGMEM image_328 = {
{"attiny45.hex"},
{"attiny45"},
0x1e9206, /* Signature bytes for 328P = 0x950F */
{0x3F, 0xe2, 0xdf, 0xff}, // pre program fuses (prot/lock, low, high, ext)
{0x0F, 0x0, 0x0, 0x0}, // post program fuses
{0x3F, 0xFF, 0xFF, 0x07}, // fuse mask
4098, // size of chip flash in bytes
128, // size in bytes of flash page

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Standalone AVR programmer for Attiny?

Post by adafruit_support_mike »

AVR microcontrollers have a feature that lets you 'lock' the Flash memory so nothing can change it. There are two blocks of memory.. the general program memory and the bootloader memory.. each of which can be locked indivdually. You can also lock the low, high, and extended fuse bytes so those can't be changed either. Locking applies to both serial programming and high-voltage ICSP, and is controlled by yet another byte of memory.

The programmer can only write data to the chip if the lock bytes allow it, so the 'pre program' fuse values configure the chip to behave appropriately while it's being programmed. The 'post program' bytes are set after the data is written, putting the chip into the state appropriate for its life in the field.

The fuse mask is used by the programmer's verification routintes. It eliminates any bits that haven't been explicitly set or unset, so those won't interfere with the tests on the bits we actually care about.

To understand what's going on, start by walking through the loader sketch's `loop()` function: https://github.com/adafruit/Standalone- ... er.pde#L69 That will give you and idea of where the values in question are actually used.

Next, take a look at the `image` data structure defined in the Optiloader.h file: https://github.com/adafruit/Standalone- ... ader.h#L25 That defines field names for the values you posted above, and the code uses the field names.

Then take a look at the `programFuses()` and `verifyFuses()` functions in code.cpp: https://github.com/adafruit/Standalone- ... de.cpp#L72

Once you have a general idea of what the code is doing, you'll need to take a look at pages 147-150 of the ATtiny2/4/85 datasheet: http://www.atmel.com/images/atmel-2586- ... asheet.pdf That will tell you the device signature you need (which the loader sketch requires), and the appropriate values for all the protection and fuse bits.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”