diff --git a/Makefile.include b/Makefile.include index 8056a026f39a..e04e79849c9c 100644 --- a/Makefile.include +++ b/Makefile.include @@ -805,6 +805,9 @@ include $(RIOTMAKE)/vars.inc.mk # Include build targets for selected tools include $(RIOTMAKE)/tools/targets.inc.mk +# Checks and defaults for USB Vendor and Product ID +include $(RIOTMAKE)/usb-codes.inc.mk + # Warn if the selected board and drivers don't provide all needed features: ifneq (, $(filter all flash, $(if $(MAKECMDGOALS), $(MAKECMDGOALS), all))) EXPECT_ERRORS := diff --git a/dist/usb_id_testing b/dist/usb_id_testing new file mode 100644 index 000000000000..289c267374df --- /dev/null +++ b/dist/usb_id_testing @@ -0,0 +1,20 @@ +# This file contains all codes that should trigger the usb_id_check warning +# about a test PID being used + +1209 0001 +1209 0002 +1209 0003 +1209 0004 +1209 0005 +1209 0006 +1209 0007 +1209 0008 +1209 0009 +1209 000a +1209 000b +1209 000c +1209 000d +1209 000e +1209 000f +1209 0010 +1209 7d01 diff --git a/examples/usbus_minimal/Kconfig b/examples/usbus_minimal/Kconfig deleted file mode 100644 index a31bf18547ed..000000000000 --- a/examples/usbus_minimal/Kconfig +++ /dev/null @@ -1,5 +0,0 @@ -config USB_VID - default 0x$(DEFAULT_VID) if KCONFIG_USB - -config USB_PID - default 0x$(DEFAULT_PID) if KCONFIG_USB diff --git a/examples/usbus_minimal/Makefile b/examples/usbus_minimal/Makefile index c4a0d293d4ff..b9d5dfb4a663 100644 --- a/examples/usbus_minimal/Makefile +++ b/examples/usbus_minimal/Makefile @@ -16,10 +16,8 @@ USEMODULE += usbus USEMODULE += auto_init_usbus # USB device vendor and product ID -export DEFAULT_VID = 1209 -export DEFAULT_PID = 7D00 -USB_VID ?= $(DEFAULT_VID) -USB_PID ?= $(DEFAULT_PID) +USB_VID ?= $(USB_VID_TESTING) +USB_PID ?= $(USB_PID_TESTING) # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 @@ -28,25 +26,3 @@ QUIET ?= 1 SHOULD_RUN_KCONFIG ?= include $(RIOTBASE)/Makefile.include - -# Set USB VID/PID via CFLAGS if not being set via Kconfig -ifndef CONFIG_USB_VID - CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) -else - USB_VID = $(patsubst 0x%,%,$(CONFIG_USB_VID)) -endif - -ifndef CONFIG_USB_PID - CFLAGS += -DCONFIG_USB_PID=0x$(USB_PID) -else - USB_PID = $(patsubst 0x%,%,$(CONFIG_USB_PID)) -endif - -.PHONY: usb_id_check -usb_id_check: - @if [ $(USB_VID) = $(DEFAULT_VID) -o $(USB_PID) = $(DEFAULT_PID) ] ; then \ - $(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \ - $(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \ - fi - -all: | usb_id_check diff --git a/makefiles/usb-codes.inc.mk b/makefiles/usb-codes.inc.mk new file mode 100644 index 000000000000..ccc3e57926ac --- /dev/null +++ b/makefiles/usb-codes.inc.mk @@ -0,0 +1,33 @@ +# Set USB VID/PID via CFLAGS if not being set via Kconfig +ifndef CONFIG_USB_VID + ifdef USB_VID + CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) + endif +else + USB_VID = $(patsubst 0x%,%,$(CONFIG_USB_VID)) +endif + +ifndef CONFIG_USB_PID + ifdef USB_PID + CFLAGS += -DCONFIG_USB_PID=0x$(USB_PID) + endif +else + USB_PID = $(patsubst 0x%,%,$(CONFIG_USB_PID)) +endif + +# Exported for the benefit of Kconfig +USB_VID_TESTING = 1209 +USB_PID_TESTING = 7D01 +usb_id_check: + @if grep --quiet --ignore-case "^$(USB_VID) $(USB_PID)$$" $(RIOTBASE)/dist/usb_id_testing; then \ + $(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \ + $(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \ + fi + @if [ "$(USB_VID) $(subst D,d,$(USB_PID))" = "1209 7d00" ]; then \ + $(COLOR_ECHO) "$(COLOR_RED)RIOT standard peripherals code (1209/7D00) cannot be set explicitly.$(COLOR_RESET)" 1>&2 ; \ + $(COLOR_ECHO) "$(COLOR_RED)Unset USB_VID / USB_PID for the code to be picked automatically, or set$(COLOR_RESET)" 1>&2 ; \ + $(COLOR_ECHO) "$(COLOR_RED)them to \$${USB_VID_TESTING} / \$${USB_PID_TESTING} during development.$(COLOR_RESET)" 1>&2 ; \ + exit 1; \ + fi +.PHONY: usb_id_check +all: | usb_id_check diff --git a/sys/include/usb.h b/sys/include/usb.h index 83dbc620f89c..de838e51d32d 100644 --- a/sys/include/usb.h +++ b/sys/include/usb.h @@ -51,7 +51,7 @@ extern "C" { #define CONFIG_USB_PID INTERNAL_PERIPHERAL_PID #else #error Please configure your vendor and product IDs. For development, you may \ - set CONFIG_USB_VID=0x1209 CONFIG_USB_PID=0x7D01. + set USB_VID=${USB_VID_TESTING} USB_PID=${USB_PID_TESTING}. #endif #endif diff --git a/sys/usb/Kconfig b/sys/usb/Kconfig index d4a20f88b7c5..a63fba746453 100644 --- a/sys/usb/Kconfig +++ b/sys/usb/Kconfig @@ -45,12 +45,14 @@ endchoice config USB_PID hex "Product ID" range 0x0000 0xFFFF + default 0x7D01 help You must provide your own PID. config USB_VID hex "Vendor ID" range 0x0000 0xFFFF + default 0x1209 help You must provide your own VID. diff --git a/tests/usbus/Makefile b/tests/usbus/Makefile index 9d6340926c41..236d98343c39 100644 --- a/tests/usbus/Makefile +++ b/tests/usbus/Makefile @@ -6,20 +6,7 @@ FEATURES_PROVIDED += periph_usbdev DISABLE_MODULE += auto_init_usbus # USB device vendor and product ID -DEFAULT_VID = 1209 -DEFAULT_PID = 7D00 -USB_VID ?= $(DEFAULT_VID) -USB_PID ?= $(DEFAULT_PID) - -CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) -DCONFIG_USB_PID=0x$(USB_PID) +USB_VID ?= $(USB_VID_TESTING) +USB_PID ?= $(USB_PID_TESTING) include $(RIOTBASE)/Makefile.include - -.PHONY: usb_id_check -usb_id_check: - @if [ $(USB_VID) = $(DEFAULT_VID) ] || [ $(USB_PID) = $(DEFAULT_PID) ] ; then \ - $(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \ - $(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \ - fi - -all: | usb_id_check diff --git a/tests/usbus_cdc_acm_stdio/Makefile b/tests/usbus_cdc_acm_stdio/Makefile index 634bea950313..e3e13039a918 100644 --- a/tests/usbus_cdc_acm_stdio/Makefile +++ b/tests/usbus_cdc_acm_stdio/Makefile @@ -6,21 +6,4 @@ USEMODULE += shell USEMODULE += shell_commands USEMODULE += ps -# USB device vendor and product ID -DEFAULT_VID = 1209 -DEFAULT_PID = 7D00 -USB_VID ?= $(DEFAULT_VID) -USB_PID ?= $(DEFAULT_PID) - -CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) -DCONFIG_USB_PID=0x$(USB_PID) - include $(RIOTBASE)/Makefile.include - -.PHONY: usb_id_check -usb_id_check: - @if [ $(USB_VID) = $(DEFAULT_VID) ] || [ $(USB_PID) = $(DEFAULT_PID) ] ; then \ - $(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \ - $(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \ - fi - -all: | usb_id_check diff --git a/tests/usbus_cdc_ecm/Makefile b/tests/usbus_cdc_ecm/Makefile index 346b8cb0c3a0..ae7a94bb4d52 100644 --- a/tests/usbus_cdc_ecm/Makefile +++ b/tests/usbus_cdc_ecm/Makefile @@ -9,36 +9,4 @@ USEMODULE += shell USEMODULE += shell_commands USEMODULE += ps -# USB device vendor and product ID -# pid.codes test VID/PID, not globally unique -export DEFAULT_VID = 1209 -export DEFAULT_PID = 7D00 -USB_VID ?= $(DEFAULT_VID) -USB_PID ?= $(DEFAULT_PID) - include $(RIOTBASE)/Makefile.include - -# Set USB VID/PID via CFLAGS if not being set via Kconfig -ifndef CONFIG_USB_VID - CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) -else - USB_VID = $(patsubst 0x%,%,$(CONFIG_USB_VID)) -endif - -ifndef CONFIG_USB_PID - CFLAGS += -DCONFIG_USB_PID=0x$(USB_PID) -else - USB_PID = $(patsubst 0x%,%,$(CONFIG_USB_PID)) -endif - -# There is a Kconfig in the app folder, we need to indicate not to run it by default -SHOULD_RUN_KCONFIG ?= - -.PHONY: usb_id_check -usb_id_check: - @if [ $(USB_VID) = $(DEFAULT_VID) -o $(USB_PID) = $(DEFAULT_PID) ] ; then \ - $(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \ - $(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \ - fi - -all: | usb_id_check