EmbeddedRelated.com
Forums

Writing to flash

Started by Jardar Johannes Maatje March 5, 2003
I an integer that I want to be located in flash memory on the MSP430F1121
chip. But I have a problem making this work:


    #define ONBOARD_FLASH_ADDRESS 0x1080
...
    uint *ptrToCounter  = (uint *) ONBOARD_FLASH_ADDRESS;
	*ptrToCounter 
    FCTL2 = FWKEY + FSSEL0 + FN0;
    while ( FCTL3 & BUSY);
    FCTL3 = FWKEY;
    FCTL1 = FWKEY + WRT;
    *ptrToCounter = absoluteFlashPointer;
    FCTL1 = FWKEY;
    FCTL3 = FWKEY + LOCK;
    while ( ! (FCTL3 & WAIT) );
    absoluteFlashPointer = *ptrToCounter;

When I read back the pointers are not the same.

Jardar


Beginning Microcontrollers with the MSP430

Have a look at SLAA103, it includes C code to program flash.

Al

Jardar Johannes Maatje wrote:
> 
> I an integer that I want to be located in flash memory on the
> MSP430F1121
> chip. But I have a problem making this work:
> 
>     #define ONBOARD_FLASH_ADDRESS 0x1080
> ...
>     uint *ptrToCounter  = (uint *) ONBOARD_FLASH_ADDRESS;
>       *ptrToCounter > 
>     FCTL2 = FWKEY + FSSEL0 + FN0;
>     while ( FCTL3 & BUSY);
>     FCTL3 = FWKEY;
>     FCTL1 = FWKEY + WRT;
>     *ptrToCounter = absoluteFlashPointer;
>     FCTL1 = FWKEY;
>     FCTL3 = FWKEY + LOCK;
>     while ( ! (FCTL3 & WAIT) );
>     absoluteFlashPointer = *ptrToCounter;
> 
> When I read back the pointers are not the same.
> 
> Jardar
> 
>                    
> 
> 
> 
> .
> 
> 

Jardar -

An important thing to remember: you can change flash bits in only one
direction. I believe that you can only change a  1 to a 0. If you need
to go the other way, your ONLY option is to clear the whole segment!

Jim Wagner

--- Jardar Johannes Maatje <maatje@maat...> wrote:
> I an integer that I want to be located in flash
memory on the
> MSP430F1121
> chip. But I have a problem making this work:
> 
> 
>     #define ONBOARD_FLASH_ADDRESS 0x1080
> ...
>     uint *ptrToCounter  = (uint *) ONBOARD_FLASH_ADDRESS;
> 	*ptrToCounter > 
>     FCTL2 = FWKEY + FSSEL0 + FN0;
>     while ( FCTL3 & BUSY);
>     FCTL3 = FWKEY;
>     FCTL1 = FWKEY + WRT;
>     *ptrToCounter = absoluteFlashPointer;
>     FCTL1 = FWKEY;
>     FCTL3 = FWKEY + LOCK;
>     while ( ! (FCTL3 & WAIT) );
>     absoluteFlashPointer = *ptrToCounter;
> 
> When I read back the pointers are not the same.
> 
> Jardar
> 
> 


__________________________________________________


Not according to SLAA130. This states that FLASH reprogramming is
possible at a byte level. ie erase/program as a cycle.

Al

James Wagner wrote:
> 
> Jardar -
> 
> An important thing to remember: you can change flash bits in only one
> direction. I believe that you can only change a  1 to a 0. If you need
> to go the other way, your ONLY option is to clear the whole segment!
> 
> Jim Wagner
> 
> --- Jardar Johannes Maatje <maatje@maat...> wrote:
> > I an integer that I want to be located in flash memory on the
> > MSP430F1121
> > chip. But I have a problem making this work:
> >
> >
> >     #define ONBOARD_FLASH_ADDRESS 0x1080
> > ...
> >     uint *ptrToCounter  = (uint *) ONBOARD_FLASH_ADDRESS;
> >       *ptrToCounter > >
> >     FCTL2 = FWKEY + FSSEL0 + FN0;
> >     while ( FCTL3 & BUSY);
> >     FCTL3 = FWKEY;
> >     FCTL1 = FWKEY + WRT;
> >     *ptrToCounter = absoluteFlashPointer;
> >     FCTL1 = FWKEY;
> >     FCTL3 = FWKEY + LOCK;
> >     while ( ! (FCTL3 & WAIT) );
> >     absoluteFlashPointer = *ptrToCounter;
> >
> > When I read back the pointers are not the same.
> >
> > Jardar
> >
> >
> 
> __________________________________________________
> 
> 
>                    
> 
> 
> 
> .
> 
> 

No, I think you'll find that this is not a correct interpretation. 
Yes,
you can write at the bye or word level, but you can only overprogram a
byte a fixed number of times before you need to erase it, *and* you can
only change bits from 1 to 0 as James wrote.

-- Paul.

> -----Original Message-----
> From: onestone [mailto:onestone@ones...] 
> Sent: 06 March 2003 01:04
> To: msp430@msp4...
> Subject: Re: [msp430] Writing to flash
> 
> 
> Not according to SLAA130. This states that FLASH 
> reprogramming is possible at a byte level. ie erase/program 
> as a cycle.
> 
> Al
> 
> James Wagner wrote:
> > 
> > Jardar -
> > 
> > An important thing to remember: you can change flash bits 
> in only one 
> > direction. I believe that you can only change a  1 to a 0. 
> If you need 
> > to go the other way, your ONLY option is to clear the whole segment!
> > 
> > Jim Wagner
> > 
> > --- Jardar Johannes Maatje <maatje@maat...> wrote:
> > > I an integer that I want to be located in flash memory on the 
> > > MSP430F1121 chip. But I have a problem making this work:
> > >
> > >
> > >     #define ONBOARD_FLASH_ADDRESS 0x1080
> > > ...
> > >     uint *ptrToCounter  = (uint *) ONBOARD_FLASH_ADDRESS;
> > >       *ptrToCounter > > >
> > >     FCTL2 = FWKEY + FSSEL0 + FN0;
> > >     while ( FCTL3 & BUSY);
> > >     FCTL3 = FWKEY;
> > >     FCTL1 = FWKEY + WRT;
> > >     *ptrToCounter = absoluteFlashPointer;
> > >     FCTL1 = FWKEY;
> > >     FCTL3 = FWKEY + LOCK;
> > >     while ( ! (FCTL3 & WAIT) );
> > >     absoluteFlashPointer = *ptrToCounter;
> > >
> > > When I read back the pointers are not the same.
> > >
> > > Jardar
> > >
> > >
> > 
> > __________________________________________________
> > 
> > 
> >                    
> > 
> > 
> > 
> > .
> > 
> > ">http://docs.yahoo.com/info/terms/ 
> 
> 
> 

Thanks all of you, everything si fine now. Did not know that it was only
possible to set it from 1 to 0.

Jardar

> No, I think you'll find that this is not a
correct interpretation.  Yes,
> you can write at the bye or word level, but you can only overprogram a
> byte a fixed number of times before you need to erase it, *and* you can
> only change bits from 1 to 0 as James wrote.
>
> -- Paul.
>
> > -----Original Message-----
> > From: onestone [mailto:onestone@ones...]
> > Sent: 06 March 2003 01:04
> > To: msp430@msp4...
> > Subject: Re: [msp430] Writing to flash
> >
> >
> > Not according to SLAA130. This states that FLASH
> > reprogramming is possible at a byte level. ie erase/program
> > as a cycle.
> >
> > Al
> >
> > James Wagner wrote:
> > >
> > > Jardar -
> > >
> > > An important thing to remember: you can change flash bits
> > in only one
> > > direction. I believe that you can only change a  1 to a 0.
> > If you need
> > > to go the other way, your ONLY option is to clear the whole
segment!
> > >
> > > Jim Wagner
> > >
> > > --- Jardar Johannes Maatje <maatje@maat...> wrote:
> > > > I an integer that I want to be located in flash memory on
the
> > > > MSP430F1121 chip. But I have a problem making this work:
> > > >
> > > >
> > > >     #define ONBOARD_FLASH_ADDRESS 0x1080
> > > > ...
> > > >     uint *ptrToCounter  = (uint *) ONBOARD_FLASH_ADDRESS;
> > > >       *ptrToCounter > > > >
> > > >     FCTL2 = FWKEY + FSSEL0 + FN0;
> > > >     while ( FCTL3 & BUSY);
> > > >     FCTL3 = FWKEY;
> > > >     FCTL1 = FWKEY + WRT;
> > > >     *ptrToCounter = absoluteFlashPointer;
> > > >     FCTL1 = FWKEY;
> > > >     FCTL3 = FWKEY + LOCK;
> > > >     while ( ! (FCTL3 & WAIT) );
> > > >     absoluteFlashPointer = *ptrToCounter;
> > > >
> > > > When I read back the pointers are not the same.
> > > >
> > > > Jardar
> > > >
> > > >
> > >
> > > __________________________________________________
> > > 
> > >
> > >                    
> > >
> > >
> > >
> > > .
> > >
> > > ">http://docs.yahoo.com/info/terms/
> >
> >
> >
>
>
> .
>
>
>
> ">http://docs.yahoo.com/info/terms/
>
>