diff --git a/features/unsupported/USBHost/USBHost/TARGET_STM/USBEndpoint_STM.cpp b/features/unsupported/USBHost/USBHost/TARGET_STM/USBEndpoint_STM.cpp new file mode 100644 index 0000000000..17aedacf53 --- /dev/null +++ b/features/unsupported/USBHost/USBHost/TARGET_STM/USBEndpoint_STM.cpp @@ -0,0 +1,139 @@ +/* mbed USBHost Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if defined(TARGET_STM) && defined(USBHOST_OTHER) + +#include "dbg.h" +#include "USBEndpoint.h" +extern uint32_t HAL_HCD_HC_GetMaxPacket(HCD_HandleTypeDef *hhcd, uint8_t chn_num); +extern uint32_t HAL_HCD_HC_GetType(HCD_HandleTypeDef *hhcd, uint8_t chn_num); + + +void USBEndpoint::init(HCED * hced_, ENDPOINT_TYPE type_, ENDPOINT_DIRECTION dir_, uint32_t size, uint8_t ep_number, HCTD* td_list_[2]) +{ + hced = hced_; + type = type_; + dir = dir_; + setup = (type == CONTROL_ENDPOINT) ? true : false; + + //TDs have been allocated by the host + memcpy((HCTD**)td_list, td_list_, sizeof(HCTD*)*2); //TODO: Maybe should add a param for td_list size... at least a define + memset(td_list_[0], 0, sizeof(HCTD)); + memset(td_list_[1], 0, sizeof(HCTD)); + + td_list[0]->ep = this; + td_list[1]->ep = this; + + address = (ep_number & 0x7F) | ((dir - 1) << 7); + this->size = size; + this->ep_number = ep_number; + transfer_len = 0; + transferred = 0; + buf_start = 0; + nextEp = NULL; + + td_current = td_list[0]; + td_next = td_list[1]; + + intf_nb = 0; + + state = USB_TYPE_IDLE; +} +void USBEndpoint::setSize(uint32_t size) +{ + this->size = size; +} + + +void USBEndpoint::setDeviceAddress(uint8_t addr) +{ + this->device_address = addr; + HAL_HCD_HC_Init((HCD_HandleTypeDef*)hced->hhcd,hced->ch_num, address, addr, HCD_SPEED_FULL, type, size); +} + +void USBEndpoint::setSpeed(uint8_t speed) +{ + this->speed = speed; +} + + + +void USBEndpoint::setState(uint8_t st) { + if (st > 18) + return; + if (state == USB_TYPE_FREE) HAL_HCD_HC_Halt((HCD_HandleTypeDef*)hced->hhcd, hced->ch_num); + + state = (USB_TYPE)st; +} + + +extern uint32_t HAL_HCD_HC_GetMaxPacket(HCD_HandleTypeDef *hhcd, uint8_t chn_num); +extern uint32_t HAL_HCD_HC_GetType(HCD_HandleTypeDef *hhcd, uint8_t chn_num); + + +USB_TYPE USBEndpoint::queueTransfer() +{ + HCD_HandleTypeDef *hhcd = (HCD_HandleTypeDef*)hced->hhcd; + uint32_t *addr = &((uint32_t *)hhcd->pData)[hced->ch_num]; + uint32_t type = HAL_HCD_HC_GetType(hhcd, hced->ch_num); + uint32_t max_size = HAL_HCD_HC_GetMaxPacket(hhcd, hced->ch_num); + /* if a packet is queue on disconnected ; no solution for now */ + if(*addr == (uint32_t) -1) { + /* set td as disconnected */ + td_current->state = USB_TYPE_DISCONNECTED; + return USB_TYPE_DISCONNECTED; + } + MBED_ASSERT(*addr ==0); + if ((type == EP_TYPE_BULK) || (type== EP_TYPE_CTRL)) { + transfer_len = td_current->size <= max_size ? td_current->size : max_size; + transferred = td_current->size; + } else { + transfer_len = td_current->size; + transferred = td_current->size; + MBED_ASSERT(transferred <= (int)max_size); + } + buf_start = (uint8_t *)td_current->currBufPtr; + + //Now add this free TD at this end of the queue + state = USB_TYPE_PROCESSING; + /* one request */ + td_current->nextTD = (hcTd*)0; + + *addr = (uint32_t)td_current; + /* dir /setup is inverted for ST */ + /* token is useful only ctrl endpoint */ + /* last parameter is ping ? */ + MBED_ASSERT(HAL_HCD_HC_SubmitRequest((HCD_HandleTypeDef*)hced->hhcd, hced->ch_num, dir-1, type,!setup,(uint8_t*) td_current->currBufPtr, transfer_len, 0)==HAL_OK); + return USB_TYPE_PROCESSING; +} + +void USBEndpoint::unqueueTransfer(volatile HCTD * td) +{ + + uint32_t *addr = &((uint32_t *)((HCD_HandleTypeDef*)hced->hhcd)->pData)[hced->ch_num]; + td->state=0; + td->currBufPtr=0; + td->size=0; + td->nextTD=0; + *addr = 0; + td_current = td_next; + td_next = td; +} + +void USBEndpoint::queueEndpoint(USBEndpoint * ed) +{ + nextEp = ed; +} +#endif diff --git a/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_DISCOF429ZI.h b/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_DISCOF429ZI.h new file mode 100644 index 0000000000..720f7324ce --- /dev/null +++ b/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_DISCOF429ZI.h @@ -0,0 +1,112 @@ +/* mbed USBHost Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef USBHALHOST_DISCOF429ZI +#define USBHALHOST_DISCOF429ZI + +#define USBHAL_IRQn OTG_HS_IRQn + +#define HCCA_SIZE sizeof(HCD_HandleTypeDef) +#define ED_SIZE sizeof(HCED) +#define TD_SIZE sizeof(HCTD) + +#define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE) + (MAX_TD*TD_SIZE)) +/* STM device FS have 11 channels (definition is for 60 channels) */ +static volatile uint8_t usb_buf[TOTAL_SIZE]; +typedef struct +{ + /* store the request ongoing on each endpoit */ + /* 1st field of structure avoid giving knowledge of all structure to + * endpoint */ + volatile uint32_t addr[MAX_ENDPOINT]; + USBHALHost *inst; + void (USBHALHost::*deviceConnected)(int hub, int port, bool lowSpeed, USBHostHub * hub_parent); + void (USBHALHost::*deviceDisconnected)(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr); + void (USBHALHost::*transferCompleted)(volatile uint32_t addr); +}USBHALHost_Private_t; +/* CONFIGURATION for USB_VBUS + * on 64 bits board PC_0 is used (0 VBUS on, 1 VBUS off) + * on 144 pins board PG_6 is used ( 1 VBUS on, 0 VBUS on) + */ +static gpio_t gpio_vbus; + +#define VBUS_OFF 1 +#define VBUS_ON 0 +#define USB_VBUS_CONFIG \ + do {__HAL_RCC_GPIOC_CLK_ENABLE();\ + gpio_init_out_ex(&gpio_vbus, PC_4, VBUS_OFF);\ + }while(0); + + +void usb_vbus( uint8_t state) +{ + if(state == 0) + { + gpio_write(&gpio_vbus, VBUS_OFF); + } + else + { + gpio_write(&gpio_vbus, VBUS_ON); + } + wait(0.2); +} + + +USBHALHost::USBHALHost() { + gpio_t pin_vbus; + instHost = this; + HCD_HandleTypeDef *hhcd; + USBHALHost_Private_t *HALPriv = new(USBHALHost_Private_t); + memset(HALPriv, 0, sizeof(USBHALHost_Private_t)); + memInit(); + memset((void*)usb_hcca, 0, HCCA_SIZE); + hhcd = (HCD_HandleTypeDef *)usb_hcca; + hhcd->Instance = USB_OTG_HS; + hhcd->pData = (void*)HALPriv; + hhcd->Init.Host_channels = 11; + /* for now failed with dma */ + hhcd->Init.dma_enable = 0; + hhcd->Init.speed = HCD_SPEED_HIGH; + hhcd->Init.phy_itface = HCD_PHY_EMBEDDED; + hhcd->Init.use_external_vbus = 1; + HALPriv->inst = this; + HALPriv->deviceConnected = &USBHALHost::deviceConnected; + HALPriv->deviceDisconnected = &USBHALHost::deviceDisconnected; + HALPriv->transferCompleted = &USBHALHost::transferCompleted; + for (int i = 0; i < MAX_ENDPOINT; i++) { + edBufAlloc[i] = false; + HALPriv->addr[i]=(uint32_t)-1; + } + for (int i = 0; i < MAX_TD; i++) { + tdBufAlloc[i] = false; + } + /* Configure USB HS GPIOs */ + __HAL_RCC_GPIOB_CLK_ENABLE(); + + /*USB DM and DP */ + pin_function(PB_14, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF12_OTG_HS_FS)); + pin_function(PB_15, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF12_OTG_HS_FS)); + /* Configure VBUS Pin */ + gpio_init_in(&pin_vbus, PB_13); + /* Configure POWER_SWITCH IO pin */ + USB_VBUS_CONFIG; + /* Enable USB HS Clocks */ + __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); + + /* Set USBFS Interrupt priority */ + HAL_NVIC_SetPriority(USBHAL_IRQn, 5, 0); + NVIC_SetVector(USBHAL_IRQn, (uint32_t)&_usbisr); +} +#endif diff --git a/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_DISCOL476VG.h b/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_DISCOL476VG.h new file mode 100644 index 0000000000..3e443f55ca --- /dev/null +++ b/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_DISCOL476VG.h @@ -0,0 +1,118 @@ +/* Copyright (c) 2016 mbed.org, MIT License +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software +* and associated documentation files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +#ifndef USBHALHOST_DISCOL476VG +#define USBHALHOST_DISCOL476VG + +#define USBHAL_IRQn OTG_FS_IRQn + +#define HCCA_SIZE sizeof(HCD_HandleTypeDef) +#define ED_SIZE sizeof(HCED) +#define TD_SIZE sizeof(HCTD) + +#define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE) + (MAX_TD*TD_SIZE)) +/* STM device FS have 11 channels (definition is for 60 channels) */ +static volatile uint8_t usb_buf[TOTAL_SIZE]; +typedef struct +{ + /* store the request ongoing on each endpoit */ + /* 1st field of structure avoid giving knowledge of all structure to + * endpoint */ + volatile uint32_t addr[MAX_ENDPOINT]; + USBHALHost *inst; + void (USBHALHost::*deviceConnected)(int hub, int port, bool lowSpeed, USBHostHub * hub_parent); + void (USBHALHost::*deviceDisconnected)(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr); + void (USBHALHost::*transferCompleted)(volatile uint32_t addr); +}USBHALHost_Private_t; + +static gpio_t gpio_vbus; + +#define VBUS_OFF 1 +#define VBUS_ON 0 +#define USB_VBUS_CONFIG \ + do {\ + gpio_init_out_ex(&gpio_vbus, PC_9, VBUS_OFF);\ + }while(0); + + +void usb_vbus( uint8_t state) +{ + if(state == 0) + { + gpio_write(&gpio_vbus, VBUS_OFF); + } + else + { + gpio_write(&gpio_vbus, VBUS_ON); + } + wait(0.2); +} + + +USBHALHost::USBHALHost() { + instHost = this; + HCD_HandleTypeDef *hhcd; + USBHALHost_Private_t *HALPriv = new(USBHALHost_Private_t); + memset(HALPriv, 0, sizeof(USBHALHost_Private_t)); + memInit(); + memset((void*)usb_hcca, 0, HCCA_SIZE); + hhcd = (HCD_HandleTypeDef *)usb_hcca; + hhcd->Instance = USB_OTG_FS; + hhcd->pData = (void*)HALPriv; + hhcd->Init.Host_channels = 11; + /* for now failed with dma */ + hhcd->Init.dma_enable = 0; + hhcd->Init.speed = HCD_SPEED_FULL; + hhcd->Init.phy_itface = HCD_PHY_EMBEDDED; + hhcd->Init.use_external_vbus = 1; + HALPriv->inst = this; + HALPriv->deviceConnected = &USBHALHost::deviceConnected; + HALPriv->deviceDisconnected = &USBHALHost::deviceDisconnected; + HALPriv->transferCompleted = &USBHALHost::transferCompleted; + for (int i = 0; i < MAX_ENDPOINT; i++) { + edBufAlloc[i] = false; + HALPriv->addr[i]=(uint32_t)-1; + } + for (int i = 0; i < MAX_TD; i++) { + tdBufAlloc[i] = false; + } + __HAL_RCC_PWR_CLK_ENABLE(); +#ifdef TARGET_STM32L4 + HAL_PWREx_EnableVddUSB(); +#endif + + /* Configure USB HS GPIOs */ + __HAL_RCC_GPIOA_CLK_ENABLE(); + + /*USB DM and DP */ + pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); + pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); + + /* Configure VBUS Pin */ + __HAL_RCC_GPIOC_CLK_ENABLE(); + pin_function(PC_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); + /* Configure POWER_SWITCH IO pin */ + USB_VBUS_CONFIG; + __HAL_RCC_SYSCFG_CLK_ENABLE(); + + /* Enable USB FS Clocks */ + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + /* Set USBFS Interrupt priority */ + HAL_NVIC_SetPriority(USBHAL_IRQn, 5, 0); + NVIC_SetVector(USBHAL_IRQn, (uint32_t)&_usbisr); +} +#endif diff --git a/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_STM.cpp b/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_STM.cpp new file mode 100644 index 0000000000..4a8c333cec --- /dev/null +++ b/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_STM.cpp @@ -0,0 +1,233 @@ +/* mbed USBHost Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef TARGET_STM +#include "mbed.h" +#include "USBHALHost.h" +#include "dbg.h" +#include "pinmap.h" + +#include "USBHALHost_STM_TARGET.h" + +void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd) +{ + USBHALHost_Private_t *priv=(USBHALHost_Private_t *)(hhcd->pData); + USBHALHost *obj= priv->inst; + int i; + void (USBHALHost::*func)(int hub, int port, bool lowSpeed, USBHostHub * hub_parent ) = priv->deviceConnected; + for (i=0; iaddr[i]==(uint32_t)-1)priv->addr[i]=0; + (obj->*func)(0,1,1,NULL); +} +void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd) +{ + USBHALHost_Private_t *priv=(USBHALHost_Private_t *)(hhcd->pData); + USBHALHost *obj= priv->inst; + void (USBHALHost::*func1)(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr)= priv->deviceDisconnected; + void (USBHALHost::*func2)(volatile uint32_t addr)= priv->transferCompleted; + int i; + (obj->*func1)(0,1,(USBHostHub *)NULL,0); + + /* fix me call with same frame number */ + /* all on going transaction must end and any new one must be rejected */ + for (i=0; iaddr[i]; + priv->addr[i]=(uint32_t)-1; + if ((addr!=(uint32_t)-1)&& (addr!=0)){ + HCTD *td = (HCTD *)addr; + td->currBufPtr +=HAL_HCD_HC_GetXferCount(hhcd, i); + td->state = USB_TYPE_DISCONNECTED; + (obj->*func2)(addr); + } + } + for (i=1; i< MAX_ENDPOINT;i++)HAL_HCD_HC_Halt(hhcd,i); +} +int HAL_HCD_HC_GetDirection(HCD_HandleTypeDef *hhcd,uint8_t chnum) +{ +/* useful for transmission */ + return hhcd->hc[chnum].ep_is_in; +} + +uint32_t HAL_HCD_HC_GetMaxPacket(HCD_HandleTypeDef *hhcd,uint8_t chnum) +{ +/* useful for transmission */ + return hhcd->hc[chnum].max_packet; +} + + +uint32_t HAL_HCD_HC_GetType(HCD_HandleTypeDef *hhcd,uint8_t chnum) +{ +/* useful for transmission */ + return hhcd->hc[chnum].ep_type; +} + +void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd,uint8_t chnum, HCD_URBStateTypeDef urb_state) +{ + USBHALHost_Private_t *priv=(USBHALHost_Private_t *)(hhcd->pData); + USBHALHost *obj= priv->inst; + void (USBHALHost::*func)(volatile uint32_t addr)= priv->transferCompleted; + uint32_t addr = priv->addr[chnum]; + uint32_t max_size = HAL_HCD_HC_GetMaxPacket(hhcd, chnum); + uint32_t type = HAL_HCD_HC_GetType(hhcd, chnum); + uint32_t dir = HAL_HCD_HC_GetDirection(hhcd,chnum); + uint32_t length; + if ((addr!=(uint32_t)-1) && (addr!=0)) { + HCTD *td = (HCTD *)addr; + /* put the state */ + if ((urb_state == URB_IDLE) && (type == EP_TYPE_INTR) ) { + length = td->size; + MBED_ASSERT(HAL_HCD_HC_SubmitRequest(hhcd, chnum, dir ,type , 1,(uint8_t*) td->currBufPtr, length, 0)==HAL_OK); + return; + } + td->state = (urb_state == URB_DONE) ? USB_TYPE_IDLE : USB_TYPE_ERROR; + if (urb_state == URB_NOTREADY) + USB_ERR("urb_state != URB_NOTREADY"); + /* move buffer pointer , for size */ + if ((type != EP_TYPE_BULK) && (type != EP_TYPE_CTRL )) { + /* in packet */ + } else { + if (urb_state == URB_DONE) { + if (td->size > max_size) { + /* enqueue another request */ + td->currBufPtr += max_size; + td->size -= max_size; + length = td->size <= max_size ? td->size : max_size; + MBED_ASSERT(HAL_HCD_HC_SubmitRequest(hhcd, chnum, dir ,type , 1,(uint8_t*) td->currBufPtr, length, 0)==HAL_OK); + return; + } + } + } + td->state = (urb_state == URB_DONE) ? USB_TYPE_IDLE : USB_TYPE_ERROR; + td->currBufPtr +=HAL_HCD_HC_GetXferCount(hhcd, chnum); + priv->addr[chnum]=0; + (obj->*func)(addr); + } + else + { + USB_DBG_EVENT("spurious %d %d",chnum, urb_state); + } +} +USBHALHost * USBHALHost::instHost; + + +void USBHALHost::init() { + + NVIC_DisableIRQ(USBHAL_IRQn); + NVIC_SetVector(USBHAL_IRQn, (uint32_t)(_usbisr)); + HAL_HCD_Init((HCD_HandleTypeDef *) usb_hcca); + NVIC_EnableIRQ(USBHAL_IRQn); + HAL_HCD_Start((HCD_HandleTypeDef *) usb_hcca); + usb_vbus(1); +} + +uint32_t USBHALHost::controlHeadED() { + return 0xffffffff; +} + +uint32_t USBHALHost::bulkHeadED() { + return 0xffffffff; +} + +uint32_t USBHALHost::interruptHeadED() { + return 0xffffffff; +} + +void USBHALHost::updateBulkHeadED(uint32_t addr) { +} + + +void USBHALHost::updateControlHeadED(uint32_t addr) { +} + +void USBHALHost::updateInterruptHeadED(uint32_t addr) { +} + + +void USBHALHost::enableList(ENDPOINT_TYPE type) { +} + + +bool USBHALHost::disableList(ENDPOINT_TYPE type) { + return true; +} + + +void USBHALHost::memInit() { + usb_hcca = (volatile HCD_HandleTypeDef *)usb_buf; + usb_edBuf = usb_buf + HCCA_SIZE; + usb_tdBuf = usb_buf + HCCA_SIZE +(MAX_ENDPOINT*ED_SIZE); + /* init channel */ + for (int i=0; i < MAX_ENDPOINT; i++) { + HCED *hced = (HCED*)(usb_edBuf + i*ED_SIZE); + hced->ch_num = i; + hced->hhcd = (HCCA *) usb_hcca; + } +} + +volatile uint8_t * USBHALHost::getED() { + for (int i = 0; i < MAX_ENDPOINT; i++) { + if ( !edBufAlloc[i] ) { + edBufAlloc[i] = true; + return (volatile uint8_t *)(usb_edBuf + i*ED_SIZE); + } + } + perror("Could not allocate ED\r\n"); + return NULL; //Could not alloc ED +} + +volatile uint8_t * USBHALHost::getTD() { + int i; + for (i = 0; i < MAX_TD; i++) { + if ( !tdBufAlloc[i] ) { + tdBufAlloc[i] = true; + return (volatile uint8_t *)(usb_tdBuf + i*TD_SIZE); + } + } + perror("Could not allocate TD\r\n"); + return NULL; //Could not alloc TD +} + + +void USBHALHost::freeED(volatile uint8_t * ed) { + int i; + i = (ed - usb_edBuf) / ED_SIZE; + edBufAlloc[i] = false; +} + +void USBHALHost::freeTD(volatile uint8_t * td) { + int i; + i = (td - usb_tdBuf) / TD_SIZE; + tdBufAlloc[i] = false; +} + + +void USBHALHost::resetRootHub() { + // Initiate port reset + wait(0.2); + HAL_HCD_ResetPort((HCD_HandleTypeDef *)usb_hcca); +} + + +void USBHALHost::_usbisr(void) { + if (instHost) { + instHost->UsbIrqhandler(); + } +} + +void USBHALHost::UsbIrqhandler() { + HAL_HCD_IRQHandler((HCD_HandleTypeDef *)usb_hcca); +} +#endif diff --git a/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_STM_144_64pins.h b/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_STM_144_64pins.h new file mode 100644 index 0000000000..305b928d53 --- /dev/null +++ b/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_STM_144_64pins.h @@ -0,0 +1,121 @@ +/* mbed USBHost Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef USBHALHOST_STM32_144_64 +#define USBHALHOST_STM32_144_64 + +#define USBHAL_IRQn OTG_FS_IRQn + +#define HCCA_SIZE sizeof(HCD_HandleTypeDef) +#define ED_SIZE sizeof(HCED) +#define TD_SIZE sizeof(HCTD) + +#define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE) + (MAX_TD*TD_SIZE)) +/* STM device FS have 11 channels (definition is for 60 channels) */ +static volatile uint8_t usb_buf[TOTAL_SIZE]; +typedef struct +{ + /* store the request ongoing on each endpoit */ + /* 1st field of structure avoid giving knowledge of all structure to + * endpoint */ + volatile uint32_t addr[MAX_ENDPOINT]; + USBHALHost *inst; + void (USBHALHost::*deviceConnected)(int hub, int port, bool lowSpeed, USBHostHub * hub_parent); + void (USBHALHost::*deviceDisconnected)(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr); + void (USBHALHost::*transferCompleted)(volatile uint32_t addr); +}USBHALHost_Private_t; + +/* CONFIGURATION for USB_VBUS + * on 64 bits board PC_0 is used (0 VBUS on, 1 VBUS off) + * on 144 pins board PG_6 is used ( 1 VBUS on, 0 VBUS on) + */ +static gpio_t gpio_vbus; + +#if defined(USBHALHOST_64pins) +#define VBUS_OFF 1 +#define VBUS_ON 0 +#define USB_VBUS_CONFIG \ + do {__HAL_RCC_GPIOC_CLK_ENABLE();\ + gpio_init_out_ex(&gpio_vbus, PC_0, VBUS_OFF);\ + }while(0); +#else +#define VBUS_OFF 0 +#define VBUS_ON 1 +#define USB_VBUS_CONFIG \ + do {__HAL_RCC_GPIOG_CLK_ENABLE();\ + gpio_init_out_ex(&gpio_vbus, PG_6, VBUS_OFF);\ + }while(0); +#endif + +void usb_vbus( uint8_t state) +{ + if(state == 0) + { + gpio_write(&gpio_vbus, VBUS_OFF); + } + else + { + gpio_write(&gpio_vbus, VBUS_ON); + } + wait(0.2); +} + +USBHALHost::USBHALHost() { + instHost = this; + HCD_HandleTypeDef *hhcd; + USBHALHost_Private_t *HALPriv = new(USBHALHost_Private_t); + memset(HALPriv, 0, sizeof(USBHALHost_Private_t)); + memInit(); + memset((void*)usb_hcca, 0, HCCA_SIZE); + hhcd = (HCD_HandleTypeDef *)usb_hcca; + hhcd->Instance = USB_OTG_FS; + hhcd->pData = (void*)HALPriv; + hhcd->Init.Host_channels = 11; + hhcd->Init.speed = HCD_SPEED_FULL; + hhcd->Init.phy_itface = HCD_PHY_EMBEDDED; + HALPriv->inst = this; + HALPriv->deviceConnected = &USBHALHost::deviceConnected; + HALPriv->deviceDisconnected = &USBHALHost::deviceDisconnected; + HALPriv->transferCompleted = &USBHALHost::transferCompleted; + for (int i = 0; i < MAX_ENDPOINT; i++) { + edBufAlloc[i] = false; + HALPriv->addr[i]=(uint32_t)-1; + } + for (int i = 0; i < MAX_TD; i++) { + tdBufAlloc[i] = false; + } + __HAL_RCC_PWR_CLK_ENABLE(); +#ifdef TARGET_STM32L4 + HAL_PWREx_EnableVddUSB(); +#endif + /* Configure USB FS GPIOs */ + __HAL_RCC_GPIOA_CLK_ENABLE(); + + /*USB DM and DP */ + pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); + pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); + /*USB ID */ + pin_function(PA_10, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)); + + __HAL_RCC_SYSCFG_CLK_ENABLE(); + /* Configure POWER_SWITCH IO pin */ + USB_VBUS_CONFIG; + /* Enable USB FS Clocks */ + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + + /* Set USBFS Interrupt priority */ + HAL_NVIC_SetPriority(OTG_FS_IRQn, 6, 0); +} +#endif diff --git a/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_STM_TARGET.h b/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_STM_TARGET.h new file mode 100644 index 0000000000..1cde2f384d --- /dev/null +++ b/features/unsupported/USBHost/USBHost/TARGET_STM/USBHALHost_STM_TARGET.h @@ -0,0 +1,39 @@ +/* Copyright (c) 2016 mbed.org, MIT License +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software +* and associated documentation files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +/* 144 pins boards */ +#if defined(TARGET_NUCLEO_F429ZI) || defined(TARGET_NUCLEO_F446ZE) || defined(TARGET_NUCLEO_F207ZG) \ +|| defined(TARGET_NUCLEO_F767ZI) || defined(TARGET_NUCLEO_F746ZG) +#include "USBHALHost_STM_144_64pins.h" +#endif + +/* 64 pins boards */ +#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_L476RG) || defined(TARGET_NUCLEO_F411RE) +#define USBHALHOST_64pins +#include "USBHALHost_STM_144_64pins.h" +#endif + +/* DISCO board */ + +#ifdef TARGET_DISCO_F429ZI +#include "USBHALHost_DISCOF429ZI.h" +#endif + +#ifdef TARGET_DISCO_L476VG +#include "USBHALHost_DISCOL476VG.h" +#endif diff --git a/features/unsupported/USBHost/USBHost/USBDeviceConnected.cpp b/features/unsupported/USBHost/USBHost/USBDeviceConnected.cpp index 8314b3ef40..7741213f23 100644 --- a/features/unsupported/USBHost/USBHost/USBDeviceConnected.cpp +++ b/features/unsupported/USBHost/USBHost/USBDeviceConnected.cpp @@ -94,7 +94,7 @@ void USBDeviceConnected::init(uint8_t hub_, uint8_t port_, bool lowSpeed_) { void USBDeviceConnected::disconnect() { for(int i = 0; i < MAX_INTF; i++) { - intf[i].detach.call(); + if (intf[i].detach) intf[i].detach.call(); } init(); } diff --git a/features/unsupported/USBHost/USBHost/USBEndpoint.cpp b/features/unsupported/USBHost/USBHost/USBEndpoint.cpp index 6e07421855..fc54500f7e 100644 --- a/features/unsupported/USBHost/USBHost/USBEndpoint.cpp +++ b/features/unsupported/USBHost/USBHost/USBEndpoint.cpp @@ -17,7 +17,7 @@ #include "dbg.h" #include "USBEndpoint.h" - +#if !defined(USBHOST_OTHER) void USBEndpoint::init(HCED * hced_, ENDPOINT_TYPE type_, ENDPOINT_DIRECTION dir_, uint32_t size, uint8_t ep_number, HCTD* td_list_[2]) { hced = hced_; @@ -76,6 +76,7 @@ void USBEndpoint::setSpeed(uint8_t speed) hced->control &= ~(1 << 13); hced->control |= (speed << 13); } +#endif //Only for control Eps void USBEndpoint::setNextToken(uint32_t token) @@ -95,7 +96,6 @@ void USBEndpoint::setNextToken(uint32_t token) break; } } - struct { USB_TYPE type; const char * str; @@ -120,19 +120,18 @@ struct { {USB_TYPE_PROCESSING, "USB_TYPE_PROCESSING"}, {USB_TYPE_ERROR, "USB_TYPE_ERROR"} }; +const char * USBEndpoint::getStateString() { + return type_string[state].str; +} +#if !defined(USBHOST_OTHER) void USBEndpoint::setState(uint8_t st) { if (st > 18) return; state = type_string[st].type; } - -const char * USBEndpoint::getStateString() { - return type_string[state].str; -} - -void USBEndpoint::queueTransfer() +USB_TYPE USBEndpoint::queueTransfer() { transfer_len = (uint32_t)td_current->bufEnd - (uint32_t)td_current->currBufPtr + 1; transferred = transfer_len; @@ -142,6 +141,7 @@ void USBEndpoint::queueTransfer() state = USB_TYPE_PROCESSING; td_current->nextTD = (hcTd*)td_next; hced->tailTD = td_next; + return USB_TYPE_PROCESSING; } void USBEndpoint::unqueueTransfer(volatile HCTD * td) @@ -160,3 +160,4 @@ void USBEndpoint::queueEndpoint(USBEndpoint * ed) nextEp = ed; hced->nextED = (ed == NULL) ? 0 : (hcEd*)(ed->getHCED()); } +#endif diff --git a/features/unsupported/USBHost/USBHost/USBEndpoint.h b/features/unsupported/USBHost/USBHost/USBEndpoint.h index 64b320f213..5517944adb 100644 --- a/features/unsupported/USBHost/USBHost/USBEndpoint.h +++ b/features/unsupported/USBHost/USBHost/USBEndpoint.h @@ -47,6 +47,7 @@ public: * @param ep_number endpoint number * @param td_list array of two allocated transfer descriptors */ + void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]); /** @@ -67,7 +68,7 @@ public: /** * Queue a transfer on the endpoint */ - void queueTransfer(); + USB_TYPE queueTransfer(); /** * Unqueue a transfer from the endpoint @@ -104,7 +105,8 @@ public: * Call the handler associted to the end of a transfer */ inline void call() { - rx.call(); + if (rx) + rx.call(); }; @@ -122,12 +124,17 @@ public: const char * getStateString(); inline USB_TYPE getState() { return state; } inline ENDPOINT_TYPE getType() { return type; }; +#ifdef USBHOST_OTHER + inline uint8_t getDeviceAddress() { return device_address; }; + inline uint32_t getSize() { return size; }; +#else inline uint8_t getDeviceAddress() { return hced->control & 0x7f; }; + inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; }; + inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); }; +#endif inline int getLengthTransferred() { return transferred; } inline uint8_t * getBufStart() { return buf_start; } inline uint8_t getAddress(){ return address; }; - inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; }; - inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); }; inline volatile HCTD** getTDList() { return td_list; }; inline volatile HCED * getHCED() { return hced; }; inline ENDPOINT_DIRECTION getDir() { return dir; } @@ -145,6 +152,12 @@ private: ENDPOINT_TYPE type; volatile USB_TYPE state; ENDPOINT_DIRECTION dir; +#ifdef USBHOST_OTHER + uint32_t size; + uint32_t ep_number; + uint32_t speed; + uint8_t device_address; +#endif bool setup; uint8_t address; diff --git a/features/unsupported/USBHost/USBHost/USBHost.cpp b/features/unsupported/USBHost/USBHost/USBHost.cpp index 0ff47c5eeb..a10eb5a59a 100644 --- a/features/unsupported/USBHost/USBHost/USBHost.cpp +++ b/features/unsupported/USBHost/USBHost/USBHost.cpp @@ -249,13 +249,14 @@ void USBHost::usb_process() { USBHost::USBHost() : usbThread(osPriorityNormal, USB_THREAD_STACK) { +#ifndef USBHOST_OTHER headControlEndpoint = NULL; headBulkEndpoint = NULL; headInterruptEndpoint = NULL; tailControlEndpoint = NULL; tailBulkEndpoint = NULL; tailInterruptEndpoint = NULL; - +#endif lenReportDescr = 0; controlEndpointAllocated = false; @@ -312,6 +313,12 @@ void USBHost::transferCompleted(volatile uint32_t addr) if (td->ep != NULL) { USBEndpoint * ep = (USBEndpoint *)(td->ep); +#ifdef USBHOST_OTHER + state = ((HCTD *)td)->state; + if (state == USB_TYPE_IDLE) + ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart()); + +#else if (((HCTD *)td)->control >> 28) { state = ((HCTD *)td)->control >> 28; } else { @@ -319,6 +326,9 @@ void USBHost::transferCompleted(volatile uint32_t addr) ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart()); state = 16 /*USB_TYPE_IDLE*/; } +#endif + if (state == USB_TYPE_IDLE) + ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart()); ep->unqueueTransfer(td); @@ -428,8 +438,10 @@ void USBHost::freeDevice(USBDeviceConnected * dev) USB_DBG("FREE INTF %d on dev: %p, %p, nb_endpot: %d, %s", j, (void *)dev->getInterface(j), dev, dev->getInterface(j)->nb_endpoint, dev->getName(j)); for (int i = 0; i < dev->getInterface(j)->nb_endpoint; i++) { if ((ep = dev->getEndpoint(j, i)) != NULL) { +#ifndef USBHOST_OTHER ed = (HCED *)ep->getHCED(); ed->control |= (1 << 14); //sKip bit +#endif unqueueEndpoint(ep); freeTD((volatile uint8_t*)ep->getTDList()[0]); @@ -450,6 +462,9 @@ void USBHost::freeDevice(USBDeviceConnected * dev) void USBHost::unqueueEndpoint(USBEndpoint * ep) { +#ifdef USBHOST_OTHER + ep->setState(USB_TYPE_FREE); +#else USBEndpoint * prec = NULL; USBEndpoint * current = NULL; @@ -499,6 +514,7 @@ void USBHost::unqueueEndpoint(USBEndpoint * ep) current = current->nextEndpoint(); } } +#endif } @@ -563,8 +579,10 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint return false; } +#ifndef USBHOST_OTHER HCED * prevEd; +#endif // set device address in the USBEndpoint descriptor if (dev == NULL) { ep->setDeviceAddress(0); @@ -578,6 +596,7 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint ep->setIntfNb(intf_nb); +#ifndef USBHOST_OTHER // queue the new USBEndpoint on the ED list switch (ep->getType()) { @@ -625,6 +644,7 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint return false; } +#endif ep->dev = dev; dev->addEndpoint(intf_nb, ep); @@ -659,7 +679,7 @@ int USBHost::findDevice(uint8_t hub, uint8_t port, USBHostHub * hub_parent) void USBHost::printList(ENDPOINT_TYPE type) { -#if DEBUG_EP_STATE +#if defined(DEBUG_EP_STATE) && !defined(USBHOST_OTHER) volatile HCED * hced; switch(type) { case CONTROL_ENDPOINT: @@ -699,7 +719,8 @@ void USBHost::printList(ENDPOINT_TYPE type) // add a transfer on the TD linked list USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) { - td_mutex.lock(); + USB_TYPE ret=USB_TYPE_PROCESSING; + td_mutex.lock(); // allocate a TD which will be freed in TDcompletion volatile HCTD * td = ed->getNextTD(); @@ -707,6 +728,7 @@ USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) return USB_TYPE_ERROR; } +#ifndef USBHOST_OTHER uint32_t token = (ed->isSetup() ? TD_SETUP : ( (ed->getDir() == IN) ? TD_IN : TD_OUT )); uint32_t td_toggle; @@ -731,10 +753,16 @@ USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) ed->queueTransfer(); printList(type); enableList(type); +#else + /* call method specific for endpoint */ + td->currBufPtr = buf; + td->size = len; + ret = ed->queueTransfer(); +#endif td_mutex.unlock(); - return USB_TYPE_PROCESSING; + return ret; } @@ -1033,9 +1061,9 @@ USB_TYPE USBHost::generalTransfer(USBDeviceConnected * dev, USBEndpoint * ep, ui printf("\r\n\r\n"); } #endif - addTransfer(ep, buf, len); + res = addTransfer(ep, buf, len); - if (blocking) { + if ((blocking)&& (res == USB_TYPE_PROCESSING)) { ep->ep_queue.get(); res = ep->getState(); @@ -1049,7 +1077,7 @@ USB_TYPE USBHost::generalTransfer(USBDeviceConnected * dev, USBEndpoint * ep, ui return USB_TYPE_OK; } - return USB_TYPE_PROCESSING; + return res; } @@ -1090,9 +1118,9 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType, #endif control->setNextToken(TD_SETUP); - addTransfer(control, (uint8_t*)setupPacket, 8); + res = addTransfer(control, (uint8_t*)setupPacket, 8); - control->ep_queue.get(); + if (res == USB_TYPE_PROCESSING) control->ep_queue.get(); res = control->getState(); USB_DBG_TRANSFER("CONTROL setup stage %s", control->getStateString()); @@ -1104,9 +1132,9 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType, if (length_transfer) { token = (write) ? TD_OUT : TD_IN; control->setNextToken(token); - addTransfer(control, (uint8_t *)buf, length_transfer); + res = addTransfer(control, (uint8_t *)buf, length_transfer); - control->ep_queue.get(); + if (res == USB_TYPE_PROCESSING) control->ep_queue.get(); res = control->getState(); #if DEBUG_TRANSFER @@ -1131,9 +1159,9 @@ USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType, token = (write) ? TD_IN : TD_OUT; control->setNextToken(token); - addTransfer(control, NULL, 0); + res = addTransfer(control, NULL, 0); - control->ep_queue.get(); + if (res == USB_TYPE_PROCESSING) control->ep_queue.get(); res = control->getState(); USB_DBG_TRANSFER("CONTROL ack stage %s", control->getStateString()); diff --git a/features/unsupported/USBHost/USBHost/USBHost.h b/features/unsupported/USBHost/USBHost/USBHost.h index 40c5664c40..df681847d0 100644 --- a/features/unsupported/USBHost/USBHost/USBHost.h +++ b/features/unsupported/USBHost/USBHost/USBHost.h @@ -16,7 +16,9 @@ #ifndef USBHOST_H #define USBHOST_H - +#ifdef TARGET_STM +#include "mbed.h" +#endif #include "USBHALHost.h" #include "USBDeviceConnected.h" #include "IUSBEnumerator.h" diff --git a/features/unsupported/USBHost/USBHost/USBHostConf.h b/features/unsupported/USBHost/USBHost/USBHostConf.h index 3a93b30bf6..dba2335936 100644 --- a/features/unsupported/USBHost/USBHost/USBHostConf.h +++ b/features/unsupported/USBHost/USBHost/USBHostConf.h @@ -16,7 +16,70 @@ #ifndef USBHOST_CONF_H #define USBHOST_CONF_H +#if defined(TARGET_STM) +/* +* Maximum number of devices that can be connected +* to the usb host +*/ +/* hub + 2 devices */ +#define MAX_DEVICE_CONNECTED 3 +/* +* Maximum of Hub connected to the usb host +*/ +#define MAX_HUB_NB 0 + +/* +* Maximum number of ports on a USB hub +*/ +#define MAX_HUB_PORT 2 + +/* +* Enable USBHostMSD +*/ +#define USBHOST_MSD 1 + +/* +* Enable USBHostKeyboard +*/ +#define USBHOST_KEYBOARD 1 + +/* +* Enable USBHostMouse +*/ +#define USBHOST_MOUSE 1 + +/* +* Enable USBHostSerial or USBHostMultiSerial (if set > 1) +*/ +#define USBHOST_SERIAL 1 + +/* +* Enable USB3Gmodule +*/ +#define USBHOST_3GMODULE 1 + +/* +* Enable USB MIDI +*/ +#define USBHOST_MIDI 1 + +/* +* Maximum number of interfaces of a usb device +*/ +#define MAX_INTF 2 + +/* +* Maximum number of endpoints on each interface +*/ +#define MAX_ENDPOINT_PER_INTERFACE 2 + +/* +* Maximum number of endpoint descriptors that can be allocated +*/ +#define MAX_ENDPOINT 11 /* USB FS 11 channel */ + +#else /* * Maximum number of devices that can be connected * to the usb host @@ -77,7 +140,7 @@ * Maximum number of endpoint descriptors that can be allocated */ #define MAX_ENDPOINT (MAX_DEVICE_CONNECTED * MAX_INTF * MAX_ENDPOINT_PER_INTERFACE) - +#endif /* * Maximum number of transfer descriptors that can be allocated */ @@ -86,6 +149,6 @@ /* * usb_thread stack size */ -#define USB_THREAD_STACK (256*4 + MAX_HUB_NB*256*4) +#define USB_THREAD_STACK (256*4 + 2*256*4) #endif diff --git a/features/unsupported/USBHost/USBHost/USBHostTypes.h b/features/unsupported/USBHost/USBHost/USBHostTypes.h index 860e77d6c6..c2dedb40dc 100644 --- a/features/unsupported/USBHost/USBHost/USBHostTypes.h +++ b/features/unsupported/USBHost/USBHost/USBHostTypes.h @@ -67,6 +67,7 @@ enum ENDPOINT_TYPE { #define HUB_CLASS 0x09 #define SERIAL_CLASS 0x0A +#if !defined(USBHOST_OTHER) // ------------------ HcControl Register --------------------- #define OR_CONTROL_PLE 0x00000004 #define OR_CONTROL_CLE 0x00000010 @@ -114,6 +115,13 @@ enum ENDPOINT_TYPE { #define TD_TOGGLE_1 (uint32_t)(0x03000000) // Toggle 1 #define TD_CC (uint32_t)(0xF0000000) // Completion Code +#else + +#define TD_SETUP (uint32_t)(0) // Direction of Setup Packet +#define TD_IN (uint32_t)(0x00100000) // Direction In +#define TD_OUT (uint32_t)(0x00080000) // Direction Out + +#endif #define DEVICE_DESCRIPTOR (1) #define CONFIGURATION_DESCRIPTOR (2) #define INTERFACE_DESCRIPTOR (4) @@ -140,6 +148,27 @@ enum ENDPOINT_TYPE { #define DEVICE_DESCRIPTOR_LENGTH 0x12 #define CONFIGURATION_DESCRIPTOR_LENGTH 0x09 +// ------------ HostController Transfer Descriptor ------------ +#if defined(USBHOST_OTHER) + +typedef struct hcTd { + __IO uint32_t state; + __IO uint8_t * currBufPtr; // Physical address of current buffer pointer + __IO hcTd * nextTD; // Physical pointer to next Transfer Descriptor + __IO uint32_t size; // size of buffer + void * ep; // ep address where a td is linked in +} PACKED HCTD; +// ----------- HostController EndPoint Descriptor ------------- +typedef struct hcEd { + uint8_t ch_num; + void *hhcd; +} PACKED HCED; +// ----------- Host Controller Communication Area ------------ +#define HCCA void + + +#else +// -------------OHCI register -------------------------------- // ------------ HostController Transfer Descriptor ------------ typedef struct hcTd { __IO uint32_t control; // Transfer descriptor control @@ -149,7 +178,6 @@ typedef struct hcTd { void * ep; // ep address where a td is linked in uint32_t dummy[3]; // padding } PACKED HCTD; - // ----------- HostController EndPoint Descriptor ------------- typedef struct hcEd { __IO uint32_t control; // Endpoint descriptor control @@ -157,8 +185,6 @@ typedef struct hcEd { __IO HCTD * headTD; // Physcial address of head in Transfer descriptor list __IO hcEd * nextED; // Physical address of next Endpoint descriptor } PACKED HCED; - - // ----------- Host Controller Communication Area ------------ typedef struct hcca { __IO uint32_t IntTable[32]; // Interrupt Table @@ -167,6 +193,7 @@ typedef struct hcca { volatile uint8_t Reserved[116]; // Reserved for future use volatile uint8_t Unknown[4]; // Unused } PACKED HCCA; +#endif typedef struct { uint8_t bLength; diff --git a/features/unsupported/tests/usb/host/mass_storage/main.cpp b/features/unsupported/tests/usb/host/mass_storage/main.cpp new file mode 100644 index 0000000000..ae0d7bc49a --- /dev/null +++ b/features/unsupported/tests/usb/host/mass_storage/main.cpp @@ -0,0 +1,44 @@ +#include "mbed.h" +#include "USBHostMSD.h" +DigitalOut led(LED1); +void msd_task(void const *) { + printf("init msd\n"); + USBHostMSD msd("usb"); + int i = 0; + printf("wait for usb memory stick insertion\n"); + while(1) { + + // try to connect a MSD device + while(!msd.connect()) { + Thread::wait(500); + } + + // in a loop, append a file + // if the device is disconnected, we try to connect it again + + // append a file + FILE * fp = fopen("/usb/test1.txt", "a"); + + if (fp != NULL) { + fprintf(fp, "Hello fun SD Card World: %d!\r\n", i++); + printf("Goodbye World!\r\n"); + fclose(fp); + } else { + printf("FILE == NULL\r\n"); + } + Thread::wait(500); + printf("again\n"); + // if device disconnected, try to connect again + while (msd.connected()) { + Thread::wait(500); + } + } +} + +int main() { + Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4); + while(1) { + led=!led; + Thread::wait(500); + } +} diff --git a/features/unsupported/tests/usb/host/mouse/main.cpp b/features/unsupported/tests/usb/host/mouse/main.cpp new file mode 100644 index 0000000000..0954ead3d6 --- /dev/null +++ b/features/unsupported/tests/usb/host/mouse/main.cpp @@ -0,0 +1,34 @@ +#include "mbed.h" +#include "USBHostMouse.h" + +DigitalOut led(LED1); + +void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) { + printf("buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z); +} + +void mouse_task(void const *) { + + USBHostMouse mouse; + + while(1) { + // try to connect a USB mouse + while(!mouse.connect()) + Thread::wait(500); + + // when connected, attach handler called on mouse event + mouse.attachEvent(onMouseEvent); + + // wait until the mouse is disconnected + while(mouse.connected()) + Thread::wait(500); + } +} + +int main() { + Thread mouseTask(mouse_task, NULL, osPriorityNormal, 256 * 4); + while(1) { + led=!led; + Thread::wait(500); + } +} diff --git a/targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_hal_hcd.c b/targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_hal_hcd.c index e2ba96d481..4f49587a87 100644 --- a/targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_hal_hcd.c +++ b/targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_hal_hcd.c @@ -200,7 +200,10 @@ HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd, hhcd->hc[ch_num].ep_num = epnum & 0x7FU; hhcd->hc[ch_num].ep_is_in = ((epnum & 0x80U) == 0x80U); hhcd->hc[ch_num].speed = speed; - + /* reset to 0 */ + hhcd->hc[ch_num].toggle_out = 0; + hhcd->hc[ch_num].toggle_in = 0; + status = USB_HC_Init(hhcd->Instance, ch_num, epnum, @@ -335,7 +338,26 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, uint16_t length, uint8_t do_ping) { - hhcd->hc[ch_num].ep_is_in = direction; + if ((hhcd->hc[ch_num].ep_is_in != direction)) { + if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL)){ + /* reconfigure the endpoint !!! from tx -> rx, and rx ->tx */ + USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; + if (direction) + { + USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_BBERRM; + USBx_HC(ch_num)->HCCHAR |= 1 << 15; + } + else + { + USBx_HC(ch_num)->HCINTMSK &= ~USB_OTG_HCINTMSK_BBERRM; + USBx_HC(ch_num)->HCCHAR &= ~(1 << 15); + } + hhcd->hc[ch_num].ep_is_in = direction; + /* if reception put toggle_in to 1 */ + if (direction == 1) hhcd->hc[ch_num].toggle_in=1; + } + } + hhcd->hc[ch_num].ep_type = ep_type; if(token == 0) @@ -372,6 +394,18 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, hhcd->hc[ch_num].do_ping = do_ping; } } + else if ((token == 1) && (direction == 1)) + { + if( hhcd->hc[ch_num].toggle_in == 0) + { + hhcd->hc[ch_num].data_pid = HC_PID_DATA0; + } + else + { + hhcd->hc[ch_num].data_pid = HC_PID_DATA1; + } + + } break; case EP_TYPE_BULK: @@ -402,7 +436,7 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, hhcd->hc[ch_num].data_pid = HC_PID_DATA1; } } - + break; case EP_TYPE_INTR: if(direction == 0U) @@ -429,7 +463,7 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, } } break; - + case EP_TYPE_ISOC: hhcd->hc[ch_num].data_pid = HC_PID_DATA0; break; @@ -866,6 +900,8 @@ static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum) } else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH) { + + int reactivate = 0; __HAL_HCD_MASK_HALT_HC_INT(chnum); if(hhcd->hc[chnum].state == HC_XFRC) @@ -896,9 +932,10 @@ static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum) tmpreg &= ~USB_OTG_HCCHAR_CHDIS; tmpreg |= USB_OTG_HCCHAR_CHENA; USBx_HC(chnum)->HCCHAR = tmpreg; + reactivate = 1; } __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH); - HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); + if (reactivate == 0) HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); } else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR) diff --git a/targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_ll_usb.c b/targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_ll_usb.c index d49b33325e..85dbca6514 100644 --- a/targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_ll_usb.c +++ b/targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_ll_usb.c @@ -1518,6 +1518,7 @@ HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDe /* Write packet into the Tx FIFO. */ USB_WritePacket(USBx, hc->xfer_buff, hc->ch_num, hc->xfer_len, 0); + hc->xfer_count = hc->xfer_len; } } diff --git a/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_hcd.c b/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_hcd.c index 44d6840605..25a8e574df 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_hcd.c +++ b/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_hcd.c @@ -204,7 +204,10 @@ HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd, hhcd->hc[ch_num].ep_num = epnum & 0x7FU; hhcd->hc[ch_num].ep_is_in = ((epnum & 0x80U) == 0x80U); hhcd->hc[ch_num].speed = speed; - + /* reset to 0 */ + hhcd->hc[ch_num].toggle_out = 0; + hhcd->hc[ch_num].toggle_in = 0; + status = USB_HC_Init(hhcd->Instance, ch_num, epnum, @@ -339,9 +342,27 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, uint16_t length, uint8_t do_ping) { - hhcd->hc[ch_num].ep_is_in = direction; - hhcd->hc[ch_num].ep_type = ep_type; - + if ((hhcd->hc[ch_num].ep_is_in != direction)) { + if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL)){ + /* reconfigure the endpoint !!! from tx -> rx, and rx ->tx */ + USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; + if (direction) + { + USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_BBERRM; + USBx_HC(ch_num)->HCCHAR |= 1 << 15; + } + else + { + USBx_HC(ch_num)->HCINTMSK &= ~USB_OTG_HCINTMSK_BBERRM; + USBx_HC(ch_num)->HCCHAR &= ~(1 << 15); + } + hhcd->hc[ch_num].ep_is_in = direction; + /* if reception put toggle_in to 1 */ + if (direction == 1) hhcd->hc[ch_num].toggle_in=1; + } + } + hhcd->hc[ch_num].ep_type = ep_type; + if(token == 0U) { hhcd->hc[ch_num].data_pid = HC_PID_SETUP; @@ -376,6 +397,17 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, hhcd->hc[ch_num].do_ping = do_ping; } } + else if ((token == 1) && (direction == 1)) + { + if( hhcd->hc[ch_num].toggle_in == 0) + { + hhcd->hc[ch_num].data_pid = HC_PID_DATA0; + } + else + { + hhcd->hc[ch_num].data_pid = HC_PID_DATA1; + } + } break; case EP_TYPE_BULK: @@ -870,20 +902,21 @@ static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum) } else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH) { + int reactivate=0; __HAL_HCD_MASK_HALT_HC_INT(chnum); - + if(hhcd->hc[chnum].state == HC_XFRC) { hhcd->hc[chnum].urb_state = URB_DONE; } - + else if (hhcd->hc[chnum].state == HC_STALL) { hhcd->hc[chnum].urb_state = URB_STALL; } - + else if((hhcd->hc[chnum].state == HC_XACTERR) || - (hhcd->hc[chnum].state == HC_DATATGLERR)) + (hhcd->hc[chnum].state == HC_DATATGLERR)) { if(hhcd->hc[chnum].ErrCnt++ > 3U) { @@ -894,15 +927,16 @@ static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum) { hhcd->hc[chnum].urb_state = URB_NOTREADY; } - + /* re-activate the channel */ tmpreg = USBx_HC(chnum)->HCCHAR; tmpreg &= ~USB_OTG_HCCHAR_CHDIS; tmpreg |= USB_OTG_HCCHAR_CHENA; USBx_HC(chnum)->HCCHAR = tmpreg; + reactivate = 1; } __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH); - HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); + if (reactivate == 0) HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); } else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR) diff --git a/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_ll_usb.c b/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_ll_usb.c index 0f6def20fc..702c45aaa0 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_ll_usb.c +++ b/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_ll_usb.c @@ -1540,6 +1540,7 @@ HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDe /* Write packet into the Tx FIFO. */ USB_WritePacket(USBx, hc->xfer_buff, hc->ch_num, hc->xfer_len, 0); + hc->xfer_count = hc->xfer_len; } } diff --git a/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_hcd.c b/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_hcd.c index a49717bb89..1ac92a912b 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_hcd.c +++ b/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_hcd.c @@ -200,6 +200,9 @@ HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd, hhcd->hc[ch_num].ep_num = epnum & 0x7F; hhcd->hc[ch_num].ep_is_in = ((epnum & 0x80) == 0x80); hhcd->hc[ch_num].speed = speed; + /* reset to 0 */ + hhcd->hc[ch_num].toggle_out = 0; + hhcd->hc[ch_num].toggle_in = 0; status = USB_HC_Init(hhcd->Instance, ch_num, @@ -337,9 +340,27 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, uint16_t length, uint8_t do_ping) { - hhcd->hc[ch_num].ep_is_in = direction; - hhcd->hc[ch_num].ep_type = ep_type; - + if ((hhcd->hc[ch_num].ep_is_in != direction)) { + if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL)){ + /* reconfigure the endpoint !!! from tx -> rx, and rx ->tx */ + USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; + if (direction) + { + USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_BBERRM; + USBx_HC(ch_num)->HCCHAR |= 1 << 15; + } + else + { + USBx_HC(ch_num)->HCINTMSK &= ~USB_OTG_HCINTMSK_BBERRM; + USBx_HC(ch_num)->HCCHAR &= ~(1 << 15); + } + hhcd->hc[ch_num].ep_is_in = direction; + /* if reception put toggle_in to 1 */ + if (direction == 1) hhcd->hc[ch_num].toggle_in=1; + } + } + hhcd->hc[ch_num].ep_type = ep_type; + if(token == 0) { hhcd->hc[ch_num].data_pid = HC_PID_SETUP; @@ -348,7 +369,7 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, { hhcd->hc[ch_num].data_pid = HC_PID_DATA1; } - + /* Manage Data Toggle */ switch(ep_type) { @@ -359,7 +380,7 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, { /* For Status OUT stage, Length==0, Status Out PID = 1 */ hhcd->hc[ch_num].toggle_out = 1; } - + /* Set the Data Toggle bit as per the Flag */ if ( hhcd->hc[ch_num].toggle_out == 0) { /* Put the PID 0 */ @@ -374,8 +395,20 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, hhcd->hc[ch_num].do_ping = do_ping; } } + else if ((token == 1) && (direction == 1)) + { + if( hhcd->hc[ch_num].toggle_in == 0) + { + hhcd->hc[ch_num].data_pid = HC_PID_DATA0; + } + else + { + hhcd->hc[ch_num].data_pid = HC_PID_DATA1; + } + + } break; - + case EP_TYPE_BULK: if(direction == 0) { @@ -404,7 +437,7 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, hhcd->hc[ch_num].data_pid = HC_PID_DATA1; } } - + break; case EP_TYPE_INTR: if(direction == 0) @@ -870,7 +903,8 @@ static void HCD_HC_IN_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum) } else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH) { - __HAL_HCD_MASK_HALT_HC_INT(chnum); + int reactivate = 0; + __HAL_HCD_MASK_HALT_HC_INT(chnum); if(hhcd->hc[chnum].state == HC_XFRC) { @@ -894,15 +928,16 @@ static void HCD_HC_IN_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum) { hhcd->hc[chnum].urb_state = URB_NOTREADY; } - + /* re-activate the channel */ tmpreg = USBx_HC(chnum)->HCCHAR; tmpreg &= ~USB_OTG_HCCHAR_CHDIS; tmpreg |= USB_OTG_HCCHAR_CHENA; - USBx_HC(chnum)->HCCHAR = tmpreg; + USBx_HC(chnum)->HCCHAR = tmpreg; + reactivate = 1; } __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH); - HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); + if (reactivate == 0 )HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); } else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR) diff --git a/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_ll_usb.c b/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_ll_usb.c index d992109199..b8593ef562 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_ll_usb.c +++ b/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_ll_usb.c @@ -1520,6 +1520,8 @@ HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDe /* Write packet into the Tx FIFO. */ USB_WritePacket(USBx, hc->xfer_buff, hc->ch_num, hc->xfer_len, 0); + hc->xfer_count = hc->xfer_len; + } } diff --git a/targets/TARGET_STM/TARGET_STM32L4/device/stm32l4xx_hal_hcd.c b/targets/TARGET_STM/TARGET_STM32L4/device/stm32l4xx_hal_hcd.c index 2cf5cc729f..f43fde3ea9 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/device/stm32l4xx_hal_hcd.c +++ b/targets/TARGET_STM/TARGET_STM32L4/device/stm32l4xx_hal_hcd.c @@ -206,6 +206,9 @@ HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd, hhcd->hc[ch_num].ep_num = epnum & 0x7F; hhcd->hc[ch_num].ep_is_in = ((epnum & 0x80) == 0x80); hhcd->hc[ch_num].speed = speed; + /* reset to 0 */ + hhcd->hc[ch_num].toggle_out = 0; + hhcd->hc[ch_num].toggle_in = 0; status = USB_HC_Init(hhcd->Instance, ch_num, @@ -343,8 +346,26 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, uint16_t length, uint8_t do_ping) { - hhcd->hc[ch_num].ep_is_in = direction; - hhcd->hc[ch_num].ep_type = ep_type; + if ((hhcd->hc[ch_num].ep_is_in != direction)) { + if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL)){ + /* reconfigure the endpoint !!! from tx -> rx, and rx ->tx */ + USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; + if (direction) + { + USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_BBERRM; + USBx_HC(ch_num)->HCCHAR |= 1 << 15; + } + else + { + USBx_HC(ch_num)->HCINTMSK &= ~USB_OTG_HCINTMSK_BBERRM; + USBx_HC(ch_num)->HCCHAR &= ~(1 << 15); + } + hhcd->hc[ch_num].ep_is_in = direction; + /* if reception put toggle_in to 1 */ + if (direction == 1) hhcd->hc[ch_num].toggle_in=1; + } + } + hhcd->hc[ch_num].ep_type = ep_type; if(token == 0) { @@ -380,6 +401,17 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, hhcd->hc[ch_num].do_ping = do_ping; } } + else if ((token == 1) && (direction == 1)) + { + if( hhcd->hc[ch_num].toggle_in == 0) + { + hhcd->hc[ch_num].data_pid = HC_PID_DATA0; + } + else + { + hhcd->hc[ch_num].data_pid = HC_PID_DATA1; + } + } break; case EP_TYPE_BULK: @@ -878,6 +910,7 @@ static void HCD_HC_IN_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum) } else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH) { + int reactivate = 0; __HAL_HCD_MASK_HALT_HC_INT(chnum); if(hhcd->hc[chnum].state == HC_XFRC) @@ -907,10 +940,11 @@ static void HCD_HC_IN_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum) tmpreg = USBx_HC(chnum)->HCCHAR; tmpreg &= ~USB_OTG_HCCHAR_CHDIS; tmpreg |= USB_OTG_HCCHAR_CHENA; - USBx_HC(chnum)->HCCHAR = tmpreg; + USBx_HC(chnum)->HCCHAR = tmpreg; + reactivate = 1; } __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH); - HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); + if (reactivate == 0) HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); } else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR) diff --git a/targets/TARGET_STM/TARGET_STM32L4/device/stm32l4xx_ll_usb.c b/targets/TARGET_STM/TARGET_STM32L4/device/stm32l4xx_ll_usb.c index 2fffe7d275..8048d89a36 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/device/stm32l4xx_ll_usb.c +++ b/targets/TARGET_STM/TARGET_STM32L4/device/stm32l4xx_ll_usb.c @@ -1399,6 +1399,8 @@ HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDe /* Write packet into the Tx FIFO. */ USB_WritePacket(USBx, hc->xfer_buff, hc->ch_num, hc->xfer_len, 0); + hc->xfer_count = hc->xfer_len; + } } diff --git a/targets/targets.json b/targets/targets.json index 42b0fbc846..b3132ec1b8 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -734,7 +734,7 @@ "supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"], "inherits": ["Target"], "detect_code": ["0835"], - "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"], + "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USBHOST_OTHER"], "device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"], "features": ["LWIP"], "release_versions": ["2", "5"], @@ -816,7 +816,7 @@ "supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"], "inherits": ["Target"], "detect_code": ["0720"], - "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USB_STM_HAL"], + "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USB_STM_HAL", "USBHOST_OTHER"], "device_has": ["ANALOGIN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"], "release_versions": ["2", "5"], "device_name": "STM32F401RE" @@ -842,7 +842,7 @@ "supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"], "inherits": ["Target"], "detect_code": ["0740"], - "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USB_STM_HAL"], + "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USB_STM_HAL", "USBHOST_OTHER"], "device_has": ["ANALOGIN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"], "release_versions": ["2", "5"], "device_name": "STM32F411RE" @@ -882,7 +882,7 @@ "extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx", "F429_F439"], "supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"], "progen": {"target": "nucleo-f429zi"}, - "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USB_STM_HAL"], + "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USB_STM_HAL", "USBHOST_OTHER"], "device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"], "detect_code": ["0796"], "features": ["LWIP"], @@ -925,7 +925,7 @@ "supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"], "inherits": ["Target"], "detect_code": ["0778"], - "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USB_STM_HAL"], + "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USB_STM_HAL", "USBHOST_OTHER"], "device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"], "release_versions": ["2", "5"], "device_name" : "STM32F446ZE" @@ -949,7 +949,7 @@ "extra_labels": ["STM", "STM32F7", "STM32F746", "STM32F746ZG", "F746_F756"], "supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"], "default_toolchain": "ARM", - "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"], + "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USBHOST_OTHER"], "supported_form_factors": ["ARDUINO"], "detect_code": ["0816"], "device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"], @@ -977,7 +977,7 @@ "supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"], "default_toolchain": "ARM", "supported_form_factors": ["ARDUINO"], - "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"], + "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USBHOST_OTHER"], "detect_code": ["0818"], "device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"], "features": ["LWIP"], @@ -1068,7 +1068,7 @@ "supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"], "inherits": ["Target"], "detect_code": ["0765"], - "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"], + "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2","USBHOST_OTHER"], "device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"], "release_versions": ["2", "5"], "device_name": "stm32l476rg" @@ -1168,7 +1168,7 @@ "core": "Cortex-M4F", "default_toolchain": "ARM", "extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx"], - "macros": ["RTC_LSI=1","TRANSACTION_QUEUE_SIZE_SPI=2"], + "macros": ["RTC_LSI=1","TRANSACTION_QUEUE_SIZE_SPI=2", "USBHOST_OTHER"], "supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"], "device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"], "release_versions": ["2", "5"], @@ -1233,7 +1233,7 @@ "extra_labels": ["STM", "STM32L4", "STM32L476VG"], "supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"], "detect_code": ["0820"], - "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"], + "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USBHOST_OTHER"], "device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"], "release_versions": ["2", "5"], "device_name": "stm32l476vg" diff --git a/tools/build_travis.py b/tools/build_travis.py index 7d4ae0fc5b..408d7dc32e 100644 --- a/tools/build_travis.py +++ b/tools/build_travis.py @@ -45,26 +45,26 @@ build_list = ( { "target": "NUCLEO_F072RB", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, { "target": "NUCLEO_F091RC", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, { "target": "NUCLEO_F103RB", "toolchains": "GCC_ARM", "libs": ["rtos", "fat"] }, - { "target": "NUCLEO_F207ZG", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, + { "target": "NUCLEO_F207ZG", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat", "usb_host"] }, { "target": "NUCLEO_F302R8", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, { "target": "NUCLEO_F303K8", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, { "target": "NUCLEO_F303RE", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, { "target": "NUCLEO_F303ZE", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, { "target": "NUCLEO_F334R8", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, - { "target": "NUCLEO_F401RE", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, + { "target": "NUCLEO_F401RE", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat", "usb_host"] }, { "target": "NUCLEO_F410RB", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, - { "target": "NUCLEO_F411RE", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, + { "target": "NUCLEO_F411RE", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat", "usb_host"] }, { "target": "NUCLEO_F412ZG", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, { "target": "NUCLEO_L432KC", "toolchains": "GCC_ARM", "libs": ["dsp", "fat"] }, - { "target": "NUCLEO_L476RG", "toolchains": "GCC_ARM", "libs": ["dsp", "fat"] }, + { "target": "NUCLEO_L476RG", "toolchains": "GCC_ARM", "libs": ["dsp", "fat", "rtos", "usb_host"] }, { "target": "NUCLEO_L011K4", "toolchains": "GCC_ARM", "libs": ["dsp"] }, { "target": "NUCLEO_L031K6", "toolchains": "GCC_ARM", "libs": ["dsp"] }, { "target": "NUCLEO_L073RZ", "toolchains": "GCC_ARM", "libs": ["dsp", "fat"] }, - { "target": "NUCLEO_F429ZI", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, + { "target": "NUCLEO_F429ZI", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat", "usb_host"] }, { "target": "NUCLEO_F446RE", "toolchains": "GCC_ARM", "libs": ["dsp", "fat"] }, - { "target": "NUCLEO_F446ZE", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, - { "target": "NUCLEO_F746ZG", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, - { "target": "NUCLEO_F767ZI", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, + { "target": "NUCLEO_F446ZE", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat", "usb_host"] }, + { "target": "NUCLEO_F746ZG", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat", "usb_host" ] }, + { "target": "NUCLEO_F767ZI", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat", "usb_host"] }, { "target": "MOTE_L152RC", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, @@ -80,7 +80,7 @@ build_list = ( { "target": "DISCO_F334C8", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, { "target": "DISCO_F401VC", "toolchains": "GCC_ARM", "libs": ["dsp", "fat"] }, { "target": "DISCO_F407VG", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, - { "target": "DISCO_F429ZI", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, + { "target": "DISCO_F429ZI", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat", "usb_host"] }, { "target": "DISCO_F469NI", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, { "target": "DISCO_F746NG", "toolchains": "GCC_ARM", "libs": ["dsp", "fat"] }, { "target": "DISCO_F769NI", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "fat"] }, @@ -126,7 +126,7 @@ build_list = ( { "target": "SAMD21J18A", "toolchains": "GCC_ARM", "libs": ["dsp", "fat"] }, { "target": "SAMD21G18A", "toolchains": "GCC_ARM", "libs": ["dsp", "fat"] }, { "target": "SAML21J18A", "toolchains": "GCC_ARM", "libs": ["dsp", "fat"] }, - { "target": "DISCO_L476VG", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, + { "target": "DISCO_L476VG", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat", "usb_host"] }, { "target": "NUMAKER_PFM_NUC472", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, { "target": "NUMAKER_PFM_M453", "toolchains": "GCC_ARM", "libs": ["dsp", "rtos", "usb", "fat"] }, @@ -173,49 +173,63 @@ linking_list = [ "toolchains": "GCC_ARM", "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_16"], "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], - "usb" : ["USB_1", "USB_2" ,"USB_3"], + "usb" : ["USB_1", "USB_2" ,"USB_3", "USB_10", "USB_11"], } }, {"target": "NUCLEO_F401RE", "toolchains": "GCC_ARM", "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_16"], "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], - "usb" : ["USB_1", "USB_2" ,"USB_3"], + "usb" : ["USB_1", "USB_2" ,"USB_3", "USB_10", "USB_11"], } }, {"target": "NUCLEO_F411RE", "toolchains": "GCC_ARM", "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_16"], "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], - "usb" : ["USB_1", "USB_2" ,"USB_3"], + "usb" : ["USB_1", "USB_2" ,"USB_3", "USB_10", "USB_11"], } }, {"target": "NUCLEO_F429ZI", "toolchains": "GCC_ARM", "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_16"], "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], - "usb" : ["USB_1", "USB_2" ,"USB_3"], + "usb" : ["USB_1", "USB_2" ,"USB_3", "USB_10", "USB_11"], } }, {"target": "NUCLEO_F207ZG", "toolchains": "GCC_ARM", "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_16"], "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], - "usb" : ["USB_1", "USB_2" ,"USB_3"], + "usb" : ["USB_1", "USB_2" ,"USB_3", "USB_10", "USB_11"], } }, {"target": "NUCLEO_F746ZG", "toolchains": "GCC_ARM", "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_16"], "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], - "usb" : ["USB_1", "USB_2" ,"USB_3"], + "usb" : ["USB_1", "USB_2" ,"USB_3", "USB_10", "USB_11"], } }, {"target": "NUCLEO_F767ZI", "toolchains": "GCC_ARM", "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_16"], "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], - "usb" : ["USB_1", "USB_2" ,"USB_3"], + "usb" : ["USB_1", "USB_2" ,"USB_3", "USB_10", "USB_11"], + } + }, + {"target": "NUCLEO_L476RG", + "toolchains": "GCC_ARM", + "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_16"], + "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], + "usb" : [ "USB_10", "USB_11"], + } + }, + {"target": "DISCO_F429ZI", + "toolchains": "GCC_ARM", + "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_16"], + "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], + "usb" : [ "USB_10", "USB_11"], } }, {"target": "DISCO_F407VG", @@ -236,7 +250,7 @@ linking_list = [ "toolchains": "GCC_ARM", "tests": {"" : ["MBED_2", "MBED_10", "MBED_11", "MBED_16"], "rtos" : ["RTOS_1", "RTOS_2", "RTOS_3"], - "usb" : ["USB_1", "USB_2" ,"USB_3"], + "usb" : ["USB_1", "USB_2" ,"USB_3", "USB_10", "USB_11"], } }, {"target": "NUMAKER_PFM_NUC472", diff --git a/tools/tests.py b/tools/tests.py index a9f40ea090..037ceea50f 100644 --- a/tools/tests.py +++ b/tools/tests.py @@ -977,7 +977,8 @@ TESTS = [ "supported": CORTEX_ARM_SUPPORT, }, - # USB Tests + # USB Tests + # USB device test list { "id": "USB_1", "description": "Mouse", "source_dir": join(TEST_DIR, "usb", "device", "basic"), @@ -1018,7 +1019,17 @@ TESTS = [ "source_dir": join(TEST_DIR, "usb", "device", "audio_cb"), "dependencies": [MBED_LIBRARIES, USB_LIBRARIES], }, - + # USB host test list + { + "id": "USB_10", "description": "MSD", + "source_dir": join(TEST_DIR, "usb", "host", "mass_storage"), + "dependencies": [MBED_LIBRARIES, USB_HOST_LIBRARIES, FAT_FS, RTOS], + }, + { + "id": "USB_11", "description": "mouse", + "source_dir": join(TEST_DIR, "usb", "host", "mouse"), + "dependencies": [MBED_LIBRARIES, USB_HOST_LIBRARIES, RTOS], + }, # CMSIS DSP { "id": "CMSIS_DSP_1", "description": "FIR",