Browse Source

Few bug fixes to wait for SD card to be finished

Michael McMaster 4 years ago
parent
commit
e3ca941eb7

+ 1 - 1
lib/SCSI2SD/src/firmware/config.c

@@ -36,7 +36,7 @@
 
 #include <string.h>
 
-static const uint16_t FIRMWARE_VERSION = 0x0641;
+static const uint16_t FIRMWARE_VERSION = 0x0642;
 
 // Optional static config
 extern uint8_t* __fixed_config;

+ 7 - 1
lib/SCSI2SD/src/firmware/disk.c

@@ -635,7 +635,8 @@ void scsiDiskPoll()
 				(prep - i < buffers) &&
 				(prep < totalSDSectors) &&
 				((totalSDSectors - prep) >= sdPerScsi) &&
-				(likely(!useSlowDataCount) || scsiPhyComplete()))
+				(likely(!useSlowDataCount) || scsiPhyComplete()) &&
+				(HAL_SD_GetState(&hsd) != HAL_SD_STATE_BUSY)) // rx complete but IRQ not fired yet.
 			{
 				// Start an SD transfer if we have space.
 				uint32_t startBuffer = prep % buffers;
@@ -714,6 +715,11 @@ void scsiDiskPoll()
 		}
 		__enable_irq();
 
+		while (HAL_SD_GetState(&hsd) == HAL_SD_STATE_BUSY)
+		{
+			// Wait while keeping BSY.
+		}
+
 		if (scsiDev.phase == DATA_IN)
 		{
 			scsiDev.phase = STATUS;

+ 1 - 1
lib/SCSI2SD/src/firmware/fpga.c

@@ -76,7 +76,7 @@ void s2s_fpgaInit()
 void s2s_fpgaReset()
 {
 	HAL_GPIO_WritePin(FPGA_RST_GPIO_Port, FPGA_RST_Pin, GPIO_PIN_SET);
-	s2s_delay_clocks(4);
+	s2s_delay_clocks(12);
 	HAL_GPIO_WritePin(FPGA_RST_GPIO_Port, FPGA_RST_Pin, GPIO_PIN_RESET);
 }
 

+ 7 - 0
lib/SCSI2SD/src/firmware/scsiPhy.c

@@ -94,6 +94,11 @@ scsiSetDataCount(uint32_t count)
 	*SCSI_DATA_CNT_MID = (count >> 8) & 0xff;
 	*SCSI_DATA_CNT_LO = count & 0xff;
 	*SCSI_DATA_CNT_SET = 1;
+
+#ifdef STM32F4xx
+	__NOP();
+	__NOP();
+#endif
 }
 
 int scsiFifoReady(void)
@@ -106,6 +111,8 @@ int scsiFifoReady(void)
 	__NOP();
 #ifdef STM32F4xx
 	__NOP();
+	__NOP();
+	__NOP();
 #endif
 	return HAL_GPIO_ReadPin(GPIOE, FPGA_GPIO3_Pin) != 0;
 }