本帖最后由 inurl 于 2013-2-19 11:26 编辑
john_lee 发表于 2013-2-18 21:31
如果楼主的 UART 数据协议格式,能保证下面两点,就可以使用 DMA 接收:
1、发送方所发送的每个 packet 中 ...
用DMA接收的话,要设置DMA接收长度。但是UART接收的话,packet长度是不定的。
static void DMA_RxConfiguration(uint32_t *BufferDST, uint32_t BufferSize) // 就是这个BUFFERSIZE是不定的!
{
DMA_InitTypeDef DMA_InitStructure;
DMA_ClearFlag(DMA2_FLAG_TC4 | DMA2_FLAG_TE4 | DMA2_FLAG_HT4 | DMA2_FLAG_GL4);
/* DMA2 Channel4 disable */
DMA_Cmd(DMA2_Channel4, DISABLE);
/* DMA2 Channel4 Config */
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferDST;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = BufferSize / 4;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Channel4, &DMA_InitStructure);
/* DMA2 Channel4 enable */
DMA_Cmd(DMA2_Channel4, ENABLE);
}
|