cancel
Showing results for 
Search instead for 
Did you mean: 

OctoSPI mem-mapped mode not working if TZ enabled on STM32H563

JungerGott
Associate

Hi,
I'm working on the evalboard of the STM32H563. With a plain project I'm able to activate the memory mapped mode of a plugged nor-flash.
If I change the project to have Trustzone activated and divided the application in secure/non-secure part, I'm not able to activate the memory mapped mode. The communication to the flash is basically working because I can read the ID. The hal functions don't give any error, so I expect that everything should work.

Has anybody an idea what the problem can be?

 

Best regards,
Stefan

 

7 REPLIES 7
rdl_42
Associate II

Stefan,

I have the same problem on an STM32U5G9 processor.  I'm reading 0x00's from my flash in non-secure mode without any faults for secure access from non-secure.  Flash is mapped to 0x9000'0000 through 0x9400'0000 via octospi1.  I've seen some indication that the TrustZone security controller needs to have the watermark configuration set for external flash access but haven't had any success yet.

Have you made any progress on this?  Anyone else have any guidance?

Thanks,

-Rob

JungerGott
Associate

If you go in CubeMx in menu Tools/Memory Management, have you added the OctoSpi memory range as a NS application region?

 

 

Jocelyn RICARD
ST Employee

Hello,

In TrustZone environment, external memory should be mapped as non secure in SAU configuration.

If you leave SAU disabled at set ALLNS bit is should be enough because IDAU maps this region as non secure by default. If you enable SAU, then all memory is secure by default. You need then to create a SAU region for external memory and set it as non secure.

Second step, is the GTZC configuration. For external memories you need to setup the MPCWM.

In Table 31 of STM32U5 RM you can see which MPCWM to use. For instance of OSPI1 this is MPCWM1.

You have an example of usage of MPCWM here:

STM32Cube_FW_U5_V1.8.0\Projects\STM32U575I-EV\Examples\GTZC\GTZC_MPCWM_IllegalAccess_TrustZone\

Best regards

Jocelyn

My secure portion is actually a third party bootloader that doesn't appear to use CubeMX.  I believe I have correctly added OctoSpi memory range as NS manually.

-Rob

Jocelyn,

I have modified the example you referenced for my specifics, but am not seeing the MPCWM registers change when I step through HAL_GTZC_TZSC_MPCWM_ConfigMemAttributes() with the IAR C-Spy debugger.  I am building with STM32Cube_FW_V1.5.0.  See code below.

Any suggestions?

Thanks,

-Rob


#include <stm32u5xx_hal_gtzc.h>

/***************** Adapted from STM example code ***************************/

/**
* @brief  Configure SAU and MPCWM1 in initial conditions
* @note   SAU and MPCWM1 are setup to allow non-secure access
*         from 0x6000'0000 to 0xAFFF'FFFF.
* @retval None
*/
void SECURE_SAU_MPCWM_SetInitConfig(void)
{
  MPCWM_ConfigTypeDef MPCWM_Desc;
  /* protect this SAU/MPCWM1 setup section from any fault interrupt occurrence */
//  __disable_fault_irq();

  /* Set first half of memory as non-secure, second half as secure */

  /* SAU update based on partition_stm32u5xx.h used at setup      */
  /* Set all of SAU region 4 : (0x60000000-0xAFFFFFFF) as non-secure */
  SAU->RNR  = (4 & SAU_RNR_REGION_Msk);
  SAU->RBAR = (FMC_BASE & SAU_RBAR_BADDR_Msk);
  SAU->RLAR = (  ((FMC_BASE + 0x4FFFFFFFUL) & SAU_RLAR_LADDR_Msk)
               | ((0 << SAU_RLAR_NSC_Pos) & SAU_RLAR_NSC_Msk)
               | 1U);   // enable region

  /* MPCWM2: set one non-secure area on first half */
  /* The second half is set as secure by default */
  MPCWM_Desc.AreaId     = GTZC_TZSC_MPCWM_ID1;      // OSPI1 starting at 0x9000'0000
  MPCWM_Desc.Offset     = 0 * GTZC_TZSC_MPCWM_GRANULARITY_1;        // 128 KB granularity
  MPCWM_Desc.Length     = 64 * 4 * GTZC_TZSC_MPCWM_GRANULARITY_1;   // 64 MB
  MPCWM_Desc.AreaStatus = ENABLE;
  MPCWM_Desc.Attribute  = GTZC_TZSC_MPCWM_REGION_NSEC;
  MPCWM_Desc.Lock       = GTZC_TZSC_MPCWM_LOCK_OFF;

  if (HAL_GTZC_TZSC_MPCWM_ConfigMemAttributes(FMC_BASE, &MPCWM_Desc) != HAL_OK)
  {
    /* Initialization error */
    while(1);
  }

  /* re-enable fault interrupt occurrences after this SAU/MPCWM2 setup section */
//  __enable_fault_irq();
}
/***************** Adapted from STM example code ***************************/


int main(void)
{
    /* Initialise all required board hardware. */
    hal_init();

SECURE_SAU_MPCWM_SetInitConfig();

To close out my stm32u5g9 issue, I found that the STZC clock was not enabled.  I also setup a separate SAU region just for the ospi from 0x9000'0000 to 0x9FFF'FFFF.

I am now able to read external flash from non-secure mode.

-Rob

Hello @rdl_42 ,

thank you for your update.

Best regards

Jocelyn