本帖最后由 mgf006 于 2018-4-30 13:40 编辑
在调试HID时,发现一个怪问题:
当我板子用USB供电连接着电脑时,使用没问题。初始化,功能都正常。但如果不用USB端口,而只用外部电源供电时,程序在USB中断初始化的地方一直卡着出不来了。调试时运行那USB中断初始化时也同样卡死,只能重新复位。想请教一下各位,这可能是什么情况?
初始化用的几个函数如下:基本上都是官方提供的库代码
Set_USBClock();
USB_Init();
USB_Interrupts_Config();
USB中断初始化模块程序如下:
/* Configure the EXTI line 18 connected internally to the USB IP */
EXTI_ClearITPendingBit(EXTI_Line18);
EXTI_InitStructure.EXTI_Line = EXTI_Line18;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable the USB interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);//执行到这一条就卡死了
/* Enable the USB Wake-up interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
发现原因是,原来是SUB挂起之后进入了Stop状态。把Suspend函数中的进入Stop模式相关语句去掉即可
/* enter system in STOP mode, only when wakeup flag in not set */
if((_GetISTR()&ISTR_WKUP)==0)
{
//__WFI(); //注释掉这一句,不然在不连接电脑USB时,直接进入STOP,无法唤醒
/* Reset SLEEPDEEP bit of Cortex System Control Register */
#if defined (STM32F30X) || defined (STM32F37X)
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
#else
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
#endif
}
|