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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
  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. #define EEPROM_FILENAME "eeprom.dat"
  37. bool PersistentStore::access_start() {
  38. if (!card.isDetected()) return false;
  39. SdFile file, root = card.getroot();
  40. if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
  41. return false;
  42. int16_t bytes_read = file.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] = 0xFF;
  46. file.close();
  47. return true;
  48. }
  49. bool PersistentStore::access_finish() {
  50. if (!card.isDetected()) return false;
  51. SdFile file, root = card.getroot();
  52. int16_t bytes_written = 0;
  53. if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
  54. bytes_written = file.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
  55. file.close();
  56. }
  57. return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
  58. }
  59. #else // !SDSUPPORT
  60. #error "Please define SPI_EEPROM (in Configuration.h) or disable EEPROM_SETTINGS."
  61. #endif // !SDSUPPORT
  62. bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
  63. for (size_t i = 0; i < size; i++)
  64. HAL_STM32F1_eeprom_content[pos + i] = value[i];
  65. crc16(crc, value, size);
  66. pos += size;
  67. return false;
  68. }
  69. bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
  70. for (size_t i = 0; i < size; i++) {
  71. uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
  72. if (writing) value[i] = c;
  73. crc16(crc, &c, 1);
  74. }
  75. pos += size;
  76. return false;
  77. }
  78. size_t PersistentStore::capacity() { return HAL_STM32F1_EEPROM_SIZE; }
  79. #endif // EEPROM_SETTINGS
  80. #endif // __STM32F1__