diff --git a/platformio.ini b/platformio.ini index f1b06b1c..2a8717a5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 diff --git a/speeduino/SD_logger.h b/speeduino/SD_logger.h index 442b1d4c..4ae709f4 100644 --- a/speeduino/SD_logger.h +++ b/speeduino/SD_logger.h @@ -3,7 +3,11 @@ #ifdef SD_LOGGING -#include +#ifdef __SD_H__ + #include +#else + #include "SdFat.h" +#endif //#include #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 diff --git a/speeduino/SD_logger.ino b/speeduino/SD_logger.ino index 8f5f72a3..de54ebd7 100644 --- a/speeduino/SD_logger.ino +++ b/speeduino/SD_logger.ino @@ -1,6 +1,10 @@ #ifdef SD_LOGGING #include -#include +#ifdef __SD_H__ + #include +#else + #include "SdFat.h" +#endif #include "SD_logger.h" #include "logger.h" #include "rtc_common.h" diff --git a/speeduino/board_stm32_official.h b/speeduino/board_stm32_official.h index 9fe8248f..86cc077b 100644 --- a/speeduino/board_stm32_official.h +++ b/speeduino/board_stm32_official.h @@ -5,6 +5,7 @@ #include #include #include "STM32RTC.h" +#include #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 diff --git a/speeduino/board_stm32_official.ino b/speeduino/board_stm32_official.ino index 82a768ad..fbf78169 100644 --- a/speeduino/board_stm32_official.ino +++ b/speeduino/board_stm32_official.ino @@ -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)