cancel
Showing results for 
Search instead for 
Did you mean: 

7 USART3 registers == 28 bytes. What are the other addresses in USART3 for?

MMust.5
Senior II

STM32F407 Discovery

 

 

typedef struct __UART_HandleTypeDef
{
USART_TypeDef *Instance;
UART_InitTypeDef Init;
const uint8_t *pTxBuffPtr;
uint16_t TxXferSize;
__IO uint16_t TxXferCount;
uint8_t *pRxBuffPtr;
uint16_t RxXferSize;
__IO uint16_t RxXferCount;
__IO HAL_UART_RxTypeTypeDef ReceptionType;
DMA_HandleTypeDef *hdmatx;
DMA_HandleTypeDef *hdmarx;
HAL_LockTypeDef Lock;
__IO HAL_UART_StateTypeDef gState;
__IO HAL_UART_StateTypeDef RxState;
__IO uint32_t ErrorCode;
} UART_HandleTypeDef;

 

I take the USART3 setting as an example.
The starting address for storing this UART_HandleTypeDef structure will be 0x4000 4800.
USART3 has 7 registers. Each register is 32 bits.
7*32==224/8==28 bytes
7 USART3 registers occupy 28 bytes.
These 7 registers are configured by the USART_TypeDef *Instance structure;
0x4000 4800 + 28 bytes== 4000 481C
0x4000 4800 ----- 4000 481C There are 7 registers in this address limit.

tim2.png

But USART3 is allocated a lot more addresses 0x4000 4800 - 0x4000 4BFF What's in there?
And most importantly, I'm wondering where it is stored:

 

UART_InitTypeDef Init;
const uint8_t *pTxBuffPtr;
uint16_t TxXferSize;
__IO uint16_t TxXferCount;
uint8_t *pRxBuffPtr;
uint16_t RxXferSize;
__IO uint16_t RxXferCount;
__IO HAL_UART_RxTypeTypeDef ReceptionType;
DMA_HandleTypeDef *hdmatx;
DMA_HandleTypeDef *hdmarx;
HAL_LockTypeDef Lock;
__IO HAL_UART_StateTypeDef gState;
__IO HAL_UART_StateTypeDef RxState;
__IO uint32_t ErrorCode;

 

And what does it set up? Or they are ordinary variables and are stored as ordinary data, while registers are not configured.
That is, there are only 7 registers in this address limit 0x4000 4800 - 0x4000 4BFF, right?
What is the rest of the space for?

15 REPLIES 15
LCE
Principal

Check your *.map file in the release or debug folder, search for "huart3" (or whatever you named it), there you will see its address and length.

Yes, of course, I may be wrong, I just wanted to explain how I see it.

See, I've simplified the code.

struct nr1
{
int CR1;
} Instance;

struct nr2
{
int BaudRate;
} Init;

struct nr3
{
int HAL_UART_STATE_RESET;
} ReceptionType;

struct common
{
struct nr1 Instance;
struct nr2 Init;
struct nr3 ReceptionType;

} UART_HandleTypeDef;
int main()
{
UART_HandleTypeDef.Instance.CR1=1;
UART_HandleTypeDef.Init.BaudRate=2;
UART_HandleTypeDef.ReceptionType.HAL_UART_STATE_RESET=3;
return 0;
}

The main thing to pay attention to here is the UART_HandleTypeDef structure.
There are 3 other structures in this structure.
And now the main thing: The information of the UART_HandleTypeDef structure is stored in memory in order, and not randomly.
That is, the information of structures will be stored in order in memory.
UART_HandleTypeDef.Instance.CR1=1;
UART_HandleTypeDef.Init.BaudRate=2;
UART_HandleTypeDef.ReceptionType.HAL_UART_STATE_RESET=3;

And you write that this information is stored somewhere in SRAM.

tim2.png

huart3.Init.BaudRate = 9600;
huart3 is the start address USART3 address 0x4000 4800
BaudRate is in the UART_HandleTypeDef structure and must come immediately after the registers.
I looked in Memory, but it doesn't happen.

tim2.png

> huart3.Init.BaudRate = 9600;
> huart3 is the start address USART3 address 0x4000 4800

Yes...


> BaudRate is in the UART_HandleTypeDef structure and must come immediately after the registers.

No...


> I looked in Memory, but it doesn't happen.

Yes, because the register area is not used for variables (UART_HandleTypeDef huart3) created by the user.

huart3 is a structure = lots of variables, and includes the pointer "Instance" to the hardware registers starting at USART3 address 0x4000 4800.
Just because the first member / variable of the struct Instance is a pointer, does NOT mean that the struct is placed there.

Again, check your map file, search the memory for huart3.Instance, which should have the value of 0x4000 4800, but is somewhere in SRAM, where variables are normally placed.

Sorry, but if you don't get it now, I can't explain it any better.

I understood everything, thanks.

tim2.png

If the address was stored in the UART_HandleTypeDef structure, then it would be as I described at the beginning))

I messed up something and thought that the address in the UART_HandleTypeDef structure is saved.

It's a POINTER, passing by ADDRESS

USART_TypeDef *Instance;

huart3 is a structure, in RAM, there's a pointer associating it with the UART3 peripheral's memory/registers.

The UART is implemented as logic gates, not RAM cells

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