mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 18:55:13 +03:00
little fixes in pl2303
This commit is contained in:
parent
3dd520bed2
commit
f11e5e5b4d
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,6 +7,8 @@
|
||||
*.pho
|
||||
*.drl
|
||||
*.pdf
|
||||
*.svg
|
||||
*.xml
|
||||
*/mk/*
|
||||
.hg*
|
||||
.dropbox.attr
|
||||
|
||||
107
F0-nolib/Servo/kicad/Servo_control
Normal file
107
F0-nolib/Servo/kicad/Servo_control
Normal file
@ -0,0 +1,107 @@
|
||||
"Source:","/tmp/kicad/Servo_control.sch"
|
||||
"Date:","óÒ 13 ÍÁÒ 2019 17:09:04"
|
||||
"Tool:","Eeschema (6.0.0-rc1-dev-1613-ga55d9819b)"
|
||||
"Generator:","/usr/local/share/kicad/plugins/bom_csv_grouped_by_value.py"
|
||||
"Component Count:","59"
|
||||
|
||||
"Individual Components:"
|
||||
|
||||
"Item","Qty","Reference(s)","Value","LibPart","Footprint","Datasheet"
|
||||
"","","BZ1","Buzzer","Device:Buzzer","Buzzer_Beeper:Buzzer_12x9.5RM7.6","~"
|
||||
"","","C1","0.1","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C2","0.1","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C3","0.1","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C4","47u","Servo_control-rescue:CP-Chiller_control-rescue","Capacitor_Tantalum_SMD:CP_EIA-3216-18_Kemet-A_Pad1.53x1.40mm_HandSolder",""
|
||||
"","","C5","0.1","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C6","0.1","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C7","22p","Device:C","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C8","0.1","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C9","22p","Device:C","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C10","0.1","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C11","0.1","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C12","0.1","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"","","C13","1u","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","C14","10u","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_1206_3216Metric_Pad1.24x1.80mm_HandSolder",""
|
||||
"","","D1","USB6B1","elements:USB6B1","Package_SOIC:SOIC-8_3.9x4.9mm_P1.27mm",""
|
||||
"","","D2","SP0504BAHT","Power_Protection:SP0504BAHT","Package_TO_SOT_SMD:SOT-23-5","http://www.littelfuse.com/~/media/files/littelfuse/technical%20resources/documents/data%20sheets/sp05xxba.pdf"
|
||||
"","","D3","SMAJ5.0","Device:D","Diode_SMD:D_SMA_Handsoldering",""
|
||||
"","","D4","SMAJ5.0","Device:D","Diode_SMD:D_SMA_Handsoldering",""
|
||||
"","","D5","SS14","Device:D_Schottky","Diode_SMD:D_SMA_Handsoldering",""
|
||||
"","","J1","USB_B_Micro","Servo_control-rescue:USB_B_Micro-Connector_Specialized","Connector_USB:USB_Micro-B_Wuerth-629105150521","~"
|
||||
"","","J2","ADC_in","Connector_Generic:Conn_01x06","Connector_PinHeader_2.54mm:PinHeader_1x06_P2.54mm_Vertical","~"
|
||||
"","","J3","Jumper0","Connector_Generic:Conn_01x02","Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Vertical","~"
|
||||
"","","J4","Jumper1","Connector_Generic:Conn_01x02","Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Vertical","~"
|
||||
"","","J5","Dig_In","Connector_Generic:Conn_01x03","Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_Vertical","~"
|
||||
"","","J6","Ext_LED","Connector_Generic:Conn_01x02","Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Vertical","~"
|
||||
"","","J7","Servo1","Connector_Generic:Conn_01x03","Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_Vertical","~"
|
||||
"","","J8","Servo2","Connector_Generic:Conn_01x03","Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_Vertical","~"
|
||||
"","","J9","Servo3","Connector_Generic:Conn_01x03","Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_Vertical","~"
|
||||
"","","J10","5V","Connector_Generic:Conn_01x02","Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Vertical","~"
|
||||
"","","L1","BMBA 0.1mH","Servo_control-rescue:L-Chiller_control-rescue","Inductor_SMD:L_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","Q1","2N7002","Servo_control-rescue:Q_NMOS_GSD-Chiller_control-rescue","Package_TO_SOT_SMD:SOT-23",""
|
||||
"","","Q2","SI2300","Servo_control-rescue:Q_NMOS_GSD-Chiller_control-rescue","Package_TO_SOT_SMD:SOT-23",""
|
||||
"","","Q3","2N7002","Servo_control-rescue:Q_NMOS_GSD-Chiller_control-rescue","Package_TO_SOT_SMD:SOT-23",""
|
||||
"","","Q4","2N7002","Servo_control-rescue:Q_NMOS_GSD-Chiller_control-rescue","Package_TO_SOT_SMD:SOT-23",""
|
||||
"","","Q5","2N7002","Servo_control-rescue:Q_NMOS_GSD-Chiller_control-rescue","Package_TO_SOT_SMD:SOT-23",""
|
||||
"","","R1","10k","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R2","220","Device:R","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R3","220","Device:R","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R4","220","Device:R","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R5","220","Device:R","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R6","510","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R7","10k","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R8","510","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R9","10k","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R10","1k","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R11","1k","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R12","510","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R13","510","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R14","510","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R15","10k","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R16","10k","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","R17","10k","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"","","SW1","Reset","Servo_control-rescue:SW_Push-Chiller_control-rescue","Button_Switch_SMD:SW_SPST_FSMSM",""
|
||||
"","","SW2","Boot","Servo_control-rescue:SW_Push-Chiller_control-rescue","Button_Switch_SMD:SW_SPST_FSMSM",""
|
||||
"","","U1","LM1117-3.3","Servo_control-rescue:LM1117-3.3-Chiller_control-rescue","Package_TO_SOT_SMD:SOT-223-3_TabPin2",""
|
||||
"","","U2","CH340G","ch34x:CH340G","Package_SOIC:SOIC-16_3.9x9.9mm_P1.27mm",""
|
||||
"","","U3","STM32F030F4Px","Servo_control-rescue:STM32F030F4Px-Chiller_control-rescue","Package_SSOP:TSSOP-20_4.4x6.5mm_P0.65mm",""
|
||||
"","","Y1","12MHz","Device:Crystal","Crystal:Crystal_HC49-U_Vertical",""
|
||||
|
||||
|
||||
|
||||
"Collated Components:"
|
||||
|
||||
"Item","Qty","Reference(s)","Value","LibPart","Footprint","Datasheet"
|
||||
"1","1","BZ1","Buzzer","Device:Buzzer","Buzzer_Beeper:Buzzer_12x9.5RM7.6","~"
|
||||
"2","9","C1, C2, C3, C5, C6, C8, C10, C11, C12","0.1","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"3","1","C4","47u","Servo_control-rescue:CP-Chiller_control-rescue","Capacitor_Tantalum_SMD:CP_EIA-3216-18_Kemet-A_Pad1.53x1.40mm_HandSolder",""
|
||||
"4","2","C7, C9","22p","Device:C","Capacitor_SMD:C_0603_1608Metric_Pad0.84x1.00mm_HandSolder",""
|
||||
"5","1","C13","1u","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"6","1","C14","10u","Servo_control-rescue:C-Chiller_control-rescue","Capacitor_SMD:C_1206_3216Metric_Pad1.24x1.80mm_HandSolder",""
|
||||
"7","1","D1","USB6B1","elements:USB6B1","Package_SOIC:SOIC-8_3.9x4.9mm_P1.27mm",""
|
||||
"8","1","D2","SP0504BAHT","Power_Protection:SP0504BAHT","Package_TO_SOT_SMD:SOT-23-5","http://www.littelfuse.com/~/media/files/littelfuse/technical%20resources/documents/data%20sheets/sp05xxba.pdf"
|
||||
"9","2","D3, D4","SMAJ5.0","Device:D","Diode_SMD:D_SMA_Handsoldering",""
|
||||
"10","1","D5","SS14","Device:D_Schottky","Diode_SMD:D_SMA_Handsoldering",""
|
||||
"11","1","J1","USB_B_Micro","Servo_control-rescue:USB_B_Micro-Connector_Specialized","Connector_USB:USB_Micro-B_Wuerth-629105150521","~"
|
||||
"12","1","J2","ADC_in","Connector_Generic:Conn_01x06","Connector_PinHeader_2.54mm:PinHeader_1x06_P2.54mm_Vertical","~"
|
||||
"13","1","J3","Jumper0","Connector_Generic:Conn_01x02","Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Vertical","~"
|
||||
"14","1","J4","Jumper1","Connector_Generic:Conn_01x02","Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Vertical","~"
|
||||
"15","1","J5","Dig_In","Connector_Generic:Conn_01x03","Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_Vertical","~"
|
||||
"16","1","J6","Ext_LED","Connector_Generic:Conn_01x02","Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Vertical","~"
|
||||
"17","1","J7","Servo1","Connector_Generic:Conn_01x03","Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_Vertical","~"
|
||||
"18","1","J8","Servo2","Connector_Generic:Conn_01x03","Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_Vertical","~"
|
||||
"19","1","J9","Servo3","Connector_Generic:Conn_01x03","Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_Vertical","~"
|
||||
"20","1","J10","5V","Connector_Generic:Conn_01x02","Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Vertical","~"
|
||||
"21","1","L1","BMBA 0.1mH","Servo_control-rescue:L-Chiller_control-rescue","Inductor_SMD:L_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"22","4","Q1, Q3, Q4, Q5","2N7002","Servo_control-rescue:Q_NMOS_GSD-Chiller_control-rescue","Package_TO_SOT_SMD:SOT-23",""
|
||||
"23","1","Q2","SI2300","Servo_control-rescue:Q_NMOS_GSD-Chiller_control-rescue","Package_TO_SOT_SMD:SOT-23",""
|
||||
"24","6","R1, R7, R9, R15, R16, R17","10k","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"25","4","R2, R3, R4, R5","220","Device:R","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"26","5","R6, R8, R12, R13, R14","510","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"27","2","R10, R11","1k","Servo_control-rescue:R-Chiller_control-rescue","Resistor_SMD:R_0805_2012Metric_Pad1.15x1.50mm_HandSolder",""
|
||||
"28","1","SW1","Reset","Servo_control-rescue:SW_Push-Chiller_control-rescue","Button_Switch_SMD:SW_SPST_FSMSM",""
|
||||
"29","1","SW2","Boot","Servo_control-rescue:SW_Push-Chiller_control-rescue","Button_Switch_SMD:SW_SPST_FSMSM",""
|
||||
"30","1","U1","LM1117-3.3","Servo_control-rescue:LM1117-3.3-Chiller_control-rescue","Package_TO_SOT_SMD:SOT-223-3_TabPin2",""
|
||||
"31","1","U2","CH340G","ch34x:CH340G","Package_SOIC:SOIC-16_3.9x9.9mm_P1.27mm",""
|
||||
"32","1","U3","STM32F030F4Px","Servo_control-rescue:STM32F030F4Px-Chiller_control-rescue","Package_SSOP:TSSOP-20_4.4x6.5mm_P0.65mm",""
|
||||
"33","1","Y1","12MHz","Device:Crystal","Crystal:Crystal_HC49-U_Vertical",""
|
||||
@ -442,4 +442,39 @@ X 2 2 200 0 100 L 50 50 0 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# USB_B_Micro-Connector_Specialized
|
||||
#
|
||||
DEF USB_B_Micro-Connector_Specialized J 0 40 Y Y 1 F N
|
||||
F0 "J" -200 450 50 H V L CNN
|
||||
F1 "USB_B_Micro-Connector_Specialized" -200 350 50 H V L CNN
|
||||
F2 "" 150 -50 50 H I C CNN
|
||||
F3 "" 150 -50 50 H I C CNN
|
||||
$FPLIST
|
||||
USB*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
C -150 85 25 0 1 10 F
|
||||
C -25 135 15 0 1 10 F
|
||||
S -200 -300 200 300 0 1 10 f
|
||||
S -5 -300 5 -270 0 1 0 N
|
||||
S 10 50 -20 20 0 1 10 F
|
||||
S 200 -205 170 -195 0 1 0 N
|
||||
S 200 -105 170 -95 0 1 0 N
|
||||
S 200 -5 170 5 0 1 0 N
|
||||
S 200 195 170 205 0 1 0 N
|
||||
P 2 0 1 10 -75 85 25 85 N
|
||||
P 4 0 1 10 -125 85 -100 85 -50 135 -25 135 N
|
||||
P 4 0 1 10 -100 85 -75 85 -50 35 0 35 N
|
||||
P 4 0 1 10 25 110 25 60 75 85 25 110 F
|
||||
P 5 0 1 0 -170 220 -70 220 -80 190 -160 190 -170 220 F
|
||||
P 9 0 1 0 -185 230 -185 220 -175 190 -175 180 -65 180 -65 190 -55 220 -55 230 -185 230 N
|
||||
X VBUS 1 300 200 100 L 50 50 1 1 w
|
||||
X D- 2 300 -100 100 L 50 50 1 1 P
|
||||
X D+ 3 300 0 100 L 50 50 1 1 P
|
||||
X ID 4 300 -200 100 L 50 50 1 1 P
|
||||
X GND 5 0 -400 100 U 50 50 1 1 w
|
||||
X Shield 6 -100 -400 100 U 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
#End Library
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
EESchema Schematic File Version 4
|
||||
LIBS:Servo_control-cache
|
||||
EELAYER 26 0
|
||||
EELAYER 29 0
|
||||
EELAYER END
|
||||
$Descr A4 11693 8268
|
||||
encoding utf-8
|
||||
@ -1429,7 +1429,7 @@ Wire Wire Line
|
||||
Connection ~ 4900 2525
|
||||
Connection ~ 4400 2275
|
||||
$Comp
|
||||
L Connector_Specialized:USB_B_Micro J1
|
||||
L Servo_control-rescue:USB_B_Micro-Connector_Specialized J1
|
||||
U 1 1 5C8BC41C
|
||||
P 850 4650
|
||||
F 0 "J1" H 905 5117 50 0000 C CNN
|
||||
|
||||
BIN
F0-nolib/Servo/kicad/Servo_control_bom.ods
Normal file
BIN
F0-nolib/Servo/kicad/Servo_control_bom.ods
Normal file
Binary file not shown.
@ -30,6 +30,7 @@ CC := $(PREFIX)-gcc
|
||||
LD := $(PREFIX)-gcc
|
||||
AR := $(PREFIX)-ar
|
||||
AS := $(PREFIX)-as
|
||||
SIZE := $(PREFIX)-size
|
||||
OBJCOPY := $(OPREFIX)-objcopy
|
||||
OBJDUMP := $(OPREFIX)-objdump
|
||||
GDB := $(OPREFIX)-gdb
|
||||
@ -85,7 +86,7 @@ LIST := $(OBJDIR)/$(BINARY).list
|
||||
BIN := $(BINARY).bin
|
||||
HEX := $(BINARY).hex
|
||||
|
||||
all: bin list
|
||||
all: bin list size
|
||||
|
||||
elf: $(ELF)
|
||||
bin: $(BIN)
|
||||
@ -106,9 +107,6 @@ $(OBJDIR)/%.o: %.c
|
||||
@echo " CC $<"
|
||||
$(CC) $(CFLAGS) $(DEFS) $(INCLUDE) $(ARCH_FLAGS) -o $@ -c $<
|
||||
|
||||
#$(OBJDIR)/%.d: %.c $(OBJDIR)
|
||||
# $(CC) -MM -MG $< | sed -e 's,^\([^:]*\)\.o[ ]*:,$(@D)/\1.o $(@D)/\1.d:,' >$@
|
||||
|
||||
$(BIN): $(ELF)
|
||||
@echo " OBJCOPY $(BIN)"
|
||||
$(OBJCOPY) -Obinary $(ELF) $(BIN)
|
||||
@ -125,9 +123,12 @@ $(ELF): $(OBJDIR) $(OBJS)
|
||||
@echo " LD $(ELF)"
|
||||
$(LD) $(LDFLAGS) $(ARCH_FLAGS) $(OBJS) $(LDLIBS) -o $(ELF)
|
||||
|
||||
size: $(ELF)
|
||||
$(SIZE) $(ELF)
|
||||
|
||||
clean:
|
||||
@echo " CLEAN"
|
||||
$(RM) $(OBJS) $(DEPS) $(ELF) $(HEX) $(LIST) $(OBJDIR)/*.map
|
||||
$(RM) $(OBJS) $(DEPS) $(ELF) $(HEX) $(LIST) $(OBJDIR)/*.map *.d
|
||||
@rmdir $(OBJDIR) 2>/dev/null || true
|
||||
|
||||
dfuboot: $(BIN)
|
||||
|
||||
@ -32,6 +32,17 @@
|
||||
|
||||
#define FORMUSART(X) CONCAT(USART, X)
|
||||
#define USARTX FORMUSART(USARTNUM)
|
||||
#if USARTNUM == 2
|
||||
#define USARTDMA DMA1_Channel4
|
||||
#define DMAIRQn DMA1_Channel4_5_IRQn
|
||||
#define USARTIRQn USART2_IRQn
|
||||
#elif USARTNUM == 1
|
||||
#define USARTDMA DMA1_Channel2
|
||||
#define DMAIRQn DMA1_Channel2_3_IRQn
|
||||
#define USARTIRQn USART1_IRQn
|
||||
#else
|
||||
#error "Wrong USARTNUM"
|
||||
#endif
|
||||
|
||||
// LEDS: 0 - PC13, 1 - PC14
|
||||
// LED0
|
||||
|
||||
@ -70,7 +70,7 @@ void clstate_handler(uint16_t val){
|
||||
|
||||
int main(void){
|
||||
uint32_t lastT = 0;
|
||||
int L;
|
||||
int L = 0;
|
||||
char *txt;
|
||||
char tmpbuf[129];
|
||||
sysreset();
|
||||
@ -89,7 +89,7 @@ int main(void){
|
||||
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
|
||||
|
||||
USB_setup();
|
||||
//iwdg_setup();
|
||||
iwdg_setup();
|
||||
|
||||
while (1){
|
||||
IWDG->KR = IWDG_REFRESH; // refresh watchdog
|
||||
@ -97,13 +97,6 @@ int main(void){
|
||||
LED_blink(LED0);
|
||||
lastT = Tms;
|
||||
transmit_tbuf(); // non-blocking transmission of data from UART buffer every 0.5s
|
||||
/*uint8_t r = 0;
|
||||
if((r = USB_receive(tmpbuf, 128))){
|
||||
tmpbuf[r] = 0;
|
||||
SEND("Received data over USB:\n");
|
||||
SEND(tmpbuf);
|
||||
newline();
|
||||
}*/
|
||||
}
|
||||
usb_proc();
|
||||
uint8_t r = 0;
|
||||
@ -124,11 +117,15 @@ int main(void){
|
||||
if(!USB_configured()) SEND("dis");
|
||||
SEND("connected\n");
|
||||
break;
|
||||
case 'L':
|
||||
USB_send("Very long test string for USB (it's length is more than 64 bytes\n"
|
||||
"This is another part of the string! Can you see all of this?\n");
|
||||
break;
|
||||
case 'R':
|
||||
SEND("Soft reset\n");
|
||||
NVIC_SystemReset();
|
||||
break;
|
||||
case 'U':
|
||||
case 'S':
|
||||
USB_send("Test string for USB\n");
|
||||
break;
|
||||
case 'W':
|
||||
@ -137,9 +134,10 @@ int main(void){
|
||||
break;
|
||||
default: // help
|
||||
SEND(
|
||||
"'C' - test is USB configured\n"
|
||||
"'C' - test if USB is configured\n"
|
||||
"'L' - send long string over USB\n"
|
||||
"'R' - software reset\n"
|
||||
"'U' - send test string over USB\n"
|
||||
"'S' - send short string over USB\n"
|
||||
"'W' - test watchdog\n"
|
||||
);
|
||||
break;
|
||||
|
||||
Binary file not shown.
@ -60,19 +60,10 @@ void transmit_tbuf(){
|
||||
if(!l) return;
|
||||
txrdy = 0;
|
||||
odatalen[tbufno] = 0;
|
||||
#if USARTNUM == 2
|
||||
DMA1_Channel4->CCR &= ~DMA_CCR_EN;
|
||||
DMA1_Channel4->CMAR = (uint32_t) tbuf[tbufno]; // mem
|
||||
DMA1_Channel4->CNDTR = l;
|
||||
DMA1_Channel4->CCR |= DMA_CCR_EN; // start transmission
|
||||
#elif USARTNUM == 1
|
||||
DMA1_Channel2->CCR &= ~DMA_CCR_EN;
|
||||
DMA1_Channel2->CMAR = (uint32_t) tbuf[tbufno]; // mem
|
||||
DMA1_Channel2->CNDTR = l;
|
||||
DMA1_Channel2->CCR |= DMA_CCR_EN;
|
||||
#else
|
||||
#error "Not implemented"
|
||||
#endif
|
||||
USARTDMA->CCR &= ~DMA_CCR_EN;
|
||||
USARTDMA->CMAR = (uint32_t) tbuf[tbufno]; // mem
|
||||
USARTDMA->CNDTR = l;
|
||||
USARTDMA->CCR |= DMA_CCR_EN;
|
||||
tbufno = !tbufno;
|
||||
}
|
||||
|
||||
@ -103,8 +94,8 @@ void newline(){
|
||||
|
||||
|
||||
void usart_setup(){
|
||||
// Nucleo's USART2 connected to VCP proxy of st-link
|
||||
uint32_t tmout = 16000000;
|
||||
// Nucleo's USART2 connected to VCP proxy of st-link
|
||||
#if USARTNUM == 2
|
||||
// setup pins: PA2 (Tx - AF1), PA15 (Rx - AF1)
|
||||
// AF mode (AF1)
|
||||
@ -112,24 +103,7 @@ void usart_setup(){
|
||||
| (GPIO_MODER_MODER2_AF | GPIO_MODER_MODER15_AF);
|
||||
GPIOA->AFR[0] = (GPIOA->AFR[0] &~GPIO_AFRH_AFRH2) | 1 << (2 * 4); // PA2
|
||||
GPIOA->AFR[1] = (GPIOA->AFR[1] &~GPIO_AFRH_AFRH7) | 1 << (7 * 4); // PA15
|
||||
// DMA: Tx - Ch4
|
||||
DMA1_Channel4->CPAR = (uint32_t) &USART2->TDR; // periph
|
||||
DMA1_Channel4->CCR |= DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE; // 8bit, mem++, mem->per, transcompl irq
|
||||
// Tx CNDTR set @ each transmission due to data size
|
||||
NVIC_SetPriority(DMA1_Channel4_5_IRQn, 3);
|
||||
NVIC_EnableIRQ(DMA1_Channel4_5_IRQn);
|
||||
NVIC_SetPriority(USART2_IRQn, 0);
|
||||
// setup usart2
|
||||
RCC->APB1ENR |= RCC_APB1ENR_USART2EN; // clock
|
||||
// oversampling by16, 115200bps (fck=48mHz)
|
||||
//USART2_BRR = 0x1a1; // 48000000 / 115200
|
||||
USART2->BRR = 480000 / 1152;
|
||||
USART2->CR3 = USART_CR3_DMAT; // enable DMA Tx
|
||||
USART2->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE; // 1start,8data,nstop; enable Rx,Tx,USART
|
||||
while(!(USART2->ISR & USART_ISR_TC)){if(--tmout == 0) break;} // polling idle frame Transmission
|
||||
USART2->ICR |= USART_ICR_TCCF; // clear TC flag
|
||||
USART2->CR1 |= USART_CR1_RXNEIE;
|
||||
NVIC_EnableIRQ(USART2_IRQn);
|
||||
// USART1 of main board
|
||||
#elif USARTNUM == 1
|
||||
// PA9 - Tx, PA10 - Rx (AF1)
|
||||
@ -137,26 +111,26 @@ void usart_setup(){
|
||||
| (GPIO_MODER_MODER9_AF | GPIO_MODER_MODER10_AF);
|
||||
GPIOA->AFR[1] = (GPIOA->AFR[1] & ~(GPIO_AFRH_AFRH1 | GPIO_AFRH_AFRH2)) |
|
||||
1 << (1 * 4) | 1 << (2 * 4); // PA9, PA10
|
||||
// USART1 Tx DMA - Channel2 (default value in SYSCFG_CFGR1)
|
||||
DMA1_Channel2->CPAR = (uint32_t) &USART1->TDR; // periph
|
||||
DMA1_Channel2->CMAR = (uint32_t) tbuf; // mem
|
||||
DMA1_Channel2->CCR |= DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE; // 8bit, mem++, mem->per, transcompl irq
|
||||
// Tx CNDTR set @ each transmission due to data size
|
||||
NVIC_SetPriority(DMA1_Channel2_3_IRQn, 3);
|
||||
NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
|
||||
NVIC_SetPriority(USART1_IRQn, 0);
|
||||
// setup usart1
|
||||
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
|
||||
USART1->BRR = 480000 / 1152;
|
||||
USART1->CR3 = USART_CR3_DMAT; // enable DMA Tx
|
||||
USART1->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE; // 1start,8data,nstop; enable Rx,Tx,USART
|
||||
while(!(USART1->ISR & USART_ISR_TC)){if(--tmout == 0) break;} // polling idle frame Transmission
|
||||
USART1->ICR |= USART_ICR_TCCF; // clear TC flag
|
||||
USART1->CR1 |= USART_CR1_RXNEIE;
|
||||
NVIC_EnableIRQ(USART1_IRQn);
|
||||
#else
|
||||
#error "Not implemented"
|
||||
#error "Wrong USARTNUM"
|
||||
#endif
|
||||
// USARTX Tx DMA
|
||||
USARTDMA->CPAR = (uint32_t) &USARTX->TDR; // periph
|
||||
USARTDMA->CMAR = (uint32_t) tbuf; // mem
|
||||
USARTDMA->CCR |= DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE; // 8bit, mem++, mem->per, transcompl irq
|
||||
// Tx CNDTR set @ each transmission due to data size
|
||||
NVIC_SetPriority(DMAIRQn, 3);
|
||||
NVIC_EnableIRQ(DMAIRQn);
|
||||
NVIC_SetPriority(USARTIRQn, 0);
|
||||
// setup usart1
|
||||
USARTX->BRR = 480000 / 1152;
|
||||
USARTX->CR3 = USART_CR3_DMAT; // enable DMA Tx
|
||||
USARTX->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE; // 1start,8data,nstop; enable Rx,Tx,USART
|
||||
while(!(USARTX->ISR & USART_ISR_TC)){if(--tmout == 0) break;} // polling idle frame Transmission
|
||||
USARTX->ICR |= USART_ICR_TCCF; // clear TC flag
|
||||
USARTX->CR1 |= USART_CR1_RXNEIE;
|
||||
NVIC_EnableIRQ(USARTIRQn);
|
||||
}
|
||||
|
||||
#if USARTNUM == 2
|
||||
@ -165,7 +139,7 @@ void usart2_isr(){
|
||||
#elif USARTNUM == 1
|
||||
void usart1_isr(){
|
||||
#else
|
||||
#error "Not implemented"
|
||||
#error "Wrong USARTNUM"
|
||||
#endif
|
||||
#ifdef CHECK_TMOUT
|
||||
static uint32_t tmout = 0;
|
||||
@ -276,5 +250,5 @@ void dma1_channel2_3_isr(){
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error "Not implemented"
|
||||
#error "Wrong USARTNUM"
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* geany_encoding=koi8-r
|
||||
* usb.c
|
||||
* usb.c - base functions for different USB types
|
||||
*
|
||||
* Copyright 2018 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
|
||||
*
|
||||
@ -48,7 +48,7 @@ static uint16_t EP1_Handler(ep_t ep){
|
||||
}
|
||||
|
||||
// data IN/OUT handler
|
||||
static uint16_t EP2_Handler(ep_t ep){
|
||||
static uint16_t EP23_Handler(ep_t ep){
|
||||
MSG("EP2\n");
|
||||
if(ep.rx_flag){
|
||||
int rd = ep.rx_cnt, rest = IDATASZ - idatalen;
|
||||
@ -98,11 +98,11 @@ void USB_setup(){
|
||||
CRS->CR |= CRS_CR_CEN; // enable freq counter & block CRS->CFGR as read-only
|
||||
RCC->CFGR |= RCC_CFGR_SW;
|
||||
// allow RESET and CTRM interrupts
|
||||
USB -> CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM;
|
||||
USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM;
|
||||
// clear flags
|
||||
USB -> ISTR = 0;
|
||||
USB->ISTR = 0;
|
||||
// and activate pullup
|
||||
USB -> BCDR |= USB_BCDR_DPPU;
|
||||
USB->BCDR |= USB_BCDR_DPPU;
|
||||
NVIC_EnableIRQ(USB_IRQn);
|
||||
}
|
||||
|
||||
@ -111,13 +111,10 @@ void usb_proc(){
|
||||
if(!usbON){ // endpoints not activated
|
||||
MSG("Configured; activate other endpoints\n");
|
||||
// make new BULK endpoint
|
||||
// Buffer have 1024 bytes, but last 256 we use for CAN bus
|
||||
// first free is 64; 768 - CAN data
|
||||
// free: 64 128 192 256 320 384 448 512 576 640 704
|
||||
// (first 64 are control registers, up to 192 - buffer for EP0)
|
||||
EP_Init(1, EP_TYPE_INTERRUPT, 192, 192, EP1_Handler);
|
||||
EP_Init(2, EP_TYPE_BULK, 256, 256, EP2_Handler); // OUT - receive data
|
||||
EP_Init(3, EP_TYPE_BULK, 320, 320, EP2_Handler); // IN - transmit data
|
||||
// Buffer have 1024 bytes, but last 256 we use for CAN bus (30.2 of RM: USB main features)
|
||||
EP_Init(1, EP_TYPE_INTERRUPT, 10, 0, EP1_Handler); // IN1 - transmit
|
||||
EP_Init(2, EP_TYPE_BULK, 0, USB_RXBUFSZ, EP23_Handler); // OUT2 - receive data
|
||||
EP_Init(3, EP_TYPE_BULK, USB_TXBUFSZ, 0, EP23_Handler); // IN3 - transmit data
|
||||
usbON = 1;
|
||||
}
|
||||
}else{
|
||||
@ -126,10 +123,15 @@ void usb_proc(){
|
||||
}
|
||||
|
||||
void USB_send(char *buf){
|
||||
uint16_t l = 0;
|
||||
uint16_t l = 0, ctr = 0;
|
||||
char *p = buf;
|
||||
while(*p++) ++l;
|
||||
EP_Write(3, (uint8_t*)buf, l);
|
||||
while(l){
|
||||
uint16_t s = (l > USB_TXBUFSZ) ? USB_TXBUFSZ : l;
|
||||
EP_Write(3, (uint8_t*)&buf[ctr], s);
|
||||
l -= s;
|
||||
ctr += s;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,7 +150,7 @@ int USB_receive(char *buf, int bufsize){
|
||||
idatalen = rest;
|
||||
}else idatalen = 0;
|
||||
if(ovfl){
|
||||
EP2_Handler(endpoints[2]);
|
||||
EP23_Handler(endpoints[2]);
|
||||
uint16_t epstatus = USB->EPnR[2];
|
||||
epstatus = CLEAR_DTOG_RX(epstatus);
|
||||
epstatus = SET_VALID_RX(epstatus);
|
||||
|
||||
@ -28,6 +28,17 @@
|
||||
#include <stm32f0xx.h>
|
||||
|
||||
#define USB_BTABLE_BASE 0x40006000
|
||||
// !!! when working with CAN bus change USB_BTABLE_SIZE to 768 !!!
|
||||
#define USB_BTABLE_SIZE 1024
|
||||
// first 64 bytes of USB_BTABLE are registers!
|
||||
#define USB_EP0_BASEADDR 64
|
||||
// for USB FS EP0 buffers are from 8 to 64 bytes long
|
||||
#define USB_EP0_BUFSZ 8
|
||||
// USB transmit buffer size
|
||||
#define USB_TXBUFSZ 64
|
||||
// USB receive buffer size
|
||||
#define USB_RXBUFSZ 64
|
||||
|
||||
#undef USB_BTABLE
|
||||
#define USB_BTABLE ((USB_BtableDef *)(USB_BTABLE_BASE))
|
||||
#define USB_ISTR_EPID 0x0000000F
|
||||
|
||||
@ -26,12 +26,6 @@
|
||||
#include <string.h> // memcpy
|
||||
#include "usart.h"
|
||||
|
||||
|
||||
#define EP0DATABUF_SIZE (64)
|
||||
#define DEVICE_DESCRIPTOR_SIZE_BYTE (18)
|
||||
#define DEVICE_QALIFIER_SIZE_BYTE (10)
|
||||
#define STRING_LANG_DESCRIPTOR_SIZE_BYTE (4)
|
||||
|
||||
static usb_LineCoding lineCoding = {115200, 0, 0, 8};
|
||||
static config_pack_t setup_packet;
|
||||
static uint8_t ep0databuf[EP0DATABUF_SIZE];
|
||||
@ -40,7 +34,7 @@ static uint8_t ep0dbuflen = 0;
|
||||
usb_LineCoding getLineCoding(){return lineCoding;}
|
||||
|
||||
const uint8_t USB_DeviceDescriptor[] = {
|
||||
DEVICE_DESCRIPTOR_SIZE_BYTE, // bLength
|
||||
18, // bLength
|
||||
0x01, // bDescriptorType - USB_DEVICE_DESC_TYPE
|
||||
0x10, // bcdUSB_L - 1.10
|
||||
0x01, // bcdUSB_H
|
||||
@ -61,7 +55,7 @@ const uint8_t USB_DeviceDescriptor[] = {
|
||||
};
|
||||
|
||||
const uint8_t USB_DeviceQualifierDescriptor[] = {
|
||||
DEVICE_QALIFIER_SIZE_BYTE, //bLength
|
||||
10, //bLength
|
||||
0x06, // bDescriptorType
|
||||
0x10, // bcdUSB_L
|
||||
0x01, // bcdUSB_H
|
||||
@ -112,8 +106,8 @@ const uint8_t USB_ConfigDescriptor[] = {
|
||||
0x05, /* bDescriptorType: Endpoint */
|
||||
0x02, /* bEndpointAddress: OUT2 */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
0x40, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
(USB_RXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||
(USB_RXBUFSZ >> 8),
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
|
||||
/*Endpoint IN3 Descriptor*/
|
||||
@ -121,40 +115,36 @@ const uint8_t USB_ConfigDescriptor[] = {
|
||||
0x05, /* bDescriptorType: Endpoint */
|
||||
0x83, /* bEndpointAddress IN3 */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
0x40, /* wMaxPacketSize: 64 */
|
||||
0x00,
|
||||
(USB_TXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||
(USB_TXBUFSZ >> 8),
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
};
|
||||
|
||||
_USB_LANG_ID_(LANG_US);
|
||||
_USB_LANG_ID_(USB_StringLangDescriptor, LANG_US);
|
||||
// these descriptors are not used in PL2303 emulator!
|
||||
_USB_STRING_(USB_StringSerialDescriptor, u"0")
|
||||
_USB_STRING_(USB_StringManufacturingDescriptor, u"Prolific Technology Inc.")
|
||||
_USB_STRING_(USB_StringProdDescriptor, u"USB-Serial Controller")
|
||||
|
||||
static usb_dev_t USB_Dev;
|
||||
ep_t endpoints[MAX_ENDPOINTS];
|
||||
ep_t endpoints[ENDPOINTS_NUM];
|
||||
|
||||
/*
|
||||
* default handlers
|
||||
*/
|
||||
// SET_LINE_CODING
|
||||
void WEAK linecoding_handler(usb_LineCoding __attribute__((unused)) *lc){
|
||||
MSG("linecoding");
|
||||
MSG("linecoding_handler\n");
|
||||
}
|
||||
|
||||
// SET_CONTROL_LINE_STATE
|
||||
void WEAK clstate_handler(uint16_t __attribute__((unused)) val){
|
||||
#ifdef EBUG
|
||||
SEND("change state to ");
|
||||
printu(val);
|
||||
usart_putchar('\n');
|
||||
#endif
|
||||
MSG("clstate_handler\n");
|
||||
}
|
||||
|
||||
// SEND_BREAK
|
||||
void WEAK break_handler(){
|
||||
MSG("Break\n");
|
||||
MSG("break_handler\n");
|
||||
}
|
||||
|
||||
// handler of vendor requests
|
||||
@ -234,7 +224,7 @@ uint16_t EP0_Handler(ep_t ep){
|
||||
wr0((const uint8_t *)&USB_StringSerialDescriptor, USB_StringSerialDescriptor.bLength);
|
||||
break;
|
||||
case DEVICE_QALIFIER_DESCRIPTOR:
|
||||
wr0(USB_DeviceQualifierDescriptor, DEVICE_QALIFIER_SIZE_BYTE);
|
||||
wr0(USB_DeviceQualifierDescriptor, USB_DeviceQualifierDescriptor[0]);
|
||||
break;
|
||||
default:
|
||||
WRITEDUMP("UNK_DES");
|
||||
@ -359,26 +349,41 @@ uint16_t EP0_Handler(ep_t ep){
|
||||
return epstatus;
|
||||
}
|
||||
|
||||
// TODO: change initialisation with different buffer size! (EP0 have 8 bytes per buffer, EP1 - 10 bytes!)
|
||||
|
||||
static uint16_t lastaddr = USB_EP0_BASEADDR;
|
||||
/**
|
||||
* Endpoint initialisation, size of input buffer fixed to 64 bytes
|
||||
* Endpoint initialisation
|
||||
* !!! when working with CAN bus change USB_BTABLE_SIZE to 768 !!!
|
||||
* @param number - EP num (0...7)
|
||||
* @param type - EP type (EP_TYPE_BULK, EP_TYPE_CONTROL, EP_TYPE_ISO, EP_TYPE_INTERRUPT)
|
||||
* @param addr_tx - transmission buffer address @ USB/CAN buffer
|
||||
* @param addr_rx - reception buffer address @ USB/CAN buffer
|
||||
* @param txsz - transmission buffer size @ USB/CAN buffer
|
||||
* @param rxsz - reception buffer size @ USB/CAN buffer
|
||||
* @param uint16_t (*func)(ep_t *ep) - EP handler function
|
||||
* @return 0 if all OK
|
||||
*/
|
||||
void EP_Init(uint8_t number, uint8_t type, uint16_t addr_tx, uint16_t addr_rx, uint16_t (*func)(ep_t ep)){
|
||||
int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, uint16_t (*func)(ep_t ep)){
|
||||
if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large
|
||||
if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE) return 2; // out of btable
|
||||
USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA);
|
||||
USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1;
|
||||
USB_BTABLE->EP[number].USB_ADDR_TX = addr_tx;
|
||||
if(rxsz & 1 || rxsz > 992) return 3; // wrong rx buffer size
|
||||
uint16_t countrx = 0;
|
||||
if(rxsz < 64) countrx = rxsz / 2;
|
||||
else{
|
||||
if(rxsz & 0x1f) return 3; // should be multiple of 32
|
||||
countrx = 31 + rxsz / 32;
|
||||
}
|
||||
USB_BTABLE->EP[number].USB_ADDR_TX = lastaddr;
|
||||
endpoints[number].tx_sz = txsz;
|
||||
endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + lastaddr);
|
||||
lastaddr += txsz;
|
||||
USB_BTABLE->EP[number].USB_COUNT_TX = 0;
|
||||
USB_BTABLE->EP[number].USB_ADDR_RX = addr_rx;
|
||||
USB_BTABLE->EP[number].USB_COUNT_RX = 0x8400; // buffer size (64 bytes): Table127 of RM: BL_SIZE=1, NUM_BLOCK=1
|
||||
USB_BTABLE->EP[number].USB_ADDR_RX = lastaddr;
|
||||
endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + lastaddr);
|
||||
lastaddr += rxsz;
|
||||
// buffer size: Table127 of RM: BL_SIZE=1, NUM_BLOCK=1
|
||||
USB_BTABLE->EP[number].USB_COUNT_RX = countrx << 10;
|
||||
endpoints[number].func = func;
|
||||
endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + addr_tx);
|
||||
endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + addr_rx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// standard IRQ handler
|
||||
@ -389,7 +394,9 @@ void usb_isr(){
|
||||
USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM;
|
||||
USB->ISTR = 0;
|
||||
// Endpoint 0 - CONTROL
|
||||
EP_Init(0, EP_TYPE_CONTROL, 64, 128, EP0_Handler);
|
||||
// ON USB LS size of EP0 may be 8 bytes, but on FS it should be 64 bytes!
|
||||
lastaddr = USB_EP0_BASEADDR; // roll back to beginning of buffer
|
||||
EP_Init(0, EP_TYPE_CONTROL, USB_EP0_BUFSZ, USB_EP0_BUFSZ, EP0_Handler);
|
||||
// clear address, leave only enable bit
|
||||
USB->DADDR = USB_DADDR_EF;
|
||||
// state is default - wait for enumeration
|
||||
|
||||
@ -28,8 +28,10 @@
|
||||
#include <wchar.h>
|
||||
#include "usb_defs.h"
|
||||
|
||||
#define EP0DATABUF_SIZE (64)
|
||||
|
||||
// Max EP amount (EP0 + other used)
|
||||
#define MAX_ENDPOINTS 4
|
||||
#define ENDPOINTS_NUM 4
|
||||
// bRequest, standard; for bmRequestType == 0x80
|
||||
#define GET_STATUS 0x00
|
||||
#define GET_DESCRIPTOR 0x06
|
||||
@ -121,16 +123,17 @@ static const struct name \
|
||||
} \
|
||||
name = {sizeof(name), 0x03, str};
|
||||
|
||||
#define _USB_LANG_ID_(lng_id) \
|
||||
#define _USB_LANG_ID_(name, lng_id) \
|
||||
\
|
||||
static const struct USB_StringLangDescriptor \
|
||||
static const struct name \
|
||||
{ \
|
||||
uint8_t bLength; \
|
||||
uint8_t bDescriptorType; \
|
||||
uint16_t bString; \
|
||||
\
|
||||
} \
|
||||
USB_StringLangDescriptor = {0x04, 0x03, lng_id};
|
||||
name = {0x04, 0x03, lng_id};
|
||||
#define STRING_LANG_DESCRIPTOR_SIZE_BYTE (4)
|
||||
|
||||
// EP0 configuration packet
|
||||
typedef struct {
|
||||
@ -143,19 +146,20 @@ typedef struct {
|
||||
|
||||
// endpoints state
|
||||
typedef struct __ep_t{
|
||||
uint16_t *tx_buf;
|
||||
uint8_t *rx_buf;
|
||||
uint16_t (*func)();
|
||||
uint16_t status;
|
||||
unsigned rx_cnt : 10;
|
||||
unsigned tx_flag : 1;
|
||||
unsigned rx_flag : 1;
|
||||
unsigned setup_flag : 1;
|
||||
uint16_t *tx_buf; // transmission buffer address
|
||||
uint8_t *rx_buf; // reception buffer address
|
||||
uint16_t (*func)(); // endpoint action function
|
||||
uint16_t status; // status flags
|
||||
unsigned tx_sz : 10; // Tx buffer size
|
||||
unsigned rx_cnt : 10; // received data counter
|
||||
unsigned tx_flag : 1; // transmission flag
|
||||
unsigned rx_flag : 1; // reception flag
|
||||
unsigned setup_flag : 1; // this is setup packet (only for EP0)
|
||||
} ep_t;
|
||||
|
||||
// USB status & its address
|
||||
typedef struct {
|
||||
uint8_t USB_Status;
|
||||
uint8_t USB_Status;
|
||||
uint16_t USB_Addr;
|
||||
}usb_dev_t;
|
||||
|
||||
@ -186,7 +190,7 @@ extern ep_t endpoints[];
|
||||
|
||||
void USB_Init();
|
||||
uint8_t USB_GetState();
|
||||
void EP_Init(uint8_t number, uint8_t type, uint16_t addr_tx, uint16_t addr_rx, uint16_t (*func)(ep_t ep));
|
||||
int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, uint16_t (*func)(ep_t ep));
|
||||
void EP_WriteIRQ(uint8_t number, const uint8_t *buf, uint16_t size);
|
||||
void EP_Write(uint8_t number, const uint8_t *buf, uint16_t size);
|
||||
int EP_Read(uint8_t number, uint8_t *buf);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user