cancel
Showing results for 
Search instead for 
Did you mean: 

How do I select a base address in Memory protection unit?

Muzahir Hussain
Associate III
Posted on November 05, 2017 at 12:04

I am trying to configure MPU in STM32F103RB using ARM Information Center. It says there that '

The base address must be aligned to the size of the region. For example, a 64KB region must be aligned on a multiple of 64KB, for example, at

0x00010000

or

0x00020000

.' Here's a link to that page,

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Cihjddef.html

.

What does this mean?

I want to select a region of 64 bytes starting from 0x20000000. How can I do this?

#stm32-nucleo #memory-protection #stm32f103rb
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on November 05, 2017 at 18:59

You do seem to be creating complication where there is none. It is a test of if an address is valid. The base address needs the order bits to be zero, the range comparator in the processor looks only at the high order bits, so the address provided needs to be suitably aligned.

if ((0x20000000 % 64) == 0)

  puts('Address is usable');

else

  puts('Address is NOT usable');

So for 64 bytes valid addresses would look like

0x20000000

0x20000040

0x20000080

0x200000C0

0x20000100, etc

If this is unclear perhaps consult with a teacher or tutor who understands binary math and micro-controllers.

More generally

if ((MMURegionAddress % MMURegionSize) == 0)

  puts('Address is usable');

else

  puts('Address is NOT usable');

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4
Posted on November 05, 2017 at 14:43

In the first case

BaseAddr % Size == 0, where Size is a power of two

This would be true for 0x20000000[0x00040] which would mean 0x20000000..0x2000003F

But you could NOT do 0x20002000[0x4000]

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 05, 2017 at 17:12

How do I calculate BaseAddr % SIze?

In my case 64 is 2^6, so how do I calculate,

0x20000000 % 6?

Posted on November 05, 2017 at 18:59

You do seem to be creating complication where there is none. It is a test of if an address is valid. The base address needs the order bits to be zero, the range comparator in the processor looks only at the high order bits, so the address provided needs to be suitably aligned.

if ((0x20000000 % 64) == 0)

  puts('Address is usable');

else

  puts('Address is NOT usable');

So for 64 bytes valid addresses would look like

0x20000000

0x20000040

0x20000080

0x200000C0

0x20000100, etc

If this is unclear perhaps consult with a teacher or tutor who understands binary math and micro-controllers.

More generally

if ((MMURegionAddress % MMURegionSize) == 0)

  puts('Address is usable');

else

  puts('Address is NOT usable');

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 05, 2017 at 19:58

Thanks