Dmitry wrote:
>
> Fellows,
> there is a code snippet:
>
> static int __attribute__((section(".infomemnobits"))) interf;
>
> void critical flash_ww(int *data, int val)
> {
> while(BUSY & FCTL3);
> FCTL3 = FWKEY;
> FCTL1 = FWKEY + WRT;
> *data = val;
> FCTL1 = FWKEY;
> FCTL3 = FWKEY + LOCK;
> }
>
> void write_value(int val)
> {
> flash_ww(&interf, val);
> }
>
> int read_value()
> {
> return interf;
> }
>
> So, any write to flash memory returns no errors,
> however reading from information memory always returns zero.
> Where am I wrong?
>
You have specifically asked not to initialize interf. You can only
change bits that are 1's.
I do something like this:
const int interf = 0xffff;
void critical flash_ww(int *data, int val)
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
dint();
FCTL2 = FWKEY + FSSEL_2 + FN2; // SMCLK/4 for Flash Timing Generator
3.684Mhz clk
FCTL3 = FWKEY;
FCTL1 = FWKEY + WRT;
*data = val; //initialized to 0xffff
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
// re-enalble WDT?
eint();
};
It only works once since you can only reliably write to 0xffff.
Cheers,
Garst