My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

persistent_store_impl.cpp 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 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 EITHER(USE_REAL_EEPROM, SRAM_EEPROM_EMULATION)
  26. #include "../shared/persistent_store_api.h"
  27. bool PersistentStore::access_start() {
  28. return true;
  29. }
  30. bool PersistentStore::access_finish() {
  31. return true;
  32. }
  33. bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
  34. while (size--) {
  35. uint8_t v = *value;
  36. // Save to either external EEPROM, program flash or Backup SRAM
  37. #if USE_REAL_EEPROM
  38. // EEPROM has only ~100,000 write cycles,
  39. // so only write bytes that have changed!
  40. uint8_t * const p = (uint8_t * const)pos;
  41. if (v != eeprom_read_byte(p)) {
  42. eeprom_write_byte(p, v);
  43. if (eeprom_read_byte(p) != v) {
  44. SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
  45. return true;
  46. }
  47. }
  48. #else
  49. *(__IO uint8_t *)(BKPSRAM_BASE + (uint8_t * const)pos) = v;
  50. #endif
  51. crc16(crc, &v, 1);
  52. pos++;
  53. value++;
  54. };
  55. return false;
  56. }
  57. bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
  58. do {
  59. // Read from either external EEPROM, program flash or Backup SRAM
  60. const uint8_t c = (
  61. #if USE_REAL_EEPROM
  62. eeprom_read_byte((uint8_t*)pos)
  63. #else
  64. (*(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)))
  65. #endif
  66. );
  67. if (writing) *value = c;
  68. crc16(crc, &c, 1);
  69. pos++;
  70. value++;
  71. } while (--size);
  72. return false;
  73. }
  74. size_t PersistentStore::capacity() {
  75. return (
  76. #if USE_REAL_EEPROM
  77. E2END + 1
  78. #else
  79. 4096 // 4kB
  80. #endif
  81. );
  82. }
  83. #endif // USE_REAL_EEPROM || SRAM_EEPROM_EMULATION
  84. #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC