I found that the write flash bit is not remove when buffer is not full.
Our MSP430 flash was “something” corrupted if I was using CHECK_CRC followed by a SET_PC. Its calling twice flushbuffer, which will force a set WRT which will never be unset until a reset.
I’m sharing for others…
/*******************************************************************************
* *Function: flushBuffer
* *Description: Flushes any remaining data in the buffer
* *Returns:
* SUCCESSFUL_OPERATION Flash is now locked.
*******************************************************************************/
#ifdef RAM_BASED_BSL
char flushBuffer(void)
{
unsigned long i;
char exceptions = SUCCESSFUL_OPERATION;
unsigned char* data = &BlockBuffer[0];
if (LockedStatus == UNLOCKED)
{
if (((BlockBufferStart & 0x7F) == 0) && (BlockBufferPtr == 128)) //Buffer is full and
// aligned
{
while (FCTL3 & BUSY) ;
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY + BLKWRT + WRT; // Set write/block bit
for (i = BlockBufferStart; i < BlockBufferStart + 128; i += 4)
{
__data20_write_long(i, *((long*)data));
data += 4;
while ((FCTL3 & WAIT) == 0) ;
} // for
FCTL1 = FwRamKey;
while (FCTL3 & BUSY) ;
FCTL3 = FwRamKey + LOCK;
} // if
else
{
FCTL3 = FwRamKey; // Clear Lock bit
FCTL1 = FwRamKey + WRT; // Set write bit
for (i = BlockBufferStart; i < BlockBufferStart + BlockBufferPtr; i++)
{
if ((BlockBufferStart & 0x01) || i == BlockBufferStart + BlockBufferPtr - 1)
{
exceptions = BSL430_writeByte(i, *data);
data += 1;
}
else
{
exceptions = BSL430_writeWord(i, *(int *)data);
data += 2;
i++;
}
if (exceptions != SUCCESSFUL_OPERATION)
{
return exceptions;
} // if
} // for
// GHE: Fix where flash is written unexpectedly on a set pc
FCTL1 = FwRamKey;
while (FCTL3 & BUSY) ;
FCTL3 = FwRamKey + LOCK;
// GHE: End of the fix
} // else
BlockBufferStart = 0;
BlockBufferNext = 0;
BlockBufferPtr = 0;
}
else
{
exceptions = BSL_LOCKED;
}
return exceptions;
}