Procházet zdrojové kódy

Merge branch 'dev'

Dmitry před 8 roky
rodič
revize
b8b118164b
12 změnil soubory, kde provedl 132 přidání a 102 odebrání
  1. 91 54
      Makefile
  2. 1 1
      demo/cdc_loop.c
  3. 10 17
      inc/usb.h
  4. 4 6
      readme.md
  5. 1 1
      src/usb_32v0.c
  6. 1 1
      src/usb_32v0A.S
  7. 1 1
      src/usb_32v1.c
  8. 1 1
      src/usb_32v1A.S
  9. 1 1
      src/usb_32v2.c
  10. 19 17
      src/usb_32v3.c
  11. 1 1
      src/usb_32v3A.S
  12. 1 1
      src/usbd_core.c

+ 91 - 54
Makefile

@@ -8,43 +8,6 @@ LD           = $(TOOLSET)gcc
 AR           = $(TOOLSET)gcc-ar
 OBJCOPY      = $(TOOLSET)objcopy
 
-STARTUP.stm32l052x8  = $(CMSISDEV)/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l052xx.s
-CFLAGS.stm32l052x8   = -mcpu=cortex-m0plus -mfloat-abi=soft
-DEFINES.stm32l052x8  = STM32L0 STM32L052xx
-LDSCRIPT.stm32l052x8 = demo/stm32l052x8.ld
-
-STARTUP.stm32l100xc  = $(CMSISDEV)/ST/STM32L1xx/Source/Templates/gcc/startup_stm32l100xc.s
-CFLAGS.stm32l100xc   = -mcpu=cortex-m3 -mfloat-abi=soft
-DEFINES.stm32l100xc  = STM32L1 STM32L100xC
-LDSCRIPT.stm32l100xc = demo/stm32l100xc.ld
-
-STARTUP.stm32l476rg  = $(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l476xx.s
-CFLAGS.stm32l476rg   = -mcpu=cortex-m4
-DEFINES.stm32l476rg  = STM32L4 STM32L476xx
-LDSCRIPT.stm32l476rg = demo/stm32l476xg.ld
-
-STARTUP.stm32f103x6  = $(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103x6.s
-CFLAGS.stm32f103x6   = -mcpu=cortex-m3
-DEFINES.stm32f103x6  = STM32F1 STM32F103x6
-LDSCRIPT.stm32f103x6 = demo/stm32f103x6.ld
-
-MCU         ?= stm32l100xc
-LDFLAGS     ?= --specs=nano.specs -nostartfiles -Wl,--gc-sections
-DSRC         = $(wildcard demo/*.c) $(wildcard demo/*.S) $(STARTUP.$(MCU))
-DOBJ         = $(call fixpath, $(addsuffix .o, $(basename $(DSRC))))
-DOUT         = cdc-loop
-LDSCRIPT     = $(call fixpath, $(LDSCRIPT.$(MCU)))
-
-
-MODULE      ?= libusb_stm32.a
-CFLAGS      ?= $(CFLAGS.$(MCU))
-CFLAGS2      = -mthumb -Os -std=gnu99
-DEFINES     ?= $(DEFINES.$(MCU)) FORCE_C_DRIVER
-INCLUDES    ?= $(CMSISDEV)/ST $(CMSISCORE) .
-SOURCES      = $(wildcard src/*.c) $(wildcard src/*.S)
-OBJECTS      = $(addsuffix .o, $(basename $(SOURCES)))
-ARFLAGS     ?= -cvq
-
 ifeq ($(OS),Windows_NT)
 	RM = del /Q
 	fixpath = $(strip $(subst /,\, $1))
@@ -53,6 +16,59 @@ else
 	fixpath = $(strip $1)
 endif
 
+MODULE      ?= libusb.a
+CFLAGS      ?= -mcpu=cortex-m3
+DEFINES     ?= STM32F1 STM32F103x6
+
+ARFLAGS      = -cvq
+LDFLAGS      = --specs=nano.specs -nostartfiles -Wl,--gc-sections
+INCLUDES     = $(CMSISDEV)/ST $(CMSISCORE) inc
+CFLAGS2      = -mthumb -Os -std=gnu99
+
+OBJDIR       = obj
+SOURCES      = $(wildcard src/*.c) $(wildcard src/*.S)
+OBJECTS      = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(SOURCES)))))
+DSRC         = $(wildcard demo/*.c) $(wildcard demo/*.S) $(STARTUP)
+DOBJ         = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(DSRC)))))
+DOUT         = cdc_loop
+
+SRCPATH      = $(sort $(dir $(SOURCES) $(DSRC)))
+vpath %.c $(SRCPATH)
+vpath %.S $(SRCPATH)
+vpath %.s $(SRCPATH)
+
+
+help all:
+	@echo 'Usage: make target [program]'
+	@echo 'Available targets are:'
+	@echo '  bluepill'
+	@echo '  stm32f103x6   CDC loopback demo for STM32F103 based boards'
+	@echo '  32l100c-disco'
+	@echo '  stm32l100xc   CDC loopback demo for STM32L100xC based boards'
+	@echo '  32l476rg-nucleo'
+	@echo '  stm32l476rg   CDC loopback demo for STM32L476xG based boards'
+	@echo '  stm32l052x8   CDC loopback demo for STM32L052x8 based boards'
+	@echo '  doc           DOXYGEN documentation'
+	@echo '  module        static library module using following envars (defaults)'
+	@echo '                MODULE  module name (libusb.a)'
+	@echo '                CFLAGS  mcu specified compiler flags (-mcpu=cortex-m3)'
+	@echo '                DEFINES mcu and module specified defines (STM32F1 STM32F103x6)'
+	@echo '                        see USB Device HW driver and core API section for the'
+	@echo '                        compile-time control macros'
+	@echo ' '
+	@echo 'Environmental variables (defaults):'
+	@echo '  CMSIS         Path to the CMSIS V4 or CMSIS V5 root folder ($(CMSIS))'
+	@echo '  CMSISCORE     Path to the CMSIS Core include folder(s) ($(CMSISCORE))'
+	@echo '  CMSISDEV      Path to the CMSIS Device folder ($(CMSISDEV))'
+	@echo '  FLASH         st-link flash utility ($(FLASH))'
+	@echo ' '
+	@echo 'Examples:'
+	@echo '  make bluepill program'
+	@echo '  make module MODULE="usbd.a" CFLAGS="-mcpu=cotrex-m4" DEFINES="STM32L4 STM32L476xx USBD_VBUS_DETECT"'
+
+$(OBJDIR):
+	@mkdir $@
+
 program: $(DOUT).hex
 	$(FLASH) --reset --format ihex write $(DOUT).hex
 
@@ -62,35 +78,56 @@ $(DOUT).hex : $(DOUT).elf
 	@echo building $@
 	@$(OBJCOPY) -O ihex $< $@
 
-$(DOUT).elf : $(DOBJ) $(OBJECTS)
-	@echo building $@ for $(MCU)
-	@$(LD) $(CFLAGS) $(CFLAGS2) $(LDFLAGS) -Wl,--script='$(LDSCRIPT)' -Wl,-Map=$(DOUT).map $(DOBJ) -lc $(OBJECTS) -o $@
+$(DOUT).elf : $(OBJDIR) $(DOBJ) $(OBJECTS)
+	@echo building $@
+	@$(LD) $(CFLAGS) $(CFLAGS2) $(LDFLAGS) -Wl,--script='$(LDSCRIPT)' -Wl,-Map=$(DOUT).map $(DOBJ) $(OBJECTS) -o $@
 
 clean:
-	$(RM) $(DOUT).* $(OBJECTS)
+	@$(RM) $(DOUT).*
+	@$(RM) $(call fixpath, $(OBJDIR)/*.*)
 
 doc:
 	doxygen
 
-module: $(MODULE)
+module: clean $(MODULE)
 
-
-$(MODULE): $(OBJECTS)
+$(MODULE): $(OBJDIR) $(OBJECTS)
 	@$(AR) $(ARFLAGS) $(MODULE) $(OBJECTS)
 
-%.o: %.c
-	@echo compiling $@
+$(OBJDIR)/%.o: %.c
+	@echo compiling $<
 	@$(CC) $(CFLAGS) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
 
-%.o: %.S
-	@echo assembling $@
+$(OBJDIR)/%.o: %.S
+	@echo assembling $<
 	@$(CC) $(CFLAGS) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
 
-%.o: %.s
-	@echo assembling $@
+$(OBJDIR)/%.o: %.s
+	@echo assembling $<
 	@$(CC) $(CFLAGS) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
 
-
-.INTERMEDIATE: $(OBJECTS) $(DOBJ)
-
-.PHONY: module doc demo clean program
+.PHONY: module doc demo clean program help all
+
+stm32f103x6 bluepill:
+	@$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103x6.s' \
+						LDSCRIPT='demo/stm32f103x6.ld' \
+						DEFINES='STM32F1 STM32F103x6 USBD_SOF_DISABLED USBD_ASM_DRIVER' \
+						CFLAGS='-mcpu=cortex-m3 -mthumb'
+
+stm32l052x8:
+	@$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l052xx.s' \
+						LDSCRIPT='demo/stm32l052x8.ld' \
+						DEFINES='STM32L0 STM32L052xx USBD_SOF_DISABLED' \
+						CFLAGS='-mcpu=cortex-m0plus -mthumb'
+
+stm32l100xc 32l100c-disco:
+	@$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L1xx/Source/Templates/gcc/startup_stm32l100xc.s' \
+						LDSCRIPT='demo/stm32l100xc.ld' \
+						DEFINES='STM32L1 STM32L100xC USBD_SOF_DISABLED' \
+						CFLAGS='-mcpu=cortex-m3 -mthumb'
+
+stm32l476xg 32l476rg-nucleo:
+	@$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l476xx.s' \
+						LDSCRIPT='demo/stm32l476xg.ld' \
+						DEFINES='STM32L4 STM32L476xx USBD_SOF_DISABLED' \
+						CFLAGS='-mcpu=cortex-m4 -mthumb'

+ 1 - 1
demo/cdc_loop.c

@@ -17,7 +17,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include "usb.h"
-#include "inc/usb_cdc.h"
+#include "usb_cdc.h"
 
 #define CDC_EP0_SIZE    0x08
 #define CDC_RXD_EP      0x01

+ 10 - 17
usb.h → inc/usb.h

@@ -28,47 +28,40 @@
     defined(STM32L452xx) || defined(STM32L462xx) || \
     defined(STM32F042x6) || defined(STM32F048xx) || \
     defined(STM32F070x6) || defined(STM32F070xB) || \
-    defined(STM32F072xB) || defined(STM32F078xx) \
+    defined(STM32F072xB) || defined(STM32F078xx)
 
     #define USE_STMV0_DRIVER
 
-    #if (defined(FORCE_ASM_DRIVER) || defined(STM32L052xx)) && !defined(FORCE_C_DRIVER)
-        #define USE_STMV0A_DRIVER
-    #endif
-
 #elif defined(STM32L1)
     #define USE_STMV1_DRIVER
-    #if (defined(FORCE_ASM_DRIVER) || defined(STM32L100xC)) && !defined(FORCE_C_DRIVER)
-        #define USE_STMV1A_DRIVER
-    #endif
+
 #elif defined(STM32L476xx)
     #define USE_STMV2_DRIVER
+
 #elif defined(STM32F102x6) || defined(STM32F102xB) || \
       defined(STM32F103x6) || defined(STM32F103xB) || \
       defined(STM32F103xE) || defined(STM32F103xG) || \
       defined(STM32F302x8) || defined(STM32F302xC) || defined(STM32F302xE) || \
       defined(STM32F303xC) || defined(STM32F303xE) || \
       defined(STM32F373xC)
-    #define USE_STMV3_DRIVER
-    #if (defined(FORCE_ASM_DRIVER) || defined(STM32F103x6)) && !defined(FORCE_C_DRIVER)
-        #define USE_STMV3A_DRIVER
-    #endif
+
+      #define USE_STMV3_DRIVER
 
 #else
     #error Unsupported STM32 family
 #endif
 
 
-#include "inc/usbd_core.h"
+#include "usbd_core.h"
 #if !defined(__ASSEMBLER__)
-    #include "inc/usb_std.h"
-    #if defined(USE_STMV0A_DRIVER)
+    #include "usb_std.h"
+    #if defined(USE_STMV0_DRIVER) && defined(USBD_ASM_DRIVER)
         extern const struct usbd_driver usb_stmv0a;
         #define usbd_hw usb_stmv0a
     #elif defined(USE_STMV0_DRIVER)
         extern const struct usbd_driver usb_stmv0;
         #define usbd_hw usb_stmv0
-    #elif defined(USE_STMV1A_DRIVER)
+    #elif defined(USE_STMV1_DRIVER) && defined(USBD_ASM_DRIVER)
         extern const struct usbd_driver usb_stmv1a;
         #define usbd_hw usb_stmv1a
     #elif defined(USE_STMV1_DRIVER)
@@ -77,7 +70,7 @@
     #elif defined(USE_STMV2_DRIVER)
         extern const struct usbd_driver usb_stmv2;
         #define usbd_hw usb_stmv2
-    #elif defined(USE_STMV3A_DRIVER)
+    #elif defined(USE_STMV3_DRIVER) && defined(USBD_ASM_DRIVER)
         extern const struct usbd_driver usb_stmv3a;
         #define usbd_hw usb_stmv3a
     #elif defined(USE_STMV3_DRIVER)

+ 4 - 6
readme.md

@@ -44,14 +44,12 @@ make module MODULE=path/module.a DEFINES="mcu spcified defines" CFLAGS="cpu cpec
 ```
 + to build demo
 ```
-make demo MCU=stm32l100xc
-make demo MCU=stm32l052x8
-make demo MCU=stm32l476rg
-make demo MCU=stm32f103x6
+make bluepill program
+make stm32l052x8
 ```
-+ to flash demo using st-flash
++ to get a help
 ```
-make program
+make help
 ```
 
 ### Default values: ###

+ 1 - 1
src/usb_32v0.c

@@ -16,7 +16,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include "stm32.h"
-#include "../usb.h"
+#include "usb.h"
 
 #if defined(USE_STMV0_DRIVER)
 

+ 1 - 1
src/usb_32v0A.S

@@ -17,7 +17,7 @@
     #define __ASSEMBLER__
 #endif
 
-#include "../usb.h"
+#include "usb.h"
 #if defined(USE_STMV0_DRIVER)
 #include "memmap.inc"
 

+ 1 - 1
src/usb_32v1.c

@@ -16,7 +16,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include "stm32.h"
-#include "../usb.h"
+#include "usb.h"
 
 #if defined(USE_STMV1_DRIVER)
 

+ 1 - 1
src/usb_32v1A.S

@@ -17,7 +17,7 @@
     #define __ASSEMBLER__
 #endif
 
-#include "../usb.h"
+#include "usb.h"
 #if defined(USE_STMV1_DRIVER)
 #include "memmap.inc"
 

+ 1 - 1
src/usb_32v2.c

@@ -16,7 +16,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include "stm32.h"
-#include "../usb.h"
+#include "usb.h"
 
 #if defined(USE_STMV2_DRIVER)
 

+ 19 - 17
src/usb_32v3.c

@@ -17,7 +17,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include "stm32.h"
-#include "../usb.h"
+#include "usb.h"
 
 #if defined(USE_STMV3_DRIVER)
 
@@ -148,22 +148,6 @@ bool ep_isstalled(uint8_t ep) {
     }
 }
 
-void enable(bool enable) {
-    if (enable) {
-        RCC->APB1ENR  |= RCC_APB1ENR_USBEN;
-        RCC->APB1RSTR |= RCC_APB1RSTR_USBRST;
-        RCC->APB1RSTR &= ~RCC_APB1RSTR_USBRST;
-        USB->CNTR = USB_CNTR_CTRM | USB_CNTR_RESETM | USB_CNTR_ERRM |
-#if !defined(USBD_SOF_DISABLED)
-        USB_CNTR_SOFM |
-#endif
-        USB_CNTR_SUSPM | USB_CNTR_WKUPM;
-    } else if (RCC->APB1ENR & RCC_APB1ENR_USBEN) {
-        RCC->APB1RSTR |= RCC_APB1RSTR_USBRST;
-        RCC->APB1ENR &= ~RCC_APB1ENR_USBEN;
-    }
-}
-
 void reset (void) {
     USB->CNTR |= USB_CNTR_FRES;
     USB->CNTR &= ~USB_CNTR_FRES;
@@ -201,6 +185,24 @@ uint8_t connect(bool connect) {
     return usbd_lane_unk;
 }
 
+void enable(bool enable) {
+    if (enable) {
+        RCC->APB1ENR  |= RCC_APB1ENR_USBEN;
+        RCC->APB1RSTR |= RCC_APB1RSTR_USBRST;
+        RCC->APB1RSTR &= ~RCC_APB1RSTR_USBRST;
+        USB->CNTR = USB_CNTR_CTRM | USB_CNTR_RESETM | USB_CNTR_ERRM |
+#if !defined(USBD_SOF_DISABLED)
+        USB_CNTR_SOFM |
+#endif
+        USB_CNTR_SUSPM | USB_CNTR_WKUPM;
+    } else if (RCC->APB1ENR & RCC_APB1ENR_USBEN) {
+        RCC->APB1RSTR |= RCC_APB1RSTR_USBRST;
+        RCC->APB1ENR &= ~RCC_APB1ENR_USBEN;
+        /* disconnecting DP if configured */
+        connect(0);
+    }
+}
+
 void setaddr (uint8_t addr) {
     USB->DADDR = USB_DADDR_EF | addr;
 }

+ 1 - 1
src/usb_32v3A.S

@@ -17,7 +17,7 @@
     #define __ASSEMBLER__
 #endif
 
-#include "../usb.h"
+#include "usb.h"
 #if defined(USE_STMV3_DRIVER)
 #include "memmap.inc"
 

+ 1 - 1
src/usbd_core.c

@@ -16,7 +16,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include <string.h>
-#include "../usb.h"
+#include "usb.h"
 
 #define _MIN(a, b) ((a) < (b)) ? (a) : (b)