cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 memory bandwidth issues with DCMI, FMC, ADC, parallel bus, DMA1, DMA2 / DCACHE issue

rob-bits
Associate II

I am developing a product which has an STM32H743 device. I am designing the firmware for the first PCBA prototype. The product receives 30fps video signal from an 720i analog video decoder through DCMI (every second bytes are stored, all lines, so 360x240 resolution frames are captured) to external SDRAM. The stm32 does an image conversion and sending the converted data from internal RAM to a second processing unit through parallel bus. The second processing unit displays the data. The parallel bus is a 16bit interface, with 10MHz clock (20Mbyte data rate with ~44% duty cycle – 44% reading, 56% idle). And in the during operation, the device captures two channel audio signals as well.

The ideal operation flow is the following:

  • DCMI interface uses DMA1 Stream0 (very high priority, fifo), dma in double buffer mode. DMA moves data from DCMI to FMC external SDRAM. It generates two interrupt signal, half transfer complete and full transfer complete. When full transfer completed the transfer is restarted. With 30FPS I am getting half transfer and full transfer signals, so this seems like working properly.
  • When half transfer completed flag is set, the CPU runs a conversion function lets call ycrycbToRGB16() which converts the ycrycb video format to rgb 16bit format. This function finishes before the full transfer signal are set (<15ms execution time)
  • When full transfer completed, and ycrycbToRGB16() executed which is true, then we give a signal to external processor. It can start reading out the converted data, through the parallel interface (bus enable high). The parallel interface is implemented, at the STM32 side, with a timer capture input and full utilization of GPIO port B. The TIM5 input capture, captures the parallel bus clock signal and triggers a dma transfer (DMA2 Stream0, TIM5_CH1, fifo) to copy data from internal SDRAM to GPIOB port. When all data is read, the external processor signalize this on a GPIO input and goes to idle.
  • ADC capture is running in the background on two channels. Slow channels are used, clock operates on 10MHz maximum, 48ksps,scan conversion mode, DMA circular mode (DMA2 Stream1, the DMA transfer cycle is ~15kHz), this data is also send concatenated with the video capture data.

The whole process must be in synchronization, if there is a pending something or too much calculation time, frames will be skipped and the ideal operation will be not kept.

And the issues that I observing:

  1. The ideal timing requirements are met only if D-CACHE is enabled. In this case everything executed properly the data acquisition runs smoothly without issue. However, the image data contains artifacts. And it is because the DMA2 copies the internal SDRAM content to GPIOB while the CPU still has data in D-CACHE and it did not store the data to internal SRAM, in fact it took approx.  60ms to update all the frame in sram. Here is an example image, with a dummy signal where the color bars changing colors at each vsync event. E.g. the red bar becomes pink and pink bar becomes red. It can be seen some pixel data remains at previous color but most of them are updated and was read out successfully with the parallel bus.
    robbits_0-1725041231489.png

     

  2. If I disable the D-CACHE, the performance drops too much, and the timing requirements of the ideal operation is not met. E.g. the calculation time of the ycrycbToRGB16() function increases from ~7ms to 20ms which is not acceptable. With D-Cache the algo finished sooner, but the data was not there in the internal sram. So either solution is not ok.
    Here is another test frame:
    robbits_1-1725041231491.png

     


    The image does not contain any artifact, but the capture rate dropped to 15FPS instead of 30FPS because of the slowing down to access to SDRAM.
  3. If I increase the clock rate of the parallel bus, from 10MHz to 20MHz the timings are “crashed”. It seems stm32 is missing clocks from the external controller and therefore the data transmission breaks. The clock signal looks like this on the proto (with 20MHz clock):
    robbits_2-1725041231496.png

     

All the parallel bus lines has a 120ohm series resistor now.

Some additional info:

  • The STM32 configured to 480MHz SYSCLK from a 16MHz HSE crystal
  • The FMC is configured to 240MHz FMC clock (SDRAM common clock 2HCLK – 120MHz, CAS latency 3 clock – 80MHz)
  • The TIM5 configured with no preclear and autoload of 2
  • each frame consists of ~320kB data, in double buffer mode it is 640kB data

I think I have some memory bandwidth issues. There must be some wait cycles when the CPU tries to write to internal SDRAM. Or when DCMI/DMA1 writes to external SDRAM and the TIM5 triggers data transfer with DMA2 to GPIO port happens in the same time causes latency.

I am thinking about the following options:

  1. Write code for MDMA or BDMA or DMAMUX or DMA2D controller for more advanced memory action. Especially considering a different domain rams+dma (D1, D2, D3)
  2. using mixed memory usage of D-CACHE + non cached sram. E.g. non cache for parallel bus data
  3. using d-cache but handling cases for sdram preparation before dma transfer e.g. clear/invalidate d-cache
  4. maximize the external SDRAM clock to 200MHz (as the SRAM maximum) and lower the SYSCLK
  5. using different memory layout e.g. smaller internal sram buffers for dcmi and writing data to external sdram with dma when the internal buffer is filled

Is there anything else to improve the acquisition? Do you see any issue with the concept of the ideal operation implementation?

 

11 REPLIES 11

Seems like the SCB_CleanDCache_by_Addr() solved the cache issue with the DMA buffer. However I am a bit confused with the MPU and ram configuration.

I am allocating a big array as:

 

 

 

#define FRAME_Y_BYTE_SIZE  (94800UL)
__attribute__((section(".my_buffer_section"))) uint8_t gSendBuffer[4][FRAME_Y_BYTE_SIZE];

 

 

 

So currently I am using 379 200 bytes here. And it can fit to a 512kB AXI SRAM.

 And I modified the .ld file. I have these MEMORY specification:

 

 

 

/* Specify the memory areas */
MEMORY
{
  RAM_EXEC (xrw)  : ORIGIN = 0x24000000, LENGTH = 512K
  DTCMRAM (xrw)   : ORIGIN = 0x20000000, LENGTH = 128K
  RAM_D2 (xrw)    : ORIGIN = 0x30000000, LENGTH = 288K
  RAM_D3 (xrw)    : ORIGIN = 0x38000000, LENGTH = 64K
  ITCMRAM (xrw)   : ORIGIN = 0x00000000, LENGTH = 64K
}

 

 

 

Basically, this is default. But what I modified, I moved all sections to the RAM_D2. E.g. isr_vector, program code, other data, rodata .. etc. And I defined a section for the gSendBuffer:

 

 

 

  /* Define the custom section */
  .my_buffer_section :
  {
    . = ALIGN(4);  /* Align to 4-byte boundary */
    KEEP(*(.my_buffer_section))
    . = ALIGN(4);  /* Align to 4-byte boundary */
  } > RAM_EXEC

 

 

 

So basically the RAM_EXEC is used only for the gSendBuffer.

Then I configured the MPU (as it is decribed in the section MPU setting DMA RAM buffer in the MPU usage in STM32 with ARM Cortex M7 ST document)::

 

 

 

void MPU_Config(void)
{
  MPU_Region_InitTypeDef MPU_InitStruct = {0};

  /* Disables the MPU */
  HAL_MPU_Disable();

  /** Initializes and configures the Region and the memory to be protected
  */
  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  MPU_InitStruct.BaseAddress = 0x2400000;
  MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
  MPU_InitStruct.SubRegionDisable = 0x0;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
  MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
  MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

  HAL_MPU_ConfigRegion(&MPU_InitStruct);
  /* Enables the MPU */
  HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

}

 

 

 

So here the full axi sdram is excluded from cache if I understand well. So considering these thing, I should not need the SCB_CleanDCache_by_Addr() funciton to clean the cache, because the gSendBuffer should be non-cached. But without the function I had isssues and with the funciton I did not. 

I guess I still has some configuration issue with MPU or loader.

In the linker map file I see this:

 

.my_buffer_section
                0x2400016c    0x5c940 load address 0x08018960
 .my_buffer_section
                0x2400016c    0x5c940 ./Core/Src/global.o
                0x2400016c                gSendBuffer
                0x2405caac                        . = ALIGN (0x4)

.bss            0x2405cab0     0xedac load address 0x080752a0
                0x2405cab0                        _sbss = .
                0x2405cab0                        __bss_start__ = _sbss

 

Do you see any potential issue with my configuration?

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

Update:

There is a typo in the MPU guarded baseaddress... I used 0x2400000 instead of 0x24000000. So missed a zero... Now it works as it intended. However, I got worst performance on image conversion, so I think I will disable MPU on this and use the SCB_CleanDCache_by_Addr() instead.

Seems like the issue is not related to the series resistor, but I replaced it to 10R. So here is the thing, I could manage to increase the parallel bus speed to 25MHz from 10Mhz, but it works only, if the audio capture is disabled. Without audio capture, the video stream runs smoothly. When I enable the audio capture, the DMA stream for parallel out is corrupted somehow... Both peripheral uses the DMA2 (Stream0 and Stream1). The DMA streams are configured as:

robbits_0-1725366998328.png

The TIM5_CH1 is the parallel interface clock input, it is configured for very high priority. The analog capture is on low priority. On the following picture you can see a "normal operation". CH9 is the interesting on, it shows the interrupt of the DMA2 Stream0, on CH5 you can see the parallel reading clock. Between two DMA interrupts we have ~1.895ms time. 

robbits_1-1725367094817.png

And here it is the corrupted one:

robbits_2-1725367262363.png

The third transfer does not finish properly, and the last dma interrupt occours at ~2.95ms instead of 1.89ms. But the first arrived in time. And you can see the impulse train on the paralel clock are "doubled" in each reading cycle, because the MCU did not signalized the end of the parallel communication and so the external controller started a new reading cycle. 

I checked plenty of things in the code already but I feel like I lost in the woods...It seems like the DMA2 Stream0 and Stream1 got into trouble somehow. Or there is some bandwidth issues on the internal buses. If I change back the paralell read speed to 10MHz then everything works properly. 

Any idea to look for?