Skip to content

Commit

Permalink
🐛 Fix LPC1768 SD-based EEPROM debug
Browse files Browse the repository at this point in the history
Fixes #22746
  • Loading branch information
thinkyhead committed Oct 3, 2021
1 parent e2a790b commit 22bf774
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
42 changes: 26 additions & 16 deletions Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/**
* Marlin 3D Printer Firmware
*
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins [email protected]
* Copyright (c) 2015-2016 Nico Tonnhofer [email protected]
* Copyright (c) 2016 Victor Perez [email protected]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* 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
Expand All @@ -20,12 +19,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

/**
* Implementation of EEPROM settings in SD Card
*/

#ifdef TARGET_LPC1768

#include "../../inc/MarlinConfig.h"

#if ENABLED(SDCARD_EEPROM_EMULATION)

//#define DEBUG_SD_EEPROM_EMULATION

#include "../shared/eeprom_api.h"

#include <chanfs/diskio.h>
Expand All @@ -38,9 +44,11 @@ FATFS fat_fs;
FIL eeprom_file;
bool eeprom_file_open = false;

#define EEPROM_FILENAME "eeprom.dat"
#ifndef MARLIN_EEPROM_SIZE
#define MARLIN_EEPROM_SIZE size_t(0x1000) // 4KiB of Emulated EEPROM
#endif

size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }

bool PersistentStore::access_start() {
Expand All @@ -50,7 +58,7 @@ bool PersistentStore::access_start() {
MSC_Release_Lock();
return false;
}
FRESULT res = f_open(&eeprom_file, "eeprom.dat", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
FRESULT res = f_open(&eeprom_file, EEPROM_FILENAME, FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
if (res) MSC_Release_Lock();

if (res == FR_OK) {
Expand Down Expand Up @@ -81,18 +89,20 @@ bool PersistentStore::access_finish() {
// This extra chit-chat goes away soon, but is helpful for now
// to see errors that are happening in read_data / write_data
static void debug_rw(const bool write, int &pos, const uint8_t *value, const size_t size, const FRESULT s, const size_t total=0) {
PGM_P const rw_str = write ? PSTR("write") : PSTR("read");
SERIAL_CHAR(' ');
SERIAL_ECHOPGM_P(rw_str);
SERIAL_ECHOLNPGM("_data(", pos, ",", value, ",", size, ", ...)");
if (total) {
SERIAL_ECHOPGM(" f_");
#if ENABLED(DEBUG_SD_EEPROM_EMULATION)
PGM_P const rw_str = write ? PSTR("write") : PSTR("read");
SERIAL_CHAR(' ');
SERIAL_ECHOPGM_P(rw_str);
SERIAL_ECHOPGM("()=", s, "\n size=", size, "\n bytes_");
SERIAL_ECHOLNPGM_P(write ? PSTR("written=") : PSTR("read="), total);
}
else
SERIAL_ECHOLNPGM(" f_lseek()=", s);
SERIAL_ECHOLNPGM("_data(", pos, ",", *value, ",", size, ", ...)");
if (total) {
SERIAL_ECHOPGM(" f_");
SERIAL_ECHOPGM_P(rw_str);
SERIAL_ECHOPGM("()=", s, "\n size=", size, "\n bytes_");
SERIAL_ECHOLNPGM_P(write ? PSTR("written=") : PSTR("read="), total);
}
else
SERIAL_ECHOLNPGM(" f_lseek()=", s);
#endif
}

// File function return codes for type FRESULT. This goes away soon, but
Expand Down
6 changes: 4 additions & 2 deletions Marlin/src/pins/stm32f4/pins_ARMED.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
#define BOARD_INFO_NAME "Arm'ed"
#define DEFAULT_MACHINE_NAME BOARD_INFO_NAME

#define I2C_EEPROM
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
#if NO_EEPROM_SELECTED
#define I2C_EEPROM
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
#endif

//
// Limit Switches
Expand Down

0 comments on commit 22bf774

Please sign in to comment.