Update for new version of mbed.
Fork of USBDevice_STM32F103 by
Diff: USBDevice/USBHAL_STM32L1.cpp
- Revision:
- 62:23cb405e1ee5
- Parent:
- 61:5f4f01a06669
- Child:
- 63:05e2f2e4dc3e
--- a/USBDevice/USBHAL_STM32L1.cpp Sat Jun 20 11:54:36 2015 +0900 +++ b/USBDevice/USBHAL_STM32L1.cpp Sun Jun 21 11:53:49 2015 +0900 @@ -16,19 +16,33 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if defined(TARGET_STM32L1) +#if defined(TARGET_STM32L1)||defined(TARGET_STM32F1) #include "USBDevice.h" +#if defined(TARGET_STM32F1) +#define USB_LP_IRQn USB_LP_CAN1_RX0_IRQn +const uint8_t PCD_EP_TYPE_CTRL = EP_TYPE_CTRL; +const uint8_t PCD_EP_TYPE_INTR = EP_TYPE_INTR; +const uint8_t PCD_EP_TYPE_BULK = EP_TYPE_BULK; +const uint8_t PCD_EP_TYPE_ISOC = EP_TYPE_ISOC; + +#elif defined(TARGET_STM32L1) +void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) { + __SYSCFG_CLK_ENABLE(); // for SYSCFG_PMC_USB_PU + if (state == 1) { + __HAL_SYSCFG_USBPULLUP_ENABLE(); + } else { + __HAL_SYSCFG_USBPULLUP_DISABLE(); + } +} +#endif + static PCD_HandleTypeDef hpcd_USB_FS; static volatile int epComplete = 0; USBHAL * USBHAL::instance; uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) {return 0;} -extern "C" void USB_LP_IRQHandler(void) { - HAL_PCD_IRQHandler(&hpcd_USB_FS); -} - USBHAL::USBHAL(void) { hpcd_USB_FS.pData = this; hpcd_USB_FS.Instance = USB; @@ -39,37 +53,27 @@ hpcd_USB_FS.Init.Sof_enable = DISABLE; hpcd_USB_FS.Init.low_power_enable = DISABLE; hpcd_USB_FS.Init.battery_charging_enable = DISABLE; + NVIC_SetVector(USB_LP_IRQn, (uint32_t)&_usbisr); HAL_PCD_Init(&hpcd_USB_FS); + HAL_PCD_Start(&hpcd_USB_FS); } void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd) { - __SYSCFG_CLK_ENABLE(); // for SYSCFG_PMC_USB_PU __USB_CLK_ENABLE(); HAL_NVIC_SetPriority(USB_LP_IRQn, 0, 0); HAL_NVIC_EnableIRQ(USB_LP_IRQn); } void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd) { - MBED_ASSERT(hpcd->Instance == USB); __USB_CLK_DISABLE(); // Peripheral clock disable HAL_NVIC_DisableIRQ(USB_LP_IRQn); // Peripheral interrupt Deinit } -void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) { - MBED_ASSERT(READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN)); - if (state == 1) { - __HAL_SYSCFG_USBPULLUP_ENABLE(); - } else { - __HAL_SYSCFG_USBPULLUP_DISABLE(); - } -} - USBHAL::~USBHAL(void) { HAL_PCD_DeInit(&hpcd_USB_FS); } void USBHAL::connect(void) { - MBED_ASSERT(hpcd_USB_FS.Instance == USB); HAL_PCD_DevConnect(&hpcd_USB_FS); } @@ -283,7 +287,11 @@ } void USBHAL::remoteWakeup(void) {} -void USBHAL::_usbisr(void) {} + +void USBHAL::_usbisr(void) { + HAL_PCD_IRQHandler(&hpcd_USB_FS); +} + void USBHAL::usbisr(void) {} void USBHAL::SetupStageCallback() {