> At 15:31 23-03-05 -0500, you wrote:
> > Hi all, I want to reprogram my F1612 in the field via
RS232. To
> >be able to use block writing, I must run my reprogramming code from RAM
and
> >I wonder how I can transfer a function (already in flash) there. I must
> >know the code start and stop address to copy the entire code in RAM and
> >then change the PC register to start reprogramming. I would like to do
this
> >in C if it’s possible. Thanks, Fred
>
Hi Fred,
if you do not care about a few wasted ram bytes during the reprogramming
you can do the following:
Write your reprogramming code as usual, compile and check the size of the
reprogramming function in the map file. Now use a character array with the
size of your function plus a little bit of headroom. You can memcpy your
function to the character array and call it in ram. Here the solution i
use (in my example the character array is global because i use a dedicated
boot programm for reprogramming and i do not care about the wasted ram.
But of course the character array can also live in the stack so the ram
space is only wasted during reprogramming):
#define byte unsigned char
#define sbyte signed char
#define word unsigned short int
#define sword signed short int
#define dword unsigned long int
#define sdword signed long int
#define bool unsigned char
typedef void(*vwwpwFnctPtr)(word, word *, word );
static char fnct_data[128];
void DoWriteSegment (word Dest, word *Src, word BlckCnt );
/********************************************************/
sword WriteSegment ( word Dest, word *Src, word len ) {
word blockcnt;
vwwpwFnctPtr copyfnct = (vwwpwFnctPtr)fnct_data;
if ( (Dest < 0x1100) OR ((Dest + len) > 0xE000) ) {
return -1;
}
blockcnt = len / 64; // ein Block = 64 Byte
if ( (len % 64) != 0 ) blockcnt++;
// Watch Busy Bit
while ( (FCTL3 & BUSY) != 0 );
FCTL2 = FWKEY | FSSEL_1 | 19;
memcpy(fnct_data,DoWriteSegment,sizeof(fnct_data));
copyfnct(Dest,Src,blockcnt);
return 0;
}
/********************************************************/
void DoWriteSegment (word Dest, word *Src, word BlckCnt ) {
word m;
dint();
// Reset LockBit
FCTL3 = FWKEY;
while ( BlckCnt > 0 ) {
BlckCnt--;
// Set Write and WriteBlock Bit
FCTL1 = FWKEY | WRT | BLKWRT;
// Execute Write to segment
for ( m = 64/2; m > 0 ; m-- ) {
*((word*)Dest) = *Src++;
Dest += 2;
while ( (FCTL3 & WAIT) == 0 );
}
// Clear Write bits
FCTL1 = FWKEY;
// Watch Busy Bit
while ( (FCTL3 & BUSY) != 0 );
}
// Set Lock Bit
FCTL3 = FWKEY + LOCK;
eint();
}
Cheers,
Christian