|
在弄一個(gè)USB讀取U盤升級(jí)程序的IAP和APP,但是發(fā)現(xiàn)在跳轉(zhuǎn)到APP后,重新打開(kāi)USB的時(shí)候,USB工作異常(其他功能均正常)。
通過(guò)在IAP程序中關(guān)閉USB外設(shè),跳轉(zhuǎn)至APP,USB外設(shè)能正常工作。
想請(qǐng)教大家,有什么辦法可以復(fù)位USB外設(shè);蛘哂猩掇k法可以避免跳轉(zhuǎn)到APP后重新打開(kāi)USB時(shí)USB外設(shè)工作異常。
有哥們提醒,從時(shí)鐘入手,通過(guò)時(shí)鐘來(lái)操作是可行的。但是有點(diǎn)需要注意是需要再?gòu)?fù)位過(guò)程中關(guān)閉時(shí)鐘。
RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_OTG_HS, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_OTG_HS, DISABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_OTG_HS_ULPI, DISABLE);
RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_OTG_HS, DISABLE);
原子哥的是OTG_FS ,所以我改為
RCC_AHB2PeriphResetCmd(RCC_AHB2Periph_OTG_FS, ENABLE);
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, DISABLE);
//RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS_ULPI, DISABLE);
RCC_AHB2PeriphResetCmd(RCC_AHB2Periph_OTG_FS, DISABLE);
我的IAP程序是:
typedef void (*_func)(void);
__disable_irq();
/* MCU peripherals re-initial. */
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStruct.GPIO_Pin &= ~(GPIO_Pin_13 | GPIO_Pin_14); /* SWDIO/SWCLK */
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_Init(GPIOD, &GPIO_InitStruct);
GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_Init(GPIOF, &GPIO_InitStruct);
GPIO_Init(GPIOG, &GPIO_InitStruct);
GPIO_Init(GPIOH, &GPIO_InitStruct);
GPIO_Init(GPIOI, &GPIO_InitStruct);
/* reset systick */
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
/* disable all peripherals clock. */
RCC->AHB1ENR = (1<<20); /* 20: F4 CCMDAT ARAMEN. */
RCC->AHB2ENR = 0;
RCC->AHB3ENR = 0;
RCC->APB1ENR = 0;
RCC->APB2ENR = 0;
/* Switch to default cpu clock. */
RCC->CFGR = 0;
} /* MCU peripherals re-initial. */
/* Disable MPU */
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
/* disable and clean up all interrupts. */
{
int i;
for(i = 0; i < 8; i++)
{
/* disable interrupts. */
NVIC->ICER[ i] = 0xFFFFFFFF;[ i]
/* clean up interrupts flags. */
NVIC->ICPR[ i] = 0xFFFFFFFF;[ i]
}
}
// /* Set new vector table pointer */
SCB->VTOR = FLASH_APP1_ADDR;
// /* reset register values */
__set_BASEPRI(0);
__set_FAULTMASK(0);
// /* set up MSP and switch to it */
__set_MSP(*(uint32_t*)FLASH_APP1_ADDR);
__set_PSP(*(uint32_t*)FLASH_APP1_ADDR);
__set_CONTROL(0);
// /* ensure what we have done could take effect */
__ISB();
__disable_irq();
//
//
RCC_AHB2PeriphResetCmd(RCC_AHB2Periph_OTG_FS, ENABLE);
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, DISABLE);
//RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS_ULPI, DISABLE);
RCC_AHB2PeriphResetCmd(RCC_AHB2Periph_OTG_FS, DISABLE);
// /* never return */
((_func)(*(uint32_t*)(FLASH_APP1_ADDR + 4)))();
APP 程序是跳轉(zhuǎn)正常,就是無(wú)法檢測(cè)到U盤插入。請(qǐng)教各位大佬,請(qǐng)指條明路。
|
|