Skip to main content
heyo
Associate III
Aug 2, 2023 7:37 AM UTC
Question

SDRAM MPU configuration

I store "FrontendHeap" to my external SDRAM and in the text appears question mark and when I want to change screen it crashes at specific screen.

Photo 2023-08-02 10 27 44-min.jpg

I configured my SDRAM

 

 

 

void MX_FMC_Init(void)
{
 /* USER CODE BEGIN FMC_Init 0 */

 /* USER CODE END FMC_Init 0 */

 FMC_SDRAM_TimingTypeDef SdramTiming = {0};

 /* USER CODE BEGIN FMC_Init 1 */

 /* USER CODE END FMC_Init 1 */

 /** Perform the SDRAM1 memory initialization sequence
 */
 hsdram1.Instance = FMC_SDRAM_DEVICE;
 /* hsdram1.Init */
 hsdram1.Init.SDBank = FMC_SDRAM_BANK1;
 hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
 hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
 hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
 hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
 hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_2;
 hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
 hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
 hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_ENABLE;
 hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_2;
 /* SdramTiming */
 SdramTiming.LoadToActiveDelay = 2;
 SdramTiming.ExitSelfRefreshDelay = 7;
 SdramTiming.SelfRefreshTime = 5;
 SdramTiming.RowCycleDelay = 7;
 SdramTiming.WriteRecoveryTime = 3;
 SdramTiming.RPDelay = 3;
 SdramTiming.RCDDelay = 2;

 if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
 {
 Error_Handler( );
 }

 /* USER CODE BEGIN FMC_Init 2 */
 FMC_SDRAM_CommandTypeDef Command;
 /* Step 1 and Step 2 already done in HAL_SDRAM_Init() */
 /* Step 3: Configure a clock configuration enable command */
 Command.CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; /* Set MODE bits to "001" */
 Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; /* configure the Target Bank bits */
 Command.AutoRefreshNumber = 1;
 Command.ModeRegisterDefinition = 0;
 HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);
 HAL_Delay(1); /* Step 4: Insert 100 us minimum delay - Min HAL Delay is 1ms */
 /* Step 5: Configure a PALL (precharge all) command */
 Command.CommandMode = FMC_SDRAM_CMD_PALL; /* Set MODE bits to "010" */
 HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);
 /* Step 6: Configure an Auto Refresh command */
 Command.CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; /* Set MODE bits to "011" */
 Command.AutoRefreshNumber = 2;
 HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);
 /* Step 7: Program the external memory mode register */
 Command.CommandMode = FMC_SDRAM_CMD_LOAD_MODE;/*set the MODE bits to "100" */
 Command.ModeRegisterDefinition = (uint32_t)0 | 0<<3 | 2<<4 | 0<<7 | 1<<9;
 HAL_SDRAM_SendCommand(&hsdram1, &Command, 0xfff);
 /* Step 8: Set the refresh rate counter - refer to section SDRAM refresh timer register in RM0455 */
 /* Set the device refresh rate
 * COUNT = [(SDRAM self refresh time / number of row) x SDRAM CLK] – 20
 = [(64ms/4096) * 100MHz] - 20 = 1562.5 - 20 ~ 1542 */
 HAL_SDRAM_ProgramRefreshRate(&hsdram1, 1542);
 /* USER CODE END FMC_Init 2 */
}

 

 

 

And MPU:

 

 

 

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 = 0xC0000000;
 MPU_InitStruct.Size = MPU_REGION_SIZE_8MB;
 MPU_InitStruct.SubRegionDisable = 0x0;
 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
 MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
 MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
 MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);

 /** Initializes and configures the Region and the memory to be protected
 */
 MPU_InitStruct.Number = MPU_REGION_NUMBER1;
 MPU_InitStruct.BaseAddress = 0xC0300000;
 MPU_InitStruct.Size = MPU_REGION_SIZE_2MB;
 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);

 /** Initializes and configures the Region and the memory to be protected
 */
 MPU_InitStruct.Number = MPU_REGION_NUMBER2;
 MPU_InitStruct.BaseAddress = 0xC0600000;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);

 /** Initializes and configures the Region and the memory to be protected
 */
 MPU_InitStruct.Number = MPU_REGION_NUMBER3;
 MPU_InitStruct.BaseAddress = 0xC000000;
 MPU_InitStruct.Size = MPU_REGION_SIZE_1MB;
 MPU_InitStruct.AccessPermission = MPU_REGION_PRIV_RO;
 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

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

}

 

 

 

At 0xC0300000 and 0xC0600000 is framebuffers. at Cx0000000 is frontendheap. Maybe someone sees where problem is? When frontend heap is in the internal processor RAM it works fine

This topic has been closed for replies.

4 replies

Graduate II
Aug 2, 2023 8:19 AM UTC

Hello

What if you set the heap area as non-cacheable in mmu config ?

Br J.T

heyo
heyoAuthor
Associate III
Aug 2, 2023 8:29 AM UTC

Unfortunately, same..:sad_but_relieved_face:

Graduate II
Aug 2, 2023 8:40 AM UTC

Ok.  Can you temporary disable the mmu to see its causing the problems ?

heyo
heyoAuthor
Associate III
Aug 2, 2023 9:15 AM UTC

If I disable MPU it does not start at all.