mirror of
https://github.com/erichelgeson/BlueSCSI.git
synced 2025-01-24 02:30:16 +00:00
Try clock speeds from 50 -> 32mhz for SD communication
Helps compatibility with SD and different STM32 chips. Add warning if under 40mhz - testing showed 40-50mhz gave almost no change in speed Thanks @marcelv-3 via https://github.com/erichelgeson/BlueSCSI/discussions/58
This commit is contained in:
parent
32219ce18b
commit
551faf72b2
@ -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_ready) {
|
||||||
if(!SD.begin(SD1_CONFIG)) {
|
|
||||||
#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!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user