cancel
Showing results for 
Search instead for 
Did you mean: 

Problem writing to flash

ian239955
Associate II
Posted on July 09, 2014 at 11:55

Hi, I'm running the example code to try to program the flash memory. This starts:

void WriteFlash(void)

{  

  /*!< At this stage the microcontroller clock setting is already configured, 

       this is done through SystemInit() function which is called from startup

       file (startup_stm32f4xx.s) before to branch to application main.

       To reconfigure the default setting of SystemInit() function, refer to

       system_stm32f4xx.c file

     */

  

  /* Unlock the Flash to enable the flash control register access *************/ 

  FLASH_Unlock();

 

/* Erase the user Flash area

    (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR)

***********//* Clear pending flags (if any) */  

  FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | 

                  FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); 

.............        etc................ 

Then it erases the flash:

if (FLASH_EraseSector(i, VoltageRange_3) != FLASH_COMPLETE) ..... 

But when I step into this, it jumps out to a hard fault on this line:

/* if the erase operation is completed, disable the SER Bit */

    FLASH->CR &= (~FLASH_CR_SER);

Does anyone know what the hard fault is and how to overcome it?

Thanks

2 REPLIES 2
ian239955
Associate II
Posted on July 09, 2014 at 14:58

Solved it, I did not think I was, but I was erasing the code that was running. derrrrrr.

Posted on July 09, 2014 at 15:22

Solved it, I did not think I was, but I was erasing the code that was running. derrrrrr.

That tends to rain on the parade a bit. I'd also watch out for what the ART has cached.

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