2014-04-12 8:43 AM
Hi everyone,
I have problem with writing to flash memory in my application. uC STM32F051C4Code:#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)2014-04-12 5:23 PM
Use a WORD aligned address
2014-04-13 1:45 AM
How? :)
2014-04-13 2:19 AM
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.2014-04-13 2:58 AM
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 0x0000F0F02014-04-13 6:22 AM
2014-04-13 11:09 AM
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.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.