<?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>struct problem / usart</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/22594/struct-problem-usart</link><description> 
I&amp;#39;m working with the RealView Compiler and have a strange problem
with the usart. 

 
I&amp;#39;ve installed one typedef struct in a headerfile - when I try to
install a array of this struct in the c-file (as global struct
variable) - I&amp;#39;m not able to get some</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/154527?ContentTypeID=1</link><pubDate>Sat, 24 Nov 2007 07:13:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f120df57-1e43-421a-b7ef-1319980b233f</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
If the compiler is fast in comparison to the project size, and you
want to be lazy, you might add most of your includes into a &amp;quot;global&amp;quot;
header file and include from all other source files.&lt;/p&gt;

&lt;p&gt;
If the compiler supports precompiled headers, then it is normally
an advantage to make user of a global master header file.&lt;/p&gt;

&lt;p&gt;
Anything that shouldn&amp;#39;t be generaly visible may then be put into
the single source file that uses them, or a specific header file that
is only included for the set of source files that are allowed to know
this extra information.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/153993?ContentTypeID=1</link><pubDate>Sat, 24 Nov 2007 06:41:34 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:32a70d4c-3529-4bf8-a32f-ac2e6a02fd5a</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
yes you are totally right.... but could you explain me how I have
to organize all c-files, using nearly the same headerfiles?&lt;/p&gt;

&lt;p&gt;
e.g. there&amp;#39;s a lib-headerfile from Keil, which I used in every
c-file to get access to registers with inline functions...&lt;/p&gt;

&lt;p&gt;
Is it a better way to include this headerfile in every c-file or
is it much better to have one headerfile which includes all other
headerfiles?&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
tobi&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/153995?ContentTypeID=1</link><pubDate>Sat, 24 Nov 2007 05:48:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b8240587-ad7a-4792-a1c3-06fca17c2ee3</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
at the moment I have one headerfile where all other headerfiles
where included - so in every c-file I only include this
headerfile...&lt;/p&gt;

&lt;p&gt;
If I use in one of this heatherfiles to define my struct -&amp;gt;
then I have to use extern to define a variable, haven&amp;#39;t I? So that
could be the reason for my strange errors?&lt;/p&gt;

&lt;pre&gt;
header.h

#include header1.h
#include header2.h
&lt;/pre&gt;
&lt;pre&gt;
header1.h

typedef struct {...}STRUCT_VAR;
extern STRUCT_VAR struct_array[];
&lt;/pre&gt;
&lt;pre&gt;
header1.c

#include &amp;lt;header.h&amp;gt;
STRUCT_VAR struct_array[NBR_STRUCT];
&lt;/pre&gt;

&lt;p&gt;
BTW, is this a common way? Or is it better to have in every c-file
all #include &amp;lt;header.h&amp;gt; which are needed in the specific
c-file?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/153375?ContentTypeID=1</link><pubDate>Sat, 24 Nov 2007 05:44:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d9aeb7fc-5cb3-429d-98a6-6296f378f9ec</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
I&amp;#39;d have thought that you&amp;#39;d get an error or at least a warning if
that were the case.&lt;/p&gt;

&lt;p&gt;
The questions you&amp;#39;re asking suggest that you&amp;#39;re very much a newbie
to &amp;#39;C&amp;#39; programming - yes?&lt;br /&gt;
In this case, it is much more likely to be due to errors in your &amp;#39;C&amp;#39;
than any hardware problems...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/153376?ContentTypeID=1</link><pubDate>Sat, 24 Nov 2007 05:33:55 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7dd14621-0881-41a9-8d5d-3a52eb76c63f</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Most programs consists of more than a single C file.&lt;/p&gt;

&lt;p&gt;
extern mystruct_t myarray[] in the header file allows other C
files (that includes the header file) to know about the existence of
a global variable myarry.&lt;/p&gt;

&lt;p&gt;
If your myarray variable is not expected to be known to other
source files, then you should probably hide it. No information about
it in the header file, and writing:&lt;/p&gt;

&lt;pre&gt;
static mystruct_t myarray[NUMBER_OF_X_ENTRIES];
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
in the single source file where the variable should be used. This
will hide the variable from the linker. To the linker, it will just
be an anonymous block of memory (together with all other static
variables in the same source file) without any name.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/152688?ContentTypeID=1</link><pubDate>Sat, 24 Nov 2007 05:02:30 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c82a20b5-0277-4540-a283-24e01c891426</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
thanks for the useful information..&lt;/p&gt;

&lt;p&gt;
Is is possible that the struct is too large for the data segment?
What are the steps to install the struct in the external sram?&lt;/p&gt;

&lt;pre&gt;
extern mystruct_t myarray[];
&lt;/pre&gt;

&lt;p&gt;
Is this line of code necessary that the code is working? I only
have the typedef struct definition in the headerfile.&lt;/p&gt;

&lt;p&gt;
tobi&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/151917?ContentTypeID=1</link><pubDate>Sat, 24 Nov 2007 04:41:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3738e3c4-9e6b-4853-81d2-102e7702f27d</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
There are many places where you may make mistakes when using
#define, and we don&amp;#39;t have access to the full code.&lt;/p&gt;

&lt;p&gt;
But you should avoid using #define with lower-case symbol names.
It is common practice to always use upper-case letters for a #define,
just to very clearly inform other users that they may need to look
closer at the definition to be able to understand the code.&lt;/p&gt;

&lt;p&gt;
The name &amp;#39;size&amp;#39; for a #define would also make any declaration for
a parameter or local variable with the name &amp;#39;size&amp;#39; to fail or give
very unpredictable results. The code:&lt;/p&gt;

&lt;pre&gt;
int copy_struct(void* p,unsigned size) {
}
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
would be parsed by the compiler as the broken code sequence:&lt;/p&gt;

&lt;pre&gt;
int copy_struct(void* p,unsigned 20) {
}
&lt;/pre&gt;

&lt;p&gt;
You should also avoid the use of generic names for your defines -
they are not defined in any name space, so generic names gives a
large chance of collisions.&lt;/p&gt;

&lt;p&gt;
In your header file, you may write something like:&lt;/p&gt;

&lt;pre&gt;
#define SIZE_OF_X 20
#define NUMBER_OF_X_ENTRIES 10

typedef struct {
    unsigned char data[SIZE_OF_X];
} mystruct_t;

extern mystruct_t myarray[];
&lt;/pre&gt;

&lt;p&gt;
In your source file, you may write something like:&lt;/p&gt;

&lt;pre&gt;
#include &amp;quot;myheader.h&amp;quot;
mystruct_t myarray[NUMBER_OF_X_ENTRIES];
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/147375?ContentTypeID=1</link><pubDate>Sat, 24 Nov 2007 02:26:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:59160375-23eb-4fb1-92ba-6377cf605304</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
now I found the problem - it was the struct but I don&amp;#39;t know
why...&lt;/p&gt;

&lt;p&gt;
I use the AT91SAM7S256 processor - (sorry for missing this
message) - I think that the problem is undependent of the prozessor..
I work with Realview MDK.&lt;/p&gt;

&lt;pre&gt;
#define size 20
&lt;/pre&gt;
&lt;pre&gt;
typedef struct my_struct {

          unsigned char Data[size];
}MY_STRUCT;
&lt;/pre&gt;

&lt;p&gt;
If I write Data[20] - everything is working fine - but if I use
the #define, the usart and anything else which use a clock doesn&amp;#39;t
work...&lt;/p&gt;

&lt;p&gt;
It seems that the #define is not configurated when I enter the
c-file with the global variable of the struct&lt;/p&gt;

&lt;pre&gt;
MY_STRUCT struct_array_global[number];
&lt;/pre&gt;

&lt;p&gt;
number is a define too...&lt;/p&gt;

&lt;p&gt;
In a local function I only init a ptr to the head of this global
array.&lt;/p&gt;

&lt;p&gt;
Maybe everybody of you coud explain me why the version with the
#define size don&amp;#39;t work...&lt;/p&gt;

&lt;p&gt;
best regards&lt;br /&gt;
tobi&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/146144?ContentTypeID=1</link><pubDate>Sat, 24 Nov 2007 01:55:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:09f1326f-f710-49ab-89f8-39a7d19efaff</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
I asked you to specify all required facts about your system and
your problem, or we will not be able to answer any questions.&lt;/p&gt;

&lt;p&gt;
You haven&amp;#39;t even told us what processor you run. It seems to be an
Atmel ARM chip but you are spending a huge amount of time trying to
avoid facts. Why are you so against facts? Because you specifically
don&amp;#39;t want any help?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/144319?ContentTypeID=1</link><pubDate>Fri, 23 Nov 2007 10:58:19 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:10e15982-4317-49ab-bc08-70e720a543ff</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
If I try to see if the clock is ready - within my code&lt;/p&gt;

&lt;p&gt;
it fails&lt;/p&gt;

&lt;pre&gt;
while ( ! (AT91C_BASE_PMC-&amp;gt;PMC_SR &amp;amp; AT91C_PMC_MOSCS) );
&lt;/pre&gt;

&lt;p&gt;
/* Waits for the Main Oscillator to be stabilized */&lt;/p&gt;

&lt;p&gt;
But within the startup code there must be the main oscillator
stable or not???&lt;/p&gt;

&lt;p&gt;
tobi&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/141898?ContentTypeID=1</link><pubDate>Fri, 23 Nov 2007 09:34:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e844e77e-cf0d-4eb4-b7da-01ff4aafca00</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
wow I was able to post something....&lt;/p&gt;

&lt;p&gt;
If I try to ask the state of the PMC System Clock Status Register
- no bit is set (so no clock is enabled) -&amp;gt; but nothing happens if
I do that by foot... usually that would be done in the startup code
file...&lt;/p&gt;

&lt;p&gt;
Could there be a software problem? I killed something during the
programming?? Os is it more likely a hardware problem?&lt;/p&gt;

&lt;p&gt;
tobi&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/138625?ContentTypeID=1</link><pubDate>Fri, 23 Nov 2007 09:30:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fdace731-11ce-4b73-bbb2-6905e2c6035f</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
I think the problem is the clock.... nothing works (both rs232,
timer interrupts and so on...)&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/135208?ContentTypeID=1</link><pubDate>Fri, 23 Nov 2007 02:39:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8910932c-33aa-4e96-900e-a5953c4cd31e</guid><dc:creator>Per Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Excuse me for pointing it out but you have made a number of posts
with assumptions and guesses and request for answers.&lt;/p&gt;

&lt;p&gt;
But you haven&amp;#39;t spent any time posting any facts.&lt;/p&gt;

&lt;p&gt;
We don&amp;#39;t know how large stack size you have. We haven&amp;#39;t managed to
figure out if you are consuming any stack space by recursive calls or
by large auto variables.&lt;/p&gt;

&lt;p&gt;
We don&amp;#39;t know how large your arreay is, or exactly how it is
declared.&lt;/p&gt;

&lt;p&gt;
You haven&amp;#39;t given a really clear description of exactly what
fails, and your reasoning why it shouldn&amp;#39;t fail.&lt;/p&gt;

&lt;p&gt;
How will people be able to help unless you clearly specify all
facts about the problem?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/124263?ContentTypeID=1</link><pubDate>Fri, 23 Nov 2007 01:36:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:450d1f67-98ce-4cd7-b03d-e6a3e9732361</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
ok - I tried to initialize the struct array - and get the same
error... no data messages via the usart...&lt;/p&gt;

&lt;p&gt;
so I think the problem would be that the data segment array is too
small - how can I make it bigger??? Or is there a better solution
because the struct array has up to 50 members -&amp;gt; so it is not so
small but I must be able to get access to this struct array from more
c-functions within one c-file...&lt;/p&gt;

&lt;p&gt;
Is it possible to store the struct array within the external ram?
How could I do that?&lt;/p&gt;

&lt;p&gt;
tobi&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/113437?ContentTypeID=1</link><pubDate>Fri, 23 Nov 2007 01:07:17 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:105a76c2-75d0-4e48-b635-38ad7eee6449</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
could there be a problem with to less stack size?&lt;/p&gt;

&lt;p&gt;
I mean I only install a ptr to the first element of the struct
array... that&amp;#39;s all...&lt;/p&gt;

&lt;p&gt;
Could it be that I override something which is used by the usart??
Is there a difference when I install the struct global or within a
function? Is the array stored in another place within the
ram-area?&lt;/p&gt;

&lt;p&gt;
tobi&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/99971?ContentTypeID=1</link><pubDate>Fri, 23 Nov 2007 00:59:58 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:120f16e6-a280-4bf2-8892-7edd9caee24b</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
yes - there are no warnings or errors...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/88707?ContentTypeID=1</link><pubDate>Fri, 23 Nov 2007 00:58:28 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4165eeaa-6a55-4ff1-a0f7-e64ddd94019d</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
Does the project build cleanly; ie with zero errors and zero
warnings?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct problem / usart</title><link>https://community.arm.com/thread/49031?ContentTypeID=1</link><pubDate>Fri, 23 Nov 2007 00:55:34 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6e777727-5406-4983-9f8d-8c8b1bdb7d7a</guid><dc:creator>tobi schultz</dc:creator><description>&lt;p&gt;&lt;p&gt;
I installed one ptr to the array within a function (when the array
is installed within this function, too -&amp;gt; everything works)&lt;/p&gt;

&lt;p&gt;
When I installed the array global and use one ptr within this
function to point to the array -&amp;gt; no messages over the usart&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>