I'm encountering a silly problem with a flash routine that is declared to work in sysmem RAM section (CCS4), but sometimes thisRAM section seems disturbed shortly after power-up. Hard to believe that it is overwritten by a stack, since the stack usage is really limited.
Therefore I want to review the startup code (auto_init), But I don't find it in the ccsv4\ools\compiler\msp430 directory. It looks like it is contained in object form. Is that true?
The function in RAM especially tends to get corrupted when the target device is run without attached debugger. Any suggestions to localize the problem is appreciated.
The flash function is taken from old sample fet40_flashwrite_02, but avoiding the silly RAM copy mechanism:
#define FLASH_START (char *)0x1000
#pragma CODE_SECTION (flash_write, ".sysmem")
/*
* this function also erases the flash segment
*/
void flash_write(void *data, unsigned int size)
{
int i; // Use as write counter
char *Flash_ptr = FLASH_START; // Initialize Flash pointer
char *ptr = data;
FCTL2 = FWKEY | FSSEL1 | 19; // MCLK/2 for Flash Timing Generator
FCTL1 = FWKEY | ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
_DINT();
while(FCTL3 & BUSY); // Check Flash BUSY bit
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment
while(!(FCTL3 & WAIT)) // WAIT until Flash is ready
;
while(FCTL3 & BUSY); // Check Flash BUSY bit
FCTL1 = FWKEY + BLKWRT + WRT; // Enable block-write operation
for(i = 0; i < size; i++)
{
*Flash_ptr = *ptr; // Write value to flash
Flash_ptr++;
ptr++;
while(!(FCTL3 & WAIT)) // WAIT until Flash is ready
;
}
FCTL1 = FWKEY; // Clear BLKWRT & WRT bits
while(FCTL3 & BUSY) // Check Flash BUSY bit
;
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
_EINT();
return; // Exits routine
}