cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with SDRAM/MDMA in custom 'STM32H747I_DISCO_FoodReco_Quantized' application

eeeeee
Associate III

I'm trying to create an AI Vision application based on the STM32H747I_DISCO_FoodReco_Quantized application. I've made a custom board with the STM32H743ZI microcontroller. I believe the problem is that the data is not correctly written to the external SDRAM.

The line data from the camera that is written to 0x30000000 through DMA seems alright, and from my understanding, the data in 0x30000000 is used to build up a frame in the capturebuffer in the external SDRAM through MDMA. This capturebuffer is then transferred to a framebuffer in the SDRAM and the framebuffer is then used to perform the inference on.

There is data written to the framebuffer in my screenshot below, but it has a lot of F's seperating the data. I have no clue why this is happening. Is this a MDMA configuration error? Or a SDRAM configuration error? Possibly both?

0693W00000HnoLPQAZ.png 

What I did is I connected my custom board to an external SDRAM, that is different from the SDRAM used on the STM32H747I-DISCO board. The difference here is that I use a x8 wide SDRAM and the discovery board has a 32x wide SDRAM.

I modified the code in 'system_stm32h7xx.c' in the attached snippet to match the GPIO connections and changed MemoryDataWidth, ColumnBitsNumber, InternalBankNumber and RowBitsNumber to the correct values matching the SDRAM I use (IS42S83200G-7TL).

void SystemInit_ExtMemCtl(void)
{
  __IO uint32_t tmp = 0;
  register uint32_t tmpreg = 0, timeout = 0xFFFF;
  register __IO uint32_t index;
 
  /* Enable GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface
      clock */
 
  //enable klok b,c,d,e,f,g
  RCC->AHB4ENR |= 0b1111110;
 
  /* Delay after an RCC peripheral clock enabling */
  tmp = READ_BIT(RCC->AHB4ENR, RCC_AHB4ENR_GPIOEEN);
 
  /* Connect PBx pins to FMC Alternate function */
  GPIOB->AFR[0] = 0x0CC00000;
  GPIOB->AFR[1] = 0x00000000;
  /* Configure PDx pins in Alternate function mode */
  GPIOB->MODER = 0b11111111111111111110101111111111;
  /* Configure PDx pins speed to 100 MHz */
  GPIOB->OSPEEDR = 0b11110000000000;
  /* Configure PDx pins Output type to push-pull */
  GPIOB->OTYPER = 0x00000000;
  /* Configure PDx pins in Pull-up */
  GPIOB->PUPDR = 0b01010000000000;
 
  /* Connect PCx pins to FMC Alternate function */
  GPIOC->AFR[0] = 0x0000000C;
  GPIOC->AFR[1] = 0x00000000;
  /* Configure PDx pins in Alternate function mode */
  GPIOC->MODER = 0b11111111111111111111111111111110;
  /* Configure PDx pins speed to 100 MHz */
  GPIOC->OSPEEDR = 0b11;
  /* Configure PDx pins Output type to push-pull */
  GPIOC->OTYPER = 0x00000000;
  /* Configure PDx pins in Pull-up */
  GPIOC->PUPDR = 0b00000000000001;
 
  /* Connect PDx pins to FMC Alternate function */
  GPIOD->AFR[0] = 0x000000CC;
  GPIOD->AFR[1] = 0xCC000000;
  /* Configure PDx pins in Alternate function mode */
  GPIOD->MODER = 0b10101111111111111111111111111010;
  /* Configure PDx pins speed to 100 MHz */
  GPIOD->OSPEEDR = 0b11110000000000000000000000001111;
  /* Configure PDx pins Output type to push-pull */
  GPIOD->OTYPER = 0x00000000;
  /* Configure PDx pins in Pull-up */
  GPIOD->PUPDR = 0b01010000000000000000000000000101;
 
  /* Connect PEx pins to FMC Alternate function */
  GPIOE->AFR[0] = 0xC000000C;
  GPIOE->AFR[1] = 0x00000CCC;
  /* Configure PEx pins in Alternate function mode */
  GPIOE->MODER = 0b11111111111010101011111111111110;
  /* Configure PEx pins speed to 100 MHz */
  GPIOE->OSPEEDR = 0b1111111100000000000011;
  /* Configure PEx pins Output type to push-pull */
  GPIOE->OTYPER = 0b00000000;
  /* Configure PEx pins in Pull-up */
  GPIOE->PUPDR = 0b0101010100000000000001;
 
  /* Connect PFx pins to FMC Alternate function */
  GPIOF->AFR[0] = 0x00CCCCCC;
  GPIOF->AFR[1] = 0xCCCCC000;
  /* Configure PFx pins in Alternate function mode */
  GPIOF->MODER = 0xAABFFAAA;
  /* Configure PFx pins speed to 100 MHz */
  GPIOF->OSPEEDR = 0xFFC00FFF;
  /* Configure PFx pins Output type to push-pull */
  GPIOF->OTYPER = 0x00000000;
  /* Configure PFx pins in Pull-up */
  GPIOF->PUPDR = 0x55400555;
 
  /* Connect PGx pins to FMC Alternate function */
  GPIOG->AFR[0] = 0x00CC0CCC;
  GPIOG->AFR[1] = 0xC000000C;
  /* Configure PGx pins in Alternate function mode */
  GPIOG->MODER = 0xBFFEFAAA;
  /* Configure PGx pins speed to 100 MHz */
  GPIOG->OSPEEDR = 0xC0030FFF;
  /* Configure PGx pins Output type to push-pull */
  GPIOG->OTYPER = 0x00000000;
  /* Configure PGx pins in Pull-up */
  GPIOG->PUPDR = 0x40010555;
 
//  /* Connect PHx pins to FMC Alternate function */
//  GPIOH->AFR[0] = 0xCCC00000;
//  GPIOH->AFR[1] = 0xCCCCCCCC;
//  /* Configure PHx pins in Alternate function mode */
//  GPIOH->MODER = 0xAAAAABFF;
//  /* Configure PHx pins speed to 100 MHz */
//  GPIOH->OSPEEDR = 0xFFFFFC00;
//  /* Configure PHx pins Output type to push-pull */
//  GPIOH->OTYPER = 0x00000000;
//  /* Configure PHx pins in Pull-up */
//  GPIOH->PUPDR = 0x55555400;
//
//  /* Connect PIx pins to FMC Alternate function */
//  GPIOI->AFR[0] = 0xCCCCCCCC;
//  GPIOI->AFR[1] = 0x00000CC0;
//  /* Configure PIx pins in Alternate function mode */
//  GPIOI->MODER = 0xFFEBAAAA;
//  /* Configure PIx pins speed to 100 MHz */
//  GPIOI->OSPEEDR = 0x003CFFFF;
//  /* Configure PIx pins Output type to push-pull */
//  GPIOI->OTYPER = 0x00000000;
//  /* Configure PIx pins in Pull-up */
//  GPIOI->PUPDR = 0x00145555;
 
  /*-- FMC Configuration ------------------------------------------------------*/
  /* Enable the FMC interface clock */
  (RCC->AHB3ENR |= (RCC_AHB3ENR_FMCEN));
  /*SDRAM Timing and access interface configuration*/
  /*LoadToActiveDelay  = 2
    ExitSelfRefreshDelay = 6
    SelfRefreshTime      = 4
    RowCycleDelay        = 6
    WriteRecoveryTime    = 2
    RPDelay              = 2
    RCDDelay             = 2
    SDBank             = FMC_SDRAM_BANK2
    ColumnBitsNumber   = FMC_SDRAM_COLUMN_BITS_NUM_9
    RowBitsNumber      = FMC_SDRAM_ROW_BITS_NUM_12
    MemoryDataWidth    = FMC_SDRAM_MEM_BUS_WIDTH_32
    InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4
    CASLatency         = FMC_SDRAM_CAS_LATENCY_2
    WriteProtection    = FMC_SDRAM_WRITE_PROTECTION_DISABLE
    SDClockPeriod      = FMC_SDRAM_CLOCK_PERIOD_2
    ReadBurst          = FMC_SDRAM_RBURST_ENABLE
    ReadPipeDelay      = FMC_SDRAM_RPIPE_DELAY_0*/
 
  FMC_Bank5_6_R->SDCR[0] = 0x00001800;
  FMC_Bank5_6_R->SDCR[1] = 0b111001010;
  FMC_Bank5_6_R->SDTR[0] = 0x00106000;
  FMC_Bank5_6_R->SDTR[1] = 0x01020361;
 
  /* SDRAM initialization sequence */
  /* Clock enable command */
  FMC_Bank5_6_R->SDCMR = 0x00000009;
  tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
  while ((tmpreg != 0) && (timeout-- > 0))
  {
    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
  }
 
  /* Delay */
  for (index = 0; index < 1000; index++)
    ;
 
  /* PALL command */
  FMC_Bank5_6_R->SDCMR = 0x0000000A;
  timeout = 0xFFFF;
  while ((tmpreg != 0) && (timeout-- > 0))
  {
    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
  }
 
  FMC_Bank5_6_R->SDCMR = 0x000000EB;
  timeout = 0xFFFF;
  while ((tmpreg != 0) && (timeout-- > 0))
  {
    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
  }
 
  FMC_Bank5_6_R->SDCMR = 0x0004400C;
  timeout = 0xFFFF;
  while ((tmpreg != 0) && (timeout-- > 0))
  {
    tmpreg = FMC_Bank5_6_R->SDSR & 0x00000020;
  }
  /* Set refresh count */
  tmpreg = FMC_Bank5_6_R->SDRTR;
  FMC_Bank5_6_R->SDRTR = (tmpreg | (370 << 1));
 
  /* Disable write protection */
  tmpreg = FMC_Bank5_6_R->SDCR[1];
  FMC_Bank5_6_R->SDCR[1] = (tmpreg & 0xFFFFFDFF);
 
  /*FMC controller Enable*/
  FMC_Bank1_R->BTCR[0] |= 0x80000000;
 
  (void)(tmp);
}
#endif /* DATA_IN_ExtSDRAM */

I haven't changed the MDMA settings that were already present in the 'fp_vision_camera.c' file. When I change that the program runs into a dma error.

Hope someone can help me.

Thanks in advance!

0 REPLIES 0