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.

EmulatedEeprom.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #ifdef STM32F7
  20. /**
  21. * Description: functions for I2C connected external EEPROM.
  22. * Not platform dependent.
  23. */
  24. #include "../../inc/MarlinConfig.h"
  25. // --------------------------------------------------------------------------
  26. // Includes
  27. // --------------------------------------------------------------------------
  28. #include "../HAL.h"
  29. #include "EEPROM_Emul/eeprom_emul.h"
  30. // --------------------------------------------------------------------------
  31. // Externals
  32. // --------------------------------------------------------------------------
  33. // --------------------------------------------------------------------------
  34. // Local defines
  35. // --------------------------------------------------------------------------
  36. // --------------------------------------------------------------------------
  37. // Types
  38. // --------------------------------------------------------------------------
  39. // --------------------------------------------------------------------------
  40. // Variables
  41. // --------------------------------------------------------------------------
  42. // --------------------------------------------------------------------------
  43. // Public Variables
  44. // --------------------------------------------------------------------------
  45. // --------------------------------------------------------------------------
  46. // Private Variables
  47. // --------------------------------------------------------------------------
  48. static bool eeprom_initialised = false;
  49. // --------------------------------------------------------------------------
  50. // Function prototypes
  51. // --------------------------------------------------------------------------
  52. // --------------------------------------------------------------------------
  53. // Private functions
  54. // --------------------------------------------------------------------------
  55. // --------------------------------------------------------------------------
  56. // Public functions
  57. // --------------------------------------------------------------------------
  58. // FLASH_FLAG_PGSERR (Programming Sequence Error) was renamed to
  59. // FLASH_FLAG_ERSERR (Erasing Sequence Error) in STM32F7
  60. #define FLASH_FLAG_PGSERR FLASH_FLAG_ERSERR
  61. // --------------------------------------------------------------------------
  62. // EEPROM
  63. // --------------------------------------------------------------------------
  64. void eeprom_init() {
  65. if(!eeprom_initialised) {
  66. HAL_FLASH_Unlock();
  67. __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
  68. /* EEPROM Init */
  69. if(EE_Initialise() != EE_OK)
  70. {
  71. while(1) {
  72. HAL_Delay(1);
  73. }
  74. }
  75. HAL_FLASH_Lock();
  76. eeprom_initialised = true;
  77. }
  78. }
  79. void eeprom_write_byte(unsigned char *pos, unsigned char value) {
  80. uint16_t eeprom_address = (unsigned) pos;
  81. eeprom_init();
  82. HAL_FLASH_Unlock();
  83. __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
  84. if(EE_WriteVariable(eeprom_address, (uint16_t) value) != EE_OK) {
  85. while(1) {
  86. HAL_Delay(1);
  87. }
  88. }
  89. HAL_FLASH_Lock();
  90. }
  91. unsigned char eeprom_read_byte(unsigned char *pos) {
  92. uint16_t data = 0xFF;
  93. uint16_t eeprom_address = (unsigned) pos;
  94. eeprom_init();
  95. if(EE_ReadVariable(eeprom_address, &data) != EE_OK) {
  96. return (char) data;
  97. }
  98. return (char)data;
  99. }
  100. void eeprom_read_block (void *__dst, const void *__src, size_t __n) {
  101. uint16_t data = 0xFF;
  102. uint16_t eeprom_address = (unsigned) __src;
  103. eeprom_init();
  104. for(uint8_t c = 0; c < __n; c++) {
  105. EE_ReadVariable(eeprom_address+c, &data);
  106. *((uint8_t*)__dst + c) = data;
  107. }
  108. }
  109. void eeprom_update_block (const void *__src, void *__dst, size_t __n) {
  110. }
  111. #endif // STM32F7