This is an old revision of the document!


Installation instructions for Windows

this section contains the information necessary to install AVR development software on Windows operating system.

Installation

You need the following software which can be downloaded from manufacturers homepage or acquired from the CD supplied with the HomeLab Kit.

1. AVR Studio

AVR Studio 4 IDE (Integrated Development Environment) is a base software for writing the source code, compiling it and uploading the program to the controller. AVR Studio can be downloaded from Atmel homepage.

2. WinAVR

WinAVR is a GNU-GCC compiler for AVR microcontrollers. This is a freeware which can be downloaded from Sourceforge webpage. During the installation process WinAVR offers a folder name containing long version number. We suggest to cut the version number from folder name and install it just like shown below:

C:\WinAVR

3. HomeLab library

HomeLab library is a set of functions designed for HomeLab Kit and AVR controllers. By using the library the programming is much easier and effective. Latest version of the library can be downloaded from the HomeLab webpage. This library should be installed to the same folder where WinAVR was installed.

4.. Virtual COM port driver

Driver enables to connect USB JTAG-ICE programmer with your PC. Driver have to be installed before connecting the programmer. Driver file name is “CDM x.xx.xx.exe”, where “x” denotes the version number. After installing the driver you can connect the JTAG-ICE programmer through the USB port and let Windows to detect the device automatically. You should see the notice on the windows task bar.

Notice of finding the new device

According to number of virtual ports defined before on the particular computer the windows assigns next port number for the new device. New COM port name (range number) will be also generated when the device is plugged another USB port on the same computer. Some AVR Studio versions can not use the programmer if the COM port number exceeds number 10 and number 4 in case of using it as debugger. To prevent this situation you can modify the assigned port number in Device manager and assign it to the range COM0…COM4. See the complete procedure here .

Creating new project

Writing a program for the controller you need to create the project space. The project includes typically different files like source codes, header files, compiled program files, etc. It is strongly suggested to create new folder for every project (which is offered also by the New Project Wizard).

Following steps have to be completed when creating new project with the help of wizard.

1. Open AVR Studio and press New Project. If the dialog box is not opened automatically select Project - New project from the menu bar. Press Next.

2. Next dialog box is about compiler and initial settings. Select AVR GCC compiler. On the left, insert the name of the project and main source file name. The source file name should have extension “.c”. Two check box should be also checked which will create then the new folder and initial file. You should also show the folder where project files will be created. After proper selections press Next.

NB! If AVR GCC is missing on the compiler list, it is not properly installed. In that case the WinAVR software have to be installed before starting to write C source code.

3. On the next dialog box you have to select the debugger platform and microcontroller. HomLab Kit is using JTAG ICE as debugger platform and ATmega128 as microcontroller. After selections press Finish.

4. Now the project space is created and new window will open where you can start to write the program source code.

5. Before the first compilation you need to set some project parameters. The important parameters are controller frequency and optimization method. HomeLab controller has frequency 14,7456 MHz (14745600 Hz). The frequency can be set on the project properties with Hz (not MHz): Project → Configuration Options → General. Optimization method should left -Os, if there is no need for other methods.

6. Kodulabori teegi kasutamine AVR Studio-ga eeldab, et see on tarkvara paigaldamise juhendi kohaselt süsteemi paigaldatud. Iga projekti korral tuleb teek projekti seadetest Project → Configuration Options → Libraries lisada lingitavate objektide nimekirja.

Kui objekt libhomelab.a nimekirjast puudub, siis ei ole kodulabori teek korrektselt süsteemi paigaldatud.

Seadistuste testimine

Kui arenduskeskkond on esimest korda paigaldatud ja seadistatud, on mõistlik testida, kas kõik sai tehtud õigesti. Selleks on lihtsaim viis teha üks väike programm, see ära kompileerida ja laadida kontrollerisse.

1. Ühendada programmaator ATMega128 plaadiga. Ühendamisel kontrollida, et programmaator saab ühendatud õigesse pesasse (JTAG) ja õigetpidi (kaabel on suunatud kontrolleri plaadist eemale - vaata järgmist pilti). Peale programmaatori ühendada ka kontrolleri toide (kontrolleri plaadil peab süttima väike roheline LED). Sisestada lihtne C-kood:

#include <avr/io.h>
#include <homelab/delay.h>
 
int main(void)
{
	// Viigu PB7 seadmine väljundiks
	DDRB = 0x80;
 
	// Lõputu tsükkel
	while (true)
	{
		// Viigu PB7 inverteerimine
		PORTB ^= 0x80;
		hw_delay_ms(500);
	}
}
Kompileerimise ja programmaatori nupud

Kompileerida programm käsuga Build (kiirklahv F7) ja kontrollida, et kompileerimine õnnestuks. Selleks peab teadete aknasse tekkinud kompilaatori väljundi lõpp olema järgmine:

Build succeeded with 0 Warnings...

2. Avada koodi laadimise aken nupust Tools → Program AVR → Auto Connect. Tulemuseks peaks avanema kompileeritud faili mikrokontrollerisse laadimise aken. Kontrollige, et avatud oleks kaart Program.

Kui eespool toodud aken ei avane ja avaneb aken Connection Failed, siis puudub ühendus programmaatoriga. Esmalt tuleks kontrollida, kas mikrokontrolleril on järel toide ja kas programmaator on ühendatud õigesti (JTAG pistikusse, kaabel õiges suunas). Kui see on korras, siis tuleks kontrollida, mis COM pordi numbri on Windows programmaatorile omistanud. Kui see on suurem 9-st, siis ei pruugi tarkvara seda leida ja pordile tuleb omistada väiksem järjenumber.

3. Programmaatori aknas sisestada Flash-sektsioonis tekstikasti Input HEX File kompileeritud fail. Seda saab teha “…” nuppu vajutades. Kompileeritud fail asub tavaliselt projekti alamkataloogis default ja see on sama nimega, mis projekt, kuid laiendiga “.hex”, näiteks “labor1.hex”. Pärast õige faili valimist vajutada nupule Program, mis laeb valitud programmi kontrollerisse. Kui kõik õnnestus, tekib programeerimiskeskkonna allosasse teade:

OK
Reading FLASH input file.. OK
Setting device parameters for jtag programming ..OK
Entering programming mode.. OK
Erasing device.. OK
Programming FLASH ..       OK
Reading FLASH ..       OK
FLASH contents is equal to file.. OK
Leaving programming mode.. OK

Prorammi mõjul peaks kontrolleri plaadil olev LED PB7 perioodiliselt süttima ja kustuma. Kui programm töötab, on tarkvara paigaldatud edukalt ja esimene projekt tehtud. Palju õnne!

Siluri kasutamine

ATmega128 registrite loetelu siluris

Programmi silumiseks (inglise keeles debugging) nimetatakse vigade otsimist programmist. Selleks on loodud eraldi vahendid - silurid (inglise keeles debugger), mis võimaldavad programmi täita samm-sammult, peatades seda soovitud kohtades. Selline programmi täitmine võimaldab igas programmi faasis kontrollida muutujate väärtusi, registrite sisusid ja programmi täitmise järjekorda. Eriti oluline on silumise võimaluse kasutamine keerukamate programmide juures, kus vea põhjust on tihti keeruline otsida. Mikrokontrollerite puhul on veel oluline, et tarkvara samm-sammult täitmine toimub reaalselt kontrolleris ja võimaldab nii lisaks registrite väärtuste vaatamisele näha ka reaalsete väljundite muutumist. Siluri kasutamiseks on eelkõige vaja kahte tingimust: kasutatav mikrokontroller peab silumist toetama ja olemas peab olema ka vajalik riistvara - silumist toetav JTAG programmaator. Odavamad programmaatorid, mis kasutavad ISP programmeerimise liidest, võimaldavad laadida kontrollerisse küll kompileeritud programmi, kuid ei võimalda silumist.

Programmi käivitamiseks siluri režiimis AVR Studio-ga tuleks see esmalt kompileerida nupuga Build (kiirklahv F7) ja käivitada kompileeritud programm käsuga Run (kiirklahv F5). Programmi lähtekoodi võib enne seda soovitud kohtadele lisada katkestuspunkte (inglise keeles break point) (kiirklahv F9). Kui programmi täitmine jõuab katkestuspunktini, peatatakse programmi töö, võimaldades nii uurida mikrokontrolleri olekut sellesse punkti jõudmisel. Programmi täitmist võib jätkata jällegi käsuga Run või siis kasutada käskhaaval täitmist käsuga Step Into (kiirklahv F11).

Ujukoma-arvude kasutamine

Mõnikord tekib vajadus AVR programmis kasutada ujukoma-arve. Nendega arvutamiseks ja nende esitamiseks printf-tüüpi funktsioonidega tuleb projekti seadistustes teha järgmised muudatused:

1. Avada projekti seaded menüüst Project → Configuration Options. Seadete kaardil Libraries tuleb sinna, kuhu on lisatud kodulabori teegi objekt libhomelab.a, järgi lisada ka libprintf_flt.a ja libm.a.

2. Seejärel tuleb avada Custom Options kaart ja valida [All files] sektsioon. Parempoolsesse kasti lisada read “-lprintf_flt” ja “-lm”. [Linker Options] sektsiooni lisada rida “-uvfprintf”.

3. Vajutada OK ja sulgeda seadete aken.

en/examples/setup/windows.1265295147.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0