黄金会员
主题
帖子
积分8542
阅读权限40
注册时间2009-3-2
最后登录1970-1-1
在线时间 小时
|
最近使用STM32 VCP,但是不连接USB主程序不运行。查看库文件发现USB挂起时使STM32进入了睡眠状态。把挂起函数电源控制部分代码注释掉,问题解决(代码没有更深入研究,仅供参考)。
/*******************************************************************************
* Function Name : Suspend
* Description : sets suspend mode operating conditions
* Input : None.
* Output : None.
* Return : USB_SUCCESS.
*******************************************************************************/
void Suspend(void)
{
uint32_t i =0;
uint16_t wCNTR;
uint32_t tmpreg = 0;
__IO uint32_t savePWR_CR=0;
/* suspend preparation */
/* ... */
/*Store CNTR value */
wCNTR = _GetCNTR();
/* This a sequence to apply a force RESET to handle a robustness case */
/*Store endpoints registers status */
for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i);
/* unmask RESET flag */
wCNTR|=CNTR_RESETM;
_SetCNTR(wCNTR);
/*apply FRES */
wCNTR|=CNTR_FRES;
_SetCNTR(wCNTR);
/*clear FRES*/
wCNTR&=~CNTR_FRES;
_SetCNTR(wCNTR);
/*poll for RESET flag in ISTR*/
while((_GetISTR()&ISTR_RESET) == 0);
/* clear RESET flag in ISTR */
_SetISTR((uint16_t)CLR_RESET);
//restore Enpoints
for (i=0;i<8;i++)
_SetENDPOINT(i, EP[i]);
// Now it is safe to enter macrocell in suspend mode
wCNTR |= CNTR_FSUSP;
_SetCNTR(wCNTR);
/*
// force low-power mode in the macrocell
wCNTR = _GetCNTR();
wCNTR |= CNTR_LPMODE;
_SetCNTR(wCNTR);
//prepare entry in low power mode (STOP mode)
// Select the regulator state in STOP mode
savePWR_CR = PWR->CR;
tmpreg = PWR->CR;
// Clear PDDS and LPDS bits
tmpreg &= ((uint32_t)0xFFFFFFFC);
//Set LPDS bit according to PWR_Regulator value
tmpreg |= PWR_Regulator_LowPower;
//Store the new value
PWR->CR = tmpreg;
// Set SLEEPDEEP bit of Cortex System Control Register
#if defined (STM32F30X) || defined (STM32F37X)
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
#else
SCB->SCR |= SCB_SCR_SLEEPDEEP;
#endif
*/
//enter system in STOP mode, only when wakeup flag in not set
if((_GetISTR()&ISTR_WKUP)==0)
{
__WFI();
/*
// 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
*/
}
else
{
// Clear Wakeup flag
_SetISTR(CLR_WKUP);
// clear FSUSP to abort entry in suspend mode
wCNTR = _GetCNTR();
wCNTR&=~CNTR_FSUSP;
_SetCNTR(wCNTR);
/*
//restore sleep mode configuration
// restore Power regulator config in sleep mode
PWR->CR = savePWR_CR;
// 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
*/
}
}
|
|