Fixed SCSI issues. It should now be stable on all systems. v6.0BETA3
authorMichael McMaster <michael@codesrc.com>
Sat, 16 Jul 2016 11:01:17 +0000 (21:01 +1000)
committerMichael McMaster <michael@codesrc.com>
Sat, 16 Jul 2016 11:01:17 +0000 (21:01 +1000)
19 files changed:
CHANGELOG
Makefile
STM32CubeMX/SCSI2SD-V6/Src/fsmc.c
STM32CubeMX/SCSI2SD-V6/Src/main.c
rtl/fpga_bitmap.o
src/firmware/cdrom.c
src/firmware/config.c
src/firmware/debug.h [deleted file]
src/firmware/disk.c
src/firmware/main.c
src/firmware/mo.c
src/firmware/scsi.c
src/firmware/scsiPhy.c
src/firmware/scsiPhy.h
src/firmware/sd.c
src/firmware/tape.c
src/scsi2sd-util6/Makefile
src/scsi2sd-util6/SCSI2SD_HID.cc
src/scsi2sd-util6/scsi2sd-util.cc

index 03414da6786b2b3f839cdea73375f726d02f8028..1103a755cb7dc5d9840e6d1dd26a1c613ccb343e 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+20160716               6.03 (BETA3)
+       - SCSI bug fixes.
+
 20160616               6.01
        - Improved SD card compatibility
        - Fixed SCSI interfaces on slower SCSI controllers
index fa96308080a41e69d479408277aa273ed9613ad4..61c822633ef0d85ce55a8284eaae0c7189dca9bb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -131,6 +131,7 @@ USBCOMPOSITE_SRC= \
 
 SRC = \
        src/firmware/bootloader.c \
+       src/firmware/cdrom.c \
        src/firmware/config.c \
        src/firmware/disk.c \
        src/firmware/diagnostic.c \
@@ -140,10 +141,12 @@ SRC = \
        src/firmware/inquiry.c \
        src/firmware/led.c \
        src/firmware/main.c \
+       src/firmware/mo.c \
        src/firmware/mode.c \
        src/firmware/scsiPhy.c \
        src/firmware/scsi.c \
        src/firmware/sd.c \
+       src/firmware/tape.c \
        src/firmware/time.c \
        src/firmware/trace.c \
        ${USBCOMPOSITE_SRC}
index 51aa1a4e95ef9068b438337f359c12de03dd69a2..de40c3431b8adef34b99b13023ac1c0198ce5308 100755 (executable)
@@ -66,11 +66,13 @@ void MX_FSMC_Init(void)
   hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
   hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
   /* Timing */
+
 /*
   Timing.AddressSetupTime = 3;
   Timing.AddressHoldTime = 2;
   Timing.DataSetupTime = 5;
 */
+
   Timing.AddressSetupTime = 2;
   Timing.AddressHoldTime = 1;
   Timing.DataSetupTime = 4;
index 0150258c3aab7bf7cdf4d3ec37bbd4e4e17eb810..bf352acef85292b4ba69bb068f3db6c16c6396b5 100755 (executable)
@@ -92,8 +92,8 @@ int main(void)
   MX_SDIO_SD_Init();
   MX_SPI1_Init();
   MX_TIM4_Init();
-  MX_USART3_UART_Init();
-  MX_USB_HOST_Init();
+  // TODO re-enable MX_USART3_UART_Init();
+  // TODO re-enable MX_USB_HOST_Init();
 
   /* USER CODE BEGIN 2 */
   mainInit();
@@ -105,7 +105,7 @@ int main(void)
   while (1)
   {
   /* USER CODE END WHILE */
-    MX_USB_HOST_Process();
+    // TODO re-enable MX_USB_HOST_Process();
 
   /* USER CODE BEGIN 3 */
   mainLoop();
index 16130841bb44c71ff8a517f31a57d295dd13d880..b744be24ba1cd802cb23606f59abffae863d2cac 100644 (file)
Binary files a/rtl/fpga_bitmap.o and b/rtl/fpga_bitmap.o differ
index 1c9305f8034a4670bba304075c0f919a8a02d985..220389a5902e37081cad9301e6bca810b0c81e6d 100755 (executable)
 //
 //     You should have received a copy of the GNU General Public License
 //     along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
-#pragma GCC push_options
-#pragma GCC optimize("-flto")
 
-#include "device.h"
 #include "scsi.h"
 #include "config.h"
 #include "cdrom.h"
 
+#include <string.h>
+
 static const uint8_t SimpleTOC[] =
 {
        0x00, // toc length, MSB
@@ -276,7 +275,7 @@ int scsiCDRomCommand()
 {
        int commandHandled = 1;
 
-       uint8 command = scsiDev.cdb[0];
+       uint8_t command = scsiDev.cdb[0];
        if (command == 0x43)
        {
                // CD-ROM Read TOC
@@ -323,4 +322,3 @@ int scsiCDRomCommand()
        return commandHandled;
 }
 
-#pragma GCC pop_options
index a19087d82df3fe6a21980a8a640a60fd1c843027..528eb0fcc3eba83bf629c1ba36413615956d9786 100755 (executable)
@@ -16,7 +16,6 @@
 //     along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.\r
 \r
 #include "config.h"\r
-#include "debug.h"\r
 #include "led.h"\r
 \r
 #include "scsi.h"\r
@@ -38,7 +37,7 @@
 \r
 #include <string.h>\r
 \r
-static const uint16_t FIRMWARE_VERSION = 0x0601;\r
+static const uint16_t FIRMWARE_VERSION = 0x0603;\r
 \r
 // 1 flash row\r
 static const uint8_t DEFAULT_CONFIG[128] =\r
@@ -176,7 +175,7 @@ debugCommand()
        response[15] = scsiDev.lastSense;\r
        response[16] = scsiDev.phase;\r
        response[17] = scsiStatusBSY();\r
-       response[18] = *SCSI_STS_SELECTED;\r
+       response[18] = scsiStatusSEL();\r
        response[19] = scsiStatusATN();\r
        response[20] = scsiStatusRST();\r
        response[21] = scsiDev.rstCount;\r
@@ -189,6 +188,7 @@ debugCommand()
        response[28] = scsiDev.lastSenseASC;\r
        response[29] = *SCSI_STS_DBX;\r
        response[30] = LastTrace;\r
+       response[31] = scsiStatusACK();\r
        hidPacket_send(response, sizeof(response));\r
 }\r
 \r
@@ -330,116 +330,7 @@ void s2s_configPoll()
 \r
 }\r
 \r
-void debugPoll()\r
-{\r
-#if 0\r
-       if (!usbReady)\r
-       {\r
-               return;\r
-       }\r
-\r
-       if(USBFS_GetEPState(USB_EP_COMMAND) == USBFS_OUT_BUFFER_FULL)\r
-       {\r
-               // The host sent us some data!\r
-               int byteCount = USBFS_GetEPCount(USB_EP_COMMAND);\r
-               USBFS_ReadOutEP(USB_EP_COMMAND, (uint8 *)&hidBuffer, byteCount);\r
-\r
-               if (byteCount >= 1 &&\r
-                       hidBuffer[0] == 0x01)\r
-               {\r
-                       // Reboot command.\r
-                       Bootloadable_1_Load();\r
-               }\r
-\r
-               // Allow the host to send us another command.\r
-               // (assuming we didn't reboot outselves)\r
-               USBFS_EnableOutEP(USB_EP_COMMAND);\r
-       }\r
-\r
-       switch (usbDebugEpState)\r
-       {\r
-       case USB_IDLE:\r
-               memcpy(&hidBuffer, &scsiDev.cdb, 12);\r
-               hidBuffer[12] = scsiDev.msgIn;\r
-               hidBuffer[13] = scsiDev.msgOut;\r
-               hidBuffer[14] = scsiDev.lastStatus;\r
-               hidBuffer[15] = scsiDev.lastSense;\r
-               hidBuffer[16] = scsiDev.phase;\r
-               hidBuffer[17] = SCSI_ReadFilt(SCSI_Filt_BSY);\r
-               hidBuffer[18] = SCSI_ReadFilt(SCSI_Filt_SEL);\r
-               hidBuffer[19] = SCSI_ReadFilt(SCSI_Filt_ATN);\r
-               hidBuffer[20] = SCSI_ReadFilt(SCSI_Filt_RST);\r
-               hidBuffer[21] = scsiDev.rstCount;\r
-               hidBuffer[22] = scsiDev.selCount;\r
-               hidBuffer[23] = scsiDev.msgCount;\r
-               hidBuffer[24] = scsiDev.cmdCount;\r
-               hidBuffer[25] = scsiDev.watchdogTick;\r
-               hidBuffer[26] = blockDev.state;\r
-               hidBuffer[27] = scsiDev.lastSenseASC >> 8;\r
-               hidBuffer[28] = scsiDev.lastSenseASC;\r
-               hidBuffer[29] = scsiReadDBxPins();\r
-               hidBuffer[30] = LastTrace;\r
-\r
-               hidBuffer[58] = sdDev.capacity >> 24;\r
-               hidBuffer[59] = sdDev.capacity >> 16;\r
-               hidBuffer[60] = sdDev.capacity >> 8;\r
-               hidBuffer[61] = sdDev.capacity;\r
-\r
-               hidBuffer[62] = FIRMWARE_VERSION >> 8;\r
-               hidBuffer[63] = FIRMWARE_VERSION;\r
-\r
-               USBFS_LoadInEP(USB_EP_DEBUG, (uint8 *)&hidBuffer, sizeof(hidBuffer));\r
-               usbDebugEpState = USB_DATA_SENT;\r
-               break;\r
-\r
-       case USB_DATA_SENT:\r
-               if (USBFS_bGetEPAckState(USB_EP_DEBUG))\r
-               {\r
-                       // Data accepted.\r
-                       usbDebugEpState = USB_IDLE;\r
-               }\r
-               break;\r
-       }\r
-#endif\r
-}\r
-\r
-#if 0\r
-CY_ISR(debugTimerISR)\r
-{\r
-       Debug_Timer_ReadStatusRegister();\r
-       Debug_Timer_Interrupt_ClearPending();\r
-       uint8 savedIntrStatus = CyEnterCriticalSection();\r
-       debugPoll();\r
-       CyExitCriticalSection(savedIntrStatus);\r
-}\r
-#endif\r
-\r
-void s2s_debugInit()\r
-{\r
-#if 0\r
-       Debug_Timer_Interrupt_StartEx(debugTimerISR);\r
-       Debug_Timer_Start();\r
-#endif\r
-}\r
 \r
-void debugPause()\r
-{\r
-#if 0\r
-       Debug_Timer_Stop();\r
-#endif\r
-}\r
-\r
-void debugResume()\r
-{\r
-#if 0\r
-       Debug_Timer_Start();\r
-#endif\r
-}\r
-\r
-int isDebugEnabled()\r
-{\r
-       return usbReady;\r
-}\r
 \r
 // Public method for storing MODE SELECT results.\r
 void s2s_configSave(int scsiId, uint16_t bytesPerSector)\r
diff --git a/src/firmware/debug.h b/src/firmware/debug.h
deleted file mode 100755 (executable)
index 683c75b..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-//     Copyright (C) 2015 Michael McMaster <michael@codesrc.com>
-//
-//     This file is part of SCSI2SD.
-//
-//     SCSI2SD is free software: you can redistribute it and/or modify
-//     it under the terms of the GNU General Public License as published by
-//     the Free Software Foundation, either version 3 of the License, or
-//     (at your option) any later version.
-//
-//     SCSI2SD is distributed in the hope that it will be useful,
-//     but WITHOUT ANY WARRANTY; without even the implied warranty of
-//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//     GNU General Public License for more details.
-//
-//     You should have received a copy of the GNU General Public License
-//     along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
-#ifndef Debug_H
-#define Debug_H
-
-void debugInit(void);
-void debugPause(void);
-void debugResume(void);
-int isDebugEnabled(void);
-
-#endif
-
index d4c826b76815083319d799ed72ff4ee04f14246c..5a211faada85339b0b959187ade473259ffb10f9 100755 (executable)
@@ -19,7 +19,6 @@
 #include "scsi.h"\r
 #include "scsiPhy.h"\r
 #include "config.h"\r
-#include "debug.h"\r
 #include "disk.h"\r
 #include "sd.h"\r
 #include "time.h"\r
@@ -597,6 +596,15 @@ void scsiDiskPoll()
                                }\r
                                sdActive = 1;\r
                        }\r
+#endif\r
+#if 0\r
+                       uint32_t maxSectors = sizeof(scsiDev.data) / SD_SECTOR_SIZE;\r
+                       uint32_t rem = totalSDSectors - i;\r
+                       uint32_t sectors =\r
+                               rem < maxSectors ? rem : maxSectors;\r
+                       sdTmpRead(&scsiDev.data[0], i + sdLBA, sectors);\r
+                       scsiWrite(&scsiDev.data[0], sectors * SD_SECTOR_SIZE);\r
+                       i += sectors;\r
 #endif\r
                        if ((prep - i < buffers) &&\r
                                (prep < totalSDSectors))\r
@@ -673,8 +681,9 @@ void scsiDiskPoll()
                        // do this in a half-duplex fashion. We need to write as much as\r
                        // possible in each SD card transaction.\r
                        uint32_t maxSectors = sizeof(scsiDev.data) / SD_SECTOR_SIZE;\r
+                       uint32_t rem = totalSDSectors - i;\r
                        uint32_t sectors =\r
-                               totalSDSectors < maxSectors ? totalSDSectors : maxSectors;\r
+                               rem < maxSectors ? rem : maxSectors;\r
                        scsiRead(&scsiDev.data[0], sectors * SD_SECTOR_SIZE);\r
                        sdTmpWrite(&scsiDev.data[0], i + sdLBA, sectors);\r
                        i += sectors;\r
index a2317626cfe783e123c2a2f698aa99e5dba11292..6e4cd3f346ddeb5f65870cb538af67c4892a8839 100755 (executable)
@@ -55,9 +55,6 @@ void mainInit()
        scsiPhyConfig();\r
        scsiInit();\r
 \r
-       s2s_debugInit();\r
-\r
-\r
        MX_USB_DEVICE_Init(); // USB lun config now available.\r
 \r
        // Optional bootup delay\r
index e13acc5db5029cc751d982993d2a7d0762706ec9..a6962781a1ae5da66fb9efab57bfebdfa0ae9d97 100644 (file)
 //
 //     You should have received a copy of the GNU General Public License
 //     along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
-#pragma GCC push_options
-#pragma GCC optimize("-flto")
 
-#include "device.h"
 #include "scsi.h"
 #include "config.h"
 #include "mo.h"
@@ -28,7 +25,7 @@ int scsiMOCommand()
 {
        int commandHandled = 0;
 
-       uint8 command = scsiDev.cdb[0];
+       uint8_t command = scsiDev.cdb[0];
        if ((command == 0x2C) || // ERASE(10)
                (command == 0xAC)) // ERASE(12)
        {
@@ -40,4 +37,3 @@ int scsiMOCommand()
        return commandHandled;
 }
 
-#pragma GCC pop_options
index c4b53a572d9c33249079f65b3baa4f3cbe9063a7..9e144a28465eb0f65321694b6bab472be274d0e2 100755 (executable)
 #include "mode.h"\r
 #include "time.h"\r
 #include "bsp.h"\r
-//#include "cdrom.h"\r
+#include "cdrom.h"\r
 //#include "debug.h"\r
-//#include "tape.h"\r
-//#include "mo.h"\r
+#include "tape.h"\r
+#include "mo.h"\r
 \r
 #include <string.h>\r
 \r
@@ -157,7 +157,6 @@ void process_Status()
        scsiDev.lastSense = scsiDev.target->sense.code;\r
        scsiDev.lastSenseASC = scsiDev.target->sense.asc;\r
 \r
-\r
        // Command Complete occurs AFTER a valid status has been\r
        // sent. then we go bus-free.\r
        enter_MessageIn(message);\r
@@ -263,7 +262,7 @@ static void process_Command()
        control = scsiDev.cdb[scsiDev.cdbLen - 1];\r
 \r
        scsiDev.cmdCount++;\r
-       // TODO const S2S_TargetCfg* cfg = scsiDev.target->cfg;\r
+       const S2S_TargetCfg* cfg = scsiDev.target->cfg;\r
 \r
        if (unlikely(scsiDev.resetFlag))\r
        {\r
@@ -352,7 +351,6 @@ static void process_Command()
        {\r
                enter_Status(CONFLICT);\r
        }\r
-#if 0\r
        // Handle odd device types first that may override basic read and\r
        // write commands. Will fall-through to generic disk handling.\r
        else if (((cfg->deviceType == S2S_CFG_OPTICAL) && scsiCDRomCommand()) ||\r
@@ -361,7 +359,6 @@ static void process_Command()
        {\r
                // Already handled.\r
        }\r
-#endif\r
        else if (scsiDiskCommand())\r
        {\r
                // Already handled.\r
@@ -605,13 +602,9 @@ static void process_SelectionPhase()
                // SCSI1/SASI initiators may not set their own ID.\r
                scsiDev.initiatorId = (selStatus >> 3) & 0x7;\r
 \r
-               // Wait until the end of the selection phase.\r
-               while (likely(!scsiDev.resetFlag))\r
+               while (likely(!scsiDev.resetFlag) && scsiStatusSEL())\r
                {\r
-                       if ((*SCSI_STS_SELECTED & 0x40) == 0)\r
-                       {\r
-                               break;\r
-                       }\r
+                       // Wait until the end of the selection phase.\r
                }\r
 \r
                scsiDev.phase = COMMAND;\r
index 1a8a6aea0585d33580d0a1593cd2e2627e9391be..cb9c2065e1bf4ad4702a436795cc799d9b6dde74 100755 (executable)
@@ -76,21 +76,16 @@ void EXTI4_IRQHandler()
        }\r
 }\r
 \r
-#if 0\r
-uint8_t\r
-scsiReadDBxPins()\r
+static void assertFail()\r
 {\r
-       return\r
-               (SCSI_ReadPin(SCSI_In_DBx_DB7) << 7) |\r
-               (SCSI_ReadPin(SCSI_In_DBx_DB6) << 6) |\r
-               (SCSI_ReadPin(SCSI_In_DBx_DB5) << 5) |\r
-               (SCSI_ReadPin(SCSI_In_DBx_DB4) << 4) |\r
-               (SCSI_ReadPin(SCSI_In_DBx_DB3) << 3) |\r
-               (SCSI_ReadPin(SCSI_In_DBx_DB2) << 2) |\r
-               (SCSI_ReadPin(SCSI_In_DBx_DB1) << 1) |\r
-               SCSI_ReadPin(SCSI_In_DBx_DB0);\r
+       while (1)\r
+       {\r
+               s2s_ledOn();\r
+               s2s_delay_ms(100);\r
+               s2s_ledOff();\r
+               s2s_delay_ms(100);\r
+       }\r
 }\r
-#endif\r
 \r
 static void\r
 startScsiRx(uint32_t count)\r
@@ -103,6 +98,12 @@ startScsiRx(uint32_t count)
 uint8_t\r
 scsiReadByte(void)\r
 {\r
+#if FIFODEBUG\r
+       if (!scsiPhyFifoAltEmpty()) {\r
+               // Force a lock-up.\r
+               assertFail();\r
+       }\r
+#endif\r
        startScsiRx(1);\r
 \r
        trace(trace_spinPhyRxFifo);\r
@@ -111,6 +112,16 @@ scsiReadByte(void)
        uint8_t val = scsiPhyRx();\r
        // TODO scsiDev.parityError = scsiDev.parityError || SCSI_Parity_Error_Read();\r
 \r
+#if FIFODEBUG\r
+       if (!scsiPhyFifoEmpty()) {\r
+               int j = 0;\r
+               uint8_t k __attribute((unused));\r
+               while (!scsiPhyFifoEmpty()) { k = scsiPhyRx(); ++j; }\r
+\r
+               // Force a lock-up.\r
+               assertFail();\r
+       }\r
+#endif\r
        return val;\r
 }\r
 \r
@@ -176,6 +187,13 @@ scsiRead(uint8_t* data, uint32_t count)
                        chunk = chunk & 0xFFFFFFF8;\r
                }\r
 \r
+#if FIFODEBUG\r
+               if (!scsiPhyFifoAltEmpty()) {\r
+                       // Force a lock-up.\r
+                       assertFail();\r
+               }\r
+#endif\r
+\r
                startScsiRx(chunk);\r
                // Wait for the next scsi interrupt (or the 1ms systick)\r
                __WFI();\r
@@ -208,6 +226,14 @@ scsiRead(uint8_t* data, uint32_t count)
                        };\r
                }\r
 \r
+#if FIFODEBUG\r
+               if (!scsiPhyFifoEmpty()) {\r
+                       int j = 0;\r
+                       while (!scsiPhyFifoEmpty()) { scsiPhyRx(); ++j; }\r
+                       // Force a lock-up.\r
+                       assertFail();\r
+               }\r
+#endif\r
                i += chunk;\r
        }\r
 }\r
@@ -215,12 +241,25 @@ scsiRead(uint8_t* data, uint32_t count)
 void\r
 scsiWriteByte(uint8_t value)\r
 {\r
+#if FIFODEBUG\r
+       if (!scsiPhyFifoEmpty()) {\r
+               // Force a lock-up.\r
+               assertFail();\r
+       }\r
+#endif\r
        trace(trace_spinPhyTxFifo);\r
        scsiPhyTx(value);\r
        scsiPhyFifoFlip();\r
 \r
        trace(trace_spinTxComplete);\r
        while (!scsiPhyComplete() && likely(!scsiDev.resetFlag)) {}\r
+\r
+#if FIFODEBUG\r
+       if (!scsiPhyFifoAltEmpty()) {\r
+               // Force a lock-up.\r
+               assertFail();\r
+       }\r
+#endif\r
 }\r
 \r
 static void\r
@@ -277,6 +316,13 @@ scsiWrite(const uint8_t* data, uint32_t count)
                uint32_t chunk = ((count - i) > SCSI_FIFO_DEPTH)\r
                        ? SCSI_FIFO_DEPTH : (count - i);\r
 \r
+#if FIFODEBUG\r
+               if (!scsiPhyFifoEmpty()) {\r
+                       // Force a lock-up.\r
+                       assertFail();\r
+               }\r
+#endif\r
+\r
                if (chunk < 16)\r
                {\r
                        scsiWritePIO(data + i, chunk);\r
@@ -305,6 +351,14 @@ scsiWrite(const uint8_t* data, uint32_t count)
                }\r
 \r
                while (!scsiPhyComplete() && likely(!scsiDev.resetFlag)) {}\r
+\r
+#if FIFODEBUG\r
+               if (!scsiPhyFifoAltEmpty()) {\r
+                       // Force a lock-up.\r
+                       assertFail();\r
+               }\r
+#endif\r
+\r
                scsiPhyFifoFlip();\r
 #if 0\r
 // TODO NEED SCSI IRQs\r
@@ -314,6 +368,13 @@ scsiWrite(const uint8_t* data, uint32_t count)
                i += chunk;\r
        }\r
        while (!scsiPhyComplete() && likely(!scsiDev.resetFlag)) {}\r
+\r
+#if FIFODEBUG\r
+       if (!scsiPhyFifoAltEmpty()) {\r
+               // Force a lock-up.\r
+               assertFail();\r
+       }\r
+#endif\r
 }\r
 \r
 static inline void busSettleDelay(void)\r
@@ -325,22 +386,25 @@ static inline void busSettleDelay(void)
 \r
 void scsiEnterBusFree()\r
 {\r
-       *SCSI_CTRL_PHASE = 0;\r
        *SCSI_CTRL_BSY = 0x00;\r
+       // We now have a Bus Clear Delay of 800ns to release remaining signals.\r
+       *SCSI_CTRL_PHASE = 0;\r
 }\r
 \r
 void scsiEnterPhase(int phase)\r
 {\r
        // ANSI INCITS 362-2002 SPI-3 10.7.1:\r
        // Phase changes are not allowed while REQ or ACK is asserted.\r
-#if 0\r
-       while (likely(!scsiDev.resetFlag) &&\r
-               (SCSI_ReadPin(SCSI_In_REQ) || SCSI_ReadFilt(SCSI_Filt_ACK))\r
-               ) {}\r
-#endif\r
+       while (likely(!scsiDev.resetFlag) && scsiStatusACK()) {}\r
 \r
        int newPhase = phase > 0 ? phase : 0;\r
-       if (newPhase != *SCSI_CTRL_PHASE)\r
+       int oldPhase = *SCSI_CTRL_PHASE;\r
+\r
+       if (!scsiPhyFifoEmpty() || !scsiPhyFifoAltEmpty()) {\r
+               // Force a lock-up.\r
+               assertFail();\r
+       }\r
+       if (newPhase != oldPhase)\r
        {\r
                *SCSI_CTRL_PHASE = newPhase;\r
                busSettleDelay();\r
@@ -349,6 +413,7 @@ void scsiEnterPhase(int phase)
                {\r
                        s2s_delay_us(100);\r
                }\r
+\r
        }\r
 }\r
 \r
@@ -466,13 +531,7 @@ void scsiPhyReset()
                {\r
                        if (scsiDev.data[j] != (uint8_t) j)\r
                        {\r
-                               while (1)\r
-                               {\r
-                                       s2s_ledOn();\r
-                                       s2s_delay_ms(100);\r
-                                       s2s_ledOff();\r
-                                       s2s_delay_ms(100);\r
-                               }\r
+                               assertFail();\r
                        }\r
                }\r
 \r
index 6c72e4151b017fbaccc93a367ae03ad97b8443f7..353f1c06d0a1976515202e9ccb55a3f28f6a4e03 100755 (executable)
@@ -38,6 +38,7 @@
 
 #define scsiPhyFifoFull() ((*SCSI_STS_FIFO & 0x01) == 0x01)
 #define scsiPhyFifoEmpty() ((*SCSI_STS_FIFO & 0x02) == 0x02)
+#define scsiPhyFifoAltEmpty() ((*SCSI_STS_ALTFIFO & 0x02) == 0x02)
 
 #define scsiPhyFifoFlip() \
 {\
@@ -52,6 +53,8 @@
 #define scsiStatusATN() ((*SCSI_STS_SCSI & 0x01) == 0x01)
 #define scsiStatusBSY() ((*SCSI_STS_SCSI & 0x02) == 0x02)
 #define scsiStatusRST() ((*SCSI_STS_SCSI & 0x04) == 0x04)
+#define scsiStatusSEL() ((*SCSI_STS_SCSI & 0x08) == 0x08)
+#define scsiStatusACK() ((*SCSI_STS_SCSI & 0x10) == 0x10)
 
 extern uint8_t scsiPhyFifoSel;
 
index 8f0d50342d3a1b646a2fb15090fbe738ce434e17..80a0c13232f24d484c0ff5086e5c9d48446c71dd 100755 (executable)
@@ -943,7 +943,7 @@ int sdInit()
                sdInitDMA();\r
        }\r
 \r
-       if (scsiDev.phase == BUS_FREE)\r
+       if (firstInit || (scsiDev.phase == BUS_FREE))\r
        {\r
                uint8_t cs = HAL_GPIO_ReadPin(nSD_CD_GPIO_Port, nSD_CD_Pin) ? 0 : 1;\r
                uint8_t wp = HAL_GPIO_ReadPin(nSD_WP_GPIO_Port, nSD_WP_Pin) ? 0 : 1;\r
index 9416a95c8013734ded8ca2285c754a946eae1f44..d108ab6140cd88e8929028163f7b50b49dbfb017 100644 (file)
 //
 //     You should have received a copy of the GNU General Public License
 //     along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
-#pragma GCC push_options
-#pragma GCC optimize("-flto")
 
-#include "device.h"
 #include "scsi.h"
 #include "config.h"
 #include "tape.h"
@@ -30,4 +27,3 @@ int scsiTapeCommand()
        return 0;
 }
 
-#pragma GCC pop_options
index 3cd88aa06be114119952da7387164ad0eba2fcb2..9bc3b7776002ca00ad1b05918cfefa7623915669 100755 (executable)
@@ -1,4 +1,4 @@
-VPATH=../firmware
+VPATH=../firmware dfu-programmer/src
 
 VERSION=6.0
 NAME=scsi2sd-util6
@@ -7,6 +7,15 @@ ifeq ($(USE_SYSTEM), Yes)
 USE_SYSTEM_HIDAPI = Yes
 USE_SYSTEM_ZLIB = Yes
 USE_SYSTEM_WX = Yes
+USE_SYSTEM_LIBUSB = Yes
+endif
+
+ifeq ($(USE_SYSTEM_LIBUSB), Yes)
+CPPFLAGS_LIBUSB=$(shell pkg-config libusb-1.0 --cflags)
+LDFLAGS_LIBUSB=$(shell pkg-config libusb-1.0 --libs)
+else
+CPPFLAGS_LIBUSB=-I libusb-1.0.9/libusb
+LDFLAGS_LIBUSB=-L $(BUILD)/libusb/libusb/.libs -lusb-1.0
 endif
 
 ifeq ($(USE_SYSTEM_HIDAPI), Yes)
@@ -33,11 +42,20 @@ else
 LDFLAGS_WX=$(shell $(BUILD)/wx/wx-config --libs)
 endif
 
-CPPFLAGS = $(CPPFLAGS_HIDAPI) -I. -I ../../include -Ilibzipper-1.0.4 $(CPPFLAGS_ZLIB)
+CPPFLAGS = $(CPPFLAGS_HIDAPI) -I. -I ../../include -Idfu-programmer/src \
+       -Ilibzipper-1.0.4 \
+       $(CPPFLAGS_ZLIB) \
+       $(CPPFLAGS_LIBUSB) \
+       -DHAVE_LIBUSB_1_0 \
+
+
 CFLAGS += -Wall -Wno-pointer-sign -O2 -g
 CXXFLAGS += -Wall -O2 -g -std=c++0x
 
-LDFLAGS += -L$(BUILD)/libzipper/.libs -lzipper $(LDFLAGS_ZLIB) $(LDFLAGS_HIDAPI)
+LDFLAGS += -L$(BUILD)/libzipper/.libs -lzipper \
+       $(LDFLAGS_ZLIB) \
+       $(LDFLAGS_HIDAPI) \
+       $(LDFLAGS_LIBUSB)
 
 
 # wxWidgets 3.0.2 uses broken Webkit headers under OSX Yosemeti
@@ -56,6 +74,7 @@ ifeq ($(TARGET),Win32)
        LIBZIPPER_CONFIG+=--host=i686-w64-mingw32
        EXE=.exe
        WX_CONFIG+=--host=i686-w64-mingw32
+       LIBUSB_CONFIG+=--host=i686-w64-mingw32 --disable-shared
 endif
 ifeq ($(TARGET),Win64)
        VPATH += hidapi/windows
@@ -66,12 +85,13 @@ ifeq ($(TARGET),Win64)
        LIBZIPPER_CONFIG+=--host=x86_64-w64-mingw32
        EXE=.exe
        WX_CONFIG+=--host=x86_64-w64-mingw32
+       LIBUSB_CONFIG+=--host=x86_64-w64-mingw32 --disable-shared
 endif
 ifeq ($(TARGET),Linux)
        VPATH += hidapi/linux
-       CPPFLAGS += -DHAS_LIBUSB
        LDFLAGS += -ludev -lexpat -lusb-1.0
        BUILD := $(PWD)/build/linux
+       LIBUSB_CONFIG+=--disable-shared
 endif
 ifeq ($(TARGET),Darwin)
        # Should match OSX
@@ -80,6 +100,7 @@ ifeq ($(TARGET),Darwin)
        CC=clang -mmacosx-version-min=10.7
        CXX=clang++ -stdlib=libc++ -mmacosx-version-min=10.7
        WX_CONFIG += --with-macosx-version-min=10.7
+       LIBUSB_CONFIG += --with-macosx-version-min=10.7 --disable-shared
        BUILD := $(PWD)/build/mac
 all: $(BUILD)/scsi2sd-util6.dmg
 
@@ -109,11 +130,14 @@ OBJ = \
        $(BUILD)/SCSI2SD_HID.o \
        $(BUILD)/hidpacket.o \
 
+#      $(BUILD)/Dfu.o \
+#      $(BUILD)/dfu.o \
+
+
 EXEOBJ = \
        $(BUILD)/scsi2sd-util6.o \
 
 
-
 ifneq ($(USE_SYSTEM_ZLIB),Yes)
 $(OBJ): $(BUILD)/zlib/buildstamp
 $(EXEOBJ): $(BUILD)/zlib/buildstamp
@@ -128,6 +152,19 @@ $(BUILD)/zlib/buildstamp:
        touch $@
 endif
 
+ifneq ($(USE_SYSTEM_LIBUSB),Yes)
+$(OBJ): $(BUILD)/libusb/buildstamp
+$(EXEOBJ): $(BUILD)/libusb/buildstamp
+$(BUILD)/libusb/buildstamp:
+       mkdir -p $(dir $@)
+       ( \
+               cd $(dir $@) && \
+               $(CURDIR)/libusb-1.0.9/configure $(LIBUSB_CONFIG) && \
+               $(MAKE) \
+       ) && \
+       touch $@
+endif
+
 ifneq ($(USE_SYSTEM_WX),Yes)
 $(OBJ): $(BUILD)/wx/buildstamp
 $(EXEOBJ): $(BUILD)/wx/buildstamp
index f70bfb7adf91fe6947140fea741ed345d22321a7..15c0d854b299ff071d020a6c3ad7ce80b6e23861 100644 (file)
@@ -138,27 +138,9 @@ HID::writeSector(uint32_t sector, const std::vector<uint8_t>& in)
 bool
 HID::readSCSIDebugInfo(std::vector<uint8_t>& buf)
 {
-#if 0
-       buf[0] = 0; // report id
-       hid_set_nonblocking(myDebugHandle, 1);
-       int result =
-               hid_read_timeout(
-                       myDebugHandle,
-                       &buf[0],
-                       HID_PACKET_SIZE,
-                       HID_TIMEOUT_MS);
-       hid_set_nonblocking(myDebugHandle, 0);
-
-       if (result <= 0)
-       {
-               const wchar_t* err = hid_error(myDebugHandle);
-               std::stringstream ss;
-               ss << "USB HID read failure: " << err;
-               throw std::runtime_error(ss.str());
-       }
-       return result > 0;
-#endif
-       return false;
+       std::vector<uint8_t> cmd { S2S_CMD_DEBUG };
+       sendHIDPacket(cmd, buf, 1);
+       return buf.size() > 0;
 }
 
 
index 8f1d23f46d91d9ed080db319dff5b212283c5db9..51b421ade7d3bb1daabca6e40180a7b0e765fd8b 100644 (file)
@@ -41,6 +41,7 @@
 #include "BoardPanel.hh"
 #include "TargetPanel.hh"
 #include "SCSI2SD_HID.hh"
+//#include "Dfu.hh"
 
 #include <algorithm>
 #include <iomanip>
@@ -58,10 +59,6 @@ using std::shared_ptr;
 using std::tr1::shared_ptr;
 #endif
 
-#ifdef HAS_LIBUSB
-#include <libusb-1.0/libusb.h>
-#endif
-
 using namespace SCSI2SD;
 
 class ProgressWrapper
@@ -111,33 +108,6 @@ void ProgressUpdate(unsigned char arrayId, unsigned short rowNum)
 
 namespace
 {
-bool hasDFUdevice() {
-#ifdef HAS_LIBUSB
-       bool found = false;
-
-       libusb_device **list;
-       ssize_t cnt = libusb_get_device_list(NULL, &list);
-       ssize_t i = 0;
-       if (cnt < 0) return false;
-
-       for (i = 0; i < cnt; i++) {
-               libusb_device *device = list[i];
-               libusb_device_descriptor desc;
-               libusb_get_device_descriptor(device, &desc);
-               if (desc.idVendor == 0x0483 && desc.idProduct == 0xdf11) {
-                       found = true;
-                       break;
-               }
-       }
-
-       libusb_free_device_list(list, 1);
-
-       return found;
-#else
-       return false;
-#endif
-}
-
 
 static uint8_t sdCrc7(uint8_t* chr, uint8_t cnt, uint8_t crc)
 {
@@ -285,10 +255,11 @@ public:
                myLogWindow->PassMessages(false); // Prevent messagebox popups
 
                myTimer = new wxTimer(this, ID_Timer);
-               myTimer->Start(16); //ms, suitable for scsi debug logging
+               myTimer->Start(64); //ms, suitable for scsi debug logging
        }
 
 private:
+       //Dfu myDfu;
        wxLogWindow* myLogWindow;
        BoardPanel* myBoardPanel;
        std::vector<TargetPanel*> myTargets;
@@ -532,13 +503,15 @@ private:
                                }
 
 
-                               if (hasDFUdevice())
+/*
+                               if (myDfu.hasDevice())
                                {
                                        mmLogStatus("STM DFU Bootloader found");
                                        progress->Show(0);
                                        doDFUUpdate(filename);
                                        return;
                                }
+*/
                        }
                        catch (std::exception& e)
                        {
@@ -606,7 +579,7 @@ private:
                }
                try
                {
-                       std::vector<uint8_t> info(HID::HID_PACKET_SIZE);
+                       std::vector<uint8_t> info;
                        if (myHID->readSCSIDebugInfo(info))
                        {
                                dumpSCSICommand(info);
@@ -940,9 +913,6 @@ class App : public wxApp
 public:
        virtual bool OnInit()
        {
-#ifdef HAS_LIBUSB
-               libusb_init(NULL);
-#endif
                AppFrame* frame = new AppFrame();
                frame->Show(true);
                SetTopWindow(frame);