drivers: usb_dc_stm32: change all endpoints to bidirectional

The various STM32 reference manuals sometimes define the USB endpoints
as IN or OUT only and sometimes as bidirectional, even in the same
manual. This is likely because the OTG implementation has one set of
registers for the IN endpoints and one other set for OUT endpoints.
However at the end a given endpoint address can both transmit and
receive data.

This causes some confusion how to declare the endpoints in the device
tree, and depending on the SoC, they are either the same number of IN
and OUT endpoints declared, or they are declared as bidirectional. At
the end it doesn't really matter given how the driver uses those values:

    #define NUM_IN_EP (CONFIG_USB_NUM_BIDIR_ENDPOINTS + \
                       CONFIG_USB_NUM_IN_ENDPOINTS)

    #define NUM_OUT_EP (CONFIG_USB_NUM_BIDIR_ENDPOINTS + \
                        CONFIG_USB_NUM_OUT_ENDPOINTS)

    #define NUM_BIDIR_EP NUM_OUT_EP

This patch therefore cleanup the driver, the DTS, and the DTS fixups to
only define the number of bidirectional endpoints.

In addition to the cleanup, that fixes a regression introduced by commit
52eacf16a2 ("driver: usb: add check for endpoint capabilities"), which
introduced a wrong check for SoC only defining the number of
bidirectional endpoints.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
This commit is contained in:
Aurelien Jarno 2018-06-18 13:00:56 +02:00 committed by Anas Nashif
commit 7688f49065
13 changed files with 14 additions and 66 deletions

View file

@ -54,8 +54,6 @@
#define CONFIG_USB_IRQ ST_STM32_USB_40005C00_IRQ_USB
#define CONFIG_USB_IRQ_PRI ST_STM32_USB_40005C00_IRQ_USB_PRIORITY
#define CONFIG_USB_NUM_BIDIR_ENDPOINTS ST_STM32_USB_40005C00_NUM_BIDIR_ENDPOINTS
#define CONFIG_USB_NUM_IN_ENDPOINTS ST_STM32_USB_40005C00_NUM_IN_ENDPOINTS
#define CONFIG_USB_NUM_OUT_ENDPOINTS ST_STM32_USB_40005C00_NUM_OUT_ENDPOINTS
#define CONFIG_USB_RAM_SIZE ST_STM32_USB_40005C00_RAM_SIZE
#define CONFIG_PWM_STM32_1_DEV_NAME ST_STM32_PWM_40012C00_PWM_LABEL

View file

@ -57,8 +57,6 @@
#define CONFIG_USB_IRQ ST_STM32_USB_40005C00_IRQ_USB
#define CONFIG_USB_IRQ_PRI ST_STM32_USB_40005C00_IRQ_USB_PRIORITY
#define CONFIG_USB_NUM_BIDIR_ENDPOINTS ST_STM32_USB_40005C00_NUM_BIDIR_ENDPOINTS
#define CONFIG_USB_NUM_IN_ENDPOINTS ST_STM32_USB_40005C00_NUM_IN_ENDPOINTS
#define CONFIG_USB_NUM_OUT_ENDPOINTS ST_STM32_USB_40005C00_NUM_OUT_ENDPOINTS
#define CONFIG_USB_RAM_SIZE ST_STM32_USB_40005C00_RAM_SIZE
#define CONFIG_PWM_STM32_1_DEV_NAME ST_STM32_PWM_40012C00_PWM_LABEL

View file

@ -87,8 +87,6 @@
#define CONFIG_USB_IRQ ST_STM32_OTGFS_50000000_IRQ_OTGFS
#define CONFIG_USB_IRQ_PRI ST_STM32_OTGFS_50000000_IRQ_OTGFS_PRIORITY
#define CONFIG_USB_NUM_BIDIR_ENDPOINTS ST_STM32_OTGFS_50000000_NUM_BIDIR_ENDPOINTS
#define CONFIG_USB_NUM_IN_ENDPOINTS ST_STM32_OTGFS_50000000_NUM_IN_ENDPOINTS
#define CONFIG_USB_NUM_OUT_ENDPOINTS ST_STM32_OTGFS_50000000_NUM_OUT_ENDPOINTS
#define CONFIG_USB_RAM_SIZE ST_STM32_OTGFS_50000000_RAM_SIZE
#define CONFIG_PWM_STM32_1_DEV_NAME ST_STM32_PWM_40010000_PWM_LABEL

View file

@ -52,8 +52,6 @@
#define CONFIG_USB_IRQ ST_STM32_USB_40005C00_IRQ_USB
#define CONFIG_USB_IRQ_PRI ST_STM32_USB_40005C00_IRQ_USB_PRIORITY
#define CONFIG_USB_NUM_BIDIR_ENDPOINTS ST_STM32_USB_40005C00_NUM_BIDIR_ENDPOINTS
#define CONFIG_USB_NUM_IN_ENDPOINTS ST_STM32_USB_40005C00_NUM_IN_ENDPOINTS
#define CONFIG_USB_NUM_OUT_ENDPOINTS ST_STM32_USB_40005C00_NUM_OUT_ENDPOINTS
#define CONFIG_USB_RAM_SIZE ST_STM32_USB_40005C00_RAM_SIZE
/* End of SoC Level DTS fixup file */

View file

@ -93,8 +93,6 @@
#define CONFIG_USB_IRQ ST_STM32_OTGFS_50000000_IRQ_OTGFS
#define CONFIG_USB_IRQ_PRI ST_STM32_OTGFS_50000000_IRQ_OTGFS_PRIORITY
#define CONFIG_USB_NUM_BIDIR_ENDPOINTS ST_STM32_OTGFS_50000000_NUM_BIDIR_ENDPOINTS
#define CONFIG_USB_NUM_IN_ENDPOINTS ST_STM32_OTGFS_50000000_NUM_IN_ENDPOINTS
#define CONFIG_USB_NUM_OUT_ENDPOINTS ST_STM32_OTGFS_50000000_NUM_OUT_ENDPOINTS
#define CONFIG_USB_RAM_SIZE ST_STM32_OTGFS_50000000_RAM_SIZE
#endif

View file

@ -69,28 +69,6 @@
#define EP_TYPE_INTR PCD_EP_TYPE_INTR
#endif
#ifndef CONFIG_USB_NUM_IN_ENDPOINTS
#define CONFIG_USB_NUM_IN_ENDPOINTS 0
#endif /* CONFIG_USB_NUM_IN_ENDPOINTS */
#ifndef CONFIG_USB_NUM_OUT_ENDPOINTS
#define CONFIG_USB_NUM_OUT_ENDPOINTS 0
#endif /* CONFIG_USB_NUM_OUT_ENDPOINTS */
/* Total in ep number = bidirectional ep number + in ep number */
#define NUM_IN_EP (CONFIG_USB_NUM_BIDIR_ENDPOINTS + \
CONFIG_USB_NUM_IN_ENDPOINTS)
/* Total out ep number = bidirectional ep number + out ep number */
#define NUM_OUT_EP (CONFIG_USB_NUM_BIDIR_ENDPOINTS + \
CONFIG_USB_NUM_OUT_ENDPOINTS)
/*
* Total bidirectional ep number = bidirectional ep number + (out ep number +
* in ep number) / 2. Because out ep number = in ep number,
* total bidirectional ep number = total out ep number or total in ep number
*/
#define NUM_BIDIR_EP NUM_OUT_EP
/*
* USB and USB_OTG_FS are defined in STM32Cube HAL and allows to distinguish
* between two kind of USB DC. STM32 F0, F3, and L0 series support USB device
@ -110,7 +88,7 @@
* per endpoint.
*
*/
#define USB_BTABLE_SIZE (8 * NUM_BIDIR_EP)
#define USB_BTABLE_SIZE (8 * CONFIG_USB_NUM_BIDIR_ENDPOINTS)
#else /* USB_OTG_FS */
@ -118,7 +96,7 @@
#define EP_MPS USB_OTG_FS_MAX_PACKET_SIZE
/* We need one RX FIFO and n TX-IN FIFOs */
#define FIFO_NUM (1 + NUM_IN_EP)
#define FIFO_NUM (1 + CONFIG_USB_NUM_BIDIR_ENDPOINTS)
/* 4-byte words FIFO */
#define FIFO_WORDS (CONFIG_USB_RAM_SIZE / 4)
@ -155,9 +133,9 @@ struct usb_dc_stm32_ep_state {
struct usb_dc_stm32_state {
PCD_HandleTypeDef pcd; /* Storage for the HAL_PCD api */
usb_dc_status_callback status_cb; /* Status callback */
struct usb_dc_stm32_ep_state out_ep_state[NUM_OUT_EP];
struct usb_dc_stm32_ep_state in_ep_state[NUM_IN_EP];
u8_t ep_buf[NUM_OUT_EP][EP_MPS];
struct usb_dc_stm32_ep_state out_ep_state[CONFIG_USB_NUM_BIDIR_ENDPOINTS];
struct usb_dc_stm32_ep_state in_ep_state[CONFIG_USB_NUM_BIDIR_ENDPOINTS];
u8_t ep_buf[CONFIG_USB_NUM_BIDIR_ENDPOINTS][EP_MPS];
#ifdef USB
u32_t pma_offset;
@ -172,7 +150,7 @@ static struct usb_dc_stm32_ep_state *usb_dc_stm32_get_ep_state(u8_t ep)
{
struct usb_dc_stm32_ep_state *ep_state_base;
if (EP_IDX(ep) >= NUM_BIDIR_EP) {
if (EP_IDX(ep) >= CONFIG_USB_NUM_BIDIR_ENDPOINTS) {
return NULL;
}
@ -263,13 +241,13 @@ static int usb_dc_stm32_init(void)
#ifdef USB
usb_dc_stm32_state.pcd.Instance = USB;
usb_dc_stm32_state.pcd.Init.speed = PCD_SPEED_FULL;
usb_dc_stm32_state.pcd.Init.dev_endpoints = NUM_BIDIR_EP;
usb_dc_stm32_state.pcd.Init.dev_endpoints = CONFIG_USB_NUM_BIDIR_ENDPOINTS;
usb_dc_stm32_state.pcd.Init.phy_itface = PCD_PHY_EMBEDDED;
usb_dc_stm32_state.pcd.Init.ep0_mps = PCD_EP0MPS_64;
usb_dc_stm32_state.pcd.Init.low_power_enable = 0;
#else /* USB_OTG_FS */
usb_dc_stm32_state.pcd.Instance = USB_OTG_FS;
usb_dc_stm32_state.pcd.Init.dev_endpoints = NUM_BIDIR_EP;
usb_dc_stm32_state.pcd.Init.dev_endpoints = CONFIG_USB_NUM_BIDIR_ENDPOINTS;
usb_dc_stm32_state.pcd.Init.speed = USB_OTG_SPEED_FULL;
usb_dc_stm32_state.pcd.Init.phy_itface = PCD_PHY_EMBEDDED;
usb_dc_stm32_state.pcd.Init.ep0_mps = USB_OTG_MAX_EP0_SIZE;
@ -304,13 +282,13 @@ static int usb_dc_stm32_init(void)
/* Start PMA configuration for the endpoints after the BTABLE. */
usb_dc_stm32_state.pma_offset = USB_BTABLE_SIZE;
for (i = 0; i < NUM_IN_EP; i++) {
for (i = 0; i < CONFIG_USB_NUM_BIDIR_ENDPOINTS; i++) {
k_sem_init(&usb_dc_stm32_state.in_ep_state[i].write_sem, 1, 1);
}
#else /* USB_OTG_FS */
/* TODO: make this dynamic (depending usage) */
HAL_PCDEx_SetRxFiFo(&usb_dc_stm32_state.pcd, FIFO_EP_WORDS);
for (i = 0; i < NUM_IN_EP; i++) {
for (i = 0; i < CONFIG_USB_NUM_BIDIR_ENDPOINTS; i++) {
HAL_PCDEx_SetTxFiFo(&usb_dc_stm32_state.pcd, i,
FIFO_EP_WORDS);
k_sem_init(&usb_dc_stm32_state.in_ep_state[i].write_sem, 1, 1);
@ -465,14 +443,8 @@ int usb_dc_ep_check_cap(const struct usb_dc_ep_cfg_data * const cfg)
return -1;
}
if (EP_IS_IN(cfg->ep_addr) && (ep_idx > CONFIG_USB_NUM_IN_ENDPOINTS)) {
SYS_LOG_ERR("IN endpoint index/address out of range");
return -1;
}
if (EP_IS_OUT(cfg->ep_addr) &&
(ep_idx > CONFIG_USB_NUM_OUT_ENDPOINTS)) {
SYS_LOG_ERR("OUT endpoint index/address out of range");
if (ep_idx > CONFIG_USB_NUM_BIDIR_ENDPOINTS) {
SYS_LOG_ERR("endpoint index/address out of range");
return -1;
}

View file

@ -24,8 +24,6 @@
interrupts = <31 0>;
interrupt-names = "usb";
num-bidir-endpoints = <8>;
num-in-endpoints = <0>;
num-out-endpoints = <0>;
ram-size = <1024>;
status = "disabled";
label= "USB";

View file

@ -51,8 +51,6 @@
interrupts = <31 0>;
interrupt-names = "usb";
num-bidir-endpoints = <8>;
num-in-endpoints = <0>;
num-out-endpoints = <0>;
ram-size = <1024>;
status = "disabled";
label= "USB";

View file

@ -161,8 +161,6 @@
interrupts = <20 0>;
interrupt-names = "usb";
num-bidir-endpoints = <8>;
num-in-endpoints = <0>;
num-out-endpoints = <0>;
ram-size = <512>;
status = "disabled";
label= "USB";

View file

@ -196,9 +196,7 @@
reg = <0x50000000 0x40000>;
interrupts = <67 0>;
interrupt-names = "otgfs";
num-bidir-endpoints = <1>;
num-in-endpoints = <3>;
num-out-endpoints = <3>;
num-bidir-endpoints = <4>;
ram-size = <1280>;
status = "disabled";
label= "OTGFS";

View file

@ -60,8 +60,6 @@
interrupts = <31 0>;
interrupt-names = "usb";
num-bidir-endpoints = <8>;
num-in-endpoints = <0>;
num-out-endpoints = <0>;
ram-size = <1024>;
status = "disabled";
label= "USB";

View file

@ -48,8 +48,6 @@
interrupts = <31 0>;
interrupt-names = "usb";
num-bidir-endpoints = <8>;
num-in-endpoints = <0>;
num-out-endpoints = <0>;
ram-size = <1024>;
status = "disabled";
label= "USB";

View file

@ -104,9 +104,7 @@
reg = <0x50000000 0x40000>;
interrupts = <67 0>;
interrupt-names = "otgfs";
num-bidir-endpoints = <1>;
num-in-endpoints = <5>;
num-out-endpoints = <5>;
num-bidir-endpoints = <6>;
ram-size = <1280>;
status = "disabled";
label= "OTGFS";