[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-dev] Fuse and lock bits
From: |
Rick Altherr |
Subject: |
[avr-libc-dev] Fuse and lock bits |
Date: |
Mon, 27 Aug 2007 09:04:43 -0700 |
Having had a bit of experience with the CONFIG bits in PIC
development, I was surprised to see that the FUSE and LOCK bits in
AVR weren't able to be set in the source code. A friend and I came
up with the following solution:
- Create a header file for each device that contain:
- A define that allocates an extra ELF section for the various
fuse and lock bits
- A set of defines that describe the various bits in the fuse and
lock bits
- A define for the default value described in the datasheet
- A set of Makefile rules that:
- Extract the new ELF sections into separate hex files
- Invoke avrdude with commands that program the lock and fuse bits
with the contents of the new sections
Here is an excerpt from the ATmega8's header file for HFUSE:
/* High Fuse Byte */
#define HFUSE const unsigned char hfuse __attribute__((section
(".hfuse")))
#define BOOTRST ~_BV(0)
#define BOOTSZ0 ~_BV(1)
#define BOOTSZ1 ~_BV(2)
#define EESAVE ~_BV(3)
#define CKOPT ~_BV(4)
#define SPIEN ~_BV(5)
#define WDTON ~_BV(6)
#define RSTDISBL ~_BV(7)
#define HFUSE_DEFAULT SPIEN & BOOTSZ1 & BOOTSZ0
The Makefile rules are a bit more complex since they are entwined
with a whole set of rules to reduce the amount of setup needed for an
AVR-based project. I've attached an example project that shows these
header files and Makefile rules in use. The use of the fuse header
is in example.c where LFUSE is set. To build it, put the files from
the header.tar.gz into the same directory as the I/O definition
headers. Then, in example.tar.gz, run 'make' to build the software
and 'make program' to write it to a device. To get rid of all the
generated files, run 'make clean'.
headers.tar.gz
Description: GNU Zip compressed data
example.tar.gz
Description: GNU Zip compressed data
Currently, we only have files for the ATmega8 and ATmega16. That's
mainly because those are the only 2 devices we have used this with.
It definitely makes keeping track of things like clock configuration
and watchdog timer enable easier as well as enables a way for them to
be included in a source repository.
--
Rick Altherr
address@hidden
"He said he hadn't had a byte in three days. I had a short, so I
split it with him."
-- Slashdot signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-libc-dev] Fuse and lock bits,
Rick Altherr <=