Browse Source

Use USB clock recovery when running USB from IRC48M oscillator

teensy4-core
PaulStoffregen 8 years ago
parent
commit
27fa2e2a52
2 changed files with 17 additions and 1 deletions
  1. +11
    -0
      teensy3/kinetis.h
  2. +6
    -1
      teensy3/usb_dev.c

+ 11
- 0
teensy3/kinetis.h View File

#define USB_USBTRC_SYNC_DET ((uint8_t)0x02) // #define USB_USBTRC_SYNC_DET ((uint8_t)0x02) //
#define USB_USBTRC_USB_RESUME_INT ((uint8_t)0x01) // #define USB_USBTRC_USB_RESUME_INT ((uint8_t)0x01) //
#define USB0_USBFRMADJUST (*(volatile uint8_t *)0x40072114) // Frame Adjust Register #define USB0_USBFRMADJUST (*(volatile uint8_t *)0x40072114) // Frame Adjust Register
#define USB0_CLK_RECOVER_CTRL (*(volatile uint8_t *)0x40072140) // USB Clock recovery control
#define USB_CLK_RECOVER_CTRL_CLOCK_RECOVER_EN ((uint8_t)0x80)
#define USB_CLK_RECOVER_CTRL_RESET_RESUME_ROUGH_EN ((uint8_t)0x40)
#define USB_CLK_RECOVER_CTRL_RESTART_IFRTRIM_EN ((uint8_t)0x20)
#define USB0_CLK_RECOVER_IRC_EN (*(volatile uint8_t *)0x40072144) // IRC48M oscillator enable
#define USB_CLK_RECOVER_IRC_EN_IRC_EN ((uint8_t)0x02)
#define USB_CLK_RECOVER_IRC_EN_REG_EN ((uint8_t)0x01)
#define USB0_CLK_RECOVER_INT_EN (*(volatile uint8_t *)0x40072154) // Clock recovery combined interrupt enable
#define USB_CLK_RECOVER_INT_EN_OVF_ERROR_EN ((uint8_t)0x10)
#define USB0_CLK_RECOVER_INT_STATUS (*(volatile uint8_t *)0x4007215C) // Clock recovery separated interrupt status
#define USB_CLK_RECOVER_INT_STATUS_OVF_ERROR ((uint8_t)0x10)




// USB Device Charger Detection Module (USBDCD) // USB Device Charger Detection Module (USBDCD)

+ 6
- 1
teensy3/usb_dev.c View File

#ifdef HAS_KINETIS_MPU #ifdef HAS_KINETIS_MPU
MPU_RGDAAC0 |= 0x03000000; MPU_RGDAAC0 |= 0x03000000;
#endif #endif

#if F_CPU == 180000000 || F_CPU == 216000000
// if using IRC48M, turn on the USB clock recovery hardware
USB0_CLK_RECOVER_IRC_EN = USB_CLK_RECOVER_IRC_EN_IRC_EN | USB_CLK_RECOVER_IRC_EN_REG_EN;
USB0_CLK_RECOVER_CTRL = USB_CLK_RECOVER_CTRL_CLOCK_RECOVER_EN |
USB_CLK_RECOVER_CTRL_RESTART_IFRTRIM_EN;
#endif
// reset USB module // reset USB module
//USB0_USBTRC0 = USB_USBTRC_USBRESET; //USB0_USBTRC0 = USB_USBTRC_USBRESET;
//while ((USB0_USBTRC0 & USB_USBTRC_USBRESET) != 0) ; // wait for reset to end //while ((USB0_USBTRC0 & USB_USBTRC_USBRESET) != 0) ; // wait for reset to end

Loading…
Cancel
Save