1
\$\begingroup\$

I am trying to embed code in my Attiny4 project that will set fuses and lock bits(In AtmelStudio 7). I copy/pasted the code that Atmel suggests here:

#include <avr/io.h>

typedef struct _tagConfig
{
    unsigned char f1;
} Config;

typedef struct _tagLock
{
    unsigned char f1;
} Lock;

typedef struct _tagSig
{
    unsigned char f1;
    unsigned char f2;
    unsigned char f3;
} Signature;

Config __config __attribute__((section(".config"))) =
{
    f1 : 0xfb, // Set CKOUT
};

Lock __lock __attribute__((section(".lock"))) =
{
    f1 : 0xfc, // Further programming and verification disabled
};

Signature __sig __attribute__((section(".signature"))) =
{
    f1 : 0x03,
    f2 : 0x90,
    f3 : 0x1e,
};

Then i try to compile and it directly fails with the following errors:

attiny4-fan.elf section `.config' will not fit in region `config'
region `config' overflowed by 1 bytes
ld returned 1 exit status
recipe for target 'attiny4-fan.elf' failed

I can't seem to find any other information on how to do this for an ATTiny4/5/9/10. The Datasheet seems to mention something about the locations but since i have never done this before, especially not for the Attiny4 i'm playing with here, i have no idea on how to proceed.

Attiny4/5/9/10 Datasheet

This is the output of

avr-objdump --section-headers


Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         000000c8  00000000  00000000  00000074  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00800040  00800040  0000013c  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000003  00800040  00800040  0000013c  2**0
                  ALLOC
  3 .comment      00000030  00000000  00000000  0000013c  2**0
                  CONTENTS, READONLY
  4 .note.gnu.avr.deviceinfo 0000003c  00000000  00000000  0000016c  2**2
                  CONTENTS, READONLY
  5 .debug_info   000002ab  00000000  00000000  000001a8  2**0
                  CONTENTS, READONLY, DEBUGGING
  6 .debug_abbrev 00000284  00000000  00000000  00000453  2**0
                  CONTENTS, READONLY, DEBUGGING
  7 .debug_line   000000d3  00000000  00000000  000006d7  2**0
                  CONTENTS, READONLY, DEBUGGING
  8 .debug_str    000000f6  00000000  00000000  000007aa  2**0
                  CONTENTS, READONLY, DEBUGGING

In the mean time, i also found out that in the ATtiny DFP header file for the Attiny4/5/9/10, the following macros are defined(ATtiny9 as example):

/* Fuses */
#define FUSE_MEMORY_SIZE 0
/* Lock Bits */
#define __LOCK_BITS_EXIST
/* Signature */
#define SIGNATURE_0 0x1E
#define SIGNATURE_1 0x90
#define SIGNATURE_2 0x08

Why would FUSE_MEMORY_SIZE be defined as 0?

Can anybody help me to get my ELF to contain fuses and lock bits?

\$\endgroup\$
7
  • \$\begingroup\$ Can you compile your project to .o files and use objdump --section-headers to see if you have any other sections that match .config* in there? Looking through the linker script, any such sections would be concatenated into the space, which obviously isn't going to work... \$\endgroup\$
    – Jules
    Commented Feb 27, 2018 at 16:45
  • \$\begingroup\$ How would i do that? I'm on Windows 10. I have no other sections in the code where i try to modify these sections. \$\endgroup\$ Commented Feb 27, 2018 at 17:08
  • \$\begingroup\$ I would expect the program to have been installed in the atmel studio's toolchain directory, but unfortunately I don't have it installed on this machine at the moment, so can't check. \$\endgroup\$
    – Jules
    Commented Feb 27, 2018 at 18:34
  • \$\begingroup\$ So i googled a bit and found an .lss file. It contains a commented header that mentions .text, .data, .bss, .comment and other sections. Could that be what you were looking for? I can't find anything .config related there \$\endgroup\$ Commented Feb 27, 2018 at 18:48
  • \$\begingroup\$ You were absolutely right, it's installed in the toolchain directory, i found the file and was able to run the command. The output is the same as the one i found in the .lss file, will append it to the original question. \$\endgroup\$ Commented Feb 27, 2018 at 19:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.