My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

persistent_store_impl.cpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  6. * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
  7. * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
  24. #include "../../inc/MarlinConfig.h"
  25. #if ENABLED(EEPROM_SETTINGS) && ANY(FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
  26. #include "../shared/persistent_store_api.h"
  27. #if ENABLED(FLASH_EEPROM_EMULATION)
  28. #include <EEPROM.h>
  29. static bool eeprom_data_written = false;
  30. #endif
  31. bool PersistentStore::access_start() {
  32. #if ENABLED(FLASH_EEPROM_EMULATION)
  33. eeprom_buffer_fill();
  34. #endif
  35. return true;
  36. }
  37. bool PersistentStore::access_finish() {
  38. #if ENABLED(FLASH_EEPROM_EMULATION)
  39. if (eeprom_data_written) {
  40. eeprom_buffer_flush();
  41. eeprom_data_written = false;
  42. }
  43. #endif
  44. return true;
  45. }
  46. bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
  47. while (size--) {
  48. uint8_t v = *value;
  49. // Save to either external EEPROM, program flash or Backup SRAM
  50. #if EITHER(SPI_EEPROM, I2C_EEPROM)
  51. // EEPROM has only ~100,000 write cycles,
  52. // so only write bytes that have changed!
  53. uint8_t * const p = (uint8_t * const)pos;
  54. if (v != eeprom_read_byte(p)) {
  55. eeprom_write_byte(p, v);
  56. if (eeprom_read_byte(p) != v) {
  57. SERIAL_ECHO_MSG(MSG_ERR_EEPROM_WRITE);
  58. return true;
  59. }
  60. }
  61. #elif ENABLED(FLASH_EEPROM_EMULATION)
  62. eeprom_buffered_write_byte(pos, v);
  63. #else
  64. *(__IO uint8_t *)(BKPSRAM_BASE + (uint8_t * const)pos) = v;
  65. #endif
  66. crc16(crc, &v, 1);
  67. pos++;
  68. value++;
  69. };
  70. #if ENABLED(FLASH_EEPROM_EMULATION)
  71. eeprom_data_written = true;
  72. #endif
  73. return false;
  74. }
  75. bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
  76. do {
  77. // Read from either external EEPROM, program flash or Backup SRAM
  78. const uint8_t c = (
  79. #if EITHER(SPI_EEPROM, I2C_EEPROM)
  80. eeprom_read_byte((uint8_t*)pos)
  81. #elif ENABLED(FLASH_EEPROM_EMULATION)
  82. eeprom_buffered_read_byte(pos)
  83. #else
  84. (*(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)))
  85. #endif
  86. );
  87. if (writing) *value = c;
  88. crc16(crc, &c, 1);
  89. pos++;
  90. value++;
  91. } while (--size);
  92. return false;
  93. }
  94. size_t PersistentStore::capacity() {
  95. return (
  96. #if ENABLED(SRAM_EEPROM_EMULATION)
  97. 4096 // 4kB
  98. #else
  99. E2END + 1
  100. #endif
  101. );
  102. }
  103. #endif // EEPROM_SETTINGS && (FLASH_EEPROM_EMULATION || SRAM_EEPROM_EMULATION || SPI_EEPROM || I2C_EEPROM)
  104. #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC