Sunday, November 23, 2014

XMega - Tips

XMega - Tips

This is a collection of tips that were part of individual articles but may be easier to find in one place. 

Hardware Debugger 

  1. During most of the debug process, the frequency counter showed 1,000,038 or 1,000,039. It is very accurate so I doubt it is an internal clock. Since it showed those values when the Crystal wasn't used, I think it's a clock from the debugger.
  2. It appears that when the debugger is connected and not in debug mode it's probably holding the microcontroller in reset, since the frequency counter shows 0.

Optimization

  1.  Optimization level defaults to -O1 which is a good start when your talking about shipping a product with firmware. While developing especially with a stepping debugger, strange behavior can occur. I suggest turning optimizations off for DEBUG builds. It will be helpful if prototype boards have a larger Flash than the final product.
    The optimization setting is found in the Project Properties -> Toolchain -> AVR/GNU C Compiler -> Optimization -> Optimization Level = None

ASF Coding Style

A quick note about C code for the XMega: there are lots of great constants that make the code a bit more readable than the common practice of "magic" values in Hex, Decimal or Binary. The suffix of these constants have additional meaning:
  • _bm is a BitMask. It is generally a Hex Value like 0x80 which specifies Bit 7 (0 to 7)
    • It can also be represented by Left Bit shifting a 1 into the specified position
  • _bp is a Bit Position it is generally a single digit number like 7 which also specifies Bit 7
  • _gc
  • _gm Group Mask 
  • _gp Group Position

Warnings 

Many people especially when they start out, don't take compiler warnings very seriously, they expect/hope the compiler will create code that does what they intended. While many times this is true, it is not true all of the time. I recommend treating the warnings as errors and working through them. This has the added benefit of more predicable code behavior, especially when Optimizations are turned on. It is also a great way to learn the details of the C language. 

No comments:

Post a Comment