fixing SD card under ChibiOS3

This commit is contained in:
rusefi 2017-04-02 23:28:05 -04:00
parent b5b7657493
commit 3d206d704c
1 changed files with 7 additions and 12 deletions

View File

@ -328,7 +328,7 @@ static void MMCumount(void) {
f_sync(&FDLogFile); // sync ALL
mmcDisconnect(&MMCD1); // Brings the driver in a state safe for card removal.
mmcStop(&MMCD1); // Disables the MMC peripheral.
f_mount(NULL, 0, 0); // FATFS: Unregister work area prior to discard it
f_mount(NULL, 0, 0); // FATFS: Unregister work area prior to discard it
memset(&FDLogFile, 0, sizeof(FIL)); // clear FDLogFile
fs_ready = false; // status = false
scheduleMsg(&logger, "MMC/SD card removed");
@ -344,12 +344,12 @@ static void MMCmount(void) {
scheduleMsg(&logger, "Error: Already mounted. \"umountsd\" first");
return;
}
if ((MMCD1.state != BLK_STOP) && (MMCD1.state != BLK_ACTIVE)) {
firmwareError(CUSTOM_OBD_MMC_START1, "mmc_state1 %d", MMCD1.state);
return;
if ((MMCD1.state == BLK_STOP) || (MMCD1.state == BLK_ACTIVE)) {
// looks like we would only get here after manual unmount with mmcStop? Do we really need to ever mmcStop?
// not sure if this code is needed
// start to initialize MMC/SD
mmcStart(&MMCD1, &mmccfg); // Configures and activates the MMC peripheral.
}
// start to initialize MMC/SD
mmcStart(&MMCD1, &mmccfg); // Configures and activates the MMC peripheral.
// Performs the initialization procedure on the inserted card.
lockSpi(SPI_NONE);
@ -383,7 +383,7 @@ static void MMCmount(void) {
unlockSpi();
// if Ok - mount FS now
memset(&MMC_FS, 0, sizeof(FATFS));
if (f_mount(&MMC_FS, 0, 0) == FR_OK) {
if (f_mount(&MMC_FS, "/", 1) == FR_OK) {
sdStatus = SD_STATE_MOUNTED;
incLogFileName();
createLogFile();
@ -434,11 +434,6 @@ void initMmcCard(void) {
// start to initialize MMC/SD
mmcObjectInit(&MMCD1); // Initializes an instance.
if ((MMCD1.state != BLK_STOP) && (MMCD1.state != BLK_ACTIVE)) {
firmwareError(CUSTOM_OBD_MMC_START2, "mmc_state2 %d", MMCD1.state);
return;
}
mmcStart(&MMCD1, &mmccfg);
chThdCreateStatic(mmcThreadStack, sizeof(mmcThreadStack), LOWPRIO, (tfunc_t) MMCmonThread, NULL);