avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] storing values at a spcified location in FLASH..?


From: Eivind Sivertsen
Subject: RE: [avr-gcc-list] storing values at a spcified location in FLASH..?
Date: Mon, 17 Jan 2005 10:33:55 +0100

Thanks Andy and Eric!
I almost have it now, yes.
I had already gotten the linker and objcopy parts figured out.
And the poiner worked. It's just that the target is to be calibrated prior
to programming; and therefore the compiler/linker cannot decide themselves
where they want to put the calibration bytes. This must be declared
expliclitly.
This is of course because the ISP programmer needs to put the bytes
_somewhere_, but knows nothing about where the linker has put anything. ANd
vice versa, the program must read these bytes from an agreed location during
runtime..

But things are sorted out now, and the only problem is to get the hex file
programmed into the target.
Seems stk500.exe has a problem programming non-contiguous records. The
Srecord utility has been some help padding the empty spaces, but its 32-byte
data fields also seem to pose a problem to stk500.exe.
We'll see if avrdude can fix it!

Cheers,

Eivind



> -----Original Message-----
> From: E. Weddington [mailto:address@hidden
> Sent: 13. januar 2005 18:21
> To: address@hidden
> Cc: address@hidden
> Subject: Re: [avr-gcc-list] storing values at a spcified location in
> FLASH..?
>
>
> Eivind Sivertsen wrote:
>
> >Hi guys,
> >
> >
> >
> Hi Eivind!
>
> Are things calming down now for you? :-)
>
> >I am looking for a way to store values at specified locations in
> flash, for
> >instance calibration values, serial number...etc...
> >I know that other compilers may use preprocessor directives to
> do this, but
> >I cant find the combination that does the trick with WinAVR...
> >The solution below seems to just add the data at the flash
> location wherever
> >code ends.
> >
> >Suggestions?
> >Cheers,
> >
> >Eivind
> >
> >
> >//
> >// Test for defining location of var in flash
> >//
> >// 1. Declare the array as below
> >//
> >// 2. Add the following link flags:
> >// -Wl,--section-start=.calib=0x100,--cref
> >//
> >// 3. Generate Intel Hex file using avr-objcopy
> >// Use the following flags:
> >// -j .text -j .data -j .calib
> >//
> >
> >#include <avr/io.h>
> >#include <avr/pgmspace.h>
> >
> >const unsigned char calval[] __attribute__ ((section
> (".calib"))) = {0xcd,
> >0xce};
> >
> >int main(void){
> >unsigned char *calvalP;
> >
> >calvalP = calval;
> >
> >}// end
> >
> >
> >
> Actually you're very close.
>
> Your declaration of calval with the attribute is correct.
>
> You need to change your main() code to below:
>
> int main(void)
> {
>     unsigned char mem_calval[2];
>
>     mem_calval[0] = (unsigned char)pgm_read_byte(&(calval[0]));
>     mem_calval[1] = (unsigned char)pgm_read_byte(&(calval[1]));
>
> }
>
> Remember that you are putting calval into the Program Memory, so the
> only way to read the value from there is to use the Program Space
> routines such as pgm_read_byte(). The argument is the *program space
> address* that you are reading from, hence: &(calval[0]). Technically you
> can also use pgm_read_word() to read out a word value. You can also use
> memcpy_P() to copy any size block of data from Program Memory to a
> RAM-based buffer.
>
> I *highly* recommend that you use the WinAVR Makefile template (or
> MFile). That way you don't have to be concerned about the commands to
> generate the hex file.
>
> Put this line in your Makefile, after the group of LDFLAGS variable
> settings:
> LDFLAGS += -Wl,--section-start=.calib=0x100
> Of course, change your address to the one desired.
>
> After you build your software, open up the .map file and you can see the
> .calib section at the correct address. Then open up the .hex file and
> you can even see the correct values at the correct address.
>
> HTH
> Eric
>
> PS. Many thanks to you and Erlend for getting the Freaks website back up!
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]