okeybomb
okeybomb
这家伙很懒, 什么也没写!

注册于 2 年前

回答
2
文章
0
关注者
0

非常感谢两位大佬的解答, 大概有了一定的改善思路, 还是要试试看有没有优化空间, 准备先将部分代码放到 RAM 跑试试, 再拼一下

这是我自己写的, 时钟分频寄存器你可以根据规格书重新计算, 我用的不是标准 40M 晶振

void LL_QPI_Enable4bit (void)
{

LL_QPI_RegWrite (LL_QPI_REG_CTRL,  (LL_QPI_RegRead (LL_QPI_REG_CTRL) |LL_QPI_QUAD_ENABLE) ) ;  //reset qpi

while ( (LL_QPI_RegRead (LL_QPI_REG_CTRL) &0x02u) ==0) ;  //wait 

}

void LL_QspiInit (void)
{

unsigned long regVal; 
LL_GpioInitStructDef   GpioInit; 
LL_QpiState = LL_Qpi_Busy; 

LL_PeripheralClockEnable (CLK_QPI) ; 
LL_GpioAfInit (Psram_Ck_Remap, LL_GPIOB, LL_GPIO_P00) ; 
LL_GpioAfInit (Psram_Cs_Remap, LL_GPIOB, LL_GPIO_P27) ; 
LL_GpioAfInit (Psram_D0_Remap, LL_GPIOB, LL_GPIO_P02) ; 
LL_GpioAfInit (Psram_D1_Remap, LL_GPIOB, LL_GPIO_P03) ; 
LL_GpioAfInit (Psram_D2_Remap, LL_GPIOB, LL_GPIO_P04) ;     
LL_GpioAfInit (Psram_D3_Remap, LL_GPIOB, LL_GPIO_P05) ; 
regVal = LL_QPI_RegRead (LL_QPI_REG_CTRL) ; 
LL_QPI_RegWrite (LL_QPI_REG_CTRL,  (regVal|LL_QPI_RESET_ENABLE) ) ;  //reset qpi
while (1) 
{
    regVal = LL_QPI_RegRead (LL_QPI_REG_CTRL) ; 
    if (~ (regVal&0x00000001u) ) 
    {
        break; 
    }
}
regVal = LL_QPI_RegRead (LL_QPI_REG_CTRL) &0xFFFFF000u; 
LL_QPI_RegWrite (LL_QPI_REG_CTRL, regVal) ;  // reset reg value
regVal = LL_QPI_RegRead (LL_QPI_REG_CTRL) &0xFFFFFF0Fu; 
LL_QPI_RegWrite (LL_QPI_REG_CTRL,  (regVal|LL_QPI_CLK_DIV) ) ;  //set clk div
regVal = LL_QPI_RegRead (LL_QPI_REG_CTRL) &0xFFFFF8FFu; 
LL_QPI_RegWrite (LL_QPI_REG_CTRL,  (regVal|LL_QPI_tCPH) ) ;    //set cCPH time

regVal = LL_QPI_RegRead (LL_QPI_REG_CTRL) ; 
LL_QPI_RegWrite (LL_QPI_REG_CTRL,  (regVal|LL_QPI_BURST_ENABLE) ) ;    //set burst enable    

regVal = LL_QPI_RegRead (LL_QPI_REG_OVTR) &0xFFFFF000u; 
LL_QPI_RegWrite (LL_QPI_REG_OVTR,  (regVal|LL_QPI_tCEM) ) ;    //set cCEM time ,  "= 4uS

LL_QPI_Enable4bit () ; 
LL_QpiState = LL_Qpi_Ready; 

// 以下用于测试初始化代码是否正确, 无其他意义, 初始化 OK
// (unsigned long ) (LL_QPI_BUS) = 0xaaaaaaaa;
// TestData[0]= (unsigned long ) (LL_QPI_BUS) ;
// for (i=0; i "4; i++)
// {
// (unsigned long ) (LL_QPI_BUS+ (i*4) ) = 0xaaaaaaaa;
// }
// for (i=0; i "4; i++)
// {
// TestData[i] = (unsigned long ) (LL_QPI_BUS+ (i*4) ) ;
// }
}

发布
问题