AnsweredAssumed Answered

STM8S003F3 program flash not unlocking

Question asked by kirkham.sam on Jun 21, 2012
Hi all,

I'm trying to write an update routine for an STM8S003F3, so that it can be updated over SPI.

I'm pulling 128byte chunks of data from a routine in ram, then attempting to write them to the main program flash. I've tried to follow the programming guide
here, but it seems that when I try to write a block, nothing is happening. Here's my code:

FLASH->CR2 |= (u8)0x01;
FLASH->NCR2 &= (u8)~0x01;          
flashPtr = (u8*)(PROGRAM_FLASH_START_ADDRESS + (numBlocksWritten * 128));
for (i = 0; i < 64; i++)
    //write the block directly to memory offset by the number of 128 sized blocks written, and the start adress of the programming memory
    *flashPtr = 0; //spiPacket[3 + i];
flagstatus = 0x00;
//wait until the write has occured
while ((flagstatus == 0x00) && (flashWriteTimeout != 0x00))
    flagstatus = (uint8_t)(FLASH->IAPSR & (FLASH_IAPSR_EOP | FLASH_IAPSR_WR_PG_DIS));

I repeat that a second time for bytes 64 - 128.

I'm just writing 0x00 to each address here for testing purposes, but it's not doing anything. I feel like I must be missing something important, but can't figure it out from the guide. Any help would be much appreciated.