cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407, DCMI (using DMA) data transfer to External SRAM Problem

miliuhin9
Associate
Posted on December 12, 2016 at 16:54

Hello, 

Small Introduction:

Generally speaking, I want to get data from OV9655 camera using DCMI interface with DMA and store the incoming data into External SRAM, afterwards I want to read the stored Data from external SRAM, convert it to an .bmp format and send the image to SD Card, no rocket science.

Problem Description

(I use HAL library and custom PCB board)

:

After the configuration of DCMI, FSMC,DMA,SDIO with the help of CubeMx (see attachments for configuration code), I was able to receive an image of small size (160x120) from the OV9655 camera  and store it to SD card (2gb), but this works correctly only if i use STM32F407ZGTx internal memory ( uint16_t

internalMEM_Buff [160 x 120] ) .

The problem appears when i try to send the incoming data from DCMI DMA to external SRAM ( S62WV5128BLL-55HLI ). In debugging mode i receive an interrupt from DMA and i'm able to jump into function DMA2_Stream7_IRQHandler(), but afterwards, when i try to read what was stored into external SRAM, there is just garbage (random numbers/data), so basically nothing gets written to external SRAM.

So below i described my problem approach. 

My Problem

Approach (No solution yet) 

Therefore here are the steps I followed to see where exactly is the problem:

1. First thing, I used the internal memory of STM32F407ZGTx chip to receive a small resolution image 160x120 from the camera and i used the following function:

-----------------------------------------------------------------------------------------------------------------------------------------------

HAL_DCMI_Start_DMA(&hdcmi, (uint32_t) DCMI_MODE_SNAPSHOT, (uint32_t) internalMEM_Buff, 19200);

-----------------------------------------------------------------------------------------------------------------------------------------------

* internalMEM_Buff - represents an unsigned int array of length 19200 (160 x 120).

I receive the correct data/image from the camera, this leads me to the thought that DCMI interface and Camera (OV9655) are configured correctly.  

2. The second step was to test if in general I can write/read something to/from external SRAM, therefore I did a simple function that writes to the SRAM a specific data pattern i can recognize. I used the following functions for test purposes:

---------------------------------------------------------------------------------------------------------------

HAL_SRAM_Write_8b(&hsram2, (uint32_t*)0x60000000, (uint8_t*) writeTestPattern, (uint32_t) sizeof(writeTestPattern)

HAL_SRAM_Read_8b(&hsram2, (uint32_t*)0x60000000, (uint8_t*) readTestPattern, (uint32_t) sizeof(readTestPattern))

-------------------------------------------------------------------------------------------------------------------------------------------

When I’m reading the data from “readTestPattern�? I’m getting the correct pattern. I even did an data overflow to be sure that I’m writing and reading to/from my external SRAM. So, therefore this leads me to the conclusion that SRAM is also configured correctly.

 3. 

Therefore my guess is that the problem is related to DCMI DMA and the address I give to the following function when I want data to be stored into external SRAM:

-----------------------------------------------------------------------------------------------------------------------------------------------

HAL_DCMI_Start_DMA(&hdcmi, (uint32_t) DCMI_MODE_SNAPSHOT, (uint32_t) 0x60000000, 19200)

-----------------------------------------------------------------------------------------------------------------------------------------------

*But here is the tricky part, I know for sure that the address for FSMC NOR FLASH/SRAM BANK1 has the following address: 0x60000000

So where is my mistake? Can you please give me some ideas / feedback on this.

(Maybe I don’t understand well how HAL works with external SRAM and DMA)

P.s I know people asked a lot of times similar type of questions, but i didn't see somebody using HAL library for these tasks and having this type of problem.

Thank you in advance.
5 REPLIES 5
Posted on December 13, 2016 at 01:41

Isn't there a transfer error flag set for the DMA channel, when the DMA ISR is fired?

JW

miliuhin9
Associate
Posted on December 13, 2016 at 10:32

Hi Jan, 

Yes there is! I don't know how i missed that... 

So basically i end up in  ' DCMI_DMAError()'  function  with ' XferErrorCallback = 0x080002DF. '

Do you know what can be the cause? Is it because i set the address to External SRAM wrong? 

DCMI DMA  Configuration: 

Stream :                           DMA2 Stream 7

Direction:                          Peripheral to Memory

Priority:                             High

Mode :                              Circular

Fifo :                                 Enabled

Threshold:                        One Quarter Full (but i tried all 4 variations) 

Data Width Peripheral:     Word

Data Width Memory:        Byte

Burst Size:                       Single
Posted on December 13, 2016 at 15:42

Do you know what can be the cause?

No. I don't Cube.

Data Width Memory:        Byte

This is certainly a bad idea. Use word. FMC is able to split a single word write across AHB into two halfword writes on the external bus.

Avner Gidron
Associate II
Posted on June 17, 2017 at 15:43

Hi,

I ran across the exact same problem on the STM32F769 Eval. Did you discovered the error you had? I am stuck on it for a few dayes now and I am running out of places to look...

Avner

Posted on June 18, 2017 at 11:15

Start your own thread, stating clearly what exactly are the symptoms and how do they fall short of expectations, posting relevant pieces of code, ideally a minimal but complete compilable example exhibiting the symptoms.

JW