cancel
Showing results for 
Search instead for 
Did you mean: 

flash memory

mauro2
Associate II
Posted on January 29, 2016 at 12:50

I'm trying to flash memory using stm32f10x_flash library. here the code:

/*in the arm-gcc-link.ld file i added this lines to allocate rom memory for my data*/

.dataconf 0x0807F000:

    {

        KEEP(*(.ROMDATA))

        *(.dataconf*)

        

    } > rom

/*I declared this in the main.c to allocate rom memory */

const uint16_t Pat __attribute__((section (''.ROMDATA'')));

/* finally the function to flash memory (always in main.c) */

void FlashMemory(void)

{

uint16_t IDPat = 1; 

FLASH_Status FlashStat;

FLASH_Unlock();

FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);

FlashStat = FLASH_ProgramHalfWord(0x0807F000, IDPat);

FLASH_Lock();

}

FlashStat is FLASH_ERROR_PG.

can you tell me what it means and where is the error?

3 REPLIES 3
gmate1
Associate II
Posted on January 29, 2016 at 12:59

You missed erasing the page before programming. FLASH_ErasePage(flashaddress)

Also, a hardfault will occur, if you do un-alligned flash write.

gmate1
Associate II
Posted on January 29, 2016 at 13:04

Also, I don't know much about linker scripts, but you might be trying to write into a memory which you are here setting as Read-only (ROMDATA ?)

mauro2
Associate II
Posted on January 29, 2016 at 14:13

problem solved, thanks 😉