MPU Stack Protection

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Guys, could some explain to me how this works?

 

mpu_enty->size = 0x011

mpu_entry->addr​, points to the stat address of 4K of memory

// Check the base address: it must be aligned to the size of the region.
  // This test is written carefully to also work for the 4-GB case.
  if(!Test_align(mpu_entry->addr, 2 << (U32)mpu_entry->size))
    // ERROR: the input base address is not aligned to the size of the region.
    return(MPU_SETUP_ENTRY_INVALIDBASEADDR);

#define Test_align(val, n ) (!Tst_bits( val, (n) - 1 ) )

Last Edited: Mon. Jun 26, 2017 - 11:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That snippet of code comes from set_mpu_entry(,] in the ASF MPU 'driver'.


Are you asking why an MPU region size of (2^3) bytes does not work ?
(look at the 'Protection region sizes' table in the Memory Protection Unit section of the AVR32UC Technical Reference).


Are you asking what the Test_align(,) macro does ?
(Using your data it evaluates to v & 15 )

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's correct Mikech! addr points to a 4KByte Block of memory in SDRAM and size is MPU_REGION_SIZE_4KB​, I just don't understand how it is not working.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It appears to be a day for misreading base prefixes.
I misread your 0x011 to be decimal 3 instead of decimal 11. (I blame caffeine, lack thereof)
I suspect that you misread Table 7.1 in the AVR32UC Technical Reference where a 4 kbyte block has a 'size' of B'01011 which is decimal 11, not hex 11.