Imagecraft C Compiler and Development Environment for The
Total Page:16
File Type:pdf, Size:1020Kb
JumpStarter C for AVR – C Compiler for Atmel AVR INTRODUCTION .............................................................................................5 Version, Trademarks, and Copyrights .................................................. 5 Software License Agreement................................................................ 6 IMPORTANT: Licensing the Software................................................ 8 Transferring a License to Another Computer ....................................... 9 Using the Hardware Dongle ............................................................... 10 Annual Maintenance ........................................................................... 11 Support................................................................................................ 12 Product Updates.................................................................................. 14 File Types and File Extensions........................................................... 15 ImageCraft C Compiler Extensions.................................................... 17 Converting from Other ANSI C Compilers........................................ 19 Optimizations...................................................................................... 21 Acknowledgments .............................................................................. 24 GETTING STARTED .....................................................................................25 Quick Start Guide ............................................................................... 25 Example Projects ................................................................................ 27 EMBEDDED PROGRAMMING....................................................................29 Embedded Programming Basics......................................................... 29 Some Pitfalls ....................................................................................... 30 Best Practices...................................................................................... 32 Bit Twiddling...................................................................................... 34 General Debugging Hints ................................................................... 36 Debugging and Flash Programming With AVR Studio ..................... 40 CODE::BLOCKS IDE.....................................................................................43 Code::Blocks IDE ............................................................................... 43 Useful General Settings for CodeBlocks IDE .................................... 45 ImageCraft Enhancements to CodeBlocks ......................................... 46 Migrating From Version 7 Projects .................................................... 47 IDE and the Compiler ......................................................................... 48 Project Management ........................................................................... 49 Editor .................................................................................................. 51 Handy CodeBlocks Editor Features.................................................... 52 Multi-Target Support and Build Properties ........................................ 53 C::B Supported Variables ................................................................... 60 Menu Reference: Build Options - Project........................................... 64 1 JumpStarter C for AVR – C Compiler for Atmel AVR Build Options - Paths.......................................................................... 65 Build Options - Compiler ................................................................... 66 Build Options - Target ........................................................................ 69 Project - Debug/Download Interface .................................................. 73 ImageCraft: Bootloader Download->Logic ISP................................. 74 JUMPSTART DEBUGGER............................................................................75 JumpStart Debugger JDB ................................................................... 75 Installing Drivers for JDB-AVR......................................................... 76 Atmel Debug Pod Firmware Updates................................................. 77 Solving Debug Pod Connection Issues............................................... 78 Debugger Operations .......................................................................... 80 CodeBlocks Debugger Functions ....................................................... 83 Advanced Debug Toolbar (ADT) Functions ...................................... 86 C PREPROCESSOR........................................................................................89 C Preprocessor Dialects ...................................................................... 89 Predefined Macros .............................................................................. 90 Pragmas............................................................................................... 92 Supported Directives........................................................................... 96 String Literals and Token Pasting....................................................... 98 C IN 16 PAGES...............................................................................................99 Preamble ............................................................................................. 99 Declaration........................................................................................ 102 Expressions and Type Promotions.................................................... 105 Statements......................................................................................... 110 C LIBRARY AND STARTUP FILE ............................................................113 C Library General Description ......................................................... 113 Overriding a Library Function.......................................................... 114 Startup File........................................................................................ 115 Header Files ...................................................................................... 118 Character Type Functions................................................................. 119 Floating-Point Math Functions ......................................................... 121 Standard IO Functions ...................................................................... 123 Standard Library And Memory Allocation Functions...................... 127 String Functions................................................................................ 130 Variable Argument Functions........................................................... 134 Stack Checking Functions ................................................................ 135 2 JumpStarter C for AVR – C Compiler for Atmel AVR Greater Than 64K Access Functions ................................................ 137 PROGRAMMING THE AVR.......................................................................139 Accessing AVR Features .................................................................. 139 io???.h Header Files.......................................................................... 140 XMega Header Files ......................................................................... 142 Generating Production ELF File....................................................... 143 CRC Generation................................................................................ 145 Program Data and Constant Memory ............................................... 146 Strings ............................................................................................... 147 Stacks ................................................................................................ 148 Inline Assembly ................................................................................ 149 IO Registers ...................................................................................... 150 XMega IO Registers ......................................................................... 151 Global Registers................................................................................ 152 Addressing Absolute Memory Locations ......................................... 154 Accessing Memory Outside of the 64K Range ................................ 156 C Tasks ............................................................................................. 160 Bootloader Applications ................................................................... 161 Interrupt Handling............................................................................. 162 Accessing EEPROM......................................................................... 165 Accessing the UART, SPI, I2C etc................................................... 168 Specific AVR Issues ......................................................................... 169 C RUNTIME ARCHITECTURE ..................................................................171 Data Type Sizes ................................................................................ 171 Assembly Interface and Calling Conventions .................................. 173 Function Pointers .............................................................................. 176 C Machine Routines.......................................................................... 177 Program and Data Memory Usage...................................................