Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.

Dependencies:   mbed

Revision:
10:f2447c682c0f
Parent:
9:b7c6e7303df5
Child:
11:404bd8bb7fa6
--- a/camera_app/camera_app.cpp	Mon Jul 06 20:43:17 2015 +0000
+++ b/camera_app/camera_app.cpp	Mon Jul 06 23:20:14 2015 +0000
@@ -334,6 +334,7 @@
 //    memset(g_image.g_image_buffer,0xF80F,sizeof(g_image.g_image_buffer));
     memset(g_image.g_image_buffer,0x0F,sizeof(g_image.g_image_buffer));
     p_buffer = &(g_image.g_image_buffer[0]);
+    
     DMAConfig();
     
     //
@@ -344,9 +345,16 @@
 //    HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)p_buffer, FRAME_SIZE_IN_BYTES/4); 
     g_frame_end = 1;
  
-    /* Read the number of data items transferred */
+    /* Read the number of data items transferred (4 x uints = bytes)*/
 //    g_frame_size_in_bytes = (FRAME_SIZE_IN_BYTES - (hdma_dcmi.Instance->NDTR*4));
     g_frame_size_in_bytes = 4*(NUM_OF_4B_CHUNKS - hdma_dcmi.Instance->NDTR);
+    if(NUM_OF_4B_CHUNKS == hdma_dcmi.Instance->NDTR){
+    	HttpDebug("\r\nFailed to capture any data, check camera connections!\r\n");
+    	HAL_DCMI_MspDeInit(&phdcmi);
+    	while(1){
+    		wait(0.5);
+    	}
+    }	
     g_dma_txn_done = 1;
     g_total_dma_intrpts = 1;
     
@@ -398,38 +406,43 @@
     /* DMA controller clock enable */
     __DMA2_CLK_ENABLE();
   
-    hdma_dcmi.Instance                 = DMA2_Stream1;
     hdma_dcmi.Init.Channel             = DMA_CHANNEL_1;
     hdma_dcmi.Init.Direction           = DMA_PERIPH_TO_MEMORY;
     hdma_dcmi.Init.PeriphInc           = DMA_PINC_DISABLE;
     hdma_dcmi.Init.MemInc              = DMA_MINC_ENABLE;
-    hdma_dcmi.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
-    hdma_dcmi.Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
+    hdma_dcmi.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;//Cam is 1 byte wide data (8 bits) should this be word as well?????
+    hdma_dcmi.Init.MemDataAlignment    = DMA_PDATAALIGN_WORD;//Memory is defined as uint (1 word)
     hdma_dcmi.Init.Mode                = DMA_CIRCULAR;
     hdma_dcmi.Init.Priority            = DMA_PRIORITY_HIGH;
-    hdma_dcmi.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;
+    hdma_dcmi.Init.FIFOMode            = DMA_FIFOMODE_ENABLE;
     hdma_dcmi.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
     hdma_dcmi.Init.MemBurst            = DMA_MBURST_SINGLE;
     hdma_dcmi.Init.PeriphBurst         = DMA_PBURST_SINGLE;
+    hdma_dcmi.Instance                 = DMA2_Stream1;
     
     __HAL_LINKDMA(&phdcmi,DMA_Handle,hdma_dcmi);
     
      /* DMA interrupt init */
     HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 1, 0);
     HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);
+    
+    /* Peripheral DCMI init*/
+    
+    /* Peripheral clock enable */
+    __DCMI_CLK_ENABLE();    
  
-    phdcmi.Instance = DCMI;
     phdcmi.Init.SynchroMode      = DCMI_SYNCHRO_HARDWARE;
     phdcmi.Init.PCKPolarity      = DCMI_PCKPOLARITY_RISING;
     phdcmi.Init.VSPolarity       = DCMI_VSPOLARITY_LOW;
     phdcmi.Init.HSPolarity       = DCMI_HSPOLARITY_LOW;
     phdcmi.Init.CaptureRate      = DCMI_CR_ALL_FRAME;
-    phdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;
+    phdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;    
 #ifdef ENABLE_JPEG  
-    phdcmi.Init.JPEGMode = DCMI_JPEG_ENABLE;
+    phdcmi.Init.JPEGMode         = DCMI_JPEG_ENABLE;
 #else
-    phdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
+    phdcmi.Init.JPEGMode         = DCMI_JPEG_DISABLE;
 #endif
+    phdcmi.Instance              = DCMI;
     
   GPIO_InitTypeDef GPIO_InitStruct;
   if(phdcmi.Instance==DCMI)
@@ -439,13 +452,10 @@
    __GPIOB_CLK_ENABLE();
    __GPIOC_CLK_ENABLE();   
       
-   /**MCO2 GPIO Configuration 
+   /**MCO1/2 GPIO Configuration 
     PC9     ------> RCC_MCO_2
     PA8     ------> RCC_MCO_1    
     */
-       
-    /* Peripheral clock enable */
-    __DCMI_CLK_ENABLE();
   
     /**DCMI GPIO Configuration
     PA9     ------> DCMI_D0
@@ -496,8 +506,8 @@
     /*Configure GPIO pin : PA8 */
     GPIO_InitStruct.Pin = GPIO_PIN_8;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
+    GPIO_InitStruct.Pull = GPIO_PULLUP;
+    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
     GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);