Flash memory write -> HardFault_Handler
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-12 08: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)- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-12 05:23 PM
Use a WORD aligned address
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-13 01:45 AM
How? :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-13 02: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.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-13 02: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 0x0000F0F0- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-13 06:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
Up vote any posts that you find helpful, it shows what's working..