Skip to main content
Graduate II
August 28, 2024
Solved

RAM size is not increasing and giving runtime error

  • August 28, 2024
  • 4 replies
  • 2588 views

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 

    This topic has been closed for replies.
    Best answer by Jocelyn RICARD

    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

     

    4 replies

    ST Employee
    August 28, 2024

    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

    NitinAuthor
    Graduate II
    August 29, 2024

    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.

    ST Employee
    August 29, 2024

    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

    NitinAuthor
    Graduate II
    September 3, 2024

    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

    ST Employee
    September 4, 2024

    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

    ST Employee
    September 4, 2024

    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

    NitinAuthor
    Graduate II
    September 4, 2024

    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

    NitinAuthor
    Graduate II
    September 4, 2024

    Hi Jocelyn, SRAM3 application run it is working out now. I did a small change in unsecure_sram3() definition as below

     

     

    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_NS) / 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_NS, &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_NS, &MPCBB_desc) != HAL_OK)
        /* FIX ME */
      {
        Error_Handler();
      }
    }
     
     
    For the sake of completeness of the ticket, I did two more changes in STM32U585AIIX_FLASH.ld as below,
     
    .testprotection NS_DATA_START : to be replaced with  .testprotection NS_DATA_START_2:
    and
    .data (NS_DATA_START+NS_NO_INIT_DATA_SIZE) : AT (__etext) to be replaced with  .data (NS_DATA_START_2+NS_NO_INIT_DATA_SIZE) : AT (__etext)
     
     
    But please cross check at your end why debugging is not working since past some time, even with untouch ST release package.
     
    I really appreciate your kind support to us. Thank you so much once again.
    Nitin
    ST Employee
    September 4, 2024

    Hello Nitin,

    The change in HAL_GTZC_MPCBB_GetConfigMem was not mandatory but this is cleaner. 

    Other changes are necessary indeed. I'm sorry I forgot to mention them. If you can edit your post for test protection to add _2 at the end.

    For debugging, you must disable the RDP at least. Please also disable HDP and WRP.

    If you disabled protection debugger should be able to attach.

    Best regards

    Jocelyn

     

    NitinAuthor
    Graduate II
    September 5, 2024

    Hi Jocelyn,

    I missed doing that, edited now.

    I will try debug thing. Thanks for the clue.

    Closing this ticket now. Much thanks for the support.

     

    Regards

    Nitin