forked for unsupported target
Dependents: stm32-disco-example DISCO-F469NI_BD_SD_Card_Control
Fork of USBHOST by
USBHost/TARGET_STM/USBHALHost_DISCOF746NG.h@7:75f3e275934b, 2017-08-08 (annotated)
- Committer:
- bcjun@aname.co.kr
- Date:
- Tue Aug 08 16:20:39 2017 +0900
- Revision:
- 7:75f3e275934b
change usbhost library that forked in my account
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcjun@aname.co.kr | 7:75f3e275934b | 1 | /* mbed USBHost Library |
bcjun@aname.co.kr | 7:75f3e275934b | 2 | * Copyright (c) 2006-2013 ARM Limited |
bcjun@aname.co.kr | 7:75f3e275934b | 3 | * |
bcjun@aname.co.kr | 7:75f3e275934b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bcjun@aname.co.kr | 7:75f3e275934b | 5 | * you may not use this file except in compliance with the License. |
bcjun@aname.co.kr | 7:75f3e275934b | 6 | * You may obtain a copy of the License at |
bcjun@aname.co.kr | 7:75f3e275934b | 7 | * |
bcjun@aname.co.kr | 7:75f3e275934b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bcjun@aname.co.kr | 7:75f3e275934b | 9 | * |
bcjun@aname.co.kr | 7:75f3e275934b | 10 | * Unless required by applicable law or agreed to in writing, software |
bcjun@aname.co.kr | 7:75f3e275934b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bcjun@aname.co.kr | 7:75f3e275934b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bcjun@aname.co.kr | 7:75f3e275934b | 13 | * See the License for the specific language governing permissions and |
bcjun@aname.co.kr | 7:75f3e275934b | 14 | * limitations under the License. |
bcjun@aname.co.kr | 7:75f3e275934b | 15 | */ |
bcjun@aname.co.kr | 7:75f3e275934b | 16 | #ifndef USBHALHOST_STM32_144_64 |
bcjun@aname.co.kr | 7:75f3e275934b | 17 | #define USBHALHOST_STM32_144_64 |
bcjun@aname.co.kr | 7:75f3e275934b | 18 | |
bcjun@aname.co.kr | 7:75f3e275934b | 19 | #define USBHAL_IRQn OTG_FS_IRQn |
bcjun@aname.co.kr | 7:75f3e275934b | 20 | |
bcjun@aname.co.kr | 7:75f3e275934b | 21 | #define HCCA_SIZE sizeof(HCD_HandleTypeDef) |
bcjun@aname.co.kr | 7:75f3e275934b | 22 | #define ED_SIZE sizeof(HCED) |
bcjun@aname.co.kr | 7:75f3e275934b | 23 | #define TD_SIZE sizeof(HCTD) |
bcjun@aname.co.kr | 7:75f3e275934b | 24 | |
bcjun@aname.co.kr | 7:75f3e275934b | 25 | #define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE) + (MAX_TD*TD_SIZE)) |
bcjun@aname.co.kr | 7:75f3e275934b | 26 | /* STM device FS have 11 channels (definition is for 60 channels) */ |
bcjun@aname.co.kr | 7:75f3e275934b | 27 | static volatile uint8_t usb_buf[TOTAL_SIZE]; |
bcjun@aname.co.kr | 7:75f3e275934b | 28 | typedef struct |
bcjun@aname.co.kr | 7:75f3e275934b | 29 | { |
bcjun@aname.co.kr | 7:75f3e275934b | 30 | /* store the request ongoing on each endpoit */ |
bcjun@aname.co.kr | 7:75f3e275934b | 31 | /* 1st field of structure avoid giving knowledge of all structure to |
bcjun@aname.co.kr | 7:75f3e275934b | 32 | * endpoint */ |
bcjun@aname.co.kr | 7:75f3e275934b | 33 | volatile uint32_t addr[MAX_ENDPOINT]; |
bcjun@aname.co.kr | 7:75f3e275934b | 34 | USBHALHost *inst; |
bcjun@aname.co.kr | 7:75f3e275934b | 35 | void (USBHALHost::*deviceConnected)(int hub, int port, bool lowSpeed, USBHostHub * hub_parent); |
bcjun@aname.co.kr | 7:75f3e275934b | 36 | void (USBHALHost::*deviceDisconnected)(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr); |
bcjun@aname.co.kr | 7:75f3e275934b | 37 | void (USBHALHost::*transferCompleted)(volatile uint32_t addr); |
bcjun@aname.co.kr | 7:75f3e275934b | 38 | }USBHALHost_Private_t; |
bcjun@aname.co.kr | 7:75f3e275934b | 39 | |
bcjun@aname.co.kr | 7:75f3e275934b | 40 | /* CONFIGURATION for USB_VBUS |
bcjun@aname.co.kr | 7:75f3e275934b | 41 | * on 64 bits board PC_0 is used (0 VBUS on, 1 VBUS off) |
bcjun@aname.co.kr | 7:75f3e275934b | 42 | * on 144 pins board PG_6 is used ( 1 VBUS on, 0 VBUS on) |
bcjun@aname.co.kr | 7:75f3e275934b | 43 | */ |
bcjun@aname.co.kr | 7:75f3e275934b | 44 | static gpio_t gpio_vbus; |
bcjun@aname.co.kr | 7:75f3e275934b | 45 | |
bcjun@aname.co.kr | 7:75f3e275934b | 46 | #define VBUS_OFF 1 |
bcjun@aname.co.kr | 7:75f3e275934b | 47 | #define VBUS_ON 0 |
bcjun@aname.co.kr | 7:75f3e275934b | 48 | #define USB_VBUS_CONFIG \ |
bcjun@aname.co.kr | 7:75f3e275934b | 49 | do {__HAL_RCC_GPIOD_CLK_ENABLE();\ |
bcjun@aname.co.kr | 7:75f3e275934b | 50 | gpio_init_out_ex(&gpio_vbus, PD_5, VBUS_OFF);\ |
bcjun@aname.co.kr | 7:75f3e275934b | 51 | }while(0); |
bcjun@aname.co.kr | 7:75f3e275934b | 52 | |
bcjun@aname.co.kr | 7:75f3e275934b | 53 | void usb_vbus( uint8_t state) |
bcjun@aname.co.kr | 7:75f3e275934b | 54 | { |
bcjun@aname.co.kr | 7:75f3e275934b | 55 | if(state == 0) |
bcjun@aname.co.kr | 7:75f3e275934b | 56 | { |
bcjun@aname.co.kr | 7:75f3e275934b | 57 | gpio_write(&gpio_vbus, VBUS_OFF); |
bcjun@aname.co.kr | 7:75f3e275934b | 58 | } |
bcjun@aname.co.kr | 7:75f3e275934b | 59 | else |
bcjun@aname.co.kr | 7:75f3e275934b | 60 | { |
bcjun@aname.co.kr | 7:75f3e275934b | 61 | gpio_write(&gpio_vbus, VBUS_ON); |
bcjun@aname.co.kr | 7:75f3e275934b | 62 | } |
bcjun@aname.co.kr | 7:75f3e275934b | 63 | wait(0.2); |
bcjun@aname.co.kr | 7:75f3e275934b | 64 | } |
bcjun@aname.co.kr | 7:75f3e275934b | 65 | |
bcjun@aname.co.kr | 7:75f3e275934b | 66 | USBHALHost::USBHALHost() { |
bcjun@aname.co.kr | 7:75f3e275934b | 67 | instHost = this; |
bcjun@aname.co.kr | 7:75f3e275934b | 68 | HCD_HandleTypeDef *hhcd; |
bcjun@aname.co.kr | 7:75f3e275934b | 69 | USBHALHost_Private_t *HALPriv = new(USBHALHost_Private_t); |
bcjun@aname.co.kr | 7:75f3e275934b | 70 | memset(HALPriv, 0, sizeof(USBHALHost_Private_t)); |
bcjun@aname.co.kr | 7:75f3e275934b | 71 | memInit(); |
bcjun@aname.co.kr | 7:75f3e275934b | 72 | memset((void*)usb_hcca, 0, HCCA_SIZE); |
bcjun@aname.co.kr | 7:75f3e275934b | 73 | hhcd = (HCD_HandleTypeDef *)usb_hcca; |
bcjun@aname.co.kr | 7:75f3e275934b | 74 | hhcd->Instance = USB_OTG_FS; |
bcjun@aname.co.kr | 7:75f3e275934b | 75 | hhcd->pData = (void*)HALPriv; |
bcjun@aname.co.kr | 7:75f3e275934b | 76 | hhcd->Init.Host_channels = 11; |
bcjun@aname.co.kr | 7:75f3e275934b | 77 | hhcd->Init.speed = HCD_SPEED_FULL; |
bcjun@aname.co.kr | 7:75f3e275934b | 78 | hhcd->Init.phy_itface = HCD_PHY_EMBEDDED; |
bcjun@aname.co.kr | 7:75f3e275934b | 79 | HALPriv->inst = this; |
bcjun@aname.co.kr | 7:75f3e275934b | 80 | HALPriv->deviceConnected = &USBHALHost::deviceConnected; |
bcjun@aname.co.kr | 7:75f3e275934b | 81 | HALPriv->deviceDisconnected = &USBHALHost::deviceDisconnected; |
bcjun@aname.co.kr | 7:75f3e275934b | 82 | HALPriv->transferCompleted = &USBHALHost::transferCompleted; |
bcjun@aname.co.kr | 7:75f3e275934b | 83 | for (int i = 0; i < MAX_ENDPOINT; i++) { |
bcjun@aname.co.kr | 7:75f3e275934b | 84 | edBufAlloc[i] = false; |
bcjun@aname.co.kr | 7:75f3e275934b | 85 | HALPriv->addr[i]=(uint32_t)-1; |
bcjun@aname.co.kr | 7:75f3e275934b | 86 | } |
bcjun@aname.co.kr | 7:75f3e275934b | 87 | for (int i = 0; i < MAX_TD; i++) { |
bcjun@aname.co.kr | 7:75f3e275934b | 88 | tdBufAlloc[i] = false; |
bcjun@aname.co.kr | 7:75f3e275934b | 89 | } |
bcjun@aname.co.kr | 7:75f3e275934b | 90 | __HAL_RCC_PWR_CLK_ENABLE(); |
bcjun@aname.co.kr | 7:75f3e275934b | 91 | #ifdef TARGET_STM32L4 |
bcjun@aname.co.kr | 7:75f3e275934b | 92 | HAL_PWREx_EnableVddUSB(); |
bcjun@aname.co.kr | 7:75f3e275934b | 93 | #endif |
bcjun@aname.co.kr | 7:75f3e275934b | 94 | /* Configure USB FS GPIOs */ |
bcjun@aname.co.kr | 7:75f3e275934b | 95 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
bcjun@aname.co.kr | 7:75f3e275934b | 96 | |
bcjun@aname.co.kr | 7:75f3e275934b | 97 | /*USB DM and DP */ |
bcjun@aname.co.kr | 7:75f3e275934b | 98 | pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); |
bcjun@aname.co.kr | 7:75f3e275934b | 99 | pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); |
bcjun@aname.co.kr | 7:75f3e275934b | 100 | /*USB ID */ |
bcjun@aname.co.kr | 7:75f3e275934b | 101 | pin_function(PA_10, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)); |
bcjun@aname.co.kr | 7:75f3e275934b | 102 | |
bcjun@aname.co.kr | 7:75f3e275934b | 103 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
bcjun@aname.co.kr | 7:75f3e275934b | 104 | /* Configure POWER_SWITCH IO pin */ |
bcjun@aname.co.kr | 7:75f3e275934b | 105 | USB_VBUS_CONFIG; |
bcjun@aname.co.kr | 7:75f3e275934b | 106 | /* Enable USB FS Clocks */ |
bcjun@aname.co.kr | 7:75f3e275934b | 107 | __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
bcjun@aname.co.kr | 7:75f3e275934b | 108 | |
bcjun@aname.co.kr | 7:75f3e275934b | 109 | /* Set USBFS Interrupt priority */ |
bcjun@aname.co.kr | 7:75f3e275934b | 110 | HAL_NVIC_SetPriority(OTG_FS_IRQn, 6, 0); |
bcjun@aname.co.kr | 7:75f3e275934b | 111 | } |
bcjun@aname.co.kr | 7:75f3e275934b | 112 | #endif |