Machine Readable Fuse Database

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Machine Readable Fuse Database

Paul "LeoNerd" Evans
I'm looking for some sort of machine-readable database (in whatever
format - XML, CSV, some custom text thing; I really don't care)
containing all the default fuse values for AVR chips (or, at least,
ATmega and ATtiny).


The reason being I've written myself a nice program for helping set
fuse values. Tell it the MCU type and values for all the fuses, and it
prints out an avrdude commandline fragment to set those:

 $ avr-fuses -mtiny84a SELFPRGEN=0 RSTDISBL=1 DWEN=1 SPIEN=0 WDTON=1 \
    EESAVE=0 BODLEVEL=DISABLED CKDIV8=1 CKOUT=1 \
    SUT_CKSEL=INTRCOSC_8MHZ_6CK_14CK_64MS_DEFAULT

 -U efuse:w:0xFE:m -U hfuse:w:0xD7:m -U lfuse:w:0xE2:m

This is great and all, but it's inconvenient to use as you have to tell
it *all* the fuse values, even the ones that are default on a chip. It
would be great if I could just

 $ avr-fuses -mtiny84a EESAVE=0

and have it Do The Right Thing.


The reason this is so, is because I'm using the "devices" XML files
that are supplied with Atmel Studio to get the fuse values from. Those
give the name, value and mapping location of every fuse, but don't
supply the default values.

I notice that the AVR libc per-part .h files do know these values, in a
way.

 $ grep FUSE_DEFAULT /usr/lib/avr/include/avr/iotn84a.h
 #define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & \
   FUSE_SUT0 & FUSE_CKDIV8)
 #define HFUSE_DEFAULT (FUSE_SPIEN)
 #define EFUSE_DEFAULT (0xFF)

It's not *directly* useable as it is, but a C program could read those.
So technically I could iterate all the .h files and extract default
values that way. But it feels like quite a long way around.

Does anyone know of a better source of these?

--
Paul "LeoNerd" Evans

[hidden email]      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list

attachment0 (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Machine Readable Fuse Database

Erik Christiansen-2
On 16.07.16 14:33, Paul "LeoNerd" Evans wrote:

> I notice that the AVR libc per-part .h files do know these values, in a
> way.
>
>  $ grep FUSE_DEFAULT /usr/lib/avr/include/avr/iotn84a.h
>  #define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & \
>    FUSE_SUT0 & FUSE_CKDIV8)
>  #define HFUSE_DEFAULT (FUSE_SPIEN)
>  #define EFUSE_DEFAULT (0xFF)
>
> It's not *directly* useable as it is, but a C program could read those.
> So technically I could iterate all the .h files and extract default
> values that way. But it feels like quite a long way around.
>
> Does anyone know of a better source of these?

Given avrdude's fuse "safemode", I thought at first that it might have
the data, but it only checks whether any have changed since program
invocation, AFAICT.

I wouldn't go to the trouble of a C program, but do it with a lot less
lines of awk, but that's just taste.

Erik

_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Machine Readable Fuse Database

Paul "LeoNerd" Evans
On Thu, 21 Jul 2016 22:01:40 +1000
Erik Christiansen <[hidden email]> wrote:

> I wouldn't go to the trouble of a C program, but do it with a lot less
> lines of awk, but that's just taste.

That's not going to help.

E.g. on the tiny841,

#define LFUSE_DEFAULT    (FUSE_SUT_CKSEL0 & FUSE_SUT_CKSEL2 & \
  FUSE_SUT_CKSEL3 & FUSE_SUT_CKSEL4 & FUSE_CKDIV8)
#define HFUSE_DEFAULT    (FUSE_SPIEN)
#define EFUSE_DEFAULT    (0xFF)

That doesn't help directly, as you need to know the values of those
individual FUSE_* constants. OK, so they are:

#define FUSE_SUT_CKSEL0  (unsigned char)~_BV(0)
#define FUSE_SUT_CKSEL1  (unsigned char)~_BV(1)
#define FUSE_SUT_CKSEL2  (unsigned char)~_BV(2)
#define FUSE_SUT_CKSEL3  (unsigned char)~_BV(3)
#define FUSE_SUT_CKSEL4  (unsigned char)~_BV(4)
...

Alright. Um we're going to need _BV(). Except that isn't found in this
file. I'll have to follow the #include chain.

So now I need to understand how #include works. And #define.

And *then* I'm going to have to understand the ~ and & operators, along
with the << operator of _BV's actual definition.

Or; I could just generate/compile/run the following C program:

  #include <avr/io.h>
  printf("lfuse=%02x:hfuse=%02x:efuse=%02x\n",
    LFUSE_DEFAULt, HFUSE_DEFAULT, EFUSE_DEFAULT);

and out comes the answer directly without my having to do any other
work.

Big spoiler: I already wrote lots of code for doing exactly this kind
of "please get me values out of system .h files":

  https://metacpan.org/pod/ExtUtils::H2PM

So in practice I'll just be running that.

--
Paul "LeoNerd" Evans

[hidden email]      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list

attachment0 (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Machine Readable Fuse Database

Jim Brooks-2

This would be so mucj easier if as with microschip it was in the source files. Aftee all everything else about the configuration of the mci is jandled tjere so why not fuses.
Jim


On Jul 21, 2016 11:46 AM, "Paul "LeoNerd" Evans" <[hidden email]> wrote:
On Thu, 21 Jul 2016 22:01:40 +1000
Erik Christiansen <[hidden email]> wrote:

> I wouldn't go to the trouble of a C program, but do it with a lot less
> lines of awk, but that's just taste.

That's not going to help.

E.g. on the tiny841,

#define LFUSE_DEFAULT    (FUSE_SUT_CKSEL0 & FUSE_SUT_CKSEL2 & \
  FUSE_SUT_CKSEL3 & FUSE_SUT_CKSEL4 & FUSE_CKDIV8)
#define HFUSE_DEFAULT    (FUSE_SPIEN)
#define EFUSE_DEFAULT    (0xFF)

That doesn't help directly, as you need to know the values of those
individual FUSE_* constants. OK, so they are:

#define FUSE_SUT_CKSEL0  (unsigned char)~_BV(0)
#define FUSE_SUT_CKSEL1  (unsigned char)~_BV(1)
#define FUSE_SUT_CKSEL2  (unsigned char)~_BV(2)
#define FUSE_SUT_CKSEL3  (unsigned char)~_BV(3)
#define FUSE_SUT_CKSEL4  (unsigned char)~_BV(4)
...

Alright. Um we're going to need _BV(). Except that isn't found in this
file. I'll have to follow the #include chain.

So now I need to understand how #include works. And #define.

And *then* I'm going to have to understand the ~ and & operators, along
with the << operator of _BV's actual definition.

Or; I could just generate/compile/run the following C program:

  #include <avr/io.h>
  printf("lfuse=%02x:hfuse=%02x:efuse=%02x\n",
    LFUSE_DEFAULt, HFUSE_DEFAULT, EFUSE_DEFAULT);

and out comes the answer directly without my having to do any other
work.

Big spoiler: I already wrote lots of code for doing exactly this kind
of "please get me values out of system .h files":

  https://metacpan.org/pod/ExtUtils::H2PM

So in practice I'll just be running that.

--
Paul "LeoNerd" Evans

[hidden email]      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list


_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Machine Readable Fuse Database

Thomas Kopp
In reply to this post by Paul "LeoNerd" Evans
On Jul 16, 2016 3:34 PM, "Paul "LeoNerd" Evans" <[hidden email]> wrote:

The reason this is so, is because I'm using the "devices" XML files
that are supplied with Atmel Studio to get the fuse values from. Those
give the name, value and mapping location of every fuse, but don't
supply the default values.





They actually do - All(or at least most) of the latest xmls (atdfs now) for mega and tiny devices contain the defaultvalue for Fuse bytes. The attribute is initval. I can't quite remember when they were added but it's possible that they were only publicly available in Studio 7. If you don't want studio 7 you can also download the tiny and mega packs from http://packs.download.atmel.com/ Does that help you?

Example from AT90CAN64:
    <module caption="" name="FUSE">
      <register-group caption="" name="FUSE">
        <register caption="" name="EXTENDED" offset="0x02" size="1" initval="0xFF">
          <bitfield caption="Brown-out Detector trigger level" mask="0x0E" name="BODLEVEL" values="ENUM_BODLEVEL"/>
          <bitfield caption="Reserved for factory tests" mask="0x01" name="TA0SEL"/>
        </register>
        <register caption="" name="HIGH" offset="0x01" size="1" initval="0x99">
          <bitfield caption="On-Chip Debug Enabled" mask="0x80" name="OCDEN"/>
          <bitfield caption="JTAG Interface Enabled" mask="0x40" name="JTAGEN"/>
          <bitfield caption="Serial program downloading (SPI) enabled" mask="0x20" name="SPIEN"/>
          <bitfield caption="Watchdog timer always on" mask="0x10" name="WDTON"/>
          <bitfield caption="Preserve EEPROM through the Chip Erase cycle" mask="0x08" name="EESAVE"/>
          <bitfield caption="Select Boot Size" mask="0x06" name="BOOTSZ" values="ENUM_BOOTSZ"/>
          <bitfield caption="Boot Reset vector Enabled" mask="0x01" name="BOOTRST"/>
        </register>
        <register caption="" name="LOW" offset="0x00" size="1" initval="0x62">
          <bitfield caption="Divide clock by 8 internally; [CKDIV8=0]" mask="0x80" name="CKDIV8"/>
          <bitfield caption="Clock output on PORTC7; [CKOUT=0]" mask="0x40" name="CKOUT"/>
          <bitfield caption="Select Clock Source" mask="0x3F" name="SUT_CKSEL" values="ENUM_SUT_CKSEL"/>
        </register>

 

_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Machine Readable Fuse Database

juergen.harms (Bugzilla)
In reply to this post by Paul "LeoNerd" Evans
On 2016-07-21 20:15, Paul "LeoNerd" Evans wrote:
> of "please get me values out of system .h files":

You can go quite some ways with grep

- egrep "define [A-Z]FUSE" /usr/avr/include/avr/*.h | grep can

     informs, for instance, about the values for EFUSE, HFUSE and
     LFUSE used for can parts

- grep "#define FUSE_BOOTSZ0" /usr/avr/include/avr/*.h

     for instance, provides you with the definition of BOOTSZ0.
     But you wont get away from investing some time to get
     knowledge about BV, ~ et cie - something you anyhow need for
     understanding how C is used for programming microprocessors.

I would certainly never use C for creating your file - an editor
allowing to use regular expressions, or - much better - a short perl
script, would allow to more or less automatically produce the file you need.

Good luck


_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Machine Readable Fuse Database

Paul "LeoNerd" Evans
In reply to this post by Thomas Kopp
On Thu, 21 Jul 2016 21:37:03 +0200
Thomas Kopp <[hidden email]> wrote:

> They actually do - All(or at least most) of the latest xmls (atdfs
> now) for mega and tiny devices contain the defaultvalue for Fuse
> bytes. The attribute is initval. I can't quite remember when they
> were added but it's possible that they were only publicly available
> in Studio 7.

Oooh; I see. Yes; my XML files are lacking the "initval" field but I
see it in your pasted example below; that looks perfect for me.

> If you don't want studio 7 you can also download the
> tiny and mega packs from http://packs.download.atmel.com/ Does that
> help you?

I see the packs. They appear to be Zip files. Inside those are indeed
the XML files, though they're not called .xml; I see they're .atdf.

But yes - these likely contain the information I need. Thanks muchly.

--
Paul "LeoNerd" Evans

[hidden email]      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list

attachment0 (188 bytes) Download Attachment
Loading...