diff --git a/Makefile b/Makefile index 33b737f8a..fdff14234 100644 --- a/Makefile +++ b/Makefile @@ -230,7 +230,7 @@ openocd_install: openocd_clean $(V1) mkdir -p "$(OPENOCD_DIR)" $(V1) ( \ cd $(OPENOCD_BUILD_DIR)/openocd-0.5.0 ; \ - ./configure --prefix="$(OPENOCD_DIR)" --enable-ft2232_libftdi --enable-buspirate; \ + ./configure --prefix="$(OPENOCD_DIR)" --enable-ft2232_libftdi ; \ $(MAKE) --silent ; \ $(MAKE) --silent install ; \ ) diff --git a/flight/Bootloaders/CopterControl/Makefile b/flight/Bootloaders/CopterControl/Makefile index d52541791..8c22d37a7 100644 --- a/flight/Bootloaders/CopterControl/Makefile +++ b/flight/Bootloaders/CopterControl/Makefile @@ -115,6 +115,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c SRC += $(OPSYSTEM)/pios_usb_board_data.c SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c +SRC += $(PIOSCOMMON)/pios_usb_util.c ## PIOS Hardware (Common) SRC += $(PIOSCOMMON)/pios_board_info.c diff --git a/flight/Bootloaders/CopterControl/inc/pios_usb_board_data.h b/flight/Bootloaders/CopterControl/inc/pios_usb_board_data.h index f1accee17..addb24f19 100644 --- a/flight/Bootloaders/CopterControl/inc/pios_usb_board_data.h +++ b/flight/Bootloaders/CopterControl/inc/pios_usb_board_data.h @@ -39,6 +39,7 @@ #define PIOS_USB_BOARD_PRODUCT_ID USB_PRODUCT_ID_COPTERCONTROL #define PIOS_USB_BOARD_DEVICE_VER USB_OP_DEVICE_VER(USB_OP_BOARD_ID_COPTERCONTROL, USB_OP_BOARD_MODE_BL) +#define PIOS_USB_BOARD_SN_SUFFIX "+BL" /* * The bootloader uses a simplified report structure diff --git a/flight/Bootloaders/CopterControl/pios_usb_board_data.c b/flight/Bootloaders/CopterControl/pios_usb_board_data.c index 4f02ce424..1993320d4 100644 --- a/flight/Bootloaders/CopterControl/pios_usb_board_data.c +++ b/flight/Bootloaders/CopterControl/pios_usb_board_data.c @@ -31,6 +31,7 @@ #include "pios_usb_board_data.h" /* struct usb_*, USB_* */ #include "pios_sys.h" /* PIOS_SYS_SerialNumberGet */ #include "pios_usbhook.h" /* PIOS_USBHOOK_* */ +#include "pios_usb_util.h" /* PIOS_USB_UTIL_AsciiToUtf8 */ static const uint8_t usb_product_id[28] = { sizeof(usb_product_id), @@ -50,40 +51,15 @@ static const uint8_t usb_product_id[28] = { 'l', 0, }; -static uint8_t usb_serial_number[52] = { +static uint8_t usb_serial_number[2 + PIOS_SYS_SERIAL_NUM_ASCII_LEN*2 + (sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1)*2] = { sizeof(usb_serial_number), USB_DESC_TYPE_STRING, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0 }; static const struct usb_string_langid usb_lang_id = { .bLength = sizeof(usb_lang_id), .bDescriptorType = USB_DESC_TYPE_STRING, - .bLangID = htousbs(USB_LANGID_ENGLISH_UK), + .bLangID = htousbs(USB_LANGID_ENGLISH_US), }; static const uint8_t usb_vendor_id[28] = { @@ -107,11 +83,13 @@ static const uint8_t usb_vendor_id[28] = { int32_t PIOS_USB_BOARD_DATA_Init(void) { /* Load device serial number into serial number string */ - uint8_t sn[25]; + uint8_t sn[PIOS_SYS_SERIAL_NUM_ASCII_LEN + 1]; PIOS_SYS_SerialNumberGet((char *)sn); - for (uint8_t i = 0; sn[i] != '\0' && (2 * i) < usb_serial_number[0]; i++) { - usb_serial_number[2 + 2 * i] = sn[i]; - } + + /* Concatenate the device serial number and the appropriate suffix ("+BL" or "+FW") into the USB serial number */ + uint8_t * utf8 = &(usb_serial_number[2]); + utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, sn, PIOS_SYS_SERIAL_NUM_ASCII_LEN); + utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, (uint8_t *)PIOS_USB_BOARD_SN_SUFFIX, sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1); PIOS_USBHOOK_RegisterString(USB_STRING_DESC_PRODUCT, (uint8_t *)&usb_product_id, sizeof(usb_product_id)); PIOS_USBHOOK_RegisterString(USB_STRING_DESC_SERIAL, (uint8_t *)&usb_serial_number, sizeof(usb_serial_number)); diff --git a/flight/Bootloaders/PipXtreme/Makefile b/flight/Bootloaders/PipXtreme/Makefile index f90b635a8..5747a0511 100644 --- a/flight/Bootloaders/PipXtreme/Makefile +++ b/flight/Bootloaders/PipXtreme/Makefile @@ -115,6 +115,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c SRC += $(OPSYSTEM)/pios_usb_board_data.c SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c +SRC += $(PIOSCOMMON)/pios_usb_util.c ## PIOS Hardware (Common) SRC += $(PIOSCOMMON)/pios_board_info.c diff --git a/flight/Bootloaders/PipXtreme/inc/pios_usb_board_data.h b/flight/Bootloaders/PipXtreme/inc/pios_usb_board_data.h index 2e35f2fa4..f959c0e03 100644 --- a/flight/Bootloaders/PipXtreme/inc/pios_usb_board_data.h +++ b/flight/Bootloaders/PipXtreme/inc/pios_usb_board_data.h @@ -39,6 +39,7 @@ #define PIOS_USB_BOARD_PRODUCT_ID USB_PRODUCT_ID_PIPXTREME #define PIOS_USB_BOARD_DEVICE_VER USB_OP_DEVICE_VER(USB_OP_BOARD_ID_PIPXTREME, USB_OP_BOARD_MODE_BL) +#define PIOS_USB_BOARD_SN_SUFFIX "+BL" /* * The bootloader uses a simplified report structure diff --git a/flight/Bootloaders/PipXtreme/pios_usb_board_data.c b/flight/Bootloaders/PipXtreme/pios_usb_board_data.c index 3e41e5ac9..c2e0c8762 100644 --- a/flight/Bootloaders/PipXtreme/pios_usb_board_data.c +++ b/flight/Bootloaders/PipXtreme/pios_usb_board_data.c @@ -31,6 +31,7 @@ #include "pios_usb_board_data.h" /* struct usb_*, USB_* */ #include "pios_sys.h" /* PIOS_SYS_SerialNumberGet */ #include "pios_usbhook.h" /* PIOS_USBHOOK_* */ +#include "pios_usb_util.h" /* PIOS_USB_UTIL_AsciiToUtf8 */ static const uint8_t usb_product_id[20] = { sizeof(usb_product_id), @@ -46,40 +47,15 @@ static const uint8_t usb_product_id[20] = { 'e', 0, }; -static uint8_t usb_serial_number[52] = { +static uint8_t usb_serial_number[2 + PIOS_SYS_SERIAL_NUM_ASCII_LEN*2 + (sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1)*2] = { sizeof(usb_serial_number), USB_DESC_TYPE_STRING, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0 }; static const struct usb_string_langid usb_lang_id = { .bLength = sizeof(usb_lang_id), .bDescriptorType = USB_DESC_TYPE_STRING, - .bLangID = htousbs(USB_LANGID_ENGLISH_UK), + .bLangID = htousbs(USB_LANGID_ENGLISH_US), }; static const uint8_t usb_vendor_id[28] = { @@ -103,11 +79,13 @@ static const uint8_t usb_vendor_id[28] = { int32_t PIOS_USB_BOARD_DATA_Init(void) { /* Load device serial number into serial number string */ - uint8_t sn[25]; + uint8_t sn[PIOS_SYS_SERIAL_NUM_ASCII_LEN + 1]; PIOS_SYS_SerialNumberGet((char *)sn); - for (uint8_t i = 0; sn[i] != '\0' && (2 * i) < usb_serial_number[0]; i++) { - usb_serial_number[2 + 2 * i] = sn[i]; - } + + /* Concatenate the device serial number and the appropriate suffix ("+BL" or "+FW") into the USB serial number */ + uint8_t * utf8 = &(usb_serial_number[2]); + utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, sn, PIOS_SYS_SERIAL_NUM_ASCII_LEN); + utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, (uint8_t *)PIOS_USB_BOARD_SN_SUFFIX, sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1); PIOS_USBHOOK_RegisterString(USB_STRING_DESC_PRODUCT, (uint8_t *)&usb_product_id, sizeof(usb_product_id)); PIOS_USBHOOK_RegisterString(USB_STRING_DESC_SERIAL, (uint8_t *)&usb_serial_number, sizeof(usb_serial_number)); diff --git a/flight/CopterControl/Makefile b/flight/CopterControl/Makefile index 7de345bb1..82334e56a 100644 --- a/flight/CopterControl/Makefile +++ b/flight/CopterControl/Makefile @@ -243,6 +243,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c SRC += $(OPSYSTEM)/pios_usb_board_data.c SRC += $(PIOSCOMMON)/pios_usb_desc_hid_cdc.c SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c +SRC += $(PIOSCOMMON)/pios_usb_util.c ## PIOS Hardware (Common) SRC += $(PIOSCOMMON)/pios_crc.c diff --git a/flight/CopterControl/System/inc/pios_usb_board_data.h b/flight/CopterControl/System/inc/pios_usb_board_data.h index 9907a4934..2dcb5f845 100644 --- a/flight/CopterControl/System/inc/pios_usb_board_data.h +++ b/flight/CopterControl/System/inc/pios_usb_board_data.h @@ -41,5 +41,6 @@ #define PIOS_USB_BOARD_PRODUCT_ID USB_PRODUCT_ID_COPTERCONTROL #define PIOS_USB_BOARD_DEVICE_VER USB_OP_DEVICE_VER(USB_OP_BOARD_ID_COPTERCONTROL, USB_OP_BOARD_MODE_FW) +#define PIOS_USB_BOARD_SN_SUFFIX "+FW" #endif /* PIOS_USB_BOARD_DATA_H */ diff --git a/flight/CopterControl/System/pios_board.c b/flight/CopterControl/System/pios_board.c index 78e316cb5..11a6c4386 100644 --- a/flight/CopterControl/System/pios_board.c +++ b/flight/CopterControl/System/pios_board.c @@ -246,32 +246,23 @@ void PIOS_Board_Init(void) { /* Initialize board specific USB data */ PIOS_USB_BOARD_DATA_Init(); + /* Flags to determine if various USB interfaces are advertised */ bool usb_hid_present = false; bool usb_cdc_present = false; - uint8_t hwsettings_usb_devicetype; - HwSettingsUSB_DeviceTypeGet(&hwsettings_usb_devicetype); - - switch (hwsettings_usb_devicetype) { - case HWSETTINGS_USB_DEVICETYPE_HIDONLY: - if (PIOS_USB_DESC_HID_ONLY_Init()) { - PIOS_Assert(0); - } - usb_hid_present = true; - break; - case HWSETTINGS_USB_DEVICETYPE_HIDVCP: - if (PIOS_USB_DESC_HID_CDC_Init()) { - PIOS_Assert(0); - } - usb_hid_present = true; - usb_cdc_present = true; - break; - case HWSETTINGS_USB_DEVICETYPE_VCPONLY: - break; - default: +#if defined(PIOS_INCLUDE_USB_CDC) + if (PIOS_USB_DESC_HID_CDC_Init()) { PIOS_Assert(0); } + usb_hid_present = true; + usb_cdc_present = true; +#else + if (PIOS_USB_DESC_HID_ONLY_Init()) { + PIOS_Assert(0); + } + usb_hid_present = true; +#endif uint32_t pios_usb_id; diff --git a/flight/CopterControl/System/pios_usb_board_data.c b/flight/CopterControl/System/pios_usb_board_data.c index 4f02ce424..1993320d4 100644 --- a/flight/CopterControl/System/pios_usb_board_data.c +++ b/flight/CopterControl/System/pios_usb_board_data.c @@ -31,6 +31,7 @@ #include "pios_usb_board_data.h" /* struct usb_*, USB_* */ #include "pios_sys.h" /* PIOS_SYS_SerialNumberGet */ #include "pios_usbhook.h" /* PIOS_USBHOOK_* */ +#include "pios_usb_util.h" /* PIOS_USB_UTIL_AsciiToUtf8 */ static const uint8_t usb_product_id[28] = { sizeof(usb_product_id), @@ -50,40 +51,15 @@ static const uint8_t usb_product_id[28] = { 'l', 0, }; -static uint8_t usb_serial_number[52] = { +static uint8_t usb_serial_number[2 + PIOS_SYS_SERIAL_NUM_ASCII_LEN*2 + (sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1)*2] = { sizeof(usb_serial_number), USB_DESC_TYPE_STRING, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0 }; static const struct usb_string_langid usb_lang_id = { .bLength = sizeof(usb_lang_id), .bDescriptorType = USB_DESC_TYPE_STRING, - .bLangID = htousbs(USB_LANGID_ENGLISH_UK), + .bLangID = htousbs(USB_LANGID_ENGLISH_US), }; static const uint8_t usb_vendor_id[28] = { @@ -107,11 +83,13 @@ static const uint8_t usb_vendor_id[28] = { int32_t PIOS_USB_BOARD_DATA_Init(void) { /* Load device serial number into serial number string */ - uint8_t sn[25]; + uint8_t sn[PIOS_SYS_SERIAL_NUM_ASCII_LEN + 1]; PIOS_SYS_SerialNumberGet((char *)sn); - for (uint8_t i = 0; sn[i] != '\0' && (2 * i) < usb_serial_number[0]; i++) { - usb_serial_number[2 + 2 * i] = sn[i]; - } + + /* Concatenate the device serial number and the appropriate suffix ("+BL" or "+FW") into the USB serial number */ + uint8_t * utf8 = &(usb_serial_number[2]); + utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, sn, PIOS_SYS_SERIAL_NUM_ASCII_LEN); + utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, (uint8_t *)PIOS_USB_BOARD_SN_SUFFIX, sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1); PIOS_USBHOOK_RegisterString(USB_STRING_DESC_PRODUCT, (uint8_t *)&usb_product_id, sizeof(usb_product_id)); PIOS_USBHOOK_RegisterString(USB_STRING_DESC_SERIAL, (uint8_t *)&usb_serial_number, sizeof(usb_serial_number)); diff --git a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c index 13fd988f2..1d4f0a9b2 100644 --- a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c +++ b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c @@ -38,9 +38,9 @@ static const struct usb_device_desc device_desc = { .bLength = sizeof(struct usb_device_desc), .bDescriptorType = USB_DESC_TYPE_DEVICE, .bcdUSB = htousbs(0x0200), - .bDeviceClass = 0x02, - .bDeviceSubClass = 0x00, - .bDeviceProtocol = 0x00, + .bDeviceClass = 0xef, + .bDeviceSubClass = 0x02, + .bDeviceProtocol = 0x01, .bMaxPacketSize0 = 64, /* Must be 64 for high-speed devices */ .idVendor = htousbs(USB_VENDOR_ID_OPENPILOT), .idProduct = htousbs(PIOS_USB_BOARD_PRODUCT_ID), @@ -98,10 +98,6 @@ static const uint8_t hid_report_desc[36] = { struct usb_config_hid_cdc { struct usb_configuration_desc config; struct usb_interface_association_desc iad; - struct usb_interface_desc hid_if; - struct usb_hid_desc hid; - struct usb_endpoint_desc hid_in; - struct usb_endpoint_desc hid_out; struct usb_interface_desc cdc_control_if; struct usb_cdc_header_func_desc cdc_header; struct usb_cdc_callmgmt_func_desc cdc_callmgmt; @@ -111,6 +107,10 @@ struct usb_config_hid_cdc { struct usb_interface_desc cdc_data_if; struct usb_endpoint_desc cdc_in; struct usb_endpoint_desc cdc_out; + struct usb_interface_desc hid_if; + struct usb_hid_desc hid; + struct usb_endpoint_desc hid_in; + struct usb_endpoint_desc hid_out; } __attribute__((packed)); static const struct usb_config_hid_cdc config_hid_cdc = { @@ -129,15 +129,87 @@ static const struct usb_config_hid_cdc config_hid_cdc = { .bDescriptorType = USB_DESC_TYPE_IAD, .bFirstInterface = 0, .bInterfaceCount = 2, - .bFunctionClass = 2, /* Communication */ - .bFunctionSubClass = 2, /* Abstract Control Model */ - .bFunctionProtocol = 0, /* V.25ter, Common AT commands */ + .bFunctionClass = USB_INTERFACE_CLASS_CDC, /* Communication */ + .bFunctionSubClass = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL, /* Abstract Control Model */ + .bFunctionProtocol = 1, /* V.25ter, Common AT commands */ .iInterface = 0, }, + .cdc_control_if = { + .bLength = sizeof(struct usb_interface_desc), + .bDescriptorType = USB_DESC_TYPE_INTERFACE, + .bInterfaceNumber = 0, + .bAlternateSetting = 0, + .bNumEndpoints = 1, + .bInterfaceClass = USB_INTERFACE_CLASS_CDC, + .bInterfaceSubClass = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL, /* Abstract Control Model */ + .nInterfaceProtocol = 1, /* V.25ter, Common AT commands */ + .iInterface = 0, + }, + .cdc_header = { + .bLength = sizeof(struct usb_cdc_header_func_desc), + .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, + .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_HEADER, + .bcdCDC = htousbs(0x0110), + }, + .cdc_callmgmt = { + .bLength = sizeof(struct usb_cdc_callmgmt_func_desc), + .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, + .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_CALLMGMT, + .bmCapabilities = 0x00, /* No call handling */ + .bDataInterface = 1, + }, + .cdc_acm = { + .bLength = sizeof(struct usb_cdc_acm_func_desc), + .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, + .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL, + .bmCapabilities = 0x00, + }, + .cdc_union = { + .bLength = sizeof(struct usb_cdc_union_func_desc), + .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, + .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_UNION, + .bMasterInterface = 0, + .bSlaveInterface = 1, + }, + .cdc_mgmt_in = { + .bLength = sizeof(struct usb_endpoint_desc), + .bDescriptorType = USB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = USB_EP_IN(2), + .bmAttributes = USB_EP_ATTR_TT_INTERRUPT, + .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_MGMT_LENGTH), + .bInterval = 4, /* ms */ + }, + .cdc_data_if = { + .bLength = sizeof(struct usb_interface_desc), + .bDescriptorType = USB_DESC_TYPE_INTERFACE, + .bInterfaceNumber = 1, + .bAlternateSetting = 0, + .bNumEndpoints = 2, + .bInterfaceClass = USB_INTERFACE_CLASS_DATA, + .bInterfaceSubClass = 0, + .nInterfaceProtocol = 0, /* No class specific protocol */ + .iInterface = 0, + }, + .cdc_in = { + .bLength = sizeof(struct usb_endpoint_desc), + .bDescriptorType = USB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = USB_EP_IN(3), + .bmAttributes = USB_EP_ATTR_TT_BULK, + .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_DATA_LENGTH), + .bInterval = 0, /* ms */ + }, + .cdc_out = { + .bLength = sizeof(struct usb_endpoint_desc), + .bDescriptorType = USB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = USB_EP_OUT(3), + .bmAttributes = USB_EP_ATTR_TT_BULK, /* Bulk */ + .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_DATA_LENGTH), + .bInterval = 0, /* ms */ + }, .hid_if = { .bLength = sizeof(struct usb_interface_desc), .bDescriptorType = USB_DESC_TYPE_INTERFACE, - .bInterfaceNumber = 0, + .bInterfaceNumber = 2, .bAlternateSetting = 0, .bNumEndpoints = 2, .bInterfaceClass = USB_INTERFACE_CLASS_HID, @@ -170,78 +242,6 @@ static const struct usb_config_hid_cdc config_hid_cdc = { .wMaxPacketSize = htousbs(PIOS_USB_BOARD_HID_DATA_LENGTH), .bInterval = 4, /* ms */ }, - .cdc_control_if = { - .bLength = sizeof(struct usb_interface_desc), - .bDescriptorType = USB_DESC_TYPE_INTERFACE, - .bInterfaceNumber = 1, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_INTERFACE_CLASS_CDC, - .bInterfaceSubClass = 2, /* Abstract Control Model */ - .nInterfaceProtocol = 1, /* V.25ter, Common AT commands */ - .iInterface = 0, - }, - .cdc_header = { - .bLength = sizeof(struct usb_cdc_header_func_desc), - .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, - .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_HEADER, - .bcdCDC = htousbs(0x0110), - }, - .cdc_callmgmt = { - .bLength = sizeof(struct usb_cdc_callmgmt_func_desc), - .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, - .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_CALLMGMT, - .bmCapabilities = 0x00, /* No call handling */ - .bDataInterface = 2, - }, - .cdc_acm = { - .bLength = sizeof(struct usb_cdc_acm_func_desc), - .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, - .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL, - .bmCapabilities = 0, - }, - .cdc_union = { - .bLength = sizeof(struct usb_cdc_union_func_desc), - .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, - .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_UNION, - .bMasterInterface = 1, - .bSlaveInterface = 2, - }, - .cdc_mgmt_in = { - .bLength = sizeof(struct usb_endpoint_desc), - .bDescriptorType = USB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = USB_EP_IN(2), - .bmAttributes = USB_EP_ATTR_TT_INTERRUPT, - .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_MGMT_LENGTH), - .bInterval = 4, /* ms */ - }, - .cdc_data_if = { - .bLength = sizeof(struct usb_interface_desc), - .bDescriptorType = USB_DESC_TYPE_INTERFACE, - .bInterfaceNumber = 2, - .bAlternateSetting = 0, - .bNumEndpoints = 2, - .bInterfaceClass = USB_INTERFACE_CLASS_DATA, - .bInterfaceSubClass = 0, - .nInterfaceProtocol = 0, /* No class specific protocol */ - .iInterface = 0, - }, - .cdc_in = { - .bLength = sizeof(struct usb_endpoint_desc), - .bDescriptorType = USB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = USB_EP_IN(3), - .bmAttributes = USB_EP_ATTR_TT_BULK, - .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_DATA_LENGTH), - .bInterval = 0, /* ms */ - }, - .cdc_out = { - .bLength = sizeof(struct usb_endpoint_desc), - .bDescriptorType = USB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = USB_EP_OUT(3), - .bmAttributes = USB_EP_ATTR_TT_BULK, /* Bulk */ - .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_DATA_LENGTH), - .bInterval = 0, /* ms */ - }, }; int32_t PIOS_USB_DESC_HID_CDC_Init(void) diff --git a/flight/PiOS/Common/pios_usb_util.c b/flight/PiOS/Common/pios_usb_util.c new file mode 100644 index 000000000..4bbf98d23 --- /dev/null +++ b/flight/PiOS/Common/pios_usb_util.c @@ -0,0 +1,42 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_USB_UTIL USB utility functions + * @brief USB utility functions + * @{ + * + * @file pios_usb_util.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @brief USB utility functions + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "pios_usb_util.h" + +uint8_t * PIOS_USB_UTIL_AsciiToUtf8(uint8_t * dst, uint8_t * src, uint16_t srclen) +{ + for (uint8_t i = 0; i < srclen; i++) { + *dst = *src; + dst += 2; + src += 1; + } + + return dst; +} diff --git a/flight/PiOS/STM32F10x/pios_sys.c b/flight/PiOS/STM32F10x/pios_sys.c index 04d79c45b..6b59afbad 100644 --- a/flight/PiOS/STM32F10x/pios_sys.c +++ b/flight/PiOS/STM32F10x/pios_sys.c @@ -118,8 +118,8 @@ uint32_t PIOS_SYS_getCPUFlashSize(void) /** * Returns the serial number as a string -* param[out] str pointer to a string which can store at least 32 digits + zero terminator! -* (24 digits returned for STM32) +* param[out] uint8_t pointer to a string which can store at least 12 bytes +* (12 bytes returned for STM32) * return < 0 if feature not supported */ int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array) @@ -127,7 +127,7 @@ int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array) int i; /* Stored in the so called "electronic signature" */ - for (i = 0; i < 12; ++i) { + for (i = 0; i < PIOS_SYS_SERIAL_NUM_BINARY_LEN; ++i) { uint8_t b = MEM8(0x1ffff7e8 + i); array[i] = b; @@ -148,7 +148,7 @@ int32_t PIOS_SYS_SerialNumberGet(char *str) int i; /* Stored in the so called "electronic signature" */ - for (i = 0; i < 24; ++i) { + for (i = 0; i < PIOS_SYS_SERIAL_NUM_ASCII_LEN; ++i) { uint8_t b = MEM8(0x1ffff7e8 + (i / 2)); if (!(i & 1)) b >>= 4; diff --git a/flight/PiOS/STM32F10x/pios_usb.c b/flight/PiOS/STM32F10x/pios_usb.c index c7b2855da..ea279233c 100644 --- a/flight/PiOS/STM32F10x/pios_usb.c +++ b/flight/PiOS/STM32F10x/pios_usb.c @@ -222,7 +222,6 @@ bool PIOS_USB_CheckAvailable(uint8_t id) return 0; usb_found = (usb_dev->cfg->vsense.gpio->IDR & usb_dev->cfg->vsense.init.GPIO_Pin); - return usb_found; return usb_found != 0 && transfer_possible ? 1 : 0; } diff --git a/flight/PiOS/STM32F10x/pios_usbhook.c b/flight/PiOS/STM32F10x/pios_usbhook.c index c6a952498..cb3220227 100644 --- a/flight/PiOS/STM32F10x/pios_usbhook.c +++ b/flight/PiOS/STM32F10x/pios_usbhook.c @@ -304,7 +304,11 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo) switch (Type_Recipient) { case (STANDARD_REQUEST | INTERFACE_RECIPIENT): switch (pInformation->USBwIndex0) { +#if defined(PIOS_INCLUDE_USB_CDC) + case 2: /* HID Interface */ +#else case 0: /* HID Interface */ +#endif switch (RequestNo) { case GET_DESCRIPTOR: switch (pInformation->USBwValue1) { @@ -321,7 +325,11 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo) case (CLASS_REQUEST | INTERFACE_RECIPIENT): switch (pInformation->USBwIndex0) { +#if defined(PIOS_INCLUDE_USB_CDC) + case 2: /* HID Interface */ +#else case 0: /* HID Interface */ +#endif switch (RequestNo) { case USB_HID_REQ_GET_PROTOCOL: CopyRoutine = PIOS_USBHOOK_GetProtocolValue; @@ -330,16 +338,16 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo) break; #if defined(PIOS_INCLUDE_USB_CDC) - case 1: /* CDC Call Control Interface */ + case 0: /* CDC Call Control Interface */ switch (RequestNo) { case USB_CDC_REQ_GET_LINE_CODING: - CopyRoutine = PIOS_USB_CDC_GetLineCoding; + //CopyRoutine = PIOS_USB_CDC_GetLineCoding; break; } break; - case 2: /* CDC Data Interface */ + case 1: /* CDC Data Interface */ switch (RequestNo) { case 0: break; @@ -376,7 +384,11 @@ static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo) switch (Type_Recipient) { case (CLASS_REQUEST | INTERFACE_RECIPIENT): switch (pInformation->USBwIndex0) { +#if defined(PIOS_INCLUDE_USB_CDC) + case 2: /* HID */ +#else case 0: /* HID */ +#endif switch (RequestNo) { case USB_HID_REQ_SET_PROTOCOL: return PIOS_USBHOOK_SetProtocol(); @@ -386,7 +398,7 @@ static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo) break; #if defined(PIOS_INCLUDE_USB_CDC) - case 1: /* CDC Call Control Interface */ + case 0: /* CDC Call Control Interface */ switch (RequestNo) { case USB_CDC_REQ_SET_LINE_CODING: return PIOS_USB_CDC_SetLineCoding(); diff --git a/flight/PiOS/inc/pios_sys.h b/flight/PiOS/inc/pios_sys.h index 9407fa720..7f183a892 100644 --- a/flight/PiOS/inc/pios_sys.h +++ b/flight/PiOS/inc/pios_sys.h @@ -32,12 +32,15 @@ #ifndef PIOS_SYS_H #define PIOS_SYS_H +#define PIOS_SYS_SERIAL_NUM_BINARY_LEN 12 +#define PIOS_SYS_SERIAL_NUM_ASCII_LEN (PIOS_SYS_SERIAL_NUM_BINARY_LEN * 2) + /* Public Functions */ extern void PIOS_SYS_Init(void); extern int32_t PIOS_SYS_Reset(void); extern uint32_t PIOS_SYS_getCPUFlashSize(void); -extern int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array); -extern int32_t PIOS_SYS_SerialNumberGet(char *str); +extern int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t array[PIOS_SYS_SERIAL_NUM_BINARY_LEN]); +extern int32_t PIOS_SYS_SerialNumberGet(char str[PIOS_SYS_SERIAL_NUM_ASCII_LEN+1]); #endif /* PIOS_SYS_H */ diff --git a/flight/PiOS/inc/pios_usb_defs.h b/flight/PiOS/inc/pios_usb_defs.h index f0352333f..be827a494 100644 --- a/flight/PiOS/inc/pios_usb_defs.h +++ b/flight/PiOS/inc/pios_usb_defs.h @@ -300,7 +300,7 @@ struct usb_cdc_union_func_desc { uint8_t bSlaveInterface; } __attribute__((packed)); -#define USB_LANGID_ENGLISH_UK 0x0809 +#define USB_LANGID_ENGLISH_US 0x0409 struct usb_string_langid { uint8_t bLength; diff --git a/flight/PiOS/inc/pios_usb_util.h b/flight/PiOS/inc/pios_usb_util.h new file mode 100644 index 000000000..111b49239 --- /dev/null +++ b/flight/PiOS/inc/pios_usb_util.h @@ -0,0 +1,38 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_USB_UTIL USB utility functions + * @brief USB utility functions + * @{ + * + * @file pios_usb_util.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @brief USB utility functions + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PIOS_USB_UTIL_H +#define PIOS_USB_UTIL_H + +#include /* uint8_t */ + +uint8_t * PIOS_USB_UTIL_AsciiToUtf8(uint8_t * dst, uint8_t * src, uint16_t srclen); + +#endif /* PIOS_USB_UTIL_H */ diff --git a/flight/PipXtreme/Makefile b/flight/PipXtreme/Makefile index 8872a9f8d..635d46b53 100644 --- a/flight/PipXtreme/Makefile +++ b/flight/PipXtreme/Makefile @@ -162,16 +162,17 @@ SRC += $(PIOSSTM32F10X)/pios_pwm.c SRC += $(PIOSSTM32F10X)/pios_eeprom.c SRC += $(PIOSSTM32F10X)/pios_bl_helper.c -# PIOS USB related files (separated to make code maintenance more easy) -SRC += $(PIOSSTM32F10X)/pios_usb.c -SRC += $(PIOSSTM32F10X)/pios_usbhook.c -SRC += $(PIOSSTM32F10X)/pios_usb_hid.c -SRC += $(PIOSSTM32F10X)/pios_usb_cdc.c -SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c -SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c -SRC += $(OPSYSTEM)/pios_usb_board_data.c -SRC += $(PIOSCOMMON)/pios_usb_desc_hid_cdc.c -SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c +# PIOS USB related files (seperated to make code maintenance more easy) +ifeq ($(USE_USB), YES) + SRC += $(PIOSSTM32F10X)/pios_usb.c + SRC += $(PIOSSTM32F10X)/pios_usbhook.c + SRC += $(PIOSSTM32F10X)/pios_usb_hid.c + SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c + SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c + SRC += $(HOME_DIR)/pios_usb_board_data.c + SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c + SRC += $(PIOSCOMMON)/pios_usb_util.c +endif ## PIOS Hardware (Common) SRC += $(PIOSCOMMON)/pios_crc.c diff --git a/flight/PipXtreme/System/inc/pios_usb_board_data.h b/flight/PipXtreme/System/inc/pios_usb_board_data.h index daef4b3e0..4448831d8 100644 --- a/flight/PipXtreme/System/inc/pios_usb_board_data.h +++ b/flight/PipXtreme/System/inc/pios_usb_board_data.h @@ -41,5 +41,6 @@ #define PIOS_USB_BOARD_PRODUCT_ID USB_PRODUCT_ID_PIPXTREME #define PIOS_USB_BOARD_DEVICE_VER USB_OP_DEVICE_VER(USB_OP_BOARD_ID_PIPXTREME, USB_OP_BOARD_MODE_FW) +#define PIOS_USB_BOARD_SN_SUFFIX "+FW" #endif /* PIOS_USB_BOARD_DATA_H */ diff --git a/flight/PipXtreme/System/pios_usb_board_data.c b/flight/PipXtreme/System/pios_usb_board_data.c index 3e41e5ac9..c2e0c8762 100644 --- a/flight/PipXtreme/System/pios_usb_board_data.c +++ b/flight/PipXtreme/System/pios_usb_board_data.c @@ -31,6 +31,7 @@ #include "pios_usb_board_data.h" /* struct usb_*, USB_* */ #include "pios_sys.h" /* PIOS_SYS_SerialNumberGet */ #include "pios_usbhook.h" /* PIOS_USBHOOK_* */ +#include "pios_usb_util.h" /* PIOS_USB_UTIL_AsciiToUtf8 */ static const uint8_t usb_product_id[20] = { sizeof(usb_product_id), @@ -46,40 +47,15 @@ static const uint8_t usb_product_id[20] = { 'e', 0, }; -static uint8_t usb_serial_number[52] = { +static uint8_t usb_serial_number[2 + PIOS_SYS_SERIAL_NUM_ASCII_LEN*2 + (sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1)*2] = { sizeof(usb_serial_number), USB_DESC_TYPE_STRING, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0, - 0, 0 }; static const struct usb_string_langid usb_lang_id = { .bLength = sizeof(usb_lang_id), .bDescriptorType = USB_DESC_TYPE_STRING, - .bLangID = htousbs(USB_LANGID_ENGLISH_UK), + .bLangID = htousbs(USB_LANGID_ENGLISH_US), }; static const uint8_t usb_vendor_id[28] = { @@ -103,11 +79,13 @@ static const uint8_t usb_vendor_id[28] = { int32_t PIOS_USB_BOARD_DATA_Init(void) { /* Load device serial number into serial number string */ - uint8_t sn[25]; + uint8_t sn[PIOS_SYS_SERIAL_NUM_ASCII_LEN + 1]; PIOS_SYS_SerialNumberGet((char *)sn); - for (uint8_t i = 0; sn[i] != '\0' && (2 * i) < usb_serial_number[0]; i++) { - usb_serial_number[2 + 2 * i] = sn[i]; - } + + /* Concatenate the device serial number and the appropriate suffix ("+BL" or "+FW") into the USB serial number */ + uint8_t * utf8 = &(usb_serial_number[2]); + utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, sn, PIOS_SYS_SERIAL_NUM_ASCII_LEN); + utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, (uint8_t *)PIOS_USB_BOARD_SN_SUFFIX, sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1); PIOS_USBHOOK_RegisterString(USB_STRING_DESC_PRODUCT, (uint8_t *)&usb_product_id, sizeof(usb_product_id)); PIOS_USBHOOK_RegisterString(USB_STRING_DESC_SERIAL, (uint8_t *)&usb_serial_number, sizeof(usb_serial_number)); diff --git a/flight/Project/Windows USB/OpenPilot-CDC.inf b/flight/Project/Windows USB/OpenPilot-CDC.inf new file mode 100644 index 000000000..a33223129 --- /dev/null +++ b/flight/Project/Windows USB/OpenPilot-CDC.inf @@ -0,0 +1,32 @@ +[Version] +Signature="$Windows NT$" +Class=Ports +ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} +Provider=%ProviderName% +DriverVer=10/15/2009,1.0.0.0 + +[MANUFACTURER] +%ProviderName%=DeviceList, NTx86, NTamd64 + +[DeviceList.NTx86] +%CopterControl%= DriverInstall,USB\VID_20A0&PID_415b&MI_00 + +[DeviceList.NTamd64] +%CopterControl%= DriverInstall,USB\VID_20A0&PID_415b&MI_00 + +[DriverInstall] +include=mdmcpq.inf +CopyFiles=FakeModemCopyFileSection +AddReg=LowerFilterAddReg,SerialPropPageAddReg + +[DriverInstall.Services] +include = mdmcpq.inf +AddService = usbser, 0x00000002, LowerFilter_Service_Inst + +; This adds the serial port property tab to the device properties dialog +[SerialPropPageAddReg] +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[Strings] +ProviderName = "CDC Driver" +CopterControl = "OpenPilot CDC Driver" diff --git a/flight/board_hw_defs/coptercontrol/board_hw_defs.c b/flight/board_hw_defs/coptercontrol/board_hw_defs.c index cb1ce745e..43f9360b8 100644 --- a/flight/board_hw_defs/coptercontrol/board_hw_defs.c +++ b/flight/board_hw_defs/coptercontrol/board_hw_defs.c @@ -1263,20 +1263,21 @@ static const struct pios_usb_cfg pios_usb_main_cfg_cc3d = { #include const struct pios_usb_hid_cfg pios_usb_hid_cfg = { - .data_if = 0, + .data_if = 2, .data_rx_ep = 1, .data_tx_ep = 1, }; + #endif /* PIOS_INCLUDE_USB_HID */ #if defined(PIOS_INCLUDE_USB_CDC) #include const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = { - .ctrl_if = 1, + .ctrl_if = 0, .ctrl_tx_ep = 2, - .data_if = 2, + .data_if = 1, .data_rx_ep = 3, .data_tx_ep = 3, }; diff --git a/make/boards/coptercontrol/board-info.mk b/make/boards/coptercontrol/board-info.mk index dcad2f43e..674ad4152 100644 --- a/make/boards/coptercontrol/board-info.mk +++ b/make/boards/coptercontrol/board-info.mk @@ -1,6 +1,6 @@ BOARD_TYPE := 0x04 BOARD_REVISION := 0x02 -BOOTLOADER_VERSION := 0x02 +BOOTLOADER_VERSION := 0x03 HW_TYPE := 0x01 MCU := cortex-m3 diff --git a/make/boards/pipxtreme/board-info.mk b/make/boards/pipxtreme/board-info.mk index 3c814a0da..045721092 100644 --- a/make/boards/pipxtreme/board-info.mk +++ b/make/boards/pipxtreme/board-info.mk @@ -1,6 +1,6 @@ BOARD_TYPE := 0x03 BOARD_REVISION := 0x01 -BOOTLOADER_VERSION := 0x01 +BOOTLOADER_VERSION := 0x02 HW_TYPE := 0x01 MCU := cortex-m3 diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index 712546582..0cee2a6d9 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -15,7 +15,6 @@ -