write and read functions:
uint8_t Write_Flash_Float(uint32_t address , uWriteFlashFloat* values){
if(values ≠ NULL){
HAL_FLASH_Unlock();
FLASH_Erase_Sector(FLASH_SECTOR_11, VOLTAGE_RANGE_3);
// for(int i = 0, j = 0; i < STEK_NUMBER_OF_POINTS && j < (STEK_NUMBER_OF_POINTS*4) ; ++i , j = j+4){
// HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, (address +j), values[i].FlashValuesuint32);
// }
for(int i = 0, j = 0; i < 6 && j < 24 ; ++i , j = j+4){
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, (address +j), values[i].FlashValuesuint32);
}
HAL_FLASH_Lock();
return 1;
}
else return 0;
}
float Read_Flash_Float(uint32_t address){
uWriteFlashFloat readData;
readData.FlashValuesuint32 = *(uint32_t*)address;
return readData.FlashValuesFloat;
}
int Read_Flash_Int(uint32_t address){
uWriteFlashFloat readData;
readData.FlashValuesuint32 = *(uint32_t*)address;
return readData.FlashValuesuint32;
}
union dec.
typedef union{
float FlashValuesFloat;
uint32_t FlashValuesuint32;
}uWriteFlashFloat;
NOTE: My problem was solved when I filled the first 4 bytes of the sector with any value and read the rest. But I would be happy to learn why there is such a problem in the first 4 bytes.