|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2024-5-15 21:17:52
|
显示全部楼层
dma设置的代码和lcd_color_fill代码如下:
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
DMA_DeInit(DMA2_Stream0);
DMA_InitStructure.DMA_Channel = DMA_Channel_1;
// DMA_InitStructure.DMA_PeripheralBaseAddr = 0;//(uint32_t)(0x6C000000); // LCD RAM address
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) & (LCD->LCD_RAM); // LCD RAM address
DMA_InitStructure.DMA_Memory0BaseAddr = 0;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_BufferSize = 0; // Will be configured later
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream1, DISABLE);
// Enable transfer complete interrupt
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);
// Configure and enable DMA interrupt
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void DMA_StartTransfer(uint32_t *src, uint32_t *dst, uint32_t length)
{
// Disable the DMA stream before configuring it
DMA_Cmd(DMA2_Stream0, DISABLE);
// Wait until the DMA stream is disabled
while (DMA_GetCmdStatus(DMA2_Stream0) != DISABLE) {}
// Configure the source and destination addresses and the number of data items
DMA2_Stream0->M0AR = (uint32_t)src;
DMA2_Stream0->PAR = (uint32_t)dst;
DMA2_Stream0->NDTR = length;
// 清除所有 DMA 中断标志
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
// 启用传输完成中断
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);
// Enable the DMA stream
DMA_Cmd(DMA2_Stream0, ENABLE);
}
// DMA interrupt handler
void DMA2_Stream0_IRQHandler(void)
{
if (DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0)) {
// Clear DMA interrupt flag
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
}
} |
|