LabVIEW Embedded for ARM Porting Guide - Chapter 2: Integration of LabVIEW and Keil Toolchains
Overview
The 32-bit RISC ARM processor architecture developed by ARM Limited is widely used across many embedded designs due to its low price, low power consumption, and wide variety of peripherals for many of the major silicon vendors. Today, the ARM family accounts for more than 75 percent of all 32-bit RISC CPUs. You can use the NI LabVIEW Embedded Module for ARM Microcontrollers for programming ARM microcontrollers with the RTX embedded operating system.
This document offers a general outline for targeting LabVIEW code to any custom ARM target. It is the second document in a five-part series that demonstrates the steps you need to take to port LabVIEW code to the Phytec LPC3180 ARM9 microcontroller. For additional information, read these chapters:
Chapter 1: Introduction
Chapter 3: Implementing Elemental I/O
Chapter 4: Porting the RTX Real-Time Kernel
Chapter 5: Integrating the Real-Time Agent
Table of Contents
Integration of LabVIEW and Keil Toolchains
To port an ARM target to LabVIEW, the target must support the RTX Real-Time Kernel. For an ARM target to support live front panel debugging, the target must also work with the Real-Time Agent module.
To determine if your target already supports the RTX Real-Time Kernel, browse to the \Keil\ARM\Startup directory, then browse to the folder that corresponds to the manufacturer of your ARM microcontroller. If there is an RTX_Conf*.c file for your target, then the RTX Real-Time Kernel has already been ported for your ARM device. If no such file exists, skip to chapter 4 for more information on the RTX Real-Time Kernel and a guide for porting RTX to your ARM microcontroller.
To determine if your target already supports the Real-Time Agent module, browse to the \Keil\ARM\RT Agent\RTX directory, and locate the device that corresponds to your ARM microcontroller. If you are able to locate your device in this directory, then the Real-Time Agent module has already been configured for your device. If your device does not exist in this directory, skip to chapter 5 for more information about the Real-Time Agent module and a guide for adding the module to your application.
If the RTX Real-Time Kernel and Real-Time Agent module have already been developed for your ARM microcontroller, continue with this chapter to create a new embedded target in LabVIEW. Creating the target entails modifying a template μVision project to a form that LabVIEW recognizes, incorporating all of the driver source code for the essential peripherals, and integrating the Keil toolchain.
If support for the RTX Real-Time Kernel and Real-Time Agent module has not already been developed for your ARM microcontroller, such as the case with the LPC3180, see chapters 4 and 5 for more information on how to accomplish this.
Use the Target Editor to Manage Embedded Targets (Microprocessor SDK required)
NOTE: This portion of the tutorial requires the LabVIEW Microprocessor SDK. If you do not own a copy of the LabVIEW Microprocessor SDK, follow the instructions in this alternative tutorial.
All of the ARM targets for LabVIEW use the same plug-in VIs. Therefore, to ease the process of adding a new ARM target to LabVIEW, a template target has already been provided that contains a TgtSupp.xml file configured with the correct plug-in VIs, folder structure, and placeholder driver files. Creating a new target for LabVIEW involves making a copy of this template target and giving it a proper name that clearly identifies what the target is.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView directory.
- Make a copy of the Generic folder and rename it LPC3180.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\LPC2378 directory and copy everything in this folder.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\ directory and paste everything that was copied from the LPC2378 folder.
- Delete the LM3Sxxxx and LPC2378 folder.
- Open LabVIEW and select Tools»Embedded»Target Editor.
- Select File»Open, then browse to the LPC3180 folder renamed in the previous step.
- Locate and open the TgtSupp.xml file.
- Right-click the Other icon and rename it LPC3180.
- Right-click Applications and select Properties.
- On the Category page, select Manage Interrupts and delete this entry be clicking the Red X Remove Property Page Button.
- Click OK to return to the Target Editor.
- Select File»Save, then exit the Target Editor. You have now created the target.
- Close LabVIEW completely and open LabVIEW again so that the available targets are renumerated.
Prepare the Template Files
LabVIEW relies on a properly configured µVision project that defines where to locate various driver files that are target-specific. Because these driver files are target-specific, some of the driver files included in the generic template are reusable while others are not. Follow these steps to prepare the appropriate driver files for the LPC3180.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\eio directory and delete everything in this folder. You will create elemental I/O drivers for the target in a later chapter.
-
Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\interrupt\ directory. Delete all files in this directory except the interrupt.xml file. The interrupt.xml file for the LPC2378 configures how LabVIEW generates code when using interrupts. Because interrupts for the LPC2378 are incompatible with those for the LPC3180, do not use interrupts. Integrating interrupts are beyond this document’s scope; therefore, consult the LabVIEW Embedded Module for ARM Help for more information.
- Open interrupt.xml in a text editor.
- Delete all of the text in this file and replace it with the following:
- <Version>1</Version>
- <Array>
- <Name>ProvidedInterruptData</Name>
- <Dimsize>0</Dimsize>
- </Array>
- Save interrupt.xml and exit the text editor.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\Template\System directory, and delete the RTX_Config.c and LPC2300.s files. Copy the LPC3000.s, Retarget.c, and RTX_Config.c created for the LPC3180 in chapter 5 to this directory. These files are also included in the chapter 5 folder contained in the LPC3180.zip solution files.
- Open RTX_Config.c in a text editor.
- Add the following header file:
- #include <LVConfig.h> /* LV Config header */
- Close and save RTX_Config.c.
- Open LPC3000.s in a text editor.
- Comment out the following lines from the startup file:
- Undef_Handler B Undef_Handler
- PAbt_Handler B PAbt_Handler
- Add the following line to the startup file:
- IMPORT Undef_Handler
- IMPORT PAbt_Handler
- Close and save LPC3000.s.
- These changes allow LabVIEW to set the correct error bits when an Undefined IRQ handler or Prefetch Abort handler fires.
- Comment out the following lines from the startup file:
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\Template\Project directory. Copy the Ext_RAM.ini and Clock.ini files created for the LPC3180 in chapter 4 to this directory. These files are also included in the chapter 4 folder contained in the LPC3180.zip
- Open Ext_RAM.ini in a text editor and modify the line that states
- LOAD Ext_SDRAM\Blinky.axf INCREMENTAL
- to the following:
- LOAD Obj\LabVIEW.axf INCREMENTAL
- Close and save Ext_RAM.ini.
- The template μVision project is configured by default to compile the application into an executable named LabVIEW.axf in the Obj directory; therefore, this change ensures that the correct file is loaded into memory upon execution.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\Template\Drivers directory. Delete the Ethernet, Interrupt, I2C, and SPI folders.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\Template\Drivers\RTClock directory. Open ARM_RTClock.c in a text and delete the code for both functions, ARM_rtc_gettime() and ARM_init_rtc();
- Save ARM_RTClock.c and exit the text editor.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180 directory. Open TargetConfig.ini in a text editor.
- Delete all text below the line that states “[Files].”
- In the [Define] Section, add the following line: SocketSupport = 0.
Modify the Template uVision Project
When LabVIEW compiles a VI, it makes calls to μVision, directing it to open up a preconfigured project that has been customized to the specific target. This preconfigured project defines how μVision compiles the code. It also defines how the code is downloaded and run on the target.
- Open the μVision 3 environment.
- Open the Project menu and select Open Project….
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\Template\Project directory and open the LabVIEW.uV2 project.
- In the Project Workspace, under the Target Startup folder, remove the LPC2300.s file by right-clicking the individual file and selecting Remove File…. Also, remove the LPC23_EMAC.c, ARM_irq.c, ARM_I2C.c, and ARM_SPI.c files from the Target Drivers folder.
- Right-click the Target Startup folder and select Add Files to Group “Target Startup.” Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\Template\System and add the LPC3000.s and Retarget.c files that were copied to this directory in the previous section.
- Configure the project options by selecting the Options for Target icon
on the build toolbar.
- On the Device tab, select the NXP LPC3180 in the CPU vendor database list.
- Configure the Target settings as shown.
- Make sure the Operating system is set to use the RTX Kernel.
- Set the Code Generation for Thumb-Mode, make sure Cross-Module Optimization is checked, and make sure Use MicroLIB is NOT checked.
- Ensure that the Xtal is set to 13.0 MHz and that the Read/Only Memory Areas off-chipROM1 and Read/Write Memory Areas off-chip RAM1 are checked. Set the Memory Areas Start and Size as follows:
- On the Output and Listing tab, leave the settings as they are. The name of the executable MUST be LabVIEW.
- Change to the Asm tab. In the Conditional assembly control Symbols, Define field, type RAM_INTVEC, REMAP. When set, the startup code copies exception vectors from on-chip flash memory to on-chip RAM, and from on-chip RAM to address 0. For documentation on the various SET symbols, see the top of the device’s startup file (LPC3000.s).
- In the Debug tab, select the Use: ULINK ARM Debugger option.
- Configure the ARM Target Driver Setup by clicking the Settingsbutton. The ARM Target Driver Setup settings should be as follows with Max JTAG Clock set to RTCK and all Debug options checked (Cache Options, Download Options, and Misc Options):
- Click OK to return to the Options for Target window.
- Be sure that the Load Application at Startup, under the ULINK ARM Debugger setting, is checked.
- Add the correct Initialization File by clicking the browse button and select the Ext_RAM.ini filethat you previously copied into the same folder as the project.
- The Debug tab should now appear as follows:
- In the Utilities tab, configure the Target Driver for Flash Programming by clicking the Settings button.
- Select the LPC2000 IAP2 512kB Flash and click the Remove button.
- Click the Add button. In the new window, highlight the LPC3180 NAND Flash SP and then click Add to return to the previous window.
- Configure the remaining Flash Download Setup options as follows and click OK. Be sure to set the RAM for Algorithm Start and Size values correctly.
- Back on the Utilities tab, add the correct initialization file by clicking the browse button and select the Clock.ini file that you previously copied into the same folder as the project.
- The Utilities tab should now appear as follows:
- Click OK to return to the Project Workspace. Save the project and exit μVision.
Add support for the Advanced Analysis Libraries
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\MCB2300 directory. Copy the build directory, and paste it into the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180 directory. Under the LPC3180 directory, create a new folder named “lib.”
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\build directory and open LVAnalysis.Uv2 in the μVision environment.
- Configure the project options by selecting the Options for Target icon
on the build toolbar.
- On the Device tab, select the NXP LPC3180 in the CPU vendor database list.
- Configure the Target settings as shown.
- Make sure the Operating system is set to use the RTX Kernel.
- Set the Code Generation for Thumb-Mode, make sure Cross-Module Optimization is checked, and make sure Use MicroLIB is NOT checked.
- Ensure that the Xtal is set to 13.0 MHz and that the Read/Only Memory Areas off-chipROM1 and Read/Write Memory Areas off-chip RAM1 are checked. Set the Memory Areas Start and Size as follows:
- In the Output tab, click on the Select Folder for Objects button and browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\build directory and click OK.
- In the Listing tab, click on the Select Folder for Listings button and browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\build directory and click OK.
- Click OK to return to the project workspace.
- Build the library by selecting either the Build Target icon
on the build toolbar or the Project»Build target on the main menu bar.
- When the build is complete, a LVAnalysis.lib file will appear in the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\lib directory.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\ directory and open TargetConfig.ini in a text editor.
- Under the line that states [FILES], add the following:
- <LABVIEW>\Targets\Keil\Embedded\RealView\LPC3180\lib\LVAnalysis.lib = lib
- Save and close TargetConfig.ini.
Download and Execute a Program on the Target
Having modified the template µVision project, the next step is to create a LabVIEW Project, target the device, and verify that a simple VI can be compiled, downloaded, and executed on the target. Before doing so, ensure that you have downloaded the secondary boot loader for the LPC3180 to the target. Execution from flash memory does not operate correctly without this secondary boot loader. For more information about the boot loader and instructions for loading it onto the target, see chapter 4.
Create a New Project
- Open LabVIEW and create a new project by selecting File»New Project.
- In the Project Window, save the project by selecting File»Save As. Select a directory for your project and name the project LPC3180.
- Right-click project LPC3180.lvproj and select New»Targets and Devices.
- Under Targets and Devices, expand the Embedded folder, select the LPC3180 target, and then click OK.
- Back on the Project Explorer, right-click the LPC3180 target and select New»VI.
- In the newly created VI, recreate the following code by placing a while loop and creating an indicator on the loop iteration terminal. Place a Wait (ms).VI in the while loop and connect a constant 100 to the milliseconds to wait input.
- Save the VI as Main.vi.
- In the Project Explorer, right-click Build Specifications and select New»Application.
- To enable the debugging features, select Application Information under the Category window and ensure that the “Enable debugging” option is checked.
- Next, select Advanced Debugging Options under the Category window and ensure that the USB ULINK2 JTAG is the selected Debugging Mode.
- Select Source Files under the Category window and select Main.vi as your Top-level VI. Click OK to return to the Project Explorer.
- Go to the front panel of Main.vi.
- Click the Run Arrow to compile the VI, download it to flash memory, and execute the program.
- Successful execution of the VI should increment the Numeric indicator approximately once every 100 ms to indicate the value of the iteration terminal.
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
