Skip to main content
tyr0
Associate II
February 25, 2016
Question

Writting to Flash memory on STM32F10xx

  • February 25, 2016
  • 2 replies
  • 646 views
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

    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    February 25, 2016
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    tyr0
    tyr0Author
    Associate II
    February 25, 2016
    Posted on February 25, 2016 at 12:38

    Thanks for your reply clive1

    The address for writting was odd really.

    Now it works