Store data on program memory, at the program's end

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

Hello friends,

I'm trying to store data at the end of my program. I'm using __attribute__((section(".MySection"))), but I don't know how to declare MySection start at the end of the program space. Can I do this? How?
Thanks in advance.

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

Is there any particular reason that you want to store the data at a specific location rather than letting the compiler decide where to put it?

Regards,
Steve A.

The Board helps those that help themselves.

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

I wonder that myself. Is the O/P familiar with PROGMEM?
https://www.avrfreaks.net/index.p...

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

Koshchi wrote:
Is there any particular reason that you want to store the data at a specific location rather than letting the compiler decide where to put it?

Yes. I store information about the sw in a specific location, and another device accesses the sw binary to adquire this information. If I don't know where is this data, the other device cannot find it. Scanning the binary isn't a valid choice.

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

Quote:

another device accesses the sw binary

Are you talking about a PC as this "other device", scanning the compiler/linker output file?

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
Quote:

another device accesses the sw binary

Are you talking about a PC as this "other device", scanning the compiler/linker output file?

Lee


Nooo... if the device is a PC, other solution will be easy to do. The sw binary will be stored on at45DB041 flash, as binary file (not motorola s-record or intel hex), and the reader (and writer) will be a ATTiny2313. The ATTiny program memory is almost full with other stuff. The ATTiny program must find a particular data easily in the at45 flash (no space on ATTiny for a scanning algorithm).
The soft is for AT90CAN128 mmcu.

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

In answer to the original question: There are two steps to storing the data, defining the data as being in program memory as part of a section, and then defining where that section resides. I do this in my bootloader, but you can adjust it for your use.

Step 1 - defining your data for a specific section:

#define BOOTSTRING_SECTION   __attribute__ ((section (".bootstring")))

const char boot_Version   [] BOOTSTRING_SECTION = "0.7";
const char boot_Monitor   [] BOOTSTRING_SECTION = "DPHIMON ";
const char boot_Prompt    [] BOOTSTRING_SECTION = "* ";

Step 2 - defining where the section lives:

LDFLAGS += -Wl,--section-start=.bootstring=0x3FA00

This second part is done in your makefile. If you are going to play this game, I strongly urge you to use the template makefile from WinAVR's Mfile app! If you are using AVRStudio, tell the project to use an external makefile.

Important note!The linker section address above is in bytes but the addresses listed in your data sheet for the flash is in words! In my case (an ATmega2560) my strings are in very high memory.

Hope this helps!

Stu

PS: If you are placing your data at any address larger than 64 KiB (that's bytes), you will need to use a little more complicated procedure to access that data. Post here and I will follow up with a note on how to do that.

PPS: You might want to read [TUT] [C] GCC and the PROGMEM Attribute

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!

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

Quote:
If you are using AVRStudio, tell the project to use an external makefile.
AVR Studio can also take care of this without having to touch a makefile.

Project->Configuration Options->Memory Settings
click Add button
Memory Type: Flash
Name: .MySection
Address (Hex): 0x3F0 (this is a word address)

the LDFLAGS makefile option will then be created by studio (and will be converted to a byte address)

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

curtvm wrote:
Quote:
If you are using AVRStudio, tell the project to use an external makefile.
AVR Studio can also take care of this without having to touch a makefile.
Thanks, Curt, forgot about that. I've used external makefiles for so long now that I don't even pay attention to the AVRStudio makefile system.

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!

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

Thanks guys, see ya.