Skip to content

Commit b149a92

Browse files
committed
feat(usb): allow USB PID to be 0x0000
Fixes #2215 Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 64bea5c commit b149a92

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

cores/arduino/stm32/usb/usbd_desc.c

+34-15
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,43 @@
2626
/* Private typedef -----------------------------------------------------------*/
2727
/* Private define ------------------------------------------------------------*/
2828

29-
/* USB VID and PID: Either both or neither must be specified. If not
30-
* specified, default to the ST VID, with a PID assigned to HID or a PID
31-
* assigned to CDC devices. */
32-
#if !USBD_PID && !USBD_VID
33-
// Undef the default zero values
34-
#undef USBD_PID
29+
/* USB VID and PID have to be specified to correct values.
30+
* They can be defined thanks:
31+
* - boards.txt: *.build.vid or *.build.pid
32+
* - build_opt.h: define CUSTOM_USBD_VID or CUSTOM_USBD_PID
33+
* Else if not defined or specified, default to the ST VID,
34+
* with PID assigned to HID or CDC devices.
35+
*/
36+
#if !defined(USBD_VID) || USBD_VID == 0
37+
// Undef the default definition
3538
#undef USBD_VID
36-
// Define default values, based on the USB class used
37-
#define USBD_VID 0x0483
38-
#if defined(USBD_USE_HID_COMPOSITE)
39-
#define USBD_PID 0x5711
40-
#elif defined(USBD_USE_CDC)
41-
#define USBD_PID 0x5740
39+
#if defined(CUSTOM_USBD_VID)
40+
#define USBD_VID CUSTOM_USBD_VID
41+
#else
42+
// Define default values
43+
#define USBD_VID 0x0483
44+
#endif
45+
#endif /* USBD_VID */
46+
47+
#if !defined(USBD_PID) || USBD_PID == -1
48+
// Undef the default definition
49+
#undef USBD_PID
50+
#if defined(CUSTOM_USBD_PID)
51+
#define USBD_PID CUSTOM_USBD_PID
52+
#else
53+
// Define default values, based on the USB class used
54+
#if defined(USBD_USE_HID_COMPOSITE)
55+
#define USBD_PID 0x5711
56+
#elif defined(USBD_USE_CDC)
57+
#define USBD_PID 0x5740
58+
#else
59+
#error "USB PID not specified"
60+
#endif
4261
#endif
43-
#endif /* !USBD_PID && !USBD_VID */
62+
#endif /* USBD_VID */
4463

45-
#if !USBD_VID || !USBD_PID
46-
#error "USB VID or PID not specified"
64+
#if USBD_VID == 0
65+
#error "USB VID not properly specified"
4766
#endif
4867

4968
/* Manufacturer string: Use the specified string if specified, guess

platform.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ compiler.arm.cmsis.c.flags="-I{runtime.tools.CMSIS-5.9.0.path}/CMSIS/Core/Includ
8282
build.usb_flags=-DUSBCON {build.usb_speed} -DUSBD_VID={build.vid} -DUSBD_PID={build.pid} -DHAL_PCD_MODULE_ENABLED
8383

8484
# Specify defaults for vid/pid, since an empty value is impossible to
85-
# detect in the preprocessor, but a 0 can be checked for.
85+
# detect in the preprocessor, but a 0 can be checked for vid and -1
86+
# for pid (can be 0).
8687
# Boards should specify either both, or neither of these.
8788
build.vid=0
88-
build.pid=0
89+
build.pid=-1
8990

9091
# To customize the USB manufacturer or product string, must add defines
9192
# for them, e.g.:

0 commit comments

Comments
 (0)