EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Writing to FLASH

Started by Maris Kalbergs September 28, 2006
Do not try writing to flash when the supply voltage is below 2.7V. Read
the manual for the specs. Then checkout the samples on line there is
code that does this in C or asm. If you can't figure out the difference
between writing flash using the register indirect mode, and simply
writing a register you need to go away and study the very basics before
you start trying to write code.

Al

Maris Kalbergs wrote:

> Hello!
>
> I am newbie in your group and i have one question.
> I need to write some registers into flash memory when power supply is
> half of max. At the moment i am using MSP430F123.
>
> Do you have some idea how to write for example R10 register content into
> Flash momery?
>
> Thanks a lot.
>
> Maris.
>
>
>
>
>
>

Beginning Microcontrollers with the MSP430

Can you tell me where i can find this very basic things? Because i still
miss something?

Thanks in advanced
Maris

On Sun, 2006-10-01 at 23:17 +0930, Onestone wrote:
> Do not try writing to flash when the supply voltage is below 2.7V.
> Read
> the manual for the specs. Then checkout the samples on line there is
> code that does this in C or asm. If you can't figure out the
> difference
> between writing flash using the register indirect mode, and simply
> writing a register you need to go away and study the very basics
> before
> you start trying to write code.
>
> Al
>
> Maris Kalbergs wrote:
>
> > Hello!
> >
> > I am newbie in your group and i have one question.
> > I need to write some registers into flash memory when power supply
> is
> > half of max. At the moment i am using MSP430F123.
> >
> > Do you have some idea how to write for example R10 register content
> into
> > Flash momery?
> >
> > Thanks a lot.
> >
> > Maris.
> >
> >
> >
> >----------------------
> >
> >No virus found in this incoming message.
> >Checked by AVG Free Edition.
> >Version: 7.1.405 / Virus Database: 268.12.9/456 - Release Date:
> 25/09/2006
> >
> >
>
Maris Kalbergs wrote:
> Can you tell me where i can find this very basic things? Because i still
> miss something?
You are seriously telling, that you cannot figure out where to get basic
information from? You are not trolling, aren't you?

next best library: there you find books on "programming", "electronics",
"microcontrolers".
introductory courses into electronics, sometimes found on the schedules of the
next university or on internet or by manuf or thirdparty training companies
flash memory datasheets from the next best manuf
ask a friend
google
amazon: you can buy books there.
G.
>
> Thanks in advanced
> Maris
>
> On Sun, 2006-10-01 at 23:17 +0930, Onestone wrote:
>
>>Do not try writing to flash when the supply voltage is below 2.7V.
>>Read
>>the manual for the specs. Then checkout the samples on line there is
>>code that does this in C or asm. If you can't figure out the
>>difference
>>between writing flash using the register indirect mode, and simply
>>writing a register you need to go away and study the very basics
>>before
>>you start trying to write code.
>>
>>Al
>>
>>Maris Kalbergs wrote:
>>>Hello!
>>>
>>>I am newbie in your group and i have one question.
>>>I need to write some registers into flash memory when power supply
>>
>>is
>>
>>>half of max. At the moment i am using MSP430F123.
>>>
>>>Do you have some idea how to write for example R10 register content
>>
>>into
>>
>>>Flash momery?
>>>
>>>Thanks a lot.
>>>
>>>Maris.
>>>
>>>
>>>
>>>----------------------
>>>
>>>No virus found in this incoming message.
>>>Checked by AVG Free Edition.
>>>Version: 7.1.405 / Virus Database: 268.12.9/456 - Release Date:
>>
>>25/09/2006
>>
>>
SLAUE10B explains address modes and the instruction set in detail. The
technical data sheet for each family member explains the electrical
specifications, for example minimum FLASH write value and flash clock
values, while the Family user guides explain in detail how each part of
the family functions. Appplication examples give code and detailed
explanations for how it operates.

Al

Maris Kalbergs wrote:

> Can you tell me where i can find this very basic things? Because i still
> miss something?
>
> Thanks in advanced
> Maris
>
> On Sun, 2006-10-01 at 23:17 +0930, Onestone wrote:
> > Do not try writing to flash when the supply voltage is below 2.7V.
> > Read
> > the manual for the specs. Then checkout the samples on line there is
> > code that does this in C or asm. If you can't figure out the
> > difference
> > between writing flash using the register indirect mode, and simply
> > writing a register you need to go away and study the very basics
> > before
> > you start trying to write code.
> >
> > Al
> >
> > Maris Kalbergs wrote:
> >
> > > Hello!
> > >
> > > I am newbie in your group and i have one question.
> > > I need to write some registers into flash memory when power supply
> > is
> > > half of max. At the moment i am using MSP430F123.
> > >
> > > Do you have some idea how to write for example R10 register content
> > into
> > > Flash momery?
> > >
> > > Thanks a lot.
> > >
> > > Maris.
> > >
> > >
> > >
> > >----------------------
> > >
> > >
>
>
my patience ran out:)
here is my code for msp430f149 at 4MHz
(to better watch code, set fixed font in yahoo groups)

void to_flash_uint(unsigned int *dst, unsigned int *src){
WDTCTL=WDTPW+WDTHOLD;
_DINT();
FCTL2=FWKEY+FSSEL_1+FN3;
FCTL3=FWKEY;
FCTL1=FWKEY+WRT;
*dst=*src; //reference!!!! because of compiler!
FCTL1=FWKEY;
FCTL3=FWKEY+LOCK;
_EINT();// f=MCLK/(8+1)=4MHz/9D4kHz;
}

sfrb infoB = 0x1000;
void erase_infoB(void){
WDTCTL=WDTPW+WDTHOLD;
_DINT();
FCTL2=FWKEY+FSSEL_1+FN3;
FCTL3=FWKEY;
FCTL1=FWKEY+ERASE;
infoB = 0; //dummy write
FCTL1=FWKEY;
FCTL3=FWKEY+LOCK;
_EINT();// f=MCLK/(8+1)=4MHz/9D4kHz;
}
e.g.

unsigned int f_x @ "INFO B" = 0x1234;
unsigned int x = 0x4321;
//to RAM:
x=f_x;
//to flash
to_flash_uint(&f_x, &x);

you can't do to_flash_uint(f_x, x);
you must use reference adressing!

becase (see: 'to_flash_uint' code):
dst=src;
would be compiled e.g.
MOV.W R14, R15 //no flash write!!!!

and
*dst=*src;
is compiled into
MOV.W @R14, 0(R15) //and it is ok!
is it clear enough?
Thanks for your program, but it didn't help me out.
Here is my code and may be you could say that's wrong in it.

MOV #FWKEY+FSSEL1+FN3,&FCTL2 ; SMCLK/2
MOV #FWKEY,&FCTL3 ; Clear LOCK
MOV #FWKEY+WRT,&FCTL1 ; Enable write
MOV.W @R11,&0E010h ; Register to FLASH
L333 BIT #BUSY,&FCTL3 ; Test BUSY
JNZ L333
MOV #FWKEY,&FCTL1 ; Done. Clear WRT
MOV #FWKEY+LOCK,&FCTL3 ; Set LOCK

R11 - register where is data kept
&0E010h - address in FLASH where we want to sore our data.

Thanks

Maris

On Mon, 2006-10-02 at 12:40 +0000, Kamil wrote:
> my patience ran out:)
> here is my code for msp430f149 at 4MHz
> (to better watch code, set fixed font in yahoo groups)
>
> void to_flash_uint(unsigned int *dst, unsigned int *src){
> WDTCTL=WDTPW+WDTHOLD;
> _DINT();
> FCTL2=FWKEY+FSSEL_1+FN3;
> FCTL3=FWKEY;
> FCTL1=FWKEY+WRT;
> *dst=*src; //reference!!!! because of compiler!
> FCTL1=FWKEY;
> FCTL3=FWKEY+LOCK;
> _EINT();// f=MCLK/(8+1)=4MHz/9D4kHz;
> }
>
> sfrb infoB = 0x1000;
> void erase_infoB(void){
> WDTCTL=WDTPW+WDTHOLD;
> _DINT();
> FCTL2=FWKEY+FSSEL_1+FN3;
> FCTL3=FWKEY;
> FCTL1=FWKEY+ERASE;
> infoB = 0; //dummy write
> FCTL1=FWKEY;
> FCTL3=FWKEY+LOCK;
> _EINT();// f=MCLK/(8+1)=4MHz/9D4kHz;
> }
>
> e.g.
>
> unsigned int f_x @ "INFO B" = 0x1234;
> unsigned int x = 0x4321;
> //to RAM:
> x=f_x;
> //to flash
> to_flash_uint(&f_x, &x);
>
> you can't do to_flash_uint(f_x, x);
> you must use reference adressing!
>
> becase (see: 'to_flash_uint' code):
> dst=src;
> would be compiled e.g.
> MOV.W R14, R15 //no flash write!!!!
>
> and
> *dst=*src;
> is compiled into
> MOV.W @R14, 0(R15) //and it is ok!
>
> is it clear enough?
>
--- In m..., Maris Kalbergs
wrote:
>
> Thanks for your program, but it didn't help me out.
> Here is my code and may be you could say that's wrong in it.
>
> MOV #FWKEY+FSSEL1+FN3,&FCTL2 ; SMCLK/2
> MOV #FWKEY,&FCTL3 ; Clear LOCK
> MOV #FWKEY+WRT,&FCTL1 ; Enable write
> MOV.W @R11,&0E010h ; Register to FLASH
> L333 BIT #BUSY,&FCTL3 ; Test BUSY
> JNZ L333
> MOV #FWKEY,&FCTL1 ; Done. Clear WRT
> MOV #FWKEY+LOCK,&FCTL3 ; Set LOCK
>
> R11 - register where is data kept
> &0E010h - address in FLASH where we want to sore our data.

you wrote: 'R11 - register where is data kept'
then @R1 is wrong! you should write mov.w r11, @0e010h not @r11
(i suppose that you have choosen right clock for flash, according to
tech spec of your IC.(a.450kHz))
and of course you have erased this flash block or you have only 1's
in dataword you are writing to.

Memfault Beyond the Launch