EmbeddedRelated.com
Forums

Data flash access

Started by p_murayama February 23, 2008
Hello!

I am trying to write in the data flash. There are a couple ot things
I don't understand.

1. What is the meaning of FRKEY? I understand FWKEY as a kind of protection
so that the flash cannot be easily accidentaly overwritten. Am I right? But what
is the point of this when reading?
I can directly read what I wrote, for instance like this:

#define DATA_FLASH 0x1000

uint8 mydata;

mydata = *(uimt8 *)(DATA_FLASH + offset);

FRKEY is not used in TI's sample (slac15, for F169) code and they copy one
segment into the other by direct access to the flash.

2. A piece of TI's code (called fet140_flashwrite_01.c

FCTL1 = FWKEY + ERASE;
FCTL3 = FWKEY;
*Flash_Ptr = 0; // Erase the segnment
FCTL1 = FWKEY + WRT;
for(i = 0 ; i < 128 ; ++i) {
Flash_Ptr++ = value;
}

What I don't understand: why do they need to erase the segment
before writing the whole segment? Couldn't it be done by writing directly?
I tried, it works but I suspect there might be a reason...

3. What I tried after resetting the whole block is to write some data, and there
it does not work at all.

Here is the code with some comments:

[I skip the begining of the program, it simply stops the WDT (required for flash
writing) and sets the system frequency to XT2 (8MHz)]

// First, set the clock to 1/64 of the crystal
FCTL2 = FWKEY + FSSEL_3 + 0x3F; // 0x3F is the divider by 64, therefore 125 kHz
FCTL3 = FWKEY; // Clear anything but key.
dataflash = (uint8 *) DATA_FLASH;
// FCTL1 = FWKEY + ERASE // Clearing one segment works without these lines
// *dataflash = 0; // but subsequent writings don't work even with these lines.
for(i = 0 ; i < 128 ; ++i) {
dataflash[i] = 0; // This works fine and clears everyting as expexcted
}
dataflash[18] = 0xAA; // Random writing. Does not work at all
FCTL1 = FWKEY; // Clears everything but the key
FCTL3 = FWKEY + LOCK;
Any hint?

Thanks,

Pascal

Beginning Microcontrollers with the MSP430

Pascal,

FLASH is a genre of EPROM (Erasable Programmable Read Only Memory). As
such, it can be read but cannot be written. In addition, it can also
be "Programmed" and "Erased".

"Programmable" means, with a special procedure, you can change any bit
in FLASH from "1" to "0". "Erasable" means, with a different
procedure, you can change all the bits in a block of FLASH to "1".

MSP430F members all have on-chip "Flash Memory Controller" to do
"Programming" or "Erasing". Some of the registers in the "Flash Memory
Controller" have a special feature that reduces the possibility of
unintentional access to these registers. When you write to these
registers, you have to include FWKEY bits. (Otherwise, you will get a
key violation.) When you read these registers, you will get the
current setting of the other bits plus FRKEY instead of FWKEY. By the
way, the standard header files also define FXKEY = FRKEY ^ FWKEY.

I hope the above answers your questions in an indirect (but more
enlightening?) way.

--- In m..., "p_murayama" wrote:
>
> Hello!
>
> I am trying to write in the data flash. There are a couple ot things
> I don't understand.
>
> 1. What is the meaning of FRKEY? I understand FWKEY as a kind of
protection
> so that the flash cannot be easily accidentaly overwritten. Am I
right? But what
> is the point of this when reading?
> I can directly read what I wrote, for instance like this:
>
> #define DATA_FLASH 0x1000
>
> uint8 mydata;
>
> mydata = *(uimt8 *)(DATA_FLASH + offset);
>
> FRKEY is not used in TI's sample (slac15, for F169) code and they
copy one
> segment into the other by direct access to the flash.
>
> 2. A piece of TI's code (called fet140_flashwrite_01.c
>
> FCTL1 = FWKEY + ERASE;
> FCTL3 = FWKEY;
> *Flash_Ptr = 0; // Erase the segnment
> FCTL1 = FWKEY + WRT;
> for(i = 0 ; i < 128 ; ++i) {
> Flash_Ptr++ = value;
> }
>
> What I don't understand: why do they need to erase the segment
> before writing the whole segment? Couldn't it be done by writing
directly?
> I tried, it works but I suspect there might be a reason...
>
> 3. What I tried after resetting the whole block is to write some
data, and there
> it does not work at all.
>
> Here is the code with some comments:
>
> [I skip the begining of the program, it simply stops the WDT
(required for flash
> writing) and sets the system frequency to XT2 (8MHz)]
>
> // First, set the clock to 1/64 of the crystal
> FCTL2 = FWKEY + FSSEL_3 + 0x3F; // 0x3F is the divider by 64,
therefore 125 kHz
> FCTL3 = FWKEY; // Clear anything but key.
> dataflash = (uint8 *) DATA_FLASH;
> // FCTL1 = FWKEY + ERASE // Clearing one segment works without these
lines
> // *dataflash = 0; // but subsequent writings don't work even with
these lines.
> for(i = 0 ; i < 128 ; ++i) {
> dataflash[i] = 0; // This works fine and clears everyting as
expexcted
> }
> dataflash[18] = 0xAA; // Random writing. Does not work at all
> FCTL1 = FWKEY; // Clears everything but the key
> FCTL3 = FWKEY + LOCK;
> Any hint?
>
> Thanks,
>
> Pascal
>
> Well, that must be a matter of nuance for experts, but for regular users
> like me, whatever you call the action of storing data ("write", "put",
> "program", "store"...), it's all about getting data into the chip.

To use simplified terms, basically you can write a '0' into Flash (where a '1' was)
but you CANNOT write a '1' where a '0' was.... (you need to erase for that)
You can however overwrite say like this :

1111 1111 into
1111 1110 into
1111 1000 etc...

So you are still writing ones where there already were ones, same for zeroes.
You can only write a maximum number of times to any array of Flash which IIRC is 64 bytes.
The number of writes is determined by the "Cumulative programming time".

HTH
Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of p_murayama
Sent: Monday, 25 February 2008 1:21 AM
To: m...
Subject: [msp430] Re: Data flash access

Hello!

It works fine now! Thanks a lot!

> FLASH is a genre of EPROM (Erasable Programmable Read Only Memory). As
> such, it can be read but cannot be written. In addition, it can also
> be "Programmed" and "Erased".

Well, that must be a matter of nuance for experts, but for regular users
like me, whatever you call the action of storing data ("write", "put",
"program", "store"...), it's all about getting data into the chip.
Do you think the W in FWKEY or WRT in "FCTL1 = FWKEY + WRT;"
mean program, not write? What about chapter 5.3.3. of the user guide
("Writing Flash Memory")?

Having played with it today, it looks like it's better to first erase it and
write a bunch of contiguous data. (writing twice at the same location
does not work).

Here is the result fo this snowy sunday:

http://passworld.co.jp/ForumMSP430/viewtopic.php?f=8&t0&p%2#p252
Pascal
Hello!

Great, that explains it all!
So the other kinds of EEPROM probably have an auto erase before rewriting.
I have been using a 24C64 recently (EEPROM by I2C), and it can be written, read
byte by byte, overwritten as easily as any memory.
Anyway thanks! What I thought was a workaraound:
- Copy flash data into ram;
- Erase flash;
- Modify ram
- Copy ram into flash;
is in fact the only way to deal with the flash update.

By the way, is there any sample code around, showing what FRKEY and FXKEY
are used for? Apparently I don't need those to read the flash.

Pascal

> To use simplified terms, basically you can write a '0' into Flash (where a '1' was)
> but you CANNOT write a '1' where a '0' was.... (you need to erase for that)
> You can however overwrite say like this :
>
> 1111 1111 into
> 1111 1110 into
> 1111 1000 etc...
>
> So you are still writing ones where there already were ones, same for zeroes.
> You can only write a maximum number of times to any array of Flash which IIRC is 64
bytes.
> The number of writes is determined by the "Cumulative programming time".
>
> HTH
> Best Regards,
> Kris
>
> -----Original Message-----
> From: m... [mailto:m...] On Behalf Of
p_murayama
> Sent: Monday, 25 February 2008 1:21 AM
> To: m...
> Subject: [msp430] Re: Data flash access
>
> Hello!
>
> It works fine now! Thanks a lot!
>
> > FLASH is a genre of EPROM (Erasable Programmable Read Only Memory). As
> > such, it can be read but cannot be written. In addition, it can also
> > be "Programmed" and "Erased".
>
> Well, that must be a matter of nuance for experts, but for regular users
> like me, whatever you call the action of storing data ("write", "put",
> "program", "store"...), it's all about getting data into the chip.
> Do you think the W in FWKEY or WRT in "FCTL1 = FWKEY + WRT;"
> mean program, not write? What about chapter 5.3.3. of the user guide
> ("Writing Flash Memory")?
>
> Having played with it today, it looks like it's better to first erase it and
> write a bunch of contiguous data. (writing twice at the same location
> does not work).
>
> Here is the result fo this snowy sunday:
>
> http://passworld.co.jp/ForumMSP430/viewtopic.php?f=8&t0&p%2#p252
> Pascal
>
Sorry, there is a typo. FSKEY should be FXKEY.

--- In m..., "old_cow_yellow"
wrote:
>
> The FWKEY, FRKEY, and FXKEY are bit-pattens of the upper byte of FCTL
> registers. They apply to FCTL registers, not to the FLASH memory itself.
>
> To write to FCTLx, you use:
> MOV.W #(FWKEY + bits-in-lower-byte),&FCTLx
>
> To check if FCTLx has certain bits (in its lower byte), you use:
> CMP.W #(FRKEY + certain bits),&FCTLx
>
> To flip certain bits (in its lower byte), you use:
> XOR.W #(FSKEY + certain bits),&FCTLx
> --- In m..., "p_murayama" wrote:
> >
> > Hello!
> >
> > Great, that explains it all!
> > So the other kinds of EEPROM probably have an auto erase before
> rewriting.
> > I have been using a 24C64 recently (EEPROM by I2C), and it can be
> written, read
> > byte by byte, overwritten as easily as any memory.
> > Anyway thanks! What I thought was a workaraound:
> > - Copy flash data into ram;
> > - Erase flash;
> > - Modify ram
> > - Copy ram into flash;
> > is in fact the only way to deal with the flash update.
> >
> > By the way, is there any sample code around, showing what FRKEY and
> FXKEY
> > are used for? Apparently I don't need those to read the flash.
> >
> > Pascal
> >
> > > To use simplified terms, basically you can write a '0' into Flash
> (where a '1' was)
> > > but you CANNOT write a '1' where a '0' was.... (you need to erase
> for that)
> > > You can however overwrite say like this :
> > >
> > > 1111 1111 into
> > > 1111 1110 into
> > > 1111 1000 etc...
> > >
> > > So you are still writing ones where there already were ones, same
> for zeroes.
> > > You can only write a maximum number of times to any array of Flash
> which IIRC is 64
> > bytes.
> > > The number of writes is determined by the "Cumulative programming
> time".
> > >
> > > HTH
> > > Best Regards,
> > > Kris
> > >
> > > -----Original Message-----
> > > From: m... [mailto:m...] On
> Behalf Of
> > p_murayama
> > > Sent: Monday, 25 February 2008 1:21 AM
> > > To: m...
> > > Subject: [msp430] Re: Data flash access
> > >
> > > Hello!
> > >
> > > It works fine now! Thanks a lot!
> > >
> > > > FLASH is a genre of EPROM (Erasable Programmable Read Only
> Memory). As
> > > > such, it can be read but cannot be written. In addition, it
can also
> > > > be "Programmed" and "Erased".
> > >
> > > Well, that must be a matter of nuance for experts, but for regular
> users
> > > like me, whatever you call the action of storing data ("write",
> "put",
> > > "program", "store"...), it's all about getting data into the chip.
> > > Do you think the W in FWKEY or WRT in "FCTL1 = FWKEY + WRT;"
> > > mean program, not write? What about chapter 5.3.3. of the user guide
> > > ("Writing Flash Memory")?
> > >
> > > Having played with it today, it looks like it's better to first
> erase it and
> > > write a bunch of contiguous data. (writing twice at the same
location
> > > does not work).
> > >
> > > Here is the result fo this snowy sunday:
> > >
> > >
http://passworld.co.jp/ForumMSP430/viewtopic.php?f=8&t0&p%2#p252
> > >
> > >
> > > Pascal
> > >
>
The FWKEY, FRKEY, and FXKEY are bit-pattens of the upper byte of FCTL
registers. They apply to FCTL registers, not to the FLASH memory itself.

To write to FCTLx, you use:
MOV.W #(FWKEY + bits-in-lower-byte),&FCTLx

To check if FCTLx has certain bits (in its lower byte), you use:
CMP.W #(FRKEY + certain bits),&FCTLx

To flip certain bits (in its lower byte), you use:
XOR.W #(FSKEY + certain bits),&FCTLx
--- In m..., "p_murayama" wrote:
>
> Hello!
>
> Great, that explains it all!
> So the other kinds of EEPROM probably have an auto erase before
rewriting.
> I have been using a 24C64 recently (EEPROM by I2C), and it can be
written, read
> byte by byte, overwritten as easily as any memory.
> Anyway thanks! What I thought was a workaraound:
> - Copy flash data into ram;
> - Erase flash;
> - Modify ram
> - Copy ram into flash;
> is in fact the only way to deal with the flash update.
>
> By the way, is there any sample code around, showing what FRKEY and
FXKEY
> are used for? Apparently I don't need those to read the flash.
>
> Pascal
>
> > To use simplified terms, basically you can write a '0' into Flash
(where a '1' was)
> > but you CANNOT write a '1' where a '0' was.... (you need to erase
for that)
> > You can however overwrite say like this :
> >
> > 1111 1111 into
> > 1111 1110 into
> > 1111 1000 etc...
> >
> > So you are still writing ones where there already were ones, same
for zeroes.
> > You can only write a maximum number of times to any array of Flash
which IIRC is 64
> bytes.
> > The number of writes is determined by the "Cumulative programming
time".
> >
> > HTH
> > Best Regards,
> > Kris
> >
> > -----Original Message-----
> > From: m... [mailto:m...] On
Behalf Of
> p_murayama
> > Sent: Monday, 25 February 2008 1:21 AM
> > To: m...
> > Subject: [msp430] Re: Data flash access
> >
> > Hello!
> >
> > It works fine now! Thanks a lot!
> >
> > > FLASH is a genre of EPROM (Erasable Programmable Read Only
Memory). As
> > > such, it can be read but cannot be written. In addition, it can also
> > > be "Programmed" and "Erased".
> >
> > Well, that must be a matter of nuance for experts, but for regular
users
> > like me, whatever you call the action of storing data ("write",
"put",
> > "program", "store"...), it's all about getting data into the chip.
> > Do you think the W in FWKEY or WRT in "FCTL1 = FWKEY + WRT;"
> > mean program, not write? What about chapter 5.3.3. of the user guide
> > ("Writing Flash Memory")?
> >
> > Having played with it today, it looks like it's better to first
erase it and
> > write a bunch of contiguous data. (writing twice at the same location
> > does not work).
> >
> > Here is the result fo this snowy sunday:
> >
> > http://passworld.co.jp/ForumMSP430/viewtopic.php?f=8&t0&p%2#p252
> >
> >
> > Pascal
>
Hello!

It works fine now! Thanks a lot!

> FLASH is a genre of EPROM (Erasable Programmable Read Only Memory). As
> such, it can be read but cannot be written. In addition, it can also
> be "Programmed" and "Erased".

Well, that must be a matter of nuance for experts, but for regular users
like me, whatever you call the action of storing data ("write", "put",
"program", "store"...), it's all about getting data into the chip.
Do you think the W in FWKEY or WRT in "FCTL1 = FWKEY + WRT;"
mean program, not write? What about chapter 5.3.3. of the user guide
("Writing Flash Memory")?

Having played with it today, it looks like it's better to first erase it and
write a bunch of contiguous data. (writing twice at the same location
does not work).

Here is the result fo this snowy sunday:

http://passworld.co.jp/ForumMSP430/viewtopic.php?f=8&t0&p%2#p252
Pascal

--- In m..., "old_cow_yellow" wrote:
>
> Pascal,
>
> FLASH is a genre of EPROM (Erasable Programmable Read Only Memory). As
> such, it can be read but cannot be written. In addition, it can also
> be "Programmed" and "Erased".
>
> "Programmable" means, with a special procedure, you can change any bit
> in FLASH from "1" to "0". "Erasable" means, with a different
> procedure, you can change all the bits in a block of FLASH to "1".
>
> MSP430F members all have on-chip "Flash Memory Controller" to do
> "Programming" or "Erasing". Some of the registers in the "Flash Memory
> Controller" have a special feature that reduces the possibility of
> unintentional access to these registers. When you write to these
> registers, you have to include FWKEY bits. (Otherwise, you will get a
> key violation.) When you read these registers, you will get the
> current setting of the other bits plus FRKEY instead of FWKEY. By the
> way, the standard header files also define FXKEY = FRKEY ^ FWKEY.
>
> I hope the above answers your questions in an indirect (but more
> enlightening?) way.
>
> --- In m..., "p_murayama" wrote:
> >
> > Hello!
> >
> > I am trying to write in the data flash. There are a couple ot things
> > I don't understand.
> >
> > 1. What is the meaning of FRKEY? I understand FWKEY as a kind of
> protection
> > so that the flash cannot be easily accidentaly overwritten. Am I
> right? But what
> > is the point of this when reading?
> > I can directly read what I wrote, for instance like this:
> >
> > #define DATA_FLASH 0x1000
> >
> > uint8 mydata;
> >
> > mydata = *(uimt8 *)(DATA_FLASH + offset);
> >
> > FRKEY is not used in TI's sample (slac15, for F169) code and they
> copy one
> > segment into the other by direct access to the flash.
> >
> > 2. A piece of TI's code (called fet140_flashwrite_01.c
> >
> > FCTL1 = FWKEY + ERASE;
> > FCTL3 = FWKEY;
> > *Flash_Ptr = 0; // Erase the segnment
> > FCTL1 = FWKEY + WRT;
> > for(i = 0 ; i < 128 ; ++i) {
> > Flash_Ptr++ = value;
> > }
> >
> > What I don't understand: why do they need to erase the segment
> > before writing the whole segment? Couldn't it be done by writing
> directly?
> > I tried, it works but I suspect there might be a reason...
> >
> > 3. What I tried after resetting the whole block is to write some
> data, and there
> > it does not work at all.
> >
> > Here is the code with some comments:
> >
> > [I skip the begining of the program, it simply stops the WDT
> (required for flash
> > writing) and sets the system frequency to XT2 (8MHz)]
> >
> > // First, set the clock to 1/64 of the crystal
> > FCTL2 = FWKEY + FSSEL_3 + 0x3F; // 0x3F is the divider by 64,
> therefore 125 kHz
> > FCTL3 = FWKEY; // Clear anything but key.
> > dataflash = (uint8 *) DATA_FLASH;
> > // FCTL1 = FWKEY + ERASE // Clearing one segment works without these
> lines
> > // *dataflash = 0; // but subsequent writings don't work even with
> these lines.
> > for(i = 0 ; i < 128 ; ++i) {
> > dataflash[i] = 0; // This works fine and clears everyting as
> expexcted
> > }
> > dataflash[18] = 0xAA; // Random writing. Does not work at all
> > FCTL1 = FWKEY; // Clears everything but the key
> > FCTL3 = FWKEY + LOCK;
> >
> >
> > Any hint?
> >
> > Thanks,
> >
> > Pascal
>
No AN EEPROM is NOT a FLASH, very different. EEPROMS are individually
addressable and writable, and can be overwritten like RAM. They are just
slow, and very expensive to implement. FLASH is block or segment
addressed and must be erased before it can be written. You must erase a
segment, but can write individual bytes/words.

Al

p_murayama wrote:

>Hello!
>
>Great, that explains it all!
>So the other kinds of EEPROM probably have an auto erase before rewriting.
>I have been using a 24C64 recently (EEPROM by I2C), and it can be written, read
>byte by byte, overwritten as easily as any memory.
>Anyway thanks! What I thought was a workaraound:
>- Copy flash data into ram;
>- Erase flash;
>- Modify ram
>- Copy ram into flash;
>is in fact the only way to deal with the flash update.
>
>By the way, is there any sample code around, showing what FRKEY and FXKEY
>are used for? Apparently I don't need those to read the flash.
>
>Pascal
>
>
>
>>To use simplified terms, basically you can write a '0' into Flash (where a '1' was)
>>but you CANNOT write a '1' where a '0' was.... (you need to erase for that)
>>You can however overwrite say like this :
>>
>>1111 1111 into
>>1111 1110 into
>>1111 1000 etc...
>>
>>So you are still writing ones where there already were ones, same for zeroes.
>>You can only write a maximum number of times to any array of Flash which IIRC is 64
>>
>>
>bytes.
>
>
>>The number of writes is determined by the "Cumulative programming time".
>>
>>HTH
>>Best Regards,
>>Kris
>>
>>-----Original Message-----
>>From: m... [mailto:m...] On Behalf Of
>>
>>
>p_murayama
>
>
>>Sent: Monday, 25 February 2008 1:21 AM
>>To: m...
>>Subject: [msp430] Re: Data flash access
>>
>>Hello!
>>
>>It works fine now! Thanks a lot!
>>
>>
>>
>>>FLASH is a genre of EPROM (Erasable Programmable Read Only Memory). As
>>>such, it can be read but cannot be written. In addition, it can also
>>>be "Programmed" and "Erased".
>>>
>>>
>>Well, that must be a matter of nuance for experts, but for regular users
>>like me, whatever you call the action of storing data ("write", "put",
>>"program", "store"...), it's all about getting data into the chip.
>>Do you think the W in FWKEY or WRT in "FCTL1 = FWKEY + WRT;"
>>mean program, not write? What about chapter 5.3.3. of the user guide
>>("Writing Flash Memory")?
>>
>>Having played with it today, it looks like it's better to first erase it and
>>write a bunch of contiguous data. (writing twice at the same location
>>does not work).
>>
>>Here is the result fo this snowy sunday:
>>
>>http://passworld.co.jp/ForumMSP430/viewtopic.php?f=8&t0&p%2#p252
>>Pascal
>>
>>
>
This goes to highlight what I've said many times before. programmers who
fail to learn about the hardware they are dealing with will fail. This
is not a thing for experts, it is very basic indeed. A technical data
sheet should be read in conjunction with the User Guide. The UG even
tells you this. technical Datat sheets assume some tiny bit of
knowledeg, it would be beyond their scope to try and teach rudimentay
hardware.

Al

p_murayama wrote:

>Hello!
>
>It works fine now! Thanks a lot!
>
>
>
>>FLASH is a genre of EPROM (Erasable Programmable Read Only Memory). As
>>such, it can be read but cannot be written. In addition, it can also
>>be "Programmed" and "Erased".
>>
>>Well, that must be a matter of nuance for experts, but for regular users
>like me, whatever you call the action of storing data ("write", "put",
>"program", "store"...), it's all about getting data into the chip.
>Do you think the W in FWKEY or WRT in "FCTL1 = FWKEY + WRT;"
>mean program, not write? What about chapter 5.3.3. of the user guide
>("Writing Flash Memory")?
>
>Having played with it today, it looks like it's better to first erase it and
>write a bunch of contiguous data. (writing twice at the same location
>does not work).
>
>Here is the result fo this snowy sunday:
>
>http://passworld.co.jp/ForumMSP430/viewtopic.php?f=8&t0&p%2#p252
>Pascal
>--- In m..., "old_cow_yellow" wrote:
>
>
>>Pascal,
>>
>>FLASH is a genre of EPROM (Erasable Programmable Read Only Memory). As
>>such, it can be read but cannot be written. In addition, it can also
>>be "Programmed" and "Erased".
>>
>>"Programmable" means, with a special procedure, you can change any bit
>>in FLASH from "1" to "0". "Erasable" means, with a different
>>procedure, you can change all the bits in a block of FLASH to "1".
>>
>>MSP430F members all have on-chip "Flash Memory Controller" to do
>>"Programming" or "Erasing". Some of the registers in the "Flash Memory
>>Controller" have a special feature that reduces the possibility of
>>unintentional access to these registers. When you write to these
>>registers, you have to include FWKEY bits. (Otherwise, you will get a
>>key violation.) When you read these registers, you will get the
>>current setting of the other bits plus FRKEY instead of FWKEY. By the
>>way, the standard header files also define FXKEY = FRKEY ^ FWKEY.
>>
>>I hope the above answers your questions in an indirect (but more
>>enlightening?) way.
>>
>>--- In m..., "p_murayama" wrote:
>>
>>
>>>Hello!
>>>
>>>I am trying to write in the data flash. There are a couple ot things
>>>I don't understand.
>>>
>>>1. What is the meaning of FRKEY? I understand FWKEY as a kind of
>>>
>>>
>>protection
>>
>>
>>>so that the flash cannot be easily accidentaly overwritten. Am I
>>>
>>>
>>right? But what
>>
>>
>>>is the point of this when reading?
>>>I can directly read what I wrote, for instance like this:
>>>
>>>#define DATA_FLASH 0x1000
>>>
>>>uint8 mydata;
>>>
>>>mydata = *(uimt8 *)(DATA_FLASH + offset);
>>>
>>>FRKEY is not used in TI's sample (slac15, for F169) code and they
>>>
>>>
>>copy one
>>
>>
>>>segment into the other by direct access to the flash.
>>>
>>>2. A piece of TI's code (called fet140_flashwrite_01.c
>>>
>>>FCTL1 = FWKEY + ERASE;
>>>FCTL3 = FWKEY;
>>>*Flash_Ptr = 0; // Erase the segnment
>>>FCTL1 = FWKEY + WRT;
>>>for(i = 0 ; i < 128 ; ++i) {
>>> Flash_Ptr++ = value;
>>>}
>>>
>>>What I don't understand: why do they need to erase the segment
>>>before writing the whole segment? Couldn't it be done by writing
>>>
>>>
>>directly?
>>
>>
>>>I tried, it works but I suspect there might be a reason...
>>>
>>>3. What I tried after resetting the whole block is to write some
>>>
>>>
>>data, and there
>>
>>
>>>it does not work at all.
>>>
>>>Here is the code with some comments:
>>>
>>>[I skip the begining of the program, it simply stops the WDT
>>>
>>>
>>(required for flash
>>
>>
>>>writing) and sets the system frequency to XT2 (8MHz)]
>>>
>>>// First, set the clock to 1/64 of the crystal
>>>FCTL2 = FWKEY + FSSEL_3 + 0x3F; // 0x3F is the divider by 64,
>>>
>>>
>>therefore 125 kHz
>>
>>
>>>FCTL3 = FWKEY; // Clear anything but key.
>>>dataflash = (uint8 *) DATA_FLASH;
>>>// FCTL1 = FWKEY + ERASE // Clearing one segment works without these
>>>
>>>
>>lines
>>
>>
>>>// *dataflash = 0; // but subsequent writings don't work even with
>>>
>>>
>>these lines.
>>
>>
>>>for(i = 0 ; i < 128 ; ++i) {
>>> dataflash[i] = 0; // This works fine and clears everyting as
>>>
>>>
>>expexcted
>>
>>
>>>}
>>>dataflash[18] = 0xAA; // Random writing. Does not work at all
>>>FCTL1 = FWKEY; // Clears everything but the key
>>>FCTL3 = FWKEY + LOCK;
>>>
>>>
>>>Any hint?
>>>
>>>Thanks,
>>>
>>>Pascal
>>>
>>>
>>