Skip to content

Commit

Permalink
Merge pull request #2489 from hathach/fix-non-crystal-less-ci-fs
Browse files Browse the repository at this point in the history
fix crytsal-less access on unsupported kinetis mcu
  • Loading branch information
hathach authored Feb 24, 2024
2 parents 21de824 + a52b464 commit f21b792
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/portable/chipidea/ci_fs/dcd_ci_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,20 @@ void dcd_init(uint8_t rhport)
{
(void) rhport;

// save crystal-less setting (recovery clock)
// save crystal-less setting (if available)
#if defined(FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED) && FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED == 1
uint32_t clk_recover_irc_en = CI_REG->CLK_RECOVER_IRC_EN;
uint32_t clk_recover_ctrl = CI_REG->CLK_RECOVER_CTRL;;
uint32_t clk_recover_ctrl = CI_REG->CLK_RECOVER_CTRL;
#endif

CI_REG->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
while (CI_REG->USBTRC0 & USB_USBTRC0_USBRESET_MASK);

// restore crystal-less setting
// restore crystal-less setting (if available)
#if defined(FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED) && FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED == 1
CI_REG->CLK_RECOVER_IRC_EN = clk_recover_irc_en;
CI_REG->CLK_RECOVER_CTRL |= clk_recover_ctrl;
#endif

tu_memclr(&_dcd, sizeof(_dcd));
CI_REG->USBTRC0 |= TU_BIT(6); /* software must set this bit to 1 */
Expand Down
8 changes: 4 additions & 4 deletions src/portable/nxp/khci/dcd_khci.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,17 @@ void dcd_init(uint8_t rhport)
{
(void) rhport;

// save crystal-less setting (recovery clock)
#ifdef USB_CLK_RECOVER_IRC_EN_IRC_EN
// save crystal-less setting (if available)
#if defined(FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED) && FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED == 1
uint32_t clk_recover_irc_en = KHCI->CLK_RECOVER_IRC_EN;
uint32_t clk_recover_ctrl = KHCI->CLK_RECOVER_CTRL;
#endif

KHCI->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
while (KHCI->USBTRC0 & USB_USBTRC0_USBRESET_MASK);

// restore crystal-less setting
#ifdef USB_CLK_RECOVER_IRC_EN_IRC_EN
// restore crystal-less setting (if available)
#if defined(FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED) && FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED == 1
KHCI->CLK_RECOVER_IRC_EN = clk_recover_irc_en;
KHCI->CLK_RECOVER_CTRL |= clk_recover_ctrl;
#endif
Expand Down

0 comments on commit f21b792

Please sign in to comment.