GD32H7在USB HOST 工作模式 从IAP跳转到APP一个BUG
USB HOST 在IAP挂载U盘后,更新APP程序后
进入app程序化化卡在
/*!
\brief configure USB core to soft reset
\param[in] usb_regs: pointer to USB core registers
\param[out] none
\retval none
*/
static void usb_core_reset (usb_core_regs *usb_regs)
{
/* enable core soft reset */
usb_regs->gr->GRSTCTL |= GRSTCTL_CSRST;
/* wait for the core to be soft reset */
while (usb_regs->gr->GRSTCTL & GRSTCTL_CSRST) {
/* no operation */
}
/* wait for additional 3 PHY clocks */
usb_udelay(3U);
}
这个位置出不来
测试发现是上电初始化顺序的问题,并且进入app前需要关闭USB的时钟与中断
nvic_irq_disable((uint8_t)USBHS0_IRQn); // 失能OTG USB FS中断
nvic_irq_disable((uint8_t)USBHS0_WKUP_IRQn);
exti_interrupt_disable(EXTI_31);
rcu_periph_clock_disable(RCU_USBHS0); // 失能OTG FS时钟
rcu_periph_clock_disable(RCU_PMU);
需要做如下处理:将官方代码
#ifdef USE_ULPI_PHY
usb_gpio_config();
#endif /* USE_ULPI_PHY */
usb_rcu_config();
usb_timer_init();
/* configure GPIO pin used for switching VBUS power and charge pump I/O */
usb_vbus_config();
/* register device class */
usbh_class_register(&usb_host_msc, &usbh_msc);
#ifdef USE_USBHS0
#ifdef USE_USB_FS
usb_para_init (&msc_host_core, USBHS0, USB_SPEED_FULL);
#endif
#ifdef USE_USB_HS
usb_para_init (&msc_host_core, USBHS0, USB_SPEED_HIGH);
#endif
#endif /* USE_USBHS0 */
#ifdef USE_USBHS1
#ifdef USE_USB_FS
usb_para_init (&msc_host_core, USBHS1, USB_SPEED_FULL);
#endif
#ifdef USE_USB_HS
usb_para_init (&msc_host_core, USBHS1, USB_SPEED_HIGH);
#endif
#endif /* USE_USBHS1 */
usbh_init(&usb_host_msc, &msc_host_core, &usr_cb);
#ifdef USE_USB_HS
#ifndef USE_ULPI_PHY
#ifdef USE_USBHS0
pllusb_rcu_config(USBHS0);
#elif defined USE_USBHS1
pllusb_rcu_config(USBHS1);
#else
#endif
#endif /* !USE_ULPI_PHY */
#endif /* USE_USB_HS */
usb_intr_config();
while (1) {
usbh_core_task(&usb_host_msc);
}
代码中的 pll 时钟需要靠前初始化
#ifdef USE_USB_HS
#ifndef USE_ULPI_PHY
#ifdef USE_USBHS0
pllusb_rcu_config(USBHS0);
#elif defined USE_USBHS1
pllusb_rcu_config(USBHS1);
#else
#endif
#endif /* !USE_ULPI_PHY */
#endif /* USE_USB_HS */
改为:
#ifdef USE_ULPI_PHY
usb_gpio_config();
#endif /* USE_ULPI_PHY */
usb_rcu_config();
usb_timer_init();
/* configure GPIO pin used for switching VBUS power and charge pump I/O */
usb_vbus_config();
/* register device class */
usbh_class_register(&usb_host_msc, &usbh_msc);
#ifdef USE_USBHS0
#ifdef USE_USB_FS
usb_para_init (&msc_host_core, USBHS0, USB_SPEED_FULL);
#endif
#ifdef USE_USB_HS
usb_para_init (&msc_host_core, USBHS0, USB_SPEED_HIGH);
#endif
#endif /* USE_USBHS0 */
#ifdef USE_USBHS1
#ifdef USE_USB_FS
usb_para_init (&msc_host_core, USBHS1, USB_SPEED_FULL);
#endif
#ifdef USE_USB_HS
usb_para_init (&msc_host_core, USBHS1, USB_SPEED_HIGH);
#endif
#endif /* USE_USBHS1 */
#ifdef USE_USB_HS
#ifndef USE_ULPI_PHY
#ifdef USE_USBHS0
pllusb_rcu_config(USBHS0);
#elif defined USE_USBHS1
pllusb_rcu_config(USBHS1);
#else
#endif
#endif /* !USE_ULPI_PHY */
#endif /* USE_USB_HS */
usbh_init(&usb_host_msc, &msc_host_core, &usr_cb);
usb_intr_config();
while (1) {
usbh_core_task(&usb_host_msc);
}
即可正常跳转。
本文来自博客园,作者:求隐,转载请注明原文链接:https://www.cnblogs.com/duguqiuying/articles/17751617.html