cancel
Showing results for 
Search instead for 
Did you mean: 

STM32N6570-DK with FSBL and Appl - mapping external PSRAM in FSBL

Jack3
Senior III

Hello superhero MCU enthusiasts,

I'm playing with the STM32N6570-DK and have created a simple project with an FSBL that initializes the MCU and boots the Appl. Once booted, the Appl flashes a "Hello World" LED.
Both can be loaded to external flash using the STM32CubeProgrammer.

Now, I'm trying to map external PSRAM (XSPI1 -> 0x90000000) inside the FSBL, but it fails.

To do that, I change a line in a file in the FSBL, stm32_extmem_conf.h, line 35 of (PSRAM disabled):

#define EXTMEM_DRIVER_PSRAM 0

Now I try to enable and map the external PSRAM by setting the definition to 1:

#define EXTMEM_DRIVER_PSRAM 1

However, it doesn't succeed.

When debugging I see we land into a HardFault.

The FSBL generates a HardFault when executing SAL_XSPI_EnableMapMode, because the function HAL_XSPI_MemoryMapped fails.
I can't find the cause.
Anyone?
I posted a project here with a short Readme.md:

https://github.com/AngryCarrot61/STM32N6570-DK_004

Note: to see FSBL and Appl working one has to set EXTMEM_DRIVER_PSRAM to 0.
However the goal is to get PSRAM mapped (XSPI1 at 0x90000000).

Flashing:
the debug directories for FSBL and Appl contain a batch file: '0_SigningTool.bat'.
After compiling, run the batch files to sign the binaries.
Using STM32CubeProgrammer we select EL 'MX66UW1G45G_STM32N6570-DK'.
FSBL will be loaded at 0x70000000, and Appl at 0x70100000.
Enjoy!

 

Any help is much apreciated regarding the part to map the PSRAM!

Cheers!

1 ACCEPTED SOLUTION

Accepted Solutions
Jack3
Senior III

Thank you very much, I forgot to add the PSRAM into the MPU.
However, the initialization still failes, so I wouldn't be able to access it anyway.
My new STM32N6 MPU configuration:

static void MPU_Config(void)
{
  /*
   * XSPI2 0x70000000 128MB FLASH (1-Gbit   Octo-SPI)
   * XSPI1 0x90000000  32MB PSRAM (256-Mbit Hexadeca-SPI)
   */
  MPU_Region_InitTypeDef default_config = {0};
  MPU_Attributes_InitTypeDef attr_config = {0};
  uint32_t primask_bit = __get_PRIMASK();
  __disable_irq();

  /* disable the MPU */
  HAL_MPU_Disable();

  /* create an attribute configuration for the MPU */
  attr_config.Attributes = INNER_OUTER(MPU_WRITE_BACK | MPU_NON_TRANSIENT | MPU_RW_ALLOCATE);
  attr_config.Number = MPU_ATTRIBUTES_NUMBER0;

  HAL_MPU_ConfigMemoryAttributes(&attr_config);

  /* Create a region associated with memory address 0x70000000 */
  /*Normal memory type, code execution allowed */
  default_config.Number = MPU_REGION_NUMBER0;
  default_config.Enable = MPU_REGION_ENABLE;
  default_config.BaseAddress = XSPI2_BASE; /* FLASH 128MB 0x70000000 */
  default_config.LimitAddress = XSPI2_BASE + 0x08000000-1;
  default_config.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  default_config.AccessPermission = MPU_REGION_ALL_RO;
  default_config.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  default_config.AttributesIndex = MPU_ATTRIBUTES_NUMBER0;
  HAL_MPU_ConfigRegion(&default_config);

  /* Ensure the FSBL enables MPU access for the PSRAM region before mapping it: */
  default_config.Number = MPU_REGION_NUMBER1;
  default_config.Enable = MPU_REGION_ENABLE;
  default_config.BaseAddress = XSPI1_BASE; /* PSRAM 32MB 0x90000000 */
  default_config.LimitAddress = XSPI1_BASE + 0x02000000-1;
  default_config.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  default_config.AccessPermission = MPU_REGION_ALL_RW;
  default_config.IsShareable = MPU_ACCESS_INNER_SHAREABLE | MPU_ACCESS_OUTER_SHAREABLE;
  default_config.AttributesIndex = MPU_ATTRIBUTES_NUMBER0;
  HAL_MPU_ConfigRegion(&default_config);

  /* enable the MPU */
  HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

  /* Exit critical section to lock the system and avoid any issue around MPU mechanisme */
  __set_PRIMASK(primask_bit);
}

I still hope to find the problem soon. I'm looking into my PSRAM initialization.
Thanks for helping!

 

UPDATE: I got access to the external PSRAM working from the FSBL.

I added HAL_PWREx_EnableVddIO* lines.

void HAL_MspInit(void)
{
  HAL_PWREx_EnableVddIO2();
  HAL_PWREx_EnableVddIO3();
  HAL_PWREx_EnableVddIO4();
  HAL_PWREx_EnableVddIO5();
}

After the PSRAM test, FSBL launches the application (Appl), which blinks the LEDs.


I updated the repository on github:
https://github.com/AngryCarrot61/STM32N6570-DK_004

Enjoy!

View solution in original post

1 REPLY 1
Jack3
Senior III

Thank you very much, I forgot to add the PSRAM into the MPU.
However, the initialization still failes, so I wouldn't be able to access it anyway.
My new STM32N6 MPU configuration:

static void MPU_Config(void)
{
  /*
   * XSPI2 0x70000000 128MB FLASH (1-Gbit   Octo-SPI)
   * XSPI1 0x90000000  32MB PSRAM (256-Mbit Hexadeca-SPI)
   */
  MPU_Region_InitTypeDef default_config = {0};
  MPU_Attributes_InitTypeDef attr_config = {0};
  uint32_t primask_bit = __get_PRIMASK();
  __disable_irq();

  /* disable the MPU */
  HAL_MPU_Disable();

  /* create an attribute configuration for the MPU */
  attr_config.Attributes = INNER_OUTER(MPU_WRITE_BACK | MPU_NON_TRANSIENT | MPU_RW_ALLOCATE);
  attr_config.Number = MPU_ATTRIBUTES_NUMBER0;

  HAL_MPU_ConfigMemoryAttributes(&attr_config);

  /* Create a region associated with memory address 0x70000000 */
  /*Normal memory type, code execution allowed */
  default_config.Number = MPU_REGION_NUMBER0;
  default_config.Enable = MPU_REGION_ENABLE;
  default_config.BaseAddress = XSPI2_BASE; /* FLASH 128MB 0x70000000 */
  default_config.LimitAddress = XSPI2_BASE + 0x08000000-1;
  default_config.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  default_config.AccessPermission = MPU_REGION_ALL_RO;
  default_config.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  default_config.AttributesIndex = MPU_ATTRIBUTES_NUMBER0;
  HAL_MPU_ConfigRegion(&default_config);

  /* Ensure the FSBL enables MPU access for the PSRAM region before mapping it: */
  default_config.Number = MPU_REGION_NUMBER1;
  default_config.Enable = MPU_REGION_ENABLE;
  default_config.BaseAddress = XSPI1_BASE; /* PSRAM 32MB 0x90000000 */
  default_config.LimitAddress = XSPI1_BASE + 0x02000000-1;
  default_config.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  default_config.AccessPermission = MPU_REGION_ALL_RW;
  default_config.IsShareable = MPU_ACCESS_INNER_SHAREABLE | MPU_ACCESS_OUTER_SHAREABLE;
  default_config.AttributesIndex = MPU_ATTRIBUTES_NUMBER0;
  HAL_MPU_ConfigRegion(&default_config);

  /* enable the MPU */
  HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

  /* Exit critical section to lock the system and avoid any issue around MPU mechanisme */
  __set_PRIMASK(primask_bit);
}

I still hope to find the problem soon. I'm looking into my PSRAM initialization.
Thanks for helping!

 

UPDATE: I got access to the external PSRAM working from the FSBL.

I added HAL_PWREx_EnableVddIO* lines.

void HAL_MspInit(void)
{
  HAL_PWREx_EnableVddIO2();
  HAL_PWREx_EnableVddIO3();
  HAL_PWREx_EnableVddIO4();
  HAL_PWREx_EnableVddIO5();
}

After the PSRAM test, FSBL launches the application (Appl), which blinks the LEDs.


I updated the repository on github:
https://github.com/AngryCarrot61/STM32N6570-DK_004

Enjoy!