Merge pull request #69 from erichelgeson/eric/spiSpeed

Try clock speeds from 50 -> 32mhz for SD communication
This commit is contained in:
Eric Helgeson 2022-03-26 08:28:43 -05:00 committed by GitHub
commit 13b8de7bfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 6 deletions

View File

@ -62,7 +62,6 @@
#define MAX_BLOCKSIZE 2048 // Maximum BLOCK size
// SDFAT
#define SD1_CONFIG SdSpiConfig(PA4, DEDICATED_SPI, SD_SCK_MHZ(SPI_FULL_SPEED), &SPI)
SdFs SD;
#if DEBUG == 1
@ -251,7 +250,7 @@ byte SCSI_INFO_BUF[36] = {
void onFalseInit(void);
void noSDCardFound(void);
void onBusReset(void);
void initFileLog(void);
void initFileLog(int);
void finalizeFileLog(void);
/*
@ -421,16 +420,27 @@ void setup()
//Occurs when the RST pin state changes from HIGH to LOW
//attachInterrupt(RST, onBusReset, FALLING);
// Try different clock speeds till we find one that is stable.
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
Serial.println("SD initialization failed!");
#endif
noSDCardFound();
}
initFileLog();
initFileLog(mhz);
readSCSIDeviceConfig();
readSDCardInfo();
@ -528,7 +538,7 @@ void setup()
/*
* Setup initialization logfile
*/
void initFileLog() {
void initFileLog(int success_mhz) {
LOG_FILE = SD.open(LOG_FILENAME, O_WRONLY | O_CREAT | O_TRUNC);
LOG_FILE.println("BlueSCSI <-> SD - https://github.com/erichelgeson/BlueSCSI");
LOG_FILE.print("VERSION: ");
@ -541,6 +551,12 @@ void initFileLog() {
LOG_FILE.println(SDFAT_FILE_TYPE);
LOG_FILE.print("SdFat version: ");
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.println(MAX_FILE_PATH);
LOG_FILE.println("Initialized SD Card - lets go!");