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_sdcard.cpp 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
  24. */
  25. #ifdef __STM32F1__
  26. #include "../../inc/MarlinConfig.h"
  27. #if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
  28. #include "../shared/persistent_store_api.h"
  29. #ifndef E2END
  30. #define E2END 4095
  31. #endif
  32. #define HAL_STM32F1_EEPROM_SIZE (E2END + 1)
  33. static char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
  34. #if ENABLED(SDSUPPORT)
  35. #include "../../sd/cardreader.h"
  36. static char eeprom_filename[] = "eeprom.dat";
  37. bool PersistentStore::access_start() {
  38. if (!card.isDetected()) return false;
  39. int16_t bytes_read = 0;
  40. constexpr char eeprom_zero = 0xFF;
  41. card.openFile(eeprom_filename, true);
  42. bytes_read = card.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
  43. if (bytes_read < 0) return false;
  44. for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++)
  45. HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero;
  46. card.closefile();
  47. return true;
  48. }
  49. bool PersistentStore::access_finish() {
  50. if (!card.isDetected()) return false;
  51. card.openFile(eeprom_filename, false);
  52. int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
  53. card.closefile();
  54. return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
  55. }
  56. #else // !SDSUPPORT
  57. #error "Please define SPI_EEPROM (in Configuration.h) or disable EEPROM_SETTINGS."
  58. #endif // !SDSUPPORT
  59. bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
  60. for (size_t i = 0; i < size; i++)
  61. HAL_STM32F1_eeprom_content[pos + i] = value[i];
  62. crc16(crc, value, size);
  63. pos += size;
  64. return false;
  65. }
  66. bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
  67. for (size_t i = 0; i < size; i++) {
  68. uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
  69. if (writing) value[i] = c;
  70. crc16(crc, &c, 1);
  71. }
  72. pos += size;
  73. return false;
  74. }
  75. size_t PersistentStore::capacity() { return HAL_STM32F1_EEPROM_SIZE; }
  76. #endif // EEPROM_SETTINGS
  77. #endif // __STM32F1__