最近项目拟用华大的HC32F460,在开发过程,遇到一个奇怪问题,我准备用DMA来传递数据,用定时器的比较匹配事件来触发DMA,发现无法启动DMA(定时器的比较匹配功能正常,有PWM波形输出)。如果改用定时器上溢事件启动DMA,DMA可以正常启动,不知道是何原因?
测试代码如下:
void dma_rs232_init()
{
stc_dma_config_t stcDmaCfg;
stc_irq_regi_conf_t stcIrqRegiConf;
MEM_ZERO_STRUCT(stcDmaCfg);
stcDmaCfg.u16BlockSize = 1;
stcDmaCfg.u16TransferCnt = 0;
stcDmaCfg.u32SrcAddr = (uint32_t)(&rs232_data); /* 源地址 */
stcDmaCfg.u32DesAddr = (uint32_t)(&(M4_USART1->DR)); /* 串口发送寄存器地址 */
stcDmaCfg.u16SrcRptSize = 1;
stcDmaCfg.u16DesRptSize = 1;
stcDmaCfg.stcDmaChCfg.enSrcRptEn = Disable;
stcDmaCfg.stcDmaChCfg.enDesRptEn = Disable;
stcDmaCfg.stcDmaChCfg.enSrcInc = AddressFix;
stcDmaCfg.stcDmaChCfg.enDesInc = AddressFix;
stcDmaCfg.stcDmaChCfg.enTrnWidth = Dma8Bit;
stcDmaCfg.stcDmaChCfg.enLlpEn = Disable;
stcDmaCfg.stcDmaChCfg.enIntEn = Enable;
PWC_Fcg0PeriphClockCmd(PWC_FCG0_PERIPH_DMA1,Enable);
DMA_Cmd(M4_DMA1,Enable);
DMA_InitChannel(M4_DMA1, DmaCh1, &stcDmaCfg);
DMA_ChannelCmd(M4_DMA1, DmaCh1,Enable);
DMA_ClearIrqFlag(M4_DMA1, DmaCh1,TrnCpltIrq);
/* 配置DMA中断 */
MEM_ZERO_STRUCT(stcIrqRegiConf);
stcIrqRegiConf.enIntSrc = INT_DMA1_BTC1;
stcIrqRegiConf.enIRQn = DMA_IRQn2;
stcIrqRegiConf.pfnCallback = &dma1_ch1_tran_irq_callback;
enIrqRegistration(&stcIrqRegiConf);
NVIC_ClearPendingIRQ(stcIrqRegiConf.enIRQn);
NVIC_SetPriority(stcIrqRegiConf.enIRQn, DMA_IRQn2_PRI);
NVIC_EnableIRQ(stcIrqRegiConf.enIRQn);
PWC_Fcg0PeriphClockCmd(PWC_FCG0_PERIPH_AOS,Enable);
DMA_SetTriggerSrc(M4_DMA1, DmaCh1, EVT_TMRA2_CMP); /* TIMRA_2的比较匹配 */
}
以上代码,无法启动DMA,串口无法发送数据
如果改为DMA_SetTriggerSrc(M4_DMA1, DmaCh1, EVT_TMRA2_OVF); /* TIMRA_2的上溢 */,可以正常工作。
其中:TIMA2 配置为通道1的PWM输出
|