AnsweredAssumed Answered

Writting to Flash memory on STM32F10xx

Question asked by a.alya on Feb 25, 2016
Latest reply on Feb 25, 2016 by a.alya
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

Outcomes