2017-08-21 11:53 PM
I'm use STM8L152R8.
I should be firmware upgrade using this cpu.
But, I have some problem as below...
Byte programming and word programming is no problem as below
FLASH->CR1 = 0; // Standard programming Time (EEPM, WAITM, IE Clear)
FLASH->DUKR = FLASH_RASS_KEY2; // Unlock Flash Data FLASH->DUKR = FLASH_RASS_KEY1; while ((FLASH->IAPSR & FLASH_IAPSR_DUL) == 0); // Wait Data EEPROM are unlock...
[Byte Programmin]
for (ulAddr = ulStartAddr; ulAddr < ulEndAddr; ulAddr++)
*((PointerAttr u8*) (MemoryAddressCast)ulAddr) = *i_pData++;[Word programming]
FLASH->CR2 |= FLASH_CR2_WPRG;
for (ulAddr = ulStartAddr; ulAddr < ulEndAddr; ulAddr += 4) // All write Size { *((PointerAttr u8*)(MemoryAddressCast)ulAddr) = *i_pData++; *(((PointerAttr u8*)(MemoryAddressCast)ulAddr) + 1) = *i_pData++; *(((PointerAttr u8*)(MemoryAddressCast)ulAddr) + 2) = *i_pData++; *(((PointerAttr u8*)(MemoryAddressCast)ulAddr) + 3) = *i_pData++; }...
FLASH->IAPSR &= ~FLASH_IAPSR_DUL; // Flash Lock
But, I should be use block programming because byte and word programming is too slow..
I use this code... But always cpu stop..... (I use this function execute memory)
FLASH->CR2 |= FLASH_CR2_PRG;
for (ulAddr = ulStartAddr; ulAddr < ulEndAddr; ulAddr++) *((PointerAttr u8*) (MemoryAddressCast)ulAddr) = *i_pData++;Please help me...