about structs

Hi,
I am new to C and Keil, However I wish to know more about the c programming in keil especially developing programs for STM32. My question is about USART1. I see that in file named stm32f10x_map.h definition for USART is given like:

typedef struct
{
  vu16 SR;
  u16  RESERVED0;
  vu16 DR;
  u16  RESERVED1;
  vu16 BRR;
  u16  RESERVED2;
  vu16 CR1;
  u16  RESERVED3;
  vu16 CR2;
  u16  RESERVED4;
  vu16 CR3;
  u16  RESERVED5;
  vu16 GTPR;
  u16  RESERVED6;
  vu16 hamed;
} USART_TypeDef;


and also USART1 is defined as a pointer to this struct like:

#ifdef _USART1
  EXT USART_TypeDef           *USART1;
#endif /*_USART1 */


but later I see in file USART.c a command like:

USART1->SR &= ~USART_FLAG_RXNE


My question is that where does SR defined for the compiler? as I see it is only defined as a vu16 type in USART_TypeDef. Does compiler differ between SR and DR or BRR ,etc.? How?

Parents
  • I'm not really sure I understand your question.

    The struct has a number of fields, and the pointer will be initialized to the address of the special function registers controlling the UART.

    So using the pointer and write to a field in the struct will result in a write to the memory address that corresponds to that register in the UART device.

    vu16 is just a nice way of telling that the struct member - which maps on top of a UART register - is a 16-bit unsigned, and that it is volatile so the compiler must generate code that always performs memory accesses instead of caching any value in processor registers.

    So the definition of SR? It's just defined in the struct as basically how many bytes from the start of the struct. And the pointer is set to the start of the memory range that contains the UART control registers. So this means that the SR field of the struct gets mapped on top of the SR register in the UART device.

Reply
  • I'm not really sure I understand your question.

    The struct has a number of fields, and the pointer will be initialized to the address of the special function registers controlling the UART.

    So using the pointer and write to a field in the struct will result in a write to the memory address that corresponds to that register in the UART device.

    vu16 is just a nice way of telling that the struct member - which maps on top of a UART register - is a 16-bit unsigned, and that it is volatile so the compiler must generate code that always performs memory accesses instead of caching any value in processor registers.

    So the definition of SR? It's just defined in the struct as basically how many bytes from the start of the struct. And the pointer is set to the start of the memory range that contains the UART control registers. So this means that the SR field of the struct gets mapped on top of the SR register in the UART device.

Children
More questions in this forum