Selaa lähdekoodia

Revised MCU support

Dmitry 9 vuotta sitten
vanhempi
commit
48a67dcda2
4 muutettua tiedostoa jossa 77 lisäystä ja 80 poistoa
  1. 17 28
      inc/usbd_core.h
  2. 12 19
      readme.md
  3. 27 17
      src/memmap.inc
  4. 21 16
      usb.h

+ 17 - 28
inc/usbd_core.h

@@ -52,32 +52,21 @@
 /** @} */
 
 
-#if defined(__ASSEMBLER__)
-    #define usbd_evt_reset      0
-    #define usbd_evt_sof        1
-    #define usbd_evt_susp       2
-    #define usbd_evt_wkup       3
-    #define usbd_evt_eptx       4
-    #define usbd_evt_eprx       5
-    #define usbd_evt_epsetup    6
-    #define usbd_evt_error      7
-    #define usbd_evt_esof       8
-#else
-
-
-/** USB device events */
-enum usbd_evt {
-    usbd_evt_reset,             /**< Reset */
-    usbd_evt_sof,               /**< Start Of Frame */
-    usbd_evt_susp,              /**< Suspend */
-    usbd_evt_wkup,              /**< Wakeup */
-    usbd_evt_eptx,              /**< Transmit completed */
-    usbd_evt_eprx,              /**< Data packet received */
-    usbd_evt_epsetup,           /**< Setup packet received */
-    usbd_evt_error,             /**< Data error */
-    usbd_evt_esof,              /**< Missed SOF */
-    usbd_evt_count, /* this is trick to count qty */
-};
+/** \name USB device events
+ * @{ */
+#define usbd_evt_reset      0   /**< Reset */
+#define usbd_evt_sof        1   /**< Start Of Frame */
+#define usbd_evt_susp       2   /**< Suspend */
+#define usbd_evt_wkup       3   /**< Wakeup */
+#define usbd_evt_eptx       4   /**< Transmit completed */
+#define usbd_evt_eprx       5   /**< Data packet received */
+#define usbd_evt_epsetup    6   /**< Setup packet received */
+#define usbd_evt_error      7   /**< Data error */
+#define usbd_evt_esof       8   /**< Missed SOF */
+#define usbd_evt_count      9   /* this is trick to count qty */
+/** @} */
+
+#if !defined(__ASSEMBLER__)
 
 /** USB device machine state */
 enum usbd_machine_state {
@@ -172,7 +161,7 @@ typedef bool (*usbd_cfg_callback)(usbd_device *dev, uint8_t cfg);
 
 /** @} */
 
-/**\addtogroup USB_HW_API Hardware driver API functions 
+/**\addtogroup USB_HW_API Hardware driver API functions
  * @{ */
 
 /** Enables or disables USB hardware
@@ -394,7 +383,7 @@ inline static void usbd_reg_endpoint(usbd_device *dev, uint8_t ep, usbd_evt_call
  * \param evt device \ref usbd_evt "event" wants to be registered
  * \param cb pointer to user \ref usbd_evt_callback for this event
  */
-inline static void usbd_reg_event(usbd_device *dev, enum usbd_evt evt, usbd_evt_callback callback) {
+inline static void usbd_reg_event(usbd_device *dev, uint8_t evt, usbd_evt_callback callback) {
     dev->events[evt] = callback;
 }
 

+ 12 - 19
readme.md

@@ -2,41 +2,34 @@
 
 + Lightweight and fast
 + Event-driven process workflow
-+ Completely separated USB hardware driver and middleware
++ Completely separated USB hardware driver and usb core
 + Easy to use.
 
 ### Supported hardware ###
 
-| MCU series   | Driver Name | Written on | Endpoints (1) | Internal S/N | Doublebuffered transfer   |
-| ------------ | ----------- | ---------- | ------------- |------------- | ------------------------- |
-| STM32L052    | usb_stmv0a  | GCC ASM    |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-| STM32L052    | usb_stmv0   | C          |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-| STM32L053(3) | usb_stmv0   | C          |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-| STM32F042(3) | usb_stmv0   | C          |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-| STM32F072(3) | usb_stmv0   | C          |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-| STM32L1xx    | usb_stmv1a  | GCC ASM    |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-| STM32L1xx    | usb_stmv1   | C          |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-| STM32L432(3) | usb_stmv0   | C          |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-| STM32L433(3) | usb_stmv0   | C          |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-| STM32L442(3) | usb_stmv0   | C          |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-| STM32L443(3) | usb_stmv0   | C          |             8 | FNV1A 32bit  | ISO, BULK OUT, BULK IN (2)|
-
-
-1. Single physicsl endpoint can be used to implement
+| HW driver  | Written on | Endpoints |                     Features | MCU series |
+|------------|------------|-----------|------------------------------|------------|
+| usb_stmv0  | GCC C      | 8         | Internal S/N, Doublebuffered | STM32L0x2 STM32L0x3 STM32L4x2 STM32L4x3 STM32F0x2 STM32F0x8 |
+| usb_stmv0a | GCC ASM    | 8         | Internal S/N, Doublebuffered | STM32L0x2 STM32L0x3 STM32L4x2 STM32L4x3 STM32F0x2 STM32F0x8 |
+| usb_stmv1  | GCC C      | 8         | Internal S/N, Doublebuffered | STM32L1xx  |
+| usb_stmv1a | GCC ASM    | 8         | Internal S/N, Doublebuffered | STM32L1xx  |
+
+
+1. Single physical endpoint can be used to implement
   + one bi-directional/single-buffer logical endpoint (CONTROL)
   + one mono-directional/double-buffer logical endpoint (BULK OR ISOCHRONOUS)
   + two mono-directional/single-buffer logical endpoints (BULK OR INTERRUPT)
 
 2. At this moment BULK IN endpoint can use both buffers, but it is not **real** doublebuffered.
 
-3. **Not tested**
+3. Tested with STM32L052, STM31L100
 
 ### Implemented definitions for classes ###
 1. USB HID based on [Device Class Definition for Human Interface Devices (HID) Version 1.11](http://www.usb.org/developers/hidpage/HID1_11.pdf)
 2. USB DFU based on [USB Device Firmware Upgrade Specification, Revision 1.1] (http://www.usb.org/developers/docs/devclass_docs/DFU_1.1.pdf)
 3. USB CDC based on [Class definitions for Communication Devices 1.2] (http://www.usb.org/developers/docs/devclass_docs/CDC1.2_WMC1.1_012011.zip)
 
-### Useful Recources ###
+### Useful Resources ###
 1. [USB Implementers Forum official site] (http://www.usb.org/home)
 2. [USB Made Simple] (http://www.usbmadesimple.co.uk/)
 3. [LUFA - the Lightweight USB Framework for AVRs.] (https://github.com/abcminiuser/lufa)

+ 27 - 17
src/memmap.inc

@@ -1,5 +1,29 @@
+/* This file is the part of the LUS32 project
+ *
+ * Copyright ©2016 Dmitry Filimonchuk <dmitrystu[at]gmail[dot]com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if defined(STM32L052xx) || defined(STM32L053xx) || \
+    defined(STM32L062xx) || defined(STM32L063xx) || \
+    defined(STM32L072xx) || defined(STM32L073xx) || \
+    defined(STM32L082xx) || defined(STM32L083xx) || \
+    defined(STM32L432xx) || defined(STM32L433xx) || \
+    defined(STM32L442xx) || defined(STM32L443xx) || \
+    defined(STM32L452xx) || defined(STM32L462xx) || \
+    defined(STM32F042x6) || defined(STM32F048xx) || \
+    defined(STM32F070x6) || defined(STM32F070xB) || \
+    defined(STM32F072xB) || defined(STM32F078xx) \
 
-#if defined(STM32L0)
     #define USB_EPBASE      0x40005C00
     #define USB_REGBASE     0x40005C40
     #define USB_CNTR        0x00
@@ -9,19 +33,11 @@
     #define USB_BTABLE      0x10
     #define USB_BCDR        0x18
     #define USB_PMABASE     0x40006000
-
     #define RCC_BASE        0x40021000
     #define RCC_APB1RSTR    0x28
     #define RCC_APB1ENR     0x38
-
-
     #define UID_BASE        0x1FF80050
 
-
-
-
-
-
 #elif defined(STM32L1)
 /* common definitions for STM31L100xx STM32L151xx STM32L152xx STM32L162xx */
     #define USB_EPBASE      0x40005C00
@@ -32,27 +48,21 @@
     #define USB_DADDR       0x0C
     #define USB_BTABLE      0x10
     #define USB_PMABASE     0x40006000
-
     #define SYSCFG_BASE     0x40010000
     #define SYSCFG_PMC      0x04
-
     #define RCC_BASE        0x40023800
     #define RCC_APB1ENR     0x24
     #define RCC_APB1RSTR    0x18
     #define RCC_APB2ENR     0x20
-
-
     #if defined(STM32L100xB) || defined(STM32L100xBA) || \
         defined(STM32L151xB) || defined(STM32L151xBA)
     /* Cat.1 and Cat.2 devices */
-    #define UID_BASE        0x1FF80050
+        #define UID_BASE        0x1FF80050
     #else
-    #define UID_BASE        0x1FF800D0
+        #define UID_BASE        0x1FF800D0
     #endif
-
 #else
     #error Unsupported MCU
-
 #endif
 
 

+ 21 - 16
usb.h

@@ -20,30 +20,35 @@
     extern "C" {
 #endif
 
-#if defined(STM32L0)
-    #if defined(FORCE_C_DRIVER)
-        #define USE_STMV0_DRIVER
-    #elif defined(FORCE_ASM_DRIVER)
-        #define USE_STMV0A_DRIVER
-    #elif defined(STM32L052xx)
+#if defined(STM32L052xx) || defined(STM32L053xx) || \
+    defined(STM32L062xx) || defined(STM32L063xx) || \
+    defined(STM32L072xx) || defined(STM32L073xx) || \
+    defined(STM32L082xx) || defined(STM32L083xx) || \
+    defined(STM32L432xx) || defined(STM32L433xx) || \
+    defined(STM32L442xx) || defined(STM32L443xx) || \
+    defined(STM32L452xx) || defined(STM32L462xx) || \
+    defined(STM32F042x6) || defined(STM32F048xx) || \
+    defined(STM32F070x6) || defined(STM32F070xB) || \
+    defined(STM32F072xB) || defined(STM32F078xx) \
+
+    #define USE_STMV0_DRIVER
+
+    #if (defined(FORCE_ASM_DRIVER) || defined(STM32L052xx)) && !defined(FORCE_C_DRIVER)
+        #undef USE_STMV0_DRIVER
         #define USE_STMV0A_DRIVER
-    #else
-        #define USE_STMV0_DRIVER
     #endif
+
 #elif defined(STM32L1)
-    #if defined(FORCE_C_DRIVER)
-        #define USE_STMV1_DRIVER
-    #elif defined(FORCE_ASM_DRIVER)
-        #define USE_STMV1A_DRIVER
-    #elif defined(STM32L100xC)
+    #define USE_STMV1_DRIVER
+    #if (defined(FORCE_ASM_DRIVER) || defined(STM32L100xC)) && !defined(FORCE_C_DRIVER)
+        #undef USE_STMV1_DRIVER
         #define USE_STMV1A_DRIVER
-    #else
-        #define USE_STMV1_DRIVER
     #endif
 #else
-    #error "No supported MCU family selected"
+    #error Unsupported STM32 family
 #endif
 
+
 #include "inc/usbd_core.h"
 #if !defined(__ASSEMBLER__)
     #include "inc/usb_std.h"