时钟系统
一、时钟树(寄存器手册P109)
1)在该系统中,一共有四个时钟源(Clock Sources)(上图红色部分):
-
INTOSC2:内部10M时钟源,精度不如外部时钟源,是上电复位后的默认时钟源,由于精度原因,因此不能作为USB或者CAN的时钟源。
-
INTOSC1:是内部的备用10M时钟源,一般用于看门狗的时钟源,以及作为时钟丢失检测电路的时钟源。
-
XTAL:系统的外部时钟源,其频率要求为:(数据手册P64)
- AUXCLKIN:外部的辅助时钟源,一般用于CAN和USB的时钟源
2)有四个派生时钟(Derived Clocks)(时钟树中的蓝绿色部分):
- OSCCLK:可以直接作为系统时钟,同时也可以进入PLL倍频出更高的时钟频率,复位时作为默认的系统时钟
- PLLRAWCLK:由OSCCLK倍频而来
- AUXOSCCLK: 同上
- AUXPLLRAWCLK:同上
3)n个设备时钟(Device Clock Domains)(时钟树中的蓝色部分)
下表显示了各个模块的时钟源(寄存器手册P114)
二、系统时钟配置
在F2837xD_SysCtrl.c文件中,有相应的配置系统时钟的库函数:InitSysCtrl(void)
,在该函数中,有一个函数:InitSysPll(Uint16 clock_source, Uint16 imult, Uint16 fmult, Uint16 divsel)
。在配置主频时,修改该函数的参数即可,其计算公式为:
PLLSYSCLK = (clock_source) * (IMULT + FMULT) / (divsel)
void InitSysCtrl(void)
{
//
// Disable the watchdog
//
DisableDog();
#ifdef _FLASH
//
// Copy time critical code and Flash setup code to RAM. This includes the
// following functions: InitFlash()
//
// The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart
// symbols are created by the linker. Refer to the device .cmd file.
//
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
//
// Call Flash Initialization to setup flash waitstates. This function must
// reside in RAM.
//
InitFlash();
#endif
//
// *IMPORTANT*
//
// The Device_cal function, which copies the ADC & oscillator calibration
// values from TI reserved OTP into the appropriate trim registers, occurs
// automatically in the Boot ROM. If the boot ROM code is bypassed during
// the debug process, the following function MUST be called for the ADC and
// oscillators to function according to specification. The clocks to the
// ADC MUST be enabled before calling this function.
//
// See the device data manual and/or the ADC Reference Manual for more
// information.
//
#ifdef CPU1
EALLOW;
//
// Enable pull-ups on unbonded IOs as soon as possible to reduce power
// consumption.
//
GPIO_EnableUnbondedIOPullups();
CpuSysRegs.PCLKCR13.bit.ADC_A = 1;
CpuSysRegs.PCLKCR13.bit.ADC_B = 1;
CpuSysRegs.PCLKCR13.bit.ADC_C = 1;
CpuSysRegs.PCLKCR13.bit.ADC_D = 1;
//
// Check if device is trimmed
//
if(*((Uint16 *)0x5D1B6) == 0x0000){
//
// Device is not trimmed--apply static calibration values
//
AnalogSubsysRegs.ANAREFTRIMA.all = 31709;
AnalogSubsysRegs.ANAREFTRIMB.all = 31709;
AnalogSubsysRegs.ANAREFTRIMC.all = 31709;
AnalogSubsysRegs.ANAREFTRIMD.all = 31709;
}
CpuSysRegs.PCLKCR13.bit.ADC_A = 0;
CpuSysRegs.PCLKCR13.bit.ADC_B = 0;
CpuSysRegs.PCLKCR13.bit.ADC_C = 0;
CpuSysRegs.PCLKCR13.bit.ADC_D = 0;
EDIS;
//
// Initialize the PLL control: SYSPLLMULT and SYSCLKDIVSEL.
//
// Defined options to be passed as arguments to this function are defined
// in F2837xD_Examples.h.
//
// Note: The internal oscillator CANNOT be used as the PLL source if the
// PLLSYSCLK is configured to frequencies above 194 MHz.
//
// PLLSYSCLK = (XTAL_OSC) * (IMULT + FMULT) / (PLLSYSCLKDIV)
//
#ifdef _LAUNCHXL_F28379D
InitSysPll(XTAL_OSC,IMULT_40,FMULT_0,PLLCLK_BY_2);
#else
InitSysPll(XTAL_OSC, IMULT_20, FMULT_0, PLLCLK_BY_2);
#endif // _LAUNCHXL_F28379D
#endif // CPU1
//
// Turn on all peripherals
//
InitPeripheralClocks();
}
注意:
- 如果系统时钟要配置到194Mhz以上,就不能使用内部的时钟源,大概率是内部的时钟源的精度不够,此时必须将外部时钟作为时钟源。
- 在
InitSysCtrl()
函数中有几处宏定义需要添加。
_FLASH
:如果在系统中使用到了FLASH,就必须添加该宏定义用来初始化FLASHCPU1
/CPU2
:必须定义这两个宏定义其中的一个,由于是F28379D是双核的,因此对不同的CPU进行操作,其相关的寄存器会有不同的偏移量,如果都不定义,或者都定义,则相关头文件中的的偏移将无法计算LAUNCHXL_F28379D
:这个定义不定义都行,如果使用的是官方的launchpad,为了方便起见,需要定义该宏定义,如果是自己的板子,无需定义。