Mercurial > public > ostc4
annotate OtherSources/firmwareEraseProgram.c @ 1067:a7ed4eb3142b Icon_Integration
Exit to Correct Menu when Exiting from 'Reset Menu' Submenus.
Write Progress and Success Messages when Flashing the Bootloader.
Only Show 'Flash Bootloader' if the Available Bootloader is Different from the Existing One.
(mikeller)
| author | heinrichsweikamp |
|---|---|
| date | Tue, 17 Feb 2026 09:49:37 +0100 |
| parents | 4b6afe5551e1 |
| children |
| rev | line source |
|---|---|
| 5 | 1 /** |
| 2 ****************************************************************************** | |
| 3 * @file firmwareEraseProgram.c | |
| 36 | 4 * @author heinrichs weikamp gmbh |
| 5 | 5 * @version V0.0.1 |
| 6 * @date 05-May-2015 | |
| 7 * @version V0.0.1 | |
| 8 * @since 05-May-2015 | |
| 9 * @brief erase and program the STM32F4xx internal FLASH memory | |
| 10 * | |
| 11 @verbatim | |
| 12 ============================================================================== | |
| 13 ##### How to use ##### | |
| 14 ============================================================================== | |
| 15 ADDR_FLASH_SECTOR_0 to/with ADDR_FLASH_SECTOR_5 (256KB) is used for this bootloader | |
| 16 | |
| 17 ADDR_FLASH_SECTOR_23 is blocked and used for Font T48 and image_heinrichs_weikamp | |
| 18 Font T24 for button text is not blocked / protected | |
| 19 other fonts should not be used here | |
| 20 | |
| 21 | |
| 22 ============================================================================== | |
| 23 ##### From AN2557 ##### | |
| 24 STM32F10xxx In-Application programming CD00161640.pdf 2010 | |
| 25 ============================================================================== | |
| 26 User program conditions | |
| 27 The user application to be loaded into the Flash memory using IAP should be built with | |
| 28 these configuration settings: | |
| 29 1. Set the program load address at 0x08003000, using your toolchain linker file | |
| 30 2. Relocate the vector table at address 0x08003000, using the | |
| 31 "NVIC_SetVectorTable"function or the VECT_TAB_OFFSET definition inside the | |
| 32 "system_stm32f10x.c" | |
| 33 | |
| 34 can be found here system_stm32f4xx.c | |
| 35 | |
| 36 | |
| 37 @endverbatim | |
| 38 ****************************************************************************** | |
| 39 * @attention | |
| 40 * | |
| 41 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
| 42 * | |
| 43 ****************************************************************************** | |
| 44 */ | |
| 45 | |
| 46 /* Includes ------------------------------------------------------------------*/ | |
| 47 #include "stm32f4xx_hal.h" | |
| 48 #include "stdio.h" | |
| 49 #include "firmwareEraseProgram.h" | |
| 50 #include "settings.h" // to access SHardwareData | |
| 51 | |
| 52 /* Exported variables --------------------------------------------------------*/ | |
| 53 | |
| 54 /* Private types -------------------------------------------------------------*/ | |
| 55 | |
| 56 /* Private variables ---------------------------------------------------------*/ | |
| 57 | |
| 58 static FLASH_EraseInitTypeDef EraseInitStruct; /*Variable used for Erase procedure*/ | |
| 59 | |
| 60 uint32_t FirstSector = 0, NbOfSectors = 0, Address = 0; | |
| 61 uint32_t SectorError = 0; | |
| 62 __IO uint32_t data32 = 0 , MemoryProgramStatus = 0; | |
| 63 | |
| 64 | |
| 65 | |
| 66 /* Private function prototypes -----------------------------------------------*/ | |
| 67 //static void firmware_Error_Handler(HAL_StatusTypeDef reason); | |
| 68 static uint32_t GetSector(uint32_t Address); | |
| 69 uint8_t hardware_programm_sub(uint8_t *buffer64, uint8_t length, uint32_t startAddress); | |
| 70 | |
| 71 /* Exported functions --------------------------------------------------------*/ | |
| 72 | |
| 73 const SHardwareData* hardwareDataGetPointer(void) | |
| 74 { | |
| 75 return (SHardwareData*)HARDWAREDATA_ADDRESS; | |
| 76 } | |
| 77 | |
| 78 uint8_t hardware_programmPrimaryBluetoothNameSet(void) | |
| 79 { | |
| 80 uint8_t data = 0xF0; | |
| 81 return hardware_programm_sub(&data, 1, HARDWAREDATA_ADDRESS + 7); | |
| 82 } | |
| 83 | |
| 84 | |
| 85 uint8_t hardware_programmSecondaryBluetoothNameSet(void) | |
| 86 { | |
| 87 uint8_t data = 0xF0; | |
| 88 return hardware_programm_sub(&data, 1, HARDWAREDATA_ADDRESS + 52 + 7); | |
| 89 } | |
| 90 | |
| 91 | |
| 92 uint8_t hardware_programmProductionData(uint8_t *buffer52) | |
| 93 { | |
| 94 buffer52[7] = 0xFF;// production_bluetooth_name_set | |
| 95 return hardware_programm_sub(buffer52, 52, HARDWAREDATA_ADDRESS);// check base_bootloader.c of OSTC4bootloader code and settings.h | |
| 96 } | |
| 97 | |
| 98 | |
| 99 uint8_t hardware_programmSecondarySerial(uint8_t *buffer12) | |
| 100 { | |
| 101 buffer12[7] = 0xFF;// secondary_bluetooth_name_set | |
| 102 return hardware_programm_sub(buffer12, 12, HARDWAREDATA_ADDRESS + 52); | |
| 103 } | |
| 104 | |
| 105 | |
| 106 uint8_t hardware_programm_sub(uint8_t *buffer, uint8_t length, uint32_t startAddress) | |
| 107 { | |
| 108 HAL_StatusTypeDef answer; | |
| 109 | |
| 110 uint32_t ptr = 0; | |
| 111 uint8_t data8; | |
| 112 | |
| 113 // test empty | |
| 114 Address = startAddress; | |
| 115 for(int i=0;i<length;i++) | |
| 116 { | |
| 117 if((*(uint8_t *)Address != 0xFF) && (buffer[i] != 0xFF)) | |
| 118 return 0xE0; | |
| 119 Address = Address + 1; | |
| 120 } | |
| 121 | |
| 122 // start programming | |
| 123 HAL_FLASH_Unlock(); | |
| 124 | |
| 125 Address = startAddress; | |
| 126 ptr = 0; | |
| 127 answer = HAL_OK; | |
| 128 while (ptr < length) | |
| 129 { | |
| 130 if(buffer[ptr] != 0xFF) | |
| 131 { | |
| 132 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, buffer[ptr]); | |
| 133 } | |
| 134 if (answer == HAL_OK) | |
| 135 { | |
| 136 Address = Address + 1; | |
| 137 ptr++; | |
| 138 } | |
| 139 else | |
| 140 { | |
| 141 HAL_FLASH_Lock(); | |
| 142 return answer; | |
| 143 } | |
| 144 } | |
| 145 HAL_FLASH_Lock(); | |
| 146 | |
| 147 /* Check if the programmed data is OK | |
| 148 MemoryProgramStatus = 0: data programmed correctly | |
| 149 MemoryProgramStatus != 0: number of words not programmed correctly ******/ | |
| 150 Address = startAddress; // check base_bootloader.c of OSTC4bootloader code | |
| 151 MemoryProgramStatus = 0x0; | |
| 152 | |
| 153 ptr = 0; | |
| 154 while(ptr < length) | |
| 155 { | |
| 156 data8 = *(__IO uint8_t*)Address; | |
| 157 | |
| 158 if((buffer[ptr] != 0xFF) && (data8 != buffer[ptr])) | |
| 159 { | |
| 160 MemoryProgramStatus++; | |
| 161 } | |
| 162 | |
| 163 Address = Address + 1; | |
| 164 ptr++; | |
| 165 } | |
| 166 | |
| 167 /* Check if there is an issue to program data */ | |
| 168 if (MemoryProgramStatus == 0) | |
| 169 { | |
| 170 return HAL_OK; | |
| 171 } | |
| 172 else | |
| 173 { | |
| 174 return 0xEE; | |
| 175 } | |
| 176 } | |
| 177 | |
| 178 | |
| 179 uint8_t firmware2_variable_upperpart_eraseFlashMemory(uint32_t length, uint32_t offset) | |
| 180 { | |
| 181 uint32_t startAddress, endAddress; | |
| 182 | |
| 183 // HAL_StatusTypeDef answer; | |
| 184 HAL_FLASH_Unlock(); | |
| 185 | |
| 186 startAddress = FLASH_FW2_START_ADDR + offset; | |
| 187 endAddress = startAddress + length; | |
| 188 | |
| 189 if(endAddress > FLASH_FW2_END_ADDR) | |
| 190 endAddress = FLASH_FW2_END_ADDR; | |
| 191 | |
| 192 FirstSector = GetSector(startAddress); | |
| 193 NbOfSectors = GetSector(endAddress) - FirstSector + 1; | |
| 194 | |
| 195 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; | |
| 196 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1; | |
| 197 EraseInitStruct.Sector = FirstSector; | |
| 198 EraseInitStruct.NbSectors = NbOfSectors; | |
| 199 | |
| 200 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError); | |
| 201 } | |
| 202 | |
| 203 | |
| 204 uint8_t firmware2_variable_upperpart_programFlashMemory(uint32_t length, uint32_t offset, uint8_t *pBuffer1, uint32_t pBuffer1Size, uint8_t *pBuffer2) | |
| 205 { | |
| 206 HAL_StatusTypeDef answer; | |
| 207 uint32_t ptr = 0; | |
| 208 uint32_t length1, length2; | |
| 209 | |
| 210 if((pBuffer2) && (length > pBuffer1Size)) | |
| 211 { | |
| 212 length1 = pBuffer1Size; | |
| 213 length2 = length - length1; | |
| 214 } | |
| 215 else | |
| 216 { | |
| 217 length1 = length; | |
| 218 length2 = 0; | |
| 219 } | |
| 220 | |
| 221 Address = FLASH_FW2_START_ADDR + offset; | |
| 222 | |
| 223 ptr = 0; | |
| 224 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length1)) | |
| 225 { | |
| 226 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[ptr]); | |
| 227 if (answer == HAL_OK) | |
| 228 { | |
| 229 Address = Address + 1; | |
| 230 ptr++; | |
| 231 } | |
| 232 else | |
| 233 { | |
| 234 return answer; | |
| 235 } | |
| 236 } | |
| 237 ptr = 0; | |
| 238 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length2)) | |
| 239 { | |
| 240 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer2[ptr]); | |
| 241 if (answer == HAL_OK) | |
| 242 { | |
| 243 Address = Address + 1; | |
| 244 ptr++; | |
| 245 } | |
| 246 else | |
| 247 { | |
| 248 return answer; | |
| 249 } | |
| 250 } | |
| 251 HAL_FLASH_Lock(); | |
| 252 | |
| 253 Address = FLASH_FW2_START_ADDR + offset;; | |
| 254 MemoryProgramStatus = 0x0; | |
| 255 | |
| 256 ptr = 0; | |
| 257 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length1)) | |
| 258 { | |
| 259 data32 = *(__IO uint8_t*)Address; | |
| 260 | |
| 261 if (data32 != pBuffer1[ptr]) | |
| 262 { | |
| 263 MemoryProgramStatus++; | |
| 264 } | |
| 265 | |
| 266 Address = Address + 1; | |
| 267 ptr++; | |
| 268 } | |
| 269 ptr = 0; | |
| 270 while ((Address <= FLASH_FW2_END_ADDR) && (ptr < length2)) | |
| 271 { | |
| 272 data32 = *(__IO uint8_t*)Address; | |
| 273 | |
| 274 if (data32 != pBuffer2[ptr]) | |
| 275 { | |
| 276 MemoryProgramStatus++; | |
| 277 } | |
| 278 | |
| 279 Address = Address + 1; | |
| 280 ptr++; | |
| 281 } | |
| 282 | |
| 283 if (MemoryProgramStatus == 0) | |
| 284 { | |
| 285 return HAL_OK; | |
| 286 } | |
| 287 else | |
| 288 { | |
| 289 return 0xEE; | |
| 290 } | |
| 291 } | |
| 292 | |
| 293 uint8_t firmware_eraseFlashMemory(void) | |
| 294 { | |
| 295 // HAL_StatusTypeDef answer; | |
| 296 /* Unlock the Flash to enable the flash control register access *************/ | |
| 297 HAL_FLASH_Unlock(); | |
| 298 | |
| 299 /* Erase the user Flash area | |
| 300 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/ | |
| 301 | |
| 302 /* Get the 1st sector to erase */ | |
| 303 FirstSector = GetSector(FLASH_FW_START_ADDR); | |
| 304 /* Get the number of sector to erase from 1st sector*/ | |
| 305 NbOfSectors = GetSector(FLASH_FW_END_ADDR) - FirstSector + 1; | |
| 306 | |
| 307 /* Fill EraseInit structure*/ | |
| 308 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; | |
| 309 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1; | |
| 310 EraseInitStruct.Sector = FirstSector; | |
| 311 EraseInitStruct.NbSectors = NbOfSectors; | |
| 312 | |
| 313 /* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache, | |
| 314 you have to make sure that these data are rewritten before they are accessed during code | |
| 315 execution. If this cannot be done safely, it is recommended to flush the caches by setting the | |
| 316 DCRST and ICRST bits in the FLASH_CR register. */ | |
| 317 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError); | |
| 318 } | |
| 319 | |
| 320 uint8_t firmware_programFlashMemory(uint8_t *pBuffer1, uint32_t length1)//, uint8_t *pBuffer2, uint32_t length2) | |
| 321 { | |
| 322 HAL_StatusTypeDef answer; | |
| 323 | |
| 324 /* Program the user Flash area word by word | |
| 325 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/ | |
| 326 | |
| 327 uint32_t ptr = 0; | |
| 328 | |
| 329 Address = FLASH_FW_START_ADDR; | |
| 330 | |
| 331 ptr = 0; | |
| 332 while ((Address <= FLASH_FW_END_ADDR) && (ptr < length1)) | |
| 333 { | |
| 334 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[ptr]); | |
| 335 if (answer == HAL_OK) | |
| 336 // if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, DATA_32) == HAL_OK) | |
| 337 { | |
| 338 Address = Address + 1;//4; | |
| 339 ptr++; | |
| 340 } | |
| 341 else | |
| 342 { | |
| 343 return answer; | |
| 344 } | |
| 345 } | |
| 346 /* same for pBuffer2 | |
| 347 ptr = 0; | |
| 348 while ((Address < FLASH_FW_END_ADDR) && (ptr < length2)) | |
| 349 { | |
| 350 | |
| 351 if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer2[ptr]) == HAL_OK) | |
| 352 { | |
| 353 Address = Address + 1; | |
| 354 ptr++; | |
| 355 } | |
| 356 else | |
| 357 { | |
| 358 firmware_Error_Handler(); | |
| 359 } | |
| 360 } | |
| 361 */ | |
| 362 /* Lock the Flash to disable the flash control register access (recommended | |
| 363 to protect the FLASH memory against possible unwanted operation) *********/ | |
| 364 HAL_FLASH_Lock(); | |
| 365 | |
| 366 /* Check if the programmed data is OK | |
| 367 MemoryProgramStatus = 0: data programmed correctly | |
| 368 MemoryProgramStatus != 0: number of words not programmed correctly ******/ | |
| 369 Address = FLASH_FW_START_ADDR; | |
| 370 MemoryProgramStatus = 0x0; | |
| 371 | |
| 372 ptr = 0; | |
| 373 while ((Address <= FLASH_FW_END_ADDR) && (ptr < length1)) | |
| 374 { | |
| 375 data32 = *(__IO uint8_t*)Address; | |
| 376 | |
| 377 if (data32 != pBuffer1[ptr]) | |
| 378 { | |
| 379 MemoryProgramStatus++; | |
| 380 } | |
| 381 | |
| 382 Address = Address + 1;//4; | |
| 383 ptr++; | |
| 384 } | |
| 385 /* same for pBuffer2 | |
| 386 ptr = 0; | |
| 387 while ((Address < FLASH_FW_END_ADDR) && (ptr < length2)) | |
| 388 { | |
| 389 data32 = *(__IO uint32_t*)Address; | |
| 390 | |
| 391 if (data32 != pBuffer2[ptr]) | |
| 392 { | |
| 393 MemoryProgramStatus++; | |
| 394 } | |
| 395 | |
| 396 Address = Address + 1;//4; | |
| 397 ptr++; | |
| 398 } | |
| 399 */ | |
| 400 /* Check if there is an issue to program data */ | |
| 401 if (MemoryProgramStatus == 0) | |
| 402 { | |
| 403 return HAL_OK; | |
| 404 /* No error detected. Switch on LED3 */ | |
| 405 } | |
| 406 else | |
| 407 { | |
| 408 return 0xEE; | |
| 409 } | |
| 410 | |
| 411 | |
| 412 } | |
| 413 | |
| 1017 | 414 |
| 415 uint8_t bootloader_eraseFlashMemory(void) | |
| 416 { | |
| 417 // HAL_StatusTypeDef answer; | |
| 418 /* Unlock the Flash to enable the flash control register access *************/ | |
| 419 HAL_FLASH_Unlock(); | |
| 420 | |
| 421 /* Erase the user Flash area | |
| 422 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/ | |
| 423 | |
| 424 /* Get the 1st sector to erase */ | |
| 425 FirstSector = GetSector(FLASH_BOOT_START_ADDR); | |
| 426 /* Get the number of sector to erase from 1st sector*/ | |
| 427 NbOfSectors = GetSector(FLASH_BOOT_END_ADDR) - FirstSector + 1; | |
| 428 | |
| 429 /* Fill EraseInit structure*/ | |
| 430 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; | |
| 431 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_1; | |
| 432 EraseInitStruct.Sector = FirstSector; | |
| 433 EraseInitStruct.NbSectors = NbOfSectors; | |
| 434 | |
| 435 /* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache, | |
| 436 you have to make sure that these data are rewritten before they are accessed during code | |
| 437 execution. If this cannot be done safely, it is recommended to flush the caches by setting the | |
| 438 DCRST and ICRST bits in the FLASH_CR register. */ | |
| 439 return HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError); | |
| 440 } | |
| 441 | |
| 442 uint8_t bootloader_programFlashMemory(uint8_t *pBuffer1, uint32_t length1, SHardwareData* pHwInfo) | |
| 443 { | |
| 444 HAL_StatusTypeDef answer; | |
| 445 | |
| 446 /* Program the user Flash area word by word | |
| 447 (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/ | |
| 448 | |
| 449 uint32_t index = 0; | |
| 450 Address = FLASH_BOOT_START_ADDR; | |
| 451 | |
| 452 uint8_t* pHardwareInfo = (uint8_t*) pHwInfo; | |
| 453 uint8_t tmp = 0; | |
| 454 | |
| 455 index = 0; | |
| 456 while ((Address <= FLASH_FW_END_ADDR) && (index < length1)) | |
| 457 { | |
| 458 if((Address >= HARDWAREDATA_ADDRESS) && (Address < HARDWAREDATA_ADDRESS + sizeof(SHardwareData))) | |
| 459 { | |
| 460 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, *pHardwareInfo++); | |
| 461 } | |
| 462 else | |
| 463 { | |
| 464 answer = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, pBuffer1[index]); | |
| 465 } | |
| 466 if (answer == HAL_OK) | |
| 467 { | |
| 468 Address = Address + 1; | |
| 469 index++; | |
| 470 } | |
| 471 else | |
| 472 { | |
| 473 return answer; | |
| 474 } | |
| 475 } | |
| 476 /* Lock the Flash to disable the flash control register access (recommended | |
| 477 to protect the FLASH memory against possible unwanted operation) *********/ | |
| 478 HAL_FLASH_Lock(); | |
| 479 | |
| 480 /* Check if the programmed data is OK | |
| 481 MemoryProgramStatus = 0: data programmed correctly | |
| 482 MemoryProgramStatus != 0: number of words not programmed correctly ******/ | |
| 483 Address = FLASH_BOOT_START_ADDR; | |
| 484 MemoryProgramStatus = 0x0; | |
| 485 | |
| 486 index = 0; | |
| 487 pHardwareInfo = (uint8_t*) pHwInfo; | |
| 488 | |
| 489 while ((Address <= FLASH_FW_END_ADDR) && (index < length1)) | |
| 490 { | |
| 491 if((Address >= HARDWAREDATA_ADDRESS) && (Address < HARDWAREDATA_ADDRESS + sizeof(SHardwareData))) | |
| 492 { | |
| 493 tmp = *pHardwareInfo++; | |
| 494 } | |
| 495 else | |
| 496 { | |
| 497 tmp = pBuffer1[index]; | |
| 498 } | |
| 499 | |
| 500 data32 = *(__IO uint8_t*)Address; | |
| 501 if (data32 != tmp) | |
| 502 { | |
| 503 MemoryProgramStatus++; | |
| 504 } | |
| 505 | |
| 506 Address = Address + 1; | |
| 507 index++; | |
| 508 } | |
| 509 /* Check if there is an issue to program data */ | |
| 510 if (MemoryProgramStatus == 0) | |
| 511 { | |
| 512 return HAL_OK; | |
| 513 /* No error detected. Switch on LED3 */ | |
| 514 } | |
| 515 else | |
| 516 { | |
| 517 return 0xEE; | |
| 518 } | |
| 519 } | |
| 520 | |
| 521 | |
| 522 uint32_t CalcFletcher32(uint32_t startAddr, uint32_t endAddr) | |
| 523 { | |
| 524 uint16_t sum1 = 0; | |
| 525 uint16_t sum2 = 0; | |
|
1051
4b6afe5551e1
Refactors CalcFletcher32 in OtherSources/firmwareEraseProgram.c to iterate over 16-bit words via a pointer instead of an index-based loop. Removes unused variables and returns the computed 32-bit Fletcher checksum directly. (mikeller)
heinrichsweikamp
parents:
1017
diff
changeset
|
526 for (uint16_t *index = (uint16_t *)startAddr; index <= (uint16_t *)endAddr; index++) { |
|
4b6afe5551e1
Refactors CalcFletcher32 in OtherSources/firmwareEraseProgram.c to iterate over 16-bit words via a pointer instead of an index-based loop. Removes unused variables and returns the computed 32-bit Fletcher checksum directly. (mikeller)
heinrichsweikamp
parents:
1017
diff
changeset
|
527 sum1 = sum1 + *index; |
|
4b6afe5551e1
Refactors CalcFletcher32 in OtherSources/firmwareEraseProgram.c to iterate over 16-bit words via a pointer instead of an index-based loop. Removes unused variables and returns the computed 32-bit Fletcher checksum directly. (mikeller)
heinrichsweikamp
parents:
1017
diff
changeset
|
528 sum2 = (sum2 + sum1); |
| 1017 | 529 } |
|
1051
4b6afe5551e1
Refactors CalcFletcher32 in OtherSources/firmwareEraseProgram.c to iterate over 16-bit words via a pointer instead of an index-based loop. Removes unused variables and returns the computed 32-bit Fletcher checksum directly. (mikeller)
heinrichsweikamp
parents:
1017
diff
changeset
|
530 return (sum2 << 16) | sum1; |
| 1017 | 531 } |
| 532 | |
| 533 | |
| 5 | 534 /* Private functions ---------------------------------------------------------*/ |
| 535 | |
| 536 /** | |
| 537 * @brief Gets the sector of a given address | |
| 538 * @param None | |
| 539 * @retval The sector of a given address | |
| 540 */ | |
| 541 static uint32_t GetSector(uint32_t Address) | |
| 542 { | |
| 543 uint32_t sector = 0; | |
| 544 | |
| 545 if((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0)) | |
| 546 { | |
| 547 sector = FLASH_SECTOR_0; | |
| 548 } | |
| 549 else if((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1)) | |
| 550 { | |
| 551 sector = FLASH_SECTOR_1; | |
| 552 } | |
| 553 else if((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2)) | |
| 554 { | |
| 555 sector = FLASH_SECTOR_2; | |
| 556 } | |
| 557 else if((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3)) | |
| 558 { | |
| 559 sector = FLASH_SECTOR_3; | |
| 560 } | |
| 561 else if((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4)) | |
| 562 { | |
| 563 sector = FLASH_SECTOR_4; | |
| 564 } | |
| 565 else if((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5)) | |
| 566 { | |
| 567 sector = FLASH_SECTOR_5; | |
| 568 } | |
| 569 else if((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6)) | |
| 570 { | |
| 571 sector = FLASH_SECTOR_6; | |
| 572 } | |
| 573 else if((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7)) | |
| 574 { | |
| 575 sector = FLASH_SECTOR_7; | |
| 576 } | |
| 577 else if((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8)) | |
| 578 { | |
| 579 sector = FLASH_SECTOR_8; | |
| 580 } | |
| 581 else if((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9)) | |
| 582 { | |
| 583 sector = FLASH_SECTOR_9; | |
| 584 } | |
| 585 else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10)) | |
| 586 { | |
| 587 sector = FLASH_SECTOR_10; | |
| 588 } | |
| 589 else if((Address < ADDR_FLASH_SECTOR_12) && (Address >= ADDR_FLASH_SECTOR_11)) | |
| 590 { | |
| 591 sector = FLASH_SECTOR_11; | |
| 592 } | |
| 593 else if((Address < ADDR_FLASH_SECTOR_13) && (Address >= ADDR_FLASH_SECTOR_12)) | |
| 594 { | |
| 595 sector = FLASH_SECTOR_12; | |
| 596 } | |
| 597 else if((Address < ADDR_FLASH_SECTOR_14) && (Address >= ADDR_FLASH_SECTOR_13)) | |
| 598 { | |
| 599 sector = FLASH_SECTOR_13; | |
| 600 } | |
| 601 else if((Address < ADDR_FLASH_SECTOR_15) && (Address >= ADDR_FLASH_SECTOR_14)) | |
| 602 { | |
| 603 sector = FLASH_SECTOR_14; | |
| 604 } | |
| 605 else if((Address < ADDR_FLASH_SECTOR_16) && (Address >= ADDR_FLASH_SECTOR_15)) | |
| 606 { | |
| 607 sector = FLASH_SECTOR_15; | |
| 608 } | |
| 609 else if((Address < ADDR_FLASH_SECTOR_17) && (Address >= ADDR_FLASH_SECTOR_16)) | |
| 610 { | |
| 611 sector = FLASH_SECTOR_16; | |
| 612 } | |
| 613 else if((Address < ADDR_FLASH_SECTOR_18) && (Address >= ADDR_FLASH_SECTOR_17)) | |
| 614 { | |
| 615 sector = FLASH_SECTOR_17; | |
| 616 } | |
| 617 else if((Address < ADDR_FLASH_SECTOR_19) && (Address >= ADDR_FLASH_SECTOR_18)) | |
| 618 { | |
| 619 sector = FLASH_SECTOR_18; | |
| 620 } | |
| 621 else if((Address < ADDR_FLASH_SECTOR_20) && (Address >= ADDR_FLASH_SECTOR_19)) | |
| 622 { | |
| 623 sector = FLASH_SECTOR_19; | |
| 624 } | |
| 625 else if((Address < ADDR_FLASH_SECTOR_21) && (Address >= ADDR_FLASH_SECTOR_20)) | |
| 626 { | |
| 627 sector = FLASH_SECTOR_20; | |
| 628 } | |
| 629 else if((Address < ADDR_FLASH_SECTOR_22) && (Address >= ADDR_FLASH_SECTOR_21)) | |
| 630 { | |
| 631 sector = FLASH_SECTOR_21; | |
| 632 } | |
| 633 else if((Address < ADDR_FLASH_SECTOR_23) && (Address >= ADDR_FLASH_SECTOR_22)) | |
| 634 { | |
| 635 sector = FLASH_SECTOR_22; | |
| 636 } | |
| 637 else/*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_23))*/ | |
| 638 { | |
| 639 sector = FLASH_SECTOR_23; | |
| 640 } | |
| 641 | |
| 642 return sector; | |
| 643 } | |
| 644 | |
| 645 /* | |
| 646 static void firmware_Error_Handler(HAL_StatusTypeDef reason) | |
| 647 { | |
| 648 static HAL_StatusTypeDef last_reason = HAL_OK; | |
| 649 | |
| 650 last_reason = reason; | |
| 651 while(1) | |
| 652 { | |
| 653 } | |
| 654 } | |
| 655 */ |
