cancel
Showing results for 
Search instead for 
Did you mean: 

RAM size is not increasing and giving runtime error

Nitin
Associate III

Hi I am working on SBSFU Application project from STM32U585 project. I have done below changes to the existing project.

1. Added my project code SBSFU_Appli_NonSecure project.

2. Previously this project was assigned 192KB and it was hardly using 3% of it. And now the requirement is of more RAM, I have increased RAM boundry to 256KB as below in STM32U585AIIX_FLASH.ld

RAM (xrw) : ORIGIN = NS_DATA_START, LENGTH = 256KB/*NS_DATA_SIZE*/

3. Now what I am seeing is I am not getting to jump to NS main() after this

"[INF] Jumping to the first image slot"

 

Same kind of experiment I have tried in TFM project and it worked, but I am not able to get the catch here.

Need help, thanks in advance...

@Jocelyn RICARD 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Nitin,

I made a check on my side.

First, there is a small error in region_defs.h:

Line 213 and also line 220

Please replace 

#ifdef SRAM3_BASE

by 

#ifdef _SRAM3_BASE_NS

 

The SRAM3_BASE is actually not known when using gcc preprocessor on linker file.

 

After that you need to make duplicate and adapt this unsecure_sram1 function like this:

 

static void  unsecure_sram3(uint32_t start, uint32_t end)
{

  MPCBB_ConfigTypeDef MPCBB_desc;
  uint32_t regwrite = 0xffffffff;
  uint32_t index;
  uint32_t block_start = (start - SRAM3_BASE) / GTZC_MPCBB_BLOCK_SIZE;
  uint32_t block_end = block_start + ((end - start) + 1) / GTZC_MPCBB_BLOCK_SIZE;

  if (start & 0xff)
    /*  Check alignment to avoid further problem  */
    /*  FIX ME  */
    while (1);

  if (HAL_GTZC_MPCBB_GetConfigMem(SRAM3_BASE, &MPCBB_desc) != HAL_OK)
  {
    /* FIX ME */
    Error_Handler();
  }

  for (index = 0; index < SRAM3_SIZE / GTZC_MPCBB_BLOCK_SIZE; index++)
  {
    /* clean register on index aligned */
    if (!(index & 0x1f))
    {
      regwrite = 0xffffffff;
    }
    if ((index >= block_start) && (index < block_end))
    {
      regwrite = regwrite & ~(1 << (index & 0x1f));
    }
    /* write register when 32 sub block are set  */
    if ((index & 0x1f) == 0x1f)
    {
      MPCBB_desc.AttributeConfig.MPCBB_SecConfig_array[index >> 5] = regwrite;
    }
  }
  if (HAL_GTZC_MPCBB_ConfigMem(SRAM3_BASE, &MPCBB_desc) != HAL_OK)
    /* FIX ME */
  {
    Error_Handler();
  }
}

 

Then add the call in MX_GTZC_Init

static void MX_GTZC_Init(void)
{

  if (HAL_GTZC_TZSC_ConfigPeriphAttributes(GTZC_PERIPH_ICACHE_REG,
                                           GTZC_TZSC_PERIPH_SEC | GTZC_TZSC_PERIPH_NPRIV) != HAL_OK)
  {
    Error_Handler();
  }

  unsecure_sram1(NS_DATA_START, NS_DATA_LIMIT);
  unsecure_sram3(NS_DATA_START_2, NS_DATA_LIMIT_2);
}

 

Finally, in linker file replace

RAM (xrw) : ORIGIN = NS_DATA_START, LENGTH = NS_DATA_SIZE

by

RAM (xrw) : ORIGIN = NS_DATA_START_2, LENGTH = NS_DATA_SIZE_2

 

So, with these changes you can use SRAM3 instead of SRAM1.

Best regards

Jocelyn

 

View solution in original post

12 REPLIES 12
Jocelyn RICARD
ST Employee

Hello @Nitin ,

It is normal that it does not work.

If you check the region_defs.h you will see that SRAM1 is 192 KB and fully allocated to non secure.

Then you have SRAM2 of 64KB allocated for secure application.

Then you have SRAM3 that is 512KB on this STM32U585.

So, a solution could be to just use SRAM3:

RAM (xrw) : ORIGIN = _SRAM3_BASE_NS, LENGTH = 256KB/*NS_DATA_SIZE*/

 

Best regards

Jocelyn

Hi Jocelyn, thanks for the prompt reply

I have tried it out, along with this I have tried few other options as well. Below are the details,

1. RAM (xrw) : ORIGIN = _SRAM3_BASE_NS, LENGTH = 256KB/*NS_DATA_SIZE*/ (Only SRAM3 is being used for RAM purpose from starting address)

2. RAM (xrw) : ORIGIN = NS_DATA_START, LENGTH = 256KB/*NS_DATA_SIZE*/ (Combinedly SRAM1 and SRAM2 are being used for RAM purpose)

3. RAM (xrw) : ORIGIN = SRAM3_BASE_NS + SRAM3_S_SIZE, LENGTH = _SRAM3_SIZE_MAX (SRAM3 NS is being used for RAM purpose starting from NS location, this has worked for TFM but not working out with SBSFU)

 

 

I assume there is something else we have to additional to this to make it work. Could you please try it out at your end once.

Hello Nitin,

yes, I forgot to mention that point.

This is not a SBSFU environment issue. The usage of SRAM3 for non secure application depends on the configuration made in the secure application.

So, you need to update the secure application to set SRAM3 non secure.

Best regards

Jocelyn

Hi Jocelyn, are you talking about...

changing

// unsecure_sram1(NS_DATA_START, NS_DATA_LIMIT);

to

unsecure_sram1(SRAM3_NS, SRAM3_S_SIZE);

whereas

 

#define SRAM3_NS _SRAM3_BASE_NS + SRAM3_S_SIZE or

#define SRAM3_NS _SRAM3_BASE_NS

 

If so it is still not working out. Could you please tell me specific changes required for this to work.

Hello @Nitin,

I made a check on my side.

First, there is a small error in region_defs.h:

Line 213 and also line 220

Please replace 

#ifdef SRAM3_BASE

by 

#ifdef _SRAM3_BASE_NS

 

The SRAM3_BASE is actually not known when using gcc preprocessor on linker file.

 

After that you need to make duplicate and adapt this unsecure_sram1 function like this:

 

static void  unsecure_sram3(uint32_t start, uint32_t end)
{

  MPCBB_ConfigTypeDef MPCBB_desc;
  uint32_t regwrite = 0xffffffff;
  uint32_t index;
  uint32_t block_start = (start - SRAM3_BASE) / GTZC_MPCBB_BLOCK_SIZE;
  uint32_t block_end = block_start + ((end - start) + 1) / GTZC_MPCBB_BLOCK_SIZE;

  if (start & 0xff)
    /*  Check alignment to avoid further problem  */
    /*  FIX ME  */
    while (1);

  if (HAL_GTZC_MPCBB_GetConfigMem(SRAM3_BASE, &MPCBB_desc) != HAL_OK)
  {
    /* FIX ME */
    Error_Handler();
  }

  for (index = 0; index < SRAM3_SIZE / GTZC_MPCBB_BLOCK_SIZE; index++)
  {
    /* clean register on index aligned */
    if (!(index & 0x1f))
    {
      regwrite = 0xffffffff;
    }
    if ((index >= block_start) && (index < block_end))
    {
      regwrite = regwrite & ~(1 << (index & 0x1f));
    }
    /* write register when 32 sub block are set  */
    if ((index & 0x1f) == 0x1f)
    {
      MPCBB_desc.AttributeConfig.MPCBB_SecConfig_array[index >> 5] = regwrite;
    }
  }
  if (HAL_GTZC_MPCBB_ConfigMem(SRAM3_BASE, &MPCBB_desc) != HAL_OK)
    /* FIX ME */
  {
    Error_Handler();
  }
}

 

Then add the call in MX_GTZC_Init

static void MX_GTZC_Init(void)
{

  if (HAL_GTZC_TZSC_ConfigPeriphAttributes(GTZC_PERIPH_ICACHE_REG,
                                           GTZC_TZSC_PERIPH_SEC | GTZC_TZSC_PERIPH_NPRIV) != HAL_OK)
  {
    Error_Handler();
  }

  unsecure_sram1(NS_DATA_START, NS_DATA_LIMIT);
  unsecure_sram3(NS_DATA_START_2, NS_DATA_LIMIT_2);
}

 

Finally, in linker file replace

RAM (xrw) : ORIGIN = NS_DATA_START, LENGTH = NS_DATA_SIZE

by

RAM (xrw) : ORIGIN = NS_DATA_START_2, LENGTH = NS_DATA_SIZE_2

 

So, with these changes you can use SRAM3 instead of SRAM1.

Best regards

Jocelyn

 

Nitin
Associate III

Hi Jocelyn, thanks for details support. I have followed as you have mentioned and now I am able to accommodate my application into SRAM3. Compilation is happening successfully. And I could see build analyzer.

 

Nitin_0-1725386571117.png

But when I run my application I still see my code is not jumping into application.

 

Nitin_1-1725386662928.png

 

While with SRAM1 usage my application works file(limited the RAM usage)

Nitin_2-1725386715217.png

Any idea about this.

Thanks,

Nitin

Hello Nitin,

I provided the changes needed that should make your project work.

Please attach the debugger to the target without downloading anything, just symbols to understand where it fails

Best regards

Jocelyn

Nitin
Associate III

Hi Jocelyn, since past two months we are not able to debug TFM /SBSFU projects and we are getting errors. We have tried with multiple debuggers and devices.

Nitin_0-1725455611331.png

or

Nitin_1-1725456673475.png

 

We have followed below link initially, then we were able to debug, but now it's not happening.

 

https://youtu.be/rlmQhfXyYCQ?si=x84MhCet_-n1TJ3U

Hi Nitin,

I 'm sorry, I made a mistake in unsecure_ram3 code I provided you

Please replace

  uint32_t block_start = (start - SRAM3_BASE) / GTZC_MPCBB_BLOCK_SIZE;

 

by (just add _NS)

  uint32_t block_start = (start - SRAM3_BASE_NS) / GTZC_MPCBB_BLOCK_SIZE;

 

 

Best regards

Jocelyn