<?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>overload of xc864 limit?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/25757/overload-of-xc864-limit</link><description> 
Hi, 

 
I&amp;#39;m making a program with the xc864 using the keil application but
at some point I started to get the followings errors while I tried to
program my micro: 

 
&amp;quot; Content mismatch at address 0000H (Flash=EDH Required=02H) 
Content mismatch at</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: overload of xc864 limit?</title><link>https://community.arm.com/thread/135862?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2009 06:27:15 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1071d25c-5eff-4b80-82dd-93fd2d9ded39</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
This is a 8051 chip, i.e. a 8-bit processor that will suffer
whenever it does 16-bit operations.&lt;/p&gt;

&lt;p&gt;
Don&amp;#39;t use an int variable unless a char variable is too small. See
for example the index variable in your strcmp2() function. By the way
- have you checked if your function is smaller than the Keil
function? If the Keil function is written in assembler it may win
significantly from your indexed code.&lt;/p&gt;

&lt;p&gt;
Don&amp;#39;t use a variable when a constant can be used.&lt;br /&gt;
puts(array);&lt;br /&gt;
In this case, the compiler will have to add code to initialize
array[] with values before you send it. That consumes a huge amount
of code compared to the use of the text constant &amp;quot;AT+JRES&amp;quot; stored
directly in the flash.&lt;/p&gt;

&lt;p&gt;
And why do you later bother to clear the contents from array[].
Isn&amp;#39;t it enough to initialize a uchar to 0, to remember that you have
0 valid characters in the array?&lt;/p&gt;

&lt;p&gt;
Don&amp;#39;t use software delays generated by busy loops like:&lt;/p&gt;

&lt;pre&gt;
while (i&amp;lt;100) i++;
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
The compiler can - if you turn on optimization - decide to remove the
loop, since there are no side effect in the loop, other than to
assign the value 100 to i.&lt;/p&gt;

&lt;p&gt;
Don&amp;#39;t use magic constants when you don&amp;#39;t have to. The C language
has characters constants &amp;#39;\r&amp;#39;, &amp;#39;\t&amp;#39;, &amp;#39;\n&amp;#39;, &amp;#39;\b&amp;#39;, ... available. And
if you really do have to use constants, use enum or #define to give
them a name. Same code size, but easier to read - and no need to have
a comment &amp;quot;10 en decimal = &amp;lt;LF&amp;gt;&amp;quot;&lt;/p&gt;

&lt;p&gt;
You did try earlier with:&lt;/p&gt;

&lt;pre&gt;
sprintf(array,&amp;quot;AT+JSEC=1,1,1,04,1111&amp;quot;);
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
But sprintf() is string-print-&lt;b&gt;formatted&lt;/b&gt; and you don&amp;#39;t have any
formatting. The function when assigning a string to a character array
is strcpy().&lt;/p&gt;

&lt;p&gt;
As noted, your main() contains a large number of repetitions that
performs just about the same thing, but with different modem strings.
Break out the functionality into a separate function, and just send
the string constant as a parameter to this function. That will save
you a huge amount of code space.&lt;/p&gt;

&lt;p&gt;
Create a function that converts a number represented as
hexadecimal ASCII string to the numeric value. If you need to convert
very large numbers, you can do it in two steps. Let one function
convert the string into an array of bytes. Then you can either keep
and use this array as is, or convert to 16-bit or 32-bit values.&lt;/p&gt;

&lt;p&gt;
Do you really need an array of 7 long, i.e. may any of the seven
numbers be larger than 65535, the max range of an unsigned 16-bit
integer?&lt;/p&gt;

&lt;p&gt;
Most developers normally write all comment in english. This has
several advantages. You may post your code to an international forum
and way more people will understand the comments and be able to help
you. If you later work for a larger company, that company may have
english as official company language, i.e. requiring that all
official documents, design documents, ... has to use english. The
reason being that you may have to work in a team with other
developers from other countries. And big companies often buys and
sells products and code libraries in deals with companies from other
countries.&lt;/p&gt;

&lt;p&gt;
In the end - you will be easy to shrink your code to half the
current size by just writing modular code and think about reuse.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: overload of xc864 limit?</title><link>https://community.arm.com/thread/125609?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2009 05:38:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a729bd00-dc9d-40c9-ae61-41f7d07e2538</guid><dc:creator>stephen phillips</dc:creator><description>&lt;p&gt;&lt;p&gt;
I think your first job is to look at the LISTING file for your
code. This will show you how much space one chunk of code uses versus
another.&lt;/p&gt;

&lt;p&gt;
Simple things do not assign directly to an array element:&lt;/p&gt;

&lt;pre&gt;
array_[0] = &amp;#39;1&amp;#39;;
array_[1] = &amp;#39;1&amp;#39;;
array_[2] = &amp;#39;1&amp;#39;;
array_[3] = &amp;#39;1&amp;#39;;
array_[4] = &amp;#39;1&amp;#39;;
array_[5] = &amp;#39;1&amp;#39;;
array_[6] = &amp;#39;1&amp;#39;;
array_[7] = &amp;#39;1&amp;#39;;
array_[8] = &amp;#39;\0&amp;#39;;
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
Even if the array is is near space this is horribly inefficient.&lt;/p&gt;

&lt;p&gt;
I think the problem is you lack C programming experience, not that
the processor memory isn&amp;#39;t large enough. Your main function uses the
bulk of your code space (0xCBC translates to 3260/4096), one function
80% of the code space (boggle). The real question is what do you need
to do (minimal amount). Then map how to get there. It may be more
prudent if you are in a hurry to instead &amp;#39;use a processor more
memory&amp;#39;. If you HAVE to use this processor, you must rethink your
code.&lt;/p&gt;

&lt;p&gt;
I can give you a few clues. Why do you need to use sprintf at all?
Why are you directly sending data to the serial port buffer in the
main routine? Why are there no functions to handle repetitive tasks?
(IE sending text to the serial port).&lt;/p&gt;

&lt;p&gt;
Stephen&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: overload of xc864 limit?</title><link>https://community.arm.com/thread/125608?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2009 05:15:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fe6b9d8d-29df-4853-992c-eed94e72006b</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
The whole point of using functions is that the code is not
repeated - a function occupies the same amount of code space whether
it is called once or 1000 times!&lt;/p&gt;

&lt;p&gt;
The same applies to library functions; eg, printf: if you remove
999 printf calls, and leave only 1 call, then you will still need to
have printf in the code.&lt;/p&gt;

&lt;p&gt;
Did you actually look at the MAP file, as suggested, to see
exactly what is using up all your code space?&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;Looking on the datasheet I&amp;#39;ve confirmed that the xc864 just
have 4k for flash programing, so that I must optmizate the
program...&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Before &amp;quot;oprimising&amp;quot; the program, have you actually considered
whether a 4K part has any chance of being sufficient for your
requirements?&lt;/p&gt;

&lt;p&gt;
At the end of the day, you cannot cram a quart into a pint
pot!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: overload of xc864 limit?</title><link>https://community.arm.com/thread/115107?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2009 04:34:41 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:61a1919f-196c-4b98-b216-67d2cddd94e0</guid><dc:creator>bernat feixas</dc:creator><description>&lt;p&gt;&lt;p&gt;
I&amp;#39;ve removed some printf, but after continuing writing code I&amp;#39;ve
arrived at the same point :&lt;br /&gt;
Program Size: data=102.1 xdata=0 const=0 code=4493&lt;/p&gt;

&lt;p&gt;
Looking on the datasheet I&amp;#39;ve confirmed that the xc864 just have
4k for flash programing, so that I must optmizate the program in
order to introduce it but I don&amp;#39;t what should I change or
rewrite.&lt;/p&gt;

&lt;p&gt;
I&amp;#39;ve attached my c code and my map file in case somebody could
give me an idea:&lt;/p&gt;

&lt;p&gt;
&lt;a target="_blank" href="http://docs.google.com/View?id=d8twnwb_545fpqq3rd5"&gt;&amp;quot; href=
&amp;quot;http://docs.google.com/View?id=d8twnwb_546gd8m9t5c&amp;quot;&amp;gt;&lt;a href="http://docs.google.com/View?id=d8twnwb_546gd8m9t5c"&gt;docs.google.com/View&lt;/a&gt;&lt;/a&gt;
--&amp;gt; map file&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: overload of xc864 limit?</title><link>https://community.arm.com/thread/103293?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2009 04:04:18 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f13b5b81-7ef6-4d58-a45d-d70788a5f1b0</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
I don&amp;#39;t believe that strcmp() is so large as indicated by the size
change in the map file. You must have deactivated own code too.&lt;/p&gt;

&lt;p&gt;
strcmp() is a very small function. For a single compare of short
strings, you can possibly do better with explicit
character-by-character tests, but I don&amp;#39;t expect that to be
applicable for you.&lt;/p&gt;

&lt;p&gt;
Note that it isn&amp;#39;t #include &amp;lt;string.h&amp;gt; that affects the size
of the binary. It is the number of functions you call. The file
string.h is just a menu, giving a list of available functions.&lt;/p&gt;

&lt;p&gt;
Look through the code and the map file and decide if there are
code you can rewrite, or if you have any debug printouts using
printf() or similar.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: overload of xc864 limit?</title><link>https://community.arm.com/thread/77621?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2009 03:56:14 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bdad49f7-8f49-44d5-aeee-5efd328a4d92</guid><dc:creator>bernat feixas</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thanks for the answer,&lt;/p&gt;

&lt;p&gt;
I&amp;#39;ve proved to comment the following include = #include
&amp;lt;string.h&amp;gt; , and by now it seems it works as you can see the
change in the memory map:&lt;/p&gt;

&lt;p&gt;
new code map=&lt;br /&gt;
Program Size: data=77.2 xdata=0 const=0 code=3575&lt;br /&gt;
old code map=&lt;br /&gt;
Program Size: data=77.2 xdata=0 const=0 code=4222&lt;/p&gt;

&lt;p&gt;
But now I&amp;#39;ve got another problem I used this include in order to
compare lists of characters that I&amp;#39;ve have using the strcmp
--&amp;gt;&lt;/p&gt;

&lt;p&gt;
for example =&lt;/p&gt;

&lt;p&gt;
if (strcmp(array,&amp;quot;ROK&amp;quot;)==0) then ...&lt;/p&gt;

&lt;p&gt;
can any one tell me how I can compare an array of characters
without using this function?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: overload of xc864 limit?</title><link>https://community.arm.com/thread/56513?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2009 03:34:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:29643765-c1ba-409f-9fd1-de221f97a67d</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Making your program smaller is called optimizing.&lt;/p&gt;

&lt;p&gt;
On one hand, the compiler has a setting to turn on automatic
optimization (for size and/or speed), but it is also a question of
being a skilled developer.&lt;/p&gt;

&lt;p&gt;
Avoid the use of large library functions. Look at your code and
see if you can rewrite some parts of the code to be more efficient.
Is the code always using the optimum size for all variables?&lt;/p&gt;

&lt;p&gt;
Turn on generation of a map file, and look in the map file to see
how large the program is, and the size of the different modules.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>