EmbeddedRelated.com
Forums

Flash write on F5438

Started by Stefan Hauenstein December 9, 2010
Hi guys,

I want to write 512 bytes into a one flash segment in one step. I have tested the following code and it works. But the data sheet says that the programming voltage is applied to the complete 128-byte block. Does this mean that memcpy should work only at the first 128 bytes?
Code is executed from flash, not Ram. Originally, I did write 128 * 4 bytes into the segment, but it's not as fast as the following code.

StopWatchDog();
_DINT();
_NOP();
SetReg(FCTL3, FWKEY);
SetReg(FCTL1, FWKEY | BLKWRT);

memcpy( pbSegStart, abSegmentMirror, 512);

SetReg(FCTL3, FWKEY | LOCK);
_EINT();
StartWatchDog();

Beginning Microcontrollers with the MSP430

The programming voltage is applied to the entire 128-byte of flash when you try to write to any part of those 128-byte. When you try to write to somewhere in a different 128-byte, only those 128-byte of flash got the programming voltage.

The fastest way to write into flash is to use "long-word block write", but that requires to execute the code from RAM or a different bank of flash. The next fastest is "long-word write". It seems that you are doing long-word write.

--- In m..., "Stefan Hauenstein" wrote:
>
> Hi guys,
>
> I want to write 512 bytes into a one flash segment in one step. I have tested the following code and it works. But the data sheet says that the programming voltage is applied to the complete 128-byte block. Does this mean that memcpy should work only at the first 128 bytes?
> Code is executed from flash, not Ram. Originally, I did write 128 * 4 bytes into the segment, but it's not as fast as the following code.
>
> StopWatchDog();
> _DINT();
> _NOP();
> SetReg(FCTL3, FWKEY);
> SetReg(FCTL1, FWKEY | BLKWRT);
>
> memcpy( pbSegStart, abSegmentMirror, 512);
>
> SetReg(FCTL3, FWKEY | LOCK);
> _EINT();
> StartWatchDog();
>

Guyz,
Some observations:
128 byte block probably only refers to the INFO segments which are 128 bytes.
Writing to a 512 byte block will apply voltage to the entire segment.
Don't you have to erase the segment before writing to it? I don't see that in the code...

Mike Raines
________________________________
From: m... [mailto:m...] On Behalf Of old_cow_yellow
Sent: Thursday, December 09, 2010 11:39 AM
To: m...
Subject: [SPAM] [msp430] Re: Flash write on F5438
Importance: Low

The programming voltage is applied to the entire 128-byte of flash when you try to write to any part of those 128-byte. When you try to write to somewhere in a different 128-byte, only those 128-byte of flash got the programming voltage.

The fastest way to write into flash is to use "long-word block write", but that requires to execute the code from RAM or a different bank of flash. The next fastest is "long-word write". It seems that you are doing long-word write.

--- In m..., "Stefan Hauenstein" wrote:
>
> Hi guys,
>
> I want to write 512 bytes into a one flash segment in one step. I have tested the following code and it works. But the data sheet says that the programming voltage is applied to the complete 128-byte block. Does this mean that memcpy should work only at the first 128 bytes?
> Code is executed from flash, not Ram. Originally, I did write 128 * 4 bytes into the segment, but it's not as fast as the following code.
>
> StopWatchDog();
> _DINT();
> _NOP();
> SetReg(FCTL3, FWKEY);
> SetReg(FCTL1, FWKEY | BLKWRT);
>
> memcpy( pbSegStart, abSegmentMirror, 512);
>
> SetReg(FCTL3, FWKEY | LOCK);
> _EINT();
> StartWatchDog();
>



Mike,

The 512-byte segment of main flash is sub-divided into four 128-byte rows. During write operation, programming voltage is applied to one row, not to the entire segment. (During segment erase operation, it is applied to the entire segment.)

--OCY

--- In m..., Mike Raines wrote:
>
> Guyz,
> Some observations:
> 128 byte block probably only refers to the INFO segments which are 128 bytes.
> Writing to a 512 byte block will apply voltage to the entire segment.
> Don't you have to erase the segment before writing to it? I don't see that in the code...
>
> Mike Raines
> ________________________________
> From: m... [mailto:m...] On Behalf Of old_cow_yellow
> Sent: Thursday, December 09, 2010 11:39 AM
> To: m...
> Subject: [SPAM] [msp430] Re: Flash write on F5438
> Importance: Low
>
> The programming voltage is applied to the entire 128-byte of flash when you try to write to any part of those 128-byte. When you try to write to somewhere in a different 128-byte, only those 128-byte of flash got the programming voltage.
>
> The fastest way to write into flash is to use "long-word block write", but that requires to execute the code from RAM or a different bank of flash. The next fastest is "long-word write". It seems that you are doing long-word write.
>
> --- In m..., "Stefan Hauenstein" wrote:
> >
> > Hi guys,
> >
> > I want to write 512 bytes into a one flash segment in one step. I have tested the following code and it works. But the data sheet says that the programming voltage is applied to the complete 128-byte block. Does this mean that memcpy should work only at the first 128 bytes?
> > Code is executed from flash, not Ram. Originally, I did write 128 * 4 bytes into the segment, but it's not as fast as the following code.
> >
> > StopWatchDog();
> > _DINT();
> > _NOP();
> > SetReg(FCTL3, FWKEY);
> > SetReg(FCTL1, FWKEY | BLKWRT);
> >
> > memcpy( pbSegStart, abSegmentMirror, 512);
> >
> > SetReg(FCTL3, FWKEY | LOCK);
> > _EINT();
> > StartWatchDog();
> >
>

Thanks, OCY...
Mike

________________________________
From: m... [mailto:m...] On Behalf Of old_cow_yellow
Sent: Thursday, December 09, 2010 12:38 PM
To: m...
Subject: [SPAM] [msp430] Re: Flash write on F5438
Importance: Low

Mike,

The 512-byte segment of main flash is sub-divided into four 128-byte rows. During write operation, programming voltage is applied to one row, not to the entire segment. (During segment erase operation, it is applied to the entire segment.)

--OCY

--- In m..., Mike Raines wrote:
>
> Guyz,
> Some observations:
> 128 byte block probably only refers to the INFO segments which are 128 bytes.
> Writing to a 512 byte block will apply voltage to the entire segment.
> Don't you have to erase the segment before writing to it? I don't see that in the code...
>
> Mike Raines
> ________________________________
> From: m... [mailto:m...] On Behalf Of old_cow_yellow
> Sent: Thursday, December 09, 2010 11:39 AM
> To: m...
> Subject: [SPAM] [msp430] Re: Flash write on F5438
> Importance: Low
>
> The programming voltage is applied to the entire 128-byte of flash when you try to write to any part of those 128-byte. When you try to write to somewhere in a different 128-byte, only those 128-byte of flash got the programming voltage.
>
> The fastest way to write into flash is to use "long-word block write", but that requires to execute the code from RAM or a different bank of flash. The next fastest is "long-word write". It seems that you are doing long-word write.
>
> --- In m..., "Stefan Hauenstein" wrote:
> >
> > Hi guys,
> >
> > I want to write 512 bytes into a one flash segment in one step. I have tested the following code and it works. But the data sheet says that the programming voltage is applied to the complete 128-byte block. Does this mean that memcpy should work only at the first 128 bytes?
> > Code is executed from flash, not Ram. Originally, I did write 128 * 4 bytes into the segment, but it's not as fast as the following code.
> >
> > StopWatchDog();
> > _DINT();
> > _NOP();
> > SetReg(FCTL3, FWKEY);
> > SetReg(FCTL1, FWKEY | BLKWRT);
> >
> > memcpy( pbSegStart, abSegmentMirror, 512);
> >
> > SetReg(FCTL3, FWKEY | LOCK);
> > _EINT();
> > StartWatchDog();
> >
>



Hi OCY,

thanks for your comments. That means that I have to call memcpy and the FCTL1/3 stuff 4 times with 128 bytes to write at each call. But it's interesting that memcpy is able to write to the entire segment in one call with 512 bytes to write.

Stefan
--- In m..., "old_cow_yellow" wrote:
>
> Mike,
>
> The 512-byte segment of main flash is sub-divided into four 128-byte rows. During write operation, programming voltage is applied to one row, not to the entire segment. (During segment erase operation, it is applied to the entire segment.)
>
> --OCY
>
> --- In m..., Mike Raines wrote:
> >
> > Guyz,
> > Some observations:
> > 128 byte block probably only refers to the INFO segments which are 128 bytes.
> > Writing to a 512 byte block will apply voltage to the entire segment.
> > Don't you have to erase the segment before writing to it? I don't see that in the code...
> >
> > Mike Raines
> >
> >
> > ________________________________
> > From: m... [mailto:m...] On Behalf Of old_cow_yellow
> > Sent: Thursday, December 09, 2010 11:39 AM
> > To: m...
> > Subject: [SPAM] [msp430] Re: Flash write on F5438
> > Importance: Low
> >
> >
> >
> > The programming voltage is applied to the entire 128-byte of flash when you try to write to any part of those 128-byte. When you try to write to somewhere in a different 128-byte, only those 128-byte of flash got the programming voltage.
> >
> > The fastest way to write into flash is to use "long-word block write", but that requires to execute the code from RAM or a different bank of flash. The next fastest is "long-word write". It seems that you are doing long-word write.
> >
> > --- In m..., "Stefan Hauenstein" wrote:
> > >
> > > Hi guys,
> > >
> > > I want to write 512 bytes into a one flash segment in one step. I have tested the following code and it works. But the data sheet says that the programming voltage is applied to the complete 128-byte block. Does this mean that memcpy should work only at the first 128 bytes?
> > > Code is executed from flash, not Ram. Originally, I did write 128 * 4 bytes into the segment, but it's not as fast as the following code.
> > >
> > > StopWatchDog();
> > > _DINT();
> > > _NOP();
> > > SetReg(FCTL3, FWKEY);
> > > SetReg(FCTL1, FWKEY | BLKWRT);
> > >
> > > memcpy( pbSegStart, abSegmentMirror, 512);
> > >
> > > SetReg(FCTL3, FWKEY | LOCK);
> > > _EINT();
> > > StartWatchDog();
> > >
> >
> >
> >
> >
>