原本问题解决了,是Vbus那边没有足够的电压,导致插入usb时电平没有被拉高。
但现在一但插入U盘,stm32就抛一个硬错误 HardFault_Handler出来,连 OTG_FS_IRQHandler()中断都没有进去~
求解???
以下是代码部分:
GPIO配置部分代码
- GPIO_InitTypeDef GPIO_InitStructure;
-
- USB_GPIO_APBxClock_Fun(RCC_APB2Periph_AFIO, ENABLE);
- //DM GPIO
- USB_GPIO_APBxClock_Fun(USB_GPIO_DM_CLK, ENABLE);
- GPIO_InitStructure.GPIO_Pin = USB_GPIO_DM_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init (USB_GPIO_DM_PORT, & GPIO_InitStructure );
- //DP GPIO
- USB_GPIO_APBxClock_Fun(USB_GPIO_DP_CLK, ENABLE);
- GPIO_InitStructure.GPIO_Pin = USB_GPIO_DP_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init (USB_GPIO_DP_PORT, & GPIO_InitStructure );
-
- //配置USB时钟48MHz
- RCC_OTGFSCLKConfig(RCC_OTGFSCLKSource_PLLVCO_Div3); // 72*2/3
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_OTG_FS, ENABLE);
中断配置:
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
-
- NVIC_Init(&NVIC_InitStructure);