| Author |
Message |
|
|
Posted: Feb 14, 2012 - 08:03 PM |
|

Joined: Jan 23, 2011
Posts: 10
|
|
Hi,
I am sure that this has been asked , and answered many times, but here goes ... For generally good reason I have set the global compiler optimization to level 2 (as part of the AVR Studio5 project page),
however I have some low level functions to make an 8 bit bus (RD, WR, CS, D0-D7 and A0-A5) assembled from the remnants of the GPIO pins left over once main functions have been allocated. If I set global optimization to 0 then I get control of the timing to approx 50ns steps using local bus GPIO functions.
My problem is that if optimization is > 0 then the timing control goes haywire .. it mostly gets optimized to an unpredictable state, (certainly by me).
I am sure that there must be an attribute or pragma (seems to be out of favor with GCC) that forces local optimization to be at level 0 (ie none and ignore any global optimization settings). I have scoured the GCC manual and as many sites as I can as well as experimenting but so far no luck. Any help appreciated. |
|
|
| |
|
|
|
|
|
Posted: Feb 14, 2012 - 08:20 PM |
|

Joined: Sep 21, 2004
Posts: 210
|
|
| I don't know about a pragma, but you can put the function in a file of it's own and set the optimization per file. |
|
|
| |
|
|
|
|
|
Posted: Feb 15, 2012 - 10:40 AM |
|

Joined: Aug 25, 2011
Posts: 392
Location: Europe
|
|
|
|
|
|
|
Posted: Feb 15, 2012 - 11:16 AM |
|

Joined: Oct 10, 2007
Posts: 395
Location: Valls, Spain
|
|
|
|
|
|
|
Posted: Feb 15, 2012 - 04:19 PM |
|

Joined: Jan 23, 2011
Posts: 10
|
|
| I had found the GCC function attributes pages and tried various that might have some impact but none did what I wanted. I will try putting the functions in a seperate file and see if I can set the optimisation to 0 for that file in the AVRStudio5 project ... cheers. |
|
|
| |
|
|
|
|
|
Posted: Feb 15, 2012 - 04:21 PM |
|

Joined: Aug 25, 2011
Posts: 392
Location: Europe
|
|
| Tried the pragmas? Actually I just notice that I swapped the links in my previous post. The second link will take you to the optimisation pragmas. |
|
|
| |
|
|
|
|
|
Posted: Feb 16, 2012 - 01:00 PM |
|

Joined: Jan 23, 2011
Posts: 10
|
|
Hi, I tried pragmas but got a message saying they were ignored. Apparently GCC uses attributes. Anyway the resolution is (for me anyway)
a) create a new project an build a static library
b) in this project set optimization 0. (so timing is retained)
c) put the lib file (.a) and the header file(.h) into a lib folder inside the main project.
d) On the project properties page , toolchain tab
(i) Compiler - add this folder to the include directories
(ii) Linker - Add the library path and name into the relevant boxes.
Then build the main project as normal.
I have found that this works OK. The main project can be set at optimize level 2 and the timing is retained, as expected. One niggle is that I get a warning "input non relaxable" as the lib was built with optimization 0 and resists further optimization.
Generally I adopt a zero-tolerance policy on warnings as they tend to lead to problems if unaddressed but I guess I will have to live with this one for now.
Thanks for your suggestions. |
|
|
| |
|
|
|
|
|
Posted: Feb 21, 2012 - 10:20 AM |
|

Joined: Feb 21, 2012
Posts: 4
|
|
|
|
|
|
|
Posted: Feb 21, 2012 - 10:27 AM |
|


Joined: Mar 27, 2002
Posts: 18585
Location: Lund, Sweden
|
|
The steps that create a library are not necessary for the solution of the cuirrent problem. It would have been enough to specify a separate optimization switch (i.e. no optimization) for the compilation of the source file in question and keep it in the original project.
I'm not at an AS5-enabled machine right now so can't tell the details about specifying compiler switches inividually for different source files.
Clarification: I'm not against creating libraries, but it has little to do with the solution of the current problem. |
|
|
| |
|
|
|
|
|
Posted: Mar 05, 2012 - 01:34 PM |
|

Joined: Jan 23, 2011
Posts: 10
|
|
| Hi, I did try and find a way to set the optimization of a single file within the AVRStudio5 project structure and user interface but could not find a way to do it. I am sure it can be done by manually editing the make file , but this file will be overwritten if I change the project properties. If the problem can be solved in a more elegant way then I am all ears. Thanks again. |
|
|
| |
|
|
|
|
|
Posted: Mar 05, 2012 - 03:21 PM |
|


Joined: Jan 07, 2003
Posts: 4580
Location: Oslo, Norway
|
|
|
|
|
|
|
Posted: Mar 07, 2012 - 12:11 PM |
|

Joined: Jan 23, 2011
Posts: 10
|
|
Thanks for the info, I guess I couldn't see it for looking. The AVR32 UC3 GCC compiler seems to accept the following, (slightly different) syntax
void function(void) __attribute__((optimize(3)))
{
...
}
I'll post later if it actually works (I'm confident it will). Thanks again |
|
|
| |
|
|
|
|
|
Posted: Mar 07, 2012 - 12:16 PM |
|

Joined: Jan 23, 2011
Posts: 10
|
|
Oops .. spoke too soon ,,, actual syntax required is
__attribute__((optimize(3))) void function(void)
{
...
}
Still confident it will work. |
|
|
| |
|
|
|
|
|