1 Teaching Precision Data Converters to speak Stellaris Kevin Duke.

download 1 Teaching Precision Data Converters to speak Stellaris Kevin Duke.

If you can't read please download the document

description

3 Stellaris’ fit in the TI Embedded Portfolio

Transcript of 1 Teaching Precision Data Converters to speak Stellaris Kevin Duke.

1 Teaching Precision Data Converters to speak Stellaris Kevin Duke 2 Introduction Why Stellaris? StellarisWare is a helpful asset for quickly and easily delivering sample code with minimal experience on the platform Stellaris evaluation boards have on-board emulation circuitry 32 bit ARM Cortex M3 Core 3 Stellaris fit in the TI Embedded Portfolio 4 5 Introduction Why Code Composer Studio? One of the many tool-chains that StellarisWare supports Easy to use tools to view and export data in memory for analysis/evaluation Dedicated internal support via the E2E Community 6 As simple as 7 lines of code... 7...and 5 blue wires 8 Agenda C Review Code Composer Studio Stellaris Peripherals Creating Sample Code Questions 9 C Review - Variable Types, Qualifiers, & Modifiers - StellarisWare variable naming convention - Function Prototypes & Definition 10 Variable Declaration & Qualifiers Common Qualifiers: const indicates a structure or variable that contains a non- modifiable run-time value volatile indicates a structure or variable that is subject to sudden change and will be excluded from compiler optimization 11 Volatile Keyword Example tBoolean bNewData = FALSE;// Flag for new data while( !bNewData ) { //Do something else } 12 Volatile Keyword Example tBoolean bNewData = FALSE;// Flag for new data while( 1 ) { //Do something else } 13 Volatile Keyword Example Volatile tBoolean bNewData = FALSE;// Flag for new data while( !bNewData ) { //Do something else } 14 Variable Declaration & Modifiers Common Modifiers: extern indicates that the initial value of a variable or body of a function is defined in another source file static is typically used inside function calls and indicates that the structure or variable will only be initialized once and its value will be maintained even when it leaves scope 15 Variable Types & Type Modifiers Basic Types: char is an 8 bit fixed point allocation int is usually a 16 bit fixed point allocation, but should be used with a type modifier for clarity float is a 32 bit single precision floating point allocation double is a 64 bit double precision floating point allocation Type Modifiers: signed indicates the data format is binary twos complement unsigned indicates the data format is straight-binary short specifies a 16 bit allocation long specifies a 32 bit allocation or increases allocation size Note: unsigned short is a valid declaration 16 tBoolean Type Bool and Boolean are not keywords in standard C tBoolean is an unsigned char typedef created and used heavily by StellarisWare As a good rule of thumb always include inc/hw_types.h in source utilizing StellarisWare typedef unsigned char tBoolean; #ifndef true #define true 1 #endif #ifndef false #define false 0 #endif 17 Function Prototypes Function prototypes tell the compiler what the function looks like and how it behaves Function prototypes follow the pattern: ( ); 18 Function Prototypes - Examples void enablePeripheral(); - A generic enable function prototype that returns nothing and takes no parameters signed short readData(); - A generic read function prototype that takes no parameters but returns a signed short tBoolean writeData(signed short ssData); - A generic write function prototype that writes a signed short to the serial peripheral and returns a tBoolean indicating success or failure 19 StellarisWare Naming Convention Variable types & return types are made clear in each declaration: Generic Examples: unsigned short usVariable; unsigned long ulVariable; signed short ssVariable; signed long slVariable; unsigned char * pucVariable; 20 HWREG & Writing to Memory Directly A series of HWREG macros are defined in hw_types.h along with the tBoolean declaration HWREG() is a simple macro that type casts values appropriately to be treated as locations in memory Used heavily by StellarisWare and looks scary, but is pretty simple 21 Code Composer Studio - Creating a Stellaris Project 22 Creating & Configuring a Stellaris Project Create a New CCS Project Add the Vector Table Setup Compiler Include Paths Setup Linker Search Paths Pre-defined Symbols 23 Create a New Project File > New > CCS Project 24 Create a New Project CCS Generates: Target configuration file for ICDI Linker command file Empty main file Whats here will build cleanly, but it wont run 25 Creating & Configuring a Stellaris Project Create a New CCS Project Add the Vector Table Setup Compiler Include Paths Setup Linker Search Paths Pre-defined Symbols 26 What is the NVIC? Nested Vectored Interrupt Controller Part of what makes the ARM Cortex M3! The NVIC... Enables / Disables interrupts Sets / Arbitrates interrupt priority Provides low-latency interrupt processing Works closely with the processor core for low-power modes Saves the processor state on entry to any given interrupt 27 What is the Vector Table? Maps NVIC events to action carried out by interrupt service routines The vector table always carries a unique name in each toolchain/IDE In CCS it is called startup_ccs.c How to generate your own vector table Copy & Paste a vector table from a sample StellarisWare project or use the one embedded in this slide Create a new source file in CCS, name the file startup_ccs.c, paste the contents of the file embedded in this slide If using a vector table from a StellarisWare project, make sure that it doesnt have any un-needed or undefined ISR referenced 28 The Vector Table 29 Creating & Configuring a Stellaris Project Create a New CCS Project Add the Vector Table Setup Compiler Include Paths Setup Linker Search Paths Pre-defined Symbols 30 Compiler Include Paths The include paths tell the compiler where to look for files external to the CCS project (i.e. StellarisWare header files!) Including source files in an include path does not mean that those files will be compiled when CCS builds the project Project > Properties > Build > ARM Compiler > Include Options 31 Creating & Configuring a Stellaris Project Create a New CCS Project Add the Vector Table Setup Compiler Include Paths Setup Linker Search Paths Pre-defined Symbols 32 Linker Search Path Since included files are not compiled with the rest of the project when CCS builds the project instead, pre-built libraries are provided for the linker to integrate with the project post-compile Project > Properties > ARM Linker > File Search Path 33 Creating & Configuring a Stellaris Project Create a New CCS Project Add the Vector Table Setup Compiler Include Paths Setup Linker Search Paths Pre-defined Symbols 34 Predefined Symbols The StellarisWare API is usable by all Stellaris devices, symbol definition is used to help describe to StellarisWare the environment it is being used in Generally there are 3 required definitions IDE/Toolchain Part Number Device Family Project > Properties > Build > ARM Compiler > Advanced Options > Predefined Symbols 35 Creating & Configuring a Stellaris Project Create a New CCS Project Add the Vector Table Setup Compiler Include Paths Setup Linker Search Paths Pre-defined Symbols Write Sample Code! 36 Code Composer Studio - Useful Tools 37 Watch Expressions While debugging a project in CCSv5 any variable or data structure can be added to the Watch Expression window to monitor its value Highlight the variable, right-click, & select Add Watch Expression 38 Graphing Tools Sequential ranges of memory can be graphed & the graphing tool offers a variety of ways to look at the data Assign data format, x-axis, address increment, etc. Items in the Watch Expression window can be quickly graphed by selecting the item, right-click, and select Graph The graph assumes the data-format of the variable or structure being watched & sets address increment automatically 39 Other Useful Items There are a lot of settings available for the compiler and linker in CCS, summary information is available to streamline debugging: Project > Properties > ARM Compiler > Summary of Flags Set: -mv7M3 --code_state=16 --abi=eabi -me -g -- include_path="C:/TI/ccsv5/tools/compiler/tms470/include" --include_path="C:/StellarisWare" -- define=ccs --define=lm3s define=TARGET_IS_DUSTDEVIL_RA0 --diag_warning= display_error_number Project > Properties > ARM Linker > Summary of Flags Set: -mv7M3 --code_state=16 --abi=eabi -me -g --define=ccs --define=lm3s define=TARGET_IS_DUSTDEVIL_RA0 --diag_warning=225 --display_error_number -z -- stack_size=256 -m"SummitDemo.map" --heap_size=0 -i"C:/TI/ccsv5/tools/compiler/tms470/lib" -i"C:/TI/ccsv5/tools/compiler/tms470/include" --reread_libs --warn_sections --rom_model Compiler optimization is sometimes not ideal Project > Properties > ARM Compiler > Optimization Linker options are available to modify stack/heap size: Project > Properties > ARM Linker > Basic Options 40 Stellaris Peripherals -GPIO Basics 41 Stellaris GPIO Essentials Nearly all GPIO ports/pins are multiplexed with digital and peripheral functionality, by default GPIO are under software control Each GPIO port under software control can be configured: Input or Output Interrupt events Pull up/down resistors Open drain enables Drive strength (up to 18mA, limit 4 per device) By default all GPIO, and many other peripherals use the Advanced Peripheral Bus (APB) bus 42 Traditional GPIO Data Access What does the following line of code actually do? ucSomeVariable |= 0x01; Commonly referred to as read-modify-write access ucSomeVariable = ucSomeVariable | 0x01; READ MODIFY WRITE 43 GPIO Bit Masking Available for both read and write operations Alleviates the need for read/modify/write access increasing speed Each data register is virtualized in 256 locations in the memory map, the address offset from the data address sets the bit mask 44 GPIO Bit Masking HWREG(GPIO_PORTA_BASE + GPIO_O_DATA + ( GPIO_PIN_0