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.
Revision 16:7e5aab2fabba, committed 2015-08-30
- Comitter:
- dflet
- Date:
- Sun Aug 30 21:10:11 2015 +0000
- Parent:
- 15:5433f9d94cd7
- Child:
- 17:acc075ff3fcb
- Commit message:
- 2 cams work now ov2640 and ov5642, the mt9d111 appears to be a hard nut to crack with respect to jpeg. Still have SPI issues, appears to be something to do with the MCO1 clock.
Changed in this revision
--- a/FreeRTOS/FreeRTOSConfig.h Fri Aug 28 21:04:44 2015 +0000 +++ b/FreeRTOS/FreeRTOSConfig.h Sun Aug 30 21:10:11 2015 +0000 @@ -86,7 +86,7 @@ #define configCPU_CLOCK_HZ ( ( unsigned long ) SystemCoreClock ) #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 130 ) -#define configTOTAL_HEAP_SIZE ( ( size_t ) (48 * 1024) ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) (36 * 1024) ) #define configMAX_TASK_NAME_LEN ( 24 ) #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0
--- a/camera_app/camera_app.cpp Fri Aug 28 21:04:44 2015 +0000 +++ b/camera_app/camera_app.cpp Sun Aug 30 21:10:11 2015 +0000 @@ -429,7 +429,7 @@ // // Create JPEG Header // -#ifndef OV2640_CAM +#ifdef MT9D111_CAM #ifdef ENABLE_JPEG memset(g_image.g_header, '\0', sizeof(g_image.g_header)); g_header_length = CreateJpegHeader((char *)&(g_image.g_header[0]), PIXELS_IN_X_AXIS, PIXELS_IN_Y_AXIS, 0, 0x0020, 9); @@ -449,7 +449,7 @@ #endif//ENABLE_JPEG *WriteBuffer = (char*)Image; return(g_header_length += g_frame_size_in_bytes); -#endif//OV2640_CAM +#endif//MT9D111_CAM *WriteBuffer = (char*)Image; return(g_frame_size_in_bytes); @@ -470,11 +470,9 @@ phdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; #ifdef OV5642_CAM -// phdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;//Data clocked out on falling edge phdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_RISING;//Data clocked out on rising edge - phdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;//Active low -// phdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;//Active low - phdcmi.Init.HSPolarity = DCMI_HSPOLARITY_HIGH;//Active high + phdcmi.Init.VSPolarity = DCMI_VSPOLARITY_HIGH;//Active high + phdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;//Active low #endif #ifdef OV2640_CAM phdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_RISING;//Data clocked out on rising edge @@ -483,10 +481,8 @@ #endif #ifdef MT9D111_CAM phdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_RISING;//Data clocked out on rising edge -// phdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;//Data clocked out on falling edge - phdcmi.Init.VSPolarity = DCMI_VSPOLARITY_HIGH;//Active high -// phdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;//Active high -// phdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;//Active low +// phdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;//Data clocked out on falling edge + phdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;//Active high phdcmi.Init.HSPolarity = DCMI_HSPOLARITY_HIGH;//Active high #endif phdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME; @@ -600,11 +596,11 @@ /*** Configure the NVIC for DCMI and DMA ***/ /* NVIC configuration for DCMI transfer complete interrupt */ - HAL_NVIC_SetPriority(DCMI_IRQn, 1, 0); + HAL_NVIC_SetPriority(DCMI_IRQn, 3, 0); HAL_NVIC_EnableIRQ(DCMI_IRQn); /* NVIC configuration for DMA2 transfer complete interrupt */ - HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 1, 0); + HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 3, 0); HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn); HAL_DMA_Init(&phdma_dcmi);
--- a/camera_app/httpserverapp/httpserverapp.cpp Fri Aug 28 21:04:44 2015 +0000 +++ b/camera_app/httpserverapp/httpserverapp.cpp Sun Aug 30 21:10:11 2015 +0000 @@ -52,7 +52,7 @@ // Free-RTOS/TI-RTOS include #include "FreeRTOS.h" #include "osi.h" -#include "semphr.h" +//#include "semphr.h" // HTTP lib includes #include "HttpCore.h" @@ -86,14 +86,6 @@ UINT16 g_uConnection; OsiTaskHandle g_iCameraTaskHdl = 0; -SemaphoreHandle_t xSemaphore = NULL; -void createMutex() -{ - - xSemaphore = xSemaphoreCreateMutex(); -} - - void WebSocketCloseSessionHandler() { g_close = 1;
--- a/main.cpp Fri Aug 28 21:04:44 2015 +0000 +++ b/main.cpp Sun Aug 30 21:10:11 2015 +0000 @@ -52,13 +52,13 @@ #include "httpserverapp.h" //#include "stm32f4xx_hal.h" -#include "stm32f4xx_hal_rcc.h" +//#include "stm32f4xx_hal_rcc.h" /* Free-RTOS includes */ #include "FreeRTOS.h" -#include "task.h" -#include "semphr.h" -#include "portmacro.h" +//#include "task.h" +//#include "semphr.h" +//#include "portmacro.h" #include "osi.h" @@ -114,22 +114,23 @@ GPIO_InitTypeDef GPIO_InitStruct; __GPIOA_CLK_ENABLE(); - /*Configure GPIO pin : GPIO_AF0_MCO PA8 */ - GPIO_InitStruct.Pin = GPIO_PIN_8; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; + //Configure GPIO pin : GPIO_AF0_MCO PA8 + GPIO_InitStruct.Pin = GPIO_PIN_8; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF0_MCO; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); -#if defined OV5642_CAM +// #ifndef MT9D111_CAM /* MCO1 output 16MHz */ - HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1); -#else +// HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); +//#else /* MCO1 output 8MHz */ - HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_2); -#endif +// HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_2); +//#endif wait_ms(500); + } void toggleLed(int ind){ @@ -170,10 +171,9 @@ // MAIN FUNCTION //**************************************************************************** int main(void) { + + int rv = 0; - SCB->SHCSR |= 0x00070000; - int rv = 0; - // // Configuring UART // @@ -212,7 +212,7 @@ // DisplayBanner(APP_NAME); - createMutex(); +// createMutex(); //#endif @@ -233,7 +233,7 @@ NULL ); Uart_Write((uint8_t*)"HttpServerApp Initializing \n\r"); - + // // Start the task scheduler // @@ -242,143 +242,7 @@ 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*)"\n\rHardFault_Handler \n\r"); - printf("Hard Fault Register SCB->HSFR 0x%X \r\n",SCB->HFSR); - printf("Fault bits set SCB->CFSR 0x%X \r\n",SCB->CFSR); - printf("Call to Memory Address SCB->BFAR 0x%X ERROR!\r\n",SCB->BFAR); - printf("Call to Memory Address SCB->MMFAR 0x%X ERROR!\r\n",SCB->MMFAR); - 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*)"\n\rMemManage_Handler \n\r"); - printf("Fault bits set SCB->CFSR 0x%X \r\n",SCB->CFSR); - printf("Call to Memory Address SCB->BFAR 0x%X ERROR!\r\n",SCB->BFAR); - printf("Call to Memory Address SCB->MMFAR 0x%X ERROR!\r\n",SCB->MMFAR); - 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*)"\n\rBusFault_Handler \n\r"); - printf("Fault bits set SCB->CFSR 0x%X \r\n",SCB->CFSR); - printf("Call to Memory Address SCB->BFAR 0x%X ERROR!\r\n",SCB->BFAR); - printf("Call to Memory Address SCB->MMFAR 0x%X ERROR!\r\n",SCB->MMFAR); - 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/simplelink/cc3100.cpp Fri Aug 28 21:04:44 2015 +0000 +++ b/simplelink/cc3100.cpp Sun Aug 30 21:10:11 2015 +0000 @@ -229,7 +229,7 @@ // Note that all profiles and persistent settings that were done on the // device will be lost // - Uart_Write((uint8_t*)"Starting configureSimpleLinkToDefaultState \n\r"); + lRetVal = configureSimpleLinkToDefaultState(); if(lRetVal < 0) { @@ -368,17 +368,17 @@ } #endif } - + /* Switch to STA role and restart */ retVal = _wlan.sl_WlanSetMode(ROLE_STA); ASSERT_ON_ERROR(retVal); - + retVal = sl_Stop(SL_STOP_TIMEOUT); ASSERT_ON_ERROR(retVal); - + retVal = sl_Start(0, 0, 0); ASSERT_ON_ERROR(retVal); - + /* Check if the device is in station again */ if (ROLE_STA != retVal) { /* We don't want to proceed if the device is not coming up in station-mode */ @@ -1194,7 +1194,6 @@ #if _SL_INCLUDE_FUNC(sl_Start) int16_t cc3100::sl_Start(const void* pIfHdl, int8_t* pDevName, const P_INIT_CALLBACK pInitCallBack) { - int16_t ObjIdx = MAX_CONCURRENT_ACTIONS; InitComplete_t AsyncRsp;
--- a/simplelink/cc3100_driver.cpp Fri Aug 28 21:04:44 2015 +0000 +++ b/simplelink/cc3100_driver.cpp Sun Aug 30 21:10:11 2015 +0000 @@ -358,11 +358,9 @@ *****************************************************************************/ _SlReturnVal_t cc3100_driver::_SlDrvCmdOp(_SlCmdCtrl_t *pCmdCtrl,void* pTxRxDescBuff, _SlCmdExt_t *pCmdExt) { - //printf("_SlDrvCmdOp\r\n"); _SlReturnVal_t RetVal; _SlDrvObjLockWaitForever(&g_pCB->GlobalLockObj); - g_pCB->IsCmdRespWaited = TRUE; SL_TRACE0(DBG_MSG, MSG_312, "_SlDrvCmdOp: call _SlDrvMsgWrite"); @@ -382,7 +380,6 @@ /* wait for respond */ RetVal = _SlDrvMsgReadCmdCtx(); /* will free global lock */ SL_TRACE0(DBG_MSG, MSG_314, "_SlDrvCmdOp: exited _SlDrvMsgReadCmdCtx"); - } else { _SlDrvObjUnLock(&g_pCB->GlobalLockObj); @@ -625,7 +622,6 @@ VERIFY_RET_OK(_SlDrvRxHdrRead((uint8_t*)(uBuf.TempBuf), &AlignSize)); - OpCode = OPCODE(uBuf.TempBuf); RespPayloadLen = RSP_PAYLOAD_LEN(uBuf.TempBuf); @@ -640,10 +636,9 @@ _SlDrvSyncObjSignal(&g_pCB->FlowContCB.TxSyncObj); } } - + /* Find the RX messaage class and set its async event handler */ _SlDrvClassifyRxMsg(OpCode); - RxMsgClass = g_pCB->FunctionParams.AsyncExt.RxMsgClass; @@ -913,7 +908,6 @@ /* ******************************************************************************/ _SlReturnVal_t cc3100_driver::_SlDrvMsgReadCmdCtx(void) { - /* after command response is received and isCmdRespWaited */ /* flag is set FALSE, it is necessary to read out all */ /* Async messages in Commands context, because ssiDma_IsrHandleSignalFromSlave */ @@ -927,7 +921,7 @@ VERIFY_RET_OK(_SlDrvMsgRead()); g_pCB->RxDoneCnt++; - + if (CMD_RESP_CLASS == g_pCB->FunctionParams.AsyncExt.RxMsgClass) { g_pCB->IsCmdRespWaited = FALSE; @@ -946,7 +940,7 @@ /* temporary context, i.e less waste of CPU and faster buffer */ /* release. */ _SlAsyncEventGenericHandler(); - + #ifdef SL_MEMORY_MGMT_DYNAMIC sl_Free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); #else @@ -1106,20 +1100,23 @@ _SlReturnVal_t cc3100_driver::_SlDrvRxHdrRead(uint8_t *pBuf, uint8_t *pAlignSize) { uint32_t SyncCnt = 0; - uint8_t ShiftIdx; + uint8_t ShiftIdx; #ifndef SL_IF_TYPE_UART /* 1. Write CNYS pattern to NWP when working in SPI mode only */ _spi.spi_Write(g_pCB->FD, (uint8_t *)&g_H2NCnysPattern.Short, SYNC_PATTERN_LEN); #endif - + /* 2. Read 4 bytes (protocol aligned) */ _spi.spi_Read(g_pCB->FD, &pBuf[0], 4); _SL_DBG_SYNC_LOG(SyncCnt,pBuf); - + /* Wait for SYNC_PATTERN_LEN from the device */ while ( ! N2H_SYNC_PATTERN_MATCH(pBuf, g_pCB->TxSeqNum) ) { /* 3. Debug limit of scan */ + if(SyncCnt >= SL_SYNC_SCAN_THRESHOLD){ + printf("SPI Sync pattern match fault\n\r"); + } VERIFY_PROTOCOL(SyncCnt < SL_SYNC_SCAN_THRESHOLD); /* 4. Read next 4 bytes to Low 4 bytes of buffer */
--- a/simplelink/cc3100_spi.cpp Fri Aug 28 21:04:44 2015 +0000 +++ b/simplelink/cc3100_spi.cpp Sun Aug 30 21:10:11 2015 +0000 @@ -55,7 +55,7 @@ { _wlan_spi.format(8,1); - _wlan_spi.frequency(12000000); + _wlan_spi.frequency(16000000); _wlan_irq.rise(this, &cc3100_spi::IntSpiGPIOHandler); //_SlDrvRxIrqHandler is called from IntSpiGPIOHandler // _sw1_irq.rise(this, &cc3100_spi::buttonHandler_1); // _sw2_irq.rise(this, &cc3100_spi::buttonHandler_2); @@ -140,12 +140,14 @@ int len_to_return = len; // Uart_Write((uint8_t*)"Write\r\n"); _wlan_cs = 0; - +// for(int i = 0;i<len;i++){ +// printf(" %x",pBuff[i]); +// } while(len) { _wlan_spi.write(*pBuff++); len--; } - +// printf("\r\n"); _wlan_cs = 1; return len_to_return; @@ -159,8 +161,9 @@ for (i = 0; i < len; i++) { pBuff[i] = _wlan_spi.write(0xFF); +// printf(" %x",pBuff[i]); } - +// printf("\r\n"); _wlan_cs = 1; return len; }
--- a/simplelink/cc3100_wlan.cpp Fri Aug 28 21:04:44 2015 +0000 +++ b/simplelink/cc3100_wlan.cpp Sun Aug 30 21:10:11 2015 +0000 @@ -688,7 +688,7 @@ Msg.Cmd.mode = mode; VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanSetModeCmdCtrl , &Msg, NULL)); - + return (int16_t)Msg.Rsp.status; }
--- a/utils/app_config.h Fri Aug 28 21:04:44 2015 +0000 +++ b/utils/app_config.h Sun Aug 30 21:10:11 2015 +0000 @@ -15,8 +15,8 @@ #define ENABLE_JPEG //#define MT9D111_CAM -//#define OV5642_CAM -#define OV2640_CAM +#define OV5642_CAM +//#define OV2640_CAM //#define XGA_FRAME //#define VGA_FRAME @@ -34,9 +34,9 @@ #define sensor_addr 0x78 #endif -#define SPAWN_TASK_PRIORITY 7//9 -#define HTTP_SERVER_APP_TASK_PRIORITY 3//1 -#define CAMERA_SERVICE_PRIORITY 3 +#define SPAWN_TASK_PRIORITY 9//9 +#define HTTP_SERVER_APP_TASK_PRIORITY 1//1 +#define CAMERA_SERVICE_PRIORITY 1 #define OSI_STACK_SIZE 12 * 1024 //*****************************************************************************