====== IDE CodeBlocks manual setup ======
The following guide describes the AVR development environment setup, if not used HomeLab precompiled installing package.
===== Installing software =====
It is necessary to install the following software bundle:
**1. CodeBlocks **
CodeBlocks IDE (Integrated Development Environment), for software writing and its loading into the microcontroller.
**2. ATMEL AVR Toolchain**
AVR Toolchain is GNU-GCC compiler for AVR microcontrollers. This is a freeware which can be found on Atmel's website.
**3. HomeLab library**
HomeLab library contains a various functsions to make AVR and HomeLab kit programming simpler. The last versions for this library can be found on HomeLab website.
**4. DFU-Programmer**
DFU-Programmer is for programming HomeLab III series controller and using its bootloader
----
=== CodeBlocks installation ===
Following guide describes HomeLab III (Controller v1 - ATxmega128A1U) development enviroment setup and use in Windows operating system.
First install CodeBlocks software.
No need to install CodeBlocks plugis.
{{ :et:examples:setup:codeblocks:1_cb_install.png?400 |}}
Next choose correct location for CodeBlocks. All examples are in default location //C:\HomelabCB//
{{ :et:examples:setup:codeblocks:2_cb_dir.png?400 |}}
Then CodeBlocks software install on the computers.
=== Adding Homelabs extras ===
When CodeBlocks are installed, then add: AVR Toolchain, HomeLab library, DFU-Programmer
First of all, you should choose the folder where you installed the CodeBlocks, because of all the extras installed in the same folder.
{{ :et:examples:setup:codeblocks:3_homelab_dir.png?400 |}}
===== CodeBlocks setup =====
The first launch prompted compiler location. May be select //*No Compiler*//, because the choice of the compiler is set manually at a later, and it is dependent to the project template.
{{ :et:examples:setup:codeblocks:4_cb_firstrun.png?400 |}}
Then, the compiler should be set. Enter the menu //Settings -> Compiler...//. In the opened window should be set to the following lines:
Observe that would be selected **GNU GCC Compiler for AVR** and show where to install the software. If the installed sowtware location is not C:\HomelabCB then should be made corresponding changes themselves.
{{ :et:examples:setup:codeblocks:5_cb_compiler1.png?400 |}}
{{ :et:examples:setup:codeblocks:6_cb_compiler2.png?400 |}}
{{ :et:examples:setup:codeblocks:7_cb_compiler3.png?400 |}}
{{ :et:examples:setup:codeblocks:8_cb_compiler4.png?400 |}}
Then configure the programmer to be able to download the code directly from CodeBlocks environment. In order to find the menu //Tools -> Configure tools...// and choose //Add//. In the opened windows write the following rows dependent HomeLabs generation:
** HomeLab III **
* Homelab III
* C:\HomelabCB\Programmer\Program.bat
* "C:\HomelabCB\Programmer" "${TARGET_OUTPUT_BASENAME}.hex"
* ${TARGET_OUTPUT_DIR}
{{ :et:examples:setup:codeblocks:9_cb_tool.png?400 |}}
** HomeLab II (Atmega2561) **
* Homelab 2561
* C:\HomelabCB\Programmer\HL Flash\hlflash.exe
* ${TARGET_OUTPUT_BASENAME}.hex
* ${TARGET_OUTPUT_DIR}
{{ :et:examples:setup:codeblocks:9_cb_tool2.png?400 |}}
===== Linux/Ubuntu setup=====
Install Codeblocks extras:
sudo apt-get install codeblocks-contrib
To run dfu-programmer with a normal user privileges, create under /etc/udev/ folder a ruled.d file with following content:
SUBSYSTEM=="usb",ACTION=="add",ATTRS{idVendor}=="03eb",ATTRS{idProduct}=="*",GROUP="plugdev"
It is also necessary to install the library.
Typically AVR libraries are located in the folder /usr/lib/avr
It is necessary to own administrator rights to add a folder for the new library.
If the AVR Toolchain repositorys not yet been updated, you may receive an error message for ADC function. To correct this replace manually in the avr folder iox128a1u.h file (included in the library).
To make programming simpler create a following batch file:
sudo nano /usr/bin/homelab-programmer
copy the content of the file:
#!/bin/bash
dfu-programmer atxmega128a1u erase
dfu-programmer atxmega128a1u flash $1
dfu-programmer atxmega128a1u start
crant execution permission:
sudo chmod 775 /usr/bin/homelab-programmer
Codeblocks //Tools->Configure tools ...//
Set the programmer is as follows.
{{ :et:examples:setup:codeblocks:codeblokcs_programmer_linux.png?400 |}}
Add library support
//Settings -> Compiler ...//
{{ :et:examples:setup:codeblocks:compiler_path.png?400 |}}
{{ :et:examples:setup:codeblocks:linker_path.png?400 |}}
===== CodeBlocks creating a project =====
Go to menu //File->New->Project//. There should be selected a project according to HomeLab version and configure it as desired.
First, choose the name and location of the project. **Avoid the use of umlauts.**
{{ :et:examples:setup:codeblocks:10_project1.png?400 |}}
Then select the project compiling folder. It is recommended to not change it.
{{ :et:examples:setup:codeblocks:11_project2.png?400 |}}
Then choose a microcontroller and used frequency.
{{ :et:examples:setup:codeblocks:12_cb_project3.png?400 |}}
Lastly, //AVR Toolchain// installation folder should be set.
{{ :et:examples:setup:codeblocks:13_cb_project4.png?400 |}}
===== Using the CodeBlocks =====
Once the project is created, then the new project appears in the left tree with example code. To compile press the gear icon in the toolbar. If the compilation succeeds then in the bottom //Build Log// window the user program memory count are displayed or if not, then error messages in the event of failure.
{{ :et:examples:setup:codeblocks:14_cb_compile.png?400 |}}
When loading the program into the microcontroller, in case HomeLab III, first should be entered into the bootloader by holding down the button S0 on the Controller module and at the same time, press the reset button to restart. In previous HomeLabs a bootloader mode is not available. If all the necessary drivers are installed (drivers are in CodeBlocks / Programmer folder), then can be download compiled hex file. To start programmer, go to //Tools// menu.
{{ :et:examples:setup:codeblocks:15_cb_programming.png?400 |}}