2023-08-06 09:08 AM
Hello Team,
I have imported the Flash_EraseProgram from the github about nucleo-L412RB:
I have modified the code, in order to store 6 double values at flash memory and also Ι have created a simple function that read the values from the memory.
When the values are uint64_t without fractional part I can write the memory successfully(MemoryPrograamStatus ==0) and I can read them correctly.
When I try to store double words with fractional part, MemoryProgramSatus isn't 0, which means that the memory is not be writed correctly, and also I cannnot read back the values correctly.
I attach the code and what I can see at the memory and the buffers.
Thanks in advance.
Solved! Go to Solution.
2023-08-06 10:24 AM
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, (uint64_t)send_data[i]) == HAL_OK)
{
Address = Address + 8;
}
This code converts the double value to a uint64_t and writes that. Instead, you want to interpret the memory as a uint64_t:
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, *((uint64_t*)&send_data[i])) == HAL_OK)
{
Address = Address + 8;
}
Same thing on the receiving end, but it looks like your receiving code is fine.
2023-08-06 10:18 AM
The Arduino libraries have Put() and Get() functions that might serve as a reference:
float f = 123.456f; //Variable to store in EEPROM.
EEPROM.put(eeAddress, f);
https://wiki-content.arduino.cc/en/Tutorial/LibraryExamples/EEPROMPut
https://wiki-content.arduino.cc/en/Tutorial/LibraryExamples/EEPROMGet
https://github.com/PaulStoffregen/EEPROM/blob/master/EEPROM.h
2023-08-06 10:24 AM
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, (uint64_t)send_data[i]) == HAL_OK)
{
Address = Address + 8;
}
This code converts the double value to a uint64_t and writes that. Instead, you want to interpret the memory as a uint64_t:
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, *((uint64_t*)&send_data[i])) == HAL_OK)
{
Address = Address + 8;
}
Same thing on the receiving end, but it looks like your receiving code is fine.
2023-08-07 08:04 AM
*DATA_64 = *(__IO double*)StartPageAddress;
NO, you need to cast the data to a uint64_t, it doesn't know how to cram doubles into a different destination type. You want to copy the data into FLASH as a byte-for-byte copy (8 bytes at a time), so *(volatile uint64_t *) gets the data as the 8-bytes, as represented in memory.
double *a = (double *)0x08010000; // how you point to an array of doubles situated in FLASH at address 0x08010000;