| Author |
Message |
|
|
Posted: Sep 19, 2006 - 08:45 AM |
|


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia
|
|
EDIT: Bugger, I didn't see that someone else already covered this. I hope this at least contains other useful info .
Freaks,
While AVRStudio is NOT my personal preference for a front-end to AVR-GCC (that honor goes to the Programmers Notepad project), it is for many. Unfortunately, many people seem to use mis-configured project options with AVRStudio which result in less than optimal builds of their projects. To try to rectify this, I'll try to add hints here to achieve a better programming experience and end result.
Please feel free to reply to this with corrections or hints of your own.
Fonts: Out with Courier New!
Courier New is a horrible programming font - it's hard on the eyes and just seems so blocky. Having a good programming font is the first step to a good programming environment; after all you'll probably be staring at your code for many many hours. And who wants to read something that makes your eyes bleed?
My personal preference is the Microsoft Consolas font, size 9. It's fixed width (a MUST for ALL programming fonts) and is pleasantly styled. Most importantly, it scales well both upwards and downwards and thus is great for those with poor eyesight.
Far more importantly however, is to turn on Cleartype if available on LCD monitors. It will reduce eyestrain and make everything easier to read.
Optimization: Choose what's best for YOU
AVR-GCC has quite a sophisticated optimizer under its hood - this allows it to compile your code in a manner best for either size, speed or a combination of the two. Optimization is very powerful and extreamly useful, however AVRStudio defaults to it being turned off.
To turn on the optimizer, choose Project->Configuration Options from the top menu. Change the "Optimization" combo box from it's initial setting (-O0, off) to the setting you desire and click OK.
The most common optimizer setting is -Os, which compiles for the smallest resulting code size possible. This produces quite fast code too, so it's a good choice. If speed is of the essence, choose -O3.
For more information on the different settings, check out the GCC manual online. DON'T FORGET TO READ THE AVRLIBC FAQ - there are some things you need to be aware of when writing code that will be optimized!
You should also set your AVR clock's frequency in the appropriate box on this screen; this value is used by several library routines to determine delay lengths.
Main compile flags: At no extra cost!
Also in the same Configuration Options screen are several checkboxes to the right of the optimizer combobox. I recommend checking them all.
Unsigned Chars - This makes all "char" variables unsigned by default unless explicitly declared as signed. Unsigned chars are used far more than signed, so this is a good idea.
Unsigned Bitfields - This also defaults bitfields to unsigned unless explicitly declared as signed. Useful for projects which use bitfields to manage flags in registers and variables.
Pack Structure Members - Choosing this will cause GCC to pack structure members as close together as possible (to save on RAM).
Short enums - Enums in GCC-C are ints by default (16 bits wide). This switch forces all enums to become unsigned chars in size instead.
File generation: Help at hand
A final thing to look at on the first tab of the Configuration Options screen is the three checkboxes along the bottom of the window.
Create HEX File - Ticked by default. This causes GCC to both compile your project and produce a resulting HEX binary which you can use to program into an AVR.
Generate MAP file - When ticked GCC will also create a .map file in your project's directory. This file contains information on where your global variables and functions are located in your project's binary. Useful for debugging.
Generate list file - A BRILLIANT option which many miss. This causes GCC to make a .lss file in your current directory containing both your entire C code and linked AVRLibC functions as well as the resultant assembly code after each C line. This allows you to see just what functions are taking up all your room, as well as see what exactly your lines of C are producing once compiled.
Libraries: Don't re-invent the wheel!
Another feature overlooked by many. AVRLibC, the C library that comes with GCC, has several library files which should be linked with your project so that their hand-optimized routines are used in place of GCC's generic routines.
Failing to link with the correct libraries will NOT produce any GCC errors in most cases - but your resultant binary will be larger and slower than it needs to be.
From the PROJECT->CONFIGURATION OPTIONS screen, select the "Libraries" tab. Libc and Libm should be linked to all your projects, so select them both and click the "Add Library" button.
If your project makes used of the printf or scanf functions, you should link against the appropriate libraries from this screen too. The "_min" variants of each library are the minimal versions forgoing some of the advanced features available in the larger versions.
I will be adding and revising this post in the future. Cheers!
- Dean  |
_________________
Last edited by abcminiuser on Nov 14, 2006 - 05:27 AM; edited 3 times in total
|
| |
|
|
|
|
|
Posted: Sep 21, 2006 - 05:57 PM |
|


Joined: Jun 21, 2006
Posts: 239
Location: Seattle, WA
|
|
That font is awesome. I have made it the default in every one of my coding environments!
The rest of the Tutorial is good, too. Will reference it more when I get tired of ASM and switch to C for the AVR's.
Thanks and Best Regards!
Steve |
|
|
| |
|
|
|
|
|
Posted: Sep 22, 2006 - 12:41 AM |
|


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia
|
|
Cheers! I wanted to work in a mention of it into this tutorial, since I love it so much. I've actually surfed around quite a bit for a decent font, and that's the best one so far. Looks especially nice in Programmer's Notepad, and remains readable at very small sizes so I can fit more onto the screen at once. However, perhaps it's best feature over Courier New is the fact that zeros have a diagonal slash through them (in the style of old) which visually distinguishes then from a capitol "O".
- Dean  |
_________________
|
| |
|
|
|
|
|
Posted: Oct 13, 2006 - 01:41 PM |
|

Joined: Mar 28, 2001
Posts: 413
Location: Munich, Germany
|
|
| In case you want to have a look at the consolas font w/o having to have visual studio installed - here are the 'naked' .TTFs |
_________________ Andreas
|
| |
|
|
|
|
|
Posted: Oct 13, 2006 - 03:40 PM |
|


Joined: Apr 25, 2004
Posts: 3034
Location: Denmark
|
|
Where does the "Cleartype setting" hide ??
/Bingo |
|
|
| |
|
|
|
|
|
Posted: Oct 13, 2006 - 11:50 PM |
|


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia
|
|
As far as I know, it is a technology only available on Windows XP. I'd write the instructions myself, but there's already a nice guide on the internet that I just Googled and found.
Personally, I prefer to download and use the Microsoft Cleartype tuning powertoy (Windows XP English only). It allows you to tune the ClearType system to suit your individual monitor, which is important. If you can use this, do so.
For an explanation of ClearType from Microsoft themselves, see here.
I can almost guarantee you'll hate Cleartype at first - I did. It will feel strange, but try to persist (also, tune with the above powertoy, as some displays follow odd pixel configurations). After a few hours, you won't notice it unless you look for it, and it'll make reading on a laptop screen a lot easier.
Don't use Cleartype on a CRT monitor. It is designed for LCDs.
- Dean  |
_________________
|
| |
|
|
|
|
|
Posted: Oct 14, 2006 - 12:44 PM |
|


Joined: Jun 18, 2001
Posts: 928
Location: Brisbane Queensland Australia
|
|
Hi Dean
Have applied the new Consolas Font & Cleartype.
I am running 2 monitors both act as a 1 big rectangle screen.
1st is CRT (screen is a little bit fuzzy)
2nd is LCD (screen is a GREAT)
Is there any way to just apply the Cleartype to the LCD & not effect the CRT ?
Don't tell that I need an another LCD to replace the CRT.
Ken |
|
|
| |
|
|
|
|
|
Posted: Oct 14, 2006 - 12:52 PM |
|


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia
|
|
Hi Ken,
Bad news. To the best of my knowledge (keep in mind that I am far from an expert in these matters!) ClearType is system wide. I would image it changes the Windows GDI DrawText (and similar) hooks, which effect all display device contexts.
Looks like you'll be needing another LCD! At least it's a great excuse to justify the expense to the significant other .
- Dean
PS: Hmmm, perhaps I should make an OT tutorial on making the most accessible workspace, since you all seem to enjoy that aspect of this tutorial! |
_________________
|
| |
|
|
|
|
|
Posted: Oct 15, 2006 - 02:42 AM |
|


Joined: Jun 18, 2001
Posts: 928
Location: Brisbane Queensland Australia
|
|
Hi Dean
Yes that is a good excuse & add that to my Xmas list.
LCD display are getting cheaper anyway.
Quote:
Hmmm, perhaps I should make an OT tutorial on making the most accessible workspace, since you all seem to enjoy that aspect of this tutorial!
Yes, good idea.
Ken |
|
|
| |
|
|
|
|
|
Posted: Dec 02, 2006 - 10:07 PM |
|


Joined: Dec 17, 2005
Posts: 1443
Location: Europe- Estonia- Tallinn
|
|
nice tutorial dean.
i finally got mine set up too... used codevision before...
but i cant understand one thing. when they say AVR is made for C then why the hell hasn't Atmel made a normal programming environment for C programming yet? that small Gcc support in AVRstudio is just "lame" although better than nothing...
a new and separate program is what I'm crying here about. with good library and syntax checking. and at least some kind of a help file and compile all built in.
and i haven't found any good tutorial on how to set up orwhere to get command line compiler/programmer for my AVR's I'ld use that then... |
|
|
| |
|
|
|
|
|
Posted: Dec 03, 2006 - 08:01 AM |
|


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia
|
|
Bloody:
I'm not certain that Atmel had C in mind for themselves when they constructed the AVR - I think they wanted to focus on the assembly side. However, it is a known fact that the design of the AVR was made with collaboration of the IAR compiler design team. I think Atmel wanted to ensure that their new chip design was more friendly to C compilers, without focusing on higher language levels in their own offerings.
With the wide use and excellent quality of the AVR-GCC compiler, they've only recently caved and started to integrate it into their IDE.
I personally use the free Programmers Notepad software which is installed with WinAVR. I made my own AVRASM syntax highlighting scheme, and it suits me just fine. I wish it had Intellisense and smart code blocks (eg, inactive #ifdef blocks are highlighted a different colour to normal #ifdef blocks) like in the Microsoft IDE - but other than that it's great!
Swapping back and forth between AVRStudio and PN is no problem for me. I doubt Atmel could make anything better than PN - so why bother? It would still be separate from the AVRStudio IDE, and still require ALT-TABing.
- Dean  |
_________________
|
| |
|
|
|
|
|
Posted: Aug 15, 2007 - 08:20 AM |
|


Joined: Aug 10, 2007
Posts: 35
Location: Brisbane, Australia
|
|
Hi, Dean, Thanks for your posts re PROGMEM, etc. I was using 963 bytes of RAM on my ATmega168, and wondering why my stack was blowing away.
Because of the separate addressing/usage of .text and .data, does this fall into the "too hard" basket to get the compiler/linker to resolve this, i.e. "const" means "Use .text & get the compiler+linker to work out what is required"? (Aren't computers supposed to free us from this tedium? )
For Fonts, I'm quite keen on the 8K (yes, 8 Kbyte) fonts Sheldon & Sheldon Narrow (which I mostly use), available with another similar one called ProFont(with TTF & Linux variations), here: http://www.tobias-jung.de/seekingprofont/
Thanks again,
Alf
(ex-Vic, moved to Qld for wife's health) |
|
|
| |
|
|
|
|
|
Posted: Aug 15, 2007 - 08:27 AM |
|


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia
|
|
I can't say - the internals of GCC isn't my area. I do know that the PROGMEM attribute is specific to the AVR architecture (which is a very minor GCC target) and so any modifications would have to be in the form of a time consuming to maintain patch to the AVR build of GCC (and thus unlikely to manifest). Perhaps Joerg can post more about this, as he knows a lot more about it than I.
- Dean  |
_________________
|
| |
|
|
|
|
|
Posted: Aug 15, 2007 - 10:31 AM |
|


Joined: Jul 18, 2005
Posts: 33138
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
I think Jörg will confirm that it basically all boils down to GCC being a Von Neumann (single memory space) compiler while the AVR is a Harvard (multiple memory space architecture) and while work is being done for GCC to ultimately support multiple memory spaces it's early days. In the meantime the __attribute__((__progmem__)) and the pgm_???() helper functions will be needed to support the AVR's "odd" architecture
Cliff |
_________________
|
| |
|
|
|
|
|