cancel
Showing results for 
Search instead for 
Did you mean: 

Flash page erase problem. stm32f103vb

marcusdufrane
Associate III
Posted on August 11, 2015 at 18:26

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

#stm32 #flash #f103
3 REPLIES 3
Posted on August 11, 2015 at 19:28

FLASH->AR |= pageAddress; // Won't this cause bits to stick all high eventually, perhaps you want to mask the bits

''Only a small handful of the pages are actually erased.''

What does this mean in reality? Which pages are erased and which aren't, is there some pattern to it?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
marcusdufrane
Associate III
Posted on August 11, 2015 at 19:35

WOW! What a ridiculous error! I feel the need to apologize for wasting your time on that one. Sorry. Too much coffee today.

Posted on August 11, 2015 at 19:58

No worries, some times it's hard to see the wood for the trees when you've been staring at it too long.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..