I had lunch with my pal Wayne Yamaguchi last week, who has several products he makes based on Atmel AVR parts. Wayne mentioned that he has found products where someone has forgotten to burn the fuse and lock bits, and he could read the code inside the part. He admits that it is easy to get confused if you are switching between developing some code for one project and then burning some chips for products that are shipping. You have to click down a few menus to insure the bits get set. Instead he says that he puts the instructions to set the fuse and lock bits in his source code, and then he can program the parts with the .ELF file which will set the bits in the parts.
So Wayne dropped me a note and said:
Here’s some info on embedding fuse settings in the source code.
// .low = (unsigned char)(FUSE_CKDIV8 & FUSE_SUT0 & FUSE_CKSEL3 &
FUSE_CKSEL2 & FUSE_CKSEL0),
// .low = (unsigned char)(FUSE_CKDIV8 & FUSE_SUT0 & FUSE_SUT1 &
FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0),
.low = LFUSE_DEFAULT,
.high = HFUSE_DEFAULT,
// .high = (unsigned char)(FUSE_BODLEVEL0 & FUSE_SPIEN),
.extended = EFUSE_DEFAULT,
LOCKBITS = (LB_MODE_3 );
To extract the fuse/lock bits from the elf file. From the command prompt type the following.
avr-objdump -s -j .fuse <ELF file>
avr-objdump -s -j .lock <ELF file>
You should be able to find more info from winavr documentation. It took me forever to find it. Like I mentioned I use the .ELF file to program the part which includes the fuse and lock bit settings.
If you are like Wayne and in a mixed design and manufacturing small business environment, you too might prefer to put the fuse and lock bit instructions in your source code. Give it try and let us know what you think.