Celso Providelo wrote:
On Fri, 2003-12-05 at 14:23, D.Pageau wrote:
I'm looking for example on how to self read/write the 2x 128Bytes
information memory (flash) with mspgcc
Thanks
--
Dominic Pageau
Just have a look to the attachment, there is a read_ffs() and a
write_ffs(), simply ignore the data allocation and attempt to the flash
self-programming system initialization.
It works but isn't so beautiful, sorry, but I hope it can help ...
regards
What is all that complexity in your reading routing for? The info memory
works the same as the rest of flash.The only difference is the page size
- info memory is in 128 byte pages. main memory is in 512 byte pages.
There are no special issues related to reading it - its just memory. Any
read from it works with fiddling with the flash control regirsters. In
fact, chaning those is a bad idea for reading from flash - you expose
the memory to unwanted writes if anything goes wrong.
The will erase a page of flash memory (info or main) to all ones:
void flash_clr(int *ptr)
{
_DINT();
FCTL3 = FWKEY; /* Lock = 0 */
FCTL1 = FWKEY | ERASE;
*((int *) ptr) = 0; /* Erase flash segment */
}
"ptr" should point to anywhere within the page to be erased. The
assignment to the flash memory takes a while (16ms rings a bell), and
the CPU while freeze at that instruction for the appropriate time.
The following will write a word in flash memory, It has to unlock the
memory for writing. Then it just does a write to the relevant location.
You can't write bytes. You have to write whole 16 bit words. Since
erased flash is all 1s, you can get the effect of writing a byte by
actually writing a word with the extra byte set to 0xFF. The write will
success, but the byte you do not wish to write will remain unchanged.
Each write takes about 75us, and as with the the erase operation the
processor just freezes at the assignment instruction for the appropriate
length of time.
void flash_write_int16(int16_t *ptr, int16_t value)
{
_DINT();
FCTL3 = FWKEY; /* Lock = 0 */
FCTL1 = FWKEY | WRT;
*((int16_t *) ptr) = value; /* Program the flash */
}
When you have finished erasing or writing some words you should use this
to secure the flash from further changes:
void flash_secure(void)
{
_DINT();
FCTL1 = FWKEY;
FCTL3 = FWKEY | LOCK;
_EINT();
}
Regards,
Steve