diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-09-05 18:00:16 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-09-05 18:00:16 -0600 |
commit | 26b761fcac72cb7b46740b5a92fd8ff27eb947b7 (patch) | |
tree | 327180bba6b952a1f75debd554f3511d430c31c3 /nuttx/drivers/usbdev | |
parent | ab4232e290cde4cb2126cea27b45f8f95bfab854 (diff) | |
download | px4-nuttx-26b761fcac72cb7b46740b5a92fd8ff27eb947b7.tar.gz px4-nuttx-26b761fcac72cb7b46740b5a92fd8ff27eb947b7.tar.bz2 px4-nuttx-26b761fcac72cb7b46740b5a92fd8ff27eb947b7.zip |
CDC/ACM and PL2303 device drivers: Don't use the max packet size assigned to an endpoint in order to determine the request buffer size. The endpoint has not yet been configured that max packet size may be wrong.
Diffstat (limited to 'nuttx/drivers/usbdev')
-rw-r--r-- | nuttx/drivers/usbdev/Kconfig | 6 | ||||
-rw-r--r-- | nuttx/drivers/usbdev/cdcacm.c | 27 | ||||
-rw-r--r-- | nuttx/drivers/usbdev/pl2303.c | 31 |
3 files changed, 52 insertions, 12 deletions
diff --git a/nuttx/drivers/usbdev/Kconfig b/nuttx/drivers/usbdev/Kconfig index ca1d175b2..56e45ccf8 100644 --- a/nuttx/drivers/usbdev/Kconfig +++ b/nuttx/drivers/usbdev/Kconfig @@ -210,7 +210,8 @@ config PL2303_NRDREQS config PL2303_BULKIN_REQLEN int "Size of one write request buffer" - default 96 + default 768 if USBDEV_DUALSPEED + default 96 if !USBDEV_DUALSPEED ---help--- Ideally, the BULKOUT request size should *not* be the same size as the maxpacket size. That is because IN transfers of exactly the @@ -376,7 +377,8 @@ config CDCACM_NRDREQS config CDCACM_BULKIN_REQLEN int "Size of one write request buffer" - default 96 + default 768 if USBDEV_DUALSPEED + default 96 if !USBDEV_DUALSPEED ---help--- Ideally, the BULKOUT request size should *not* be the same size as the maxpacket size. That is because IN transfers of exactly the diff --git a/nuttx/drivers/usbdev/cdcacm.c b/nuttx/drivers/usbdev/cdcacm.c index 81319e30c..5920a6beb 100644 --- a/nuttx/drivers/usbdev/cdcacm.c +++ b/nuttx/drivers/usbdev/cdcacm.c @@ -1006,9 +1006,13 @@ static int cdcacm_bind(FAR struct usbdevclass_driver_s *driver, priv->epbulkout->priv = priv; - /* Pre-allocate read requests */ + /* Pre-allocate read requests. The buffer size is one full packet. */ - reqlen = priv->epbulkout->maxpacket; +#ifdef CONFIG_USBDEV_DUALSPEED + reqlen = CONFIG_CDCACM_EPBULKOUT_HSSIZE; +#else + reqlen = CONFIG_CDCACM_EPBULKOUT_FSSIZE; +#endif for (i = 0; i < CONFIG_CDCACM_NRDREQS; i++) { @@ -1025,9 +1029,24 @@ static int cdcacm_bind(FAR struct usbdevclass_driver_s *driver, reqcontainer->req->callback = cdcacm_rdcomplete; } - /* Pre-allocate write request containers and put in a free list */ + /* Pre-allocate write request containers and put in a free list. + * The buffer size should be larger than a full packet. Otherwise, + * we will send a bogus null packet at the end of each packet. + * + * Pick the larger of the max packet size and the configured request + * size. + */ - reqlen = MAX(CONFIG_CDCACM_BULKIN_REQLEN, priv->epbulkin->maxpacket); +#ifdef CONFIG_USBDEV_DUALSPEED + reqlen = CONFIG_CDCACM_EPBULKIN_HSSIZE; +#else + reqlen = CONFIG_CDCACM_EPBULKIN_FSSIZE; +#endif + + if (CONFIG_CDCACM_BULKIN_REQLEN > reqlen) + { + reqlen = CONFIG_CDCACM_BULKIN_REQLEN; + } for (i = 0; i < CONFIG_CDCACM_NWRREQS; i++) { diff --git a/nuttx/drivers/usbdev/pl2303.c b/nuttx/drivers/usbdev/pl2303.c index 71918ca41..4f75275e2 100644 --- a/nuttx/drivers/usbdev/pl2303.c +++ b/nuttx/drivers/usbdev/pl2303.c @@ -472,7 +472,7 @@ static const struct usb_epdesc_s g_epbulkoutdesc = USB_DESC_TYPE_ENDPOINT, /* type */ PL2303_EPOUTBULK_ADDR, /* addr */ PL2303_EPOUTBULK_ATTR, /* attr */ - { LSBYTE(64), MSBYTE(64) }, /* maxpacket -- might change to 512*/ + { LSBYTE(64), MSBYTE(64) }, /* maxpacket -- might change to 512 */ 0 /* interval */ }; @@ -482,7 +482,7 @@ static const struct usb_epdesc_s g_epbulkindesc = USB_DESC_TYPE_ENDPOINT, /* type */ PL2303_EPINBULK_ADDR, /* addr */ PL2303_EPINBULK_ATTR, /* attr */ - { LSBYTE(64), MSBYTE(64) }, /* maxpacket -- might change to 512*/ + { LSBYTE(64), MSBYTE(64) }, /* maxpacket -- might change to 512 */ 0 /* interval */ }; @@ -1381,9 +1381,13 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver, } priv->epbulkout->priv = priv; - /* Pre-allocate read requests */ + /* Pre-allocate read requests. The buffer size is one full packet. */ - reqlen = priv->epbulkout->maxpacket; +#ifdef CONFIG_USBDEV_DUALSPEED + reqlen = 512; +#else + reqlen = 64; +#endif for (i = 0; i < CONFIG_PL2303_NRDREQS; i++) { @@ -1400,9 +1404,24 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver, reqcontainer->req->callback = usbclass_rdcomplete; } - /* Pre-allocate write request containers and put in a free list */ + /* Pre-allocate write request containers and put in a free list. + * The buffer size should be larger than a full packet. Otherwise, + * we will send a bogus null packet at the end of each packet. + * + * Pick the larger of the max packet size and the configured request + * size. + */ + +#ifdef CONFIG_USBDEV_DUALSPEED + reqlen = 512; +#else + reqlen = 64; +#endif - reqlen = max(CONFIG_PL2303_BULKIN_REQLEN, priv->epbulkin->maxpacket); + if (CONFIG_PL2303_BULKIN_REQLEN > reqlen) + { + reqlen = CONFIG_CDCACM_BULKIN_REQLEN; + } for (i = 0; i < CONFIG_PL2303_NWRREQS; i++) { |