Need help with HAL, DCMI and OV7670

Development of new Cores using the STMCubeMX and HAL
flodejr
Posts: 29
Joined: Sat Sep 16, 2017 2:46 pm

Need help with HAL, DCMI and OV7670

Post by flodejr » Fri Oct 06, 2017 4:22 am

Hi,

I have a setup with a bare metal stm32F407VGT6 board and it is connected to the ov7670 pins via DCMI and I2C and a st7735 display via SPI. When i debugged by code, I could see data being captured and there are some noisy pixels on the display. So I tested by closing the cap on the ov7670 and examined the buffer. The capture buffer shows 0x7fff throughout, even though my selected output format is RGB565.

I have another setup on using a STm32F103 blue pill with ov7670 and st7735 as well and it is using the same settings for the ov7670 and st7735 but it is using arduino code from indrekluuk and it is working perfectly. The difference between the two is that 1) stm32F103 does not have dcmi, so it is using byte transfer from the ov7670 to the st7735 directly.

I have been trying all sorts of ways but it seems that the dcmi will always give me 0x7FFF which is near white when it should be black when dcmi is used.

I am running out of ideas what could be wrong for the dcmi case. I can't seem to get any valid captures.

User avatar
RogerClark
Posts: 7171
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Need help with HAL, DCMI and OV7670

Post by RogerClark » Fri Oct 06, 2017 7:22 am

There is a thread about using the OV7670 to the ILI9341 SPI based LCD display.

SteveStrong has done a lot of work on this to improve the code from indrekluuk so that it uses DMA to read the data from the camera (on the F103C8)

Unfortunatly Steve's latest code seems to only work on his hardware setup and it only work intermittently for me.

I'm currently using a modified version of some old code posted by Steve as a ZIP file into that thread, and it seems to work OK for me, but I know some other people eg. @kozcap still have problems even with the code that works for me

I've also written some code to save the contents of the ILI9341 to a SD card (using a readPixels function written by SteveStrong)
But I think I"m the only person who currently seems to be using that code

I've also written some code to read the LCD and send a frame via serial to the PC where I also wrote a Python based viewing program
(I posted all the code for this to the forum as well, so if you dig around you'll find it) ;-)

stevestrong
Posts: 1748
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Need help with HAL, DCMI and OV7670

Post by stevestrong » Fri Oct 06, 2017 9:17 am

If you overall get 0x7FFF, it looks like data bit 15 is not correctly wired (or somehow shorten to gnd), check it again.
Alternatively you could first check if that bit toggles when configured as GPIO output, this would prove that the wiring is ok.

flodejr
Posts: 29
Joined: Sat Sep 16, 2017 2:46 pm

Re: Need help with HAL, DCMI and OV7670

Post by flodejr » Fri Oct 06, 2017 10:19 am

stevestrong wrote:
Fri Oct 06, 2017 9:17 am
If you overall get 0x7FFF, it looks like data bit 15 is not correctly wired (or somehow shorten to gnd), check it again.
Alternatively you could first check if that bit toggles when configured as GPIO output, this would prove that the wiring is ok.
The physical port is only 8 bits wide, the DCMI interface will pack two 16-bit RGB565 words into a 32-bit word and DMA to a memory buffer address. The problem is why is it 0x7FFF, RGB565 for black should be zero, why is it giving a white color? Given the init codes for the camera are the same as those in the bluepill setup, the camera "Should" produce the correct info.

For the initialisation itself, i have written the code such that after sending the code to the camera via I2C, I will read the same register to verify that the values match. So I don't think it is a initialisation code problem. So the only difference is sampling the values from the 8 bit port based on the PIXCLK, HSYNC and VSYNC and then pack them into FIFO and send it to buffer address. But I don't know what happened in between that the values got changed or somewhat.

stevestrong
Posts: 1748
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Need help with HAL, DCMI and OV7670

Post by stevestrong » Fri Oct 06, 2017 11:19 am

Do you have code to share?
How do you check the value? Read from the buffer? Maybe you read an int32 value from a buffer of uint32?
Although zero should be zero anyway...

Or it is because of DCMI settings.
Do you use Embedded data synchronization mode?
Or wrong VSYNC/HSYNC polarity settings?

flodejr
Posts: 29
Joined: Sat Sep 16, 2017 2:46 pm

Re: Need help with HAL, DCMI and OV7670

Post by flodejr » Fri Oct 06, 2017 11:44 am

stevestrong wrote:
Fri Oct 06, 2017 11:19 am
Do you have code to share?
How do you check the value? Read from the buffer? Maybe you read an int32 value from a buffer of uint32?
Although zero should be zero anyway...
This is my current work in progress code. Very messy with a lot of various init sets found on the net. The base code has been generated using stm32Cubemx and the ioc file is included. I plan to clean it up and optimize it after I get it working, so... here it is.
Attachments
stm32F4_ov7670_st7735.zip
(110.43 KiB) Downloaded 19 times

stevestrong
Posts: 1748
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Need help with HAL, DCMI and OV7670

Post by stevestrong » Fri Oct 06, 2017 11:54 am

Have you checked the DCMI interrupts, whether overflow or other error occurred?

The first thing which you should do is to declare the global variables used in ISRs as "volatile":

Code: Select all

volatile uint8_t frameComplete = 0;
volatile uint16_t linecount = 0;
Otherwise you get unexpected behavior (unexplainable bugs).

flodejr
Posts: 29
Joined: Sat Sep 16, 2017 2:46 pm

Re: Need help with HAL, DCMI and OV7670

Post by flodejr » Sat Oct 07, 2017 2:41 pm

stevestrong wrote:
Fri Oct 06, 2017 11:54 am
Have you checked the DCMI interrupts, whether overflow or other error occurred?

The first thing which you should do is to declare the global variables used in ISRs as "volatile":

Code: Select all

volatile uint8_t frameComplete = 0;
volatile uint16_t linecount = 0;
Otherwise you get unexpected behavior (unexplainable bugs).
I have tried checking the interrupts but the interrupts are not behaving like how it is mentioned both in the HAL document and Device Specs. I am about to give up on this F4 board, seems that the dcmi device is not working properly. I will try to throw out the raw data via serial device since I can't seem to get the usb connect to function as a slave as well.

Anyway, what is important to me is to capture the image into internal ram, because I am trying to do some recognition on board, dcmi is a must to spare the cpu power for computation.

User avatar
RogerClark
Posts: 7171
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Need help with HAL, DCMI and OV7670

Post by RogerClark » Sat Oct 07, 2017 9:27 pm

Steves DMA code allows the MCU to read the parallel data and store in memory, but on the F103 there is only space for a few lines.
Unfortunately AFIK DMA on the F4 is a bit different from the F1, so I suspect Steve's 103 code would not run on the F4 without modification

flodejr
Posts: 29
Joined: Sat Sep 16, 2017 2:46 pm

Re: Need help with HAL, DCMI and OV7670

Post by flodejr » Sun Oct 08, 2017 4:16 am

Just found something new and recent and I am getting some progress. But the image colors are still wrong.

https://www.youtube.com/watch?v=vokasVZTJLM&t=948s
https://github.com/take-iwiw/DigitalCamera_STM32

Post Reply