cancel
Showing results for 
Search instead for 
Did you mean: 

FLASH of stm32L152 operating in EEPROM when the main program is advanced after IAP. PEKEYR = PEKEY1;

chench
Associate

static void EEPROM_WriteBytes(u32 Addr, u8 *Buffer, u16 Length)
{
u8 *wAddr = NULL;
wAddr = (u8 *)Addr;

DIS_INT;

FLASH->PEKEYR = PEKEY1; // unlock     // this is Program stuck
FLASH->PEKEYR = PEKEY2;

while(FLASH->PECR & FLASH_PECR_PELOCK); // wait PELOCK set 0(unlocked)
FLASH->PECR |= FLASH_PECR_FTDW; // not fast write

while(Length--)
*wAddr++ = *Buffer++;
while(FLASH->SR & FLASH_SR_BSY);

FLASH->PECR |= FLASH_PECR_PELOCK; // lock

EN_INT;
}

1 REPLY 1
STOne-32
ST Employee

Dear @chench ,

Can you please let us know if the sequence above is working and you advance on the programming . in general it is not recommended to have the Flash keys in same Write / Programming function to avoid an accidental jump to it . May be to move outside 

Let us know .

STOne-32