Browse Source

fix: fix incorrect DP port and PIN set for F103 driver
fix: fix incorrect memory sizes for F103x6 linker script
docs: add doxygen doc for USBD_DP_PORT and UDBD_DP_PIN

Dmitry 8 năm trước cách đây
mục cha
commit
0f17773c80
3 tập tin đã thay đổi với 28 bổ sung6 xóa
  1. 2 2
      demo/stm32f103x6.ld
  2. 2 0
      inc/usbd_core.h
  3. 24 4
      src/usb_32v3.c

+ 2 - 2
demo/stm32f103x6.ld

@@ -1,8 +1,8 @@
 ENTRY(Reset_Handler)
 MEMORY
 {
-    ROM  (rx): ORIGIN = 0x08000000, LENGTH =  64K
-    RAM (rwx): ORIGIN = 0x20000000, LENGTH =  20K
+    ROM  (rx): ORIGIN = 0x08000000, LENGTH =  32K
+    RAM (rwx): ORIGIN = 0x20000000, LENGTH =  10K
 }
 SECTIONS
 {

+ 2 - 0
inc/usbd_core.h

@@ -26,6 +26,8 @@
  * @{ */
 #define USBD_SOF_DISABLED   /**<\brief Disables SOF handling.*/
 #define USBD_VBUS_DETECT    /**<\brief Enables Vbus detection for V2 driver.*/
+#define USBD_DP_PORT        /**<\brief DP pullup port for F103/F303 driver.*/
+#define USBD_DP_PIN         /**<\brief DP pullup pin for F103/F303 driver.*/
 /** @} */
 #endif
 

+ 24 - 4
src/usb_32v3.c

@@ -170,13 +170,33 @@ void reset (void) {
 }
 
 uint8_t connect(bool connect) {
-#if defined(USBD_DP_PORT) && defined(USBD_DP_PIN)
-    uint32_t _t = USBD_DP_PORT->MODER & ~(0x03 << (2 * USBD_DP_PIN))
+#if defined(USBD_DP_PORT) && defined(USBD_DP_PIN) && defined(STM32F3)
+    uint32_t _t = USBD_DP_PORT->MODER & ~(0x03 << (2 * USBD_DP_PIN));
     if (connect) {
-        _t |= (0x01 << (2 * USBD_DP_PIN))
-        USBD_DP_PORT->BSRR = (0x0001 << USBD_DP_PIN)
+        _t |= (0x01 << (2 * USBD_DP_PIN));
+        USBD_DP_PORT->BSRR = (0x0001 << USBD_DP_PIN);
     }
     USBD_DP_PORT->MODER = _t;
+#elif defined(USBD_DP_PORT) && defined(USBD_DP_PIN) && defined(STM32F1)
+#if (USBD_DP_PIN < 8)
+    uint32_t _t = USBD_DP_PORT->CRL & ~(0x0F << (4 * USBD_DP_PIN));
+    if (connect) {
+        _t |= (0x02 << (4 * USBD_DP_PIN));
+        USBD_DP_PORT->BSRR = (0x0001 << USBD_DP_PIN);
+    } else {
+        _t |= (0x04 << (4 * USBD_DP_PIN));
+    }
+    USBD_DP_PORT->CRL = _t;
+#else
+    uint32_t _t = USBD_DP_PORT->CRH & ~(0x0F << (4 * (USBD_DP_PIN - 8)));
+    if (connect) {
+        _t |= (0x02 << (4 * (USBD_DP_PIN - 8)));
+        USBD_DP_PORT->BSRR = (0x0001 << USBD_DP_PIN);
+    } else {
+       _t |= (0x04 << (4 * (USBD_DP_PIN - 8)));
+    }
+    USBD_DP_PORT->CRH = _t;
+#endif
 #endif
     return usbd_lane_unk;
 }