1 Setting up Code::Blocks IDE for AVR
1. Install WINAVR first with all default settings
2. Install Codeblocks with all default settings
3. Overwrite the existing default.ini file located in
“C:\Users\xxxx\AppData\Roaming\CodeBlocks folder” with the
attached file .
Exact folder depends on your operating system. For example in
Windows XP, it may be:
C:\Documents and Settings\xxxx\Application Data\CodeBlocks
folder
xxxx means user name.
4. Launch Codeblocks application
5. Open the attached project file AVR_Project.cbp
6. Build the project. There should not be any errors
7. Go to device manager and note down the com port Numbers (Ex:
COM4 in the figure below). This will be appear only if you
connect the hardware (Nano or UNO board).
8. Go to tools -> Configure Tools Select Nano and click Edit
Go to Parameters field and change the COM port number if it is different
than the one you noted above. Please ensure that you do this carefully
without deleting ‘P’ or ‘-‘ or any spaces.
Change the baud rate if different. For nano it is 57600 and for Uno it is
115200
Click OK.
Now click on tools and click on nano. If the hardware is connected, code
will be transferred to the control.
Verify that data is written correctly by looking at the log.
In case you are unable to use default.conf
file given or have any issues, follow the
following steps.
1.1 Creating New Project in Codeblocks
Click on File -> New -> Project
Select AVR Project option
Give a project title and click next
Select the target and F_CPU below
Click Finish. Now the project is created.
Click on settings compiler-GCC compiler for AVR
Select warning option and other options as appropriate
Enable all compiler Warnings and Extra Warnings
Select optimization as –Os or other as appropriate
Set the GCC Compiler for AVR tool chain executable in case it is not defined.
Set the Tool chain directories as appropriate. You may choose WinAVR tool chain or other
tool chain.
For Compiler’s Installation Directory, select the folder one level above the bin folder.
Once you set up the project you need to set the two different project build methods "DEBUG"
and "RELEASE" as per your need.
Now Right click on Project Name in Manager Window (at the top left) and click on properties.
Go to build targets and do appropriate changes if needed. Set the output filename where it need
to appear.
Now Right click on Project in Manager Window (at the top left) and click on project's build
options
This should take you to the "project build options" screen. You then go to:
"pre/post build steps"
Here is where you change the settings to build your code into a hex file and load it to the
microcontroller. On the left should be three names your "project name", "debug" and "release".
When you click on your project name under the "pre/post build steps" tab you should see some
commands there. Those are the lines that take your complied "o" object file and using the options
-O ihex turn it into a hex file which can be loaded onto your chip.
What you need to do is delete them form the overall "project name".
Copy the following commands and paste them in post build steps for both release and debug.
avr-objcopy -O ihex -j .text -j .data $(TARGET_OUTPUT_FILE)
$(TARGET_OUTPUT_FILE).hex
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex
$(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).eep.hex
Add a programmer to tools:
First Get AVRDude programmer.
Click on Tools->configure tools
Click Add and give below data:
Name – Give any meaningful name to the programmer such as nano programmer, UNO
Programmer etc
Executables: Select appropriate programming tool
(Ex: C:\Atmega\programmers\avrdude\avrdude.exe)
Parameters: Update the parameters as needed depending on the serial port, baud rate etc
Serial port should be taken from device manager and updated in COMxx below.
Set the working directory as below (in case of codeblocks)
${PROJECT_DIR}/${TARGET_OUTPUT_DIR}
Parameters:
a. If Using Uno Board
-C"C:\Atmega\programmers\avrdude\avrdude.conf" -patmega328p -carduino
-PCOM34 -b115200 -Uflash:w:${TARGET_OUTPUT_BASENAME}.elf.hex
2. If Using Nano Board (Only Baud Rate has to be changed)
-C"C:\Atmega\programmers\avrdude\avrdude.conf" -patmega328p -carduino
-PCOM20 -b57600 -Uflash:w:${TARGET_OUTPUT_BASENAME}.elf.hex
References:
http://wiki.codeblocks.org/index.php/Variable_expansion
http://www.avrfreaks.net/forum/avr-gcc-code-blocks-codeblocks
http://forums.codeblocks.org/index.php?topic=13616.0
http://www.johnhenryshammer.com/WOW2/pagesHowTo/atmelPage.php#index