21
21
#include "ch.h"
22
22
#include "hal.h"
23
23
#include "stm32f4xx_conf.h"
24
- #include "stm32f4xx_crc.h"
25
24
#include "utils.h"
26
25
#include "mc_interface.h"
27
26
#include "timeout.h"
28
27
#include "hw.h"
28
+ #include "crc.h"
29
29
#include <string.h>
30
30
31
31
/*
56
56
#define APP_CRC_WAS_CALCULATED_FLAG ((uint32_t)0xAAAAAAAA)
57
57
#define APP_CRC_WAS_CALCULATED_FLAG_ADDRESS (uint32_t*)(APP_MAX_SIZE - 8)
58
58
59
+ #define VECTOR_TABLE_ADDRESS (uint32_t *)ADDR_FLASH_SECTOR_0
60
+ #define VECTOR_TABLE_SIZE (ADDR_FLASH_SECTOR_1 - ADDR_FLASH_SECTOR_0)
61
+
62
+ #define APP_START_ADDRESS (uint32_t *)(ADDR_FLASH_SECTOR_1 + EEPROM_EMULATION_SIZE)
63
+ #define APP_SIZE (APP_MAX_SIZE - VECTOR_TABLE_SIZE - EEPROM_EMULATION_SIZE)
64
+
59
65
// Private constants
60
66
static const uint32_t flash_addr [FLASH_SECTORS ] = {
61
67
ADDR_FLASH_SECTOR_0 ,
@@ -214,15 +220,19 @@ uint32_t flash_helper_verify_flash_memory(void) {
214
220
if ( (APP_CRC_WAS_CALCULATED_FLAG_ADDRESS )[0 ] == APP_CRC_WAS_CALCULATED_FLAG )
215
221
{
216
222
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_CRC , ENABLE );
217
- CRC_ResetDR ();
223
+ crc32_reset ();
224
+
225
+ // compute vector table (sector 0)
226
+ crc32 ((VECTOR_TABLE_ADDRESS ), (VECTOR_TABLE_SIZE )/4 );
227
+
228
+ // skip emulated EEPROM (sector 1 and 2)
218
229
219
- // A CRC over the full image should return zero. Exclude the pages used for
220
- // storing user configuration data.
221
- crc = CRC_CalcBlockCRC ((uint32_t * )( ADDR_FLASH_SECTOR_0 + EEPROM_EMULATION_SIZE ),
222
- (APP_MAX_SIZE - EEPROM_EMULATION_SIZE )/4 );
230
+ // compute application code
231
+ crc = crc32 (APP_START_ADDRESS , (APP_SIZE )/4 );
223
232
224
233
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_CRC , DISABLE );
225
234
235
+ // A CRC over the full image should return zero.
226
236
return (crc == 0 )? FAULT_CODE_NONE : FAULT_CODE_FLASH_CORRUPTION ;
227
237
}
228
238
else {
@@ -239,9 +249,16 @@ uint32_t flash_helper_verify_flash_memory(void) {
239
249
240
250
// Compute flash crc including the new flag
241
251
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_CRC , ENABLE );
242
- CRC_ResetDR ();
243
- crc = CRC_CalcBlockCRC ((uint32_t * )(ADDR_FLASH_SECTOR_0 + EEPROM_EMULATION_SIZE ),
244
- (APP_MAX_SIZE - EEPROM_EMULATION_SIZE - 4 )/4 );
252
+ crc32_reset ();
253
+
254
+ // compute vector table (sector 0)
255
+ crc32 (VECTOR_TABLE_ADDRESS , (VECTOR_TABLE_SIZE )/4 );
256
+
257
+ // skip emulated EEPROM (sector 1 and 2)
258
+
259
+ // compute application code
260
+ crc = crc32 (APP_START_ADDRESS , (APP_SIZE - 4 )/4 );
261
+
245
262
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_CRC , DISABLE );
246
263
247
264
//Store CRC
0 commit comments