To simplify and avoid alignment issues (which I think it is the alignment issue that is causing grief.)
typedef union {
double d;
uint32_t u[2];
} Xlate;
bool_t Flash_Write64Address(uint32_t address, double data) {
Xlate x;
x.d = data;
for (int i=0; i < 2; i++) {
int flashStatus = FLASH_ProgramWord(address, x.u[i]);
address += 4;
if(flashStatus != FLASH_COMPLETE) {
return FALSE;
}
return TRUE;
}
double Flash_Read64(uint32_t address) {
Xlate x;
x.u[0] = *((uint32_t *) address);
x.u[1] = *((uint32_t *) (address + 4));
return x.d;
}
[Edit]
I am supposing that address
represents an address with quad-byte alignment (its least 2 bits are 0). If address
did not have 8-byte alignment
(its least 3 bits are 0) and a double
access required it, then
return *((double *) address);
// or
return *tempPtr;
would cause a bus fault. If this is true, the above code should handle this issue.
Alternatively code could insure address
has 8-byte alignment
.