thomas haine
/
CIS001_v2_v2
cis001v2
Revision 8:66caa906d24c, committed 2021-02-10
- Comitter:
- thomashaine
- Date:
- Wed Feb 10 16:38:32 2021 +0000
- Parent:
- 7:4c77f017b4b8
- Commit message:
- v2
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_status.cpp Wed Feb 10 16:38:32 2021 +0000 @@ -0,0 +1,129 @@ +#include "mbed.h" + +/** +@param none +@return void +@brief print the start of the frame stored in frame buffer +*/ + +extern Serial pc; + +void print_HAL_status_code(HAL_StatusTypeDef val){ + + if(val == HAL_OK){ + pc.printf("HAL status : HAL_OK\r\n"); + }else if (val ==HAL_ERROR){ + pc.printf("HAL status : HAL_ERROR\r\n"); + }else if (val ==HAL_BUSY){ + pc.printf("HAL status : HAL_BUSY\r\n"); + }else if (val ==HAL_TIMEOUT){ + pc.printf("HAL status : HAL_TIMEOUT\r\n"); + }else{ + pc.printf("HAL status : undefined status code\r\n"); + } + +} + +/** +@param none +@return void +@brief print the start of the frame stored in frame buffer +*/ +void print_DCMI_error_code(uint32_t errorCode){ + + if(errorCode == HAL_DCMI_ERROR_NONE){ + pc.printf("DCMI error: No error\r\n"); + }else if(errorCode == HAL_DCMI_ERROR_OVR){ + pc.printf("DCMI error: Overrun error\r\n"); + }else if(errorCode == HAL_DCMI_ERROR_SYNC){ + pc.printf("DCMI error: Synchronization error\r\n"); + }else if(errorCode == HAL_DCMI_ERROR_TIMEOUT){ + pc.printf("DCMI error: Timeout error\r\n"); + }else if(errorCode == HAL_DCMI_ERROR_DMA){ + pc.printf("DCMI error: DMA error\r\n"); + }else { + pc.printf("DCMI error: error code not recognized\r\n"); + } +} + +/** +@param none +@return void +@brief print the start of the frame stored in frame buffer +*/ +void print_DCMI_state_code(HAL_DCMI_StateTypeDef state){ + + if(state == HAL_DCMI_STATE_RESET){ + pc.printf("DCMI state: reset\r\n"); + }else if(state == HAL_DCMI_STATE_READY){ + pc.printf("DCMI state: ready\r\n"); + }else if(state == HAL_DCMI_STATE_BUSY){ + pc.printf("DCMI state: busy\r\n"); + }else if(state == HAL_DCMI_STATE_TIMEOUT){ + pc.printf("DCMI state: Timeout\r\n"); + }else if(state == HAL_DCMI_STATE_ERROR){ + pc.printf("DCMI state: error\r\n"); + }else if(state == HAL_DCMI_STATE_SUSPENDED){ + pc.printf("DCMI state: sespended\r\n"); + }else { + pc.printf("DCMI state: state code not recognized\r\n"); + } +} + +/** +@param none +@return void +@brief print the start of the frame stored in frame buffer +*/ +void print_HAL_DMA_error_code(uint32_t error_code){ + + if(error_code==HAL_DMA_ERROR_NONE){ + pc.printf("DMA error : no error\r\n"); + }else if(error_code==HAL_DMA_ERROR_TE){ + pc.printf("DMA error : Transfer error\r\n"); + }else if(error_code==HAL_DMA_ERROR_FE){ + pc.printf("DMA error : FIFO error\r\n"); + }else if(error_code==HAL_DMA_ERROR_DME){ + pc.printf("DMA error : Direct Mode error\r\n"); + }else if(error_code==HAL_DMA_ERROR_TIMEOUT){ + pc.printf("DMA error : Timeout error\r\n"); + }else if(error_code==HAL_DMA_ERROR_PARAM){ + pc.printf("DMA error : Parameter error\r\n"); + }else if(error_code==HAL_DMA_ERROR_NO_XFER){ + pc.printf("DMA error : Abort requested with no Xfer ongoing\r\n"); + }else if(error_code==HAL_DMA_ERROR_NOT_SUPPORTED){ + pc.printf("DMA error : Not supported mode\r\n"); + }else if(error_code==HAL_DMA_ERROR_SYNC){ + pc.printf("DMA error : DMAMUX sync overrun error\r\n"); + }else if(error_code==HAL_DMA_ERROR_REQGEN){ + pc.printf("DMA error : DMAMUX request generator overrun error\r\n"); + }else if(error_code==HAL_DMA_ERROR_BUSY){ + pc.printf("DMA error : DMA Busy error\r\n"); + }else{ + pc.printf("DMA error : undefined error code\r\n"); + } +} + +/** +@param none +@return void +@brief print the start of the frame stored in frame buffer +*/ +void print_HAL_DMA_status_code(HAL_DMA_StateTypeDef state_code){ + + if(state_code == HAL_DMA_STATE_RESET){ + pc.printf("DMA state : reset - DMA not yet initialized or disabled\r\n"); + } else if(state_code== HAL_DMA_STATE_READY){ + pc.printf("DMA state : ready - DMA initialized and ready for use\r\n"); + } else if(state_code== HAL_DMA_STATE_BUSY){ + pc.printf("DMA state : busy - DMA process is ongoing \r\n"); + } /*else if(state_code== HAL_DMA_STATE_TIMEOUT){ + pc.printf("DMA state : DMA timeout state\r\n"); + } */else if(state_code== HAL_DMA_STATE_ERROR){ + pc.printf("DMA state : DMA error state\r\n"); + } else if(state_code== HAL_DMA_STATE_ABORT){ + pc.printf("DMA state : DMA Abort state\r\n"); + } else { + pc.printf("DMA state : undefined state code\r\n"); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_status.h Wed Feb 10 16:38:32 2021 +0000 @@ -0,0 +1,42 @@ +/** + ****************************************************************************** + * @file : check_status.h + * @brief : Header for check_status.cpp file. + * This file contains the common defines of the application. + ****************************************************************************** + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __CHECK_STATUS_H__ +#define __CHECK_STATUS_H__ + +/* Includes ------------------------------------------------------------------*/ + +/* USER CODE BEGIN Includes */ +/* USER CODE END Includes */ + +/* Private define ------------------------------------------------------------*/ + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + +/* USER CODE BEGIN Private defines */ + +//error debug +void print_HAL_status_code(HAL_StatusTypeDef val); +void print_DCMI_error_code(uint32_t errorCode); +void print_DCMI_state_code(HAL_DCMI_StateTypeDef state); +void print_HAL_DMA_error_code(uint32_t error_code); +void print_HAL_DMA_status_code(HAL_DMA_StateTypeDef state_code); + +/* USER CODE END Private defines */ + + +#endif /* __CHECK_STATUS_H__ */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/common_task.cpp Wed Jan 06 13:35:17 2021 +0000 +++ b/common_task.cpp Wed Feb 10 16:38:32 2021 +0000 @@ -7,17 +7,22 @@ extern Serial pc; + extern DigitalOut led3; extern DigitalOut led2; +extern DigitalOut led1; + extern SPI spi; // mosi, miso, sclk extern DigitalOut SSN; -extern InterruptIn button_capture; +extern DigitalIn button_capture; extern InterruptIn irq_cis; extern DigitalOut RSTN; extern DigitalOut SLEEPN; extern DigitalOut CAPTURE; +extern DigitalOut CONFIG1; +extern DigitalOut CONFIG2; extern uint8_t DCMI_8b_mode; @@ -106,23 +111,37 @@ * @param nonce * @retval void */ -void TASK_INIT(){ +void TASK_INIT_SENSOR(){ // Enable reset RSTN=0; //0 => reset OK wait_us(5000); //DEFAULT SIGNAL OUTPUT + // Output enable + CONFIG2=0; + CONFIG1=1; + /* config + • Pad 2’b00: version 1 + • Pad 2’b01: version 2 (default) + • Pad 2’b10: version 3 + • Pad 2’b11: test mode - scan chain + */ + + SLEEPN=0; //1 => active - CAPTURE=0; //0 => no capture + CAPTURE=0; //0 => no capture + SSN=1; //1 => spi disabled wait_us(5000); // Disable reset RSTN=1; wait_us(5000); + + } @@ -131,9 +150,9 @@ * @param nonce * @retval void */ -void TASK_RSTN(){ +void TASK_RSTN_SENSOR(){ RSTN=0; - wait_us(2000); + wait_ms(2000); RSTN=1; wait_us(1000); @@ -153,7 +172,7 @@ int packet = (adr<<8 | data); SSN=0; - + wait_us(50); spi.write(packet); wait_us(50); @@ -185,6 +204,7 @@ //sprintf(toprint,"read at add %d -> data %d \n\r",adr,rx_buffer); //myprint(toprint); return (int) rx_buffer; + } /** @@ -195,30 +215,21 @@ int TASK_TEST_SPI(void){ uint8_t a; - int data[4]={0x55, 0xAA, 0xFF, 0x00}; + const uint8_t size=4; + int data[size]={0x55, 0xAA, 0xFF, 0x00}; int pass=0; int i=0; int length = sizeof(data)/sizeof(data[0]); - sprintf(toprint,"%64s","**************"); - myprint(toprint); - sprintf(toprint,"%64s","PING SPI"); - myprint(toprint); - sprintf(toprint,"%64s","**************"); - myprint(toprint); - for (i=0;i<length;i++){ TASK_SPI_WRITE((int)test_add,data[i]); a=TASK_SPI_READ((int)test_add); if (a==data[i]) pass++; - sprintf(toprinttemp,"write 0x%02x at 0x%02x. read 0x%02x at 0x%02x",data[i],test_add,a,test_add); - sprintf(toprint,"%64s",toprinttemp); - myprint(toprint); } - return (pass==4); + return (pass==size); } @@ -230,10 +241,6 @@ int d; float average; - myprint("**************\r\n"); - myprint("ANALOG CALIB\r\n"); - myprint("**************\r\n"); - e=TASK_SPI_READ(analog_gain_add); TASK_SPI_WRITE(mode_add,0x02); //mode SO+calib
--- a/common_task.h Wed Jan 06 13:35:17 2021 +0000 +++ b/common_task.h Wed Feb 10 16:38:32 2021 +0000 @@ -1,5 +1,3 @@ - - /** ****************************************************************************** * @file : common_task.h @@ -8,8 +6,6 @@ ****************************************************************************** ****************************************************************************** */ - - /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __COMMON_TASK_H__ #define __COMMON_TASK_H__ @@ -27,32 +23,22 @@ * @brief Uncomment the line below to expanse the "assert_param" macro in the * HAL drivers code */ -/* #define USE_FULL_ASSERT 1U */ + /* USER CODE BEGIN Private defines */ int myprint(const char* mystring); - void usage(void); - - void TASK_INIT(); - - void TASK_RSTN(); - + void TASK_INIT_SENSOR(); + void TASK_RSTN_SENSOR(); void TASK_SPI_WRITE(int adr, int data); - int TASK_SPI_READ(int adr); - int TASK_TEST_SPI(); - void TASK_ANALOG_CALIB(); - void TASK_auto_ccal(); /* USER CODE END Private defines */ - - #endif /* __COMMON_TASK_H__ */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ \ No newline at end of file
--- a/main.cpp Wed Jan 06 13:35:17 2021 +0000 +++ b/main.cpp Wed Feb 10 16:38:32 2021 +0000 @@ -2,6 +2,7 @@ //my include #include "main.h" #include "common_task.h" +#include "check_status.h" #include "register_address.h" //mbed include @@ -19,6 +20,9 @@ DCMI_HandleTypeDef hdcmi; DMA_HandleTypeDef hdma_dcmi; +// DMA handle for mem2mem transfert +DMA_HandleTypeDef hd_m2m_dma; + // Virtual USB Serial port Serial pc(USBTX, USBRX); @@ -34,8 +38,8 @@ char* commandbuffer; char* commandbuffertemp; - -int MSG_LEN=64; +int IN_MSG_LEN=64; +char OUT_MSG_LEN[5]="%64s"; // SPI1 @@ -45,31 +49,45 @@ //LEDs DigitalOut led1(LED1); //PB_0 -DigitalOut led2(LED2); //PB7 -DigitalOut led3(LED3); //PB14 +DigitalOut led2(LED2); //PB_7 +DigitalOut led3(LED3); //PB_14 // GPIOS DigitalOut RSTN(PA_0); DigitalOut SLEEPN(PA_2); DigitalOut CAPTURE(PA_9); -InterruptIn button_capture(PC_13); +DigitalIn button_capture(PC_13); InterruptIn irq_cis(PA_11); //TODO -DigitalOut CONFIG1(PA_8); //TODO -DigitalOut CONFIG2(PD_2); //TODO -//FastPWM MCLK(PA_3); +DigitalOut CONFIG1(PA_8); +DigitalOut CONFIG2(PD_2); +//FastPWM MCLK(PA_3); -//keep track fo the number of line and frame read -int line_read=0; -int frame_read=0; -int imSize=frame_bsize_10b; // frame pointer and frame size char* FRAME_BUFFER; -//char hidden_array[frame_bsize_10b]; +int imSize=frame_bsize_10b; + + +int DEBUG=0; +int DEBUG_DCMI=1; +int TEST_DMA=1; -int DEBUG=1; +// DCMI callback handler +static __IO int HAL_DCMI_ErrorCallback_value=0; +static __IO int HAL_DCMI_IRQHandler_value=0; +static __IO int line_read=0; +static __IO int frame_read=0; +static __IO int frame_ready_to_send=0; + +// DMA callback handler +static __IO int DMA1_Stream0_IRQHandler_value=0; +static __IO int DMA1_Stream1_IRQHandler_value=0; +static __IO int DMA2_Stream1_IRQHandler_value=0; +static __IO int DMA_IRQHandler_value=0; +static __IO int HAL_DMA_XferCpltCallback_value=0; +static __IO int HAL_DMA_XferErrorCallback_value=0; @@ -92,11 +110,11 @@ for (i=0; i<1 ; i++){ for (k=0; k<20; k++){ for (j=0; j<32; j++){ - //pc.printf("%3i ",(uint8_t) *(FRAME_BUFFER+i*640+k*32+j)); + pc.printf("%3i ",(uint8_t) *(FRAME_BUFFER+i*640+k*32+j)); sprintf(commandbuffer, "%3i ",(uint8_t) *(FRAME_BUFFER+i*640+k*32+j)); byte_sent=cs.send(commandbuffer, strlen(commandbuffer)); } - //pc.printf("\b\r\n"); + pc.printf("\b\r\n"); sprintf(commandbuffer, "\b\r\n"); byte_sent=cs.send(commandbuffer, strlen(commandbuffer)); @@ -149,39 +167,43 @@ * ************************************************************************************************/ - - - //https://github.com/tomvdb/stm32f401-nucleo-basic-template/blob/master/Drivers/BSP/STM324x9I_EVAL/stm324x9i_eval_camera.c /** @brief start dcmi and start frame capture @param none @return void */ -void start_capture_10b(){ - +void start_capture(){ frame_read=0; line_read=0; //memset(FRAME_BUFFER,0,(size_t) frame_bsize_10b); - //HAL_DCMI_Stop(&hdcmi); - //pc.printf("starting snapshot 10b\r\n"); + HAL_DCMI_Stop(&hdcmi); + if(DEBUG_DCMI==1) + pc.printf("starting snapshot\r\n"); // disable crop features - //HAL_DCMI_DisableCrop(&hdcmi); + HAL_DCMI_DisableCrop(&hdcmi); //enable DCMI ///HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, (uint32_t) FRAME_BUFFER, Im_size); - HAL_DCMI_Start_DMA (&hdcmi, DCMI_MODE_SNAPSHOT,(uint32_t) FRAME_BUFFER, (uint32_t) imSize); - - //start capture - TASK_SPI_WRITE(capture_add,1); - wait_us(1000); - TASK_SPI_WRITE(capture_add,0); + //HAL_StatusTypeDef status = HAL_DCMI_Start_DMA (&hdcmi, DCMI_MODE_SNAPSHOT,(uint32_t) FRAME_BUFFER, (uint32_t) frame_wsize_QVGA_10b); + HAL_StatusTypeDef status = HAL_DCMI_Start_DMA (&hdcmi, DCMI_MODE_SNAPSHOT,(uint32_t) 0x30000000, (uint32_t) frame_wsize_QVGA_10b); + wait_us(100); + + if(DEBUG_DCMI==1) { + print_HAL_status_code(status); + print_DCMI_state_code(HAL_DCMI_GetState(&hdcmi)); + print_DCMI_error_code(HAL_DCMI_GetError(&hdcmi)); + pc.printf("%i XferCount\r\n",hdcmi.XferCount); + pc.printf("%i XferSize\r\n",hdcmi.XferSize); + pc.printf("%i XferTransferNumber\r\n",hdcmi.XferTransferNumber); + pc.printf("%x pBuffPtr\r\n",hdcmi.pBuffPtr); + pc.printf("%i ErrorCode\r\n",hdcmi.ErrorCode); + } } - /** @brief suspend DCMI @param none @@ -189,7 +211,10 @@ */ void suspend_capture(void){ // Suspend the Camera Capture // - HAL_DCMI_Suspend(&hdcmi); + HAL_DCMI_Suspend(&hdcmi); + + HAL_DCMI_StateTypeDef DCMI_state = HAL_DCMI_GetState(&hdcmi); + print_DCMI_state_code(DCMI_state); } /** @@ -208,25 +233,29 @@ @return void */ void stop_capture(void) { - if(HAL_DCMI_Stop(&hdcmi) == HAL_OK){ + if(HAL_DCMI_Stop(&hdcmi) == HAL_OK){ pc.printf("Error stopping camera\n\r"); - } - else{ + }else{ pc.printf("Camera stopped\n\r"); } + + HAL_DCMI_StateTypeDef DCMI_state = HAL_DCMI_GetState(&hdcmi); + print_DCMI_state_code(DCMI_state); } - +/********************************** +* +* override DCMI callbacks +* +**********************************/ /** @brief override interrupt DCMI: on frame callback; send frame @param none @return void */ void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi){ - pc.printf("frame event callback: read %i lines \r\n",line_read); - line_read=0; - send_frame_ethernet_nohandshake_while(); + frame_ready_to_send=1; } /** @@ -235,19 +264,45 @@ @return void */ void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi){ - frame_read++; + frame_read++; } /** -@brief override interrupt DCMI: on hsync callback; inrement line count +@brief override interrupt DCMI: on hsync callback; increment line count @param none @return void */ void HAL_DCMI_LineEventCallback (DCMI_HandleTypeDef *hdcmi){ - line_read++; + line_read++; +} + +/** +@brief override interrupt DCMI: on error callback; +@param none +@return void +*/ +void HAL_DCMI_ErrorCallback (DCMI_HandleTypeDef *hdcmi){ + HAL_DCMI_ErrorCallback_value=HAL_DCMI_GetError(hdcmi); + pc.printf("error callback\r\n"); } /** +@brief override interrupt DCMI: on IRQ handler; +@param none +@return void +*/ +/*void HAL_DCMI_IRQHandler (DCMI_HandleTypeDef * hdcmi){ + HAL_DCMI_IRQHandler_value=1; + pc.printf("DCMI IRQ handler\n\r"); +}*/ + +/********************************** +* +* override DCMI callbacks +* +**********************************/ + +/** @brief debug: set frmae buffer as a known pattern @param none @return void @@ -268,12 +323,6 @@ } -/********************************************************************************************** -* -* debug -* -************************************************************************************************/ - void print_memory_info() { // allocate enough room for every thread's stack statistics int cnt = osThreadGetCount(); @@ -281,15 +330,55 @@ cnt = mbed_stats_stack_get_each(stats, cnt); for (int i = 0; i < cnt; i++) { - printf("Thread: 0x%lX, Stack size: %lu / %lu\r\n", stats[i].thread_id, stats[i].max_size, stats[i].reserved_size); + printf("Thread: 0x%iX, Stack size: %iu / %iu\r\n", stats[i].thread_id, stats[i].max_size, stats[i].reserved_size); } free(stats); // Grab the heap statistics mbed_stats_heap_t heap_stats; mbed_stats_heap_get(&heap_stats); - printf("Heap size: %lu / %lu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size); + printf("Heap size: %iu / %iu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size); +} + + +/******************************************************************************/ +/* STM32H7xx Peripheral Interrupt Handlers */ +/* Add here the Interrupt Handlers for the used peripherals. */ +/* For the available peripheral interrupt handler names, */ +/* please refer to the startup file (startup_stm32h7xx.s). */ +/******************************************************************************/ +/** + * @brief This function is executed in case of complition. + * @param MDMA_HandleTypeDef * hmdma + * @retval None + */ +void HAL_DMA_XferCpltCallback (DMA_HandleTypeDef * hddma){ + HAL_DMA_XferCpltCallback_value=1; } +/** + * @brief This function is executed in case of error. + * @param MDMA_HandleTypeDef * hmdma + * @retval None + */ +void HAL_DMA_XferErrorCallback (DMA_HandleTypeDef * hddma){ + HAL_DMA_XferErrorCallback_value=1; +} + +/** + * @brief This function handles DMA1 stream0 global interrupt. + */ +void DMA2_Stream1_IRQHandler(void){ + HAL_DMA_IRQHandler(&hd_m2m_dma); + DMA2_Stream1_IRQHandler_value=1; +} +/*void DMA1_Stream0_IRQHandler(void){ + HAL_DMA_IRQHandler(&hd_m2m_dma); + DMA1_Stream0_IRQHandler_value=1; +}*/ + +/*void DMA_IRQHandler(DMA_HandleTypeDef* hdma){ + DMA_IRQHandler_value=1; +}*/ /********************************************************************************************** @@ -310,56 +399,163 @@ uint8_t OEN_flag=0; int status=0; int byte_sent; - char host_cmd[64]; + char host_cmd[IN_MSG_LEN+1]; int loopcount=0; int button_pushed=0; //ethernet - char rbuffer[MSG_LEN]; + char rbuffer[IN_MSG_LEN+1]; char * pch; int rcount; int data=0; int add=0; int readvalue=0; int i=0; - int sizetosent=64; + int sizetosent=IN_MSG_LEN; - //*********************** + //*********************************************** /* Initialize all configured peripherals - First thing to do */ - //*********************** + //*********************************************** + HAL_Init(); + // general purpose IO MX_GPIO_Init(); - MX_DMA_Init(); - MX_DCMI_Init_10b(); + // digital camera interface - //************************ + //************************************************ // config serial print - //************************ + //************************************************ pc.baud(115200);//Set baudrate here. - pc.printf("*****************\r\n CIS001 \r\n*****************\r\n"); - - //************************ - // init pointer - //************************ - // - //!!!!!! attention : malloc is in num of words and not byte !!!!!!!! idem memset - // - //initialize frame buffer for 10b photo (malloc size en byte) + pc.printf("**********************************\r\n CIS001 \r\n**********************************\r\n"); + pc.printf("Nucleo CPU SystemCoreClock is %d MHz\r\n", SystemCoreClock/1000000); + + MX_DMA_Init(); + // flexible memory controller + MX_DCMI_Init_10b(); + // direct memory access + + + //*********************************************** + /* Disable/Enable the CPU Cache */ + //*********************************************** + // must clean Dcache before disabling; + SCB_CleanDCache(); + SCB_DisableICache(); + SCB_DisableDCache(); + + //SCB_EnableICache(); + //SCB_EnableDCache(); + + + //************************************************ + // reset leds + //************************************************ + led1=0; + led2=0; + led3=0; + + //************************************************ + // init pointers + //************************************************ + pc.printf("**********************************\r\n"); + pc.printf("Initialising pointer with malloc...\r\n"); print_memory_info(); int random_memset= (rand()%3) ; - FRAME_BUFFER=(char *) malloc( frame_bsize_10b/2*sizeof(char)); - memset((void *)FRAME_BUFFER,random_memset,(size_t) frame_bsize_10b/2); + FRAME_BUFFER=(char *) malloc( frame_bsize_QVGA_10b*sizeof(char)); + memset((void *)FRAME_BUFFER,random_memset,(size_t) frame_bsize_QVGA_10b); print_memory_info(); + //initialize commandbuffer pointer + commandbuffer=(char *) malloc((IN_MSG_LEN+1)*sizeof(char)); + commandbuffertemp=(char *) malloc((IN_MSG_LEN+1)*sizeof(char)); + pc.printf("done\r\n"); - //initialize commandbuffer pointer - commandbuffer=(char *) malloc((MSG_LEN+1)*sizeof(char)); - commandbuffertemp=(char *) malloc((MSG_LEN+1)*sizeof(char)); - //************************ + //************************************************ + // test DMA + //************************************************ + if(TEST_DMA){ + pc.printf("**********************************\r\n"); + pc.printf("testing Mem2Mem DMA : writing from secondary SRAM to secondary SRAM\r\n"); + + int debug_dma=0; + const int buff_size=16384; // word size + uint32_t* DMATestPatternAddresss= (uint32_t *) (0x30000000); + uint32_t* DMAReadAddress= (uint32_t *) (0x30000000+buff_size*4); + int nb_error_dma=0; + char pattern[4]={0x00,0x55,0xaa,0xFF}; + uint32_t errordma; + HAL_DMA_StateTypeDef state_dma; + HAL_StatusTypeDef res_dma; + + for (int i=0;i<4;i++){ + //set pattern & clean dest buffer + memset((void *) DMATestPatternAddresss, (int) pattern[i], (size_t) (buff_size*sizeof(uint32_t)/sizeof(char)) ); + memset((void *) DMAReadAddress, (int) 0x01, (size_t) (buff_size*sizeof(uint32_t)/sizeof(char)) ); + + if(debug_dma){ + errordma = HAL_DMA_GetError (&hd_m2m_dma); + state_dma = HAL_DMA_GetState (&hd_m2m_dma); + pc.printf("\n\r"); + print_HAL_DMA_error_code(errordma); + print_HAL_DMA_status_code(state_dma); + } + + //reset interrupt variable + DMA2_Stream1_IRQHandler_value=0; + HAL_DMA_XferErrorCallback_value=0; + HAL_DMA_XferCpltCallback_value=0; + + res_dma= HAL_DMA_Start_IT(&hd_m2m_dma, (uint32_t) DMATestPatternAddresss, (uint32_t) DMAReadAddress, (uint32_t) buff_size); + if(debug_dma){ + errordma = HAL_DMA_GetError (&hd_m2m_dma); + state_dma = HAL_DMA_GetState (&hd_m2m_dma); + pc.printf("\n\r"); + print_HAL_status_code(res_dma); + print_HAL_DMA_error_code(errordma); + print_HAL_DMA_status_code(state_dma); + } + + while ( !(DMA2_Stream1_IRQHandler_value|| HAL_DMA_XferCpltCallback_value || HAL_DMA_XferErrorCallback_value)){ + if(debug_dma){ + pc.printf(" %i %i %i\r\n",DMA2_Stream1_IRQHandler_value,HAL_DMA_XferCpltCallback_value,HAL_DMA_XferErrorCallback_value); + wait_us(100000); + } + } + if(HAL_DMA_XferErrorCallback_value){ + pc.printf("DMA error interrupt\n\r"); + } + if(debug_dma){ + pc.printf("dma exit: dma2s1-%i CmpltCB-%i ErrorCB-%i\r\n",DMA2_Stream1_IRQHandler_value,HAL_DMA_XferCpltCallback_value,HAL_DMA_XferErrorCallback_value); + errordma = HAL_DMA_GetError (&hd_m2m_dma); + state_dma = HAL_DMA_GetState (&hd_m2m_dma); + print_HAL_DMA_error_code(errordma); + print_HAL_DMA_status_code(state_dma); + pc.printf("\n\r"); + } + + //check result + for (int j=0;j<buff_size;j++){ + if(debug_dma && j<10){ + pc.printf("%u == %u\r\n",*(DMATestPatternAddresss+j),*(DMAReadAddress+j)); + } + if(*(DMATestPatternAddresss+j)!= *(DMAReadAddress+j)){ + nb_error_dma++; + } + } + pc.printf("%i/%i error(s) in DMA test %i\r\n",nb_error_dma,buff_size,i); + nb_error_dma=0; + //wait_us(10000); + } + } + + + //************************************************ // init spi - //************************ + //************************************************ + pc.printf("**********************************\r\n"); + pc.printf("Confirguring the SPI..."); // Setup the spi for 16 bit data (2x8), high steady state clock,second edge capture, with a 5MHz clock rate /* mode | POL PHA -----+-------- @@ -370,30 +566,38 @@ spi.format(16,0); spi.frequency(100000); - //start generating MCLK uint32_t half_periode=4; //MCLK.prescaler(1); //MCLK.period_ticks(9); //MCLK.pulsewidth_ticks(half_periode); //mclk=1; + pc.printf("done\r\n"); + pc.printf("Testing the SPI...\r\n"); + a=TASK_TEST_SPI(); + if (a==0){ + pc.printf("Test spi OK :) \r\n"); + }else{ + pc.printf("Test spi KO :( \r\n"); + } + + - //************************ - // reset leds - //************************ - led1=0; - led2=0; - led3=0; + //************************************************ + //reset & init CIS001 + //************************************************ + pc.printf("**********************************\r\n"); + pc.printf("reseting image sensor..."); - //************************ - //init CIS001 - //************************ - TASK_INIT(); + TASK_INIT_SENSOR(); + + pc.printf("done\r\n"); - //************************ + //************************************************ // Ethernet & socket stuff - //************************ + //************************************************ + pc.printf("**********************************\r\n"); pc.printf("Connecting Ethernet cable....\r\n"); eth.connect(); SocketAddress sockaddr; @@ -401,13 +605,11 @@ const char* ip = eth.get_ip_address(); pc.printf("MAC Address is %s\r\n", mac ? mac : "No Mac"); pc.printf("IP address is: %s\r\n", ip ? ip : "No IP"); - pc.printf("*****************\r\n"); - pc.printf("Nucleo CPU SystemCoreClock is %d MHz\r\n", SystemCoreClock/1000000); - pc.printf("*****************\r\n"); + pc.printf("**********************************\r\n"); - //************************ + //************************************************ //open a new socket for printing information & debug - //************************ + //************************************************ status=cs.open(ð); if(status != 0){ pc.printf("error open com interface\r\n"); @@ -415,34 +617,21 @@ return 1; } else{ - pc.printf("com interface open\r\n"); + pc.printf("comunication socket open"); } status=cs.connect(ServerIP, portnumber_com); if(status !=0){ - pc.printf("error open com socket\r\n"); + pc.printf("\r\nerror open com socket\r\n"); cs.close(); return 1; }else{ - pc.printf("socket com open\r\n"); + pc.printf(" and connected\r\n"); } - // send 10x test2 to the pc - //sprintf(commandbuffer,"%64s","test2"); - //pc.printf("[%s]_%d\r\n",commandbuffer,strlen(commandbuffer)); - //byte_sent=0; - //for(i=0; i<10;i++){ - // byte_sent+=cs.send(commandbuffer, strlen(commandbuffer)); - //} - //sprintf(commandbuffer,"%64s","******************\nHello from Nucleo :)\n******************\n"); - //cs.send(commandbuffer, strlen(commandbuffer)); - - - - - //************************ + //************************************************ //open a new socket for data and command - //************************ + //************************************************ status=socket.open(ð); if(status != 0){ //myprint("*error open interface\r\n"); @@ -450,58 +639,96 @@ socket.close(); return 1; }else{ - pc.printf("interface open\r\n"); + pc.printf("data socket open "); } status=socket.connect(ServerIP, portnumber); if(status !=0){ - pc.printf("failed to connect to server\n\r"); + pc.printf("\r\nfailed to connect to server\n\r"); socket.close(); return 1; }else{ - pc.printf("socket open\r\n"); + pc.printf(" and connected\r\n"); } + //************************************************ + // set socking as non blocking and set timer. + // allows to do something else than waiting for messages + //************************************************ + socket.set_blocking(false); // non blocking + socket.set_timeout(1); // Timeout after (1)ms + pc.printf("**********************************\r\n"); - //socket.set_blocking(false); // non blocking - //socket.set_timeout(1); // Timeout after (10)ms - - - - //************************ + //************************************************ // Infinite loop - //************************ + //************************************************ pc.printf("main loop\r\n"); while (1){ + led2= !led2; loopcount++; - - //************************ + //************************************************ + // check if DCMI git an error + //************************************************ + if ((HAL_DCMI_ErrorCallback_value != 0) || (HAL_DCMI_IRQHandler_value != 0) || (DMA1_Stream0_IRQHandler_value==1)){ + //reset flags + HAL_DCMI_ErrorCallback_value=0; + HAL_DCMI_IRQHandler_value=0; + DMA1_Stream0_IRQHandler_value=0; + + + // deals with the error + print_DCMI_state_code(HAL_DCMI_GetState(&hdcmi)); + print_DCMI_error_code(HAL_DCMI_GetError(&hdcmi)); + pc.printf(" %i line %i frame\r\n",line_read,frame_read); + pc.printf("%i XferCount\r\n",hdcmi.XferCount); + pc.printf("%i XferSize\r\n",hdcmi.XferSize); + pc.printf("%i XferTransferNumber\r\n",hdcmi.XferTransferNumber); + pc.printf("%x pBuffPtr\r\n",hdcmi.pBuffPtr); + pc.printf("%i ErrorCode\r\n",hdcmi.ErrorCode); + } + + //************************************************ + // check if there is a frame ready to be sent + //************************************************ + if(line_read != 0){ + pc.printf("%i line read\r\n",line_read); + } + if(frame_ready_to_send==1){ + frame_ready_to_send=0; + pc.printf("ready to send frame: %i \r\n",line_read); + line_read=line_read; + send_frame_ethernet_nohandshake_while(); + + } + //************************************************ // blink led every 1024 loop in the main loop - //************************ + //************************************************ if(loopcount==1024){ // more or less evey second led1=!led1; loopcount=0; } - //************************************************ - // do soemthing when button is pressed + // do soemthing when button is pressed (pressed = active low) //************************************************ - if(button_capture==1 && button_pushed==0){ + if(button_capture==0 && button_pushed==0){ pc.printf("bc\n\r"); button_pushed=1; // do something here + CAPTURE=1; + wait_us(500); + CAPTURE=0; - }else if(button_capture==0 && button_pushed==1){ + }else if(button_capture==1 && button_pushed==1){ button_pushed=0; } //************************************************ - // listening for message (non bloacking) + // check if we receiveid a message (non bloacking, timeout=1ms) //************************************************ rcount = socket.recv(&rbuffer, sizeof rbuffer); if(rcount>0){ @@ -524,7 +751,7 @@ TASK_SPI_WRITE(add,data); sprintf(commandbuffertemp, "done writing %d at %d", data, add); - sprintf(commandbuffer,"%64s",commandbuffertemp); + sprintf(commandbuffer,OUT_MSG_LEN,commandbuffertemp); byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent); @@ -535,38 +762,50 @@ readvalue = TASK_SPI_READ(add); sprintf(commandbuffertemp, "%d/%d", readvalue,add); - sprintf(commandbuffer,"%64s",commandbuffertemp); + sprintf(commandbuffer,OUT_MSG_LEN,commandbuffertemp); byte_sent=socket.send(commandbuffer,strlen(commandbuffer)); //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent); sprintf(commandbuffertemp, "done reading %d at %d", readvalue, add); - sprintf(commandbuffer,"%64s",commandbuffertemp); + sprintf(commandbuffer,OUT_MSG_LEN,commandbuffertemp); byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent); }else if (strcmp (pch,"capture")==0 ||strcmp (pch,"CAPTURE")==0){ + // check size of image to be received pch = strtok (NULL, " "); pc.printf("[%s]\n\r",pch); - imSize=atoi(pch); + // PAS OP ! + //imSize=atoi(pch); + imSize=frame_bsize_10b; sprintf(commandbuffertemp, "trying to capture image of %d bytes...", imSize); - sprintf(commandbuffer,"%64s",commandbuffertemp); - //byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); + sprintf(commandbuffer,OUT_MSG_LEN,commandbuffertemp); + byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); - start_capture_10b(); + //start DCMI + start_capture(); + //start capture + wait_us(100); + CAPTURE=1; + wait_us(100); + CAPTURE=0; + wait_us(100); + + // if we want to output a dum frame if(DEBUG==1){ format_frame(imSize); byte_sent=send_frame_ethernet_nohandshake_while(); - sprintf(commandbuffertemp, "sent image of %d bytes/%d bytes", byte_sent,imSize); - sprintf(commandbuffer,"%64s",commandbuffertemp); + //sprintf(commandbuffertemp, "sent image of %d bytes/%d bytes", byte_sent,imSize); + //sprintf(commandbuffer,OUT_MSG_LEN,commandbuffertemp); //byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent); } }else if (strcmp (pch,"reset")==0 ||strcmp (pch,"RESET")==0){ - TASK_RSTN(); + TASK_RSTN_SENSOR(); sprintf(commandbuffertemp, "done reseting chip"); - sprintf(commandbuffer,"%64s",commandbuffertemp); + sprintf(commandbuffer,OUT_MSG_LEN,commandbuffertemp); byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent); @@ -578,23 +817,23 @@ }else{ sprintf(commandbuffertemp, "test spi KO"); } - sprintf(commandbuffer,"%64s",commandbuffertemp); + sprintf(commandbuffer,OUT_MSG_LEN,commandbuffertemp); byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); }else if (strcmp (pch,"exit")==0 ||strcmp (pch,"EXIT")==0){ - sprintf(commandbuffer, "%64s","close com and data sockets"); + sprintf(commandbuffer, OUT_MSG_LEN,"close com and data sockets"); byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent); status=socket.close(); status=cs.close(); }else{ - sprintf(commandbuffer, "%64s","command not recoginzed"); + sprintf(commandbuffer, OUT_MSG_LEN,"command not recoginzed"); byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent); } } else{ //tok is null - sprintf(commandbuffer, "%64s","empty tok"); + sprintf(commandbuffer, OUT_MSG_LEN,"empty tok"); byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); //pc.printf("[%s]_-_%d\n\r",commandbuffer,byte_sent); } @@ -622,29 +861,26 @@ byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); pc.printf("[%s]%d\n\r",commandbuffer,byte_sent); + }else if (strcmp (host_cmd,"pix")==0 || strcmp (host_cmd,"PIX")==0){ + sprintf(commandbuffer, "line : %i\n\r frame: %i",line_read,frame_read ); + byte_sent=cs.send(commandbuffer,strlen(commandbuffer)); + pc.printf("[%s]%d\n\r",commandbuffer,byte_sent); + + }else if (strcmp (host_cmd,"print")==0 || strcmp (host_cmd,"PRINT")==0){ + print_start_frame(); + }else{ + pc.printf("command not reconginzed\n\r"); } } - } //end non blocking timed-out - - - } //end while(1) loop - } // end main - - - - - - - /*********************************************************************************************** * * configuration function @@ -662,11 +898,9 @@ hdcmi.Instance = DCMI; hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; - hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_RISING; - //hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING; - //the data is not valid in the parallel interface, when VSYNC or HSYNC is at that level (high or low) - hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW; - hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW; + hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING; + hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_HIGH; + hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_HIGH; hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME; hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; @@ -677,17 +911,15 @@ hdcmi.Init.LineSelectStart = DCMI_OELS_ODD; if (HAL_DCMI_Init(&hdcmi) != HAL_OK) - { + { Error_Handler(); - } + } + /* USER CODE BEGIN DCMI_Init 2 */ //check status - /*HAL_DCMI_StateTypeDef status; - status=HAL_DCMI_GetState(&hdcmi); - if(status != HAL_OK){ - pc.printf("DCMI_init: %i\n\r",status); - }*/ + print_DCMI_state_code(HAL_DCMI_GetState(&hdcmi)); + /* USER CODE END DCMI_Init 2 */ } @@ -700,32 +932,40 @@ static void MX_DCMI_Init_10b(void) { + /* in CIS doc: + PCLK: pixel clock. Values of the pixels are changed on posedge of this clock and must be sampled on the negedge. + VSYNC: This signal goes up at the beginning of the frame, stays up during all transmission and goes down at the end of the frame. + HSYNC: This signal goes up at the beginning of a row of pixel and goes down at the end of the row. + */ + + 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_10B; - hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE; - hdcmi.Init.ByteSelectMode = DCMI_BSM_ALL; - hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD; - hdcmi.Init.LineSelectMode = DCMI_LSM_ALL; - hdcmi.Init.LineSelectStart = DCMI_OELS_ODD; + hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; + hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING; // Values of the pixels are changed on posedge of this clock and must be sampled on the negedge. + hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_HIGH; // Vertical synchronization active High (active low in mdcam & camel) + hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_HIGH; // Horizontal synchronization active High (active low in mdcam & camel) + + hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME; + hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_10B; + hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE; + hdcmi.Init.ByteSelectMode = DCMI_BSM_ALL; + hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD; + hdcmi.Init.LineSelectMode = DCMI_LSM_ALL; + hdcmi.Init.LineSelectStart = DCMI_OELS_ODD; if (HAL_DCMI_Init(&hdcmi) != HAL_OK) { Error_Handler(); } - - /* USER CODE BEGIN DCMI_Init 2 */ + /* USER CODE BEGIN DCMI_Init 2 */ //check status - /*HAL_DCMI_StateTypeDef status; - status=HAL_DCMI_GetState(&hdcmi); - if(status != HAL_OK){ - pc.printf("DCMI_init: %i\n\r",status); - }*/ + pc.printf("%i XferCount\r\n",hdcmi.XferCount); + pc.printf("%i XferSize\r\n",hdcmi.XferSize); + pc.printf("%i XferTransferNumber\r\n",hdcmi.XferTransferNumber); + pc.printf("%i pBuffPtr\r\n",hdcmi.pBuffPtr); + pc.printf("%i ErrorCode\r\n",hdcmi.ErrorCode); + print_DCMI_state_code(HAL_DCMI_GetState(&hdcmi)); /* USER CODE END DCMI_Init 2 */ } @@ -733,7 +973,6 @@ - /** * @brief Enable DMA controller clock * @param None @@ -741,14 +980,51 @@ */ static void MX_DMA_Init(void) { - - /* DMA controller clock enable */ - __HAL_RCC_DMA1_CLK_ENABLE(); + + /* DMA controller clock enable */ + __HAL_RCC_DMA1_CLK_ENABLE(); + __HAL_RCC_DMA2_CLK_ENABLE(); + + if(TEST_DMA==1){ + /* Configure DMA request hd_m2m_dma on DMA2_Stream1 */ + hd_m2m_dma.Init.Request = DMA_REQUEST_MEM2MEM; + hd_m2m_dma.Init.Direction = DMA_MEMORY_TO_MEMORY; + hd_m2m_dma.Init.PeriphInc = DMA_PINC_ENABLE; + hd_m2m_dma.Init.MemInc = DMA_MINC_ENABLE; + hd_m2m_dma.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; + hd_m2m_dma.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; + hd_m2m_dma.Init.Mode = DMA_NORMAL; + hd_m2m_dma.Init.Priority = DMA_PRIORITY_HIGH; + hd_m2m_dma.Init.FIFOMode = DMA_FIFOMODE_ENABLE; + hd_m2m_dma.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; + hd_m2m_dma.Init.MemBurst = DMA_MBURST_INC4; + hd_m2m_dma.Init.PeriphBurst = DMA_MBURST_INC4; + hd_m2m_dma.Instance = DMA2_Stream1; + if (HAL_DMA_Init(&hd_m2m_dma) != HAL_OK) { + Error_Handler( ); + } + + //thom : register callback + HAL_DMA_RegisterCallback (&hd_m2m_dma,HAL_DMA_XFER_CPLT_CB_ID, HAL_DMA_XferCpltCallback); + HAL_DMA_RegisterCallback (&hd_m2m_dma,HAL_DMA_XFER_ERROR_CB_ID, HAL_DMA_XferErrorCallback); + } - /* DMA interrupt init */ - /* DMA1_Stream0_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn); + + /* DMA interrupt init */ + + //DCMI + /* DMA1_Stream0_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0x00, 0); + HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn); + + + if(TEST_DMA==1){ + //MEM2MEM DMA + /* NVIC configuration for DMA transfer complete interrupt*/ + HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0x0F, 0); + HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn); + } + } @@ -776,7 +1052,6 @@ - /** * @brief This function is executed in case of error occurrence. * @retval None
--- a/main.h Wed Jan 06 13:35:17 2021 +0000 +++ b/main.h Wed Feb 10 16:38:32 2021 +0000 @@ -45,9 +45,21 @@ /* USER CODE BEGIN EC */ const int frame_bsize_8b =640*480*1; //640*480 pixels de 1 byte +const int frame_bsize_QVGA_8b =320*240*1; //320*240 pixels de 1 byte const int frame_bsize_QQVGA_8b =160*120*1; //160*120 pixels de 1 byte -const int frame_bsize_10b =640*480*2; //640*480 pixels de 2 byte -const int frame_bsize_QQVGA_10b =160*120*2; //160*120 pixels de 2 byte +const int frame_bsize_10b =640*240*2; //640*240 pixels de 2 bytes +const int frame_bsize_QVGA_10b =320*240*2; //320*240 pixels de 2 bytes +const int frame_bsize_QQVGA_10b =160*120*2; //160*120 pixels de 2 bytes + +// same value but in word size +const int frame_wsize_8b =frame_bsize_8b/4; //640*480 pixels de 1 byte /4 pour donner la tailler en word +const int frame_wsize_QVGA_8b =frame_bsize_QVGA_8b/4; //320*240 pixels de 1 byte /4 pour donner la tailler en word +const int frame_wsize_QQVGA_8b =frame_bsize_QQVGA_8b/4; //160*120 pixels de 1 byte /4 pour donner la tailler en word +const int frame_wsize_10b =frame_bsize_10b/4; //640*240 pixels de 2 bytes /4 pour donner la tailler en word +const int frame_wsize_QVGA_10b =frame_bsize_QVGA_10b/4; //320*240 pixels de 2 bytes /4 pour donner la tailler en word +const int frame_wsize_QQVGA_10b =frame_bsize_QQVGA_10b/4; //160*120 pixels de 2 bytes /4 pour donner la tailler en word + + /* USER CODE END EC */ @@ -84,6 +96,24 @@ void stop_capture(void); +// IRQ handler for DMA/MDMA +//void HAL_DMA_IRQHandler(DMA_HandleTypeDef* hdma); +void DMA2_Stream1_IRQHandler(void); +//void DMA1_Stream0_IRQHandler(void); +//void DMA1_Stream1_IRQHandler(void); +void HAL_DMA_XferErrorCallback (DMA_HandleTypeDef * hddma); +void HAL_DMA_XferCpltCallback (DMA_HandleTypeDef * hddma); + +// IRQ and callback handler for DCMI +void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi); +void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi); +void HAL_DCMI_LineEventCallback (DCMI_HandleTypeDef *hdcmi); +void HAL_DCMI_ErrorCallback (DCMI_HandleTypeDef *hdcmi); +//void HAL_DCMI_IRQHandler (DCMI_HandleTypeDef * hdcmi); + + + + /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/
--- a/register_address.h Wed Jan 06 13:35:17 2021 +0000 +++ b/register_address.h Wed Feb 10 16:38:32 2021 +0000 @@ -1,6 +1,8 @@ -static char const test_add =254; +static char const test_add =126; + +//TO BE CHANGED static char const analog_gain_add =0x02; static char const mode_add =0x03;
--- a/stm32h7xx_hal_conf.h Wed Jan 06 13:35:17 2021 +0000 +++ b/stm32h7xx_hal_conf.h Wed Feb 10 16:38:32 2021 +0000 @@ -43,7 +43,7 @@ /* #define HAL_DAC_MODULE_ENABLED */ #define HAL_DCMI_MODULE_ENABLED #define HAL_DMA2D_MODULE_ENABLED -/* #define HAL_ETH_MODULE_ENABLED */ +#define HAL_ETH_MODULE_ENABLED */ /* #define HAL_NAND_MODULE_ENABLED */ /* #define HAL_NOR_MODULE_ENABLED */ /* #define HAL_OTFDEC_MODULE_ENABLED */
--- a/stm32h7xx_hal_msp.cpp Wed Jan 06 13:35:17 2021 +0000 +++ b/stm32h7xx_hal_msp.cpp Wed Feb 10 16:38:32 2021 +0000 @@ -39,6 +39,26 @@ { __HAL_RCC_SYSCFG_CLK_ENABLE(); + + HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2); + //HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); + + // System interrupt init + // MemoryManagement_IRQn interrupt configuration + HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0); + // BusFault_IRQn interrupt configuration + HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0); + // UsageFault_IRQn interrupt configuration + HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0); + // SVCall_IRQn interrupt configuration + HAL_NVIC_SetPriority(SVCall_IRQn, 0, 0); + // DebugMonitor_IRQn interrupt configuration + HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0); + // PendSV_IRQn interrupt configuration + HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0); + // SysTick_IRQn interrupt configuration + HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); + } @@ -127,27 +147,36 @@ /* DCMI DMA Init */ /* DCMI_PSSI Init */ - hdma_dcmi.Instance = DMA1_Stream0; - //hdma_dcmi.Init.Request = DMA_REQUEST_DCMI_PSSI; - 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_WORD; - hdma_dcmi.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; - hdma_dcmi.Init.Mode = DMA_CIRCULAR; - hdma_dcmi.Init.Priority = DMA_PRIORITY_HIGH; - hdma_dcmi.Init.FIFOMode = DMA_FIFOMODE_ENABLE; - hdma_dcmi.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; - hdma_dcmi.Init.MemBurst = DMA_MBURST_INC4; - hdma_dcmi.Init.PeriphBurst = DMA_PBURST_SINGLE; + hdma_dcmi.Instance = DMA1_Stream0; + hdma_dcmi.Init.Request = DMA_REQUEST_DCMI; + 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_WORD; + hdma_dcmi.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; + hdma_dcmi.Init.Mode = DMA_CIRCULAR; + hdma_dcmi.Init.Priority = DMA_PRIORITY_HIGH; + hdma_dcmi.Init.FIFOMode = DMA_FIFOMODE_ENABLE; + hdma_dcmi.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; + hdma_dcmi.Init.MemBurst = DMA_MBURST_INC4; + hdma_dcmi.Init.PeriphBurst = DMA_PBURST_SINGLE; if (HAL_DMA_Init(&hdma_dcmi) != HAL_OK) { Error_Handler(); } + __HAL_LINKDMA(hdcmi,DMA_Handle,hdma_dcmi); + + /* DCMI interrupt Init */ + //HAL_NVIC_SetPriority(DCMI_IRQn, 0x0F, 0); // 0 is highest priority + //HAL_NVIC_EnableIRQ(DCMI_IRQn); + + HAL_NVIC_SetPriority(DCMI_IRQn, 0x00, 0); + HAL_NVIC_EnableIRQ(DCMI_IRQn); /* USER CODE BEGIN DCMI_MspInit 1 */ /* USER CODE END DCMI_MspInit 1 */ + } }