Hi,
In my application, I use the built-in flash memory of the F249 to log some
information. For now, I look at the link map to find out where to start writing
my log (beginning of the first unused flash segment, after the end of the CODE
segment).
Is there a way to determine this adress automatically ? I'm using IAR
EWB.
Thanks,
Patrick
How to automatically find the start adress of the first unused flash segment ?
Started by ●January 12, 2010
Reply by ●January 12, 20102010-01-12
If it is erased, it will contain only $FF for a large block.
Emmett Redd, Ph.D., Professor mailto:E...@MissouriState.Edu
Physics, Astronomy, and Materials Science Office: 417-836-5221
Missouri State University Dept: 417-838-5131
901 S NATIONAL AVENUE FAX: 417-836-6226
SPRINGFIELD, MO 65897 USA
-----Original Message-----
From: m... [mailto:m...] On Behalf Of distantship101
Sent: Tuesday, January 12, 2010 11:30 AM
To: m...
Subject: [msp430] How to automatically find the start adress of the first unused flash segment ?
Hi,
In my application, I use the built-in flash memory of the F249 to log some information. For now, I look at the link map to find out where to start writing my log (beginning of the first unused flash segment, after the end of the CODE segment).
Is there a way to determine this adress automatically ? I'm using IAR EWB.
Thanks,
Patrick
Emmett Redd, Ph.D., Professor mailto:E...@MissouriState.Edu
Physics, Astronomy, and Materials Science Office: 417-836-5221
Missouri State University Dept: 417-838-5131
901 S NATIONAL AVENUE FAX: 417-836-6226
SPRINGFIELD, MO 65897 USA
-----Original Message-----
From: m... [mailto:m...] On Behalf Of distantship101
Sent: Tuesday, January 12, 2010 11:30 AM
To: m...
Subject: [msp430] How to automatically find the start adress of the first unused flash segment ?
Hi,
In my application, I use the built-in flash memory of the F249 to log some information. For now, I look at the link map to find out where to start writing my log (beginning of the first unused flash segment, after the end of the CODE segment).
Is there a way to determine this adress automatically ? I'm using IAR EWB.
Thanks,
Patrick
Reply by ●January 12, 20102010-01-12
I think it should be possible to declare a segment for your log, then
read the end of code segment and round it up modulo-512 (ie. set for the
next empty sector) - and then assign the linker segment 'log' to it.
So, on startup you will have a segment available called log where your C
code can start logging onto.
I haven't used IAR in a long time, but I can't see why you couldn't put
that in your linker xcl file.
HTH
B rgds
Kris
On Tue, 2010-01-12 at 17:29 +0000, distantship101 wrote:
> Hi,
>
> In my application, I use the built-in flash memory of the F249 to log some information. For now, I look at the link map to find out where to start writing my log (beginning of the first unused flash segment, after the end of the CODE segment).
>
> Is there a way to determine this adress automatically ? I'm using IAR EWB.
>
> Thanks,
>
> Patrick
>
>
read the end of code segment and round it up modulo-512 (ie. set for the
next empty sector) - and then assign the linker segment 'log' to it.
So, on startup you will have a segment available called log where your C
code can start logging onto.
I haven't used IAR in a long time, but I can't see why you couldn't put
that in your linker xcl file.
HTH
B rgds
Kris
On Tue, 2010-01-12 at 17:29 +0000, distantship101 wrote:
> Hi,
>
> In my application, I use the built-in flash memory of the F249 to log some information. For now, I look at the link map to find out where to start writing my log (beginning of the first unused flash segment, after the end of the CODE segment).
>
> Is there a way to determine this adress automatically ? I'm using IAR EWB.
>
> Thanks,
>
> Patrick
>
>
Reply by ●January 13, 20102010-01-13
Patrick,
I have a simple idea that might work for you.
I made these modifications to the linker file
c:\...\430\config\lnk430F249.xcl file (make sure you make a backup copy of
the file)
// ---------------------
// Code
// ---------------------
-Z(CODE)CSTART,ISR_CODE,CODE00-FFBF
-Z(CONST)jcrSegment
//-P(CODE)CODE00-FFBF
To test this idea, I used the demo msp430x24x_flashwrite_01.c as a base.
I created two arrays in the C-code using this pragma directive placed before
void main()
#pragma dataseg=__data16 jcrSegment
__no_init int jcrFlashC[512];
__no_init int jcrFlashD[512];
#pragma datasegault
I was then able to use them like normal arrays in the C code:
int *Flash_ptrC; // Segment C pointer
int *Flash_ptrD; // Segment D pointer
...
Flash_ptrC = jcrFlashC;
Flash_ptrD = jcrFlashD;
...
*Flash_ptrC++ = value;
...
My test was done only in a simulation-mode - but the arrays updated
correctly and the pointer's addresses matched the segment addresses from the
map output. No compiler or linker errors.
My map output looked like this
.
*Segments in Address Order*SegmentSpaceStartEndSizeKindAlignDATA16_AN0056 -
00572Relative00120 - 012120128 - 012D6DATA16_I0200Predefined0DATA16_Z0200 -
02012Relative1CSTACK09B0 - 09FF50Relative1DATA16_AN10FE - 10FF2Relative0
CSTART1100 - 111718Relative1ISR_CODE1118Predefined0CODE1118 - 11FDE6Relative
1jcrSegment11FE - 19FD800Relative1RESETFFFE - FFFF2Relative1
.
This seems to keep the *jcrSegmen*t always at the end of the *CODE* segment
and no matter what size data I used (char,int,long,etc) or how big my code
became - it automatically adjusted the jcrSegment start and size.
A few notes:
In all fairness - I didn't beat up this code too hard - I just made quick
demo just to see if it would work.
You may want to talk with the IAR experts - they may have a better way of
doing this.
Also - I don't know all of the pitfalls with changing the CODE segment from
a sequential -Z to a random -P placement. It seems that you might lose some
efficiency in the memory placement.
You also may want to experiment with the __data16 in the pragma directive
and use __data20 instead.
Last - I didn't figure out how to elegantly jump to the start of a new 512
segment without alot of pointer math. I have the 512 size - but it's
relative to the end of the CODE segment. Pencils down.
Best Regards,
Juan Carlos
On Tue, Jan 12, 2010 at 12:31 PM, distantship101 wrote:
> Hi,
>
> In my application, I use the built-in flash memory of the F249 to log some
> information. For now, I look at the link map to find out where to start
> writing my log (beginning of the first unused flash segment, after the end
> of the CODE segment).
>
> Is there a way to determine this adress automatically ? I'm using IAR EWB.
>
> Thanks,
>
> Patrick
>
>
>
I have a simple idea that might work for you.
I made these modifications to the linker file
c:\...\430\config\lnk430F249.xcl file (make sure you make a backup copy of
the file)
// ---------------------
// Code
// ---------------------
-Z(CODE)CSTART,ISR_CODE,CODE00-FFBF
-Z(CONST)jcrSegment
//-P(CODE)CODE00-FFBF
To test this idea, I used the demo msp430x24x_flashwrite_01.c as a base.
I created two arrays in the C-code using this pragma directive placed before
void main()
#pragma dataseg=__data16 jcrSegment
__no_init int jcrFlashC[512];
__no_init int jcrFlashD[512];
#pragma datasegault
I was then able to use them like normal arrays in the C code:
int *Flash_ptrC; // Segment C pointer
int *Flash_ptrD; // Segment D pointer
...
Flash_ptrC = jcrFlashC;
Flash_ptrD = jcrFlashD;
...
*Flash_ptrC++ = value;
...
My test was done only in a simulation-mode - but the arrays updated
correctly and the pointer's addresses matched the segment addresses from the
map output. No compiler or linker errors.
My map output looked like this
.
*Segments in Address Order*SegmentSpaceStartEndSizeKindAlignDATA16_AN0056 -
00572Relative00120 - 012120128 - 012D6DATA16_I0200Predefined0DATA16_Z0200 -
02012Relative1CSTACK09B0 - 09FF50Relative1DATA16_AN10FE - 10FF2Relative0
CSTART1100 - 111718Relative1ISR_CODE1118Predefined0CODE1118 - 11FDE6Relative
1jcrSegment11FE - 19FD800Relative1RESETFFFE - FFFF2Relative1
.
This seems to keep the *jcrSegmen*t always at the end of the *CODE* segment
and no matter what size data I used (char,int,long,etc) or how big my code
became - it automatically adjusted the jcrSegment start and size.
A few notes:
In all fairness - I didn't beat up this code too hard - I just made quick
demo just to see if it would work.
You may want to talk with the IAR experts - they may have a better way of
doing this.
Also - I don't know all of the pitfalls with changing the CODE segment from
a sequential -Z to a random -P placement. It seems that you might lose some
efficiency in the memory placement.
You also may want to experiment with the __data16 in the pragma directive
and use __data20 instead.
Last - I didn't figure out how to elegantly jump to the start of a new 512
segment without alot of pointer math. I have the 512 size - but it's
relative to the end of the CODE segment. Pencils down.
Best Regards,
Juan Carlos
On Tue, Jan 12, 2010 at 12:31 PM, distantship101 wrote:
> Hi,
>
> In my application, I use the built-in flash memory of the F249 to log some
> information. For now, I look at the link map to find out where to start
> writing my log (beginning of the first unused flash segment, after the end
> of the CODE segment).
>
> Is there a way to determine this adress automatically ? I'm using IAR EWB.
>
> Thanks,
>
> Patrick
>
>
>
Reply by ●January 13, 20102010-01-13
Hi,
Thank you all for your replies. I followed Juan Carlos' suggestion, and it seems to work. It turns out the alignment can be specified when defining the segment :
// ---------------------
// Code
// ---------------------
-Z(CODE)CSTART,ISR_CODE,CODE00-FFBF
-Z(CONST)SB_LOG_SEG=[1100-FFDB]/200
This is the map output by the linker :
CODE 1392 - 4929
SB_LOG_SEG 4A00 - 4BFF
Using -Z for CODE instead of -P doesn't seem to make any difference in my case.
Thanks again !
Patrick
Thank you all for your replies. I followed Juan Carlos' suggestion, and it seems to work. It turns out the alignment can be specified when defining the segment :
// ---------------------
// Code
// ---------------------
-Z(CODE)CSTART,ISR_CODE,CODE00-FFBF
-Z(CONST)SB_LOG_SEG=[1100-FFDB]/200
This is the map output by the linker :
CODE 1392 - 4929
SB_LOG_SEG 4A00 - 4BFF
Using -Z for CODE instead of -P doesn't seem to make any difference in my case.
Thanks again !
Patrick
Reply by ●January 13, 20102010-01-13
distantship101 wrote:
>
>
> Hi,
>
> In my application, I use the built-in flash memory of the F249 to log
> some information. For now, I look at the link map to find out where to
> start writing my log (beginning of the first unused flash segment, after
> the end of the CODE segment).
>
> Is there a way to determine this adress automatically ? I'm using IAR EWB.
Yes, you can use the "#pragma segment" macro in conjunction with the
intrinsics "__segment_begin" and "__segment_end". For example:
-------------------------
#pragma segment="CODE"
void * test()
{
return __segment_end("CODE");
}
-------------------------
Note: The compiler provide a number of pragmas for backward
compatibility, like "#pragma dataseg". I wouldn't recommend using them
in new code.
-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
>
>
> Hi,
>
> In my application, I use the built-in flash memory of the F249 to log
> some information. For now, I look at the link map to find out where to
> start writing my log (beginning of the first unused flash segment, after
> the end of the CODE segment).
>
> Is there a way to determine this adress automatically ? I'm using IAR EWB.
Yes, you can use the "#pragma segment" macro in conjunction with the
intrinsics "__segment_begin" and "__segment_end". For example:
-------------------------
#pragma segment="CODE"
void * test()
{
return __segment_end("CODE");
}
-------------------------
Note: The compiler provide a number of pragmas for backward
compatibility, like "#pragma dataseg". I wouldn't recommend using them
in new code.
-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.