From d05e832f29b940f1afaa332b1f4c096c47324a32 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Fri, 6 Jul 2018 22:32:15 -0500
Subject: [PATCH 1/3] Add STM32F1 support for SD-based EEPROM

---
 .../src/HAL/HAL_AVR/persistent_store_impl.cpp |  9 ++-----
 .../src/HAL/HAL_DUE/persistent_store_impl.cpp | 12 ++++-----
 .../HAL_STM32F1/persistent_store_flash.cpp    |  2 +-
 .../HAL/HAL_STM32F1/persistent_store_impl.cpp | 26 +++++++++----------
 .../HAL/HAL_STM32F4/persistent_store_impl.cpp |  1 -
 .../HAL/HAL_STM32F7/persistent_store_impl.cpp |  9 ++-----
 .../HAL_TEENSY35_36/persistent_store_impl.cpp |  9 ++-----
 Marlin/src/sd/cardreader.h                    |  5 ++++
 8 files changed, 29 insertions(+), 44 deletions(-)

diff --git a/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp
index 9d5ddd1bd7..ef6fbeabd5 100644
--- a/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp
@@ -9,13 +9,8 @@
 namespace HAL {
 namespace PersistentStore {
 
-bool access_start() {
-  return true;
-}
-
-bool access_finish(){
-  return true;
-}
+bool access_start() { return true; }
+bool access_finish() { return true; }
 
 bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
   while (size--) {
diff --git a/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp
index f5276e045c..aef1d79f48 100644
--- a/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp
@@ -11,14 +11,12 @@ extern void eeprom_flush(void);
 namespace HAL {
 namespace PersistentStore {
 
-bool access_start() {
-  return true;
-}
+bool access_start() { return true; }
 
-bool access_finish(){
-#if DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM)
-  eeprom_flush();
-#endif
+bool access_finish() {
+  #if DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM)
+    eeprom_flush();
+  #endif
   return true;
 }
 
diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp
index a0b940f371..15472368e4 100644
--- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp
@@ -54,7 +54,7 @@ bool access_start() {
   return true;
 }
 
-bool access_finish(){
+bool access_finish() {
   FLASH_Lock();
   firstWrite = false;
   return true;
diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_impl.cpp
index bff4610085..a64eab076f 100644
--- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_impl.cpp
@@ -44,37 +44,35 @@
 namespace HAL {
 namespace PersistentStore {
 
-#define CONFIG_FILE_NAME "eeprom.dat"
 #define HAL_STM32F1_EEPROM_SIZE 4096
 char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
 
+char eeprom_filename[] = "eeprom.dat";
+
 bool access_start() {
   if (!card.cardOK) return false;
   int16_t bytes_read = 0;
-  const char eeprom_zero = 0xFF;
-  card.openFile((char *)CONFIG_FILE_NAME,true);
-  bytes_read = card.read (HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
-  if (bytes_read == -1) return false;
-  for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++) {
+  constexpr char eeprom_zero = 0xFF;
+  card.openFile(eeprom_filename, true);
+  bytes_read = card.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
+  if (bytes_read < 0) return false;
+  for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++)
     HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero;
-  }
   card.closefile();
   return true;
 }
 
-bool access_finish(){
+bool access_finish() {
   if (!card.cardOK) return false;
-  int16_t bytes_written = 0;
-  card.openFile((char *)CONFIG_FILE_NAME,true);
-  bytes_written = card.write (HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
+  card.openFile(eeprom_filename, true);
+  int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
   card.closefile();
   return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
 }
 
 bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
-  for (int i = 0; i < size; i++) {
-    HAL_STM32F1_eeprom_content [pos + i] = value[i];
-  }
+  for (int i = 0; i < size; i++)
+    HAL_STM32F1_eeprom_content[pos + i] = value[i];
   crc16(crc, value, size);
   pos += size;
   return false;
diff --git a/Marlin/src/HAL/HAL_STM32F4/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_STM32F4/persistent_store_impl.cpp
index db292bbb55..a896bded30 100644
--- a/Marlin/src/HAL/HAL_STM32F4/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_STM32F4/persistent_store_impl.cpp
@@ -33,7 +33,6 @@ namespace HAL {
 namespace PersistentStore {
 
 bool access_start() { return true; }
-
 bool access_finish() { return true; }
 
 bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
diff --git a/Marlin/src/HAL/HAL_STM32F7/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_STM32F7/persistent_store_impl.cpp
index ac4c3e7947..0cd37b9533 100644
--- a/Marlin/src/HAL/HAL_STM32F7/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_STM32F7/persistent_store_impl.cpp
@@ -33,13 +33,8 @@
 namespace HAL {
 namespace PersistentStore {
 
-bool access_start() {
-  return true;
-}
-
-bool access_finish(){
-  return true;
-}
+bool access_start() { return true; }
+bool access_finish() { return true; }
 
 bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
   while (size--) {
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp
index be0604dae2..550d2a851e 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp
@@ -9,13 +9,8 @@
 namespace HAL {
 namespace PersistentStore {
 
-bool access_start() {
-  return true;
-}
-
-bool access_finish() {
-  return true;
-}
+bool access_start() { return true; }
+bool access_finish() { return true; }
 
 bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
   while (size--) {
diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h
index 59b238e8d2..73352e920f 100644
--- a/Marlin/src/sd/cardreader.h
+++ b/Marlin/src/sd/cardreader.h
@@ -121,6 +121,11 @@ public:
   FORCE_INLINE uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
   FORCE_INLINE char* getWorkDirName() { workDir.getFilename(filename); return filename; }
 
+  #if defined(__STM32F1__) && ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
+    FORCE_INLINE int16_t read(void* buf, uint16_t nbyte) { return file.isOpen() ? file.read(buf, nbyte) : -1; }
+    FORCE_INLINE int16_t write(void* buf, uint16_t nbyte) { return file.isOpen() ? file.write(buf, nbyte) : -1; }
+  #endif
+
   Sd2Card& getSd2Card() { return sd2card; }
 
   #if ENABLED(AUTO_REPORT_SD_STATUS)

From ed720194d25c1820a6754c5871c2a735496b5066 Mon Sep 17 00:00:00 2001
From: Alexander Amelkin <mocbuhtig@amelkin.msk.ru>
Date: Fri, 6 Jul 2018 23:23:10 +0300
Subject: [PATCH 2/3] [2.0.x][HD44780] Remove unused include

The <binary.h> header is not available in STM32 toolchain
and is not used anywhere in ultralcd_common_HD44780.h.
If it is used anywhere in HD44780 support for other platforms,
it must be included in the corresponding .cpp file directly
and put under appropriate conditional compilation directives
for the platform requiring it.

As I was unable to find such code, I consider the file unused
and hence remove the inclusion.
---
 Marlin/src/lcd/ultralcd_common_HD44780.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/Marlin/src/lcd/ultralcd_common_HD44780.h b/Marlin/src/lcd/ultralcd_common_HD44780.h
index b366459cb3..970dbbf35a 100644
--- a/Marlin/src/lcd/ultralcd_common_HD44780.h
+++ b/Marlin/src/lcd/ultralcd_common_HD44780.h
@@ -52,8 +52,6 @@
   #endif
 #endif
 
-#include <binary.h>
-
 extern volatile uint8_t buttons;  //an extended version of the last checked buttons in a bit array.
 
 ////////////////////////////////////
@@ -199,5 +197,3 @@ enum HD44780CharSet : char {
 };
 
 #endif // ULTRALCD_COMMON_HD44780_H
-
-

From 03fa05ab59ed3727bec027f6dcc4fa53966e0de9 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Fri, 6 Jul 2018 20:59:33 -0500
Subject: [PATCH 3/3] Travis CI test STM32F1 with HD44780

---
 .travis.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index fa7a76571c..8d86fcafe7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -472,11 +472,12 @@ script:
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
 
   #############################
-  # STM32F1 default config test
+  # STM32F1 config test
   #############################
 
   - export TEST_PLATFORM="-e STM32F1"
   - restore_configs
   - opt_set MOTHERBOARD BOARD_STM32F1R
   - update_defaults
+  - opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}