<?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>Program with initialised global variables does not run</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/25738/program-with-initialised-global-variables-does-not-run</link><description> 
Experts, I have a &amp;#39;C&amp;#39; program that contains an array of around 10
unsigned int&amp;#39;s. If I initialise it during the declaration, the code
never enters main() (I placed a breakpoint on the first instruction
inside my main() but it never got hit). 
unsigned</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/151309?ContentTypeID=1</link><pubDate>Thu, 08 Oct 2009 02:56:19 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cee788fb-b0e7-484d-ae19-a222bce14c3a</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
Here: &lt;a href="http://www.keil.com/support/man/docs/c51/c51_ap_init.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_ap_init.htm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
Handling of a Watchdog is specifically mentioned...&lt;/p&gt;

&lt;p&gt;
(in almost the way that Per suggested)&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/142373?ContentTypeID=1</link><pubDate>Thu, 08 Oct 2009 02:53:43 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:093dce34-0307-403c-9535-469a002284cd</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;I faced the same (watch dog causing reset) problem&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
That is &lt;i&gt;&lt;b&gt;not&lt;/b&gt;&lt;/i&gt; a problem - that is the intended
behaviour of a watchdog!&lt;/p&gt;

&lt;p&gt;
If your code is leaving it too long before &amp;quot;kicking&amp;quot; the watchdog,
then the &lt;i&gt;problem&lt;/i&gt; lies in the code - not the watchdog!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/146412?ContentTypeID=1</link><pubDate>Thu, 08 Oct 2009 02:43:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ddfa61f2-d65a-4e05-93c0-47003cb0f697</guid><dc:creator>Jack Sprat</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;there is a caveat: the Keil &amp;#39;preprocessing&amp;#39; do not kick the
puppy and thus with these chips you need to muzzle the puppy in
startup.a51 and release it at the top of main&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Try reading the instructions in init.a51 instead.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/152071?ContentTypeID=1</link><pubDate>Wed, 07 Oct 2009 12:12:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:82f9cc38-c0a3-47f8-a88d-46a71d6bfc3b</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;quot;that would require, lots and lots of versions.&amp;quot;&lt;br /&gt;
Not at all. All they need is for the RTL to call a helper function
for kicking, and expecting you to supply such a function.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/147535?ContentTypeID=1</link><pubDate>Wed, 07 Oct 2009 11:24:59 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:efbf59d8-0ba3-4b58-b10c-827714d05d1f</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Keil really should consider releasing a version of the library
that kicks the watchdog during the startup operations.&lt;/i&gt;&lt;br /&gt;
that would require, lots and lots of versions.&lt;br /&gt;
&lt;i&gt;A watchdog works best if it can be turned on as soon as possible -
best is that it is turned on by a fuse, so it is turned on before the
first instruction is processed.&lt;/i&gt;&lt;br /&gt;
I do not have a problem with a WD that can be turned off, if turning
it off is complex enough to make the likelyhood of runaway doing so
is less then 1/1000000&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/146410?ContentTypeID=1</link><pubDate>Wed, 07 Oct 2009 10:37:16 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:63223a3b-0965-4af4-93af-c5e0fde6dad1</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
It is always problematic to have a watchdog that runs too fast.
For most applications it will be ok to have a watchdog timeout of
1-10 seconds. For a processor that can&amp;#39;t decompress all variables
within one watchdog cycle, Keil really should consider releasing a
version of the library that kicks the watchdog during the startup
operations. A watchdog works best if it can be turned on as soon as
possible - best is that it is turned on by a fuse, so it is turned on
before the first instruction is processed.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/144688?ContentTypeID=1</link><pubDate>Wed, 07 Oct 2009 10:26:50 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f89ee4f8-d630-4aab-80ba-ba4e46a97bfd</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;startup.c&lt;/i&gt; no such thing it is startup.a51&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;But turning off the watchdog is normally not something you want
to do. In real life, the watchdog is something you should be ready to
pay extra for, because you really do want your hardware to be
restarted in case something goes wrong.&lt;/i&gt;&lt;br /&gt;
there is a caveat: the Keil &amp;#39;preprocessing&amp;#39; do not kick the puppy and
thus with these chips you need to muzzle the puppy in startup.a51 and
release it at the top of main&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/142383?ContentTypeID=1</link><pubDate>Wed, 07 Oct 2009 08:24:02 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7040ba63-4979-43b3-a9ca-308168fae79b</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
But turning off the watchdog is normally not something you want to
do. In real life, the watchdog is something you should be ready to
pay extra for, because you really do want your hardware to be
restarted in case something goes wrong.&lt;/p&gt;

&lt;p&gt;
Your code may be ok, but if they mount your hardware besides a
huge contactor to turn on the lights for a sports stadium, your
hardware can go into a spin when the contactor gets activated. It
isn&amp;#39;t always so easy to test that the electronics can handle big
peaks on the supply or signal wires or can survive strong EMI, unless
you have very special test equipment or sends it to a laboratory for
testing. The watchdog is there as a final resource to _maybe_ solve
the problem if something goes wrong. I write _maybe_ because a
watchdog can&amp;#39;t solve a latchup problem. For a latchup, the affected
chip must be without power for a significant amount of time - it can
take days without power for the latchup to release.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/131822?ContentTypeID=1</link><pubDate>Wed, 07 Oct 2009 07:54:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:17c56407-11fa-4f9b-af8b-9907b4e3e131</guid><dc:creator>Ravi Kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Ganesh,&lt;/p&gt;

&lt;p&gt;
Even I faced the same(watch dog causing reset) problem while
working for FSM using silabs controller and SDCC compiler. Controller
was getting reset continuously.&lt;/p&gt;

&lt;p&gt;
After many trials I finally disabled the watchdog in the compiler
startup.c and the result is positive.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/130515?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2009 08:20:15 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:33df5d26-c095-4270-8543-c3ed116b1ee9</guid><dc:creator>Ganesh Okade</dc:creator><description>&lt;p&gt;&lt;p&gt;
Gentlemen: Thank you again for your responses.&lt;/p&gt;

&lt;p&gt;
As suspected by Mr. Westermark, the problem indeed was that the
watchdog was causing a reset. I looked at the MCU manual and found
that the watchdog on this chip is enabled on reset. I moved the code
to disable the watchdog from main() to startup.a51 and now every
thing works fine!&lt;/p&gt;

&lt;p&gt;
I really appreciate your time taken to help me out.&lt;/p&gt;

&lt;p&gt;
Regards,&lt;br /&gt;
Ganesh Okade&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/125610?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2009 02:30:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:851606b3-8283-4d51-a138-af8bb6aa4f74</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;But that does not imply that the processor has hard-coded
stack bytes&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Sorry - that&amp;#39;s what I meant.&lt;/p&gt;

&lt;p&gt;
The 8051 doesn&amp;#39;t have a dedicated &amp;quot;STACK&amp;quot; space in the same way
that it has DATA space and CODE space and XDATA space, etc...&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;In some situations, a program may look like it is working even
when variables are stored overlapping with the minimum required stack
space.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
For an analogy, think of building sandcastles on the beach: if you
have all your fun between tides, you will be fine; if the tide comes
in while you&amp;#39;re still trying to build your sandcastle, you will be in
trouble...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/115100?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2009 01:35:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6ec5501b-ea2b-41ba-abd6-fd3179eed489</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Of course there are such a thing as &amp;quot;stack space&amp;quot;. But that does
not imply that the processor has hard-coded stack bytes but
represents the memory region(s) the application require to handle
worst-case nesting/state saves.&lt;/p&gt;

&lt;p&gt;
Most processor architectures requires a RAM address range to be
shared between stack and variables, and will get into trouble
depending on the amount of variables that gets allocated into this
RAM address range or if the MMU configuration (large processors)
hasn&amp;#39;t reserved a large enough address space for the stack.&lt;/p&gt;

&lt;p&gt;
In some situations, a program may look like it is working even
when variables are stored overlapping with the minimum required stack
space.&lt;/p&gt;

&lt;p&gt;
As long as the variables are not read, the program may not notice
that they have been corrupted by some stack operation. And as long as
they are not written, they will not corrupt the stack.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/103283?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2009 01:20:30 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5a0c21e4-3e2e-453c-9436-b986e3777748</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
There is no such thing as &amp;quot;stack space&amp;quot;.&lt;/p&gt;

&lt;p&gt;
The 8051 uses the DATA/IDATA space for the stack - if there&amp;#39;s not
enough of that left to meet your stack requirements, then There Will
Be Trouble Ahead...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/103286?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2009 00:59:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:77733533-964e-4af2-8b0d-b2301fde2f45</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
If the problem is with the watchdog, then you will have to update
the assembler startup file.&lt;/p&gt;

&lt;p&gt;
Have you checked what the datasheet says about the watchdog?&lt;/p&gt;

&lt;p&gt;
Have you looked at the startup file?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/77615?ContentTypeID=1</link><pubDate>Sun, 26 Jul 2009 23:15:54 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:04f74661-1616-49c8-9f95-62c86c1b07ca</guid><dc:creator>Ganesh Okade</dc:creator><description>&lt;p&gt;&lt;p&gt;
Mr. Westermark, Thank you for taking time to answer.&lt;/p&gt;

&lt;p&gt;
a) Running out of stack space: I am not too sure if I understand
this comment. Are initialised globals placed in stack space?&lt;/p&gt;

&lt;p&gt;
b) Watchdog: This could possibly be a cause because if I reduce
the no. of global variables that I initialise, everything works fine.
But then how should I handle this case? Isn&amp;#39;t a watch dog timer
disabled by default on power up? If not, where should I disable it
(obviously it cannot be in my main() because that would execute well
after the variables are initialised).&lt;/p&gt;

&lt;p&gt;
Thanks.&lt;/p&gt;

&lt;p&gt;
Regards,&lt;br /&gt;
Ganesh Okade&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Program with initialised global variables does not run</title><link>https://community.arm.com/thread/56493?ContentTypeID=1</link><pubDate>Thu, 23 Jul 2009 08:17:57 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:47a92a16-6ce4-49c1-8c5f-deec8b673c02</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Running out of stack space?&lt;/p&gt;

&lt;p&gt;
But a more probable cause: You have a watchdog that is running and
not getting kicked in time because the decompress/copy code in the
startup file takes too long.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>