Code size

Questions about the BASICtools and MakeItC
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Code size

Post by YahooArchive »

> My code has reached 0x7E83. I can't even use a 'printf' without
> exceeding the flash memory and generating linking errors. I still have
> more to do, so I need to reduce some of the unused functions.
>
> How can I eliminate some of these functions?
>

for smaller code-

- compile in Thumb mode
- make sure -Os optimization is set (the default)
- don't use string, mem functions 1K
- don't use printf 0.7K
- use volatile only where necessary
- don't use cor_hwlib (7K total) - start from scratch or purchase the
source and elminate unused functions



YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Code size

Post by YahooArchive »

Avoid using floating point, esp. printf() for floating point.
Use longs or fixed point math.

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Code size

Post by YahooArchive »

--- In ARMexpress@yahoogroups.com, "basicnode" <bruce@...> wrote:
>
> > My code has reached 0x7E83. I can't even use a 'printf' without
> > exceeding the flash memory and generating linking errors. I still
have
> > more to do, so I need to reduce some of the unused functions.
> >
> > How can I eliminate some of these functions?
> >
>
> for smaller code-
>
> - compile in Thumb mode
That does make a difference, but I thought that I couldn't use Thumb
Mode, since I am using Interrupts.

> - make sure -Os optimization is set (the default)
It's set.

> - don't use string, mem functions 1K
I Don't

> - don't use printf 0.7K
I only use printf to debug, it's commented out everywhere it has been
used.

> - use volatile only where necessary
I have to use volatile in most cases, since the compiler optimzes out
necessary code, if I don't declare variables volatile.

> - don't use cor_hwlib (7K total) - start from scratch or purchase
the
> source and elminate unused functions.

How much is the Source?

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Code size

Post by YahooArchive »

> > - compile in Thumb mode
> That does make a difference, but I thought that I couldn't use Thumb
> Mode, since I am using Interrupts.

Your interrupt routine MUST be in ARM code, so include it in a source
block with ISR in the name (upper case) and the compiler will compile
that in ARM mode.

> > - use volatile only where necessary
> I have to use volatile in most cases, since the compiler optimzes out
> necessary code, if I don't declare variables volatile.

You do NOT need to declare variables volatile unless they are altered
by an interrupt routine. Check the web for the definition of volatile
and C for more details. But you are definitely misunderstanding
something here. Our ARMweb which is 128K of code some 20K lines to
implement a compiler, TCPIP, and web server has less than a handful of
volatile variables (just checked it has 5).

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Code size

Post by YahooArchive »

>
> > > - compile in Thumb mode
> > That does make a difference, but I thought that I couldn't use
Thumb
> > Mode, since I am using Interrupts.
>
> Your interrupt routine MUST be in ARM code, so include it in a
source
> block with ISR in the name (upper case) and the compiler will
compile
> that in ARM mode.

My interrupt routines are PWM_ISR.c, and FIQ_ISR.c, so I can use
Thumb Mode. That saves almost 4K.


>
> > > - use volatile only where necessary
> > I have to use volatile in most cases, since the compiler optimzes
out
> > necessary code, if I don't declare variables volatile.
>
> You do NOT need to declare variables volatile unless they are
altered
> by an interrupt routine. Check the web for the definition of
volatile
> and C for more details. But you are definitely misunderstanding
> something here. Our ARMweb which is 128K of code some 20K lines to
> implement a compiler, TCPIP, and web server has less than a handful
of
> volatile variables (just checked it has 5).

I'll look into that some more.

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Code size

Post by YahooArchive »

I believe that my use of 'volatile' declarations is mostly justified.
My code is a While Loop that's controlled by Interrupts, I/O inputs,
and AD() inputs. Most of my variables can change values between
passes through the loop. The Compiler has no knowledge of this and
cannot make decisions about these variables. These variables must be
loaded from memory each time thay are used. The initial value of
these variables is meaningless after the first pass. A variable may
be the sum of several variables, one of which may be the result of an
I/O or AD input.

It is possible that with careful editing, I can select variables that
are only changed by code, such as 'int i' when 'i' is used as a
counter for a for/next loop, but to err on the side of caution, I
have to declare a variable volatile unless I'm sure that it's value
is not changed by any external hardware/software.

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Code size

Post by YahooArchive »

I am going through my code one variable at at time. I am finding that
I don't have to declare a variable volatile, if the value of the
variable is set within the code, even though it's a function of an
I/O operation, like 'XYZ = IN(9);.'
I still have to watch variables that are initialized to some value
and then used in an 'if' or other decision statement, before they are
updated in the code. The compiler eliminates the code for the Not
True condition, as if the variable is a constant.

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Code size

Post by YahooArchive »

> I still have to watch variables that are initialized to some value
> and then used in an 'if' or other decision statement, before they are
> updated in the code. The compiler eliminates the code for the Not
> True condition, as if the variable is a constant.

The compiler IS doing the right thing here, the code it is eliminating
can never be executed.

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Code size

Post by YahooArchive »

I am still fighting the ARMmite 32K Code Space limit. I have my code
almost complete, but the compiler is still optimizing out
some 'unreachable' branches of code. If I declare the variables in the
decision blocks 'volatile', the compiler will compile these branches,
but will then overflowm the Code Space boundary.

I need to turn-off or increase the compiler code space limit check, so
I can compile the complete program, and determine how far out-of-limit
the code is. If it's close, I can try to remove unused procedures in
Included files and/or other methods to make the code more compact.

What do I need to do to change the code space limit?

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Code size

Post by YahooArchive »

I have finished my code, and it needs 38.24K Flash Memory. I am
looking for ways to reduce it by 6K.

I use the following Coridium Hardware Library functions. I want to
remove any that are not being used. That also pertains any other
Library functions that are not required.

AD
COUNT
HIGH
HWPWM
IN
INPUT
LOW
OUTPUT
PULSIN

HWPWM uses the LIST function, but I do one channel at a time. I want
to modify HWPWM to accept a single target.

I also need a serial communication program to communicate with a
laptop. Will the Terminal Emulator program support an extensive
command set?
Which functions do I need for serial communication.

Post Reply