Firmware2/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp

83 lines
2.4 KiB
C++
Raw Normal View History

/**
* Marlin 3D Printer Firmware
*
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* 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
#include "../../inc/MarlinConfigPre.h"
2017-07-19 01:29:06 +02:00
#if ENABLED(EEPROM_SETTINGS)
#include "../../inc/MarlinConfig.h"
#include "../shared/persistent_store_api.h"
#if DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM)
#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);
bool PersistentStore::access_start() { return true; }
2017-07-19 01:29:06 +02:00
bool PersistentStore::access_finish() {
#if DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM)
eeprom_flush();
#endif
2017-07-19 01:29:06 +02:00
return true;
}
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);
if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_START();
SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
return true;
2017-07-19 01:29:06 +02:00
}
}
crc16(crc, &v, 1);
pos++;
value++;
};
return false;
2017-07-19 01:29:06 +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);
return false;
2017-07-19 01:29:06 +02:00
}
size_t PersistentStore::capacity() { return E2END + 1; }
2017-07-19 01:29:06 +02:00
#endif // EEPROM_SETTINGS
#endif // ARDUINO_ARCH_SAM