<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>about structs</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/32708/about-structs</link><description> 
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</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: about structs</title><link>https://community.arm.com/thread/117707?ContentTypeID=1</link><pubDate>Fri, 30 Jan 2015 08:25:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:88675dd1-0ef2-48f4-a5ec-3dc15197c7a5</guid><dc:creator>Hamed Adldoost</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thank you very much.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: about structs</title><link>https://community.arm.com/thread/108065?ContentTypeID=1</link><pubDate>Fri, 30 Jan 2015 08:01:46 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f1746f53-937b-4e20-9321-f7eceae3fabc</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
I did give the answer to that question - but that also requires
that you know what a struct is in the C or C++ language.&lt;/p&gt;

&lt;p&gt;
DR and SR are two different members of the struct. Which means
that they have different offset within the struct. Which means they
will overlap different memory when the struct is placed &amp;quot;on top of&amp;quot; a
block of memory.&lt;/p&gt;

&lt;p&gt;
So writing to the DR field will result in a write to one address
in the memory, while writing to the SR field will result in a write
to another address in the memory. And after having properly aligned
the struct on top of the UART control registers, a write to the DR
field of the struct will correspond to a write to the UART control
register &amp;quot;DR&amp;quot;.&lt;/p&gt;

&lt;p&gt;
You access bits in a register of the UART controller by accessing
bits in a member of the struct. And you access bits in a member of
the struct the same way that you access bits in any int-type variable
in C or C++. How you do that? That&amp;#39;s part of a &amp;quot;beginners guide to C&amp;quot;
programming book.&lt;/p&gt;

&lt;p&gt;
Your questions really are very basic after you have learned the
concepts of a struct, of a pointer and of bit operations. How to
learn these concepts isn&amp;#39;t part of the Keil forum and isn&amp;#39;t specific
to any ARM or 8051 or PPC or x86 processor but something you should
solve by selecting a suitable book introducing you to the C
programming language. A number of such books can even be downloaded
for free. And it isn&amp;#39;t really meaningful to play with bits in
processor registers until you understand the basic language
constructs.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: about structs</title><link>https://community.arm.com/thread/82377?ContentTypeID=1</link><pubDate>Fri, 30 Jan 2015 07:40:19 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a9fd017c-59c9-43ac-84f4-a299dca38f4a</guid><dc:creator>Hamed Adldoost</dc:creator><description>&lt;p&gt;&lt;p&gt;
I have not yet find the answer to my Q. My question is that what
is the difference between SR and DR according to out definition in
the codes i mentioned, so how may the compiler refer to status
register when we do USART1-&amp;gt;SR ? is SR a predefined name for
compiler? otherwise there should be no difference between SR and DR
and other registers declared in the struct USART_TypeDef.&lt;br /&gt;
please advise me how to access bits of SR register. I have seen
declaration like USART1_SR_RXNE in some codes.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: about structs</title><link>https://community.arm.com/thread/69053?ContentTypeID=1</link><pubDate>Fri, 30 Jan 2015 07:04:52 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:568a1f9c-4259-441f-ba97-8783ede9693e</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
I&amp;#39;m not really sure I understand your question.&lt;/p&gt;

&lt;p&gt;
The struct has a number of fields, and the pointer will be
initialized to the address of the special function registers
controlling the UART.&lt;/p&gt;

&lt;p&gt;
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.&lt;/p&gt;

&lt;p&gt;
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.&lt;/p&gt;

&lt;p&gt;
So the definition of SR? It&amp;#39;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.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>