11.07.2015 Views

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ICCV8 <strong>for</strong> AVR – C Compiler <strong>for</strong> Atmel AVRGeneral Debugging HintsDebugging embedded programs can be very difficult. If your program does notper<strong>for</strong>m as expected, it may be due to one or more of <strong>the</strong> following reasons.The default configurations of some CPUs may not be what is “reasonably”expected. Some examples include:On <strong>the</strong> Atmel AVR, <strong>the</strong> Mega128 left <strong>the</strong> factory preprogrammed to behavelike <strong>the</strong> older M103 device with <strong>the</strong> M103C fuse set. If you ask <strong>the</strong> <strong>compiler</strong> togenerate code <strong>for</strong> a M128 device, <strong>the</strong>n it will not work, since <strong>the</strong> M103 compatibilitymode uses a different memory map <strong>for</strong> <strong>the</strong> internal SRAM. This“minor detail” probably accounts <strong>for</strong> <strong>the</strong> majority of support requests we get<strong>for</strong> <strong>the</strong> M128 customers.On <strong>the</strong> Atmel AVR, by default some of <strong>the</strong> Mega devices use <strong>the</strong> internaloscillators instead of <strong>the</strong> external clock.For devices with external SRAM, <strong>the</strong> hardware interface may need time tostabilize after device reset be<strong>for</strong>e <strong>the</strong> external SRAM can be accessed correctly.Your program must use <strong>the</strong> correct memory addresses <strong>and</strong> instruction set.Different devices from <strong>the</strong> same family may have different memory addresses ormay even have slightly different instruction sets (e.g., some devices may have ahardware multiple instruction). Our IDE typically h<strong>and</strong>les <strong>the</strong>se details <strong>for</strong> you.When you select <strong>the</strong> device by name, <strong>the</strong> IDE generates <strong>the</strong> suitable <strong>compiler</strong> <strong>and</strong>linker switches. However, if your hardware is slightly different (e.g., you may haveexternal SRAM) or if <strong>the</strong> device you are using is not yet directly supported by <strong>the</strong>IDE yet, you can usually select “Custom” as your device <strong>and</strong> enter <strong>the</strong> data byh<strong>and</strong>.If your program crashes r<strong>and</strong>omly, it is almost certainly a memory overwrite errorcaused by logic or o<strong>the</strong>r programming errors. For example, you may have apointer variable pointing to an invalid address, <strong>and</strong> writing through <strong>the</strong> pointervariable may have catastrophic results that do not show up immediately, or thatyou overwrite beyond <strong>the</strong> bound of an array.Ano<strong>the</strong>r source of such memory errors is stack overflow. The stack typicallyshares space with variables on <strong>the</strong> SRAM, <strong>and</strong> if <strong>the</strong> stack overflows to <strong>the</strong> datavariables, Bad Things May Happen (tm).38

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!