AnsweredAssumed Answered

Flash page erase problem. stm32f103vb

Question asked by dufrane.marcus on Aug 11, 2015
Latest reply on Aug 11, 2015 by Clive One
Im having an issue erasing pages of flash. During my bootloader application while receiving a block of data I erase the page and then write the data. During testing I have the messaging protocol setup to just read the data into ram and erase the page, without writing, an attempt to simplify debugging. The problem is not all pages are erased.

My bootloader resides at 0x0800000 with all the proper precautions regarding the interrupt table. Prior to testing the erase functionality the bootloader was function fine, included passing off to an application loaded previously. The app reside at 0x08001000.
During erase testing, the bootloader attempts to erase the addresses 0x08001000, 0x08001400, 0x08001C00... 0x0800AC00.

Only a small handfull of the pages are actually erased.

What I've done to debug. 
I have verified that the pages are not write protected, I have also monitored the status register after each erase cycle. The status indicate EOP with no other issues.

I have the flash latency set to 2. The unlock procedure has been verified.

I have added additional NOP's after the register commands to erase a page with no result.

The only thing of note is that the same pages are affected.

I have also verified that my bootloader resides completely within 0x08000000 and 0x08001000.

below is my page erase function:
uint8_t erasePage(uint32_t pageAddress)
{
    uint32_t *address;
    waitForOperation();
    //set page erase bit
    FLASH->CR |= FLASH_CR_PER;
    __ASM volatile ("nop");
    __ASM volatile ("nop");
    __ASM volatile ("nop");
    __ASM volatile ("nop");
    FLASH->AR |= pageAddress;
    __ASM volatile ("nop");
    __ASM volatile ("nop");
    __ASM volatile ("nop");
    __ASM volatile ("nop");
    FLASH->CR |= FLASH_CR_STRT;
    
    waitForOperation();
    
    FLASH->CR &= FLASH_CR_PER;
    __ASM volatile ("nop");
    __ASM volatile ("nop");
    __ASM volatile ("nop");
    __ASM volatile ("nop");
    
    //verify erase
    for(address = pageAddress; address < pageAddress + 1024; address += 4)
    {
        if(*address != 0xFFFFFFFF)
        {
            return 1;
        }
    }
    return 0;
}

I must be missing something non trivial. Any ideas are welcomed.

Thanks

Outcomes