cancel
Showing results for 
Search instead for 
Did you mean: 

What is Address offset?

Vertinhol
Associate III

Hello, I have a Nucleo L476RG which I'm using for different projects, and I never gave an importance to the offset addresses that are written before every register in the reference manual.

Can anyone explain to me what are theses offsets.

1 ACCEPTED SOLUTION

Accepted Solutions

Each register has its address. This is a 32-bit mcu so registers' addresses tend to be 4 bytes apart, even if they don't occupy the full 32 bits. You calculate the registers' address by adding the peripheral's address to the offset.

But this in fact is not very important in practice. There is a header file for each STM32, for example for 'L476 this. You normally #include this file indirectly, through #include "stm32l4xx.h" - this assumes you have set properly the include paths and also added a -DSTM32L476xx switch to the command line when calling compiler - IDEs do this for you automagically.

The device-specific header file (look into it) contains both the peripherals' addresses, and also structs which in fact express the registers' offset. So, for programming, you don't need to know the address nor calculate it, for example to read out the LPTIM1's CNT register into variable "count" you simply write:

count = LPTIM1->CNT;

JW

View solution in original post

7 REPLIES 7

0693W00000SuDZDQA3.png 

JW

In older days there was one set of peripheral registers that might span 128 bytes in a simple MCU, say 8051. You might get multiple instances with different chip selects as you added chips to your board externally, say a pair of 8255 8-bit GPIO devices and an 8250 Serial USART, etc

These day you have multiple, identical, peripheral instances, parked through memory, the registers within these peripherals are a certain depth/offset into the address space.

The base address for USART1 and USART6 will be different, but the data and status registers are relatively in the same position.

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

> In older days

You know, I deeply believe in teaching the historical background, but how to do it so that it appeals to today's youth?

I usually start with Luigi Galvani's famous frog-leg twitching experiment, but by the time I got to that great story how the future Lord Kelvin saved the submarine cable, they appear to loose interest...

I'm kidding. But still, they simply don't like to hear about the old stuff.

JW

Vertinhol
Associate III

Thank you for the responses, so if I get it right, the registers where combined into one and separated by reserved bits, and the offset is how much of those reserved bits are there between every register.

Switching from Arduino to stm32 is a nightmare so far, the amount of time and effort that I spend to do simple things is way above what I was expecting, I even started to zoom on every single character in the reference manual to make sure I didn't skip any information, and that's how I got to the offset thing.

I hope that they are not very important because I don't want to bother my brain with other factors.

Well, I think I've seen that experiment where a dead frog twitches her leg when current passes through, but I never found that interesting because that's how muscles work after all, however, I don't know when that experiment happened but I believe based on the results, someone would have tried that to cure a man on wheelchair. And that's how they discovered the electric chair.

I should become a journalist if I can make stories like this, or join the British radio to decode Germans messages so I can read Lord's Kelvin cable Adventure.

Each register has its address. This is a 32-bit mcu so registers' addresses tend to be 4 bytes apart, even if they don't occupy the full 32 bits. You calculate the registers' address by adding the peripheral's address to the offset.

But this in fact is not very important in practice. There is a header file for each STM32, for example for 'L476 this. You normally #include this file indirectly, through #include "stm32l4xx.h" - this assumes you have set properly the include paths and also added a -DSTM32L476xx switch to the command line when calling compiler - IDEs do this for you automagically.

The device-specific header file (look into it) contains both the peripherals' addresses, and also structs which in fact express the registers' offset. So, for programming, you don't need to know the address nor calculate it, for example to read out the LPTIM1's CNT register into variable "count" you simply write:

count = LPTIM1->CNT;

JW

There are voids in the address space for the peripherals

Addresses of registers within the 4GB addressable space (32-bit)

printf("%p\n", &LPTIM1->CNT);

printf("%p\n", &SCB->VTOR);

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