stm32f407 + SDIO Fat Fs multiBlock write error with ov7670
i am using stm32f407 with fatfs to store vedio frames in sd card. i am capturing QQVGA YUV frames from camera to write it to sd card, i tested to write continuously in sd card with using soft flag in frame intterupt and writing data in main file using f_write function when i write continuosly it outputs 0kb data so i have to open and close file, i use user button to unmount file system, but when i do this i get true data only for some lines and random data in between frames, following is my code and intterupt routines, i stop the dcmi and dma till bytes of data are transferred then i start them again to make sure that complete frame is captured into sd card, i tried to write some fixed data in sd card with intterupts enabled but still i got random data, i am using class 10 scandisk micro sd card and i am using library with modified write functions provided by clive,
int number=0;int count=0;int stop = 0;&sharpdefine size 9600uint32_t buffer[size]; int main(void){ NVIC_Configuration(); EXTILine0_Config(); init_GPIO(); MCO1_Init(); Delay_ms(10); DCMI_OV7670_Init(); f_mount(0, &filesystem); f_open(&file, ''DATA.YUV'', FA_READ | FA_WRITE | FA_CREATE_ALWAYS); GPIOD->BSRRL = 0x1000; // this sets LED1 (green) 0x2000 0x4000 0x8000 f_close(&file); DMA_Cmd(DMA2_Stream1, ENABLE); DCMI_Cmd(ENABLE); DCMI_CaptureCmd(ENABLE); f_open(&file, ''DATA.YUV'', FA_WRITE | FA_OPEN_ALWAYS); while(1){ if((number == count) && (!stop)) { number++; DMA_Cmd(DMA2_Stream1, DISABLE); DCMI_Cmd(DISABLE); DCMI_CaptureCmd(DISABLE); f_lseek(&file, file.fsize); f_write(&file, &buffer[0] , size*4, &bw); if (bw<(size*4)) while(1); DMA_Cmd(DMA2_Stream1, ENABLE); DCMI_Cmd(ENABLE); DCMI_CaptureCmd(ENABLE); } }}and interrupt routine isvoid EXTI0_IRQHandler(void){ if(EXTI_GetITStatus(EXTI_Line0) != RESET) { DMA_Cmd(DMA2_Stream1, DISABLE); DCMI_Cmd(DISABLE); DCMI_CaptureCmd(DISABLE); f_close(&file); if (f_mount(0, NULL) != FR_OK) { printf(''could not close filesystem \n\r''); } GPIOD->BSRRH = 0x1000; GPIOD->BSRRL = 0x2000; stop = 1; /* Clear the EXTI line 0 pending bit */ EXTI_ClearITPendingBit(EXTI_Line0); }}void DCMI_IRQHandler(void){ if (DCMI_GetITStatus(DCMI_IT_FRAME) != RESET) { count++; DCMI_ClearITPendingBit(DCMI_IT_FRAME); }}and following is my dma setting DMA_InitStructure.DMA_Channel = DMA_Channel_1; DMA_InitStructure.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)&buffer[0];//&buffer[0]; //FSMC_LCD_ADDRESS; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; // row * columns * bytes per pixal devided by 4 DMA_InitStructure.DMA_BufferSize = size; // 160 * 120 / 4*4; unit depends on unit used in memory data size DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //DMA_MemoryInc_Disable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; //DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //for video DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;//DMA_FIFOMode_Enable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; any help will be greatly appreciated #stm32f4-sdio-fatfs-ov7670