各位高手:
自己做了一块基于AM3352的板子,板上有两个SPI接口,SPI0直接接到一个flash,SPI1接到SPI接口的LCD屏上。目前基于Starterware的例程,在CCS的环境下可以对SPI0接口的flash进行正常的读写,同样的代码,稍微改动后,移植到SPI1上就不行了,用示波器测试发现SPI1的CS0和SPI_CLK都始终为“0”。
我还仔细比较了一下代码运行过程中对SPI0和SPI1的寄存器设置,像MCSPI_CH0CONF, MCSPI_MODULCTRL, MCSPI_CH0STAT, MCSPI_CH0CTRL 这些寄存器都是完全一样的。很想知道AM335X的SPI0和SPI1到底有啥不同。
代码如下:
The problem is that I couldn't find CS0 and SPI_CLK toggling, I copied my code below,
/* Perform Pin-Muxing for SPI1 Instance */
retVal = McSPIPinMuxSetup(1);
/* Enable the clocks for McSPI0 module.*/
McSPI1ModuleClkConfig();
/* Perform Pin-Muxing for CS0 of SPI0 Instance */
retVal = McSPI1CSPinMuxSetup(chNum);
/* Do the necessary set up configurations for McSPI.*/
McSPISetUp();
ReadSPIDevice();
//////////////////functions///////////////////////
int McSPIPinMuxSetup(unsigned int instanceNum)
{
int status = E_INST_NOT_SUPP;
HWREG(SOC_CONTROL_REGS + CONTROL_CONF_MCASP0_ACLKX) = (CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_PUTYPESEL |
CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_RXACTIVE |
CONTROL_CONF_MUXMODE(3)); //mode3 for SPI1
HWREG(SOC_CONTROL_REGS + CONTROL_CONF_MCASP0_FSX) = (CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_PUTYPESEL |
CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_RXACTIVE |
CONTROL_CONF_MUXMODE(3)); //mode3 for SPI1
HWREG(SOC_CONTROL_REGS + CONTROL_CONF_MCASP0_AXR0) = (CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_PUTYPESEL |
CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_RXACTIVE |
CONTROL_CONF_MUXMODE(3)); //mode3 for SPI1
status = S_PASS;
return status;
}
///////////////////////////////////////////////////////////////
void McSPI1ModuleClkConfig(void)
{
HWREG(SOC_CM_PER_REGS + CM_PER_L3S_CLKSTCTRL) =
CM_PER_L3S_CLKSTCTRL_CLKTRCTRL_SW_WKUP;
while((HWREG(SOC_CM_PER_REGS + CM_PER_L3S_CLKSTCTRL) &
CM_PER_L3S_CLKSTCTRL_CLKTRCTRL) != CM_PER_L3S_CLKSTCTRL_CLKTRCTRL_SW_WKUP);
HWREG(SOC_CM_PER_REGS + CM_PER_L3_CLKSTCTRL) =
CM_PER_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP;
while((HWREG(SOC_CM_PER_REGS + CM_PER_L3_CLKSTCTRL) &
CM_PER_L3_CLKSTCTRL_CLKTRCTRL) != CM_PER_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP);
HWREG(SOC_CM_PER_REGS + CM_PER_L3_INSTR_CLKCTRL) =
CM_PER_L3_INSTR_CLKCTRL_MODULEMODE_ENABLE;
while((HWREG(SOC_CM_PER_REGS + CM_PER_L3_INSTR_CLKCTRL) &
CM_PER_L3_INSTR_CLKCTRL_MODULEMODE) !=
CM_PER_L3_INSTR_CLKCTRL_MODULEMODE_ENABLE);
HWREG(SOC_CM_PER_REGS + CM_PER_L3_CLKCTRL) =
CM_PER_L3_CLKCTRL_MODULEMODE_ENABLE;
while((HWREG(SOC_CM_PER_REGS + CM_PER_L3_CLKCTRL) &
CM_PER_L3_CLKCTRL_MODULEMODE) != CM_PER_L3_CLKCTRL_MODULEMODE_ENABLE);
HWREG(SOC_CM_PER_REGS + CM_PER_OCPWP_L3_CLKSTCTRL) =
CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP;
while((HWREG(SOC_CM_PER_REGS + CM_PER_OCPWP_L3_CLKSTCTRL) &
CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL) !=
CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP);
HWREG(SOC_CM_PER_REGS + CM_PER_L4LS_CLKSTCTRL) =
CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL_SW_WKUP;
while((HWREG(SOC_CM_PER_REGS + CM_PER_L4LS_CLKSTCTRL) &
CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL) !=
CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL_SW_WKUP);
HWREG(SOC_CM_PER_REGS + CM_PER_L4LS_CLKCTRL) =
CM_PER_L4LS_CLKCTRL_MODULEMODE_ENABLE;
while((HWREG(SOC_CM_PER_REGS + CM_PER_L4LS_CLKCTRL) &
CM_PER_L4LS_CLKCTRL_MODULEMODE) != CM_PER_L4LS_CLKCTRL_MODULEMODE_ENABLE);
HWREG(SOC_CM_PER_REGS + CM_PER_SPI1_CLKCTRL) &= ~CM_PER_SPI1_CLKCTRL_MODULEMODE;
HWREG(SOC_CM_PER_REGS + CM_PER_SPI1_CLKCTRL) |=
CM_PER_SPI1_CLKCTRL_MODULEMODE_ENABLE;
while((HWREG(SOC_CM_PER_REGS + CM_PER_SPI1_CLKCTRL) &
CM_PER_SPI1_CLKCTRL_MODULEMODE) != CM_PER_SPI1_CLKCTRL_MODULEMODE_ENABLE);
while(!(HWREG(SOC_CM_PER_REGS + CM_PER_L3S_CLKSTCTRL) &
CM_PER_L3S_CLKSTCTRL_CLKACTIVITY_L3S_GCLK));
while(!(HWREG(SOC_CM_PER_REGS + CM_PER_L3_CLKSTCTRL) &
CM_PER_L3_CLKSTCTRL_CLKACTIVITY_L3_GCLK));
while(!(HWREG(SOC_CM_PER_REGS + CM_PER_OCPWP_L3_CLKSTCTRL) &
(CM_PER_OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L3_GCLK |
CM_PER_OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L4_GCLK)));
while(!(HWREG(SOC_CM_PER_REGS + CM_PER_L4LS_CLKSTCTRL) &
(CM_PER_L4LS_CLKSTCTRL_CLKACTIVITY_L4LS_GCLK |
CM_PER_L4LS_CLKSTCTRL_CLKACTIVITY_SPI_GCLK)));
}
//////////////////////////////////////////
int McSPI1CSPinMuxSetup(unsigned int csPinNum)
{
int status = E_INVALID_CHIP_SEL;
HWREG(SOC_CONTROL_REGS + CONTROL_CONF_MCASP0_AHCLKR) = (CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_PUTYPESEL |
CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_RXACTIVE |
CONTROL_CONF_MUXMODE(3)); //mode3 for SPI1
status = S_PASS;
return status;
}
////////////////////////////////////
//To support SPI1 for LCD, replace the _SPI_0_ with _SPI_1_
static void McSPISetUp(void)
{
/* Reset the McSPI instance.*/
McSPIReset(SOC_SPI_1_REGS);
/* Enable chip select pin.*/
McSPICSEnable(SOC_SPI_1_REGS);
/* Enable master mode of operation.*/
McSPIMasterModeEnable(SOC_SPI_1_REGS);
/* Perform the necessary configuration for master mode.*/
McSPIMasterModeConfig(SOC_SPI_1_REGS, MCSPI_SINGLE_CH,
MCSPI_TX_RX_MODE, MCSPI_DATA_LINE_COMM_MODE_1,
chNum);
/* Configure the McSPI bus clock depending on clock mode. */
McSPIClkConfig(SOC_SPI_1_REGS, MCSPI_IN_CLK, MCSPI_OUT_FREQ, chNum,
MCSPI_CLK_MODE_0);
/* Configure the word length.*/
McSPIWordLengthSet(SOC_SPI_1_REGS, MCSPI_WORD_LENGTH(8), chNum);
/* Set polarity of SPIEN to low.*/
McSPICSPolarityConfig(SOC_SPI_1_REGS, MCSPI_CS_POL_LOW, chNum);
/* Enable the transmitter FIFO of McSPI peripheral.*/
McSPITxFIFOConfig(SOC_SPI_1_REGS, MCSPI_TX_FIFO_ENABLE, chNum);
/* Enable the receiver FIFO of McSPI peripheral.*/
McSPIRxFIFOConfig(SOC_SPI_1_REGS, MCSPI_RX_FIFO_ENABLE, chNum);
}
哪位高手帮忙看看。
谢谢
Chris
Chris Zhao2:
回复 Shine:
好的,我试验用一用memory view。
谢谢!
Chris Zhao2:
回复 Chris Zhao2:
Shine Zhang,
你说的太对了,我发现我的pinmux设置无效,对于SPI0,因为系统的默认设置就是SPI0,所以可以正常工作。在CCS里面设置pinmux,像下面这样做不可以吗?还是需要先对其他的寄存器进行设置?
HWREG(SOC_CONTROL_REGS + CONTROL_CONF_MCASP0_ACLKX) = (CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_PUTYPESEL |
CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_RXACTIVE |
CONTROL_CONF_MUXMODE(3)); //mode3 for SPI1
HWREG(SOC_CONTROL_REGS + CONTROL_CONF_MCASP0_FSX) = (CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_PUTYPESEL |
CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_RXACTIVE |
CONTROL_CONF_MUXMODE(3)); //mode3 for SPI1
HWREG(SOC_CONTROL_REGS + CONTROL_CONF_MCASP0_AXR0) = (CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_PUTYPESEL |
CONTROL_CONF_SPI1_SCLK_CONF_SPI1_SCLK_RXACTIVE |
CONTROL_CONF_MUXMODE(3)); //mode3 for SPI1
谢谢
Chris
Chris Zhao2:
回复 Chris Zhao2:
Shine Zhang,
我发现HWREG()命令在CCS里面没有任何效果,然后我就在GEL文件里面设置好了SPI1接口,现在至少CS0和CLK都可以看到了。
有直接在CCS里面设置pinmux的方法吗?
谢谢
Chris
Shine:
回复 Chris Zhao2:
请问有没有添加#include "hw_types.h"头文件?
或者直接用*((volatile unsigned int *)(address)))=value看能否配置。
Chris Zhao2:
回复 Shine:
有添加的,请参考我的文件列表
Chris Zhao2:
回复 Chris Zhao2:
*((volatile unsigned int *)(address)))=value 这个也不行。
我是直接在Starterware里面找相关的文件来创建的CCS工程,和这个有关吗?
Shine:
回复 Chris Zhao2:
直接在SPI0例程上改呢?
Chris Zhao2:
回复 Shine:
就是直接在SPI0的例程上面修改的。
user5275738:
回复 Chris Zhao2:
請問如何使用memory view來看是否有設置成功?