EmbeddedRelated.com
Forums

Write Flash via Firmware

Started by marcos_r_r May 11, 2012
On 5/13/2012 1:14 PM, m...@smartcar.ind.br wrote:
> How do to fix the value in memory flash ARM via code in C LPCXpresso?

The example I showed you will fix a value in memory using any C compiler
for an ARM micro as far as I know.

Robert

--

From the Divided by a Common Language File (Edited to protect the guilty)
ME - "I'd like to get Price and delivery for connector Part # XXXXX"
Dist./Rep - "$X.XX Lead time 37 days"
ME - "Anything we can do about lead time? 37 days seems a bit high."
Dist./Rep - "that is the lead time given because our stock is live....
we currently have stock."

An Engineer's Guide to the LPC2100 Series

On 13/5/2012 7:14 PM, m...@smartcar.ind.br wrote:
> How do to fix the value in memory flash ARM via code in C LPCXpresso?

'fix' is not a very exact word in this context.

fix == change (during execution): forget it, you can't do that with a
simple C statement, you will have to use the ISP interface.

fix == locate a const-variable at a specific place? Can be done, but why
on earth would you want that?

--

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

Hi,

First you need to understand what compiler/linker you use and read manual for this compiler.
LPCXpresso is just PCB with ARM controller from NXP.
Something tells me that you use GCC under Eclipse from "Code Red Tec", or?
So, it looks that magic word is GCC.
Does it help?

Best regards
Vlad

----- Original Message -----
From: m...@smartcar.ind.br
To: l...
Sent: Sunday, May 13, 2012 8:14 PM
Subject: Re: [lpc2000] Write Flash via Firmware

How do to fix the value in memory flash ARM via code in C LPCXpresso?

From: Robert Adsett
Sent: Sunday, May 13, 2012 12:38 PM
To: l...
Subject: Re: [lpc2000] Write Flash via Firmware

On 5/13/2012 11:21 AM, mailto:marcos%40smartcar.ind.br wrote:
> I had already understood this well, my doubt is another.
> What is the statement in C that writes to a given address of the flash, but not via firmware, but saw lpcxpresso.
> In the PIC instução is this:
> ORG 0X210D //address
> DE "test123"; //DE = instruction test123=text to be written

You are mistaken about what DE does.

From Microchips manual
http://ww1.microchip.com/downloads/en/devicedoc/33014j.pdf

de – DECLARE EEPROM DATA BYTE

It does not write to anywhere. It simply sets up a value in the image
that is downloaded to the device.

The equivalent in C is

const int c=230;

It's not ARM specific, although some compilers on some processors
provide extensions to C to allow placement in different memory areas.

To place it at a specific address requires either assembly, some work
with the linker or a compiler specific extension. And there are few
occasions when it is necessary to fix a constants location in memory.

Robert

--

From the Divided by a Common Language File (Edited to protect the guilty)
ME - "I'd like to get Price and delivery for connector Part # XXXXX"
Dist./Rep - "$X.XX Lead time 37 days"
ME - "Anything we can do about lead time? 37 days seems a bit high."
Dist./Rep - "that is the lead time given because our stock is live....
we currently have stock."







On 5/13/2012 1:42 PM, Wouter van Ooijen wrote:
> On 13/5/2012 7:14 PM, m...@smartcar.ind.br wrote:
>> How do to fix the value in memory flash ARM via code in C LPCXpresso?
>
> 'fix' is not a very exact word in this context.
>
> fix == change (during execution): forget it, you can't do that with a
> simple C statement, you will have to use the ISP interface.

Or as I read it

fix == place in memory at compile time as a read only value at run-time.
Like fixing a negative.

> fix == locate a const-variable at a specific place? Can be done, but why
> on earth would you want that?

Yes, if that is what was meant then that's the first question to be
asked. There's probably a better way reach the end goal.

Robert

--

From the Divided by a Common Language File (Edited to protect the guilty)
ME - "I'd like to get Price and delivery for connector Part # XXXXX"
Dist./Rep - "$X.XX Lead time 37 days"
ME - "Anything we can do about lead time? 37 days seems a bit high."
Dist./Rep - "that is the lead time given because our stock is live....
we currently have stock."
Il 13/05/2012 19:14, m...@smartcar.ind.br ha scritto:
>
>
> How do to fix the value in memory flash ARM via code in C LPCXpresso?
>
You should use something like this:
const int iMagicNumber = 123456;
> From: Robert Adsett
> Sent: Sunday, May 13, 2012 12:38 PM
> To: l...
> Subject: Re: [lpc2000] Write Flash via Firmware
>
> On 5/13/2012 11:21 AM, mailto:marcos%40smartcar.ind.br wrote:
> > I had already understood this well, my doubt is another.
> > What is the statement in C that writes to a given address of the
> flash, but not via firmware, but saw lpcxpresso.
> > In the PIC instução is this:
> > ORG 0X210D //address
> > DE "test123"; //DE = instruction test123=text to be written
>
> You are mistaken about what DE does.
>
> >From Microchips manual
> http://ww1.microchip.com/downloads/en/devicedoc/33014j.pdf
>
> de – DECLARE EEPROM DATA BYTE
>
> It does not write to anywhere. It simply sets up a value in the image
> that is downloaded to the device.
>
> The equivalent in C is
>
> const int c=230;
>
> It's not ARM specific, although some compilers on some processors
> provide extensions to C to allow placement in different memory areas.
>
> To place it at a specific address requires either assembly, some work
> with the linker or a compiler specific extension. And there are few
> occasions when it is necessary to fix a constants location in memory.
>
> Robert
>
> --
>
> >From the Divided by a Common Language File (Edited to protect the guilty)
> ME - "I'd like to get Price and delivery for connector Part # XXXXX"
> Dist./Rep - "$X.XX Lead time 37 days"
> ME - "Anything we can do about lead time? 37 days seems a bit high."
> Dist./Rep - "that is the lead time given because our stock is live....
> we currently have stock."
>
>
>
>



What I need is to define a fixed value in the flash memory through the code in C lpcxpresso?
address=0x00007F00
value=0x01

From: M. Manca
Sent: Sunday, May 13, 2012 6:01 PM
To: l...
Subject: Re: [lpc2000] Write Flash via Firmware


Il 13/05/2012 19:14, mailto:marcos%40smartcar.ind.br ha scritto:
>
>
> How do to fix the value in memory flash ARM via code in C LPCXpresso?
>
You should use something like this:
const int iMagicNumber = 123456;
> From: Robert Adsett
> Sent: Sunday, May 13, 2012 12:38 PM
> To: mailto:lpc2000%40yahoogroups.com
> Subject: Re: [lpc2000] Write Flash via Firmware
>
> On 5/13/2012 11:21 AM, mailto:marcos%40smartcar.ind.br wrote:
> > I had already understood this well, my doubt is another.
> > What is the statement in C that writes to a given address of the
> flash, but not via firmware, but saw lpcxpresso.
> > In the PIC instução is this:
> > ORG 0X210D //address
> > DE "test123"; //DE = instruction test123=text to be written
>
> You are mistaken about what DE does.
>
> >From Microchips manual
> http://ww1.microchip.com/downloads/en/devicedoc/33014j.pdf
>
> de – DECLARE EEPROM DATA BYTE
>
> It does not write to anywhere. It simply sets up a value in the image
> that is downloaded to the device.
>
> The equivalent in C is
>
> const int c=230;
>
> It's not ARM specific, although some compilers on some processors
> provide extensions to C to allow placement in different memory areas.
>
> To place it at a specific address requires either assembly, some work
> with the linker or a compiler specific extension. And there are few
> occasions when it is necessary to fix a constants location in memory.
>
> Robert
>
> --
>
> >From the Divided by a Common Language File (Edited to protect the guilty)
> ME - "I'd like to get Price and delivery for connector Part # XXXXX"
> Dist./Rep - "$X.XX Lead time 37 days"
> ME - "Anything we can do about lead time? 37 days seems a bit high."
> Dist./Rep - "that is the lead time given because our stock is live....
> we currently have stock."
>
>
>
>





On 15/5/2012 4:52 PM, m...@smartcar.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

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



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

Now we are getting somewhere. I assume that after the change the new
value must persist after a reset/powerdown? Otherwise you could simple
use an initialized variable.

Assuming a change is permanent, how will the user change these
variable(s)? Via your application, using IAP commands?

Assuming the answer is yes: you will have to set aside a FLASH block for
this use, as a separate section in your linkerscript. Give it an
appropriate name, and locate the variables in that section. The best way
is probably to have only one struct there, so you can have a modified
version of that struct elsewhere (in RAM) that you can write to the
FLASH block using IAP commands.

--

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

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
>
>