EmbeddedRelated.com
Forums

Flash into RAM question

Started by Heather August 4, 2003
Good Morning!

  I've got a question:  I'm using the Quadravox C Compiler for the 
MSP430(f449) microchip, and currently need to overwrite the Flash 
memory.  I've reviewed and used the app note on Flash Self-
Programming, but the C program shown reprograms the Flash directly, 
without moving the function to RAM first.  I know the concept is 
fairly simple:
1. copy program to RAM
2. change PC to point to RAM copy of function
3. change PC back when finished
... Unfortunately, my experience with assembly is non-impressive 
almost to the point of non-existence.  As a result, I'm having a 
problem interpreting the assembly functions to figure out how to do 
this in C.  I'm especially confused on how to copy the program into 
RAM...  Can anybody help me?

  Thanks
   Heather


Beginning Microcontrollers with the MSP430

The app note pushes the RAM CODE onto the STACK. A call is made to the RAM
code and then returns.

It's a nasty little piece of code but is does work.

I had a tough time with FLASH programming out of RAM code myself. Timing is very
important.

Ted Gregorius (Pres)
TAG Systems Racing Products, Inc.
www.tagrace.com
  ----- Original Message ----- 
  From: Heather 
  To: msp430@msp4... 
  Sent: Monday, August 04, 2003 9:40 AM
  Subject: [msp430] Flash into RAM question


  Good Morning!

    I've got a question:  I'm using the Quadravox C Compiler for the 
  MSP430(f449) microchip, and currently need to overwrite the Flash 
  memory.  I've reviewed and used the app note on Flash Self-
  Programming, but the C program shown reprograms the Flash directly, 
  without moving the function to RAM first.  I know the concept is 
  fairly simple:
  1. copy program to RAM
  2. change PC to point to RAM copy of function
  3. change PC back when finished
  ... Unfortunately, my experience with assembly is non-impressive 
  almost to the point of non-existence.  As a result, I'm having a 
  problem interpreting the assembly functions to figure out how to do 
  this in C.  I'm especially confused on how to copy the program into 
  RAM...  Can anybody help me?

    Thanks
     Heather


        
             
       
       

  .



   





Ted:  Thanks for the quick response!

  Hmm... That was what I thought it was telling me to do.  How does 
one access the stack and the flash and get this all moving, in C?  
Unfortunately, running this out of RAM is important to the project...

  Thank you!
  HAO

--- In msp430@msp4..., "Ted Gregorius" <ted@t...> wrote:
> The app note pushes the RAM CODE onto the STACK. A
call is made to 
the RAM code and then returns.
> 
> It's a nasty little piece of code but is does work.
> 
> I had a tough time with FLASH programming out of RAM code myself. 
Timing is very important.
> 
> Ted Gregorius (Pres)
> TAG Systems Racing Products, Inc.
> www.tagrace.com
>   ----- Original Message ----- 
>   From: Heather 
>   To: msp430@msp4... 
>   Sent: Monday, August 04, 2003 9:40 AM
>   Subject: [msp430] Flash into RAM question
> 
> 
>   Good Morning!
> 
>     I've got a question:  I'm using the Quadravox C Compiler for 
the 
>   MSP430(f449) microchip, and currently need to
overwrite the Flash 
>   memory.  I've reviewed and used the app note on Flash Self-
>   Programming, but the C program shown reprograms the Flash 
directly, 
>   without moving the function to RAM first.  I
know the concept is 
>   fairly simple:
>   1. copy program to RAM
>   2. change PC to point to RAM copy of function
>   3. change PC back when finished
>   ... Unfortunately, my experience with assembly is non-impressive 
>   almost to the point of non-existence.  As a result, I'm having a 
>   problem interpreting the assembly functions to figure out how to 
do 
>   this in C.  I'm especially confused on how
to copy the program 
into 
>   RAM...  Can anybody help me?
> 
>     Thanks
>      Heather
> 
> 



I use the direct Flash programming method more than the program from RAM 
method. Simply because, by the time I've moved the code to RAM, updated 
Flash, and continued I've lost more time than is involved in the direct 
write method. This works for nearly everything, even code update. I have 
a very thoroughly tested piece of comms code combined with flash manager 
that is the only sector I don't erase, I can then freely erase a sector 
at a time, re-programming it and verify as I go, allowing retries etc. 
using markers in data flash I also can handle power failures during 
update, since my flash code is in the start up code pointed to by the 
reset vector. It just gets skipped in normal operation. The RAM based 
method lacks this robustness, and I find it far harder to manage. I 
mainly use FLASH as a data logging store, workign from flash directly 
imposes the least interference to the logging cycle as well.

Sorry but assembler only for me.

Al

Heather wrote:
> Good Morning!
> 
>   I've got a question:  I'm using the Quadravox C Compiler for
the 
> MSP430(f449) microchip, and currently need to overwrite the Flash 
> memory.  I've reviewed and used the app note on Flash Self-
> Programming, but the C program shown reprograms the Flash directly, 
> without moving the function to RAM first.  I know the concept is 
> fairly simple:
> 1. copy program to RAM
> 2. change PC to point to RAM copy of function
> 3. change PC back when finished
> ... Unfortunately, my experience with assembly is non-impressive 
> almost to the point of non-existence.  As a result, I'm having a 
> problem interpreting the assembly functions to figure out how to do 
> this in C.  I'm especially confused on how to copy the program into 
> RAM...  Can anybody help me?
> 
>   Thanks
>    Heather
> 
> 
> 
> .
> 
>  
> 
> ">http://docs.yahoo.com/info/terms/ 
> 
> 
> 


Al,

  Thanks for the response... direct Flash programming does sounds 
like it has a number of useful aspects...  Question, though -- is it 
possible to poll the UART for input?  Or would I have to have an 
entire sector's replacement in RAM before I could use this technique?

  Thank you!

   Heather

--- In msp430@msp4..., onestone <onestone@b...> wrote:
> I use the direct Flash programming method more
than the program 
from RAM 
> method. Simply because, by the time I've
moved the code to RAM, 
updated 
> Flash, and continued I've lost more time than
is involved in the 
direct 
> write method. This works for nearly everything,
even code update. I 
have 
> a very thoroughly tested piece of comms code
combined with flash 
manager 
> that is the only sector I don't erase, I can
then freely erase a 
sector 
> at a time, re-programming it and verify as I go,
allowing retries 
etc. 
> using markers in data flash I also can handle
power failures during 
> update, since my flash code is in the start up code pointed to by 
the 
> reset vector. It just gets skipped in normal
operation. The RAM 
based 
> method lacks this robustness, and I find it far
harder to manage. I 
> mainly use FLASH as a data logging store, workign from flash 
directly 
> imposes the least interference to the logging
cycle as well.
> 
> Sorry but assembler only for me.
> 
> Al
> 
> Heather wrote:
> > Good Morning!
> > 
> >   I've got a question:  I'm using the Quadravox C Compiler
for 
the 
> > MSP430(f449) microchip, and currently need to
overwrite the Flash 
> > memory.  I've reviewed and used the app note on Flash Self-
> > Programming, but the C program shown reprograms the Flash 
directly, 
> > without moving the function to RAM first.  I
know the concept is 
> > fairly simple:
> > 1. copy program to RAM
> > 2. change PC to point to RAM copy of function
> > 3. change PC back when finished
> > ... Unfortunately, my experience with assembly is non-impressive 
> > almost to the point of non-existence.  As a result, I'm having a 
> > problem interpreting the assembly functions to figure out how to 
do 
> > this in C.  I'm especially confused on
how to copy the program 
into 
> > RAM...  Can anybody help me?
> > 
> >   Thanks
> >    Heather
> > 
> > 
> > 
> > .
> > 
> >  
> > 
> > ">http://docs.yahoo.com/info/terms/ 
> > 
> > 
> >


Once you have erased a segment you can program it either word at a time 
or byte at a time, so no need to buffer an entire segment. ie you can 
poll the UART. I do recommned that you add some robust error checking so 
that you can retry for lost data, failed data etc. You also should have 
some power fail strategy if a power loss is possible, And, if you are 
writing new program code  especially you need to be aware of failed 
bytes. Often repeated write attempts will work, but if this fails you 
either scrap the part, or recompile with JMP instructions over the dead 
areas. It is not so critical writing data, you can simply maintain a log 
of failed bytes

Al

Heather wrote:
> Al,
> 
>   Thanks for the response... direct Flash programming does sounds 
> like it has a number of useful aspects...  Question, though -- is it 
> possible to poll the UART for input?  Or would I have to have an 
> entire sector's replacement in RAM before I could use this technique?
> 
>   Thank you!
> 
>    Heather
> 
> --- In msp430@msp4..., onestone <onestone@b...> wrote:
> 
>>I use the direct Flash programming method more than the program 
> 
> from RAM 
> 
>>method. Simply because, by the time I've moved the code to RAM, 
> 
> updated 
> 
>>Flash, and continued I've lost more time than is involved in the 
> 
> direct 
> 
>>write method. This works for nearly everything, even code update. I 
> 
> have 
> 
>>a very thoroughly tested piece of comms code combined with flash 
> 
> manager 
> 
>>that is the only sector I don't erase, I can then freely erase a 
> 
> sector 
> 
>>at a time, re-programming it and verify as I go, allowing retries 
> 
> etc. 
> 
>>using markers in data flash I also can handle power failures during 
>>update, since my flash code is in the start up code pointed to by 
> 
> the 
> 
>>reset vector. It just gets skipped in normal operation. The RAM 
> 
> based 
> 
>>method lacks this robustness, and I find it far harder to manage. I 
>>mainly use FLASH as a data logging store, workign from flash 
> 
> directly 
> 
>>imposes the least interference to the logging cycle as well.
>>
>>Sorry but assembler only for me.
>>
>>Al
>>
>>Heather wrote:
>>
>>>Good Morning!
>>>
>>>  I've got a question:  I'm using the Quadravox C Compiler
for 
> 
> the 
> 
>>>MSP430(f449) microchip, and currently need to overwrite the Flash 
>>>memory.  I've reviewed and used the app note on Flash Self-
>>>Programming, but the C program shown reprograms the Flash 
> 
> directly, 
> 
>>>without moving the function to RAM first.  I know the concept is 
>>>fairly simple:
>>>1. copy program to RAM
>>>2. change PC to point to RAM copy of function
>>>3. change PC back when finished
>>>... Unfortunately, my experience with assembly is non-impressive 
>>>almost to the point of non-existence.  As a result, I'm having
a 
>>>problem interpreting the assembly functions to figure out how to 
> 
> do 
> 
>>>this in C.  I'm especially confused on how to copy the program 
> 
> into 
> 
>>>RAM...  Can anybody help me?
>>>
>>>  Thanks
>>>   Heather
>>>
>>>
>>>
>>>.
>>>
>>> 
>>>
>>>">http://docs.yahoo.com/info/terms/ 
> 
>>>
>>>
> 
> 
> 
> .
> 
>  
> 
> ">http://docs.yahoo.com/info/terms/ 
> 
> 
>