2018-08-14 03:13:59 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
*
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-08-14 03:13:59 +02:00
|
|
|
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
|
|
|
|
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
|
|
|
|
* Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2017-08-01 04:44:26 +02:00
|
|
|
#ifdef ARDUINO_ARCH_SAM
|
|
|
|
|
2018-08-14 10:28:52 +02:00
|
|
|
#include "../../inc/MarlinConfigPre.h"
|
2017-07-19 01:29:06 +02:00
|
|
|
|
|
|
|
#if ENABLED(EEPROM_SETTINGS)
|
|
|
|
|
2018-08-15 00:54:12 +02:00
|
|
|
#include "../../inc/MarlinConfig.h"
|
2018-08-14 10:28:52 +02:00
|
|
|
#include "../shared/persistent_store_api.h"
|
|
|
|
|
2019-07-10 04:26:35 +02:00
|
|
|
#if !defined(E2END) && NONE(I2C_EEPROM, SPI_EEPROM)
|
2018-08-15 00:54:12 +02:00
|
|
|
#define E2END 0xFFF // Default to Flash emulated EEPROM size (EepromEmulation_Due.cpp)
|
|
|
|
#endif
|
|
|
|
|
Fixes for the Arduino DUE HAL (Serial Port, Graphics Display, EEPROM emulation) (#8651)
* Fixing the DUE serial port assignments: Now -1 means the SAM3x USB Device emulating a serial port, and 0 means the USB to serial adapter included as a programming port
* Improving the Fast IO port access implementation on Arduino DUE
* Implemented EEPROM emulation on Due by storing data on the internal FLASH (with wear leveling)
* Implemented a Software SPI for the ST7920 graphics display for the Arduino RAMPS for DUE, as the default one in u8glib is clocking data too fast on ARM, and the display does not understand it.
* Fixing the case where the serial port selected is the USB device
* Adding configuration for the Makerparts 3D printer (www.makerparts.net)
* Tuned MakerParts acceleration on X and Y axis so it never loses steps. Also adjusted pulses per mm to match default hw configuration
* Fine tuned Maximum acceleration for MakerParts printer
* Style cleanup
* Style cleanup (2)
* Style fixes (3)
* Fixing the DUE serial port assignments: Now -1 means the SAM3x USB Device emulating a serial port, and 0 means the USB to serial adapter included as a programming port
* Improving the Fast IO port access implementation on Arduino DUE
* Implemented EEPROM emulation on Due by storing data on the internal FLASH (with wear leveling)
* Implemented a Software SPI for the ST7920 graphics display for the Arduino RAMPS for DUE, as the default one in u8glib is clocking data too fast on ARM, and the display does not understand it.
* Fixing the case where the serial port selected is the USB device
* Adding configuration for the Makerparts 3D printer (www.makerparts.net)
* Tuned MakerParts acceleration on X and Y axis so it never loses steps. Also adjusted pulses per mm to match default hw configuration
* Fine tuned Maximum acceleration for MakerParts printer
* Style cleanup
* Style changes to u8g_dev_st7920_128_64_sw_spi.cpp
* Even more improvements to the FastIO HAL for DUE. Now WRITE() is 2 ASM instructions, if value is constant, and 5 cycles if value is not constant. Previously, it was 7..8 cycles
* After some problems and debugging, seems we need to align the interrupt vector table to 256 bytes, otherwise, the program sometimes stops working
* Moved comments out of macro, otherwise, token pasting does not properly work sometimes
* Improved Software SPI implementation on DUE: Now it honors the selected speed passed to spiInit(). This allows much faster SDCARD access, improving SDCARD menus and reducing latency
* Update u8g_dev_st7920_128_64_sw_spi.cpp
* Disabling EEPROM over FLASH emulatiion if an I2C or SPI EEPROM is present
2017-12-13 00:51:36 +01:00
|
|
|
extern void eeprom_flush(void);
|
|
|
|
|
2018-08-14 00:30:26 +02:00
|
|
|
bool PersistentStore::access_start() { return true; }
|
2017-07-19 01:29:06 +02:00
|
|
|
|
2018-08-14 00:30:26 +02:00
|
|
|
bool PersistentStore::access_finish() {
|
2019-07-06 01:20:15 +02:00
|
|
|
#if NONE(I2C_EEPROM, SPI_EEPROM)
|
2018-07-07 05:32:15 +02:00
|
|
|
eeprom_flush();
|
|
|
|
#endif
|
2017-07-19 01:29:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-14 00:30:26 +02:00
|
|
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
2017-07-19 01:29:06 +02:00
|
|
|
while (size--) {
|
|
|
|
uint8_t * const p = (uint8_t * const)pos;
|
|
|
|
uint8_t v = *value;
|
|
|
|
// EEPROM has only ~100,000 write cycles,
|
|
|
|
// so only write bytes that have changed!
|
|
|
|
if (v != eeprom_read_byte(p)) {
|
|
|
|
eeprom_write_byte(p, v);
|
2019-02-20 11:04:07 +01:00
|
|
|
delay(2);
|
2017-07-19 01:29:06 +02:00
|
|
|
if (eeprom_read_byte(p) != v) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHO_MSG(MSG_ERR_EEPROM_WRITE);
|
2017-10-18 21:00:29 +02:00
|
|
|
return true;
|
2017-07-19 01:29:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
crc16(crc, &v, 1);
|
|
|
|
pos++;
|
|
|
|
value++;
|
|
|
|
};
|
2017-10-18 21:00:29 +02:00
|
|
|
return false;
|
2017-07-19 01:29:06 +02:00
|
|
|
}
|
|
|
|
|
2018-08-14 00:30:26 +02:00
|
|
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
2017-07-19 01:29:06 +02:00
|
|
|
do {
|
2018-10-10 01:59:49 +02:00
|
|
|
uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
2018-01-05 02:51:18 +01:00
|
|
|
if (writing) *value = c;
|
2017-07-19 01:29:06 +02:00
|
|
|
crc16(crc, &c, 1);
|
|
|
|
pos++;
|
|
|
|
value++;
|
|
|
|
} while (--size);
|
2017-10-18 21:00:29 +02:00
|
|
|
return false;
|
2017-07-19 01:29:06 +02:00
|
|
|
}
|
|
|
|
|
2018-08-14 08:04:11 +02:00
|
|
|
size_t PersistentStore::capacity() { return E2END + 1; }
|
2017-07-19 01:29:06 +02:00
|
|
|
|
|
|
|
#endif // EEPROM_SETTINGS
|
2018-08-14 00:30:26 +02:00
|
|
|
#endif // ARDUINO_ARCH_SAM
|