各位大大,小弟最近在做视频采集,STM32F4+OV2640,配置STM32的FSMC,并开启DMA模式刷屏到LCD上显示速度很快,但是同样的分辨率,当配置成JPEG模式时,DMA将图像数据传到内部RAM的数组中,再用串口将数据发送到上位机,但320*240分辨率的JPEG图像在上位机上显示速度只有0.6帧左右,感觉DMA输出到内部RAM再取出显示速度太慢,
请问各位大大有没有什么好的解决办法。
以下是我的代码:
#define IMAGE_BUFFER_SIZE 100 //以字为单位 经试验,增大这个数值速度并未提升
u32 Image_Buffer1[IMAGE_BUFFER_SIZE]={0};
u32 Image_Buffer2[IMAGE_BUFFER_SIZE]={0};
//OV2640 JPEG模式接口配置
void OV2640_JpegDcmiInit(void)
{
DCMI_InitTypeDef DCMI_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure; //NVIC
/*** Configures the DCMI to interface with the OV2640 camera module ***/
/* Enable DCMI clock */
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);
/* DCMI configuration */
DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_Continuous;//单张DCMI_CaptureMode_Continuous;
DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;
DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Rising;//
DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_Low;
DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_Low;
DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;
DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;
//初始化DCMI
DCMI_Init(&DCMI_InitStructure);
//使能JPG
DCMI_JPEGCmd(ENABLE);
/* Configures the DMA2 to transfer Data from DCMI */
/* Enable DMA2 clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
/* DMA2 Stream1 Configuration */
DMA_DeInit(DMA2_Stream1);
DMA_InitStructure.DMA_Channel = DMA_Channel_1;
DMA_InitStructure.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&Image_Buffer1;//传输到内部数组
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = IMAGE_BUFFER_SIZE; //以字为单位
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_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
/*DMA double buffer mode*///双缓冲区模式
DMA_DoubleBufferModeConfig(DMA2_Stream1,(uint32_t)&Image_Buffer2,DMA_Memory_0);//DMA_Memory_0首先被传输
DMA_DoubleBufferModeCmd(DMA2_Stream1,ENABLE);
DMA_Init(DMA2_Stream1, &DMA_InitStructure); //初始化DMA
Dma_FreeBuf_Ok = 0;//此时没有数据准备完成
// DMA_Cmd(DMA2_Stream1,ENABLE);//启动DMA2_Stream1
//中断使能
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = DCMI_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DCMI_ITConfig(DCMI_IT_FRAME,ENABLE); //中断使能
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DMA_ITConfig(DMA2_Stream1,DMA_IT_TC,ENABLE);
}
//DMA传输完成中断
void DMA2_Stream1_IRQHandler(void)
{
DMA_InitTypeDef DMA_InitStructure;
if(DMA_GetITStatus(DMA2_Stream1,DMA_IT_TCIF1) != RESET)
{
DMA_ClearITPendingBit(DMA2_Stream1,DMA_IT_TCIF1);
Dma_FreeBuf_Ok = 1;//有准备好的数据了
}
}
//主循环
while(1)
{
//uip_polling();
if(Dma_FreeBuf_Ok == 1)//DMA有空闲缓冲区了
{
usart_sendJPEGdata();
Dma_FreeBuf_Ok = 0;
}
//串口传输
void usart_sendJPEGdata(void)
{
u32 i;
if(DMA_GetCurrentMemoryTarget(DMA2_Stream1) == 1)
{
for(i=0;i<IMAGE_BUFFER_SIZE;i++)
{
USART_SendData(USART2,Image_Buffer1
);
while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET);
USART_SendData(USART2,Image_Buffer1>>8);
while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET);
USART_SendData(USART2,Image_Buffer1>>16);
while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET);
USART_SendData(USART2,Image_Buffer1>>24);
while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET);
}
}
else
{
for(i=0;i<IMAGE_BUFFER_SIZE;i++)
{
USART_SendData(USART2,Image_Buffer2);
while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET);
USART_SendData(USART2,Image_Buffer2>>8);
while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET);
USART_SendData(USART2,Image_Buffer2>>16);
while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET);
USART_SendData(USART2,Image_Buffer2>>24);
while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET);
}
}
}
//以下是图像显示效果
---------------------------------
还有,原子哥,当不用串口使用uip的时候,发出的数据也比较慢,1s大概能发4kbyte,差不多就一帧的样子,感觉跟串口输出的速度很接近。不知道这是什么原因造成的。
一周热门 更多>