Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
39ce2db1
Commit
39ce2db1
authored
Feb 03, 2015
by
Damien George
Browse files
stmhal: Add "CDC" option to pyb.usb_mode, for CDC device only.
parent
d39c7aa5
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
stmhal/Makefile
View file @
39ce2db1
...
...
@@ -94,7 +94,7 @@ SRC_C = \
system_stm32f4xx.c
\
stm32f4xx_it.c
\
usbd_conf.c
\
usbd_desc
_cdc_msc
.c
\
usbd_desc.c
\
usbd_cdc_interface.c
\
usbd_msc_storage.c
\
mphal.c
\
...
...
@@ -281,7 +281,7 @@ GEN_PINS_AF_PY = $(BUILD)/pins_af.py
INSERT_USB_IDS
=
../tools/insert-usb-ids.py
FILE2H
=
../tools/file2h.py
USB_IDS_FILE
=
usbd_desc
_cdc_msc
.c
USB_IDS_FILE
=
usbd_desc.c
CDCINF_TEMPLATE
=
pybcdc.inf_template
GEN_CDCINF_FILE
=
$(HEADER_BUILD)
/pybcdc.inf
GEN_CDCINF_HEADER
=
$(HEADER_BUILD)
/pybcdc_inf.h
...
...
stmhal/main.c
View file @
39ce2db1
...
...
@@ -473,7 +473,7 @@ soft_reset:
#if defined(USE_DEVICE_MODE)
// init USB device to default setting if it was not already configured
if
(
!
(
pyb_usb_flags
&
PYB_USB_FLAG_USB_MODE_CALLED
))
{
pyb_usb_dev_init
(
USBD_PID_
DEFAULT
,
USBD_MODE_CDC_MSC
,
NULL
);
pyb_usb_dev_init
(
USBD_PID_
CDC_MSC
,
USBD_MODE_CDC_MSC
,
NULL
);
}
#endif
...
...
stmhal/usb.c
View file @
39ce2db1
...
...
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2013, 2014
, 2015
Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
...
...
@@ -60,7 +60,7 @@ const mp_obj_tuple_t pyb_usb_hid_mouse_obj = {
{
&
mp_type_tuple
},
5
,
{
MP_OBJ_NEW_SMALL_INT
(
USBD_PID_
SECONDARY
),
MP_OBJ_NEW_SMALL_INT
(
USBD_PID_
CDC_HID
),
MP_OBJ_NEW_SMALL_INT
(
1
),
// subclass: boot
MP_OBJ_NEW_SMALL_INT
(
2
),
// protocol: mouse
MP_OBJ_NEW_SMALL_INT
(
USBD_HID_MOUSE_MAX_PACKET
),
...
...
@@ -79,7 +79,7 @@ const mp_obj_tuple_t pyb_usb_hid_keyboard_obj = {
{
&
mp_type_tuple
},
5
,
{
MP_OBJ_NEW_SMALL_INT
(
USBD_PID_
SECONDARY
),
MP_OBJ_NEW_SMALL_INT
(
USBD_PID_
CDC_HID
),
MP_OBJ_NEW_SMALL_INT
(
1
),
// subclass: boot
MP_OBJ_NEW_SMALL_INT
(
1
),
// protocol: keyboard
MP_OBJ_NEW_SMALL_INT
(
USBD_HID_KEYBOARD_MAX_PACKET
),
...
...
@@ -100,7 +100,7 @@ void pyb_usb_dev_init(uint16_t pid, usb_device_mode_t mode, USBD_HID_ModeInfoTyp
// only init USB once in the device's power-lifetime
USBD_SetPID
(
pid
);
USBD_SelectMode
(
mode
,
hid_info
);
USBD_Init
(
&
hUSBDDevice
,
(
USBD_DescriptorsTypeDef
*
)
&
VCP
_Desc
,
0
);
USBD_Init
(
&
hUSBDDevice
,
(
USBD_DescriptorsTypeDef
*
)
&
USBD
_Desc
riptors
,
0
);
USBD_RegisterClass
(
&
hUSBDDevice
,
&
USBD_CDC_MSC_HID
);
USBD_CDC_RegisterInterface
(
&
hUSBDDevice
,
(
USBD_CDC_ItfTypeDef
*
)
&
USBD_CDC_fops
);
switch
(
pyb_usb_storage_medium
)
{
...
...
@@ -213,7 +213,7 @@ STATIC mp_obj_t pyb_usb_mode(mp_uint_t n_args, const mp_obj_t *args) {
#elif defined(USE_DEVICE_MODE)
// USB device
if
(
strcmp
(
mode_str
,
"CDC+MSC"
)
==
0
)
{
pyb_usb_dev_init
(
USBD_PID_
DEFAULT
,
USBD_MODE_CDC_MSC
,
NULL
);
pyb_usb_dev_init
(
USBD_PID_
CDC_MSC
,
USBD_MODE_CDC_MSC
,
NULL
);
}
else
if
(
strcmp
(
mode_str
,
"CDC+HID"
)
==
0
)
{
mp_obj_t
hid_info_obj
=
(
mp_obj_t
)
&
pyb_usb_hid_mouse_obj
;
// default is mouse mode
if
(
n_args
==
2
)
{
...
...
@@ -232,6 +232,8 @@ STATIC mp_obj_t pyb_usb_mode(mp_uint_t n_args, const mp_obj_t *args) {
hid_info
.
report_desc
=
bufinfo
.
buf
;
hid_info
.
report_desc_len
=
bufinfo
.
len
;
pyb_usb_dev_init
(
pid
,
USBD_MODE_CDC_HID
,
&
hid_info
);
}
else
if
(
strcmp
(
mode_str
,
"CDC"
)
==
0
)
{
pyb_usb_dev_init
(
USBD_PID_CDC
,
USBD_MODE_CDC
,
NULL
);
}
else
{
goto
bad_mode
;
}
...
...
stmhal/usb.h
View file @
39ce2db1
...
...
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2013, 2014
, 2015
Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
...
...
@@ -30,8 +30,9 @@
#define PYB_USB_FLAG_USB_MODE_CALLED (0x0002)
// Windows needs a different PID to distinguish different device configurations
#define USBD_PID_DEFAULT (0x9800)
#define USBD_PID_SECONDARY (0x9801)
#define USBD_PID_CDC_MSC (0x9800)
#define USBD_PID_CDC_HID (0x9801)
#define USBD_PID_CDC (0x9802)
typedef
enum
{
PYB_USB_STORAGE_MEDIUM_NONE
=
0
,
...
...
stmhal/usbd_desc
_cdc_msc
.c
→
stmhal/usbd_desc.c
View file @
39ce2db1
...
...
@@ -43,20 +43,21 @@
#define USBD_SERIALNUMBER_HS_STRING "000000000010"
#define USBD_PRODUCT_FS_STRING "Pyboard Virtual Comm Port in FS Mode"
#define USBD_SERIALNUMBER_FS_STRING "000000000011"
#define USBD_CONFIGURATION_HS_STRING "
VCP
Config"
#define USBD_INTERFACE_HS_STRING "
VCP
Interface"
#define USBD_CONFIGURATION_FS_STRING "
VCP
Config"
#define USBD_INTERFACE_FS_STRING "
VCP
Interface"
#define USBD_CONFIGURATION_HS_STRING "
Pyboard
Config"
#define USBD_INTERFACE_HS_STRING "
Pyboard
Interface"
#define USBD_CONFIGURATION_FS_STRING "
Pyboard
Config"
#define USBD_INTERFACE_FS_STRING "
Pyboard
Interface"
// USB Standard Device Descriptor
// needs to be in RAM because we modify the VID and PID
__ALIGN_BEGIN
static
uint8_t
hUSBDDeviceDesc
[
USB_LEN_DEV_DESC
]
__ALIGN_END
=
{
0x12
,
// bLength
USB_DESC_TYPE_DEVICE
,
// bDescriptorType
0x00
,
// bcdUSB
0x02
,
0x
00
,
// bDeviceClass
0x0
0
,
// bDeviceSubClass
0x0
0
,
// bDeviceProtocol
0x
ef
,
// bDeviceClass
: Miscellaneous Device Class
0x0
2
,
// bDeviceSubClass
: Common Class
0x0
1
,
// bDeviceProtocol
: Interface Association Descriptor
USB_MAX_EP0_SIZE
,
// bMaxPacketSize
LOBYTE
(
USBD_VID
),
// idVendor
HIBYTE
(
USBD_VID
),
// idVendor
...
...
@@ -91,7 +92,7 @@ void USBD_SetPID(uint16_t pid) {
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
STATIC
uint8_t
*
USBD_
VCP_
DeviceDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
STATIC
uint8_t
*
USBD_DeviceDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
*
length
=
sizeof
(
hUSBDDeviceDesc
);
return
hUSBDDeviceDesc
;
}
...
...
@@ -102,7 +103,7 @@ STATIC uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *len
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
STATIC
uint8_t
*
USBD_
VCP_
LangIDStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
STATIC
uint8_t
*
USBD_LangIDStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
*
length
=
sizeof
(
USBD_LangIDDesc
);
return
USBD_LangIDDesc
;
}
...
...
@@ -113,7 +114,7 @@ STATIC uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
STATIC
uint8_t
*
USBD_
VCP_
ProductStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
STATIC
uint8_t
*
USBD_ProductStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
if
(
speed
==
0
)
{
USBD_GetString
((
uint8_t
*
)
USBD_PRODUCT_HS_STRING
,
USBD_StrDesc
,
length
);
}
else
{
...
...
@@ -128,7 +129,7 @@ STATIC uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
STATIC
uint8_t
*
USBD_
VCP_
ManufacturerStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
STATIC
uint8_t
*
USBD_ManufacturerStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
USBD_GetString
((
uint8_t
*
)
USBD_MANUFACTURER_STRING
,
USBD_StrDesc
,
length
);
return
USBD_StrDesc
;
}
...
...
@@ -139,7 +140,7 @@ STATIC uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
STATIC
uint8_t
*
USBD_
VCP_
SerialStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
STATIC
uint8_t
*
USBD_SerialStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
if
(
speed
==
USBD_SPEED_HIGH
)
{
USBD_GetString
((
uint8_t
*
)
USBD_SERIALNUMBER_HS_STRING
,
USBD_StrDesc
,
length
);
}
else
{
...
...
@@ -154,7 +155,7 @@ STATIC uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
STATIC
uint8_t
*
USBD_
VCP_
ConfigStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
STATIC
uint8_t
*
USBD_ConfigStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
if
(
speed
==
USBD_SPEED_HIGH
)
{
USBD_GetString
((
uint8_t
*
)
USBD_CONFIGURATION_HS_STRING
,
USBD_StrDesc
,
length
);
}
else
{
...
...
@@ -169,7 +170,7 @@ STATIC uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
STATIC
uint8_t
*
USBD_
VCP_
InterfaceStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
STATIC
uint8_t
*
USBD_InterfaceStrDescriptor
(
USBD_SpeedTypeDef
speed
,
uint16_t
*
length
)
{
if
(
speed
==
0
)
{
USBD_GetString
((
uint8_t
*
)
USBD_INTERFACE_HS_STRING
,
USBD_StrDesc
,
length
);
}
else
{
...
...
@@ -178,14 +179,14 @@ STATIC uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_
return
USBD_StrDesc
;
}
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
,
const
USBD_DescriptorsTypeDef
USBD
_Desc
riptors
=
{
USBD_DeviceDescriptor
,
USBD_LangIDStrDescriptor
,
USBD_ManufacturerStrDescriptor
,
USBD_ProductStrDescriptor
,
USBD_SerialStrDescriptor
,
USBD_ConfigStrDescriptor
,
USBD_InterfaceStrDescriptor
,
};
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
stmhal/usbd_desc.h
View file @
39ce2db1
...
...
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2013, 2014
, 2015
Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
...
...
@@ -24,6 +24,6 @@
* THE SOFTWARE.
*/
extern
const
USBD_DescriptorsTypeDef
VCP
_Desc
;
extern
const
USBD_DescriptorsTypeDef
USBD
_Desc
riptors
;
void
USBD_SetPID
(
uint16_t
pid
);
stmhal/usbdev/class/src/usbd_cdc_msc_hid.c
View file @
39ce2db1
This diff is collapsed.
Click to expand it.
tools/insert-usb-ids.py
View file @
39ce2db1
...
...
@@ -10,7 +10,7 @@ import string
def
parse_usb_ids
(
filename
):
rv
=
dict
()
if
filename
==
'usbd_desc
_cdc_msc
.c'
:
if
filename
==
'usbd_desc.c'
:
for
line
in
open
(
filename
).
readlines
():
line
=
line
.
rstrip
(
'
\r\n
'
)
match
=
re
.
match
(
'^#define\s+(\w+)\s+0x([0-9A-Fa-f]+)$'
,
line
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment