cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to write to specific addresses in flash

arnold_w
Senior
Posted on June 24, 2015 at 14:28

I am working with the 

Discovery development board 

STM32F407 microcontroller and building using Eclipse/GNU. I trying to reprogram sector 0 (address range: 0x0800 0000 - 0x0800 3FFF; 16 Kbytes total) from within my application, but 6 memory locations does not seem to program properly:

Programming failed at address 0x8000004. Value we would like to write 0x05. Value actually written 0x01

Programming failed at address 0x8000401. Value we would like to write 0xFC. Value actually written 0x48

Programming failed at address 0x8000403. Value we would like to write 0x20. Value actually written 0x00

Programming failed at address 0x8000404. Value we would like to write 0x5D. Value actually written 0x50

Programming failed at address 0x8000408. Value we would like to write 0x61. Value actually written 0x00

Programming failed at address 0x8000409. Value we would like to write 0x06. Value actually written 0x00

All my calls to HAL_FLASH_Program returns HAL_OK. Here are excerpts from my .dump file:

08000000 <__startUpVector>:

 8000000: 2001fc00 andcs pc, r1, r0, lsl #24

 8000004: 08000401 stmdaeq r0, {r0, sl}

void __attribute__ ((section(''.jumpToApplication''),used)) __jumpToApplication(void)

{

    JMP(0x08010004);

 8000400: 4b01       ldr r3, [pc, #4] ; (8000408 <__jumpToApplication+0x8>)

 8000402: 469f       mov pc, r3

 8000404: 4770       bx lr

 8000406: bf00       nop

 8000408: 08010004 stmdaeq r1, {r2}

I'd be most grateful for any help on this matter. Thanks in advance.
3 REPLIES 3
arnold_w
Senior
Posted on June 24, 2015 at 14:39

It seems the sector is not erased properly:

Programming failed at address 0x8000004. Value before programming 0x01. Value we would like to write 0x05. Value actually written 0x01

Programming failed at address 0x8000401. Value before programming 0x4B. Value we would like to write 0xFC. Value actually written 0x48

Programming failed at address 0x8000403. Value before programming 0x46. Value we would like to write 0x20. Value actually written 0x00

Programming failed at address 0x8000404. Value before programming 0x70. Value we would like to write 0x5D. Value actually written 0x50

Programming failed at address 0x8000408. Value before programming 0x04. Value we would like to write 0x61. Value actually written 0x00

Programming failed at address 0x8000409. Value before programming 0x00. Value we would like to write 0x06. Value actually written 0x00

What could cause the FLASH_Erase_Sector-function to fail to properly erase the sector?

Posted on June 24, 2015 at 15:04

What could cause the FLASH_Erase_Sector-function to fail to properly erase the sector?

Ignoring error and status conditions returned by the controller, and not clearing those conditions before starting? Controller needs to be unlock, Sector should not be write protected.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
arnold_w
Senior
Posted on June 24, 2015 at 15:17

Thanks, I forgot to call HAL_FLASH_Unlock() before erasing. The reason only 6 memory locations failed to program was that only those 6 memory location were programmed before I tried to rewrite the sector. So it all makes sense now.