cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S003F3 program flash not unlocking

skirkham
Associate
Posted on June 21, 2012 at 13:54

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

http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/PROGRAMMING_MANUAL/CD00191pdf

, but it seems that when I try to write a block, nothing is happening. Here's my code:

FLASH->PUKR = FLASH_RASS_KEY1;
FLASH->PUKR = FLASH_RASS_KEY2;
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];
flashPtr++;
}
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));
}
//relock
FLASH->IAPSR &= (uint8_t)FLASH_MEMTYPE_PROG;

I repeat that a second time for bytes 64 -

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. #stm8s003f3 #flash-programming-stm8s
0 REPLIES 0