Search code examples
embeddedstm32nucleo

why 0x40010800 + 0x0C equals 0x40010830?


I tried to access RCC_APB2ENR register as a first step to blink green led on stm32nucleo f103rb

then I added 0x0C to 0x40010800(RCC base address).

The expected result was 0x4001080C but the actual result was 0x40010830!!!

It seems 0x0C was left shifted twice but I can't understand why this thing happened.

And even in Ubuntu, the same thing happened.

please let me know

board : stm32 nucleo f103rb IDE : uVision 5


Solution

  • RCC_BASE points to unsigned int. On your platform size of this type is 4 bytes.

    While adding or subtraction to pointers you are increasing (or decreasing) address by operand multiplied by size of element.

    For details looks Pointer Arithmetic