Explorar o código

Merge pull request #55 from horrordash/master

add USB remap support for MCUs in low pin count packages
Dmitry Filimonchuk %!s(int64=6) %!d(string=hai) anos
pai
achega
20b0b4ce3c
Modificáronse 4 ficheiros con 27 adicións e 0 borrados
  1. 1 0
      inc/usbd_core.h
  2. 8 0
      src/memmap.inc
  3. 4 0
      src/usbd_stm32l052_devfs.c
  4. 14 0
      src/usbd_stm32l052_devfs_asm.S

+ 1 - 0
inc/usbd_core.h

@@ -24,6 +24,7 @@
 #if defined(__DOXYGEN__)
 /**\name Compile-time control macros
  * @{ */
+#define USBD_PINS_REMAP     /**<\brief Remap USB pins for uC with low pin count packages.*/
 #define USBD_SOF_DISABLED   /**<\brief Disables SOF handling.*/
 #define USBD_VBUS_DETECT    /**<\brief Enables Vbus detection for L4/F4 driver.*/
 #define USBD_DP_PORT        /**<\brief DP pullup port for F103/F303 driver.*/

+ 8 - 0
src/memmap.inc

@@ -37,6 +37,7 @@
         defined(STM32F072xB) || defined(STM32F078xx)
         #define RCC_APB1RSTR    0x10
         #define RCC_APB1ENR     0x1C
+        #define RCC_APB2ENR     0x18
         #define UID_BASE        0x1FFFF7AC
     #else
         #define RCC_APB1RSTR    0x28
@@ -44,6 +45,13 @@
         #define UID_BASE        0x1FF80050
     #endif
 
+    #if defined(STM32F042x6) || defined(STM32F048xx) || \
+        defined(STM32F070x6) 
+
+        #define SYSCFG_BASE     0x40010000
+        #define SYSCFG_USBREMAP 4
+    #endif
+
 #elif defined(STM32L432xx) || defined(STM32L433xx) || \
       defined(STM32L442xx) || defined(STM32L443xx) || \
       defined(STM32L452xx) || defined(STM32L462xx)

+ 4 - 0
src/usbd_stm32l052_devfs.c

@@ -148,6 +148,10 @@ void enable(bool enable) {
         RCC->APB1ENR  |=  RCC_APB1ENR_USBEN;
         RCC->APB1RSTR |= RCC_APB1RSTR_USBRST;
         RCC->APB1RSTR &= ~RCC_APB1RSTR_USBRST;
+#if defined(USBD_PINS_REMAP) && (defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6))
+        RCC->APB2ENR  |= RCC_APB2ENR_SYSCFGCOMPEN;
+        SYSCFG->CFGR1 |= SYSCFG_CFGR1_PA11_PA12_RMP;	// remap USB pins for small packages
+#endif
         USB->CNTR = USB_CNTR_CTRM | USB_CNTR_RESETM | USB_CNTR_ERRM |
 #if !defined(USBD_SOF_DISABLED)
         USB_CNTR_SOFM |

+ 14 - 0
src/usbd_stm32l052_devfs_asm.S

@@ -232,6 +232,20 @@ _enable:
     str     r0, [r2, #RCC_APB1RSTR]     //RCC->APB1RSTR |= USBRST
     bics    r0, r3
     str     r0, [r2, #RCC_APB1RSTR]     //RCC->APB1RSTR &= ~USBRST
+
+#if defined(USBD_PINS_REMAP) && (defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6))
+    ldr     r0, [r2, #RCC_APB2ENR]
+    movs    r3, #0x01
+    orrs    r0, r3
+    str     r0, [r2, #RCC_APB2ENR]      //RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN
+
+    ldr     r2, =#SYSCFG_BASE           //SYSCFG->CFGR1
+    ldr     r0, [r2]
+    lsls    r3, #SYSCFG_USBREMAP
+    orrs    r0, r3
+    str     r0, [r2]                    //SYSCFG->CFGR1 |= SYSCFG_CFGR1_PA11_PA12_RMP;	// remap USB pins for small packages
+#endif
+
 #if !defined(USBD_SOF_DISABLED)
     movs    r0, #0xBE                   // CTRM | ERRM | WKUPM | SUSPM | RESETM | SOFM
 #else