cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U585 DCMI+DMA problem

Linas L
Senior II

Hello, I am facing problems with DMA and DCMI . Since DMA has ability to generate multiple block transfers with single configuration, it means i can transfer image larger that 0xFFFF.

So I writen code that would repat my DMA transfer for as much line as I have in my image, and transfer size would be one line pixel count.

I configured sensor for 304x304 image, and with DMA i get transfered exactly 304*304 of u16 data ( I prealod array with 0xFFFF and see where tranfer is ended)

What is strange, what data alignment is completely incorrect, while with FPGA, image is perfect and looks as expected ( i have one big light source in the middle)

This is my DMA code in LL

LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPDMA1);
 
LL_DMA_SetChannelPriorityLevel(GPDMA1,LL_DMA_CHANNEL_12,LL_DMA_HIGH_PRIORITY);
 
DMA1_TR1 = LL_DMA_DEST_ALLOCATED_PORT0|LL_DMA_DEST_HALFWORD_PRESERVE|LL_DMA_DEST_BYTE_PRESERVE|LL_DMA_SRC_BYTE_PRESERVE|LL_DMA_DEST_INCREMENT|LL_DMA_DEST_DATAWIDTH_WORD|LL_DMA_SRC_ALLOCATED_PORT0|LL_DMA_DATA_ALIGN_ZEROPADD|LL_DMA_SRC_FIXED|LL_DMA_SRC_DATAWIDTH_WORD;
LL_DMA_ConfigTransfer(GPDMA1,LL_DMA_CHANNEL_12,DMA1_TR1);
 
DMA1_TR2=LL_DMA_TCEM_BLK_TRANSFER|LL_DMA_DIRECTION_PERIPH_TO_MEMORY|LL_GPDMA1_REQUEST_DCMI_PSSI;
 
LL_DMA_ConfigChannelTransfer(GPDMA1,LL_DMA_CHANNEL_12,DMA1_TR2);
 
DMA1_BR1 =LL_DMA_BLKRPT_DEST_ADDR_INCREMENT ;
 
LL_DMA_ConfigBlkRptAddrUpdate(GPDMA1,LL_DMA_CHANNEL_12,DMA1_BR1);
 
LL_DMA_ConfigBlkCounters(GPDMA1,LL_DMA_CHANNEL_12,304*2,304-1);
 
DMA1_SAR =(uint32_t)&DCMI->DR;
DMA1_DAR =(uint32_t)&DCMI_DATA;
 
LL_DMA_ConfigAddresses(GPDMA1,LL_DMA_CHANNEL_12,DMA1_SAR,DMA1_DAR);
 
LL_DMA_EnableIT_USE(GPDMA1, LL_DMA_CHANNEL_12);
LL_DMA_EnableIT_ULE(GPDMA1, LL_DMA_CHANNEL_12);
LL_DMA_EnableIT_DTE(GPDMA1, LL_DMA_CHANNEL_12);
LL_DMA_EnableIT_TC (GPDMA1, LL_DMA_CHANNEL_12);
 
 
NVIC_SetPriority(GPDMA1_Channel12_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(GPDMA1_Channel12_IRQn);
 
LL_DMA_EnableChannel(GPDMA1, LL_DMA_CHANNEL_12);

And downloaded image from SRAM3 memory looks like this:

0693W00000aIBSfQAO.png 

Dows any one knows what could be wrong ? I spend so much time changing parameters for a transfer with not much luck...

1 ACCEPTED SOLUTION

Accepted Solutions
I.KHACHINE
ST Employee

Hi @Linas L​ 

We have many examples in our firmware package that can help you in your camera setup.

STM32CubeU5/Projects/STM32U575I-EV/Examples/DCMI/DCMI_ContinousCap_EmbeddedSynchMode/

STM32CubeU5/Projects/B-U585I-IOT02A/Examples/BSP.

STM32CubeU5/Projects/STM32U575I-EV/Examples/BSP/

STM32CubeU5/Projects/STM32U575I-EV/Demonstrations/Modules/cameraviewer/

These examples is based on BSP driver + HAL Driver.

In your DMA configuration , I see some bad parameters( like DMA_DEST_DATAWIDTH_HALFWORD, SrcBurstLength , DestBurstLength , ....)

Best Regards,

Ismail

View solution in original post

2 REPLIES 2
Linas L
Senior II

And if I try to use DMA not in LL mode, I also not getting what I am asked for.

In this example, I set camera to display fixed value of 682 (1010101010) and most of the image does have this data, but where are so many wrong data here, I have no Idea why

Camera in this example runs at 40MHz, while MCU at 160MHz ( while based on datasheet i need at least 2.5x clock difference, so i am good)

0693W00000aIClOQAW.png 

  LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPDMA1);
 
  LL_DMA_EnableIT_USE(GPDMA1, LL_DMA_CHANNEL_12);
  LL_DMA_EnableIT_ULE(GPDMA1, LL_DMA_CHANNEL_12);
  LL_DMA_EnableIT_DTE(GPDMA1, LL_DMA_CHANNEL_12);
  LL_DMA_EnableIT_TC (GPDMA1, LL_DMA_CHANNEL_12);
 
  NVIC_SetPriority(GPDMA1_Channel12_IRQn,0);
  NVIC_EnableIRQ(GPDMA1_Channel12_IRQn);
 
 
uint32_t SrcBurstLength = 0;
uint32_t DestBurstLength = 0;
 
uint32_t RepeatCount = 304-1;
uint32_t SrcAddrOffset = 0;
uint32_t DestAddrOffset = 0;
uint32_t BlkSrcAddrOffset = 0;
uint32_t BlkDestAddrOffset = 0;
 
 LL_DMA_DisableChannel(GPDMA1,LL_DMA_CHANNEL_12);
 LL_DMA_ResetChannel(GPDMA1,LL_DMA_CHANNEL_12);
 
  DMA_RepeatBlockConfTypeDef RepeatBlockConfig = {0};
 
  DCMI_DMA.Instance = GPDMA1_Channel12;
  DCMI_DMA.Init.Request = GPDMA1_REQUEST_DCMI_PSSI;
  DCMI_DMA.Init.BlkHWRequest = DMA_BREQ_BLOCK;
  DCMI_DMA.Init.Direction = DMA_PERIPH_TO_MEMORY;
  DCMI_DMA.Init.SrcInc = DMA_SINC_FIXED;
  DCMI_DMA.Init.DestInc = DMA_DINC_INCREMENTED;
  DCMI_DMA.Init.SrcDataWidth = DMA_SRC_DATAWIDTH_WORD;
  DCMI_DMA.Init.DestDataWidth = DMA_DEST_DATAWIDTH_HALFWORD;
  DCMI_DMA.Init.Priority = DMA_HIGH_PRIORITY;
  DCMI_DMA.Init.SrcBurstLength = SrcBurstLength;
  DCMI_DMA.Init.DestBurstLength = DestBurstLength;
  DCMI_DMA.Init.TransferAllocatedPort = DMA_SRC_ALLOCATED_PORT0|DMA_DEST_ALLOCATED_PORT1;
  DCMI_DMA.Init.Mode = DMA_NORMAL;
  if (HAL_DMA_Init(&DCMI_DMA) != HAL_OK)
  {
    //Error_Handler();
  }
  RepeatBlockConfig.RepeatCount = RepeatCount;
  RepeatBlockConfig.SrcAddrOffset = SrcAddrOffset;
  RepeatBlockConfig.DestAddrOffset = DestAddrOffset;
  RepeatBlockConfig.BlkSrcAddrOffset = BlkSrcAddrOffset;
  RepeatBlockConfig.BlkDestAddrOffset = BlkDestAddrOffset;
  if (HAL_DMAEx_ConfigRepeatBlock(&DCMI_DMA, &RepeatBlockConfig) != HAL_OK)
  {
    //Error_Handler();
  }
  /* USER CODE BEGIN DMA_Increment_ScatterOperation 2 */
  /* Select Callbacks functions called after Half Transfer Complete, Transfer Complete and Transfer Error */
  //HAL_DMA_RegisterCallback(&handle_GPDMA1_Channel12, HAL_DMA_XFER_CPLT_CB_ID, TransferComplete);
  //HAL_DMA_RegisterCallback(&handle_GPDMA1_Channel12, HAL_DMA_XFER_ERROR_CB_ID, TransferError);
 
  /* Configure the source, destination and buffer size DMA fields and Start DMA Channel/Stream transfer */
  /* Enable All the DMA interrupts */
  if (HAL_DMA_Start(&DCMI_DMA, (uint32_t)&DCMI->DR, (uint32_t)&DCMI_DATA, 304*4) != HAL_OK)
  {
//Error_Handler();
  }
  /* USER CODE END DMA_Increment_ScatterOperation 2 */

I tried nearly every combination with settings. but could not make this work. At this point something major is wrong with my code, I jsut don't know what exactly.

Tested this on multiple hardware ( same on) Get same effect, voltages are also same ( note, I am running 1.8V, since camera output is at 1.8V for paralel data for some unknown reason while everything else is at 3.3V)

While canbus and bootloader to program flash works as it shoud for days without any problems....

all pins are cheched with datasheet, all AF and so on, and they do work, since I get most of the data correctly...

Nevr had this problem with STM32L496 MCU, it just worked nearly first time....

I.KHACHINE
ST Employee

Hi @Linas L​ 

We have many examples in our firmware package that can help you in your camera setup.

STM32CubeU5/Projects/STM32U575I-EV/Examples/DCMI/DCMI_ContinousCap_EmbeddedSynchMode/

STM32CubeU5/Projects/B-U585I-IOT02A/Examples/BSP.

STM32CubeU5/Projects/STM32U575I-EV/Examples/BSP/

STM32CubeU5/Projects/STM32U575I-EV/Demonstrations/Modules/cameraviewer/

These examples is based on BSP driver + HAL Driver.

In your DMA configuration , I see some bad parameters( like DMA_DEST_DATAWIDTH_HALFWORD, SrcBurstLength , DestBurstLength , ....)

Best Regards,

Ismail