Продолжаю пляски с бубном
Прикрутил камеру. НА текущий момент читатся и пишутся регистры, камера, судя по осциллограммам работает.
О том, что нормально работает камера и са DCMI свидетельствует то, что помещенный в окно отладчика Watch регистр DCMI->DR мпостоянно изеняется, приченм, если камеру закрыть, там нули, а если посветить - то чем ярче, тем больше выпозают числа.
А вот с DMA какие-то проблемы - выделенный по дкадр буфер все время пуст. ДЛя проверки даже предварително заполнял его заданным значениями - они отображаются, но не меняются.
Вот инициализация:
CODE
static void Camera_HW_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DCMI_InitTypeDef DCMI_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
__IO uint32_t Timeout = TIMEOUT_MAX;
RCC_AHB1PeriphClockCmd(SCCB_Clock, ENABLE);
// Configure SIO_C and SIO_D as OUT (for SCCB/I2C)
GPIO_InitStructure.GPIO_Pin = SIO_C_Pin | SIO_D_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // PullUp is include on module
GPIO_Init(SCCB_Port, &GPIO_InitStructure);
// Configure MCO0(PA8) as clock out for Camera Module (XCLK pin)
OV7670_XCLK_Conf();
// Configures the DCMI GPIOs to interface with the OV7670 camera module
// Enable DCMI GPIOs clocks
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB |
RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOE,
ENABLE);
// Connect DCMI pins to AF13
// PORTA
GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_DCMI); // HSYNC
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_DCMI); // PCLK
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_DCMI); // D0
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_DCMI); // D1
// PORTB
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_DCMI); // D5
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_DCMI); // VSYNC
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_DCMI); // D6
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_DCMI); // D7 -
// PORTC
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_DCMI); // D4
// PORTE
GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_DCMI); // D2
GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_DCMI); // D3
// DCMI GPIO configuration
// D0..D1(PA9/10), HSYNC(PA4), PCLK(PA6)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6 | GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// D5..D7(PB6/8/9), VSYNC(PB7)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// D4(PC11)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// D2..D3(PE0/1)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//---------------------------------------------------------------------------------------
// GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_DCMI); //d0
// GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_DCMI); //d1
// GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_DCMI); //d2
//---------------------------------------------------------------------------------------
// Configures the DCMI to interface with the OV7670 camera module
// Enable DCMI clock
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);
// Reinitialize
DCMI_DeInit();
// DCMI configuration
DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_Continuous;
DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;
DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Rising;
DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_High;
DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_Low;
DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;
DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;
DCMI_Init(&DCMI_InitStructure);
// Configures the DMA2 to transfer Data from DCMI
// Enable DMA2 clock
RCC_AHB1PeriphClockCmd(DMA_Camera_STREAM_CLOCK, ENABLE);
// DMA2 Stream1 Configuration
DMA_DeInit(DMA_CameraToRAM_Stream);
// Check if the DMA Stream is disabled before enabling it.
// Note that this step is useful when the same Stream is used multiple times:
// enabled, then disabled then re-enabled... In this case, the DMA Stream disable
// will be effective only at the end of the ongoing data transfer and it will
// not be possible to re-configure it before making sure that the Enable bit
// has been cleared by hardware. If the Stream is used only once, this step might
// be bypassed.
while (DMA_GetCmdStatus(DMA_CameraToRAM_Stream) != DISABLE)
{
}
DMA_InitStructure.DMA_Channel = DMA_Camera_Channel;
DMA_InitStructure.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&RAM_Buffer;
//DMA_InitStructure.DMA_Memory0BaseAddr = 0x60020000;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = BuffSize;
// DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
// DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = 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_Init(DMA_CameraToRAM_Stream, &DMA_InitStructure);
// Enable DMA Stream Transfer Complete interrupt
DMA_ITConfig(DMA_CameraToRAM_Stream, DMA_IT_TC , ENABLE);
// Check if the DMA Stream has been effectively enabled.
// The DMA Stream Enable bit is cleared immediately by hardware if there is an
// error in the configuration parameters and the transfer is no started (ie. when
// wrong FIFO threshold is configured ...)
Timeout = TIMEOUT_MAX;
while ((DMA_GetCmdStatus(DMA_CameraToRAM_Stream) != ENABLE) && (Timeout-- > 0))
{
}
// Check if a timeout condition occurred
if (Timeout == 0)
{
// Manage the error: to simplify the code enter an infinite loop
while (1)
{
// Dopísa program
}
}
// // Enable the DMA Stream IRQ Channel
NVIC_InitStructure.NVIC_IRQChannel = DMA_Camera_STREAM_IRQ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
Буфер объявлен так
Код
__IO uint16_t RAM_Buffer[BuffSize];
Ну и вот что у меня в прерываниях
Код
void DMA_Camera_STREAM_IRQHANDLER(void)
{
uint16_t i;
// Test on DMA Stream Transfer Complete interrupt
if(DMA_GetITStatus(DMA_CameraToRAM_Stream, DMA_Camera_IT_TCIF))
{
// LCD_REG = 0x0022;
//for(i = 0; i < BuffSize; i++)
// LCD_RAM = RAM_Buffer[i];
// Clear DMA Stream Transfer Complete interrupt pending bit
DMA_ClearITPendingBit(DMA_CameraToRAM_Stream, DMA_Camera_IT_TCIF);
}
}
void DCMI_IRQHandler(void)
{
uint16_t i;
if(DCMI_GetITStatus(DCMI_IT_FRAME))
{
// LCD_REG = 0x0022;
//for(i = 0; i < BuffSize; i++)
// LCD_RAM = RAM_Buffer[i];
//for(i = 0; i < 28800; i++)
// LCD_RAM = 0x0000;
DCMI_ClearITPendingBit(DCMI_IT_FRAME);
}
}
Оба прерывания вызываются, все ОК,
Но буфер пуст...
У меня вопрос - а нужен ли мне собственно DMA?
МОжно ли как-то без него заполнять буфер длиной 640 байт а по прерыванию новой строки отправлять этот буфер по USB?
ДОБАВЛЮ:
Если это
Код
// DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
заменить на это
Код
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
// DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
ну то есть включить DMA_MemoryInc, то в буфере оказываются данные, но в дальнейшем не изменяются.
И прерывание DMA_Stream не вызывается...