This repository has been archived on 2022-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
Marlin-Artillery-M600/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp

100 lines
3 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/>.
*
*/
/**
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
*/
#ifdef __STM32F1__
#include "../../inc/MarlinConfig.h"
[2.0.x] Multiple updates to STM32F1 HAL (#8733) * STM32F1 HAL Adding files for STM32F1 HAL based on libmaple/stm32duino core. Current persistent_store uses cardreader changes to be sent in separate commit, but could be changed to use i2c eeprom. There is another persistent_store implementation that uses the MCU flash memory to emulate eeprom Adding readme with some information about the stm32 HAL. * Switch to Timer4 to avoid a hard reset on STM32F103C6 boards On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers. * Add support for EEPROM emulation using Flash Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled. * Basic Pins for a malyan M200 This is a work in progress to go hand in hand with the STM32 work. * Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor. * Missing file - change HAL_adc_init to actually do something We have an actual ADC init function now. * Remove pinmode hack Remove the pin mode hack that I was using to init PA0. Updated Readme.md * Several changes to timers and GPIO Faster GPIO, and faster timer functions by accesing registers and libmaple. Still more changes pending for the Timer's code to skip using the HardwareTimer class altogether. Switch all enums to be within #defines This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order. * Update Malyan M200 pins Update Malyan M200 pins with correct fan values. * Test all pins on actual hardware, update definitions Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final. * Update HAL_timers_Stm32f1.cpp * Add sample configurations for Malyan M200 Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan. Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer. readme.md update * Updates to timers, and some stm32 boards definitiions * Correct pin toggle macro. * Remove duplicated Malyan M200 entry from pins.h * Update configuration_store.cpp * Formatting, indentation * Formatting in HAL_Stm32f1.cpp
2017-12-11 06:12:45 +01:00
#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
#include "../persistent_store_api.h"
#include "../../sd/cardreader.h"
#define HAL_STM32F1_EEPROM_SIZE 4096
char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
char eeprom_filename[] = "eeprom.dat";
bool PersistentStore::access_start() {
2018-01-05 17:25:42 +01:00
if (!card.cardOK) return false;
int16_t bytes_read = 0;
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++)
2018-01-05 17:25:42 +01:00
HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero;
card.closefile();
return true;
}
bool PersistentStore::access_finish() {
2018-01-05 17:25:42 +01:00
if (!card.cardOK) return false;
card.openFile(eeprom_filename, true);
int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
2018-01-05 17:25:42 +01:00
card.closefile();
return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
}
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
for (int i = 0; i < size; i++)
HAL_STM32F1_eeprom_content[pos + i] = value[i];
2018-01-05 17:25:42 +01:00
crc16(crc, value, size);
pos += size;
return false;
}
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
2018-01-05 17:25:42 +01:00
for (int i = 0; i < size; i++) {
2018-01-05 02:51:18 +01:00
uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
if (writing) value[i] = c;
2018-01-05 02:51:18 +01:00
crc16(crc, &c, 1);
2018-01-05 17:25:42 +01:00
}
pos += size;
return false;
}
bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
int data_pos = pos;
uint16_t crc = 0;
return write_data(data_pos, value, size, &crc);
}
bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
int data_pos = pos;
uint16_t crc = 0;
return read_data(data_pos, value, size, &crc);
}
const size_t PersistentStore::capacity() {
return HAL_STM32F1_EEPROM_SIZE;
}
#endif // EEPROM_SETTINGS
#endif // __STM32F1__