/** * \brief Enable full speed USB clock. * * \note The SAM3X UDP hardware interprets div as div+1. For readability the hardware div+1 * is hidden in this implementation. Use div as div effective value. * * \param pll_id Source of the USB clock. * \param div Actual clock divisor. Must be superior to 0. */ void sysclk_enable_usb(void) { Assert(CONFIG_USBCLK_DIV > 0); switch (CONFIG_USBCLK_SOURCE) { #ifdef CONFIG_PLL0_SOURCE case USBCLK_SRC_PLL0: { struct pll_config pllcfg; pll_enable_source(CONFIG_PLL0_SOURCE); pll_config_defaults(&pllcfg, 0); pll_enable(&pllcfg, 0); pll_wait_for_lock(0); pmc_switch_udpck_to_pllack(CONFIG_USBCLK_DIV - 1); pmc_enable_udpck(); break; } #endif case USBCLK_SRC_UPLL: { pmc_enable_upll_clock(); pmc_switch_udpck_to_upllck(CONFIG_USBCLK_DIV - 1); pmc_enable_udpck(); break; } } }
/** * \brief Enable full speed USB clock. * * \note The SAM3X PMC hardware interprets div as div+1. For readability the hardware div+1 * is hidden in this implementation. Use div as div effective value. * * \param pll_id Source of the USB clock. * \param div Actual clock divisor. Must be superior to 0. */ void sysclk_enable_usb(void) { Assert(CONFIG_USBCLK_DIV > 0); #ifdef CONFIG_PLL0_SOURCE if (CONFIG_USBCLK_SOURCE == USBCLK_SRC_PLL0) { struct pll_config pllcfg; pll_enable_source(CONFIG_PLL0_SOURCE); pll_config_defaults(&pllcfg, 0); pll_enable(&pllcfg, 0); pll_wait_for_lock(0); pmc_switch_udpck_to_pllack(CONFIG_USBCLK_DIV - 1); pmc_enable_udpck(); return; } #endif if (CONFIG_USBCLK_SOURCE == USBCLK_SRC_UPLL) { pmc_enable_upll_clock(); pmc_switch_udpck_to_upllck(CONFIG_USBCLK_DIV - 1); pmc_enable_udpck(); return; } }
uint32_t UDD_Init(void) { uint32_t i; for (i = 0; i < MAX_ENDPOINTS; ++i) { ul_send_fifo_ptr[i] = 0; ul_recv_fifo_ptr[i] = 0; } // Enables the USB Clock pmc_enable_periph_clk(ID_UOTGHS); pmc_enable_upll_clock(); pmc_switch_udpck_to_upllck(0); // div=0+1 pmc_enable_udpck(); // Configure interrupts NVIC_SetPriority((IRQn_Type) ID_UOTGHS, 0UL); NVIC_EnableIRQ((IRQn_Type) ID_UOTGHS); // Always authorize asynchrone USB interrupts to exit from sleep mode // for SAM3 USB wake up device except BACKUP mode //pmc_set_fast_startup_input(PMC_FSMR_USBAL); // ID pin not used then force device mode otg_disable_id_pin(); otg_force_device_mode(); // Enable USB hardware otg_disable_pad(); otg_enable_pad(); otg_enable(); otg_unfreeze_clock(); // Check USB clock //while (!Is_otg_clock_usable()) // ; // Enable High Speed udd_low_speed_disable(); udd_high_speed_enable(); //otg_ack_vbus_transition(); // Force Vbus interrupt in case of Vbus always with a high level // This is possible with a short timing between a Host mode stop/start. /*if (Is_otg_vbus_high()) { otg_raise_vbus_transition(); } otg_enable_vbus_interrupt();*/ otg_freeze_clock(); return 0UL ; }