cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 OV2640 DCMI

koksoybedirhan
Associate III

Hi,

I would like to ask a question about STM32 OV2640 usage. My task is; take an output data from OV2640 and send to Computer via USART. When I communicate with UART, I took an output which shown in the figure. I did not is it true or wrong output but after output I'll try to convert data to image with python matplotlib library. 

image.png

/* USER CODE BEGIN Header */

/**

******************************************************************************

* @file : main.c

* @brief : Main program body

******************************************************************************

* @attention

*

* Copyright (c) 2023 STMicroelectronics.

* All rights reserved.

*

* This software is licensed under terms that can be found in the LICENSE file

* in the root directory of this software component.

* If no LICENSE file comes with this software, it is provided AS-IS.

*

******************************************************************************

*/

/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/

#include "main.h"

 

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

#include "ov2640.h"

/* USER CODE END Includes */

 

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

 

/* USER CODE END PTD */

 

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

 

#ifndef HSEM_ID_0

#define HSEM_ID_0 (0U) /* HW semaphore 0*/

#endif

 

/* USER CODE END PD */

 

/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */

 

/* USER CODE END PM */

 

/* Private variables ---------------------------------------------------------*/

 

DCMI_HandleTypeDef hdcmi;

DMA_HandleTypeDef hdma_dcmi;

 

I2C_HandleTypeDef hi2c1;

 

UART_HandleTypeDef huart3;

DMA_HandleTypeDef hdma_usart3_tx;

 

SRAM_HandleTypeDef hsram1;

 

/* USER CODE BEGIN PV */

 

/* USER CODE END PV */

 

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_DMA_Init(void);

static void MX_FMC_Init(void);

static void MX_DCMI_Init(void);

static void MX_I2C1_Init(void);

static void MX_USART3_UART_Init(void);

/* USER CODE BEGIN PFP */

 

/* USER CODE END PFP */

 

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

uint16_t* camData;

double camBuf = 320*240*3;

/* USER CODE END 0 */

 

/**

* @brief The application entry point.

* @retval int

*/

int main(void)

{

/* USER CODE BEGIN 1 */

 

/* USER CODE END 1 */

/* USER CODE BEGIN Boot_Mode_Sequence_0 */

int32_t timeout;

/* USER CODE END Boot_Mode_Sequence_0 */

 

/* USER CODE BEGIN Boot_Mode_Sequence_1 */

/* Wait until CPU2 boots and enters in stop mode or timeout*/

timeout = 0xFFFF;

while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0));

if ( timeout < 0 )

{

Error_Handler();

}

/* USER CODE END Boot_Mode_Sequence_1 */

/* MCU Configuration--------------------------------------------------------*/

 

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

 

/* USER CODE BEGIN Init */

 

/* USER CODE END Init */

 

/* Configure the system clock */

SystemClock_Config();

/* USER CODE BEGIN Boot_Mode_Sequence_2 */

/* When system initialization is finished, Cortex-M7 will release Cortex-M4 by means of

HSEM notification */

/*HW semaphore Clock enable*/

__HAL_RCC_HSEM_CLK_ENABLE();

/*Take HSEM */

HAL_HSEM_FastTake(HSEM_ID_0);

/*Release HSEM in order to notify the CPU2(CM4)*/

HAL_HSEM_Release(HSEM_ID_0,0);

/* wait until CPU2 wakes up from stop mode */

timeout = 0xFFFF;

while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) == RESET) && (timeout-- > 0));

if ( timeout < 0 )

{

Error_Handler();

}

/* USER CODE END Boot_Mode_Sequence_2 */

 

/* USER CODE BEGIN SysInit */

 

/* USER CODE END SysInit */

 

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_DMA_Init();

MX_FMC_Init();

MX_DCMI_Init();

MX_I2C1_Init();

MX_USART3_UART_Init();

/* USER CODE BEGIN 2 */

ov2640_Init(0x60, CAMERA_Monitor);

uint16_t* p_lcdData;

 

HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_CONTINUOUS, p_lcdData, camBuf);

HAL_UART_Transmit_DMA(&huart3, p_lcdData, camBuf);

 

/* USER CODE END 2 */

 

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

 

}

/* USER CODE END 3 */

}

1 ACCEPTED SOLUTION

Accepted Solutions
Johi
Senior III

You start DMA, but then you need to wait until is completed before starting send via UART.

Try to send "hello world" first via serial, and then go further to the more difficult stuff.

And indeed check serial settings, especially the number of parity bits because cube includes parity bits in the total bit count, so you might need to select 9 bits and not 8 to obtain 8 databits.

View solution in original post

11 REPLIES 11
KDJEM.1
ST Employee

Hello @koksoybedirhan ,

Which STM32 device are you using?

Could you please check the Baud Rate?

If you're just sending data over UART, you aren't going to see anything useful in the terminal. You would need to save that info and process it back into an image.

Do you have any issue after converting data to the image?

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi @KDJEM.1 ,

Firstly thank you to reply my question.

I am using STM32H745 Nucleo Board and it has STM32H745ZIT6 microprocessor.
I tried 115200 and 9600 baud rate but I got same result for both of them.
For the sending data, I just saving DCMI datas to DMA and after I send datas to computer via HAL_UART_Transmit_DMA. I don't converting before sending data and I think that's what you say for the mistake. 

Could you share links about converting DCMI data to image data in STM32?

 

Best Regards.

Johi
Senior III

You start DMA, but then you need to wait until is completed before starting send via UART.

Try to send "hello world" first via serial, and then go further to the more difficult stuff.

And indeed check serial settings, especially the number of parity bits because cube includes parity bits in the total bit count, so you might need to select 9 bits and not 8 to obtain 8 databits.

koksoybedirhan
Associate III

Hi @Johi ,

Thank you for your advice. I think firstly I have to learn more about DMA usage as you said. Also I'll try 9 bits for serial settings.

Best Regards.

Hi @KDJEM.1 ,

Could you share links about the DCMI to image converting?

Best Regards.

Hello @koksoybedirhan,

You can used HAL drivers to display image and/or to save image under USB disk.

Also, you can use the USB port to display capture data or video on your computer display.

For that, I recommend you to get inspired from available examples:

- DCMI_CaptureMode: This example descripts how to use the DCMI to interface with a camera module and continuously capture images to a Camera Frame Buffer located in external SDRAM. Each camera image is then copied to the LCD display frame buffer using the DMA2D in ARGB8888 format.

Camera_To_USBDisk: This application provides a short description of how to use the DCMI to interface with camera module and display in continuous mode the picture on LCD and to save a picture in USB device.

FP-AI-VISION1_V3.1.0\Projects\STM32H747I-DISCO\Applications\USB_Webcam in FP-AI-VISION1 package: This application explain how to display capture data or video on your computer display.

I advise you to take a look to AN5020 and precisely 6.DCMI configuration Section and 8.DCMI application examples section.

I hope this help you.

Thank you.

Kaouthar

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi @KDJEM.1 ,

Thank you for your recommendation and resources.

Best Regards.

Hey @koksoybedirhan 

How did you managed to run it?

Thank you in advance!

Best regards,

Nicola

Hi @nicola3 ,

For the camera, I followed this github repo: https://github.com/SimpleMethod/STM32-OV2640
But at the end, I didn't get the value. I guess because of the wiring problems.