Both sides previous revisionPrevious revisionNext revision | Previous revision |
en:examples:setup:windows [2010/03/01 21:35] – priitj | 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. |
{{ :examples:install:windows:studio_welcome.png?400 |}} | {{ :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?400 |}} | {{ :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?400 |}} | {{ :examples:install:windows:studio_project_programmer.png?400 |}} |
{{ :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?400 |}} | {{ :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?400 |}} | {{ :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: |
[{{ :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> |
{{ :examples:install:windows:studio_programmer.png?400 |}} | {{ :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?400 |}} | {{ :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.}}] |
| |
Debugging a program means searching faults in the program. To do that programs called debuggers are created, they allow observing the program step by step and stopping the program 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. Especially important is using debugging when dealing with more complex programs where it is often difficult to find faults. At microcontrollers, it is also important that implementing the program step-by-step is done in the controller and allows to see in addition to the values of the registers also change of real outputs. For using debugger, two conditions must be filled: microcontroller must support debugging and you must have necessary hardware – JTAG programmer which allows debugging. Cheaper programmers which are using ISP programming interface may upload compiled program into the controller but may not allow debugging. | 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, it should be first compiled by pressing button //build// (F7) and start the compiled program with the command //Run// (F5). To the source code of the program may be added //break points// where desired (F9). If the implementation of the program arrives to the break point, the program is stopped and the state of the microcontroller may be investigated at the moment of arrival to that point. Implementation of the program may be continued by giving command //Run// again or use implementing command by command, this is done with command //Step Into// (F11). | 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. |
| |
| |
===== The usage of floating-point variables ===== | ===== The usage of floating-point variables ===== |
| |
Sometimes it is necessary to use floating-point variables int the program of AVR. When calculating with these and presenting them with //printf//-type functions following set-up changes must be done to the configuration of the project: | 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.** Open the set-up of the project from the menu //Project -> Configuration Options//. On the configuration tab //Libraries// comes where the object //libhomelab.a// of the library of the HomeLab was added, after that must be added also //libprintf_flt.a// and //libm.a//. | |
| |
**2.** Next, //Custom Options// tab must be opened and //[All files]// section must be chosen. To the box on the right rows "-lprintf_flt" ja "-lm" must be added. To the //[Linker Options]// section must be added row: "-uvfprintf". | **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.** 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.** Press OK and close configuration window. | **3.** Press OK and close configuration window. |