Go Down

Topic: Did you know fuses and signature bytes can be read out LIVE? (Read 1 time) previous topic - next topic

krupski

Yes, they can. I just discovered the functions in <avr/boot.h>.

Here's a demo sketch that demonstrates the functions. Since I've never heard of this before, I'm assuming it's something "new" to most of you. If not, my apologies......

Anyway, here it is:

Code: [Select]
#include <avr/boot.h> // necessary!

void setup (void)
{
Serial.begin (115200);

uint8_t x;
uint8_t addr;
uint8_t sig[3];
uint8_t fuses[4];

const char *fnames[] = {
"Low ",
"Lock",
"Ext ",
"High",
};

char buffer[64];
char *ptr;

// get AVR signature
for (addr = 0; addr < 3; addr++) {
// signature bytes are at 0, 2 and 4. OSCCAL is at 1
sig[addr] = boot_signature_byte_get (addr * 2);
}

// get AVR fuse settings. Fuse addresses are:
// 0 - low fuse
// 1 - lock fuse
// 2 - extended fuse
// 3 - high fuse
for (addr = 0; addr < 4; addr++) {
fuses[addr] = boot_lock_fuse_bits_get (addr);
}

sprintf (buffer, "Your AVR signature is %02X %02X %02X\n\n", sig[0], sig[1], sig[2]);
Serial.print (buffer);

for (addr = 0; addr < 4; addr++) {
sprintf (buffer, "Your %s fuse setting is 0x%02X (0b", fnames[addr], fuses[addr]);
Serial.print (buffer);
// convert fuse[addr] into 1010 binary
x = 8;
ptr = buffer;
while (x--) {
*ptr++ = (fuses[addr] & _BV (x)) ? '1' : '0';
}
*ptr = 0;
Serial.print (buffer);
sprintf (buffer, ") binary\n");
Serial.print (buffer);
}
}

void loop (void)
{
// nothing
}
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Coding Badly

Since I've never heard of this before, I'm assuming it's something "new" to most of you.
Uh, well, one of Nick Gammon's utility sketches not only reads the fuses but cracks the values.

Quote
If not, my apologies......
For posting on-topic technical information on a technical forum?  Apologies are never necessary for that.

Thank you for your post.


Delta_G

I didn't know you could do that.  So I'll thank you too. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

krupski

Uh, well, one of Nick Gammon's utility sketches not only reads the fuses but cracks the values.

For posting on-topic technical information on a technical forum?  Apologies are never necessary for that.

Thank you for your post.


Nick's method uses a second Arduino as an ISP and reads the fuses in programming mode. "My" method does it directly from the Arduino itself.
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

jboyton

It didn't compile for me.

Code: [Select]
sketch_may14a.ino: In function 'void setup()':
sketch_may14a:25: error: 'SIGRD' was not declared in this scope


IDE 1.0.5; OS X 10.9.5

MAS3

Which sketch is that ?

The sketch in the first post doesn't seem to contain any reference to SIGRD, nor does it generate errors in IDE 1.6.3.

boot.h does contain that string.
Have a look at your IDE installation, consider updating.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

jboyton

Which sketch is that ?

The sketch in the first post doesn't seem to contain any reference to SIGRD, nor does it generate errors in IDE 1.6.3.

boot.h does contain that string.
Have a look at your IDE installation, consider updating.
Yes, the sketch in the first post. And, like you, I found the error confusing.

Does it really require an IDE upgrade? I have the latest IDE downloaded, but until this sketch I've had no real reason to upgrade.

I tried 1.6.3 a few weeks back and the error messages were in such a dark shade of red that I couldn't read them easily. That, by itself, was a deal killer. I see in 1.6.4 they've made them a bit brighter, but still unnecessarily dark. There must be some way to adjust the color but I couldn't find where to do it.

While the color of those messages affects usability for me it is actually a minor issue. But it made me wonder how stable the new releases are.

MAS3

I can't tell.
If you hesitate to upgrade, see if you can reinstall the older version you are comfortable with.
I'm sure you can find older versions from the download page.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

jboyton

Maybe I need to reinstall my IDE. But why would you suggest that as a first course of action? Isn't that akin to suggesting I reload my OS or reformat my hard drive?

MAS3

There seems to be some problem with the copy of boot.h you are using.
This was part of the IDE installation.
That's why i suggested that.

To offer you an alternative, i attached a copy of the file from my 1.6.3 version.
I took it from this Win7 folder: C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr

The problem might as well be in some other file this one depends on, i don't know.
In that case this file doesn't help.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

jboyton

There seems to be some problem with the copy of boot.h you are using....

...The problem might as well be in some other file this one depends on, i don't know.
SIGRD isn't defined in iom328p.h in either 1.0.5 or 1.0.6, but it is defined there in 1.6.3. I think that's the reason it doesn't compile that line. Reinstalling the IDE wouldn't change that.

If I define SIGRD the compiler just flags a new error:

              fuses[addr] = boot_lock_fuse_bits_get (addr);  <---- highlighted line in code

              sketch_may14a.ino: In function 'void setup()':
              sketch_may14a:35: error: impossible constraint in 'asm'

Oh well... :-)

Peter_n

That is normal known information. Search for "GET_LOW_FUSE_BITS" in "forum.arduino.cc" or "playground.arduino.cc" or in "github.com".
This is the Playground : http://playground.arduino.cc/Main/ShowInfo

jboyton

Thank you, Peter. That's a useful sketch.

And it compiles.

nickgammon

Nick's method uses a second Arduino as an ISP and reads the fuses in programming mode. "My" method does it directly from the Arduino itself.
He is referring to my Self-read signature sketch.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

krupski

Which sketch is that ?

The sketch in the first post doesn't seem to contain any reference to SIGRD, nor does it generate errors in IDE 1.6.3.

boot.h does contain that string.
Have a look at your IDE installation, consider updating.
I don't know what "SIGRD" is, but there's no reference to it in my sketch.

BTW, I use AVR-GCC v4.9.2 and either the Arduino IDE 1.0.6 (just for the "upload" button) or else nano (text editor), minicom (serial terminal) and a Makefile to build and upload code.

Also, I don't use the setup/loop programming style - I just use int main (void) with init() at the beginning and while (1) at the end.
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Go Up