AnsweredAssumed Answered

STM8L Flash Programming

Question asked by Han JaeSeong on Aug 22, 2017
Latest reply on Aug 22, 2017 by Maxime TEISSIER

I use STM8L152R8..

I test flash programming... But, now some problem exists...

 

Byte programming and word programming is no problem.

But, i use block programming then CPU halted.....

 

#pragma location = "FLASH_CODE"
void Mem_ProgramBlock(u16 BlockNum, const u8 *Buffer)
{
u16 Count = 0;
u32 StartAddress = 0;

 

/* Set Start address wich refers to mem_type */
StartAddress = FLASH_PROGRAM_START_PHYSICAL_ADDRESS;

/* Point to the first block address */
StartAddress = StartAddress + ((u32)BlockNum * FLASH_BLOCK_SIZE);

/* Standard programming mode */
FLASH->CR2 |= (u8)0x01;

/* Copy data bytes from RAM to FLASH memory */
for (Count = 0; Count < FLASH_BLOCK_SIZE; Count++)
{
*((PointerAttr u8*)StartAddress + Count) = ((u8)(Buffer[Count]));     <= Halted
}

}

 

I use memory.... I unlock cpu before this function.... as below

 

FLASH->CR1 = 0; // Standard programming Time (EEPM, WAITM, IE Clear)
FLASH->PUKR = FLASH_RASS_KEY1; // Unlock Flash Data
FLASH->PUKR = FLASH_RASS_KEY2;
while ((FLASH->IAPSR & FLASH_IAPSR_PUL) == 0); 

 

I did not find out some bug......

Always  CPU halted in flash programming functioin...

Please help me..

Outcomes