Hi
I can use some help in understanding how to configure MPC for M33. I uses an MPS2+ board with AN505 (IOTKit_CM33). I run the example TrustZone code which is available from uVision Pack installer.
Background: the device AN505 has SSRAM1 (4MB) and SSRAM3 (2MB). SSRAM1 is mapped at 1) 0x0000_0000 - 0x003F_FFFF (NS) 2) 0x0040_0000 - 0x007F_FFFF (NS) 3) 0x1000_0000 - 0x103F_FFFF (S) and 4) 0x1040_0000 - 0x107F_FFFF (S). SSRAM3 is mapped at 1) 0x2820_0000 - 0x283F_FFFF (NS) and 2) 0x3820_0000 - 0x383F_FFFF (S). SSRAM1 has a MPC block size of 128KB. SSRAM3 has a block size of 64KB.
We are configuring half of SSRAM1 to normal world and the whole SSRAM3 to normal world.
The example code shows
/* configure unsecure code area MPSSSRAM1 (0x00200000 - 0x003FFFFF) */ // blk_max = IOTKIT_MPCSSRAM1->BLK_MAX; /* = 0x1 */ // blk_cfg = IOTKIT_MPCSSRAM1->BLK_CFG; /* = 0xC */ // blk_size = 1UL << (blk_cfg + 5U); /* = 0x20000 = 128 kB, 4MB / 128kB = 32 bit*/ // blk_cnt = 0x200000U / blk_size; /* = 0x10 */ IOTKIT_MPCSSRAM1->CTRL &= ~(1UL << 8U); /* clear auto increment */ IOTKIT_MPCSSRAM1->BLK_IDX = 0; /* write LUT index */ IOTKIT_MPCSSRAM1->BLK_LUT = 0xFFFF0000UL; /* configure blocks. 0x00200000-0x003fffff: non-secure; 0x00000-0x1ffff: secure, alias to 0x10000000-0x101fffff*/ /* configure unsecure data area MPSSSRAM3 (0x28200000 - 0x283FFFFF) */ // blk_max = IOTKIT_MPCSSRAM3->BLK_MAX; /* = 0x1 */ // blk_cfg = IOTKIT_MPCSSRAM3->BLK_CFG; /* = 0xB */ // blk_size = 1UL << (blk_cfg + 5U); /* = 0x10000 = 64 kB, 2MB / 64 kB = 32 bit */ // blk_cnt = 0x200000U / blk_size; /* = 0x20 */ IOTKIT_MPCSSRAM3->CTRL &= ~(1UL << 8U); /* clear auto increment */ IOTKIT_MPCSSRAM3->BLK_IDX = 1; /* write LUT index */ IOTKIT_MPCSSRAM3->BLK_LUT = 0xFFFFFFFFUL; /* configure blocks */
This does not make sense to me:
1) SSRAM3 is 2MB. It should have 2048KB/64KB = 32 blocks. So, we should only need 1 BLK_LUT. So, we should set BLK_IDX = 0. But the code set BLK_IDX to 1.
2) In the comment of setting SSRAM1, it says "blk_cnt = 0x10". Is this an error? Shouldn't it be 0x400000/blk_size = 0x20. SInce it is just comment, I guess it does not matter anyway.
I am quite confused here. Thank you in advance for the clarification.