How to do a .section inside a .section?

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

Hi boys:

I was in need of an special EEPROM section, and coded
my own by writing

#define SYS_DATA __attribute__ ((section (".eep_sys_sec")))

in main.c

and then instructed the linker to do

-Wl,--section-start=.eep_sys_sec=0x00810f70

expecting that, when declaring

uint8_t test_var SYS_DATA = 4;

see the value 0x04 in eeprom address 0x0f70
But I can't see it, in fact, I've declared other variables that I need in the EEPROM (by the EEMEM attribute) and they appear at their intended addresses. (starting from zero)
But not "test_var"

I searched for examples on creating sections and relocating sections, and found this solution, which works for the .text area, but I think I'm missing something here. What I expect is to overlap my area inside the .eeprom area and use it to storage some parameters that doesn't change frequently.

Thanks in advance
Nachus

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

Post the .map file.

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

Remember how the .eep file is created:

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

That is ONLY extracting a data section from the ELF called ".eeprom" (and rebasing it without the 0x8N0000 offset). You need to add to this rule to also pull out ".eep_sys_sec" from the ELF and have it copied into the .eep too.

Personally I'd just do:

struct {
  uint8_t ee_var_at_0;
etc.
  uint8_t padding[0xF30] ; // or however much is neeed

  uint8_t ee_var_at_F70;
etc.
} ee_vars EEMEM;

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

Ok:

The problem is that I use the AVRstudio project management, for a project in GCC, and Astudio doesn't let you change it's generated makefile. I tried it, but when rebuilding the project, the changes are wiped out, as if Astudio were regenerating the MF every time you build.

On the other hand, and having looked thoroughly in the meantime, Maybe it's the better solution to give absolute addresses to the two structs and the couple of uint's I need and put it in an already created config code file that is included in every one of our projects.

Thank you
Nachus

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

nachus001 wrote:
The problem is that I use the AVRstudio project management, for a project in GCC, and Astudio doesn't let you change it's generated makefile.
In general, when you start wanting to do anything "out of the ordinary" (and this certainly fits the bill) it is far better to go with an external makefile. Use the Mfile template shipped with WinAVR to build your makefile, then you can hack it to your heart's content.

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!