本帖最后由 molave20a 于 2015-2-27 16:28 编辑
手上一个项目使用K21和GSM模块通过UART DMA通讯,发现UART DMA TX有重复发送现象(概率不大),即发送20byte,实际发送了40byte(前面20byte数据正常,后面是RAM中随后的20byte)。程序在STM32上跑的好好的,应该不是逻辑问题。代码如下:
配置
=============
UART1->C2 |=(UART_C2_TE_MASK|UART_C2_RE_MASK| UART_C2_TIE_MASK| UART_C2_RIE_MASK );
UART1->C5 |=(UART_C5_RDMAS_MASK|UART_C5_TDMAS_MASK);
SIM->SCGC6|=SIM_SCGC6_DMAMUX_MASK;
SIM->SCGC7 |= SIM_SCGC7_DMA_MASK;
//Enable DMA Channel0 for UART1_TX
DMAMUX->CHCFG[0] = DMAMUX_CHCFG_SOURCE(DMA_SOURCE_CHANNEL_TX);
DMA0->TCD[0].SOFF =1 ;
DMA0->TCD[0].NBYTES_MLNO =DMA_NBYTES_MLNO_NBYTES(1);
DMA0->TCD[0].SLAST =0 ;
DMA0->TCD[0].DADDR =(uint32_t)&(UART1->D);
DMA0->TCD[0].DOFF =0 ;
DMA0->TCD[0].ATTR =DMA_ATTR_SSIZE(0)+DMA_ATTR_DSIZE(0);
DMA0->TCD[0].DLAST_SGA=0;
DMA0->TCD[0].CSR = 0;
DMA0->TCD[0].CSR|=DMA_CSR_INTMAJOR_MASK;
DMA0->TCD[0].CSR|=DMA_CSR_DREQ_MASK;
DMAMUX->CHCFG[0] |=DMAMUX_CHCFG_ENBL_MASK;
NVIC_Init(DMA0_IRQn,NVIC_PriorityGroup_1,0,0);
NVIC_EnableIRQ(DMA0_IRQn);
============================
DMA发送:
void DMA_SendData(uint8_t *ptr,uint16_t len)
{
DMA0->TCD[0].SADDR = (uint32_t)ptr;
DMA0->TCD[0].CITER_ELINKNO = len;
DMA0->TCD[0].BITER_ELINKNO = len;
DMA0->ERQ |= DMA_ERQ_ERQ0_MASK;
}
|