1 /******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
3 * Author : MCD Application Team
4 * Date First Issued : 07/28/2003
5 * Description : This file provides all the RCCU software functions
6 ********************************************************************************
11 *******************************************************************************
12 THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
13 CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
14 AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
15 OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
16 OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
17 CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 *******************************************************************************/
21 /*******************************************************************************
22 * Function Name : RCCU_PLL1Config
23 * Description : Configures the PLL1 div & mul factors.
24 * Input : New_Mul ( RCCU_PLL1_Mul_12, RCCU_PLL1_Mul_16, RCCU_PLL1_Mul_20,
26 * : New_Div ( RCCU_Div_1, RCCU_Div_2, RCCU_Div_3, RCCU_Div_4,
27 * RCCU_Div_5, RCCU_Div_6, RCCU_Div_7)
29 *******************************************************************************/
30 void RCCU_PLL1Config ( RCCU_PLL1_Mul New_Mul, RCCU_PLL_Div New_Div )
32 u32 Tmp = ( RCCU->PLL1CR & ~RCCU_MX_Mask ) | ( New_Mul << RCCU_MX_Index );
33 RCCU->PLL1CR = ( Tmp & ~RCCU_DX_Mask ) | New_Div | 0x40;
36 /*******************************************************************************
37 * Function Name : RCCU_PLL2Config
38 * Description : Configures the PLL2 div & mul factors.
39 * Input : New_Mul ( RCCU_PLL2_Mul_12, RCCU_PLL2_Mul_16, RCCU_PLL2_Mul_20,
41 * : New_Div ( RCCU_Div_1, RCCU_Div_2, RCCU_Div_3, RCCU_Div_4,
42 * RCCU_Div_5, RCCU_Div_6, RCCU_Div_7)
44 *******************************************************************************/
45 void RCCU_PLL2Config ( RCCU_PLL2_Mul New_Mul, RCCU_PLL_Div New_Div )
47 u32 Tmp = ( PCU->PLL2CR & ~RCCU_MX_Mask ) | ( New_Mul << RCCU_MX_Index );
48 PCU->PLL2CR = ( Tmp & ~RCCU_DX_Mask ) | ( New_Div | RCCU_FREEN_Mask );
51 /*******************************************************************************
52 * Function Name : RCCU_RCLKSourceConfig
53 * Description : Selects the RCLK source clock
54 * Input : New_Clock ( RCCU_PLL1_Output, RCCU_CLOCK2_16, RCCU_CLOCK2 )
56 *******************************************************************************/
57 void RCCU_RCLKSourceConfig ( RCCU_RCLK_Clocks New_Clock )
61 case RCCU_CLOCK2 :{// Resets the CSU_Cksel bit in clk_flag
62 RCCU->CFR &= ~RCCU_CSU_CKSEL_Mask;
63 // Set the CK2_16 Bit in the CFR
64 RCCU->CFR |= RCCU_CK2_16_Mask;
66 RCCU->CCR &= ~RCCU_CKAF_SEL_Mask;
67 // switch off the PLL1
68 RCCU->PLL1CR=((RCCU->PLL1CR & ~RCCU_DX_Mask)\
69 |0x00000003) & ~RCCU_FREEN_Mask;
71 case RCCU_CLOCK2_16 :{// ReSet the CK2_16 Bit in the CFR
72 RCCU->CFR &= ~RCCU_CK2_16_Mask;
74 RCCU->CCR &= ~RCCU_CKAF_SEL_Mask;
75 // switch off the PLL1
76 RCCU->PLL1CR=((RCCU->PLL1CR & ~RCCU_DX_Mask)\
77 |0x00000003) & ~RCCU_FREEN_Mask;
79 case RCCU_PLL1_Output:{// Set the CK2_16 Bit in the CFR
80 RCCU->CFR = RCCU->CFR | RCCU_CK2_16_Mask;
81 // Waits the PLL1 to lock if DX bits are different from '111'
82 // If all DX bit are set the PLL lock flag in meaningless
83 if (( RCCU->PLL1CR & 0x0007 ) != 7)
84 while(!(RCCU->CFR & RCCU_LOCK_Mask));
86 RCCU->CCR &= ~RCCU_CKAF_SEL_Mask;
87 // Select The CSU_CKSEL
88 RCCU->CFR |= RCCU_CSU_CKSEL_Mask;
90 case RCCU_RTC_CLOCK : {RCCU->CCR |= 0x04;
95 /*******************************************************************************
96 * Function Name : RCCU_RCLKClockSource
97 * Description : Returns the current RCLK source clock
99 * Return : RCCU_PLL1_Output, RCCU_CLOCK2_16, RCCU_CLOCK2, RCCU_RTC_CLOCK
100 *******************************************************************************/
101 RCCU_RCLK_Clocks RCCU_RCLKClockSource ( void )
103 if ((RCCU->CCR & 0x04)==0x04)
104 return RCCU_RTC_CLOCK;
106 else if ((RCCU->CFR & RCCU_CK2_16_Mask)==0)
107 return RCCU_CLOCK2_16;
109 else if (RCCU->CFR & RCCU_CSU_CKSEL_Mask)
110 return RCCU_PLL1_Output;
116 /*******************************************************************************
117 * Function Name : RCCU_USBClockSource
118 * Description : Gets the RCLK source clock
120 * Return : RCCU_USB_Clocks ( RCCU_PLL2_Output, RCCU_USBCK )
121 *******************************************************************************/
122 RCCU_USB_Clocks RCCU_USBClockSource ( void )
124 if ((PCU->PLL2CR & RCCU_USBEN_Mask ) >> RCCU_USBEN_Index == 1 )
125 return RCCU_PLL2_Output;
126 else return RCCU_USBCK;
129 /*******************************************************************************
130 * Function Name : RCCU_FrequencyValue
131 * Description : Calculates & Returns any internal RCCU clock frequency
132 * passed in parametres
133 * Input : RCCU_Clocks ( RCCU_CLK2, RCCU_RCLK, RCCU_MCLK, RCCU_PCLK, RCCU_FCLK )
135 *******************************************************************************/
136 u32 RCCU_FrequencyValue ( RCCU_Clocks Internal_Clk )
140 RCCU_RCLK_Clocks CurrentRCLK;
142 Tmp = ( RCCU_Div2Status() == SET )? RCCU_Main_Osc / 2 : RCCU_Main_Osc;
144 if ( Internal_Clk == RCCU_CLK2 )
150 { CurrentRCLK = RCCU_RCLKClockSource ();
151 switch ( CurrentRCLK ){
152 case RCCU_CLOCK2_16 : Div = 16;
155 case RCCU_CLOCK2 : Div = 1;
158 case RCCU_PLL1_Output :{Mul=(RCCU->PLL1CR & RCCU_MX_Mask ) >> RCCU_MX_Index;
160 {case 0: Mul = 20; break;
161 case 1: Mul = 12; break;
162 case 2: Mul = 28; break;
163 case 3: Mul = 16; break;
165 Div = ( RCCU->PLL1CR & RCCU_DX_Mask ) + 1;
167 case RCCU_RTC_CLOCK : Mul = 1;
172 switch ( Internal_Clk ){
173 case RCCU_MCLK :{Div <<= PCU->MDIVR & RCCU_FACT_Mask;
175 case RCCU_PCLK :{Div <<=(PCU->PDIVR & RCCU_FACT2_Mask ) >> RCCU_FACT2_Index;
177 case RCCU_FCLK :{Div <<= PCU->PDIVR & 0x3;
180 return (Tmp * Mul) / Div;
183 /******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/