Академический Документы
Профессиональный Документы
Культура Документы
Introduction
This lab will familiarize you with the IAR Embedded Workbench for ARM and will utilize the Fujitsu KSK-MB9BF506 evaluation board. EWARM has the ability to simulate a generic Cortex M3 core, but for the purposes of this lab, we will utilize the F506 evaluation board and an IAR J-Link. Upon completion of this lab, you will have a better understanding of how EWARM functions so that you can create your own projects as well as be confident when you are conversing with customers who also use the IAR toolchain. The lab is written for EWARM v5.50 but older versions of the tool will resemble the pictures contained therein. Since the overall footprint of the application that we will develop is around 3kB, it can be built with any version of EWARM (full, evaluation or KickStart). While the easiest way to get started on a project is to modify an existing one, this lab will assume that we are building one more-or-less from scratch.
2.) Start the Embedded Workbench for ARM. Once EWARM is loaded, you will notice that the Information Center is visible. From the Information Center, you can view the sample workspaces for your board. For this lab, however, we will be building our own application from scratch. 3.) You should have a copy of Fujitsu.zip, a zip file which contains the source code as well as the Linker Configuration File, setup macros, and flashloaders that will be necessary for our project. We will be adding these to our project. In practice outside of this lab, you can create new source code and header files that can be included in the project. This zip file should be unzipped in the ..\My Documents\IAR Embedded Workbench\ directory. 4.) Click File-New-Workspace. You should now have a blank slate that looks like this:
6.) We will be asked where we would like to store our project; by default, workspaces and projects are stored in the ..\My Documents\IAR Embedded Workbench\ directory. Well choose the Fujitsu FAE Training Lab directory that we unzipped earlier. Name the project F506 blinky and click Save. We now have a project with no files:
7.) Next, we will add code to our project. Our blinky example uses code from a couple of different directories, so we will add code for each of these separately to make it easier on ourselves. You will notice that the code in Fujitsu FAE Training Lab directory is contained in three spots: main.c in the root directory, board support files in the modules directory and the startup file in the startup directory. In order to keep our code organized, we will preserve that directory structure within the IAR workspace through the use of groups. Lets begin by adding the code from the modules directory. Click Project-Add Files. In the window that pops up, double-click the modules directory. Select the two C files drv_hd44780.c and drv_hd44780_l.c and click OK.
8.) To keep our code organized, we will put these files in a group. Click Project-Add Group. Name the group modules and click OK. You will see a modules folder in your Workspace window. Drag and drop each one of the three source files we just added into the CMSIS folder. Note that adding groups to your project and putting code in those groups does not impact EWARM at all it is to help the engineers keep their code organized.
12.) Notice that there is a function called HD44780_IO_Init( ) near the top of main( ). Rightclick that function name and choose Go to definition. The source window will open drv_hd44780_l.c and take you to the declaration of that function. To go back to main( ), click the Navigate Backward button on the toolbar near the top of the IDE. 13.) Click View-Source Browser. You will see a Visual C++-like source browser that shows you the functions, structures and defines that are in your code. Double clicking any one of these will take you to their definition in the code. A few things should be noted at this point. First, a project has by default two build configurations, Debug and Release. The difference between them is that Debug has Low optimization set and Release has Medium optimization. We will learn how to change that in part 2, Also, files are saved every time you do a build. You can quickly thumb between the open files in your source window by clicking the file name tab at the top of the source window.
End of Part 1
Notice that the default is for an ARM7TDMI core, but we are using the F506 CM3. Under Processor Variant, choose Device and select Fujitsu and then the MB9BF506.
4.) Double-click the map file in the Workspace window so that we can see what the sizes of our modules are as well as where they are placed. Near the end of this file, we see that the main( ) function is located at address 0x30F and is of size 0xB4 bytes (the location and size may vary depending on the settings you chose).
6.) Click Project-RebuildAll so that we can see the sizes of the modules. Scroll through the Build Messages Window to see that main.cs size is 990 bytes of code, 172 bytes of constants in flash and 8 bytes of RAM while the overall application is 2,960 bytes of code and 2,064 bytes of RAM with an additional 276 bytes of constants in flash. Also note that the Build Messages Window shows you the command line invocation of the tools on individual files in the project, so had we chosen to log the build messages in step 5, we would almost have a complete makefile. 7.) Lets move the main( ) function to address location 0x1000. We can do this by adding a pragma directive just before the main( ) function. On the line before int main( ), add this line: #pragma location="MyMainFunction Next, open the ICF file we chose with a text editor. Find the line: place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; Once you have located this line, place the following line just after it: place at address mem:0x1000 {section MyMainFunction}; Now, return to the project and do a RebuildAll. You will notice that in the map file, the location for the main function has changed. Note that instead of giving us the address of 0x1000, the address is 0x1001. In Cortex M3 architectures, data is even-byte aligned but code is odd-byte aligned.
End of Part 3
From this window, you can modify any breakpoint. However, let us execute the code up to that breakpoint you can do so by pressing F5 or pressing the Go button ( ) to execute the code. Notice that the breakpoint window now has a green arrow next to the breakpoint to indicate that is where you currently are halted. If we want to change the behavior of this breakpoint to stop, say, every hundredth time it hits the breakpoint, we can do so by turning this breakpoint into a conditional breakpoint. Right-click the breakpoint in the Breakpoint Window and choose Edit. In the Skip count section, put 100 and click OK.
Remember that the green arrow indicates if we are debugging at the source- or disassemblylevel (by clicking back in the source window, we can return to source-level debugging). Now lets see where the PSW1 button is located in memory. We can single-step to the source line of if(~(BUT_PDIR&PSW1)), we can see that the address of the button will be loaded into R0. Press F10 or the Step Over button to load the address of the variable into R0 by looking at the Register Window (View-Register if it isnt already visible), we see that the address is 0x40033314. Also note that windows in the IDE can be docked, i.e. they can be dragged-anddropped on top of one another. This can help clean up your IDE view so you can see what is currently important to you!
Now we can choose options of breaking when the data is read, written or both. Additionally, we can choose to break only when the data matches a certain pattern. Lets set it for breaking only when the data is written. In our Breakpoint Window, delete our old code breakpoint by either selecting it and pressing Delete or right-clicking the breakpoint and clicking Delete. Now run the code and you will see that you quickly hit the data breakpoint! Breakpoints can be turned off without deleting them by unchecking their box in the Breakpoints Window. 14.) Open the Watch Window by clicking View-Watch. We can watch the values of variables, arrays and structures within this window. To quickly insert an element in the watch window, double-click the element name in the source window and drag-and-drop it into the Watch Window. Try double-clicking cntr and then drag-and-drop it into the Watch Window.
16.) Now, lets try attaching to a running target. This is useful if you have a board that is running code out in the field but has suddenly gone off in the weeds. This technique allows you to see what is happening on the board. To see this at work, deselect all breakpoints from the Breakpoint Window and click Go or press F5. Now press the Stop Debugging button on the toolbar ( ). You should see the LED on the board continue to blink so long as there is still power to the board this simulates a board running in the field. If youd like, you can detach the debugger from the board to see that it is still running (but you will need to externally power your board) and then reattach it to make sure that the board is completely running on its own volition. Now go to Project-Options-Debugger-Download and select Attach to program notice that this will automatically deselect the Use flash loader option.