2017-08-22 12:15 AM
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..
2017-08-22 03:09 AM
The Flash memory cannot be used when programming.
In byte and word programming cases, the cpu will wait until the flash is ready again, when the operation is done, to continue.
In block programming, you still need to feed data while the flash memory is still busy.
This means the copy loop must be executed from RAM.
I recommend you look at the
implementation as reference.Once unzipped, there is an example in the STM8L15x-16x-05x-AL31-L_StdPeriph_Lib\Project\STM8L15x_StdPeriph_Examples\FLASH\Data_Program\ directory
2017-08-22 03:17 AM
This is clearly described in the
http://www.st.com/resource/en/programming_manual/cd00226555.pdf
PM0054 chapter 5.2