cancel
Showing results for 
Search instead for 
Did you mean: 

Flash memory write -> HardFault_Handler

fidel17
Associate II
Posted on April 12, 2014 at 17:43

Hi everyone,

I have problem with writing to flash memory in my application. uC STM32F051C4

Code:

#define FLASH1 (*((uint32_t *)0x08001016))

then flash function:

void FLASHunlock(void)

{

if (FLASH->CR &0x00000080)

{

FLASH->KEYR = 0x45670123;

FLASH->KEYR = 0xCDEF89AB;

}

}

void FLASHwrite(void)

{

uint16_t z=0xF0F0;

FLASHunlock();

while(FLASH->SR & 0x00000001);

FLASH->CR = 0x00000001;

FLASH1 = z;              -> here program jumps to HardFault_Handler

while (FLASH->SR & 0x00000001);

}

Any ideas? Flash is eriassed (everywhere FF FF)
6 REPLIES 6
Posted on April 13, 2014 at 02:23

Use a WORD aligned address

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
fidel17
Associate II
Posted on April 13, 2014 at 10:45

How? 🙂

Posted on April 13, 2014 at 11:19

How? 🙂

Use an address which is divisible by FOUR

#define FLASH1 (*((uint32_t *)0x08001018))

I have other issues with your code, but that's why it's faulting.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
fidel17
Associate II
Posted on April 13, 2014 at 11:58

I still get HardFault_Handler with 0x08001018, 

I was checking elier with 08004000, 08002000 - same story. 

Please share other issues 🙂

Experiment:

When i change adress to 0x48000014 witch is GPIOA ODR, everything works.

Data is stored on LSB bits of GPIOA, register value is 0x0000F0F0 

fidel17
Associate II
Posted on April 13, 2014 at 15:22

Ok i got it working with ST library.

I am still very curious what have i done wrong. 
Posted on April 13, 2014 at 20:09

The ST library code sets/clears the PG bit without disturbing the other bits, looks at the SR slightly differently, and has some additional latency based on the subroutine calls.

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