diff Small_CPU/Src/RTE_FlashAccess.c @ 571:91a8f9893e68

Reactivate compass parameter stored in NVM: The calibration parameters are stored in NVM but the automatic restore function during startup was no longer active. As result the compass needed to be calibration after every RTE update. In addition compass HW was detected at every startup causing some i2c "trouble" because of adressing not available devices. The compass HW info is now stored together with the calibration parameters to avoid i2C problems.
author Ideenmodellierer
date Wed, 25 Nov 2020 20:16:20 +0100
parents 5f11787b4f42
children
line wrap: on
line diff
--- a/Small_CPU/Src/RTE_FlashAccess.c	Mon Nov 30 20:55:23 2020 +0100
+++ b/Small_CPU/Src/RTE_FlashAccess.c	Wed Nov 25 20:16:20 2020 +0100
@@ -75,7 +75,7 @@
 
 /* Exported functions --------------------------------------------------------*/
 
-uint8_t BFA_readLastDataBlock(uint32_t *dataArray4)
+uint8_t BFA_readLastDataBlock(tfull32 *dataArray4)
 {
 	uint8_t answer;
 	
@@ -83,15 +83,15 @@
 	if(answer != BFA_OK)
 		return answer;
 
-	dataArray4[0] = *(__IO uint32_t*)(Address +  0);
-	dataArray4[1] = *(__IO uint32_t*)(Address +  4);
-	dataArray4[2] = *(__IO uint32_t*)(Address +  8);
-	dataArray4[3] = *(__IO uint32_t*)(Address + 12);
+	dataArray4[0].Full32 = *(__IO uint32_t*)(Address +  0);
+	dataArray4[1].Full32 = *(__IO uint32_t*)(Address +  4);
+	dataArray4[2].Full32 = *(__IO uint32_t*)(Address +  8);
+	dataArray4[3].Full32 = *(__IO uint32_t*)(Address + 12);
 	return BFA_OK;
 }
 
 
-uint8_t BFA_writeDataBlock(const uint32_t *dataArray4)
+uint8_t BFA_writeDataBlock(const tfull32 *dataArray4)
 {
 	uint8_t answer;
 	uint32_t dataTest[4];
@@ -128,14 +128,25 @@
 	HAL_FLASH_Unlock();
 	for(int i=0;i<4;i++)
 	{
-		answer = HAL_FLASH_Program(TYPEPROGRAM_WORD, Address, dataArray4[i]);
+		answer = HAL_FLASH_Program(TYPEPROGRAM_WORD, Address, dataArray4[i].Full32);
 		Address = Address + 4;
 	}
 	HAL_FLASH_Lock();
 	Address = StartAddress; // back to start of this data set (for reading etc.)
 	return answer;
 }
+uint16_t BFA_calc_Block_Checksum(const tfull32 *dataArray4)
+{
+	uint16_t checksum = 0;
+	uint8_t loop = 0;
+	uint16_t* p_data = (uint16_t*)dataArray4;
 
+	for (loop = 0; loop < 6; loop++) // calc checksum across first 6 words */
+	{
+		checksum += *p_data;
+	}
+	return checksum;
+}
 
 /* Private functions ---------------------------------------------------------*/
 /*