SD-Card logging for STM32 [EXPERIMENTAL] (#782)

* First test

* Update comments.
This commit is contained in:
Pasi Kemppainen 2022-02-05 00:15:58 +02:00 committed by GitHub
parent 986d5323db
commit fb0a52bf6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 6 deletions

View File

@ -63,7 +63,7 @@ platform = ststm32
framework = arduino
;board = genericSTM32F407VET6
board = black_f407ve
lib_deps = stm32duino/STM32duino RTC
lib_deps = stm32duino/STM32duino RTC, greiman/SdFat
board_build.core = stm32
build_flags = -std=gnu++11 -UBOARD_MAX_IO_PINS -DENABLE_HWSERIAL2 -DENABLE_HWSERIAL3 -DUSBCON -DHAL_PCD_MODULE_ENABLED -DUSBD_USE_CDC -DHAL_CAN_MODULE_ENABLED
upload_protocol = dfu

View File

@ -3,7 +3,11 @@
#ifdef SD_LOGGING
#include <SD.h>
#ifdef __SD_H__
#include <SD.h>
#else
#include "SdFat.h"
#endif
//#include <SdSpiCard.h>
#include "RingBuf.h"
@ -30,8 +34,10 @@
#define SD_SECTOR_SIZE 512 // Standard SD sector size
#ifdef CORE_TEENSY
#if defined CORE_TEENSY
#define SD_CS_PIN BUILTIN_SDCARD
#elif defined CORE_STM32
#define SD_CS_PIN PD2 //CS pin can be pretty much anything, but PD2 is one of the ones left unused from SDIO pins.
#else
#define SD_CS_PIN 10 //This is a made up value for now
#endif

View File

@ -1,6 +1,10 @@
#ifdef SD_LOGGING
#include <SPI.h>
#include <SD.h>
#ifdef __SD_H__
#include <SD.h>
#else
#include "SdFat.h"
#endif
#include "SD_logger.h"
#include "logger.h"
#include "rtc_common.h"

View File

@ -5,6 +5,7 @@
#include <HardwareTimer.h>
#include <HardwareSerial.h>
#include "STM32RTC.h"
#include <SPI.h>
#if defined(STM32F1)
#include "stm32f1xx_ll_tim.h"
@ -31,8 +32,18 @@
#define EEPROM_RESET_PIN USER_BTN //onboard key0 for black STM32F407 boards and blackpills, keep pressed during boot to reset eeprom
#endif
#ifdef SD_LOGGING
#define RTC_ENABLED
#if defined(STM32F407xx)
//Comment out this to disable SD logging for STM32 if needed. Currently SD logging for STM32 is experimental feature for F407.
#define SD_LOGGING
#endif
#if defined SD_LOGGING
#define RTC_ENABLED
//SD logging with STM32 uses SD card in SPI mode, because used SD library doesn't support SDIO implementation. By default SPI3 is used that uses same pins as SDIO also, but in different order.
extern SPIClass SD_SPI; //SPI3_MOSI, SPI3_MISO, SPI3_SCK
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(50), &SD_SPI)
//Alternatively same SPI bus can be used as there is for SPI flash. But this is not recommended due to slower speed and other possible problems.
//#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(50), &SPI_for_flash)
#endif
#define USE_SERIAL3

View File

@ -17,6 +17,10 @@ Default CAN3 pins are PA8 & PA15. Alternative (ALT) pins are PB3 & PB4.
*/
#endif
#if defined SD_LOGGING
SPIClass SD_SPI(PC12, PC11, PC10); //SPI3_MOSI, SPI3_MISO, SPI3_SCK
#endif
#if defined(SRAM_AS_EEPROM)
BackupSramAsEEPROM EEPROM;
#elif defined(USE_SPI_EEPROM)