Additional sections in EEPROM memory

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

Hi.
Is there a possibility to add few additional sections to eeprom memory?? How to link them during compilation??

I need to put some variables into eeprom memory but with different adresses during the compilation (.eep file). With flash memory there is no problem. But eeprom has only one section .eeprom.

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

Read the "memory sections" chapter of the AVR LibC manual.

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

I' ve read it. In my makefile:

-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0

How to add here additional sections??

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

__attribute __((section (". myeeprom")))

--section-start=. myeeprom=0x810124

Puts that at 0x0124 in the EEPROM (as that manual tells you).

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

When I use avrstudio without external makefile it is done automatically (if i create new eeprom section) but there is no change in .eep file. If i declare variable with .eeprom liner put it into .eep

unsigned char eeprom_variable1 __attribute__((section(".eeprom"))) = 0xAB;
unsigned char eeprom_variable2 __attribute__((section(".myeeprom"))) = 0xCD;

avr-gcc -mmcu=atmega88 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT testowe.o -MF dep/testowe.o.d -c ../testowe.c
avr-gcc -mmcu=atmega88 -Wl,-Map=testowe.map -Wl,-section-start=.myeeprom=0x810124 testowe.o -o testowe.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature testowe.elf testowe.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings --change-section-lma .myeeprom=0x124 -O ihex testowe.elf testowe.eep || exit 0
avr-objdump -h -S testowe.elf > testowe.lss

AVR Memory Usage
----------------
Device: atmega88

Program: 76 bytes (0.9% Full)
(.text + .data + .bootloader)

Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)

EEPROM: 1 bytes (0.2% Full)
(.eeprom)

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

Map file:

...

LOAD linker stubs

.myeeprom 0x00810124 0x1
.myeeprom 0x00810124 0x1 testowe.o
0x00810124 eeprom_variable2

LSS file:

...
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000004c 00000000 00000000 00000094 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .myeeprom 00000001 00810124 00810124 000000e1 2**0
CONTENTS, ALLOC, LOAD, DATA
2 .eeprom 00000001 00810000 00810000 000000e0 2**0
CONTENTS, ALLOC, LOAD, DATA

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

Content of .eep file only:

:01000000AB54
:00000001FF

Why value oxCD from unsigned char eeprom_variable2 __attribute__((section(".myeeprom"))) = 0xCD; is not still in eeprom memory

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

Because you didn't avr-objcopy that section to the .eep

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

avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings --change-section-lma .myeeprom=0x124 -O ihex testowe.elf testowe.eep || exit 0

??

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

Does avr studio suppose to make it automatically??

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

Ok, so where in that is the -j of your new section?

(apologies if it is there as I'm reading this (and worse still typing this) on an Android phone.. Actually SwiftKey makes the typing fairly painless)

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

hmm, does -j option needs to be with every created section or after avr-objcopy??

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

What does the manual say?

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

Even automatically generated and exported makefile from avrstudio4 says (but not include .myeeprom section into .eep file):

## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS +=  -Wl-j,--section-start=.myeeprom=0x810124  -Wl,-Map=testowe.map
LDFLAGS += -Wl,-section-start=.myeeprom=0x810124
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature

HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
HEX_EEPROM_FLAGS += --change-section-lma .myeeprom=0x124

Please help.

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

Oh sorry, I forgot to mention that both AVR Studios have a bug and don't do this properly so you need to hand craft a makefile.

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

I thought so.

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

Stil nothing with external makefile


LDFLAGS +=  -Wl -j,--section-start=.myeeprom=0x810124  -Wl,-Map=testowe.map

...

# Link: create ELF output file from object files.
.SECONDARY :$(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
	@echo
	@echo $(MSG_LINKING) $@
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)

...

%.eep: %.elf
	@echo
	@echo $(MSG_EEPROM) $@
	-$(OBJCOPY) \
	-j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 \
	-j .myeeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .myeeprom=0x124 \
	--no-change-warnings -O $(FORMAT) $< $@ || exit 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I this bug for eeprom memory only or also for flash and ram??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
-Wl -j,--section-start=.myeeprom=0x810124

->

-Wl,--section-start=.myeeprom=0x810124
-j .myeeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .myeeprom=0x124 \
                                  ^ my?

Stefan Ernst

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

sternst, yes it finally works. Thanks a lot.