写STR711程序时,USB的时钟配置过程遇到以下问题,我用的是4M晶振,并直接连接到HCLK上
以下时钟培植过程中,前两个在USB枚举的过程中找不到设备,后两个时钟配置是可以成功找到设备.不知道为什么,差别也就在PCLK这块,我如果将PCLK配置为>24M就不行
/////////ERROR ERROR ERROR ERROR
void Set_USBClock(void)
{
u32 Tmp;
RCCU_Div2Config(DISABLE);
RCCU_PLL1Config ( RCCU_PLL1_Mul_24 , RCCU_Div_2 ) ;
for ( Tmp = 0x7f ; Tmp> 0; Tmp--)
RCCU_RCLKSourceConfig ( RCCU_PLL1_Output ) ;
/*Configure MCLK = RCLK*/
RCCU_MCLKConfig (RCCU_DEFAULT ); // MCLK=RCLK
RCCU_FCLKConfig (RCCU_RCLK_2); // FCLK =RCLK/2
RCCU_PCLKConfig (RCCU_RCLK_2); // PCLK =RCLK/2
// Configure the PLL2 ( * 12 , / 1 ) HCLK=4MHz
RCCU_PLL2Config (RCCU_PLL2_Mul_12,RCCU_Div_1);
PCU->PLL2CR = 0x81D0;
}
void Set_USBClock(void)
{
u32 Tmp;
RCCU_Div2Config(DISABLE);
RCCU_PLL1Config ( RCCU_PLL1_Mul_24 , RCCU_Div_2 ) ;
// RCCU_PCLKConfig (RCCU_RCLK_2); // APB2 PCLK2=RCLK/2
for ( Tmp = 0x7f ; Tmp> 0; Tmp--)
RCCU_RCLKSourceConfig ( RCCU_PLL1_Output ) ;
/*Configure MCLK = RCLK*/
RCCU_MCLKConfig (RCCU_DEFAULT );
RCCU_PCLKConfig (RCCU_RCLK_2); // APB2 PCLK2=RCLK/2
RCCU_FCLKConfig (RCCU_RCLK_2); // APB2 PCLK2=RCLK/2
// Configure the PLL2 ( * 12 , / 1 ) assuming HCLK=4MHz
RCCU_PLL2Config (RCCU_PLL2_Mul_12,RCCU_Div_1);
PCU->PLL2CR = 0x81D0;
}
/////////OK OK OK OK OK OK
void Set_USBClock(void)
{
u32 Tmp;
RCCU_Div2Config(DISABLE);
RCCU_PLL1Config ( RCCU_PLL1_Mul_12 , RCCU_Div_1 ) ;
// RCCU_PCLKConfig (RCCU_RCLK_2); // APB2 PCLK2=RCLK/8
for ( Tmp = 0x7f ; Tmp> 0; Tmp--)
RCCU_RCLKSourceConfig ( RCCU_PLL1_Output ) ;
/*Configure MCLK = RCLK*/
RCCU_MCLKConfig (RCCU_DEFAULT );
RCCU_PCLKConfig (RCCU_RCLK_4); // APB2 PCLK2=RCLK/8
RCCU_FCLKConfig (RCCU_RCLK_2); // APB2 PCLK2=RCLK/8
// Configure the PLL2 ( * 12 , / 1 ) assuming HCLK=4MHz
RCCU_PLL2Config (RCCU_PLL2_Mul_12,RCCU_Div_1);
PCU->PLL2CR = 0x81D0;
}
void Set_USBClock(void)
{
u32 Tmp;
RCCU_Div2Config(DISABLE);
RCCU_PLL1Config ( RCCU_PLL1_Mul_24 , RCCU_Div_2 ) ;
// RCCU_PCLKConfig (RCCU_RCLK_2); // APB2 PCLK2=RCLK/2
for ( Tmp = 0x7f ; Tmp> 0; Tmp--)
RCCU_RCLKSourceConfig ( RCCU_PLL1_Output ) ;
/*Configure MCLK = RCLK*/
RCCU_MCLKConfig (RCCU_DEFAULT );
RCCU_PCLKConfig (RCCU_RCLK_4); // APB2 PCLK2=RCLK/2
RCCU_FCLKConfig (RCCU_RCLK_2); // APB2 PCLK2=RCLK/2
// Configure the PLL2 ( * 12 , / 1 ) assuming HCLK=4MHz
RCCU_PLL2Config (RCCU_PLL2_Mul_12,RCCU_Div_1);
PCU->PLL2CR = 0x81D0;
}
在 71x_init.s 中设置时钟
//------------------------------------------------------------------------------
// Setup MCLK/PCLK/FCLK = 48/24/24 MHz - External Clk is 4MHz
//------------------------------------------------------------------------------
LDR R1,=0x101 //PCU->PDIVR = 0x00000101
LDR R0,=0xA0000044 //PCLK1 = 48MHz / 2 = 24MHz
STRH R1,[R0,#0x0] //PCLK2 = 48MHz / 2 = 24MHz
MOV R1,#0x60 // 4/2 *24 /1 = 48MHz
LDR R0,=0xA0000018
STR R1,[R0,#0x0]
MOV R0,#0xA0000008 //while(!(RCCU->CFR & RCCU_LOCK_Mask))
WAIT_LOCK
LDR R1,[R0,#0x0]
TST R1,#0x0002
BEQ WAIT_LOCK
LDR R1,=0x800B //RCCU->CFR = 0x0000800B//
STR R1,[R0,#0x0]
//------------------------------------------------------------------------------
// Setup USB_CLK
//------------------------------------------------------------------------------
// Configure the PLL2 ( * 12 , / 1 ) assuming HCLK=4MHz
// 48MHz for USB is Enable
//------------------------------------------------------------------------------
LDR R1,=0x000000E8 //USBEN PLL2EN *12 /1
LSL R1, R1, #1
LDR R0,=0xA000004C
STRH R1, [R0, #0x0] //PCD_PLL2CR = 0x000001D0
WAIT_LOCK2
LDR R1,[R0,#0x0]
TST R1,#0x8000
BEQ WAIT_LOCK2
正确的时钟设置流程
如下:
void Set_USBClock(void)
{
u32 Tmp;
/*Configure MCLK = RCLK*/
RCCU_MCLKConfig (RCCU_DEFAULT ); // MCLK=RCLK
RCCU_FCLKConfig (RCCU_RCLK_2); // FCLK =RCLK/2
RCCU_PCLKConfig (RCCU_RCLK_2); // PCLK =RCLK/2
RCCU_PLL1Config ( RCCU_PLL1_Mul_24 , RCCU_Div_2 ) ;
RCCU_Div2Config(DISABLE);
while(RCCU_FlagStatus(RCCU_PLL1_LOCK)==RESET);//Wait PLL1 to lock
RCCU_RCLKSourceConfig ( RCCU_PLL1_Output ) ;
// Configure the PLL2 ( * 12 , / 1 ) HCLK=4MHz
RCCU_PLL2Config (RCCU_PLL2_Mul_12,RCCU_Div_1);
while(RCCU_PLL2_Lock_FlagStatus(RCCU_PLL2_LOCK) == RESET);// Wait PLL2 to lock
RCCU_USBCLKConfig( RCCU_PLL2_Output );
}
USB时钟
楼上的,请问你的
while(RCCU_PLL2_Lock_FlagStatus(RCCU_PLL2_LOCK) == RESET);// Wait PLL2 to lock 这句中的RCCU_PLL2_Lock_FlagStatus(RCCU_PLL2_LOCK) == RESET子程序是不是读PCU_PLL2CR寄存器的最高位即0x8000,如果为1则PLL2已锁.
能不能把这个子程序贴出来?谢谢
RCCU_PLL2_Lock_FlagStatus()
这个应该在库文件里面有。
另外可以把时钟初始化代码放到一下代码之前就可以
b ?main ; Note : use B not BL, because an application will never return this way
USB时钟
我试过以下时钟配置程序
void Set_USBClock(void)
{
u32 Tmp;
/*Configure MCLK = RCLK*/
RCCU_MCLKConfig (RCCU_DEFAULT ); // MCLK=RCLK
RCCU_FCLKConfig (RCCU_RCLK_2); // FCLK =RCLK/2
RCCU_PCLKConfig (RCCU_RCLK_2); // PCLK =RCLK/2
RCCU_PLL1Config ( RCCU_PLL1_Mul_24 , RCCU_Div_2 ) ;
RCCU_Div2Config(DISABLE);
while(RCCU_FlagStatus(RCCU_PLL1_LOCK)==RESET);//Wait PLL1 to lock
RCCU_RCLKSourceConfig ( RCCU_PLL1_Output ) ;
// Configure the PLL2 ( * 12 , / 1 ) HCLK=4MHz
RCCU_PLL2Config (RCCU_PLL2_Mul_12,RCCU_Div_1);
while(RCCU_PLL2_Lock_FlagStatus(RCCU_PLL2_LOCK) == RESET);// Wait PLL2 to lock
RCCU_USBCLKConfig( RCCU_PLL2_Output );
}
出现的结果是:
第一次找到设备,之后就没成功了.
第二天重新下载程序,调试,找到设备.第二次用同样的程序下载,再调试,就不能找到设备了.后来将RCCU_FCLKConfig (RCCU_RCLK_2); // FCLK =RCLK/2
的配置改我当初自己的设置RCCU_FCLKConfig (RCCU_RCLK_4);就没问题,这种现象弄的我一点方向都没有了,从现象上看,就只在频率值上的差别.烦请ST工程师解答,谢谢.