Both sides previous revisionPrevious revisionNext revision | Previous revision |
en:examples:setup:windows [2010/02/04 15:23] – raivo.sell | en:examples:setup:windows [2020/07/20 09:00] (current) – created - external edit 127.0.0.1 |
---|
===== Installation ===== | ===== Installation ===== |
| |
You need the following software which can be downloaded from manufacturers homepage or acquired from the CD supplied with the HomeLab Kit. | 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** | **1. AVR Studio** |
**3. HomeLab library** | **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. | 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 in the same folder where WinAVR was installed. |
| |
**4.. Virtual COM port driver** | **4.. Virtual COM port driver** |
{{ :examples:install:windows:new_hardware_popup.png?349 |Notice of finding the new device}} | {{ :examples:install:windows:new_hardware_popup.png?349 |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. [[en:examples:setup:portissue|See the complete procedure here ]]. | According to number of virtual ports previously defined on the particular computer the windows assigns next port number for the new device. New COM port name (range number) is generated if the device is plugged in to the same computer using another USB port. 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. [[en:examples:setup:portissue|See the complete procedure here ]]. |
| |
===== Creating new project ===== | ===== 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). | In order to write 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 advised 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. | 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//. | **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//. |
| |
{{ :examples:install:windows:studio_welcome.png?500 |}} | {{ :examples:install:windows:studio_welcome.png?400 |}} |
| |
**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//. | **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 boxes should be also checked, which will create 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. | 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. |
| |
{{ :examples:install:windows:studio_new_project.png?500 |}} | {{ :examples:install:windows:studio_new_project.png?400 |}} |
| |
**3.** On the next dialog box you have to select the debugger platform and microcontroller. HomeLab Kit is using JTAG ICE as debugger platform and ATmega128 as microcontroller. After selections press //Finish//. | **3.** On the next dialog box you have to select the debugger platform and microcontroller. HomeLab kit is using JTAG ICE as debugger platform and ATmega128 as microcontroller. After selections press //Finish//. |
| |
{{ :examples:install:windows:studio_project_programmer.png?500 |}} | {{ :examples:install:windows:studio_project_programmer.png?400 |}} |
| |
**4.** Now the project space is created and new window will open where you can start to write the program source code. | **4.** Now the project space is created and new window will open where you can start to write the program source code. |
{{ :examples:install:windows:studio_overview.png?500 |}} | {{ :examples:install:windows:studio_overview.png?500 |}} |
| |
**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. | **5.** You need to set some project parameters before the first compilation. The important parameters are controller frequency and optimization method. HomeLab controller has frequency 14,7456 MHz (14745600 Hz). The frequency can be set in the project properties with Hz (not MHz): //Project -> Configuration Options -> General//. Optimization method should left -Os, if there is no need for other methods. |
| |
{{ :examples:install:windows:studio_project_properties_general.png?500 |}} | {{ :examples:install:windows:studio_project_properties_general.png?400 |}} |
| |
**6.** For using HomeLab library functions the software have be properly intalled. Every new project requires to add library to list of linked objects. To do that got to //Project -> Configuration Options -> Libraries// and add object "libhomelab.a". | **6.** For using HomeLab library functions the software have to be properly installed. Every new project requires adding library to list of linked objects. To do that go to //Project -> Configuration Options -> Libraries// and add object "libhomelab.a". |
| |
{{ :examples:install:windows:studio_project_properties_libraries.png?500 |}} | {{ :examples:install:windows:studio_project_properties_libraries.png?400 |}} |
| |
If object //libhomelab.a// is missing on the left list the library is not properly installed to the system. You should resinstall it. | If object //libhomelab.a// is missing from the left list the library is not properly installed to the system and it should be reinstalled. |
| |
===== Setting's test ===== | ===== Setting's test ===== |
| |
If the development environment is just set up it is reasonable to test to mbe sure that everything is correct. Simplest way is to write a short program, compile it and upload to controller. | After set up of the development environment it is wise to test it, for ensuring its correctness. Simplest way is to write a short program, compile it and upload to controller. |
| |
**1.** Connect the programmer with ATmega128 board. Be sure that the programmer is connected correctly to JTAG connector (cable is directed away from controller board- see next picture). Connect the controller board supply (small green LED should light up if correct power supply is connected). | **1.** Connect the programmer with ATmega128 board. Be sure that the programmer is correctly connected to JTAG connector (cable is directed away from controller board- see next picture). Connect the controller board supply (small green LED should light up if correct power supply is connected). |
| |
Insert simple C source code: | Insert simple C source code: |
int main(void) | int main(void) |
{ | { |
// pin PB7 to output | // Pin PB7 to output |
DDRB = 0x80; | DDRB = 0x80; |
| |
// endless cycle | // Endless cycle |
while (true) | while (true) |
{ | { |
// pin PB7 invertion | // Pin PB7 invertion |
PORTB ^= 0x80; | PORTB ^= 0x80; |
hw_delay_ms(500); | hw_delay_ms(500); |
[{{ :examples:install:windows:studio_quick_buttons.png?267 |Compilation and programmer buttons}}] | [{{ :examples:install:windows:studio_quick_buttons.png?267 |Compilation and programmer buttons}}] |
| |
Compile the project with //Build// command (keyboard F7). Be sue that the compilation succeeded. For this you should see the following message on the message window. | Compile the project with //Build// command (keyboard F7). Make sure that the compilation succeeded. For this you should see the following message on the message window. |
| |
<code> | <code> |
**2.** Open the controller window //Tools -> Program AVR -> Auto Connect//. Be sure that the tab //Program// is open. | **2.** Open the controller window //Tools -> Program AVR -> Auto Connect//. Be sure that the tab //Program// is open. |
| |
{{ :examples:install:windows:studio_programmer.png?500 |}} | {{ :examples:install:windows:studio_programmer.png?400 |}} |
| |
If the described window does not open and //Connection Failed// window is opened instead you do not have proper connection with the board or programmer. First you should check that micrcontroller has correctly powered (green LED is on) and the programmer is properly connected to JTAG connector. If this is OK check the COM port number which is assigned by the Windows. If this is greater than 9, the AVR Studio can not recognize the programmer. Follow the instructions on the beginning of the document and assign the port number between 0 and 4. | If the described window does not open and //Connection Failed// window is opened instead you do not have proper connection with the board or programmer. First check that micrcontroller is correctly powered (green LED is on) and the programmer is properly connected to JTAG connector. If this is OK check the COM port number which is assigned by the Windows. If this is greater than 9, the AVR Studio can not recognize the programmer. Follow the instructions given in the beginning of the chapter and assign the port number between 0 and 4. |
| |
{{ :examples:install:windows:studio_project_programmer_port.png?500 |}} | {{ :examples:install:windows:studio_project_programmer_port.png?400 |}} |
| |
**3.** On the programmer window insert into //Flash//-section textbox //Input HEX File// the location of the compiled program by pressing the "..." button.Compiled program is usually located in the project folder and sub folder //default// and has same name as the project but with the extension ".hex", for example "labor1.hex". After selecting correct file press button //Program// which uploads the program to the controller. If everything went well you should see the similar message on the end of the same window. | **3.** On the programmer window insert into //Flash//-section textbox //Input HEX File// the location of the compiled program by pressing the "..." button. Compiled program is usually located in the project folders sub folder //default// and has same name as the project but with the extension ".hex", for example "labor1.hex". After selecting correct file press button //Program// which uploads the program to the controller. If all went well you should see the following message on the end of the window: |
| |
OK | OK |
Leaving programming mode.. OK | Leaving programming mode.. OK |
| |
According to the program the on-board LED (PB7) should start flashing. If it works like this you have successfully set up your programming environment and completed your first program. Congratulations! | According to the program the on-board LED (PB7) should start flashing. If the program works you have successfully set up your programming environment and completed your first program. Congratulations! |
| |
{{:kit:kit_test.jpg?500|}} | {{:kit:kit_test.jpg?500|}} |
===== Debugger ===== | ===== Debugger ===== |
| |
[{{ :examples:install:windows:studio_debugger_io_view.png?280|ATmega128 registrite loetelu siluris}}] | [{{ :examples:install:windows:studio_debugger_io_view.png?280|The list of registers in the debugger of the ATmega128.}}] |
| |
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. | Debugging a program means searching errors from the program. For that programs called debuggers are created, they allow to execute the program step by step and stopping it where it is needed. Such implementation of the program allows checking the values of the variables at any phase of the program, contents of the registers and the sequence of executing the program. Debugging is especially important while dealing with more complex programs where it is often difficult to find errors. With microcontrollers, it is important that step-by-step implementation of program is done in the controller, which allows seeing change of real outputs in addition to the values of the registers. Two conditions must be met for using a debugger: microcontroller must support debugging and you must have necessary hardware – JTAG programmer which allows debugging. Cheaper programmers using ISP programming interface may upload compiled program into the controller but not necessarily allow debugging. |
| |
| To start the program in debugging mode with the AVR Studio, firstly it should be compiled by pressing button //build// (F7) and the compiled program started with the command //Run// (F5). Before that //break points// (F9) can be added to selected palces in the source code. When implementation of the program reaches the break point, the program is stopped for determining the state of the microcontroller in that point. Implementation of the program may be continued with command //Run// again or use //Step Into// (F11) for implementing the program one command at the time. |
| |
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 ===== | ===== The usage of floating-point variables ===== |
| |
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: | Some times in AVR program it is necessary to use floating-point variables. For calculating with them and presenting with //printf//-type functions, the following set-up changes must be done to the configuration of the project: |
| |
**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//. | **1.** Open the set-up of the project from the menu //Project -> Configuration Options//. Add //libprintf_flt.a// and //libm.a// after //libhomelab.a// of the library of HomeLab in the configuration tab //Libraries//. |
| |
**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". | **2.** Next, open tab //Custom Options// and chose //[All files]//. Next add lines with "-lprintf_flt" ja "-lm" to the box on the right and line with "-uvfprintf" to the //[Linker Options]// section. |
| |
**3.** Vajutada OK ja sulgeda seadete aken. | **3.** Press OK and close configuration window. |