2021-10-31 01:13 AM
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);
}
2021-10-31 07:29 AM
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.
2021-11-01 04:57 AM
Please review my query , I edited my question as I mentioned above.
Thanx in advance.
2021-11-01 06:51 AM
> 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.