cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping external memory XSPI RAM STM32H7S7

nico23
Senior III

I'm currently using an STM32H7S78-DK, and I'm correctly able to run TouchGFX with FreeRTOS and everything. I also an error handler function that, in case of a crash of TouchGFX it writes directly to the framebuffer.

Now, I would like to do a similar thing but on the boot code, so basically before the classic jump if (BOOT_OK != BOOT_Application())

I have an external RAM mapped at the address 0x90000000 which works correctly in TouchGFX with .icf like

define symbol __region_EXTRAM_start__  = 0x90000000;
define symbol __region_EXTRAM_end__    = 0x91FFFFFF;
define region EXTRAM_region   = mem:[from __region_EXTRAM_start__ to __region_EXTRAM_end__];
place in EXTRAM_region { first section TouchGFX_Framebuffer
                       , section Video_RGB_Buffer 
                       , section Nemagfx_Stencil_Buffer };

I wanted to use the same section of memory in the Boot, accessing the framebuffer directly, so I edited the .icf of the boot with

define symbol __region_EXTRAM_start__  = 0x90000000;
define symbol __region_EXTRAM_end__    = 0x91FFFFFF;
define region EXTRAM_region   = mem:[from __region_EXTRAM_start__ to __region_EXTRAM_end__];
place in EXTRAM_region { first section Boot_Framebuffer };

And in the main.c

#pragma location = "Boot_Framebuffer"
__no_init uint32_t frameBuf[(800 * 480 * 2 + 3) / 4 * 2];

Using J-Link and IAR, during the debug, I'm seeing the frameBuf is correctly mapped from address 0x90000000 but, as soon as I try to access the memory address, for instance wiping the frameBuf with

memset((void*)frameBuf, 0, sizeof(frameBuf));

The code goes into HardFault. I have set the correct address for the LTDC with

  LTDC_Layer1->CFBAR = (uint32_t)frameBuf;
  LTDC->SRCR = (uint32_t)LTDC_SRCR_IMR;

and I'm correctly initializing the XSPI as they return HAL_OK

  MX_XSPI1_Init();  // External flash
  MX_XSPI2_Init();  // External PSRAM

I've alos configured the MPU region for the EXT RAM with

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

  /* Disables the MPU */
  HAL_MPU_Disable();
  
  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER3;
  MPU_InitStruct.BaseAddress = 0x90000000;
  MPU_InitStruct.Size = MPU_REGION_SIZE_32MB;
  MPU_InitStruct.SubRegionDisable = 0x00;
  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_NOT_SHAREABLE;
  MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;

  HAL_MPU_ConfigRegion(&MPU_InitStruct);
  
  HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}

I suspect that the CPU does not have the address of the external RAM mapped in its internal registries; could it be? Is there a way to access this frame buffer and read/write it to/from the external RAM

0 REPLIES 0