Skip to content

Commit bbb8b78

Browse files
authored
Merge pull request stm32duino#1048 from matthijskooijman/fix-external-and-internal-usb-pullup
Fix external and internal usb pullup
2 parents 1eac7c5 + d3fdc1f commit bbb8b78

File tree

6 files changed

+48
-10
lines changed

6 files changed

+48
-10
lines changed

boards.txt

+7
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ GenF4.build.series=STM32F4xx
12101210
GenF4.build.cmsis_lib_gcc=arm_cortexM4lf_math
12111211

12121212
# Black F407VE
1213+
# https://github.com/mcauser/BLACK_F407VEZ
12131214
GenF4.menu.pnum.BLACK_F407VE=Black F407VE
12141215
GenF4.menu.pnum.BLACK_F407VE.upload.maximum_size=524288
12151216
GenF4.menu.pnum.BLACK_F407VE.upload.maximum_data_size=131072
@@ -1218,6 +1219,7 @@ GenF4.menu.pnum.BLACK_F407VE.build.product_line=STM32F407xx
12181219
GenF4.menu.pnum.BLACK_F407VE.build.variant=BLACK_F407XX
12191220

12201221
# Black F407VG
1222+
# https://github.com/mcauser/BLACK_F407VEZ with bigger chip
12211223
GenF4.menu.pnum.BLACK_F407VG=Black F407VG
12221224
GenF4.menu.pnum.BLACK_F407VG.upload.maximum_size=1048576
12231225
GenF4.menu.pnum.BLACK_F407VG.upload.maximum_data_size=131072
@@ -1226,6 +1228,7 @@ GenF4.menu.pnum.BLACK_F407VG.build.product_line=STM32F407xx
12261228
GenF4.menu.pnum.BLACK_F407VG.build.variant=BLACK_F407XX
12271229

12281230
# Black F407ZE
1231+
# https://github.com/mcauser/BLACK_F407ZE
12291232
GenF4.menu.pnum.BLACK_F407ZE=Black F407ZE
12301233
GenF4.menu.pnum.BLACK_F407ZE.upload.maximum_size=524288
12311234
GenF4.menu.pnum.BLACK_F407ZE.upload.maximum_data_size=131072
@@ -1234,6 +1237,7 @@ GenF4.menu.pnum.BLACK_F407ZE.build.product_line=STM32F407xx
12341237
GenF4.menu.pnum.BLACK_F407ZE.build.variant=BLACK_F407XX
12351238

12361239
# Black F407ZG
1240+
# https://github.com/mcauser/BLACK_F407ZG
12371241
GenF4.menu.pnum.BLACK_F407ZG=Black F407ZG
12381242
GenF4.menu.pnum.BLACK_F407ZG.upload.maximum_size=1048576
12391243
GenF4.menu.pnum.BLACK_F407ZG.upload.maximum_data_size=131072
@@ -1274,6 +1278,7 @@ GenF4.menu.pnum.BLACKPILL_F401CC.build.product_line=STM32F401xC
12741278
GenF4.menu.pnum.BLACKPILL_F401CC.build.variant=Generic_F401Cx
12751279

12761280
# BlackPill F411CE
1281+
# https://github.com/mcauser/WEACT_F411CEU6
12771282
GenF4.menu.pnum.BLACKPILL_F411CE=BlackPill F411CE
12781283
GenF4.menu.pnum.BLACKPILL_F411CE.upload.maximum_size=524288
12791284
GenF4.menu.pnum.BLACKPILL_F411CE.upload.maximum_data_size=131072
@@ -1282,6 +1287,7 @@ GenF4.menu.pnum.BLACKPILL_F411CE.build.product_line=STM32F411xE
12821287
GenF4.menu.pnum.BLACKPILL_F411CE.build.variant=Generic_F411Cx
12831288

12841289
# Core board F401RCT6
1290+
# https://stm32-base.org/boards/STM32F401RCT6-STM32F-Core-Board
12851291
GenF4.menu.pnum.CoreBoard_F401RC=Core board F401RCT6
12861292
GenF4.menu.pnum.CoreBoard_F401RC.upload.maximum_size=262144
12871293
GenF4.menu.pnum.CoreBoard_F401RC.upload.maximum_data_size=65536
@@ -1298,6 +1304,7 @@ GenF4.menu.pnum.FEATHER_F405.build.product_line=STM32F405xx
12981304
GenF4.menu.pnum.FEATHER_F405.build.variant=FEATHER_F405
12991305

13001306
# ThunderPack F411xxE
1307+
# https://github.com/jgillick/ThunderPack/tree/STM32F4
13011308
GenF4.menu.pnum.THUNDERPACK_F411=ThunderPack v1.1+
13021309
GenF4.menu.pnum.THUNDERPACK_F411.upload.maximum_size=524288
13031310
GenF4.menu.pnum.THUNDERPACK_F411.upload.maximum_data_size=131072

cores/arduino/stm32/usb/usbd_if.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
#if defined(USBD_DETACH_PIN) && !defined(USBD_DETACH_LEVEL)
6969
#error "USBD_DETACH_PIN also needs USBD_DETACH_LEVEL defined"
7070
#endif /* defined(USBD_DETACH_PIN) && !defined(USBD_DETACH_LEVEL) */
71+
#if (defined(USBD_DETACH_PIN) || defined(USBD_ATTACH_PIN)) && defined(USBD_FIXED_PULLUP)
72+
#error "Cannot define both USBD_FIXED_PULLUP and USBD_ATTACH_PIN or USBD_DETACH_PIN"
73+
#endif /* (defined(USBD_DETACH_PIN) || defined(USBD_ATTACH_PIN)) && defined(USBD_FIXED_PULLUP) */
7174

7275
/* Either of these bits indicate that there are internal pullups */
7376
#if defined(USB_BCDR_DPPU) || defined(USB_OTG_DCTL_SDIS)
@@ -78,10 +81,13 @@
7881
* in USBD_LL_Init in usbd_conf.c. */
7982
#if defined(USE_USB_HS)
8083
#define USBD_USB_INSTANCE USB_OTG_HS
84+
#define USBD_DP_PINNAME USB_OTG_HS_DP
8185
#elif defined(USB_OTG_FS)
8286
#define USBD_USB_INSTANCE USB_OTG_FS
87+
#define USBD_DP_PINNAME USB_OTG_FS_DP
8388
#elif defined(USB)
8489
#define USBD_USB_INSTANCE USB
90+
#define USBD_DP_PINNAME USB_DP
8591
#endif
8692

8793
/*
@@ -97,15 +103,13 @@
97103
#elif defined(USBD_DETACH_PIN)
98104
#define USBD_PULLUP_CONTROL_PINNAME digitalPinToPinName(USBD_DETACH_PIN)
99105
#define USBD_ATTACH_LEVEL !(USBD_DETACH_LEVEL)
100-
#elif !defined(USBD_HAVE_INTERNAL_PULLUPS)
106+
#elif !defined(USBD_HAVE_INTERNAL_PULLUPS) || defined(USBD_FIXED_PULLUP)
101107
/* When no USB attach and detach pins were defined, and there are also
102108
* no internal pullups, assume there is a fixed external pullup and apply
103-
* the D+ trick. This should happen only for the USB peripheral, since
104-
* USB_OTG_HS and USB_OTG_FS always have internal pullups. */
105-
#if !defined(USB)
106-
#error "Unexpected USB configuration"
107-
#endif
108-
#define USBD_PULLUP_CONTROL_PINNAME USB_DP
109+
* the D+ trick. Also do this when there are internal *and* external
110+
* pulups (which is a hardware bug, but there are boards out there with
111+
* this). */
112+
#define USBD_PULLUP_CONTROL_PINNAME USBD_DP_PINNAME
109113
#define USBD_DETACH_LEVEL LOW
110114
// USBD_ATTACH_LEVEL not needed.
111115
#define USBD_DP_TRICK

variants/BLACK_F407XX/variant.h

+7
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ extern "C" {
301301
#define HAL_DAC_MODULE_ENABLED
302302
#define HAL_SD_MODULE_ENABLED
303303

304+
// This indicates that there is an external and fixed 1.5k pullup
305+
// on the D+ line. This define is only needed on boards that have
306+
// internal pullups *and* an external pullup. Note that it would have
307+
// been better to omit the pullup and exclusively use the internal
308+
// pullups instead.
309+
#define USBD_FIXED_PULLUP
310+
304311
#ifdef __cplusplus
305312
} // extern "C"
306313
#endif

variants/BLUE_F407VE_Mini/variant.h

+7
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ extern "C" {
184184
#define HAL_DAC_MODULE_ENABLED
185185
#define HAL_SD_MODULE_ENABLED
186186

187+
// This indicates that there is an external and fixed 1.5k pullup
188+
// on the D+ line. This define is only needed on boards that have
189+
// internal pullups *and* an external pullup. Note that it would have
190+
// been better to omit the pullup and exclusively use the internal
191+
// pullups instead.
192+
#define USBD_FIXED_PULLUP
193+
187194
#ifdef __cplusplus
188195
} // extern "C"
189196
#endif

variants/Generic_F401Rx/variant.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,11 @@ extern "C" {
127127

128128
#ifdef ARDUINO_CoreBoard_F401RC
129129
// USB, pull this pin low to enable the USB attach pullup
130-
#define USBD_ATTACH_PIN PD2
131-
#define USBD_ATTACH_LEVEL LOW
130+
// It is documented here, but not actually used, since there are also
131+
// internal pullups which are automatically used and using both would
132+
// violate the USB specification for pullup strength.
133+
//#define USBD_ATTACH_PIN PD2
134+
//#define USBD_ATTACH_LEVEL LOW
132135
#endif
133136

134137
#ifdef __cplusplus

variants/board_template/variant.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,17 @@ extern "C" {
174174
//#define USBD_ATTACH_LEVEL LOW
175175
//#define USBD_DETACH_PIN x
176176
//#define USBD_DETACH_LEVEL LOW
177-
177+
//
178+
// This indicates that there is an external and fixed 1.5k pullup
179+
// on the D+ line. This define is not normally needed, since a
180+
// fixed pullup is assumed by default. It is only required when
181+
// the USB peripheral has an internal pullup *and* an external
182+
// fixed pullup is present (which is actually a hardware bug, since just
183+
// the internal pullup is sufficient and having two pullups violates the
184+
// USB specification). In this case, defining this forces
185+
// the "write D+ LOW"-trick to be used. In the future, it might also
186+
// disable the internal pullups, but this is not currently implemented.
187+
// #define USBD_FIXED_PULLUP
178188
#ifdef __cplusplus
179189
} // extern "C"
180190
#endif

0 commit comments

Comments
 (0)