#include "bsp.h" #include #include #include "ov5640.h" #include "prepherials.h" uint32_t picture[PICTURE_BUFFER_SIZE]; int main() { system_init(); // init_old for stm32 chip camera_init(); // dma_s * dcmi_dma = dma1_p; while (1) { camera_wakeup(); dma10.dma_start((uint32_t) DCMI->DR, (uint32_t) picture, 4 * PICTURE_BUFFER_SIZE); // first few frames may cause green screen, if so we can extend the Delay to skip them. delay_ms(100, true); // wait for camera to be ready -- skip first frame 12.5fps = 80ms dcmi.enable(); dcmi.capture_enable(); // todo: use dcmi interrupt to stop dma instead of Delay delay_s(1, true); // wait for picture to be captured then stop dma // IF_ERROR_STUCK(dma_stop(dcmi_dma)); if (dma10.dma_stop() != HAL_OK) { // image more than 4*PICTURE_BUFFER_SIZE byte. 180 x 4 = 720 kBgit . dma10.dma_reset(); } dcmi.disable(); camera_sleep(); uint8_t *tmp3 = (uint8_t *) picture; uint32_t i; for (i = 1; i < 4 * PICTURE_BUFFER_SIZE - 1; i++) { if (tmp3[i] == 0xff && tmp3[i + 1] == 0xd9) { printf("%lu\n", i); break; } } if (i == 4 * PICTURE_BUFFER_SIZE - 1) i = 0; // IF_ERROR_STUCK(uart_send_massive(usart1_p, (uint8_t *) picture, i + 5)); memset(picture, 0, sizeof(picture)); delay_s(1, true); } }