基质喷涂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.5 KiB

  1. //
  2. // #include "zflash.h"
  3. //
  4. // #include <stdbool.h>
  5. // #include <stdlib.h>
  6. // #include <string.h>
  7. //
  8. // #include "zbase.h"
  9. // #include "zlog.h"
  10. //
  11. // static uint32_t* _rawstartadd;
  12. // static uint32_t* _defaultdata;
  13. // static uint32_t _rawsize;
  14. // static bool _is_first_run = false;
  15. //
  16. // static uint32_t* _flashadd;
  17. // static uint32_t _flashSector;
  18. //
  19. // static bool _xs_check_raw_data() {
  20. // uint32_t checksum = 0;
  21. // if (_rawstartadd[0] != FLASH_MASK_VAL) {
  22. // return false;
  23. // }
  24. // for (uint32_t i = 0; i < _rawsize - 1; i++) {
  25. // checksum += _rawstartadd[i];
  26. // }
  27. // if (checksum != _rawstartadd[_rawsize - 1]) {
  28. // return false;
  29. // }
  30. // return true;
  31. // }
  32. //
  33. // static HAL_StatusTypeDef _flash_erase(void) {
  34. // HAL_StatusTypeDef status;
  35. // uint32_t sector_error_point;
  36. // FLASH_EraseInitTypeDef flash_erase_structer = {
  37. // //
  38. // .TypeErase = FLASH_TYPEERASE_SECTORS, //
  39. // .Sector = _flashSector, //
  40. // .NbSectors = 1, //
  41. // .VoltageRange = FLASH_VOLTAGE_RANGE_3 //
  42. // };
  43. //
  44. // HAL_FLASH_Unlock(); // 解锁
  45. // __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR); // 清除一些错误标志
  46. // status = HAL_FLASHEx_Erase(&flash_erase_structer, &sector_error_point);
  47. // if (status != HAL_OK) {
  48. // ZLOGE("flash", "erase error");
  49. // }
  50. // HAL_FLASH_Lock(); //
  51. // return status;
  52. // }
  53. // /*******************************************************************************
  54. // * EXTERN *
  55. // *******************************************************************************/
  56. //
  57. // void zflash_init(uint32_t* flashadd, uint32_t flashSector, uint32_t* rawstartadd, uint32_t rawsize) {
  58. // _flashadd = flashadd;
  59. // _flashSector = flashSector;
  60. //
  61. // _rawstartadd = rawstartadd;
  62. // _defaultdata = NULL;
  63. // _rawsize = rawsize;
  64. //
  65. // // 读取flash数据
  66. // memcpy(_rawstartadd, (uint32_t*)(_flashadd), _rawsize * 4);
  67. //
  68. // #if 0
  69. // // 校验数据
  70. // if (_xs_check_raw_data()) {
  71. // return;
  72. // }
  73. // _is_first_run = true;
  74. // zflash_factory_reset();
  75. // #endif
  76. // }
  77. //
  78. // bool zflash_check(void) { return _xs_check_raw_data(); }
  79. //
  80. // bool zflash_set_default_data(uint32_t* defaultdata) {
  81. // _defaultdata = defaultdata;
  82. // return true;
  83. // }
  84. //
  85. // bool zflash_is_first_run(void) { return _is_first_run; }
  86. //
  87. // uint32_t zcompute_checksum(uint32_t* data, uint32_t size) {
  88. // uint32_t checksum = 0;
  89. // for (uint32_t i = 0; i < size; i++) {
  90. // checksum += data[i];
  91. // }
  92. // return checksum;
  93. // }
  94. // bool zflash_factory_reset(void) {
  95. // ZLOGI("flash", "factory reset");
  96. // memcpy(_rawstartadd, _defaultdata, _rawsize * 4);
  97. // zflash_flush();
  98. // return true;
  99. // }
  100. //
  101. // bool zflash_flush(void) {
  102. // _rawstartadd[0] = FLASH_MASK_VAL;
  103. // _rawstartadd[_rawsize - 1] = zcompute_checksum(_rawstartadd, _rawsize - 1);
  104. //
  105. // _flash_erase();
  106. // HAL_FLASH_Unlock(); //
  107. // HAL_StatusTypeDef status;
  108. // for (uint32_t i = 0; i < _rawsize; i++) {
  109. // status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, _flashadd + i * 4, _rawstartadd[i]);
  110. // if (status != HAL_OK) {
  111. // ZLOGE("flash", "write error");
  112. // }
  113. // }
  114. // HAL_FLASH_Lock(); //
  115. // return true;
  116. // }