EmbeddedRelated.com
Forums

First time trying flash

Started by Dan Bloomquist February 14, 2009
I want to use the flash in the f1013. So I found some sample code:

case COMMAND_ERASE_FLASH:
{
volatile char* Flash_ptr; // Flash pointer
//unsigned int i;

Flash_ptr = (char *) 0x1080; // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase
Flash segment

FCTL1 = FWKEY + WRT; // Set WRT bit for write
operation
break;
}

I'm running from the power of the USB programmer, 3.6 volts. But when I
inspect the flash where I have other than 0xff data it still has data!?
I am most certainly hitting this code.

Thanks, Dan.

--
email: y...@lakeweb.net but drop the 'x'.

Beginning Microcontrollers with the MSP430

Dan
Have a look at msp430FlashRoutines.zip in the files section of this
group.

Regards
-Bill Knight
R O SoftWare
Dan Bloomquist wrote:
> I want to use the flash in the f1013. So I found some sample code:
>
> case COMMAND_ERASE_FLASH:
> {
> volatile char* Flash_ptr; // Flash pointer
> //unsigned int i;
>
> Flash_ptr = (char *) 0x1080; // Initialize Flash pointer
> FCTL1 = FWKEY + ERASE; // Set Erase bit
> FCTL3 = FWKEY; // Clear Lock bit
> *Flash_ptr = 0; // Dummy write to erase
> Flash segment
>
> FCTL1 = FWKEY + WRT; // Set WRT bit for write
> operation
> break;
> }
>
> I'm running from the power of the USB programmer, 3.6 volts. But when I
> inspect the flash where I have other than 0xff data it still has data!?
> I am most certainly hitting this code.
>
> Thanks, Dan.
>

Bill Knight wrote:
> Dan
> Have a look at msp430FlashRoutines.zip in the files section of this
> group.
>
>
Hi Bill,
Thanks. After a couple of hours of reading I have learned more about the
clock and the flash than anyone should know. :)

Now with SMCLK at 1.04mhz I can divide by 2, hot for the spec, and
write/erase. And I can do it with divide by 4, just below the spec. What
is the typical policy for this as the default ~1mhz can not be brought
inside the spec? ( ~ 257 kHz to ~ 476 kHz )

Thanks, Dan.

BTW, I took my wife to lunch and to see 'Taken' today. Action packed!

--
email: y...@lakeweb.net but drop the 'x'.

I'm using mspgcc.

Really, I do search before asking stuff. I'm using the flash for a table
that can be altered. Now I can load the table fine but every time I
reload the program for another round, my flash gets erased. I would
expect this from "monitor erase all". But I can't find an alternative
that would leave the user flash alone.

An even better solution would be if I could just include the table in an
object file while I'm developing and have it written to the user flash
with the program. But I can't figure out how to do that either. Maybe a
.asm file with .org at 0x1000?

Thanks, Dan.

--
email: y...@lakeweb.net but drop the 'x'.

Dnia 15-02-2009, nie o godzinie 20:00 -0700, Dan Bloomquist napisał(a):
> I'm using mspgcc.
>
> Really, I do search before asking stuff. I'm using the flash for a
> table
> that can be altered. Now I can load the table fine but every time I
> reload the program for another round, my flash gets erased. I would
> expect this from "monitor erase all". But I can't find an alternative
> that would leave the user flash alone.

Try "monitor erase main" ;-)
--
Albert

Albert Bartoszko wrote:
> Dnia 15-02-2009, nie o godzinie 20:00 -0700, Dan Bloomquist napisał(a):
>
>> I'm using mspgcc.
>>
>> Really, I do search before asking stuff. I'm using the flash for a
>> table
>> that can be altered. Now I can load the table fine but every time I
>> reload the program for another round, my flash gets erased. I would
>> expect this from "monitor erase all". But I can't find an alternative
>> that would leave the user flash alone.
>>
>
> Try "monitor erase main" ;-)
>
Thanks Albert!

How cool is that? It works, and saves me a pile of time.

Best, Dan.

--
email: y...@lakeweb.net but drop the 'x'.

First, as far as I know, default DCO clk on MSP430x1xx devices is
about 800kHz, while 1MHz is default for MSP430x2xx devices.

Setting SMCLK to a lower frequency is not the only way to lower the
flash clock. If you ARE using SMCLK at 1MHz, why don't you set the
flash clock divider on '/3'? you'd get right within specs. You can use
ACLK, SMCLK or MCLK and divide it between 1 and 64. Check register
FCTL2 for more details on chapter 5 of the user guide (SLAU049).

Regards,
Michael K.
--- In m..., Dan Bloomquist wrote:
>
> Bill Knight wrote:
> > Dan
> > Have a look at msp430FlashRoutines.zip in the files section of
this
> > group.
> >
> >
> Hi Bill,
> Thanks. After a couple of hours of reading I have learned more about
the
> clock and the flash than anyone should know. :)
>
> Now with SMCLK at 1.04mhz I can divide by 2, hot for the spec, and
> write/erase. And I can do it with divide by 4, just below the spec.
What
> is the typical policy for this as the default ~1mhz can not be brought
> inside the spec? ( ~ 257 kHz to ~ 476 kHz )
>
> Thanks, Dan.
>
> BTW, I took my wife to lunch and to see 'Taken' today. Action packed!
>
> --
> email: yotox@... but drop the 'x'.
>

Hi Micheal,
Thanks.
Sorry about the first typo on the 2013.

So, from what I understand I can just bit out the GIE, push the status
register and then pop it when I'm done?
Also I'm using the WDT for a normal interrupt timer.

WDT_ADLY_1000 has WDTTMSEL and I assume this means no watchdog.

Best, Dan.
static void __inline__ _start_flash( )
{
__asm__ __volatile__(
"push r2 \n"
"bit #0xf7, r2 \n"
);
}

static void __inline__ _end_flash( )
{
__asm__ __volatile__(
"pop r2 \n"
);
}

And:
//this comes from signature check to have pointer...
if( flash_write_ptr )
{
_start_flash( );
FCTL1= FWKEY + ERASE; // Set Erase bit
FCTL3= FWKEY; // Clear Lock bit

*flash_write_ptr= 0; // Dummy write to erase
Flash segment

FCTL3= FWKEY // flash write key
| LOCK; // LOCK = 1
_end_flash( );
}
--
email: y...@lakeweb.net but drop the 'x'.