Skip to content

Commit ffb372e

Browse files
committed
Merge branch 'bugfix-2.0.x' into 2.0.x-Sapphire-Pro
2 parents fc87e19 + 8752fbd commit ffb372e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+469
-195
lines changed

Marlin/src/HAL/AVR/persistent_store_eeprom.cpp Marlin/src/HAL/AVR/eeprom.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
2727

28-
#include "../shared/persistent_store_api.h"
28+
#include "../shared/eeprom_api.h"
2929

3030
bool PersistentStore::access_start() { return true; }
3131
bool PersistentStore::access_finish() { return true; }

Marlin/src/HAL/DUE/EepromEmulation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#if ENABLED(FLASH_EEPROM_EMULATION)
5858

5959
#include "../shared/Marduino.h"
60-
#include "../shared/persistent_store_api.h"
60+
#include "../shared/eeprom_api.h"
6161

6262
#define EEPROMSize 4096
6363
#define PagesPerGroup 128

Marlin/src/HAL/DUE/persistent_store_eeprom.cpp Marlin/src/HAL/DUE/eeprom.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#if ENABLED(EEPROM_SETTINGS)
2828

2929
#include "../../inc/MarlinConfig.h"
30-
#include "../shared/persistent_store_api.h"
30+
#include "../shared/eeprom_api.h"
3131

3232
#if !defined(E2END) && ENABLED(FLASH_EEPROM_EMULATION)
3333
#define E2END 0xFFF // Default to Flash emulated EEPROM size (EepromEmulation_Due.cpp)

Marlin/src/HAL/DUE/inc/Conditionals_post.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
#pragma once
2323

24-
#if USE_EMULATED_EEPROM
24+
#if USE_FALLBACK_EEPROM
2525
#undef SRAM_EEPROM_EMULATION
2626
#undef SDCARD_EEPROM_EMULATION
2727
#define FLASH_EEPROM_EMULATION

Marlin/src/HAL/ESP32/persistent_store_impl.cpp Marlin/src/HAL/ESP32/eeprom_impl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
2828

29-
#include "../shared/persistent_store_api.h"
29+
#include "../shared/eeprom_api.h"
3030
#include "EEPROM.h"
3131

3232
#define EEPROM_SIZE 4096

Marlin/src/HAL/ESP32/inc/Conditionals_post.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
#pragma once
2323

2424
// If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation
25-
#if ENABLED(EEPROM_SETTINGS) && NONE(USE_REAL_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
25+
#if ENABLED(EEPROM_SETTINGS) && NONE(USE_WIRED_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
2626
#define SDCARD_EEPROM_EMULATION
2727
#endif

Marlin/src/HAL/LINUX/persistent_store_impl.cpp Marlin/src/HAL/LINUX/eeprom_impl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#if ENABLED(EEPROM_SETTINGS)
2828

29-
#include "../shared/persistent_store_api.h"
29+
#include "../shared/eeprom_api.h"
3030
#include <stdio.h>
3131

3232
#define LINUX_EEPROM_SIZE (E2END + 1)

Marlin/src/HAL/LPC1768/persistent_store_api.h Marlin/src/HAL/LPC1768/eeprom_api.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
*/
2222
#pragma once
2323

24-
#include "../shared/persistent_store_api.h"
24+
#include "../shared/eeprom_api.h"
2525

2626
#define FLASH_EEPROM_EMULATION

Marlin/src/HAL/LPC1768/persistent_store_flash.cpp Marlin/src/HAL/LPC1768/eeprom_flash.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
#if ENABLED(FLASH_EEPROM_EMULATION)
4242

43-
#include "persistent_store_api.h"
43+
#include "eeprom_api.h"
4444

4545
extern "C" {
4646
#include <lpc17xx_iap.h>

Marlin/src/HAL/LPC1768/persistent_store_sdcard.cpp Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#if ENABLED(SDCARD_EEPROM_EMULATION)
2828

29-
#include "persistent_store_api.h"
29+
#include "eeprom_api.h"
3030

3131
#include <chanfs/diskio.h>
3232
#include <chanfs/ff.h>

Marlin/src/HAL/LPC1768/inc/Conditionals_post.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
*/
2222
#pragma once
2323

24-
#if USE_EMULATED_EEPROM && NONE(SDCARD_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
24+
#if USE_FALLBACK_EEPROM && NONE(SDCARD_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
2525
#define FLASH_EEPROM_EMULATION
2626
#endif

Marlin/src/HAL/SAMD51/QSPIFlash.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
#include "../../inc/MarlinConfig.h"
24+
25+
#if ENABLED(QSPI_EEPROM)
26+
27+
#include "QSPIFlash.h"
28+
29+
#define INVALID_ADDR 0xffffffff
30+
#define SECTOR_OF(a) (a & ~(SFLASH_SECTOR_SIZE - 1))
31+
#define OFFSET_OF(a) (a & (SFLASH_SECTOR_SIZE - 1))
32+
33+
Adafruit_SPIFlashBase * QSPIFlash::_flashBase = nullptr;
34+
uint8_t QSPIFlash::_buf[SFLASH_SECTOR_SIZE];
35+
uint32_t QSPIFlash::_addr = INVALID_ADDR;
36+
37+
void QSPIFlash::begin() {
38+
if (_flashBase != nullptr) return;
39+
40+
_flashBase = new Adafruit_SPIFlashBase(new Adafruit_FlashTransport_QSPI());
41+
_flashBase->begin(NULL);
42+
}
43+
44+
size_t QSPIFlash::size() {
45+
return _flashBase->size();
46+
}
47+
48+
uint8_t QSPIFlash::readByte(const uint32_t address) {
49+
if (SECTOR_OF(address) == _addr) return _buf[OFFSET_OF(address)];
50+
51+
return _flashBase->read8(address);
52+
}
53+
54+
void QSPIFlash::writeByte(const uint32_t address, const uint8_t value) {
55+
uint32_t const sector_addr = SECTOR_OF(address);
56+
57+
// Page changes, flush old and update new cache
58+
if (sector_addr != _addr) {
59+
flush();
60+
_addr = sector_addr;
61+
62+
// read a whole page from flash
63+
_flashBase->readBuffer(sector_addr, _buf, SFLASH_SECTOR_SIZE);
64+
}
65+
66+
_buf[OFFSET_OF(address)] = value;
67+
}
68+
69+
void QSPIFlash::flush() {
70+
if (_addr == INVALID_ADDR) return;
71+
72+
_flashBase->eraseSector(_addr / SFLASH_SECTOR_SIZE);
73+
_flashBase->writeBuffer(_addr, _buf, SFLASH_SECTOR_SIZE);
74+
75+
_addr = INVALID_ADDR;
76+
}
77+
78+
#endif // QSPI_EEPROM

Marlin/src/HAL/SAMD51/QSPIFlash.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @file QSPIFlash.h
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Ha Thach and Dean Miller for Adafruit Industries LLC
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
* Derived from Adafruit_SPIFlash class with no SdFat references
27+
*
28+
*/
29+
30+
#pragma once
31+
32+
#include "Adafruit_SPIFlashBase.h"
33+
34+
// This class extends Adafruit_SPIFlashBase by adding caching support.
35+
//
36+
// This class will use 4096 Bytes of RAM as a block cache.
37+
class QSPIFlash {
38+
public:
39+
static void begin();
40+
static size_t size();
41+
static uint8_t readByte(const uint32_t address);
42+
static void writeByte(const uint32_t address, const uint8_t v);
43+
static void flush();
44+
45+
private:
46+
static Adafruit_SPIFlashBase * _flashBase;
47+
static uint8_t _buf[SFLASH_SECTOR_SIZE];
48+
static uint32_t _addr;
49+
};
50+
51+
extern QSPIFlash qspi;

Marlin/src/HAL/SAMD51/eeprom.cpp

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
*
4+
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5+
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
#ifdef __SAMD51__
23+
24+
#include "../../inc/MarlinConfig.h"
25+
26+
#if ENABLED(EEPROM_SETTINGS) && NONE(QSPI_EEPROM, FLASH_EEPROM_EMULATION)
27+
28+
#include "../shared/eeprom_api.h"
29+
30+
size_t PersistentStore::capacity() { return E2END + 1; }
31+
32+
bool PersistentStore::access_start() { return true; }
33+
bool PersistentStore::access_finish() { return true; }
34+
35+
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
36+
while (size--) {
37+
const uint8_t v = *value;
38+
uint8_t * const p = (uint8_t * const)pos;
39+
if (v != eeprom_read_byte(p)) {
40+
eeprom_write_byte(p, v);
41+
delay(2);
42+
if (eeprom_read_byte(p) != v) {
43+
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
44+
return true;
45+
}
46+
}
47+
crc16(crc, &v, 1);
48+
pos++;
49+
value++;
50+
}
51+
return false;
52+
}
53+
54+
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
55+
while (size--) {
56+
uint8_t c = eeprom_read_byte((uint8_t*)pos);
57+
if (writing) *value = c;
58+
crc16(crc, &c, 1);
59+
pos++;
60+
value++;
61+
}
62+
return false;
63+
}
64+
65+
#endif // EEPROM_SETTINGS && !(QSPI_EEPROM || FLASH_EEPROM_EMULATION)
66+
#endif // __SAMD51__
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
*
4+
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5+
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
#ifdef __SAMD51__
23+
24+
#include "../../inc/MarlinConfig.h"
25+
26+
#if ENABLED(FLASH_EEPROM_EMULATION)
27+
28+
#include "../shared/eeprom_api.h"
29+
30+
#define NVMCTRL_CMD(c) do{ \
31+
SYNC(!NVMCTRL->STATUS.bit.READY); \
32+
NVMCTRL->INTFLAG.bit.DONE = true; \
33+
NVMCTRL->CTRLB.reg = c | NVMCTRL_CTRLB_CMDEX_KEY; \
34+
SYNC(NVMCTRL->INTFLAG.bit.DONE); \
35+
}while(0)
36+
#define NVMCTRL_FLUSH() do{ \
37+
if (NVMCTRL->SEESTAT.bit.LOAD) \
38+
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_SEEFLUSH); \
39+
}while(0)
40+
41+
size_t PersistentStore::capacity() {
42+
const uint8_t psz = NVMCTRL->SEESTAT.bit.PSZ,
43+
sblk = NVMCTRL->SEESTAT.bit.SBLK;
44+
45+
return (!psz && !sblk) ? 0
46+
: (psz <= 2) ? (0x200 << psz)
47+
: (sblk == 1 || psz == 3) ? 4096
48+
: (sblk == 2 || psz == 4) ? 8192
49+
: (sblk <= 4 || psz == 5) ? 16384
50+
: (sblk >= 9 && psz == 7) ? 65536
51+
: 32768;
52+
}
53+
54+
bool PersistentStore::access_start() {
55+
NVMCTRL->SEECFG.reg = NVMCTRL_SEECFG_WMODE_BUFFERED; // Buffered mode and segment reallocation active
56+
if (NVMCTRL->SEESTAT.bit.RLOCK)
57+
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_USEE); // Unlock E2P data write access
58+
return true;
59+
}
60+
61+
bool PersistentStore::access_finish() {
62+
NVMCTRL_FLUSH();
63+
if (!NVMCTRL->SEESTAT.bit.LOCK)
64+
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_LSEE); // Lock E2P data write access
65+
return true;
66+
}
67+
68+
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
69+
while (size--) {
70+
const uint8_t v = *value;
71+
SYNC(NVMCTRL->SEESTAT.bit.BUSY);
72+
if (NVMCTRL->INTFLAG.bit.SEESFULL)
73+
NVMCTRL_FLUSH(); // Next write will trigger a sector reallocation. I need to flush 'pagebuffer'
74+
((volatile uint8_t *)SEEPROM_ADDR)[pos] = v;
75+
SYNC(!NVMCTRL->INTFLAG.bit.SEEWRC);
76+
crc16(crc, &v, 1);
77+
pos++;
78+
value++;
79+
}
80+
return false;
81+
}
82+
83+
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
84+
while (size--) {
85+
SYNC(NVMCTRL->SEESTAT.bit.BUSY);
86+
uint8_t c = ((volatile uint8_t *)SEEPROM_ADDR)[pos];
87+
if (writing) *value = c;
88+
crc16(crc, &c, 1);
89+
pos++;
90+
value++;
91+
}
92+
return false;
93+
}
94+
95+
#endif // FLASH_EEPROM_EMULATION
96+
#endif // __SAMD51__

0 commit comments

Comments
 (0)