/* Enable DMA channel */
DMA_ChannelCmd(SPI_DMA_UNIT, SPI_DMA_TX_CHANNEL, Enable);
/* Enable SPI to start DMA */
SPI_Cmd(SPI_UNIT, Enable);
while (Reset == DMA_GetIrqFlag(SPI_DMA_UNIT, SPI_DMA_TX_CHANNEL, TrnCpltIrq))
{
}
DMA_ClearIrqFlag(SPI_DMA_UNIT, SPI_DMA_TX_CHANNEL, TrnCpltIrq);
/* Disable SPI */
SPI_Cmd(SPI_UNIT, Disable);
执行了一次之后卡死在 while (Reset == DMA_GetIrqFlag(SPI_DMA_UNIT, SPI_DMA_TX_CHANNEL, TrnCpltIrq))
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
配置方法是
#define SPI_UNIT (M4_SPI1)
#define SPI_UNIT_CLOCK (PWC_FCG1_PERIPH_SPI1)
#define SPI_MOSI_PORT (PortC)
#define SPI_MOSI_PIN (Pin10)
#define SPI_MOSI_FUNC (Func_Spi1_Mosi)
#define SPI_DMA_UNIT (M4_DMA1)
#define SPI_DMA_CLOCK_UNIT (PWC_FCG0_PERIPH_DMA1)
#define SPI_DMA_TX_CHANNEL (DmaCh0)
#define SPI_DMA_TX_TRIG_SOURCE (EVT_SPI1_SPTI)
static void Spi_DmaConfig(void)
{
stc_dma_config_t stcDmaCfg;
stc_irq_regi_conf_t stcIrqRegiCfg;
/* configuration structure initialization */
MEM_ZERO_STRUCT(stcDmaCfg);
/* Configuration peripheral clock */
PWC_Fcg0PeriphClockCmd(SPI_DMA_CLOCK_UNIT, Enable);
PWC_Fcg0PeriphClockCmd(PWC_FCG0_PERIPH_AOS, Enable);
/* Configure TX DMA */
stcDmaCfg.u16BlockSize = 1u;
stcDmaCfg.u16TransferCnt = PIXEL_NUM * 24;
stcDmaCfg.u32SrcAddr = (uint32_t)(pixelBuffer);
stcDmaCfg.u32DesAddr = (uint32_t)(&SPI_UNIT->DR);
stcDmaCfg.stcDmaChCfg.enSrcInc = AddressIncrease;
stcDmaCfg.stcDmaChCfg.enDesInc = AddressFix;
stcDmaCfg.stcDmaChCfg.enTrnWidth = Dma8Bit;
stcDmaCfg.stcDmaChCfg.enIntEn = Disable;
DMA_InitChannel(SPI_DMA_UNIT, SPI_DMA_TX_CHANNEL, &stcDmaCfg);
DMA_SetTriggerSrc(SPI_DMA_UNIT, SPI_DMA_TX_CHANNEL, SPI_DMA_TX_TRIG_SOURCE);
/* Enable DMA. */
DMA_Cmd(SPI_DMA_UNIT, Enable);
}
void WS2812C_Init(void)
{
stc_spi_init_t stcSpiInit;
/* configuration structure initialization */
MEM_ZERO_STRUCT(stcSpiInit);
/* Configuration peripheral clock */
PWC_Fcg1PeriphClockCmd(SPI_UNIT_CLOCK, Enable);
/* Configuration SPI pin */
PORT_SetFunc(SPI_MOSI_PORT, SPI_MOSI_PIN, SPI_MOSI_FUNC, Disable);
/* Configuration SPI structure */
stcSpiInit.enClkDiv = SpiClkDiv32;
stcSpiInit.enFrameNumber = SpiFrameNumber1;
stcSpiInit.enDataLength = SpiDataLengthBit8;
stcSpiInit.enFirstBitPosition = SpiFirstBitPositionMSB;
stcSpiInit.enSckPolarity = SpiSckIdleLevelLow;
stcSpiInit.enSckPhase = SpiSckOddChangeEvenSample;
stcSpiInit.enReadBufferObject = SpiReadReceiverBuffer;
stcSpiInit.enWorkMode = SpiWorkMode3Line;
stcSpiInit.enTransMode = SpiTransFullDuplex;
stcSpiInit.enCommAutoSuspendEn = Disable;
stcSpiInit.enModeFaultErrorDetectEn = Disable;
stcSpiInit.enParitySelfDetectEn = Disable;
stcSpiInit.enParityEn = Disable;
stcSpiInit.enParity = SpiParityEven;
stcSpiInit.enMasterSlaveMode = SpiModeMaster;
stcSpiInit.stcDelayConfig.enSsSetupDelayOption = SpiSsSetupDelayCustomValue;
stcSpiInit.stcDelayConfig.enSsSetupDelayTime = SpiSsSetupDelaySck1;
stcSpiInit.stcDelayConfig.enSsHoldDelayOption = SpiSsHoldDelayCustomValue;
stcSpiInit.stcDelayConfig.enSsHoldDelayTime = SpiSsHoldDelaySck1;
stcSpiInit.stcDelayConfig.enSsIntervalTimeOption = SpiSsIntervalCustomValue;
stcSpiInit.stcDelayConfig.enSsIntervalTime = SpiSsIntervalSck6PlusPck2;
SPI_Init(SPI_UNIT, &stcSpiInit);
Spi_DmaConfig();
}
|