//调试目的:N32903 spi EDMA读取 winbond 25Q16 地址0开始的 8字节。
//由于官方的BSP 没有SPI DMA的demo例程。无从参考; 且官网N32903资料未公开,讨论人几乎没找着!so 请大虾看看
//另,串口 EDMA 使能位手册说置0,实际是置1,eg: outp32(REG_UART1_IER,inp32(REG_UART1_IER)|((1<<14)));//DMA_Tx_EN 0:bit14; DMA_Rx_EN 0:bit15
//以下代码截取段//
void Spi_Init(void)
{
// 新唐SPI0初始化
// SPI0_CLK PD12
// SPI0_DI PD14
// SPI0_DO PD15
// SPI0_CS1 PD13
int volatile loop = 0;
// 管脚初始化
outp32(REG_GPDFUN, inp32(REG_GPDFUN) & (~(0x3<<26)));// 初始化SPI0_CS0
outp32(REG_GPIOD_OMD, inp32(REG_GPIOD_OMD) | (1<<13));
outp32(REG_GPDFUN, inp32(REG_GPDFUN) | 0xF3000000);// 初始化SPI0_CLK SPI0_DI SPI0_DO
outp32(REG_APBCLK, inp32(REG_APBCLK) | SPIMS0_CKE);// 开启SPI时钟
outp32(REG_APBIPRST, inp32(REG_APBIPRST) | SPI0RST);
outp32(REG_APBIPRST, inp32(REG_APBIPRST) & ~SPI0RST);
for (loop=0; loop<500; loop++);
outp32(REG_SPI0_CNTRL, 0x00000044);
outp32(REG_SPI0_DIVIDER, 0x5);
}
//novton EDMA channal 1
void SPI_ReadBufEDMA(UI32 addr, UI8 *pBuf, UI16 count)
{
if(inp32(REG_PDMA_CSR1) & TRIG_EN)
return ;
outp32(REG_AHBCLK,inp32(REG_AHBCLK) | 0x0400<<1);// Enable Channel 1 Clock
outp32(REG_EDSSR,inp32(REG_EDSSR) & (~(0x07)));// 通道映射spi0 CH1_RXSEL
outp32(REG_PDMA_CSR1, inp32(REG_PDMA_CSR1) | 1<<2);//reset EDMA
outp32(REG_PDMA_CSR1, inp32(REG_PDMA_CSR1) | EDMACEN);//enable EDMA
//使能块传输完中断
outp32(REG_PDMA_IER1, 0x07);//??
outp32(REG_PDMA_CSR1, inp32(REG_PDMA_CSR1) & (~(0x01<<9)));//disenable SG
// SPI0读取
outp32(REG_PDMA_SAR1, (UI32)REG_SPI0_RX0);//原地址
outp32(REG_PDMA_DAR1, (UI32)pBuf);//目的地址
outp32(REG_PDMA_BCR1, count);//传输字节个数
outp32(REG_PDMA_CSR1, 0x00081025);//APB->Memory ,8bit宽
sys_enable_int(xIRQ_EDMA, 1, IRQ_LEVEL_1 , (void *)EDMA_Handler);
/**/
Select_Serial_Memory; //片选
spi_io(0x0B); //读命令 winbond25Q16 快读指令
//spi_io(0x03);
//地址
SPI_SendAddr(addr);
d_p("SPI0_CNTRL:0x%x\n\n",inp32(REG_SPI0_CNTRL));
outp32(REG_SPI0_EDMA, inp32(REG_SPI0_EDMA)|EDMA_RW|EDMA_GO);//read from spi ,start the EDMA process
outp32(REG_PDMA_CSR1, inp32(REG_PDMA_CSR1)|TRIG_EN|EDMACEN);//Trig_en
d_p("SPI0_CNTRL:0x%x\n\n",inp32(REG_SPI0_CNTRL));
spi_io(0x00); //快读缓冲字节 dummy
/*打印*/
d_p("PDMA_CSR1:0x%x\n",inp32(REG_PDMA_CSR1));
d_p("SPI0_EDMA:0x%x\n",inp32(REG_SPI0_EDMA));
d_p("PDMA_IER1:0x%x\n",inp32(REG_PDMA_IER1));
d_p("PDMA_SAR1:0x%x\n",inp32(REG_PDMA_SAR1));
d_p("PDMA_DAR1:0x%x\n",inp32(REG_PDMA_DAR1));
d_p("PDMA_ISR1:0x%x\n",inp32(REG_PDMA_ISR1));
d_p("PDMA_SBUF0:0x%x\n",inp32(REG_EDMA_SBUF0_C1));
d_p("PDMA_SBUF1:0x%x\n",inp32(REG_EDMA_SBUF1_C1));
d_p("PDMA_SBUF2:0x%x\n",inp32(REG_EDMA_SBUF2_C1));
d_p("PDMA_SBUF3:0x%x\n",inp32(REG_EDMA_SBUF3_C1));
d_p("SPI0_CNTRL:0x%x\n",inp32(REG_SPI0_CNTRL));
}
// main 函数
main()
{
....
Spi_Init(); // SPI0
....
//SPI TEST
//SPI_ChipErase();
SPI_SectorErase(0);
SPI_WriteBuffer(0,spi_write,sizeof(spi_write));
SPI_ReadBuffer(0,spi_read,6);
for(i=0;i<6;i++)
{
d_p("data:%d",spi_read);
}
for(i=0;i<6;i++)
{
spi_read=0;
}
SPI_ReadBufEDMA(0,spi_read,8);//??
count=1;
while(count)
{
while(in32(REG_PDMA_CSR1)&TRIG_EN);//等待传输完成
count=in32(REG_PDMA_CBCR1);
d_p("\nCBCR1:%d",count);
Util_Delay(500000);
}
for(i=0;i<8;i++)
{
d_p("\ndata:%d",spi_read);
}
SPI_ReadBuffer(0,spi_read,6);
for(i=0;i<6;i++)
{
d_p("data:%d",spi_read);
}
while(1);
}
///打印结果
data:1data:2data:3data:4data:5data:6SPI0_CNTRL:0x10044
SPI0_CNTRL:0x10044
SPI0_DMA_IRQ
PDMA_CSR1:0x881025
SPI0_EDMA:0x2
PDMA_IER1:0x7
PDMA_SAR1:0xb800c010
PDMA_DAR1:0x7ffbcc
PDMA_ISR1:0x0
PDMA_SBUF0:0xffffffff
PDMA_SBUF1:0xffffffff
PDMA_SBUF2:0x0
PDMA_SBUF3:0x0
SPI0_CNTRL:0x10044
CBCR1:0
data:255
data:255
data:255
data:255
data:255
data:255
data:255
data:255data:255data:255data:255data:255data:255data:255
//{从打印结果看出,SPI_ReadBufEDMA(0,spi_read,8);函数将Flash擦除了(奇怪!!!!),常规spi读取正常!}
|
|