cancel
Showing results for 
Search instead for 
Did you mean: 

I just want to try to write something in any particular flash memory address, using stm32cube ide, I am using these two functions for read and write as I mention above when I compile my code its compile successfully but I see my address 0x0807F800 blank

Amour.1
Associate

nt32_t Flash_Write_Data (uint32_t StartPageAddress, uint32_t *Data, uint16_t numberofwords)

{

static FLASH_EraseInitTypeDef EraseInitStruct;

uint32_t PAGEError;

int sofar=0;

 /* Unlock the Flash to enable the flash control register access *************/

  HAL_FLASH_Unlock();

  /* Erase the user Flash area*/

 uint32_t StartPage = StartPageAddress;

 uint32_t EndPageAdress = StartPageAddress + numberofwords*4;

 uint32_t EndPage = EndPageAdress;

  /* Fill EraseInit structure*/

  EraseInitStruct.TypeErase  = FLASH_TYPEERASE_PAGES;

  EraseInitStruct.Page = StartPage;

  EraseInitStruct.NbPages   = ((EndPage - StartPage)/FLASH_PAGE_SIZE) +1;

  if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)

  {

   /*Error occurred while page erase.*/

 return HAL_FLASH_GetError ();

  }

  /* Program the user Flash area word by word*/

  while (sofar<numberofwords)

  {

   if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST, StartPageAddress, Data[sofar]) == HAL_OK)

   {

   StartPageAddress += 4; // use StartPageAddress += 2 for half word and 8 for double word

   sofar++;

   }

   else

   {

    /* Error occurred while writing data in Flash memory*/

   return HAL_FLASH_GetError ();

   }

  }

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

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

  HAL_FLASH_Lock();

  return 0;

}

void Flash_Read_Data (uint32_t StartPageAddress, uint32_t *RxBuf, uint16_t numberofwords)

{

while (1)

{

*RxBuf = *(__IO uint32_t *)StartPageAddress;

StartPageAddress += 4;

RxBuf++;

if (!(numberofwords--)) break;

}

}

uint32_t data[]={0X11111111,0X22222222};

int main(void)

{

Flash_Write_Data ( 0x0807F800 ,data, 2);

 Flash_Read_Data( 0x0807F800 , Rx_Data, 3);

}

3 REPLIES 3
TDK
Guru

Perhaps add more detail on what you're doing specifically including what software you're using, what happens when you try to upload code, and what you were expecting instead.

If you feel a post has answered your question, please click "Accept as Solution".
Amour.1
Associate

Please review my query , I edited my question as I mentioned above.

Thanx in advance.

TDK
Guru

> uint32_t StartPage = StartPageAddress;

> EraseInitStruct.Page = StartPage;

The page number and the page address are not the same value. For example, page 0 is at address 0x08000000.

If you feel a post has answered your question, please click "Accept as Solution".