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

Files at this revision

API Documentation at this revision

Comitter:
dflet
Date:
Tue Jun 30 22:51:05 2015 +0000
Parent:
3:7643714ec664
Child:
5:75fcfdb7cae7
Commit message:
WIP commit 5

Changed in this revision

camera_app/camera_app.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/mt9d111/mt9d111.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/stm32f4xx_msp.c Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
utils/app_config.h Show annotated file Show diff for this revision Revisions of this file
--- a/camera_app/camera_app.cpp	Fri Jun 26 22:53:54 2015 +0000
+++ b/camera_app/camera_app.cpp	Tue Jun 30 22:51:05 2015 +0000
@@ -41,7 +41,7 @@
 //! @{
 //
 //*****************************************************************************
-#include "mbed.h"
+//#include "mbed.h"
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -49,10 +49,13 @@
 // SimpleLink include
 #include "cc3100_simplelink.h"
 
+//#include "stm32f4xx_hal_dma.h"
+//#include "stm32f4xx_hal_dcmi.h"
+
 #include "camera_app.h"
-
 #include "mt9d111.h"
 #include "i2cconfig.h"
+
 #include "cli_uart.h"
 #include "Led_config.h"
 
@@ -99,7 +102,7 @@
 #ifdef ENABLE_JPEG
 	char g_header[SMTP_BUF_LEN] /*= {'\0'}*/;
 #endif
-	unsigned int g_image_buffer[NUM_OF_4B_CHUNKS];
+	unsigned int g_image_buffer[NUM_OF_4B_CHUNKS];//12800
 };
 
 ImageBuffer g_image;
@@ -360,8 +363,15 @@
     //
     Uart_Write((uint8_t*)"CaptureImage Start\n\r");
     
+    /* Enable the DCMI */
+//    __HAL_DCMI_ENABLE(&hdcmi);
+    /* Enable the DMA */
+//    __HAL_DMA_ENABLE(&hdma_dcmi);
+    
     HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);
     HAL_NVIC_EnableIRQ(DCMI_IRQn);
+    wait(1);
+    printf("\r\nBuffer size = %d\r\n",sizeof(g_image.g_image_buffer));
     HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)p_buffer, sizeof(g_image.g_image_buffer)); 
     
     /* Wait for frame */
@@ -370,17 +380,23 @@
     }
     HAL_NVIC_DisableIRQ(DCMI_IRQn);
     HAL_NVIC_DisableIRQ(DMA2_Stream1_IRQn);
+    
+    /* Disable the DMA */
+//    __HAL_DMA_DISABLE(&hdma_dcmi);
+    /* Disable the DCMI */
+//    __HAL_DCMI_DISABLE(&hdcmi);
+    
     g_frame_end = 1;
     
     Uart_Write((uint8_t*)"\n\rCaptureImage Complete\n\r");
     /* The frame is finished, but DMA still waiting
        for data because we set max frame size
        so we need to abort the DMA transfer here */
-    HAL_DMA_Abort(&hdma_dcmi);//need this???
+//    HAL_DMA_Abort(&hdma_dcmi);//need this???
  
     /* Read the number of data items transferred */
     uint16_t image_size = (FRAME_SIZE_IN_BYTES - hdma_dcmi.Instance->NDTR)*4;      
-
+    printf("image_size = %d\r\n",image_size);
     //
     // Create JPEG Header
     //
@@ -501,32 +517,6 @@
 //    MAP_CameraIntEnable(CAMERA_BASE, CAM_INT_FE);
 //    MAP_CameraDMAEnable(CAMERA_BASE);
 
-//  hdcmi.Instance = DCMI;
-//  hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE;
-//  hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;
-//  hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;
-//  hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;
-//  hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME;
-//  hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;
-//#ifdef ENABLE_JPEG  
-//  hdcmi.Init.JPEGMode = DCMI_JPEG_ENABLE;
-//#else
-//  hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
-//#endif    
-//  HAL_DCMI_Init(&hdcmi);
-
-/*
-  hdcmi.Instance = DCMI;
-  hdcmi.Init.SynchroMode = DCMI_SYNCHRO_EMBEDDED;
-  hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;
-  hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;
-  hdcmi.Init.SyncroCode.FrameEndCode = 0;
-  hdcmi.Init.SyncroCode.FrameStartCode = 0;
-  hdcmi.Init.SyncroCode.LineStartCode = 0;
-  hdcmi.Init.SyncroCode.LineEndCode = 0;
-  HAL_DCMI_Init(&hdcmi);
-*/
-
 }
 
 
@@ -541,8 +531,8 @@
 static void CameraIntHandler()
 {
 	Uart_Write((uint8_t*)"CameraIntHandler \n\r");
-	DCMI_HandleTypeDef hdcmi;
-    DMA_HandleTypeDef hdma_dcmi;
+//	DCMI_HandleTypeDef hdcmi;
+//    DMA_HandleTypeDef hdma_dcmi;
 	//MAP_CameraIntClear(CAMERA_BASE, CAM_INT_FE);
  //   if(g_total_dma_intrpts > 1 && MAP_CameraIntStatus(CAMERA_BASE) & CAM_INT_FE)
 //    {
--- a/camera_app/mt9d111/mt9d111.cpp	Fri Jun 26 22:53:54 2015 +0000
+++ b/camera_app/mt9d111/mt9d111.cpp	Tue Jun 30 22:51:05 2015 +0000
@@ -413,7 +413,7 @@
 //*****************************************************************************
 static int RegLstWrite(s_RegList *pRegLst, unsigned int ulNofItems)
 {
-    Uart_Write((uint8_t*)"\n\rRegLstWrite \n\r");
+//    Uart_Write((uint8_t*)"\n\rRegLstWrite \n\r");
     unsigned int       ulNdx;
     unsigned short      usTemp;
     unsigned char       i;
--- a/camera_app/stm32f4xx_msp.c	Fri Jun 26 22:53:54 2015 +0000
+++ b/camera_app/stm32f4xx_msp.c	Tue Jun 30 22:51:05 2015 +0000
@@ -67,15 +67,15 @@
 {
 
   GPIO_InitTypeDef GPIO_InitStruct;
-  if(hdcmi->Instance==DCMI)
-  {
+//  if(hdcmi->Instance==DCMI)
+//  {
    __GPIOE_CLK_ENABLE();
    __GPIOA_CLK_ENABLE();
    __GPIOB_CLK_ENABLE();
    __GPIOC_CLK_ENABLE();  
-   __GPIOH_CLK_ENABLE();   
+   __GPIOH_CLK_ENABLE(); //Enable HSE Clock 8MHz  
       
-   /**MCO2 GPIO Configuration is done else where  
+   /**MCO2 GPIO Configuration 
     PC9     ------> MCO2    
     */
        
@@ -119,7 +119,7 @@
     GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
     
-    /*Configure GPIO pin : PC9 */
+    /*Configure GPIO pin : GPIO_AF0_MCO PC9 */
     GPIO_InitStruct.Pin = GPIO_PIN_9;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
@@ -139,27 +139,27 @@
     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_ENABLE;
-    hdma_dcmi.Init.MemInc = DMA_MINC_DISABLE;
+    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.Mode = DMA_NORMAL;
+    hdma_dcmi.Init.Mode = DMA_NORMAL;//DMA_CIRCULAR;
     hdma_dcmi.Init.Priority = DMA_PRIORITY_HIGH;
-    hdma_dcmi.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
+    hdma_dcmi.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
     hdma_dcmi.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
     hdma_dcmi.Init.MemBurst = DMA_MBURST_SINGLE;
     hdma_dcmi.Init.PeriphBurst = DMA_PBURST_SINGLE;
-    HAL_DMA_Init(&hdma_dcmi);
-
+    
     __HAL_LINKDMA(hdcmi,DMA_Handle,hdma_dcmi);
 
   /* System interrupt init*/
-    HAL_NVIC_SetPriority(DCMI_IRQn, 0, 0);
+    HAL_NVIC_SetPriority(DCMI_IRQn, 5, 5);
 //    HAL_NVIC_EnableIRQ(DCMI_IRQn);
   /* USER CODE BEGIN DCMI_MspInit 1 */
-//  Uart_Write((uint8_t*)"HAL_DCMI_MspInit complete \n\r");
+
   /* USER CODE END DCMI_MspInit 1 */
-  }
+//  }
+    HAL_DMA_Init(&hdma_dcmi);
 
 }
 
--- a/main.cpp	Fri Jun 26 22:53:54 2015 +0000
+++ b/main.cpp	Tue Jun 30 22:51:05 2015 +0000
@@ -51,8 +51,8 @@
 
 #include "httpserverapp.h"
 
-#include "stm32f4xx_hal.h"
-#include "stm32f4xx_hal_rcc.h"
+//#include "stm32f4xx_hal.h"
+//#include "stm32f4xx_hal_rcc.h"
 
 /* Free-RTOS includes */
 #include "osi.h"
@@ -66,6 +66,9 @@
 static void SystemClock_Config(void);
 static void MX_DMA_Init(void);
 static void MX_DCMI_Init(void);
+
+void DCMI_IRQHandler(void);
+void DMA2_Stream1_IRQHandler(void);
  
  /**
   * Initializes the Global MSP.
@@ -95,6 +98,8 @@
 static void SystemClock_Config(void)
 {
   
+  SystemCoreClockUpdate();
+  
   RCC_OscInitTypeDef RCC_OscInitStruct;
   RCC_ClkInitTypeDef RCC_ClkInitStruct;
 //  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;//Used for ov7670 test
@@ -130,15 +135,25 @@
   /* RCC_MCODIV_5 33.6MHz mco output on pin PC_9 (cam xclk) */
   /* RCC_MCODIV_4 42MHz mco output on pin PC_9 (cam xclk) */
   /* RCC_MCODIV_3 56MHz mco output on pin PC_9 (cam xclk) */
-  HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_5);
+//  HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_4);
+
+  /* RCC_MCODIV_1 8MHz mco output on pin PC_9 (cam xclk) */  
+  HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_HSE, RCC_MCODIV_4);
+
   //Used for ov7670 test
   /* RCC_MCODIV_4 24MHz mco output on pin PC_9 (cam xclk) */
 //  HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_PLLI2SCLK, RCC_MCODIV_4);
 
   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
   
-  //Used for ov7670 test
-//  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
+  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
+
+/* STM32F405x/407x/415x/417x Revision Z devices: prefetch is supported  */
+//  if (HAL_GetREVID() == 0x1001)
+//  {
+    /* Enable the Flash prefetch */
+//    __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
+//  }
   
 }
  
@@ -156,7 +171,9 @@
   hdcmi.Init.JPEGMode = DCMI_JPEG_ENABLE;
 #else
   hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
-#endif    
+#endif
+
+  HAL_DCMI_MspInit(&hdcmi);  
   HAL_DCMI_Init(&hdcmi);
 
 }
@@ -170,7 +187,7 @@
    __DMA2_CLK_ENABLE();
 
   /* DMA interrupt init */
-  HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0);
+  HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 5, 5);
 //  HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);
 
 }
@@ -251,6 +268,8 @@
 
    int rv = 0;
    
+   HAL_Init();
+   
    SystemClock_Config();
    
    //
@@ -263,7 +282,7 @@
    MX_DCMI_Init();
    initLEDs();
 
-   toggleLed(1);
+//   toggleLed(1);
 //#ifndef NOTERM
 
 	//
@@ -314,6 +333,128 @@
 	return 0;
 }
 
+/**
+  * @brief  This function handles Hard Fault exception.
+  * @param  None
+  * @retval None
+  */
+extern "C" void HardFault_Handler(void)
+{
+  /* Go to infinite loop when Hard Fault exception occurs */
+  Uart_Write((uint8_t*)"HardFault_Handler \n\r");
+  while (1)
+  {
+  }
+}
+
+/**
+  * @brief  This function handles Memory Manage exception.
+  * @param  None
+  * @retval None
+  */
+extern "C" void MemManage_Handler(void)
+{
+  Uart_Write((uint8_t*)"MemManage_Handler \n\r");
+  /* Go to infinite loop when Memory Manage exception occurs */
+  while (1)
+  {
+  }
+}
+
+/**
+  * @brief  This function handles Bus Fault exception.
+  * @param  None
+  * @retval None
+  */
+extern "C" void BusFault_Handler(void)
+{
+  Uart_Write((uint8_t*)"BusFault_Handler \n\r");
+  /* Go to infinite loop when Bus Fault exception occurs */
+  while (1)
+  {
+  }
+}
+
+/**
+  * @brief  This function handles Usage Fault exception.
+  * @param  None
+  * @retval None
+  */
+extern "C" void UsageFault_Handler(void)
+{
+  Uart_Write((uint8_t*)"UsageFault_Handler \n\r");
+  /* Go to infinite loop when Usage Fault exception occurs */
+  while (1)
+  {
+  }
+}
+
+/**
+  * @brief  This function handles SVCall exception.
+  * @param  None
+  * @retval None
+  */
+/*  
+extern "C" void SVC_Handler(void)
+{
+	Uart_Write((uint8_t*)"SVC_Handler \n\r");
+}
+*/
+/**
+  * @brief  This function handles Debug Monitor exception.
+  * @param  None
+  * @retval None
+  */
+extern "C" void DebugMon_Handler(void)
+{
+	Uart_Write((uint8_t*)"DebugMon_Handler \n\r");
+}
+
+/**
+  * @brief  This function handles PendSVC exception.
+  * @param  None
+  * @retval None
+  */
+/*  
+extern "C" void PendSV_Handler(void)
+{
+	Uart_Write((uint8_t*)"PendSV_Handler \n\r");
+}
+*/
+/**
+  * @brief  This function handles SysTick Handler.
+  * @param  None
+  * @retval None
+  */
+/*  
+extern "C" void SysTick_Handler(void)
+{
+  Uart_Write((uint8_t*)"SysTick_Handler \n\r");
+  HAL_IncTick();
+}
+*/
+/**
+  * @brief  DMA interrupt handler.
+  * @param  None
+  * @retval None
+  */
+void DMA2_Stream1_IRQHandler(void)
+{
+  Uart_Write((uint8_t*)"DMA2_Stream1_IRQHandler \n\r");
+  HAL_DMA_IRQHandler(&hdma_dcmi);  
+}
+
+/**
+  * @brief  DCMI interrupt handler.
+  * @param  None
+  * @retval None
+  */
+void DCMI_IRQHandler(void)
+{
+  Uart_Write((uint8_t*)"DCMI_IRQHandler \n\r");
+  HAL_DCMI_IRQHandler(&hdcmi);
+}
+
 //*****************************************************************************
 //
 // Close the Doxygen group.
--- a/utils/app_config.h	Fri Jun 26 22:53:54 2015 +0000
+++ b/utils/app_config.h	Tue Jun 30 22:51:05 2015 +0000
@@ -4,8 +4,8 @@
 
 
 #define SPAWN_TASK_PRIORITY            7//9
-#define HTTP_SERVER_APP_TASK_PRIORITY  1//1
-#define CAMERA_SERVICE_PRIORITY        1
+#define HTTP_SERVER_APP_TASK_PRIORITY  2//1
+#define CAMERA_SERVICE_PRIORITY        2
 #define OSI_STACK_SIZE                 2048