|
@@ -62,7 +62,6 @@
|
|
|
#define MAX_BLOCKSIZE 2048 // Maximum BLOCK size
|
|
#define MAX_BLOCKSIZE 2048 // Maximum BLOCK size
|
|
|
|
|
|
|
|
// SDFAT
|
|
// SDFAT
|
|
|
-#define SD1_CONFIG SdSpiConfig(PA4, DEDICATED_SPI, SD_SCK_MHZ(SPI_FULL_SPEED), &SPI)
|
|
|
|
|
SdFs SD;
|
|
SdFs SD;
|
|
|
|
|
|
|
|
#if DEBUG == 1
|
|
#if DEBUG == 1
|
|
@@ -251,7 +250,7 @@ byte SCSI_INFO_BUF[36] = {
|
|
|
void onFalseInit(void);
|
|
void onFalseInit(void);
|
|
|
void noSDCardFound(void);
|
|
void noSDCardFound(void);
|
|
|
void onBusReset(void);
|
|
void onBusReset(void);
|
|
|
-void initFileLog(void);
|
|
|
|
|
|
|
+void initFileLog(int);
|
|
|
void finalizeFileLog(void);
|
|
void finalizeFileLog(void);
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -421,16 +420,27 @@ void setup()
|
|
|
//Occurs when the RST pin state changes from HIGH to LOW
|
|
//Occurs when the RST pin state changes from HIGH to LOW
|
|
|
//attachInterrupt(RST, onBusReset, FALLING);
|
|
//attachInterrupt(RST, onBusReset, FALLING);
|
|
|
|
|
|
|
|
|
|
+ // Try different clock speeds till we find one that is stable.
|
|
|
LED_ON();
|
|
LED_ON();
|
|
|
|
|
+ int mhz = 50;
|
|
|
|
|
+ bool sd_ready = false;
|
|
|
|
|
+ while (mhz >= 32 && !sd_ready) {
|
|
|
|
|
+ if(SD.begin(SdSpiConfig(PA4, DEDICATED_SPI, SD_SCK_MHZ(mhz), &SPI))) {
|
|
|
|
|
+ sd_ready = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ mhz--;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ LED_OFF();
|
|
|
|
|
|
|
|
- // clock = 36MHz , about 4Mbytes/sec
|
|
|
|
|
- if(!SD.begin(SD1_CONFIG)) {
|
|
|
|
|
|
|
+ if(!sd_ready) {
|
|
|
#if DEBUG > 0
|
|
#if DEBUG > 0
|
|
|
Serial.println("SD initialization failed!");
|
|
Serial.println("SD initialization failed!");
|
|
|
#endif
|
|
#endif
|
|
|
noSDCardFound();
|
|
noSDCardFound();
|
|
|
}
|
|
}
|
|
|
- initFileLog();
|
|
|
|
|
|
|
+ initFileLog(mhz);
|
|
|
readSCSIDeviceConfig();
|
|
readSCSIDeviceConfig();
|
|
|
readSDCardInfo();
|
|
readSDCardInfo();
|
|
|
|
|
|
|
@@ -528,7 +538,7 @@ void setup()
|
|
|
/*
|
|
/*
|
|
|
* Setup initialization logfile
|
|
* Setup initialization logfile
|
|
|
*/
|
|
*/
|
|
|
-void initFileLog() {
|
|
|
|
|
|
|
+void initFileLog(int success_mhz) {
|
|
|
LOG_FILE = SD.open(LOG_FILENAME, O_WRONLY | O_CREAT | O_TRUNC);
|
|
LOG_FILE = SD.open(LOG_FILENAME, O_WRONLY | O_CREAT | O_TRUNC);
|
|
|
LOG_FILE.println("BlueSCSI <-> SD - https://github.com/erichelgeson/BlueSCSI");
|
|
LOG_FILE.println("BlueSCSI <-> SD - https://github.com/erichelgeson/BlueSCSI");
|
|
|
LOG_FILE.print("VERSION: ");
|
|
LOG_FILE.print("VERSION: ");
|
|
@@ -541,6 +551,12 @@ void initFileLog() {
|
|
|
LOG_FILE.println(SDFAT_FILE_TYPE);
|
|
LOG_FILE.println(SDFAT_FILE_TYPE);
|
|
|
LOG_FILE.print("SdFat version: ");
|
|
LOG_FILE.print("SdFat version: ");
|
|
|
LOG_FILE.println(SD_FAT_VERSION_STR);
|
|
LOG_FILE.println(SD_FAT_VERSION_STR);
|
|
|
|
|
+ LOG_FILE.print("SPI speed: ");
|
|
|
|
|
+ LOG_FILE.print(success_mhz);
|
|
|
|
|
+ LOG_FILE.println("Mhz");
|
|
|
|
|
+ if(success_mhz < 40) {
|
|
|
|
|
+ LOG_FILE.println("SPI under 40Mhz - read https://github.com/erichelgeson/BlueSCSI/wiki/Slow-SPI");
|
|
|
|
|
+ }
|
|
|
LOG_FILE.print("SdFat Max FileName Length: ");
|
|
LOG_FILE.print("SdFat Max FileName Length: ");
|
|
|
LOG_FILE.println(MAX_FILE_PATH);
|
|
LOG_FILE.println(MAX_FILE_PATH);
|
|
|
LOG_FILE.println("Initialized SD Card - lets go!");
|
|
LOG_FILE.println("Initialized SD Card - lets go!");
|