Added TARGET_DISCO_F469NI in USBHOST\USBHost\TARGET_STM\USBHALHost_STM_TARGET.h
Dependents: DISCO-F469NI_USB_Disk STM32F4xx_USB_Memory
Fork of USBHOST by
USBHost/TARGET_STM/USBHALHost_DISCOL476VG.h@1:ab240722d7ef, 2017-02-15 (annotated)
- Committer:
- frq08711@LMECWL0871.LME.ST.COM
- Date:
- Wed Feb 15 10:49:44 2017 +0100
- Revision:
- 1:ab240722d7ef
update to mbed 5.3.5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1 | /* Copyright (c) 2016 mbed.org, MIT License |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 2 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 7 | * Software is furnished to do so, subject to the following conditions: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 8 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 10 | * substantial portions of the Software. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 11 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 17 | */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 18 | #ifndef USBHALHOST_DISCOL476VG |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 19 | #define USBHALHOST_DISCOL476VG |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 20 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 21 | #define USBHAL_IRQn OTG_FS_IRQn |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 22 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 23 | #define HCCA_SIZE sizeof(HCD_HandleTypeDef) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 24 | #define ED_SIZE sizeof(HCED) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 25 | #define TD_SIZE sizeof(HCTD) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 26 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 27 | #define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE) + (MAX_TD*TD_SIZE)) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 28 | /* STM device FS have 11 channels (definition is for 60 channels) */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 29 | static volatile uint8_t usb_buf[TOTAL_SIZE]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 30 | typedef struct |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 31 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 32 | /* store the request ongoing on each endpoit */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 33 | /* 1st field of structure avoid giving knowledge of all structure to |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 34 | * endpoint */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 35 | volatile uint32_t addr[MAX_ENDPOINT]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 36 | USBHALHost *inst; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 37 | void (USBHALHost::*deviceConnected)(int hub, int port, bool lowSpeed, USBHostHub * hub_parent); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 38 | void (USBHALHost::*deviceDisconnected)(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 39 | void (USBHALHost::*transferCompleted)(volatile uint32_t addr); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 40 | }USBHALHost_Private_t; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 41 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 42 | static gpio_t gpio_vbus; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 43 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 44 | #define VBUS_OFF 1 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 45 | #define VBUS_ON 0 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 46 | #define USB_VBUS_CONFIG \ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 47 | do {\ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 48 | gpio_init_out_ex(&gpio_vbus, PC_9, VBUS_OFF);\ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 49 | }while(0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 50 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 51 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 52 | void usb_vbus( uint8_t state) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 53 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 54 | if(state == 0) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 55 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 56 | gpio_write(&gpio_vbus, VBUS_OFF); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 57 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 58 | else |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 59 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 60 | gpio_write(&gpio_vbus, VBUS_ON); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 61 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 62 | wait(0.2); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 63 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 64 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 65 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 66 | USBHALHost::USBHALHost() { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 67 | instHost = this; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 68 | HCD_HandleTypeDef *hhcd; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 69 | USBHALHost_Private_t *HALPriv = new(USBHALHost_Private_t); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 70 | memset(HALPriv, 0, sizeof(USBHALHost_Private_t)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 71 | memInit(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 72 | memset((void*)usb_hcca, 0, HCCA_SIZE); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 73 | hhcd = (HCD_HandleTypeDef *)usb_hcca; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 74 | hhcd->Instance = USB_OTG_FS; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 75 | hhcd->pData = (void*)HALPriv; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 76 | hhcd->Init.Host_channels = 11; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 77 | /* for now failed with dma */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 78 | hhcd->Init.dma_enable = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 79 | hhcd->Init.speed = HCD_SPEED_FULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 80 | hhcd->Init.phy_itface = HCD_PHY_EMBEDDED; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 81 | hhcd->Init.use_external_vbus = 1; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 82 | HALPriv->inst = this; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 83 | HALPriv->deviceConnected = &USBHALHost::deviceConnected; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 84 | HALPriv->deviceDisconnected = &USBHALHost::deviceDisconnected; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 85 | HALPriv->transferCompleted = &USBHALHost::transferCompleted; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 86 | for (int i = 0; i < MAX_ENDPOINT; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 87 | edBufAlloc[i] = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 88 | HALPriv->addr[i]=(uint32_t)-1; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 89 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 90 | for (int i = 0; i < MAX_TD; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 91 | tdBufAlloc[i] = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 92 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 93 | __HAL_RCC_PWR_CLK_ENABLE(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 94 | #ifdef TARGET_STM32L4 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 95 | HAL_PWREx_EnableVddUSB(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 96 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 97 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 98 | /* Configure USB HS GPIOs */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 99 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 100 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 101 | /*USB DM and DP */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 102 | pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 103 | pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 104 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 105 | /* Configure VBUS Pin */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 106 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 107 | pin_function(PC_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 108 | /* Configure POWER_SWITCH IO pin */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 109 | USB_VBUS_CONFIG; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 110 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 111 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 112 | /* Enable USB FS Clocks */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 113 | __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 114 | /* Set USBFS Interrupt priority */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 115 | HAL_NVIC_SetPriority(USBHAL_IRQn, 5, 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 116 | NVIC_SetVector(USBHAL_IRQn, (uint32_t)&_usbisr); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 117 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 118 | #endif |