flash write in stm32H743iit6
hi there,
I have a stm32H743iit6 and I wish to write a uint32_t array in it flash. I use sector 6 to 7 of Bank1 to write my array to. first I fill my array with number of 0 to 69 like so
for (int i = 0; i < 70; i++)//10
{
flash_buffer_W[i]=i;
}
and then I use the code below to write it in my flash area.
/* Get the 1st sector to erase */
FirstSector = GetSector(FLASH_START_ADDR);
/* Get the number of sector to erase from 1st sector*/
NbOfSectors = GetSector(FLASH_END_ADDR) - FirstSector + 1;
__disable_irq();
vTaskSuspendAll();
HAL_FLASH_Unlock();
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
EraseInitStruct.Banks = FLASH_BANK_1;
EraseInitStruct.Sector = FirstSector;
EraseInitStruct.NbSectors = NbOfSectors;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) != HAL_OK)
{
return -1;
}
/*Program the user Flash area word by word
(area defined by FLASH_START_ADDR and FLASH_END_ADDR) ***********/
Addressf = FLASH_START_ADDR;
//while (Addressf < FLASH_END_ADDR)
// for(uint32_t i=0;i<size;i++)
//{
HAL_IWDG_Refresh(&hiwdg1); //Reload Watchdog inorder to prevent Micro Reset
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, Addressf, flash_buffer_W) == HAL_OK)
{
Addressf = Addressf + 32; /*32bits increment for the next Flash word*/
}
else
{
HAL_FLASH_Lock();
return -1;
}
// }
HAL_FLASH_Lock();
xTaskResumeAll();
__enable_irq();
my problem is
1. it just write first 8 elements of flash_buffer_W[] in the address and then rewrite it to the whole area address instead of writing rest of elements.
2.if I use flash_buffer_W[i] a hardfault happens and it doesnt work whereas in
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t FlashAddress, uint32_t DataAddress)I can see that I can use a uint32_t variable.
why is that?
