Compiling ATtiny3217 (series 1) with avr-gcc

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm struggling a bit compiling a test program for the attiny3217.

This is my main.c:

int main(void) {
    return 0;
}

I'm using the toolchain from microchip v3.6.2 and the bin's are in my PATH, gcc version 5.4.0 (AVR_8_bit_GNU_Toolchain_3.6.2_503). I got the necessary atmel packs as well.

 

This is what happens:

avr-gcc -Wall -B pack/gcc/dev/attiny3217/ -I pack/include/ -Os -DF_CPU=20000000 -mmcu=attiny3217 -c src/main.c -o src/main.o
avr-gcc -Wall -B pack/gcc/dev/attiny3217/ -I pack/include/ -Os -DF_CPU=20000000 -mmcu=attiny3217 -o main.elf src/main.o
/www/forgetmenot/toolchain/avr8-gnu-toolchain-darwin_x86_64/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld: address 0x803800 of main.elf section `.data' is not within region `data'
/www/forgetmenot/toolchain/avr8-gnu-toolchain-darwin_x86_64/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld: address 0x803800 of main.elf section `.data' is not within region `data'
collect2: error: ld returned 1 exit status
make: *** [main.elf] Error 1

If I run the 2nd command with -mmcu=avrxmega3 it creates a main.elf. I doubt it's correct though. Does anybody have any ideas what's wrong?

This topic has a solution.
Last Edited: Wed. Jan 29, 2020 - 04:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Go find the linker script- avr\lib\ldscripts\avrxmega3.xn (its the .xn one that is used, but can change all the avrxmega3 scripts if wanted)-

 

There is a line than needs a change from an address of 0x800100 (or similar) to  __DATA_REGION_ORIGIN__, so the line looks like this-

 

data   (rw!x) : ORIGIN = __DATA_REGION_ORIGIN__, LENGTH = __DATA_REGION_LENGTH__

 

Now, the data region will start at the correct address. The previous way they were doing it worked but was wrong (using -Tdata which moved up the.data section, but did nothing to the data region)  and now that the 0/1 series data region varies on the low end and not the high end, the error now shows up.

Last Edited: Thu. Jan 30, 2020 - 02:46 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

2ni wrote:
This is my main.c:

int main(void) {
    return 0;
}

So where, exactly, do you think that a return from main() is going to go ... ?

 

 

https://electronics.stackexchang...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have AS7 on Windows. The avrxmega3.xn already looks like this as installed?

OUTPUT_ARCH(avr:103)
__TEXT_REGION_ORIGIN__ = DEFINED(__TEXT_REGION_ORIGIN__) ? __TEXT_REGION_ORIGIN__ : 0;
__DATA_REGION_ORIGIN__ = DEFINED(__DATA_REGION_ORIGIN__) ? __DATA_REGION_ORIGIN__ : 0x802000;
__TEXT_REGION_LENGTH__ = DEFINED(__TEXT_REGION_LENGTH__) ? __TEXT_REGION_LENGTH__ : 1024K;
__DATA_REGION_LENGTH__ = DEFINED(__DATA_REGION_LENGTH__) ? __DATA_REGION_LENGTH__ : 0xffa0;
__EEPROM_REGION_LENGTH__ = DEFINED(__EEPROM_REGION_LENGTH__) ? __EEPROM_REGION_LENGTH__ : 64K;
__FUSE_REGION_LENGTH__ = DEFINED(__FUSE_REGION_LENGTH__) ? __FUSE_REGION_LENGTH__ : 1K;
__LOCK_REGION_LENGTH__ = DEFINED(__LOCK_REGION_LENGTH__) ? __LOCK_REGION_LENGTH__ : 1K;
__SIGNATURE_REGION_LENGTH__ = DEFINED(__SIGNATURE_REGION_LENGTH__) ? __SIGNATURE_REGION_LENGTH__ : 1K;
__USER_SIGNATURE_REGION_LENGTH__ = DEFINED(__USER_SIGNATURE_REGION_LENGTH__) ? __USER_SIGNATURE_REGION_LENGTH__ : 1K;
__RODATA_PM_OFFSET__ = DEFINED(__RODATA_PM_OFFSET__) ? __RODATA_PM_OFFSET__ : 0x8000;
MEMORY
{
  text   (rx)   : ORIGIN = __TEXT_REGION_ORIGIN__, LENGTH = __TEXT_REGION_LENGTH__
  data   (rw!x) : ORIGIN = __DATA_REGION_ORIGIN__, LENGTH = __DATA_REGION_LENGTH__
  eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = __EEPROM_REGION_LENGTH__
  fuse      (rw!x) : ORIGIN = 0x820000, LENGTH = __FUSE_REGION_LENGTH__
  lock      (rw!x) : ORIGIN = 0x830000, LENGTH = __LOCK_REGION_LENGTH__
  signature (rw!x) : ORIGIN = 0x840000, LENGTH = __SIGNATURE_REGION_LENGTH__
  user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = __USER_SIGNATURE_REGION_LENGTH__
}

so I guess Curt means modifying the line:

__DATA_REGION_ORIGIN__ = DEFINED(__DATA_REGION_ORIGIN__) ? __DATA_REGION_ORIGIN__ : 0x802000;

However what is SUPPOSED to be happening here is that __DATA_REGION_ORIGIN__ is already defined by the time this is encountered so it shouldn't be falling back to the 802000 anyway. So the fault is actually that not happening somewhere else.

 

(in a minute I'll remember where!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It doesn't matter at all. It's a dummy programm which does nothing. The goal is to make the toolchain work, not the programm itself.

Nevertheless I changed it to:

int main(void) {
    while (1) {
    }
}

 

Last Edited: Wed. Jan 29, 2020 - 04:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There seems to be more about this in:

 

https://www.avrfreaks.net/forum/overriding-specs-file-not-really-working

 

Specifically see Curt's post #6 or maybe Georg-Johan's post #8 ?

Last Edited: Wed. Jan 29, 2020 - 03:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

2ni wrote:
It doesn't matter at all.

Maybe.

 

The "trouble" (sic) with trivial examples in optimising compilers is that they can spot useless code which does nothing ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

2ni wrote:

It doesn't matter at all. It's a dummy programm which does nothing. The goal is to make the toolchain work, not the programm itself.

 

 

I was about to say the same...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks @curtvm @clawson!

I don't even have these lines in the file avr8-gnu-toolchain-darwin_x86_64/avr/lib/ldscripts/avrxmega3.xn:

...
OUTPUT_ARCH(avr:103)
__TEXT_REGION_LENGTH__ = DEFINED(__TEXT_REGION_LENGTH__) ? __TEXT_REGION_LENGTH__ : 1024K;
__DATA_REGION_LENGTH__ = DEFINED(__DATA_REGION_LENGTH__) ? __DATA_REGION_LENGTH__ : 0xffa0;
__EEPROM_REGION_LENGTH__ = DEFINED(__EEPROM_REGION_LENGTH__) ? __EEPROM_REGION_LENGTH__ : 64K;
__FUSE_REGION_LENGTH__ = DEFINED(__FUSE_REGION_LENGTH__) ? __FUSE_REGION_LENGTH__ : 1K;
__LOCK_REGION_LENGTH__ = DEFINED(__LOCK_REGION_LENGTH__) ? __LOCK_REGION_LENGTH__ : 1K;
__SIGNATURE_REGION_LENGTH__ = DEFINED(__SIGNATURE_REGION_LENGTH__) ? __SIGNATURE_REGION_LENGTH__ : 1K;
__USER_SIGNATURE_REGION_LENGTH__ = DEFINED(__USER_SIGNATURE_REGION_LENGTH__) ? __USER_SIGNATURE_REGION_LENGTH__ : 1K;
__RODATA_PM_OFFSET__ = DEFINED(__RODATA_PM_OFFSET__) ? __RODATA_PM_OFFSET__ : 0x8000;
...

So I added the lines as follows (also tried on the other files avrxmega3.*) , but it didn't change anything in the output. still the same error.

OUTPUT_ARCH(avr:103)
__TEXT_REGION_ORIGIN__ = DEFINED(__TEXT_REGION_ORIGIN__) ? __TEXT_REGION_ORIGIN__ : 0;
__DATA_REGION_ORIGIN__ = DEFINED(__DATA_REGION_ORIGIN__) ? __DATA_REGION_ORIGIN__ : 0x802000;
__TEXT_REGION_LENGTH__ = DEFINED(__TEXT_REGION_LENGTH__) ? __TEXT_REGION_LENGTH__ : 1024K;
__DATA_REGION_LENGTH__ = DEFINED(__DATA_REGION_LENGTH__) ? __DATA_REGION_LENGTH__ : 0xffa0;
__EEPROM_REGION_LENGTH__ = DEFINED(__EEPROM_REGION_LENGTH__) ? __EEPROM_REGION_LENGTH__ : 64K;
__FUSE_REGION_LENGTH__ = DEFINED(__FUSE_REGION_LENGTH__) ? __FUSE_REGION_LENGTH__ : 1K;
__LOCK_REGION_LENGTH__ = DEFINED(__LOCK_REGION_LENGTH__) ? __LOCK_REGION_LENGTH__ : 1K;
__SIGNATURE_REGION_LENGTH__ = DEFINED(__SIGNATURE_REGION_LENGTH__) ? __SIGNATURE_REGION_LENGTH__ : 1K;
__USER_SIGNATURE_REGION_LENGTH__ = DEFINED(__USER_SIGNATURE_REGION_LENGTH__) ? __USER_SIGNATURE_REGION_LENGTH__ : 1K;
__RODATA_PM_OFFSET__ = DEFINED(__RODATA_PM_OFFSET__) ? __RODATA_PM_OFFSET__ : 0x8000;

 

 

Last Edited: Wed. Jan 29, 2020 - 04:18 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Got it working, thx to @curtvm and his post. I just the following line in avrxmega3.xn from:

data   (rw!x) : ORIGIN = 0x802000, LENGTH = __DATA_REGION_LENGTH__ 

to:

data   (rw!x) : ORIGIN = __DATA_REGION_ORIGIN__, LENGTH = __DATA_REGION_LENGTH__

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know exactly what toolchain you're using, but I made my own script to build a toolchain, for Linux (but probably works on any other OS with the requirements)

 

https://github.com/MarkR42/robot...

 

It was based on the toolchain documented by Vlad Belous ( https://github.com/vladbelous/ti... )

 

It works for me on the attiny3217 and attiny1614, it will probably work on other chips, the Makefile required to build is quite simple (no linker scripts or other trickery required), I just did something like:

 

OBJDIR=obj

OBJ_FILES=main.o diag.o
OBJECTS=$(addprefix $(OBJDIR)/,$(OBJ_FILES))
HEADERS=diag.h

MCU=attiny3217

ELF=$(OBJDIR)/test.elf
HEX=$(OBJDIR)/test.hex

LINKFLAGS=-Os

link: $(OBJECTS) $(HEADERS)
        avr-gcc -mmcu=$(MCU) -o $(ELF) $(OBJECTS) $(LINKFLAGS)
        # see how big it is
        avr-size $(ELF)
        # disassemble, so can see what the compiler did
        avr-objdump -S $(ELF) > $(OBJDIR)/image.asm
        avr-objdump -t $(ELF) > $(OBJDIR)/image.sym
        avr-objdump -t $(ELF) |grep 00 |sort  > $(OBJDIR)/image-sorted.sym
        avr-objcopy -j .text -j .data -j .rodata -O ihex $(ELF) $(HEX)

CFLAGS=-mmcu=$(MCU)  -Os -Wall
$(OBJDIR)/%.o: %.c Makefile $(HEADERS)
        @mkdir -p $(OBJDIR)
        avr-gcc -c $(CFLAGS) -o $@ $<

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

deleted