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.

eeprom_sdcard.cpp 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Implementation of EEPROM settings in SD Card
  24. */
  25. #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
  26. #include "../../inc/MarlinConfig.h"
  27. #if ENABLED(SDCARD_EEPROM_EMULATION)
  28. #include "../shared/eeprom_api.h"
  29. #include "../../sd/cardreader.h"
  30. #define EEPROM_FILENAME "eeprom.dat"
  31. #ifndef MARLIN_EEPROM_SIZE
  32. #define MARLIN_EEPROM_SIZE 0x1000 // 4KB
  33. #endif
  34. size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
  35. #define _ALIGN(x) __attribute__ ((aligned(x)))
  36. static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
  37. bool PersistentStore::access_start() {
  38. if (!card.isMounted()) return false;
  39. SdFile file, root = card.getroot();
  40. if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
  41. return true;
  42. int bytes_read = file.read(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
  43. if (bytes_read < 0) return false;
  44. for (; bytes_read < MARLIN_EEPROM_SIZE; bytes_read++)
  45. HAL_eeprom_data[bytes_read] = 0xFF;
  46. file.close();
  47. return true;
  48. }
  49. bool PersistentStore::access_finish() {
  50. if (!card.isMounted()) return false;
  51. SdFile file, root = card.getroot();
  52. int bytes_written = 0;
  53. if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
  54. bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
  55. file.close();
  56. }
  57. return (bytes_written == MARLIN_EEPROM_SIZE);
  58. }
  59. bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
  60. for (size_t i = 0; i < size; i++)
  61. HAL_eeprom_data[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_eeprom_data[pos + i];
  69. if (writing) value[i] = c;
  70. crc16(crc, &c, 1);
  71. }
  72. pos += size;
  73. return false;
  74. }
  75. #endif // SDCARD_EEPROM_EMULATION
  76. #endif // STM32 && !STM32GENERIC