cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G030 Flash Read/Write issues.

PGand
Associate

>>Hi I am trying to write and read data from FLASH in STM32G030 32KB Flash device.

>>However , I am experiencing unusual behavior . Sometimes I am able to read data correctly and sometimes junk data is read.

Following is my code :

#define FLASH_USER_START_ADDR  0x08007800UL

#define FLASH_USER_END_ADDR   0x08007FFFUL

uint32_t FirstPage = 0, NbOfPages = 0;

uint32_t Address = 0, PageError = 0;

static FLASH_EraseInitTypeDef EraseInitStruct = {0};

uint32_t count_f_life_data=0;

uint32_t count_one_yr_data=0;

uint32_t eep_pre_tim1_arr_prd  =136;

uint32_t eep_reg_tim1_arr_prd  =280;

void Write_Data_Flash2()

{

uint32_t Page_error_status;

HAL_FLASH_Unlock();

/* Clear OPTVERR bit set on virgin samples */

 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);

FirstPage = GetPage(FLASH_USER_START_ADDR);

NbOfPages = GetPage(FLASH_USER_END_ADDR) - FirstPage + 1;

EraseInitStruct.TypeErase  = FLASH_TYPEERASE_PAGES;

  EraseInitStruct.Page    = FirstPage;

  EraseInitStruct.NbPages   = NbOfPages;

  HAL_FLASHEx_Erase(&EraseInitStruct, &Page_error_status);

  HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x08007800UL, eep_pre_tim1_arr_prd);

  HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x08007808UL, eep_reg_tim1_arr_prd);

  HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x08007810UL, count_f_life_data);

  HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x08007818UL, count_one_yr_data);

  /* Lock the Flash to disable the flash control register access (recommended

      to protect the FLASH memory against possible unwanted operation) *********/

HAL_FLASH_Lock();

}

void Read_Data_Flash2()

{

//HAL_FLASH_Unlock();

eep_pre_tim1_arr_prd = *(__IO uint32_t *)0x08007800UL;

eep_reg_tim1_arr_prd = *(__IO uint32_t *)0x08007808UL;

count_f_life_data  = *(__IO uint32_t *)0x08007810UL;

count_one_yr_data  = *(__IO uint32_t *)0x08007818UL;

/* Lock the Flash to disable the flash control register access (recommended

   to protect the FLASH memory against possible unwanted operation) *********/

//HAL_FLASH_Lock();

}

Kindly help.

2 REPLIES 2

What exactly is "junk data" and how do they differ from good ones? Once junk, are all data junk or only some of them? Do you read/check them immediately after writing? Check after erase if the given address is blank.

Is this a "known good" hardware such as Nucleo or Disco?

JW

PGand
Associate

1 . Sorry , data isn't junk .... while reading data , I see only 0xFFFFFFFF

2.I am writing to 4 locations , 3 locations return correct data , while one location return 0xFFFFFFF , it's random and not fixed for a location.

3.Yes I'm trying to read immediately after writing ....I took code help from STM32G0 example .

4.I have observed than whenever I have a read/write operation , my debugger stops responding properly.

5.We have customized board having STM32G030 IC.