EmbeddedRelated.com
Forums

Write Flash via Firmware

Started by marcos_r_r May 11, 2012
It still makes no sense, if they are simply a variable that the user changes then just init the variable, but of course this is volatile.



If they need to be changed by the user without re-programming the flash then they need to be in a page that doesn’t contain any executable code and you need to erase and re-program that flash page to change them.



You cannot simply write a new value over flash whatever you do, you have to erase it first.



Placing an initialized value at a specific address is simple but is also not part of the language, it’s specific to the toolchain.



Generally it’s easiest to do this is assembler, but there are usually pragmas that enable a const to be placed in a specific section in C ( toolchain specific ), or using a linker script you can explicitly place a symbol at a fixed location( again linker specific ).



But there is no completely toolchain agnostic way to do this for a const.



Regards



Phil.



From: l... [mailto:l...] On Behalf Of m...@smartcar.ind.br
Sent: 15 May 2012 17:01
To: l...
Subject: Re: [lpc2000] Write Flash via Firmware





These are variables that can be changed in future by the User, but needs to leave the factory with a default value.

From: Wouter van Ooijen
Sent: Tuesday, May 15, 2012 12:14 PM
To: l...
Subject: Re: [lpc2000] Write Flash via Firmware

On 15/5/2012 4:52 PM, mailto:marcos%40smartcar.ind.br wrote:
> What I need is to define a fixed value in the flash memory through the
> code in C lpcxpresso?
> address=0x00007F00
> value=0x01

Why do you want that value *at that specific address*?

--

Wouter van Ooijen

-- -------
Van Ooijen Technische Informatica: www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: www.voti.nl/hvu
C++ on uC blog: http://www.voti.nl/erblog





An Engineer's Guide to the LPC2100 Series

Assuming that you are planning to include code to call the IAP to re-program the section, then you can assume at first boot that a device is uninitialized and make the code portable.

If you are not planning this then you misunderstand flash and should give up now.



It’s easy to define a fixed location for a variable using a pointer cast, so simply define a variable at that location and use the IAP code to initialize it at first boot.



Or even use a magic number



e.g





typedef struct {

unsigned MagicNumber;

unsigned Val1;

unsigned Val2.



...

} S1;



Now you can access a fixed location as S1 using pointer undirection and casting.



i.e.

*((S1*)Address)



At first boot test MagicNumber, if it is not set up than call your code that programs the structure.



S1 Temp;

Memcpy(&Temp,Address,sizeof(S1));

If(Temp.Address != ExpectedMagicNumber){

Update temp fields and set magic number

Call programming code

}







From: l... [mailto:l...] On Behalf Of M. Manca
Sent: 15 May 2012 17:38
To: l...
Subject: Re: [lpc2000] Write Flash via Firmware





Il 15/05/2012 18:00, m...@smartcar.ind.br ha scritto:
>
>
> These are variables that can be changed in future by the User, but
> needs to leave the factory with a default value.
>
With LpcXpresso the simplest way is define a reserved space on flash and
then access it as here:

typedef struct {
int32_t iOffset;
int16_t sMultiplier;
float fGain;
uint32_t qDelta;
} TSetup;

__attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
3241, 1.54, 0};

to define MSetup flash area:
from the ide: Project/Properties/C/C++ Build/MCU Settings and then edit
the memory app modifying the flash size i.e. 0x7f00 and adding a flash
segment named MSetup (without the point) starting from 0x7F00 and 0x100
bytes length.
This system uses the linker and the __attribute__ that is a GCC
extension but it is the best option you have if you don't require a 100%
ansi portable code (with other compilers you will need a
#if.....#elif....#end block because they don't use the same syntax.

>
> From: Wouter van Ooijen
> Sent: Tuesday, May 15, 2012 12:14 PM
> To: l...
> Subject: Re: [lpc2000] Write Flash via Firmware
>
> On 15/5/2012 4:52 PM, mailto:marcos%40smartcar.ind.br wrote:
> > What I need is to define a fixed value in the flash memory through the
> > code in C lpcxpresso?
> > address=0x00007F00
> > value=0x01
>
> Why do you want that value *at that specific address*?
>
> --
>
> Wouter van Ooijen
>
> -- -------
> Van Ooijen Technische Informatica: www.voti.nl
> consultancy, development, PICmicro products
> docent Hogeschool van Utrecht: www.voti.nl/hvu
> C++ on uC blog: http://www.voti.nl/erblog
>
>
>
>





Phil, we don't know what the application is and they may have excellent
reasons to do it this way (not the user but the factory before
shipment). For instance, if your product can ship to different countries
and the factory needs to set the default country setting just before
putting the device in the box. This way, they don't need to keep
different inventories.

My cent worth...
Cheers
Olivier

Phil Young wrote:
>
> It still makes no sense, if they are simply a variable that the user
> changes then just init the variable, but of course this is volatile.
>
> If they need to be changed by the user without re-programming the
> flash then they need to be in a page that doesn’t contain any
> executable code and you need to erase and re-program that flash page
> to change them.
>
> You cannot simply write a new value over flash whatever you do, you
> have to erase it first.
>
> Placing an initialized value at a specific address is simple but is
> also not part of the language, it’s specific to the toolchain.
>
> Generally it’s easiest to do this is assembler, but there are usually
> pragmas that enable a const to be placed in a specific section in C (
> toolchain specific ), or using a linker script you can explicitly
> place a symbol at a fixed location( again linker specific ).
>
> But there is no completely toolchain agnostic way to do this for a const.
>
> Regards
>
> Phil.
>
> From: l...
> [mailto:l... ] On
> Behalf Of m...@smartcar.ind.br
> Sent: 15 May 2012 17:01
> To: l...
> Subject: Re: [lpc2000] Write Flash via Firmware
>
> These are variables that can be changed in future by the User, but
> needs to leave the factory with a default value.
>
> From: Wouter van Ooijen
> Sent: Tuesday, May 15, 2012 12:14 PM
> To: l...
>
> Subject: Re: [lpc2000] Write Flash via Firmware
>
> On 15/5/2012 4:52 PM, mailto:marcos%40smartcar.ind.br wrote:
> > What I need is to define a fixed value in the flash memory through the
> > code in C lpcxpresso?
> > address=0x00007F00
> > value=0x01
>
> Why do you want that value *at that specific address*?
>
> --
>
> Wouter van Ooijen
>
> -- -------
> Van Ooijen Technische Informatica: www.voti.nl
> consultancy, development, PICmicro products
> docent Hogeschool van Utrecht: www.voti.nl/hvu
> C++ on uC blog: http://www.voti.nl/erblog
>
>
>
>
>
>
--

Olivier Gautherot
*Email:* o...@gautherot.net
*Cel:* +56 98 730 9361
*Web:* www.gautherot.net
*LinkedIn:* http://www.linkedin.com/in/ogautherot



In your example:
where is the value 0x01 at address 0x00007F00?

From: M. Manca
Sent: Tuesday, May 15, 2012 1:38 PM
To: l...
Subject: Re: [lpc2000] Write Flash via Firmware

Il 15/05/2012 18:00, mailto:marcos%40smartcar.ind.br ha scritto:
> These are variables that can be changed in future by the User, but
> needs to leave the factory with a default value.
>
With LpcXpresso the simplest way is define a reserved space on flash and
then access it as here:

typedef struct {
int32_t iOffset;
int16_t sMultiplier;
float fGain;
uint32_t qDelta;
} TSetup;

__attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
3241, 1.54, 0};

to define MSetup flash area:
from the ide: Project/Properties/C/C++ Build/MCU Settings and then edit
the memory app modifying the flash size i.e. 0x7f00 and adding a flash
segment named MSetup (without the point) starting from 0x7F00 and 0x100
bytes length.
This system uses the linker and the __attribute__ that is a GCC
extension but it is the best option you have if you don't require a 100%
ansi portable code (with other compilers you will need a
#if.....#elif....#end block because they don't use the same syntax.

>
> From: Wouter van Ooijen
> Sent: Tuesday, May 15, 2012 12:14 PM
> To: mailto:lpc2000%40yahoogroups.com
> Subject: Re: [lpc2000] Write Flash via Firmware
>
> On 15/5/2012 4:52 PM, mailto:marcos%40smartcar.ind.br wrote:
> > What I need is to define a fixed value in the flash memory through the
> > code in C lpcxpresso?
> > address=0x00007F00
> > value=0x01
>
> Why do you want that value *at that specific address*?
>
> --
>
> Wouter van Ooijen
>
> -- -------
> Van Ooijen Technische Informatica: www.voti.nl
> consultancy, development, PICmicro products
> docent Hogeschool van Utrecht: www.voti.nl/hvu
> C++ on uC blog: http://www.voti.nl/erblog
>
>





Marcos,

the following code (see __attribute__((...)) ) isolates the constants
into a separate section:

__attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
3241, 1.54, 0};

You then instruct the linker to store the (logical) section into a
(physical) section in the .ld script:

MEMORY {
...
FlashMSetup (rx) : ORIGIN = 0x7f00, LENGTH = 0x100 /* Note
that you surely meant "0x7f000", please check your implementation... */
...
}

SECTIONS {
...
.MSetup : ALIGN(4)
{
FILL(0xff)
__config = .; /* if you need to locate your section... otherwise
omit this line */
*(.MSetup)
}
...
} > FlashMSetup
That's all you need. Let me know if you need help to tweak your script.

Hope it helps
Olivier
m...@smartcar.ind.br wrote:
>
> In your example:
> where is the value 0x01 at address 0x00007F00?
>
> From: M. Manca
> Sent: Tuesday, May 15, 2012 1:38 PM
> To: l...
> Subject: Re: [lpc2000] Write Flash via Firmware
>
> Il 15/05/2012 18:00, mailto:marcos%40smartcar.ind.br ha scritto:
> >
> >
> > These are variables that can be changed in future by the User, but
> > needs to leave the factory with a default value.
> >
> With LpcXpresso the simplest way is define a reserved space on flash and
> then access it as here:
>
> typedef struct {
> int32_t iOffset;
> int16_t sMultiplier;
> float fGain;
> uint32_t qDelta;
> } TSetup;
>
> __attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
> 3241, 1.54, 0};
>
> to define MSetup flash area:
> from the ide: Project/Properties/C/C++ Build/MCU Settings and then edit
> the memory app modifying the flash size i.e. 0x7f00 and adding a flash
> segment named MSetup (without the point) starting from 0x7F00 and 0x100
> bytes length.
> This system uses the linker and the __attribute__ that is a GCC
> extension but it is the best option you have if you don't require a 100%
> ansi portable code (with other compilers you will need a
> #if.....#elif....#end block because they don't use the same syntax.
>
> >
> > From: Wouter van Ooijen
> > Sent: Tuesday, May 15, 2012 12:14 PM
> > To: mailto:lpc2000%40yahoogroups.com
> > Subject: Re: [lpc2000] Write Flash via Firmware
> >
> > On 15/5/2012 4:52 PM, mailto:marcos%40smartcar.ind.br wrote:
> > > What I need is to define a fixed value in the flash memory through the
> > > code in C lpcxpresso?
> > > address=0x00007F00
> > > value=0x01
> >
> > Why do you want that value *at that specific address*?
> >
> > --
> >
> > Wouter van Ooijen
> >
> > -- -------
> > Van Ooijen Technische Informatica: www.voti.nl
> > consultancy, development, PICmicro products
> > docent Hogeschool van Utrecht: www.voti.nl/hvu
> > C++ on uC blog: http://www.voti.nl/erblog
> >
> >
> >
> >
>
>
--

Olivier Gautherot
*Email:* o...@gautherot.net
*Cel:* +56 98 730 9361
*Web:* www.gautherot.net
*LinkedIn:* http://www.linkedin.com/in/ogautherot



In your example:
where is the value 0x01 at address 0x00007F00?

From: Olivier Gautherot
Sent: Tuesday, May 15, 2012 4:27 PM
To: m...@smartcar.ind.br
Cc: l...
Subject: Re: [lpc2000] Write Flash via Firmware

Marcos,

the following code (see __attribute__((...)) ) isolates the constants
into a separate section:

__attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
3241, 1.54, 0};

You then instruct the linker to store the (logical) section into a
(physical) section in the .ld script:

MEMORY {
...
FlashMSetup (rx) : ORIGIN = 0x7f00, LENGTH = 0x100 /* Note
that you surely meant "0x7f000", please check your implementation... */
...
}

SECTIONS {
...
.MSetup : ALIGN(4)
{
FILL(0xff)
__config = .; /* if you need to locate your section... otherwise
omit this line */
*(.MSetup)
}
...
} > FlashMSetup

That's all you need. Let me know if you need help to tweak your script.

Hope it helps
Olivier

mailto:marcos%40smartcar.ind.br wrote:
>
> In your example:
> where is the value 0x01 at address 0x00007F00?
>
> From: M. Manca
> Sent: Tuesday, May 15, 2012 1:38 PM
> To: mailto:lpc2000%40yahoogroups.com
> Subject: Re: [lpc2000] Write Flash via Firmware
>
> Il 15/05/2012 18:00, mailto:marcos%40smartcar.ind.br ha scritto:
> >
> >
> > These are variables that can be changed in future by the User, but
> > needs to leave the factory with a default value.
> >
> With LpcXpresso the simplest way is define a reserved space on flash and
> then access it as here:
>
> typedef struct {
> int32_t iOffset;
> int16_t sMultiplier;
> float fGain;
> uint32_t qDelta;
> } TSetup;
>
> __attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
> 3241, 1.54, 0};
>
> to define MSetup flash area:
> from the ide: Project/Properties/C/C++ Build/MCU Settings and then edit
> the memory app modifying the flash size i.e. 0x7f00 and adding a flash
> segment named MSetup (without the point) starting from 0x7F00 and 0x100
> bytes length.
> This system uses the linker and the __attribute__ that is a GCC
> extension but it is the best option you have if you don't require a 100%
> ansi portable code (with other compilers you will need a
> #if.....#elif....#end block because they don't use the same syntax.
>
> >
> > From: Wouter van Ooijen
> > Sent: Tuesday, May 15, 2012 12:14 PM
> > To: mailto:lpc2000%40yahoogroups.com
> > Subject: Re: [lpc2000] Write Flash via Firmware
> >
> > On 15/5/2012 4:52 PM, mailto:marcos%40smartcar.ind.br wrote:
> > > What I need is to define a fixed value in the flash memory through the
> > > code in C lpcxpresso?
> > > address=0x00007F00
> > > value=0x01
> >
> > Why do you want that value *at that specific address*?
> >
> > --
> >
> > Wouter van Ooijen
> >
> > -- -------
> > Van Ooijen Technische Informatica: www.voti.nl
> > consultancy, development, PICmicro products
> > docent Hogeschool van Utrecht: www.voti.nl/hvu
> > C++ on uC blog: http://www.voti.nl/erblog
> >
> >
> >
> >
>
>

--

Olivier Gautherot
*Email:* mailto:olivier%40gautherot.net
*Cel:* +56 98 730 9361
*Web:* www.gautherot.net
*LinkedIn:* http://www.linkedin.com/in/ogautherot





Il 15/05/2012 21:27, Olivier Gautherot ha scritto:
>
>
> Marcos,
>
> the following code (see __attribute__((...)) ) isolates the constants
> into a separate section:
>
> __attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
> 3241, 1.54, 0};
>
> You then instruct the linker to store the (logical) section into a
> (physical) section in the .ld script:
>
Using LpcXpresso 4 it is better to use the Project/.... menu because
LpcXpresso when you rebuild all changes the ld files (because it desn't
check about user modifications); there is a flag around the enus but I
didn't remember where to block LpcXpresso to change the ld files at
verey rebuild all.

If you use the Project/... menu it doesn't happen because LpcXpresso
knows that you modified the memory map (there is a file to manage the
setup but I didn't remember its name).
>
> MEMORY {
> ...
> FlashMSetup (rx) : ORIGIN = 0x7f00, LENGTH = 0x100 /* Note
> that you surely meant "0x7f000", please check your implementation... */
> ...
> }
>
Olivier, 0x7F00 is correct because in LPC11xx flash starts at 0x0000 and
is 32KB length, so if you would reserve 256 bytes (the last 256) it is
correct.
> SECTIONS {
> ...
> .MSetup : ALIGN(4)
> {
> FILL(0xff)
> __config = .; /* if you need to locate your section... otherwise
> omit this line */
> *(.MSetup)
> }
> ...
> } > FlashMSetup
>
> That's all you need. Let me know if you need help to tweak your script.
>
> Hope it helps
> Olivier
>
> m...@smartcar.ind.br wrote:
> >
> > In your example:
> > where is the value 0x01 at address 0x00007F00?
> >
> > From: M. Manca
> > Sent: Tuesday, May 15, 2012 1:38 PM
> > To: l...
>
> > Subject: Re: [lpc2000] Write Flash via Firmware
> >
> > Il 15/05/2012 18:00, mailto:marcos%40smartcar.ind.br ha scritto:
> > >
> > >
> > > These are variables that can be changed in future by the User, but
> > > needs to leave the factory with a default value.
> > >
> > With LpcXpresso the simplest way is define a reserved space on flash and
> > then access it as here:
> >
> > typedef struct {
> > int32_t iOffset;
> > int16_t sMultiplier;
> > float fGain;
> > uint32_t qDelta;
> > } TSetup;
> >
> > __attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
> > 3241, 1.54, 0};
> >
> > to define MSetup flash area:
> > from the ide: Project/Properties/C/C++ Build/MCU Settings and then edit
> > the memory app modifying the flash size i.e. 0x7f00 and adding a flash
> > segment named MSetup (without the point) starting from 0x7F00 and 0x100
> > bytes length.
> > This system uses the linker and the __attribute__ that is a GCC
> > extension but it is the best option you have if you don't require a 100%
> > ansi portable code (with other compilers you will need a
> > #if.....#elif....#end block because they don't use the same syntax.
> >
> > >
> > > From: Wouter van Ooijen
> > > Sent: Tuesday, May 15, 2012 12:14 PM
> > > To: mailto:lpc2000%40yahoogroups.com
>
> > > Subject: Re: [lpc2000] Write Flash via Firmware
> > >
> > > On 15/5/2012 4:52 PM, mailto:marcos%40smartcar.ind.br wrote:
> > > > What I need is to define a fixed value in the flash memory
> through the
> > > > code in C lpcxpresso?
> > > > address=0x00007F00
> > > > value=0x01
> > >
> > > Why do you want that value *at that specific address*?
> > >
> > > --
> > >
> > > Wouter van Ooijen
> > >
> > > -- -------
> > > Van Ooijen Technische Informatica: www.voti.nl
> > > consultancy, development, PICmicro products
> > > docent Hogeschool van Utrecht: www.voti.nl/hvu
> > > C++ on uC blog: http://www.voti.nl/erblog
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> > --
>
> Olivier Gautherot
> *Email:* o...@gautherot.net
> *Cel:* +56 98 730 9361
> *Web:* www.gautherot.net
> *LinkedIn:* http://www.linkedin.com/in/ogautherot
>
>



Il 15/05/2012 21:05, m...@smartcar.ind.br ha scritto:
>
>
> In your example:
> where is the value 0x01 at address 0x00007F00?
>
No Marcos, I make a copy and paste of an old test I made to see if the
LpcXpresso 4 worked ok defining a flash segment using its GUI.
I suppose that 0x01 for you is a char or a byte ok? Then this is the
solution:

__attribute__ ((section(".MSetup"))) const unsigned char byteTest = 0x01;

if you need to write just 1 data this is not the best solution, but it
is the more flexible because you may use its syntax every where in the
code and will be the compiler to allocate correctly the memory in the
order it will find the constants declarations. This means that 0x01 will
be written at 0x7F00 and:

__attribute__ ((section(".MSetup"))) const unsigned int intTest 0x12345678;

will be written at 0x7f01, 0x7f02, 0x7f03 and 0x7f04.

>
> From: M. Manca
> Sent: Tuesday, May 15, 2012 1:38 PM
> To: l...
> Subject: Re: [lpc2000] Write Flash via Firmware
>
> Il 15/05/2012 18:00, mailto:marcos%40smartcar.ind.br ha scritto:
> >
> >
> > These are variables that can be changed in future by the User, but
> > needs to leave the factory with a default value.
> >
> With LpcXpresso the simplest way is define a reserved space on flash and
> then access it as here:
>
> typedef struct {
> int32_t iOffset;
> int16_t sMultiplier;
> float fGain;
> uint32_t qDelta;
> } TSetup;
>
> __attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
> 3241, 1.54, 0};
>
> to define MSetup flash area:
> from the ide: Project/Properties/C/C++ Build/MCU Settings and then edit
> the memory app modifying the flash size i.e. 0x7f00 and adding a flash
> segment named MSetup (without the point) starting from 0x7F00 and 0x100
> bytes length.
> This system uses the linker and the __attribute__ that is a GCC
> extension but it is the best option you have if you don't require a 100%
> ansi portable code (with other compilers you will need a
> #if.....#elif....#end block because they don't use the same syntax.
>
> >
> > From: Wouter van Ooijen
> > Sent: Tuesday, May 15, 2012 12:14 PM
> > To: mailto:lpc2000%40yahoogroups.com
> > Subject: Re: [lpc2000] Write Flash via Firmware
> >
> > On 15/5/2012 4:52 PM, mailto:marcos%40smartcar.ind.br wrote:
> > > What I need is to define a fixed value in the flash memory through the
> > > code in C lpcxpresso?
> > > address=0x00007F00
> > > value=0x01
> >
> > Why do you want that value *at that specific address*?
> >
> > --
> >
> > Wouter van Ooijen
> >
> > -- -------
> > Van Ooijen Technische Informatica: www.voti.nl
> > consultancy, development, PICmicro products
> > docent Hogeschool van Utrecht: www.voti.nl/hvu
> > C++ on uC blog: http://www.voti.nl/erblog
> >
> >
> >
> >
>
>



The option is on the Linker "Target" page - uncheck the Manage Linker Scripts option - you are then in control.

--- In l..., "M. Manca" wrote:
>
> Il 15/05/2012 21:27, Olivier Gautherot ha scritto:
> >
> >
> > Marcos,
> >
> > the following code (see __attribute__((...)) ) isolates the constants
> > into a separate section:
> >
> > __attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
> > 3241, 1.54, 0};
> >
> > You then instruct the linker to store the (logical) section into a
> > (physical) section in the .ld script:
> >
> Using LpcXpresso 4 it is better to use the Project/.... menu because
> LpcXpresso when you rebuild all changes the ld files (because it desn't
> check about user modifications); there is a flag around the enus but I
> didn't remember where to block LpcXpresso to change the ld files at
> verey rebuild all.
>
> If you use the Project/... menu it doesn't happen because LpcXpresso
> knows that you modified the memory map (there is a file to manage the
> setup but I didn't remember its name).
> >
> > MEMORY {
> > ...
> > FlashMSetup (rx) : ORIGIN = 0x7f00, LENGTH = 0x100 /* Note
> > that you surely meant "0x7f000", please check your implementation... */
> > ...
> > }
> >
> Olivier, 0x7F00 is correct because in LPC11xx flash starts at 0x0000 and
> is 32KB length, so if you would reserve 256 bytes (the last 256) it is
> correct.
> >
> >
> > SECTIONS {
> > ...
> > .MSetup : ALIGN(4)
> > {
> > FILL(0xff)
> > __config = .; /* if you need to locate your section... otherwise
> > omit this line */
> > *(.MSetup)
> > }
> > ...
> > } > FlashMSetup
> >
> > That's all you need. Let me know if you need help to tweak your script.
> >
> > Hope it helps
> > Olivier
> >
> > marcos@... wrote:
> > >
> > > In your example:
> > > where is the value 0x01 at address 0x00007F00?
> > >
> > > From: M. Manca
> > > Sent: Tuesday, May 15, 2012 1:38 PM
> > > To: l...
> >
> > > Subject: Re: [lpc2000] Write Flash via Firmware
> > >
> > > Il 15/05/2012 18:00, mailto:marcos%40smartcar.ind.br ha scritto:
> > > >
> > > >
> > > > These are variables that can be changed in future by the User, but
> > > > needs to leave the factory with a default value.
> > > >
> > > With LpcXpresso the simplest way is define a reserved space on flash and
> > > then access it as here:
> > >
> > > typedef struct {
> > > int32_t iOffset;
> > > int16_t sMultiplier;
> > > float fGain;
> > > uint32_t qDelta;
> > > } TSetup;
> > >
> > > __attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
> > > 3241, 1.54, 0};
> > >
> > > to define MSetup flash area:
> > > from the ide: Project/Properties/C/C++ Build/MCU Settings and then edit
> > > the memory app modifying the flash size i.e. 0x7f00 and adding a flash
> > > segment named MSetup (without the point) starting from 0x7F00 and 0x100
> > > bytes length.
> > > This system uses the linker and the __attribute__ that is a GCC
> > > extension but it is the best option you have if you don't require a 100%
> > > ansi portable code (with other compilers you will need a
> > > #if.....#elif....#end block because they don't use the same syntax.
> > >
> > > >
> > > > From: Wouter van Ooijen
> > > > Sent: Tuesday, May 15, 2012 12:14 PM
> > > > To: mailto:lpc2000%40yahoogroups.com
> >
> > > > Subject: Re: [lpc2000] Write Flash via Firmware
> > > >
> > > > On 15/5/2012 4:52 PM, mailto:marcos%40smartcar.ind.br wrote:
> > > > > What I need is to define a fixed value in the flash memory
> > through the
> > > > > code in C lpcxpresso?
> > > > > address=0x00007F00
> > > > > value=0x01
> > > >
> > > > Why do you want that value *at that specific address*?
> > > >
> > > > --
> > > >
> > > > Wouter van Ooijen
> > > >
> > > > -- -------
> > > > Van Ooijen Technische Informatica: www.voti.nl
> > > > consultancy, development, PICmicro products
> > > > docent Hogeschool van Utrecht: www.voti.nl/hvu
> > > > C++ on uC blog: http://www.voti.nl/erblog
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> > --
> >
> > Olivier Gautherot
> > *Email:* olivier@...
> > *Cel:* +56 98 730 9361
> > *Web:* www.gautherot.net
> > *LinkedIn:* http://www.linkedin.com/in/ogautherot
> >
> >
> >
> >
>

Please find attached the error that occurs when you display the Debug and programming of the flash.

Error:

Command failed: target extended-remote |crt_emu_lpc11_13_nxp –g –mi –2 –pLPC1114/302 –vendor=NXP - wire=hid – msg-port=50908

************************************************************************************
MEMORY
{
/* Define each memory region */
MFlash32 (rx) : ORIGIN = 0x0, LENGTH = 0x7f00 /* 31k */
MSetup (rx) : ORIGIN = 0x7f00, LENGTH = 0x100 /* 0k */
RamLoc8 (rwx) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* 8k */

}
/* Define a symbol for the top of each memory region */
__top_MFlash32 = 0x0 + 0x7f00;
__top_MSetup = 0x7f00 + 0x100;
__top_RamLoc8 = 0x10000000 + 0x2000;

SECTIONS
{

.text_Flash2 : ALIGN(4)
{
FILL(0xff)
*(.text_Flash2*)
*(.text_MSetup*)
} > MSetup

/* MAIN TEXT SECTION */
.text : ALIGN(4)
{
FILL(0xff)
KEEP(*(.isr_vector))

/* Global Section Table */
. = ALIGN(4) ;
__section_table_start = .;
__data_section_table = .;
LONG(LOADADDR(.data));
LONG( ADDR(.data)) ;
LONG( SIZEOF(.data));
__data_section_table_end = .;
__bss_section_table = .;
LONG( ADDR(.bss));
LONG( SIZEOF(.bss));
__bss_section_table_end = .;
__section_table_end = . ;
/* End of Global Section Table */


*(.after_vectors*)

/* Code Read Protect data */
. = 0x000002FC ;
PROVIDE(__CRP_WORD_START__ = .) ;
KEEP(*(.crp))
PROVIDE(__CRP_WORD_END__ = .) ;
ASSERT(!(__CRP_WORD_START__ == __CRP_WORD_END__), "Linker CRP Enabled, but no CRP_WORD provided within application");
/* End of Code Read Protect */

*(.text*)
*(.rodata .rodata.*)
. = ALIGN(4);

} > MFlash32

/*
* for exception handling/unwind - some Newlib functions (in common
* with C++ and STDC++) use this.
*/
.ARM.extab : ALIGN(4)
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > MFlash32
__exidx_start = .;

.ARM.exidx : ALIGN(4)
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > MFlash32
__exidx_end = .;

_etext = .;


/* MAIN DATA SECTION */

.uninit_RESERVED : ALIGN(4)
{
KEEP(*(.bss.$RESERVED*))
} > RamLoc8

.data : ALIGN(4)
{
FILL(0xff)
_data = .;
*(vtable)
*(.data*)
. = ALIGN(4) ;
_edata = .;
} > RamLoc8 AT>MFlash32
/* MAIN BSS SECTION */
.bss : ALIGN(4)
{
_bss = .;
*(.bss*)
*(COMMON)
. = ALIGN(4) ;
_ebss = .;
PROVIDE(end = .);
} > RamLoc8

PROVIDE(_pvHeapStart = .);
PROVIDE(_vStackTop = __top_RamLoc8 - 0);
}

From: M. Manca
Sent: Tuesday, May 15, 2012 5:23 PM
To: l...
Subject: Re: [lpc2000] Write Flash via Firmware


Il 15/05/2012 21:05, mailto:marcos%40smartcar.ind.br ha scritto:
>
>
> In your example:
> where is the value 0x01 at address 0x00007F00?
>
No Marcos, I make a copy and paste of an old test I made to see if the
LpcXpresso 4 worked ok defining a flash segment using its GUI.
I suppose that 0x01 for you is a char or a byte ok? Then this is the
solution:

__attribute__ ((section(".MSetup"))) const unsigned char byteTest = 0x01;

if you need to write just 1 data this is not the best solution, but it
is the more flexible because you may use its syntax every where in the
code and will be the compiler to allocate correctly the memory in the
order it will find the constants declarations. This means that 0x01 will
be written at 0x7F00 and:

__attribute__ ((section(".MSetup"))) const unsigned int intTest =
0x12345678;

will be written at 0x7f01, 0x7f02, 0x7f03 and 0x7f04.

>
> From: M. Manca
> Sent: Tuesday, May 15, 2012 1:38 PM
> To: mailto:lpc2000%40yahoogroups.com
> Subject: Re: [lpc2000] Write Flash via Firmware
>
> Il 15/05/2012 18:00, mailto:marcos%40smartcar.ind.br ha scritto:
> >
> >
> > These are variables that can be changed in future by the User, but
> > needs to leave the factory with a default value.
> >
> With LpcXpresso the simplest way is define a reserved space on flash and
> then access it as here:
>
> typedef struct {
> int32_t iOffset;
> int16_t sMultiplier;
> float fGain;
> uint32_t qDelta;
> } TSetup;
>
> __attribute__ ((section(".MSetup"))) const TSetup recSetupData = { 1278,
> 3241, 1.54, 0};
>
> to define MSetup flash area:
> from the ide: Project/Properties/C/C++ Build/MCU Settings and then edit
> the memory app modifying the flash size i.e. 0x7f00 and adding a flash
> segment named MSetup (without the point) starting from 0x7F00 and 0x100
> bytes length.
> This system uses the linker and the __attribute__ that is a GCC
> extension but it is the best option you have if you don't require a 100%
> ansi portable code (with other compilers you will need a
> #if.....#elif....#end block because they don't use the same syntax.
>
> >
> > From: Wouter van Ooijen
> > Sent: Tuesday, May 15, 2012 12:14 PM
> > To: mailto:lpc2000%40yahoogroups.com
> > Subject: Re: [lpc2000] Write Flash via Firmware
> >
> > On 15/5/2012 4:52 PM, mailto:marcos%40smartcar.ind.br wrote:
> > > What I need is to define a fixed value in the flash memory through the
> > > code in C lpcxpresso?
> > > address=0x00007F00
> > > value=0x01
> >
> > Why do you want that value *at that specific address*?
> >
> > --
> >
> > Wouter van Ooijen
> >
> > -- -------
> > Van Ooijen Technische Informatica: www.voti.nl
> > consultancy, development, PICmicro products
> > docent Hogeschool van Utrecht: www.voti.nl/hvu
> > C++ on uC blog: http://www.voti.nl/erblog
> >
> >
> >
> >
>
>
>
>