Need help with HAL, DCMI and OV7670

Development of new Cores using the STMCubeMX and HAL
stevestrong
Posts: 1744
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Need help with HAL, DCMI and OV7670

Post by stevestrong » Sun Oct 08, 2017 8:53 am

My code for F1 does not use DCMI, and my SPI code for F4 is anyway not relevant here, because HAL-based software is used here (see second link).

If I find some time I may give a try to make a live camera app for F4, too, using our libmaple core.
flodejr wrote:
Sun Oct 08, 2017 4:16 am
But the image colors are still wrong.
I would suggest to contact the owner on github, since nobody here seems to be able to help you out with DCMI.

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

Re: Need help with HAL, DCMI and OV7670

Post by RogerClark » Sun Oct 08, 2017 9:18 pm

Looking at the ReadMe on github for that project, the specs arent that good considering its a F4 using the dedicated camera interface via DMA

Its only QVGA 320x240 and only manages 5 fps to SD.

About the only thing it can do that the F103C cant do is JPEG compression, and I suspect we may be able to do JPEG still image compression, if it could be done with an 8 line buffer.

But the F103C8 would not be able to do motion jpeg as that needs multiple complete frame buffers ( though I am not sure whether the F4 has enough RAM for true motion JPEG with frame differencing either.

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

Re: Need help with HAL, DCMI and OV7670

Post by flodejr » Mon Oct 09, 2017 8:34 am

stevestrong wrote:
Sun Oct 08, 2017 8:53 am
My code for F1 does not use DCMI, and my SPI code for F4 is anyway not relevant here, because HAL-based software is used here (see second link).

If I find some time I may give a try to make a live camera app for F4, too, using our libmaple core.
flodejr wrote:
Sun Oct 08, 2017 4:16 am
But the image colors are still wrong.
I would suggest to contact the owner on github, since nobody here seems to be able to help you out with DCMI.
Are you working on the F4 core, just some note about the DMA packing in F4, I am not sure of whether F1 behaves the same way. In the F4, the DMA if set to 16 bits(half word), it will trigger 2 transfers. the orders will be b1,b0 in first transfer, b3,b2 in second transfer. If the DMA is set to word, it will trigger one transfer and the byte order will be b3,b2,b1,b0 and this is giving me a major headache as the cubemx does not allow me to set halfword in non FIFO transfers and there is some note to say that non-FIFO halfword transfers are allowed but not guaranteed accuracy.

BTW, I have several versions of the specs on ov7670 and there are some discrepancy on the CLKRC setting. Some docs say

internal clock = External clock/ (2*(CLKRC+1),

but some docs say

Internal clock = External clock/(CLKRC+1)

I don't have a scope to verify. Are you able to comment on this?

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

Re: Need help with HAL, DCMI and OV7670

Post by RogerClark » Mon Oct 09, 2017 9:02 am

I think Steve found a trick to just transfer the upper byte of the 16 bit register using DMA.
However I don't know if the same thing works on the F4 and its not documented as being possible on the F1....

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

Re: Need help with HAL, DCMI and OV7670

Post by stevestrong » Mon Oct 09, 2017 11:44 am

Roger, the DMA on F4 is more complicated, there each channel has its own internal FIFO of 4*32 bits.

However, this FIFO can be switched off or on.
The DCMI data register should give the bytes in the right order because b1,b0 is stored on the lower addresses, so that if you configure the LCD DMA to send to SPI 16 bits in 16bit mode, it would send the data from the same buffer to SPI in the correct endianess and order: first (b1,b0) and then (b3,b2)

If non-FIFO in 16bit mode is critical for the DMA (I would anyway suggest you to try it out), then you should turn the FIFO on.

Btw, what exactly means
non-FIFO halfword transfers are allowed but not guaranteed accuracy.
What kind of "accuracy" is not guaranteed?

I could not read in F4 reference manual about any restriction on programing the transferred data width. This can be set to be 8, 16 or 32 bit without any problem. The memory pointer will then be incremented accordingly.
Which means you should be able to transfer the data from memory to SPI data register without any problem in non-FIFO (direct) mode, either in 8 or 16 bit mode as well (which is currently working in the SPI lib).

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

Re: Need help with HAL, DCMI and OV7670

Post by RogerClark » Mon Oct 09, 2017 8:07 pm

Thanks Steve...

Re: Direct camera to SPI

That takes some load from the processor, but SPI is much slower then that data rate possible from the camera, so I dont know what benefit it would be, unless the processor needs to do some unrelated activity.
e.g. If the data is going straight from the camera to the LCD, the processor cant do any image processing etc.

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

Re: Need help with HAL, DCMI and OV7670

Post by stevestrong » Tue Oct 10, 2017 9:15 am

The data cannot go from DCMI directly to SPI, because peripheral to peripheral mode is not supported by the DMA.
So an intermediate memory buffer is inevitable. And it makes sense, one could use double buffering so that DCMI->memory and memory->SPI transfers with DMA could work quasi in parallel.

Post Reply