Code formatting in AVR Studio 5

I discovered that AVR Studio 5.1 doesnt always work in relation to code formatting. I searched for bugs and found a number of places where Atmel has replied that they are working on fixing this. However, until this happens a nice work around using an external tool can be used.

This is how to setup the external tool AStyle which is on SourceForge and free.

  1. Download AStyle and unzip it somewhere you like
  2. Open AVR Studio 5
  3. Go to: Tools->External Tools…
  4. Add a tool and fill in the fields:
    1. Title = AStyle
    2. Command: full path to C:\\…\AStyle.exe
    3. Arguments: -y –indent=tab –style=ansi –errors-to-stdout –suffix=none $(ItemDir)$(ItemFileName)$(ItemExt)
      1. If you like the code formatted differently you can check the AStyle documentation
    4. And finally check the Use Output Window, so it doesnt popup a new windows every time you run it.
  5. Now we need to setup a key binding for it like Ctrl+Shift+F and make the document reload automatically when formatted
    1. Goto Tools->Options
      1. Locate Environment->Keyboard in the left tree
      2. Then fund the command: Tools.ExternalCommand1 (assuming you only have one external tool specified)
      3. Assign a Ctrl+Shift+F to it as global. And the key binding is complete.
      4. Locate Environment->Document
        1. Check “Auto-load changes, if saved”
  6. That’s it enjoy

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.