USB: st_usbfs : fix USB_COUNTn_RX buffer size calculation:

Fixes https://github.com/libopencm3/libopencm3/issues/476

Sets USB_COUNTn_RX reg fields : bits <14:10> are NUM_BLOCK; bit 15 is BL_SIZE.
 - When (size <= 62), BL_SIZE must be 0 and NUM_BLOCK set to (size / 2).
 - When (size > 62), BL_SIZE must be 1 and NUM_BLOCK=((size / 32) - 1).

Previous code improperly set NUM_BLOCK and assumed the requested size was set.
Now, we use the next largest legal buffer size. Examples:
size BL_SIZE NUM_BLOCK => Actual bufsize
0    0       0         ??? (illegal !)
1    0       1         2
63   1       1         64
Algo is valid for F102, F103 and F0 devices (USB_FS peripheral).
In addition, the new usb_set_ep_rx_bufsize() function returns the actual
size set.

Tested-by: Karl Palsson <karlp@tweak.net.au>
This commit is contained in:
fenugrec
2015-07-20 21:42:58 -04:00
committed by Karl Palsson
parent 144911a25b
commit 01f33f47b7
2 changed files with 31 additions and 13 deletions

View File

@@ -33,7 +33,7 @@
#define USBD_PM_TOP 0x40
void st_usbfs_set_address(usbd_device *dev, uint8_t addr);
void st_usbfs_set_ep_rx_bufsize(usbd_device *dev, uint8_t ep, uint32_t size);
uint16_t st_usbfs_set_ep_rx_bufsize(usbd_device *dev, uint8_t ep, uint32_t size);
void st_usbfs_ep_setup(usbd_device *usbd_dev, uint8_t addr,
uint8_t type, uint16_t max_size,