stmhal: Change USB PID when in CDC+HID mode.
This gets CDC+HID working on Windows, since it needs a different PID for a different USB configuration. Thanks to tmbinc and dhylands.
This commit is contained in:
parent
627852019b
commit
d7353fe6fe
@ -58,10 +58,14 @@ void pyb_usb_dev_init(usb_device_mode_t mode, usb_storage_medium_t medium) {
|
|||||||
#ifdef USE_DEVICE_MODE
|
#ifdef USE_DEVICE_MODE
|
||||||
if (!dev_is_enabled) {
|
if (!dev_is_enabled) {
|
||||||
// only init USB once in the device's power-lifetime
|
// only init USB once in the device's power-lifetime
|
||||||
|
// Windows needs a different PID to distinguish different device
|
||||||
|
// configurations, so we set it here depending on mode.
|
||||||
if (mode == USB_DEVICE_MODE_CDC_MSC) {
|
if (mode == USB_DEVICE_MODE_CDC_MSC) {
|
||||||
USBD_SelectMode(USBD_MODE_CDC_MSC);
|
USBD_SelectMode(USBD_MODE_CDC_MSC);
|
||||||
|
USBD_SetPID(0x9800);
|
||||||
} else {
|
} else {
|
||||||
USBD_SelectMode(USBD_MODE_CDC_HID);
|
USBD_SelectMode(USBD_MODE_CDC_HID);
|
||||||
|
USBD_SetPID(0x9801);
|
||||||
}
|
}
|
||||||
USBD_Init(&hUSBDDevice, (USBD_DescriptorsTypeDef*)&VCP_Desc, 0);
|
USBD_Init(&hUSBDDevice, (USBD_DescriptorsTypeDef*)&VCP_Desc, 0);
|
||||||
USBD_RegisterClass(&hUSBDDevice, &USBD_CDC_MSC_HID);
|
USBD_RegisterClass(&hUSBDDevice, &USBD_CDC_MSC_HID);
|
||||||
|
@ -25,3 +25,5 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
extern const USBD_DescriptorsTypeDef VCP_Desc;
|
extern const USBD_DescriptorsTypeDef VCP_Desc;
|
||||||
|
|
||||||
|
void USBD_SetPID(uint16_t pid);
|
||||||
|
@ -29,14 +29,10 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
#include "usbd_desc.h"
|
#include "usbd_desc.h"
|
||||||
#include "usbd_conf.h"
|
#include "usbd_conf.h"
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
|
|
||||||
// So we don't clash with existing ST boards, we use the unofficial FOSS VID.
|
// So we don't clash with existing ST boards, we use the unofficial FOSS VID.
|
||||||
// This needs a proper solution.
|
// This needs a proper solution.
|
||||||
#define USBD_VID 0xf055
|
#define USBD_VID 0xf055
|
||||||
@ -52,74 +48,28 @@
|
|||||||
#define USBD_CONFIGURATION_FS_STRING "VCP Config"
|
#define USBD_CONFIGURATION_FS_STRING "VCP Config"
|
||||||
#define USBD_INTERFACE_FS_STRING "VCP Interface"
|
#define USBD_INTERFACE_FS_STRING "VCP Interface"
|
||||||
|
|
||||||
/*
|
// USB Standard Device Descriptor
|
||||||
#define USBD_VID 0x0483
|
__ALIGN_BEGIN static uint8_t hUSBDDeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
|
||||||
#define USBD_PID 0x5740
|
0x12, // bLength
|
||||||
#define USBD_LANGID_STRING 0x409
|
USB_DESC_TYPE_DEVICE, // bDescriptorType
|
||||||
#define USBD_MANUFACTURER_STRING "STMicroelectronics"
|
0x00, // bcdUSB
|
||||||
#define USBD_PRODUCT_HS_STRING "STM32 Virtual ComPort in HS Mode"
|
0x02,
|
||||||
#define USBD_SERIALNUMBER_HS_STRING "00000000001A"
|
0x00, // bDeviceClass
|
||||||
#define USBD_PRODUCT_FS_STRING "STM32 Virtual ComPort in FS Mode"
|
0x00, // bDeviceSubClass
|
||||||
#define USBD_SERIALNUMBER_FS_STRING "00000000001B"
|
0x00, // bDeviceProtocol
|
||||||
#define USBD_CONFIGURATION_HS_STRING "VCP Config"
|
USB_MAX_EP0_SIZE, // bMaxPacketSize
|
||||||
#define USBD_INTERFACE_HS_STRING "VCP Interface"
|
LOBYTE(USBD_VID), // idVendor
|
||||||
#define USBD_CONFIGURATION_FS_STRING "VCP Config"
|
HIBYTE(USBD_VID), // idVendor
|
||||||
#define USBD_INTERFACE_FS_STRING "VCP Interface"
|
LOBYTE(USBD_PID), // idVendor
|
||||||
*/
|
HIBYTE(USBD_PID), // idVendor
|
||||||
|
0x00, // bcdDevice rel. 2.00
|
||||||
/* Private macro -------------------------------------------------------------*/
|
0x02,
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
USBD_IDX_MFC_STR, // Index of manufacturer string
|
||||||
uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
USBD_IDX_PRODUCT_STR, // Index of product string
|
||||||
uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
USBD_IDX_SERIAL_STR, // Index of serial number string
|
||||||
uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
USBD_MAX_NUM_CONFIGURATION // bNumConfigurations
|
||||||
uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
|
||||||
uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
|
||||||
uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
|
||||||
uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
|
||||||
#ifdef USB_SUPPORT_USER_STRING_DESC
|
|
||||||
uint8_t *USBD_VCP_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
|
||||||
#endif /* USB_SUPPORT_USER_STRING_DESC */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
const USBD_DescriptorsTypeDef VCP_Desc = {
|
|
||||||
USBD_VCP_DeviceDescriptor,
|
|
||||||
USBD_VCP_LangIDStrDescriptor,
|
|
||||||
USBD_VCP_ManufacturerStrDescriptor,
|
|
||||||
USBD_VCP_ProductStrDescriptor,
|
|
||||||
USBD_VCP_SerialStrDescriptor,
|
|
||||||
USBD_VCP_ConfigStrDescriptor,
|
|
||||||
USBD_VCP_InterfaceStrDescriptor,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* USB Standard Device Descriptor */
|
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
|
||||||
#pragma data_alignment=4
|
|
||||||
#endif
|
|
||||||
__ALIGN_BEGIN static uint8_t hUSBDDeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
|
|
||||||
0x12, /* bLength */
|
|
||||||
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
|
|
||||||
0x00, /* bcdUSB */
|
|
||||||
0x02,
|
|
||||||
0x00, /* bDeviceClass */
|
|
||||||
0x00, /* bDeviceSubClass */
|
|
||||||
0x00, /* bDeviceProtocol */
|
|
||||||
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
|
|
||||||
LOBYTE(USBD_VID), /* idVendor */
|
|
||||||
HIBYTE(USBD_VID), /* idVendor */
|
|
||||||
LOBYTE(USBD_PID), /* idVendor */
|
|
||||||
HIBYTE(USBD_PID), /* idVendor */
|
|
||||||
0x00, /* bcdDevice rel. 2.00 */
|
|
||||||
0x02,
|
|
||||||
USBD_IDX_MFC_STR, /* Index of manufacturer string */
|
|
||||||
USBD_IDX_PRODUCT_STR, /* Index of product string */
|
|
||||||
USBD_IDX_SERIAL_STR, /* Index of serial number string */
|
|
||||||
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
|
|
||||||
}; /* USB_DeviceDescriptor */
|
|
||||||
|
|
||||||
/* USB Standard Device Descriptor */
|
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
|
||||||
#pragma data_alignment=4
|
|
||||||
#endif
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
|
__ALIGN_BEGIN static uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
|
||||||
USB_LEN_LANGID_STR_DESC,
|
USB_LEN_LANGID_STR_DESC,
|
||||||
USB_DESC_TYPE_STRING,
|
USB_DESC_TYPE_STRING,
|
||||||
@ -127,12 +77,13 @@ __ALIGN_BEGIN static uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_EN
|
|||||||
HIBYTE(USBD_LANGID_STRING),
|
HIBYTE(USBD_LANGID_STRING),
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
|
||||||
#pragma data_alignment=4
|
|
||||||
#endif
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
__ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
// set the PID
|
||||||
|
void USBD_SetPID(uint16_t pid) {
|
||||||
|
hUSBDDeviceDesc[10] = LOBYTE(pid);
|
||||||
|
hUSBDDeviceDesc[11] = HIBYTE(pid);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the device descriptor.
|
* @brief Returns the device descriptor.
|
||||||
@ -140,8 +91,7 @@ __ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
|||||||
* @param length: Pointer to data length variable
|
* @param length: Pointer to data length variable
|
||||||
* @retval Pointer to descriptor buffer
|
* @retval Pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
STATIC uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
|
||||||
{
|
|
||||||
*length = sizeof(hUSBDDeviceDesc);
|
*length = sizeof(hUSBDDeviceDesc);
|
||||||
return hUSBDDeviceDesc;
|
return hUSBDDeviceDesc;
|
||||||
}
|
}
|
||||||
@ -152,8 +102,7 @@ uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
|||||||
* @param length: Pointer to data length variable
|
* @param length: Pointer to data length variable
|
||||||
* @retval Pointer to descriptor buffer
|
* @retval Pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
STATIC uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
|
||||||
{
|
|
||||||
*length = sizeof(USBD_LangIDDesc);
|
*length = sizeof(USBD_LangIDDesc);
|
||||||
return USBD_LangIDDesc;
|
return USBD_LangIDDesc;
|
||||||
}
|
}
|
||||||
@ -164,14 +113,10 @@ uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
|||||||
* @param length: Pointer to data length variable
|
* @param length: Pointer to data length variable
|
||||||
* @retval Pointer to descriptor buffer
|
* @retval Pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
STATIC uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
|
||||||
{
|
if(speed == 0) {
|
||||||
if(speed == 0)
|
|
||||||
{
|
|
||||||
USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
||||||
}
|
}
|
||||||
return USBD_StrDesc;
|
return USBD_StrDesc;
|
||||||
@ -183,8 +128,7 @@ uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
|
|||||||
* @param length: Pointer to data length variable
|
* @param length: Pointer to data length variable
|
||||||
* @retval Pointer to descriptor buffer
|
* @retval Pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
STATIC uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
|
||||||
{
|
|
||||||
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||||
return USBD_StrDesc;
|
return USBD_StrDesc;
|
||||||
}
|
}
|
||||||
@ -195,14 +139,10 @@ uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *l
|
|||||||
* @param length: Pointer to data length variable
|
* @param length: Pointer to data length variable
|
||||||
* @retval Pointer to descriptor buffer
|
* @retval Pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
STATIC uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
|
||||||
{
|
if(speed == USBD_SPEED_HIGH) {
|
||||||
if(speed == USBD_SPEED_HIGH)
|
|
||||||
{
|
|
||||||
USBD_GetString((uint8_t *)USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
USBD_GetString((uint8_t *)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
|
||||||
}
|
}
|
||||||
return USBD_StrDesc;
|
return USBD_StrDesc;
|
||||||
@ -214,14 +154,10 @@ uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
|||||||
* @param length: Pointer to data length variable
|
* @param length: Pointer to data length variable
|
||||||
* @retval Pointer to descriptor buffer
|
* @retval Pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
STATIC uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
|
||||||
{
|
if(speed == USBD_SPEED_HIGH) {
|
||||||
if(speed == USBD_SPEED_HIGH)
|
|
||||||
{
|
|
||||||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
|
||||||
}
|
}
|
||||||
return USBD_StrDesc;
|
return USBD_StrDesc;
|
||||||
@ -233,18 +169,23 @@ uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
|||||||
* @param length: Pointer to data length variable
|
* @param length: Pointer to data length variable
|
||||||
* @retval Pointer to descriptor buffer
|
* @retval Pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
STATIC uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
|
||||||
{
|
if(speed == 0) {
|
||||||
if(speed == 0)
|
|
||||||
{
|
|
||||||
USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
|
||||||
}
|
}
|
||||||
return USBD_StrDesc;
|
return USBD_StrDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
const USBD_DescriptorsTypeDef VCP_Desc = {
|
||||||
|
USBD_VCP_DeviceDescriptor,
|
||||||
|
USBD_VCP_LangIDStrDescriptor,
|
||||||
|
USBD_VCP_ManufacturerStrDescriptor,
|
||||||
|
USBD_VCP_ProductStrDescriptor,
|
||||||
|
USBD_VCP_SerialStrDescriptor,
|
||||||
|
USBD_VCP_ConfigStrDescriptor,
|
||||||
|
USBD_VCP_InterfaceStrDescriptor,
|
||||||
|
};
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
Loading…
Reference in New Issue
Block a user