cancel
Showing results for 
Search instead for 
Did you mean: 

Writting to Flash memory on STM32F10xx

tyr0
Associate II
Posted on February 25, 2016 at 10:22

Hello everyone!

I'm trying to store a user data in flash memory by the nexf source code

#define FLASH_START_ADDR  ((uint32_t)0x08000000)

#define FLASH_END_ADDR      ((uint32_t)0x0803FFFF)

#define FLASH_PAGE_SIZE       ((uint16_t)0x800)    

#define USER_DATA_START      FLASH_END_ADDR-  FLASH_PAGE_SIZE

FLASH_EraseInitTypeDef EraseInit;

uint64_t Data= 1;

HAL_FLASH_Unlock();

    EraseInit.NbPages= FLASH_BANK_1;

    EraseInit.PageAddress= (uint32_t)USER_DATA_START;

    EraseInit.TypeErase= FLASH_TYPEERASE_PAGES;

    EraseInit.NbPages= 1;

    HAL_FLASH_Unlock();

    Rslt= HAL_FLASHEx_Erase(&EraseInit, &PageError);

 HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,USER_DATA_START, Data); // tracing from this line

    HAL_FLASH_Lock();

The program crushes

inside FLAH_Program_HalfWord function

at this line:

SET_BIT(FLASH->CR, FLASH_CR_PG); // OK

*(__IO uint16_t*)Address = Data;   // Crushes

2 REPLIES 2
Posted on February 25, 2016 at 11:55

The address you use can't be ODD. You should subtract whole pages from 0x08040000

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tyr0
Associate II
Posted on February 25, 2016 at 12:38

Thanks for your reply clive1

The address for writting was odd really.

Now it works