Fixes for 2021 board
authorMichael McMaster <michael@codesrc.com>
Sat, 6 Feb 2021 10:19:59 +0000 (20:19 +1000)
committerMichael McMaster <michael@codesrc.com>
Sat, 6 Feb 2021 10:30:55 +0000 (20:30 +1000)
13 files changed:
Makefile.2020c
Makefile.2021
src/firmware/config.c
src/firmware/hwversion.c
src/firmware/main.c
src/firmware/usb_device/usb_device.c
src/firmware/usb_device/usb_device.h
src/firmware/usb_device/usbd_composite.c
src/firmware/usb_device/usbd_composite.h
src/firmware/usb_device/usbd_desc.h
src/firmware/usb_device/usbd_hid.c
src/firmware/usb_device/usbd_hid.h
src/firmware/usb_device/usbd_msc.h

index 33a3f4fdcbd37fedc68838add2ad8d8cc4dd07f3..bbc1f9f1aa5aafff4da825fb3ca8f225282d2a8e 100644 (file)
@@ -2,7 +2,7 @@
 ARMCC=arm-none-eabi-gcc
 OBJCOPY=arm-none-eabi-objcopy
 
-CPPFLAGS=-DSTM32F205xx -DSTM32F2xx -DUSE_HAL_DRIVER -Wall 
+CPPFLAGS=-DSTM32F205xx -DSTM32F2xx -DUSE_HAL_DRIVER -Wall -DS2S_USB_FS
 CFLAGS=-mcpu=cortex-m3 -mthumb -mslow-flash-data \
        -std=gnu11 \
        -specs=nosys.specs \
index 5894e9738bbff6709dc6f512f28eb25e286c2bee..d8d6860fdbf1585727dc7b9d04ba56f7dd09463e 100644 (file)
@@ -2,7 +2,8 @@
 ARMCC=arm-none-eabi-gcc
 OBJCOPY=arm-none-eabi-objcopy
 
-CPPFLAGS=-DSTM32F446xx -DSTM32F4xx -DUSE_HAL_DRIVER -Wall 
+#CPPFLAGS=-DSTM32F446xx -DSTM32F4xx -DUSE_HAL_DRIVER -Wall -DS2S_USB_HS
+CPPFLAGS=-DSTM32F446xx -DSTM32F4xx -DUSE_HAL_DRIVER -Wall -DS2S_USB_FS
 CFLAGS=-mcpu=cortex-m4 -mthumb -mslow-flash-data \
        -std=gnu11 \
        -specs=nosys.specs \
index 7c26d94ae02b61c608e2985d6fba053aa3b343dc..1803aa107753a05d0f32a81da31a7afa486a1247 100755 (executable)
@@ -41,6 +41,12 @@ static const uint16_t FIRMWARE_VERSION = 0x0632;
 // Optional static config\r
 extern uint8_t* __fixed_config;\r
 \r
+#ifdef S2S_USB_HS\r
+#define configUsbDev hUsbDeviceHS\r
+#else\r
+#define configUsbDev configUsbDev\r
+#endif\r
+\r
 // 1 flash row\r
 static const uint8_t DEFAULT_CONFIG[128] =\r
 {\r
@@ -322,19 +328,19 @@ void s2s_configPoll()
 {\r
        s2s_spin_lock(&usbDevLock);\r
 \r
-       if (!USBD_Composite_IsConfigured(&hUsbDeviceFS))\r
+       if (!USBD_Composite_IsConfigured(&configUsbDev))\r
        {\r
                usbInEpState = USB_IDLE;\r
                goto out;\r
        }\r
 \r
-       if (USBD_HID_IsReportReady(&hUsbDeviceFS))\r
+       if (USBD_HID_IsReportReady(&configUsbDev))\r
        {\r
                s2s_ledOn();\r
 \r
                // The host sent us some data!\r
                uint8_t hidBuffer[USBHID_LEN];\r
-               int byteCount = USBD_HID_GetReport(&hUsbDeviceFS, hidBuffer, sizeof(hidBuffer));\r
+               int byteCount = USBD_HID_GetReport(&configUsbDev, hidBuffer, sizeof(hidBuffer));\r
                hidPacket_recv(hidBuffer, byteCount);\r
 \r
                size_t cmdSize;\r
@@ -356,14 +362,14 @@ void s2s_configPoll()
 \r
                        if (nextChunk)\r
                        {\r
-                               USBD_HID_SendReport (&hUsbDeviceFS, nextChunk, sizeof(hidBuffer));\r
+                               USBD_HID_SendReport (&configUsbDev, nextChunk, sizeof(hidBuffer));\r
                                usbInEpState = USB_DATA_SENT;\r
                        }\r
                }\r
                break;\r
 \r
        case USB_DATA_SENT:\r
-               if (!USBD_HID_IsBusy(&hUsbDeviceFS))\r
+               if (!USBD_HID_IsBusy(&configUsbDev))\r
                {\r
                        // Data accepted.\r
                        usbInEpState = USB_IDLE;\r
@@ -377,16 +383,16 @@ out:
 \r
 void s2s_debugTimer()\r
 {\r
-       if (!USBD_Composite_IsConfigured(&hUsbDeviceFS))\r
+       if (!USBD_Composite_IsConfigured(&configUsbDev))\r
        {\r
                usbInEpState = USB_IDLE;\r
                return;\r
        }\r
 \r
-       if (USBD_HID_IsReportReady(&hUsbDeviceFS))\r
+       if (USBD_HID_IsReportReady(&configUsbDev))\r
        {\r
                uint8_t hidBuffer[USBHID_LEN];\r
-               int byteCount = USBD_HID_GetReport(&hUsbDeviceFS, hidBuffer, sizeof(hidBuffer));\r
+               int byteCount = USBD_HID_GetReport(&configUsbDev, hidBuffer, sizeof(hidBuffer));\r
                hidPacket_recv(hidBuffer, byteCount);\r
 \r
                size_t cmdSize;\r
@@ -416,14 +422,14 @@ void s2s_debugTimer()
 \r
                        if (nextChunk)\r
                        {\r
-                               USBD_HID_SendReport (&hUsbDeviceFS, nextChunk, sizeof(hidBuffer));\r
+                               USBD_HID_SendReport (&configUsbDev, nextChunk, sizeof(hidBuffer));\r
                                usbInEpState = USB_DATA_SENT;\r
                        }\r
                }\r
                break;\r
 \r
                case USB_DATA_SENT:\r
-                       if (!USBD_HID_IsBusy(&hUsbDeviceFS))\r
+                       if (!USBD_HID_IsBusy(&configUsbDev))\r
                        {\r
                                // Data accepted.\r
                                usbInEpState = USB_IDLE;\r
index 7f55b2e5433d859df992b3f44584769c941adcf5..d88a0c9bb67ea3fb30f013d72998c4fb986f68c1 100755 (executable)
@@ -66,6 +66,7 @@ checkHwSensePins()
 void
 s2s_checkHwVersion()
 {
+return; // TODO FIX FOR 2021
        checkHwSensePins();
 
        // Write a marker to flash that can be read by dfu-util now that we know
index 8e194da2e87e48c6f6fec871d44f21c3d766ca4a..a254b065c6fd22274fcc61542ed8011940dc059f 100755 (executable)
@@ -54,8 +54,14 @@ void mainInit()
        s2s_timeInit();\r
        s2s_checkHwVersion();\r
 \r
-       // DISable the ULPI chip\r
-       HAL_GPIO_WritePin(nULPI_RESET_GPIO_Port, nULPI_RESET_Pin, GPIO_PIN_RESET);\r
+       #ifdef S2S_USB_HS\r
+               // Enable the ULPI chip\r
+               HAL_GPIO_WritePin(nULPI_RESET_GPIO_Port, nULPI_RESET_Pin, GPIO_PIN_SET);\r
+               s2s_delay_ms(5);\r
+       #else\r
+               // DISable the ULPI chip\r
+               HAL_GPIO_WritePin(nULPI_RESET_GPIO_Port, nULPI_RESET_Pin, GPIO_PIN_RESET);\r
+       #endif\r
 \r
        s2s_ledInit();\r
        s2s_fpgaInit();\r
@@ -95,7 +101,13 @@ void mainLoop()
        scsiPoll();\r
        scsiDiskPoll();\r
        s2s_configPoll();\r
-       s2s_usbDevicePoll();\r
+\r
+#ifdef S2S_USB_FS\r
+       s2s_usbDevicePoll(&hUsbDeviceFS);\r
+#endif\r
+#ifdef S2S_USB_FS\r
+       s2s_usbDevicePoll(&hUsbDeviceHS);\r
+#endif\r
 \r
 #if 0\r
        sdPoll();\r
index 9aecb09b316672a6b53d5607d877e388b9eab69e..189fbef31828dfc078a77c3b2eda33687ac924bd 100755 (executable)
 #include "usbd_desc.h"
 #include "usbd_composite.h"
 
+//#include "usbd_hidt.h"
+
 /* USB Device Core handle declaration */
 USBD_HandleTypeDef hUsbDeviceFS;
+USBD_HandleTypeDef hUsbDeviceHS;
 
-/* init function */                                    
 void MX_USB_DEVICE_Init(void)
 {
-  /* Init Device Library,Add Supported Class and Start the library*/
-  USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
+#if S2S_USB_FS
+       USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
+       USBD_RegisterClass(&hUsbDeviceFS, &USBD_Composite);
+       USBD_Start(&hUsbDeviceFS);
+#endif
+#if S2S_USB_HS
+       USBD_Init(&hUsbDeviceHS, &FS_Desc, DEVICE_HS);
+       USBD_RegisterClass(&hUsbDeviceHS, &USBD_Composite);
 
-  USBD_RegisterClass(&hUsbDeviceFS, &USBD_Composite);
+USB_OTG_GlobalTypeDef* USBx  = USB_OTG_HS;
+USBx_DEVICE->DCFG |= 0x4000; // BIT 14
 
-  USBD_Start(&hUsbDeviceFS);
+       USBD_Start(&hUsbDeviceHS);
 
+#endif
 }
 /**
   * @}
index 0c096087696ce9ed5684ba3a8318491c3054fd8b..5da3ecef2076076dfa509ee2ad6f36410588a70d 100755 (executable)
@@ -49,6 +49,7 @@
 #include "usbd_def.h"
 
 extern USBD_HandleTypeDef hUsbDeviceFS;
+extern USBD_HandleTypeDef hUsbDeviceHS;
 
 /* USB_Device init function */ 
 void MX_USB_DEVICE_Init(void);
index 50dca00e82070c5aad294ec296329eacb4628201..2cf9f2ee00cd34791e8407156e16cd46a5f81fa6 100755 (executable)
@@ -27,6 +27,9 @@
 #include "usbd_ctlreq.h"
 
 
+// Support 2 USB devices.
+__ALIGN_BEGIN static USBD_CompositeClassData fsClassData __ALIGN_END;
+__ALIGN_BEGIN static USBD_CompositeClassData hsClassData __ALIGN_END;
 
 static uint8_t  USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx);
 
@@ -179,11 +182,20 @@ static uint8_t  USBD_Composite_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
        USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
 
 
-       // Use static memory. This limits us to a single HID and MSC devicd
-       static USBD_CompositeClassData classData;
-       classData.hid.state = HID_IDLE;
-       classData.hid.reportReady = 0;
-       pdev->pClassData = &classData;
+       USBD_CompositeClassData* classData;
+       if (pdev->id == DEVICE_HS)
+       {
+               classData = &hsClassData;
+       }
+       else
+       {
+               classData = &fsClassData;
+       }
+       classData->hid.state = HID_IDLE;
+       classData->hid.reportReady = 0;
+       classData->DataInReady = 0;
+       classData->DataOutReady = 0;
+       pdev->pClassData = classData;
 
        MSC_BOT_Init(pdev);
 
@@ -191,8 +203,8 @@ static uint8_t  USBD_Composite_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
        USBD_LL_PrepareReceive(
                pdev,
                HID_EPOUT_ADDR,
-               classData.hid.rxBuffer,
-               sizeof(classData.hid.rxBuffer));
+               classData->hid.rxBuffer,
+               sizeof(classData->hid.rxBuffer));
 
        return ret;
 }
@@ -350,15 +362,11 @@ static uint8_t USBD_Composite_Setup(
 }
 
 
-int FIXME_IN = 0;
-int FIXME_OUT = 0;
-USBD_HandleTypeDef  *pdevtmp;
 static uint8_t USBD_Composite_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
 {
-pdevtmp = pdev;
+       USBD_CompositeClassData *classData = (USBD_CompositeClassData*) pdev->pClassData;
        if (epnum == (HID_EPIN_ADDR & 0x7F))
        {
-               USBD_CompositeClassData *classData = (USBD_CompositeClassData*) pdev->pClassData;
                USBD_HID_HandleTypeDef *hhid = &(classData->hid);
                /* Ensure that the FIFO is empty before a new transfer, this condition could 
                be caused by  a new transfer before the end of the previous transfer */
@@ -366,40 +374,40 @@ pdevtmp = pdev;
        }
        else if (epnum == (MSC_EPIN_ADDR & 0x7F))
        {
-       FIXME_IN = epnum;
-       //      MSC_BOT_DataIn(pdev , epnum);
+               classData->DataInReady = epnum;
        }
        return USBD_OK;
 }
 
 static uint8_t USBD_Composite_DataOut(USBD_HandleTypeDef  *pdev, uint8_t epnum)
 {
-pdevtmp = pdev;
+       USBD_CompositeClassData *classData = (USBD_CompositeClassData*) pdev->pClassData;
        if (epnum == (HID_EPOUT_ADDR & 0x7F))
        {
-               USBD_CompositeClassData *classData = (USBD_CompositeClassData*) pdev->pClassData;
                USBD_HID_HandleTypeDef *hhid = &(classData->hid);
                hhid->reportReady = 1;
        }
        else if (epnum == (MSC_EPOUT_ADDR & 0x7F))
        {
-       FIXME_OUT = epnum;
-               //MSC_BOT_DataOut(pdev, epnum);
+               classData->DataOutReady = epnum;
        }
        return USBD_OK;
 }
 
-void s2s_usbDevicePoll(void) {
-       if (FIXME_IN) {
-               int tmp = FIXME_IN;
-               FIXME_IN = 0;
-               MSC_BOT_DataIn(pdevtmp, tmp);
+void s2s_usbDevicePoll(USBD_HandleTypeDef  *pdev) {
+       USBD_CompositeClassData *classData = (USBD_CompositeClassData*) pdev->pClassData;
+
+       if (classData->DataInReady)
+       {
+               int tmp = classData->DataInReady;
+               classData->DataInReady = 0;
+               MSC_BOT_DataIn(pdev, tmp);
        }
 
-       if (FIXME_OUT) {
-               int tmp = FIXME_OUT;
-               FIXME_OUT = 0;
-               MSC_BOT_DataOut(pdevtmp, tmp);
+       if (classData->DataOutReady) {
+               int tmp = classData->DataOutReady;
+               classData->DataOutReady = 0;
+               MSC_BOT_DataOut(pdev, tmp);
        }
 }
 
index ca279efeb031e5651a875267502238da223a494b..dbb9778d05eeea9b11f06d858ba3c0bcaeb806af 100755 (executable)
@@ -40,12 +40,15 @@ extern USBD_ClassTypeDef  USBD_Composite;
 
 
 typedef struct {
-       USBD_HID_HandleTypeDef hid;
-       USBD_MSC_BOT_HandleTypeDef msc;
+       __ALIGN_BEGIN USBD_HID_HandleTypeDef hid __ALIGN_END;
+       __ALIGN_BEGIN USBD_MSC_BOT_HandleTypeDef msc __ALIGN_END;
+
+       int DataInReady; // Endpoint number, 0 if not ready.
+       int DataOutReady;// Endpoint number, 0 if not ready.
 } USBD_CompositeClassData;
 
 
-void s2s_usbDevicePoll(void);
+void s2s_usbDevicePoll(USBD_HandleTypeDef* pdev);
 
 static inline uint8_t USBD_Composite_IsConfigured(USBD_HandleTypeDef *pdev) {
        return pdev->dev_state == USBD_STATE_CONFIGURED;
index aff7527efc529025693468619b1d6a354f83dd64..de7b0256c0502f83810fe021648533cc2a141ad5 100755 (executable)
@@ -76,6 +76,7 @@
   * @{
   */ 
 extern USBD_DescriptorsTypeDef FS_Desc;
+//extern USBD_DescriptorsTypeDef HS_Desc;
 /**
   * @}
   */ 
index 4371308c1dc2c4f87e98d9d6aed0482ad8973cd1..9044be799f82315788f39c2cba0cff7aa7869794 100755 (executable)
 #include "usbd_desc.h"
 #include "usbd_ctlreq.h"
 
-
-
-int usbdReportReady = 0; // Global to allow poll-based HID report processing
-
-
-
 /* USB HID device Configuration Descriptor */
 __ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ]  __ALIGN_END  =
 {
@@ -116,11 +110,15 @@ uint8_t USBD_HID_SendReport     (USBD_HandleTypeDef  *pdev,
        {
                if(hhid->state == HID_IDLE)
                {
+                       uint16_t safeLen =
+                               len < sizeof(hhid->txBuffer) ? len : sizeof(hhid->txBuffer);
+                       memcpy(hhid->txBuffer, report, safeLen);
+
                        hhid->state = HID_BUSY;
                        USBD_LL_Transmit (pdev,
                                        HID_EPIN_ADDR,
-                                       (uint8_t*)report,
-                                       len);
+                                       (uint8_t*)hhid->txBuffer,
+                                       safeLen);
                }
        }
        return USBD_OK;
@@ -134,9 +132,24 @@ uint8_t USBD_HID_SendReport     (USBD_HandleTypeDef  *pdev,
   */
 uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev)
 {
-       /* Sets the data transfer polling interval for low and full 
-       speed transfers */
-       return HID_FS_BINTERVAL;
+       uint32_t polling_interval = 0;
+
+       /* HIGH-speed endpoints */
+       if(pdev->dev_speed == USBD_SPEED_HIGH)
+       {
+               /* Sets the data transfer polling interval for high speed transfers. 
+               Values between 1..16 are allowed. Values correspond to interval 
+               of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */
+               polling_interval = (((1 <<(HID_HS_BINTERVAL - 1)))/8);
+       }
+       else   /* LOW and FULL-speed endpoints */
+       {
+               /* Sets the data transfer polling interval for low and full 
+               speed transfers */
+               polling_interval =  HID_FS_BINTERVAL;
+       }
+
+       return ((uint32_t)(polling_interval));
 }
 
 uint8_t USBD_HID_GetReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint8_t maxLen)
index 09f1f8fd89ce78696854e89302e1c787fa535a2d..bd0e55f87bece4abd805f6c32c4b62c47a45f207 100755 (executable)
@@ -51,6 +51,7 @@
 #define HID_REPORT_DESC               0x22
 
 #define HID_FS_BINTERVAL               0x20 // 32ms
+#define HID_HS_BINTERVAL               0x20 // 32ms
 
 #define HID_REQ_SET_PROTOCOL          0x0B
 #define HID_REQ_GET_PROTOCOL          0x03
@@ -75,7 +76,8 @@ typedef struct
        uint32_t             IdleState;
        uint32_t             AltSetting;
        HID_StateTypeDef     state;
-       uint8_t              rxBuffer[HID_EPOUT_SIZE];
+       __ALIGN_BEGIN uint8_t rxBuffer[HID_EPOUT_SIZE] __ALIGN_END;
+       __ALIGN_BEGIN uint8_t txBuffer[HID_EPOUT_SIZE] __ALIGN_END;
        int                  reportReady;
 }
 USBD_HID_HandleTypeDef;
index 5f7a93dc688a16645275a18f7830b78db9820377..0c7902d21714baf54f47827e3520fa5ab4e73580 100755 (executable)
@@ -91,9 +91,9 @@ typedef struct
   uint8_t                  bot_state;
   uint8_t                  bot_status;  
   uint16_t                 bot_data_length;
-  uint8_t                  bot_data[S2S_MSC_MEDIA_PACKET];  
-  USBD_MSC_BOT_CBWTypeDef  cbw;
-  USBD_MSC_BOT_CSWTypeDef  csw;
+  __ALIGN_BEGIN uint8_t                  bot_data[S2S_MSC_MEDIA_PACKET] __ALIGN_END;
+  __ALIGN_BEGIN USBD_MSC_BOT_CBWTypeDef  cbw __ALIGN_END;
+  __ALIGN_BEGIN USBD_MSC_BOT_CSWTypeDef  csw __ALIGN_END;
   
   USBD_SCSI_SenseTypeDef   scsi_sense [SENSE_LIST_DEEPTH];
   uint8_t                  scsi_sense_head;