<?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>global variables initialized to 0 instead of declared values</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/34102/global-variables-initialized-to-0-instead-of-declared-values</link><description> 
Hi all, 
I have a bootloader-fw setup on SAM3S4C. It is working fine except a
certain conditions, then the global variables of the fw part are not
initialized (are zeroed instead), like if the __main() was not
called. 

 
Bootloader occupies the first</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: global variables initialized to 0 instead of declared values</title><link>https://community.arm.com/thread/83511?ContentTypeID=1</link><pubDate>Wed, 25 Jan 2017 03:51:59 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d62fb21a-72ad-4aaa-86ad-3f2b332a7bcc</guid><dc:creator>Petr Ent</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thank you for the hints, but unfortunately none of that seems to
be the case.&lt;/p&gt;

&lt;p&gt;
I am not sure whether it should call SystemInit. I was using
Keil&amp;#39;s default handler since day one, and it contains just __main()
call. I have SystemInit function also default from Keil, and it sets
up core frequency and some other stuff, and it is called from my
code.&lt;/p&gt;

&lt;p&gt;
Jump to main function is pasted in the original post. It is just
passing of the control to the Reset Handler of the uploaded image.
The Reset Handler itself then calls __main(). I was not able to trace
into __main, debugger just steps over it.&lt;/p&gt;

&lt;p&gt;
I checked the upload process and it works fine, whole image is
loaded. I also browsed the compiled binary file and I found some
string constants used in the code, so I guess this one is fine
too.&lt;/p&gt;

&lt;p&gt;
All of that is supported by the fact that the global variables are
zeroed only directly after the image upload. When the uP is reset, it
works fine &amp;quot;till the end of time&amp;quot;. So all the static variables must
be included in the image, they are just not used the first time the
image is executed.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: global variables initialized to 0 instead of declared values</title><link>https://community.arm.com/thread/65288?ContentTypeID=1</link><pubDate>Tue, 24 Jan 2017 11:26:00 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:32dc0035-b983-41d0-88f4-6a7fb5150962</guid><dc:creator>Westonsupermare Pier</dc:creator><description>&lt;p&gt;&lt;p&gt;
Should it call SystemInit prior to __main ?&lt;/p&gt;

&lt;p&gt;
The code in __main zeros memory, and copies statics, you should
try off &amp;quot;run to main&amp;quot; and step through it. If copies the statics from
the end of the image. Make sure you write the entire image properly
and you haven&amp;#39;t truncated it.&lt;/p&gt;

&lt;p&gt;
Review the statics in the .HEX or .AXF file. Confirm you can see
the data you are expecting in there.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>