processor expert™ tips and tricks - freescale.com.cn · processor expert’s macro language. tm 4...

93
TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009. Processor Expert™ Tips and Tricks Jun Lin Product Manager August, 2009

Upload: hoangquynh

Post on 26-May-2018

247 views

Category:

Documents


0 download

TRANSCRIPT

TM

Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Processor Expert™ Tips and Tricks

Jun LinProduct Manager

August, 2009

TM

2Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Agenda

►Processor Expert Overview• What is Processor Expert?• CodeWarrior / Processor Expert Support

►Bean Store►Using Processor Expert throughout the design process►Demo—Blinking LED (Timer and I/O)►LAB1—SCI (UART) Communication With PC►LAB2—ADC, SCI (UART) Communication with neighbor’s board

and LEDs►LAB3 – Using External Libraries►Managing Code Generation►Creating Bean Templates

TM

3Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Agenda

►Bean Wizard• Benefits of Embedded Beans• Hardware Abstraction Layer• Embedded Beans™ Terminology• Embedded Beans Types• Bean Wizard™ User Interface• Steps to Encapsulate Legacy Code

►Bean Wizard Demonstration►Hands-on Training:

• Create a new bean• Modify it’s functionality• Distribute “Embedded Bean” you’ve created

►Processor Expert’s Macro Language

TM

4Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

What is Processor Expert?

A rapid application design tool with …► Graphical User Interface which allows an application to be specified by the

functionality needed► Automatic code generator which creates tested, optimized C code tuned to

the application needs and selected Freescale MCU► Built-in knowledgebase, which immediately flags resource conflicts and

incorrect settings

Creating…► Hardware Abstraction Layer (HAL) – hardware-dependent, low-level drivers

with a known application programming interface (API)

Benefits► Eases migration between Freescale devices► Designers don’t have to be intimately familiar with every page of a specification► Errors are caught early in design cycle; therefore, designers get to market

faster with higher quality product

TM

5Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Unique in the Market

►Processor Expert delivers functionality that is unique in the market.CodeWarrior -

Processor Expert

RealView Tools Suite

Green Hills IAR (VisualSTATE

6.1)

HITEX (startEasy)

Keil

Graphical InterfaceYes Yes Yes Yes Yes Yes

Configurable Application Notes Yes No No Yes Yes No

Integrated Knowledgebase Yes No No No No No

Generates Initialization Code Yes No No Yes Yes No

Generates Low Level Drivers Yes No No Yes No No

Tools to Add Higher Level Drivers Yes No No No No No

Integration with UML Modeling Tools Yes Yes Yes Yes No Yes

* Software support for ARM competitors

TM

6Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Processor Expert Tools

►Several approaches• Low level

Use ASM/C (Assembler Support Routines)Code is specialized

• Classical approachUse primarily CReuse of existing codeUse SDK (Software Development Kit) and libraries

– Components

• AbstractionFormal description of the algorithmModeling (State charts)

Device Initialization

ProcessorExpert

StateBuilder

TC1

Slide 6

TC1 Balanced page / spacing / resizing, etc.

Recolored bars / bolded titles and changed their placementTia Culbreth, 6/24/2006

TM

7Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

CodeWarrior / Processor Expert Support

Processor Expert is integrated into the following CodeWarrior tool suites with support for the indicated Freescale silicon families.

►CodeWarrior Development Studio for Microcontrollers• RS08: KA, SA• HC08: AB, AP, AS, AZ, BD, EY, GP, GR, GT, GZ, JB, JG, JK, JL, KX, LB,

LD, LJ, LK, LT, LV, MR, QB, QC, QL, QT, QY, RF, SR • HCS08: MC1321x, AC, AW, DE, DN, DV, DZ, EL, EN, GB, GT, JM, JR,

LC, QA, QD, QE, QG, RC, RD, RE, RG, SG, SH, SL • ColdFire V1: AC, JM, QE

►CodeWarrior Development Studio for HCS12(X)• HCS12: A, B, C, D, DB, DG, DJ, DP, DT, E, GC, H, KG, KT, NE, Q, UF• HCS12X: A, D, DG, DP, DT, EG, EP, EQ, ET, F, HZ

TM

8Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

CodeWarrior / Processor Expert Support

Processor Expert is integrated into the following CodeWarrior tool suites with support for the indicated Freescale silicon families.►CodeWarrior Development Studio for 56800e Digital Signal Controllers

• 56800: 5680x, 5682x, 5685x• 56800e: 56800x, 56801x, 56802x, 56803x, 5681xx, 5683xx

►CodeWarrior Development Studio for ColdFire Architectures• V2: MCF520x, MCF521x, MCF5221x, MCF5222x, MCF5223x• V3: MCF532x• V4: MCF545x

TMFreescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Using Processor Expert throughout the Design Process

TM

10Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Silicon Selection

►You can access the knowledgebase in Processor Expert to find Freescale silicon that will meet your application needs

• Select CPU Parameters Overview in the Processor Expert > View menu.

TM

11Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Silicon Evaluation

►You can use Target CPU Window to evaluate silicon

• Displays selected target microcontroller with its peripherals and pins

• Displays current resource usage by selected beans (i.e. peripherals, pins)

• Data directions of single pins are indicated by blue arrows when configured by a bean

• Pins associated with a peripheral are highlighted when mouse hovers over a peripheral

• Help is available for pins and peripherals by moving the mouse over the item

TM

12Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Design Cycle

►During the design cycle Processor Expert can be used to…• Create “example” code to learn

how to program a new peripheral

• Create code for rapid prototyping

• Create production code

TMFreescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

DemonstrationBlinking LED (Timer and I/O)

TM

14Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Demonstration overview

►This demonstration shows how to create a project with Processor Expert. It shows how to…

• Add and configure Embedded Beans to support selected peripherals• Generate the code • Test the functionality on a simple application

►The demonstration uses a M5211DEMO board.►The application uses a timer to blink the LED every 1 second.

TM

15Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Processor Expert Project Design Workflow

Create a new projectSelect Embedded Beansfrom library and add them to project

Configure it

Generate source codeBuild and debug Write application code … and verify settings

TM

16Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

► Use command: File - Startup dialog► Select Create New Project► Select ColdFire Evaluation Boards -> ColdFire V2 ->

M5211DEMO, Select P&E USB BDM Multilink, click Next

TM

17Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

► Type project name (DemoLED.mcp), click Next► No additional files required, click Next► Select Processor Expert option► Click Finish

TM

18Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

►Select check of “CAE66 64-pins”►Select all configurations►Select OK

TM

19Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Processor Expert™ Windows

►Processor Expert adds the following windows to CodeWarrior• Processor Expert Panel in

Project Manager• Target CPU• Bean Inspector• Bean Selector

TM

20Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Processor Expert™ Windows

►Bean Selector Window• Shows supported Embedded

Beans including CPU beans and bean templates.

• Allows an Embedded Bean or template to be added to the project.

• Embedded Beans can be listed by categories, alphabetically or on-chip peripherals.

• Right-click on a bean to add it to the project or to get help.

• An assistant is also available to guide bean selection

TM

21Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Select beans to be used

►The Bean Selector window displays the list of available beans for the selected MCU.

We are going to use BitIO and TimerIntEmbedded Beans

TM

22Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Processor Expert™ Windows

►Bean Inspector Window—Properties Tab

• Double-clicking on an Embedded Bean opens the Bean Inspector window

• A red exclamation point means one of the bean’s properties is either blank or in conflict with another

• Help is available for the fields by moving the mouse over them

• The Basic, Advanced and Expert buttons at the bottom of the window control the level of detail visible

TM

23Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Processor Expert™ Windows

►Bean Inspector Window—Methods Tab

• Shows functions available for the Embedded Bean

• Allows designer to select functions to be included in his application

• Code is only generated for selected functions

• The code will appear in the .cfile for this Embedded Beanin the “Generated Code” folder

• Holding the mouse over a “method”causes a description of the function’s parameters and return values to be displayed

TM

24Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Processor Expert™ Windows

►Bean Inspector Window—Events Tab

• Shows the events for the current Embedded Bean

• Allows events to be renamed• Events are usually called by

interrupts• Events are defined in Events.c

in the “User Modules” folder

TM

25Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Configure BitIO Bean

►In the Bean Selector• Path: Categories -> CPU Internal

Peripherals -> Port I/O• Add the BitIO bean to the project

►In the Bean Inspector• Configure pin

DTIN0_DTOUT0_PWM0_PTC0• Set direction to Output

►Switch to Methods tab• Enable NegVal method for code

generation

TM

26Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Configure TimerInt Bean

►Add the TimerInt bean from Bean Selector to the project to configure periodical interrupt.

►Use the Inspector to setup the settings.

TM

27Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Generate source code

►To generate code select “Generate Code ‘DemoLED.mcp’” in the menu Processor Expert.

TM

28Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Writing the user code

►Double-click on TI_OnInterrupt event in the Project Panel• Expand ‘+’ in front of “TI1: TimerInt”

►Open Events.c module at the position of empty TI1_OnInterrupt function body.

TM

29Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Writing the user code

void TI1_OnInterrupt(void){Bit1_NegVal();

}

►Write the following code in the pre-generated OnInterruptevent TI1_OnInterrupt

TM

30Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Make, debug and run application

►Make application using the Project - Make (F7) command.►Debug application using the Project - Debug (F5) command.►Run application in the debugger using the Run (F5) command.

TMFreescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Lab 1SCI (UART) Communication With PC

TM

32Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

UART Communication With PC

►This hands-on lab shows how to…• Create a new project • Add and configure Embedded Beans to support selected peripherals• Generate the code • Write a simple application• Test the functionality

►The lab is communication oriented• Uses a M5211DEMO board.• Uses UART communication between the PC and demo board.

►The application reads lines from a terminal with echo and sends it back to the terminal.

TM

33Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

► Use command: File - Startup dialog► Select Create New Project► Select ColdFire Evaluation Boards -> ColdFire V2 ->

M5211DEMO, Select P&E USB BDM Multilink, click Next

TM

34Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

► Type project name (LAB1.mcp), click Next► No additional files required, click Next► Select Processor Expert option► Click Finish

TM

35Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

►Select check of “CAE66 64-pins”►Select all configurations►Select OK

TM

36Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Add Embedded Beans to the project

►Open Bean Selector window• Double click on following bean:

Term

TM

37Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Configure Embedded Bean

►Open Term Bean settings►Open inherited AsynchroForTerminal Bean►Set the following items:

• Baud rate – 9600 baud

►Open the timing editor►Set the following items:

• Error allowed – 1%

• Check the adjusted value

TM

38Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Configure Embedded Bean►Open Bean Inspector Term1►Switch to page “Methods”►Enable “generate code” for “ReadLine”

TM

39Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Generate source code

►Start code generation• Select Generate Code ‘LAB1.mcp’ command

from Processor Expert menu

TM

40Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Writing the user code

►Double-click on LAB1.c main module in folder User Modules and open the C main module

►Write the following code into the main functionchar buffer[255];void main(void){

/*** Processor Expert internal initialization. DON'T REMOVE THIS … */PE_low_level_init();/*** End of Processor Expert internal initialization. ***/

/* Write your code here *//* For example: for(;;) { } */Term1_SendStr("LAB1 application started...");Term1_CRLF();for(;;) {

Term1_SendStr("Type any text:");Term1_ReadLine(buffer);Term1_CRLF();Term1_SendStr("You typed:");Term1_SendStr(buffer);Term1_CRLF();

}}

TM

41Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Make, debug and run application

►Make application using the Project - Make (F7) command.►Debug application using the Project - Debug (F5) command.

• Connect serial cable to PC and demo board• Start Hyperterminal application

Select Cancel in the “New Connection” dialog boxConfigure the COM1 with 9600 baud

►Run the application using the Run (F5) command.• The ‘LAB1 application started…’ string should appear• Type any text to the console followed by enter key to test the

application.The entered text will appear in the terminal when sent.

TMFreescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Target CPU Window Revisited

TM

43Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Target CPU Window

►Target CPU Window provides two graphical views of the MCU• CPU Package and Peripherals – package centric view of the MCU

CPU and peripheralsPin-outs for the selected packageSelected with the button in the Target CPU Window

• CPU Block Diagram – peripheral centric view of the MCUPins/modes of peripheralPins/port namesPeripheral pins used by beansPeripherals, which can’t be used (for any reason) Selected with the button in the Target CPU Window

TM

44Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

CPU block diagram

►What’s in the CPU block diagram?• Peripheral blocks

• Interconnection bus (no functionality)

• PinsPeripheral

name

Unavailable pins

Pins used by bean

Peripheral mode

Unused pins (ready for use)

Peripheral

TM

45Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

CPU block diagram

►Adding beans using CPU block diagram• Right click right on peripheral• Select a bean

• The selected bean will be added to the project and connected to the selected peripheral

TM

46Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

CPU block diagram

►Adding beans using CPU block diagram• If the peripheral does not have the resources required for a bean, it is

grayed out and cannot be selected.

TM

47Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

CPU block diagram

►Local menu provides the following additional capabilities• Show peripheral’s

Initialization values of bits/registersStructure (in available modes)Usage

• Rename peripheral• Open PDF documentation and find

pages related to selected peripheral*

*Supported on HC08 family only

TMFreescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Lab 2SCI (UART) Communication with Neighbor’s Board

TM

49Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Application description

►This hands-on example shows how to…• Create a new project • Add and configure embedded beans to support selected peripherals• Generate the code • Write a simple application• Test the functionality

►The demonstration is communication oriented• Uses M5211DEMO board.• Uses UART communication with neighbor’s board.• Uses ADC converter and LED’s to demonstrate the functionality

TM

50Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Application description

►The application reads the value from ADC and drives the LED bar• ADC bean is used for measure the potentiometer setting• The measured value is sent from the transmit pin of one board to the

receive pin on the second board using the UART A character representing the number of LEDs to be turned on is transmitted

• The application receives the value and sets the LEDs according to the value.

• Both boards use the same application

TM

51Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

► Use command: File - Startup dialog► Select Create New Project► Select ColdFire Evaluation Boards -> ColdFire V2 ->

M5211DEMO, Select P&E USB BDM Multilink, click Next

TM

52Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

► Type project name (LAB2.mcp), click Next► No additional files required, click Next► Select Processor Expert option► Click Finish

TM

53Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

►Select check of “CAE66 64-pins”►Select all configurations►Select OK

TM

54Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Add Embedded Beans to the project

►Open CPU block diagram• Open Target CPU window• Click the “Show CPU block diagram” button

TM

55Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Add Embedded Beans to the Project

►Right click on the UART0 block• Select Add Bean/Template

AsynchroSerial

►Find the ADC port block• Click AddBean/Template

and selectADC

►Right click on first “ball” of the TC port• Add the following bean to the project

BitsIO

Note: Select Yes to add it to all configurations if asked

TM

56Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Configure AS1 Embedded Bean

►Open AsynchroSerial Bean (double click the bean icon in CPU block diagram)

►Set the following items:• Baud rate – 9600 baud

►Open the timing editor►Set the following items:

• Error allowed – 1%

• Check the adjusted value

TM

57Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Configure ADC Embedded Bean

►Open ADC Bean properties►Set the following items:

• Conversion time – 5.1 µs

►Switch to the Methods tab• Enable Start method• Enable GetValue8 method

TM

58Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Configure the BitsIO Bean

►Configure pins DTIN0_DTOUT0_PWM0_PTC0 – PTC3. ►Use the Inspector to setup the settings.

TM

59Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Generate source code

►Start code generation• Select Generate Code ‘LAB2.mcp’ command

from Processor Expert menu

TM

60Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Writing the user code

► Open Events.h event module.► Add a flag (external variable) definition at the beginning of the

module Events.h

#include "AD1.h"

#include "Bits1.h"

extern uint8 Flag_Measured;

TM

61Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Writing the user code

void AD1_OnEnd(void){

Flag_Measured = 1;}

►In Events.c, write the following code in the pre-generated ADC event AD1_OnEnd

TM

62Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Writing the user code

► Double-click on LAB2.c main module in folder User Modules and open the C main module

► Write the following code into the main function

/* 1 LED1 is ON; 3 LED1&LED2 are ON, */const uint8 LedBarValues[] = {1, 3, 7, 15};

uint8 Flag_Measured = 0;

void main(void){

uint8 value;uint8 err;

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/PE_low_level_init();/*** End of Processor Expert internal initialization. ***/

AD1_Start();for(;;) {

if (Flag_Measured) {Flag_Measured = 0;err = AD1_GetValue8(&value); // Get the last measured value// Test whether the last result is OKif (err == ERR_OK) {

// Rotate the value to obtain only 2 upper bitsvalue >>= 6;// send the status via serialAS1_SendChar(value);

}}err = AS1_RecvChar(&value); // Get the value// Test whether the last result is OKif (err == ERR_OK) {

// set the status on the LED bar Bits1_PutVal(LedBarValues[value]);

}} /*** Don't write any code pass this line, or it will be deleted during code generation. ***//*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/for(;;){}/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/

} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

TM

63Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Make, debug and run application

►Make application using the Project - Make (F7) command.►Debug application using the Project - Debug (F5) command.

• Connect serial pins on demo boards:Connect Serial cable to neighbor’s board

►Run application using the Run (F5) command.• Move the potentiometer

Check the result

TMFreescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Lab 3 - Using External Libraries

TM

65Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Using External Libraries

►This hands-on lab shows how to use an external library with Processor Expert to create an application

►A simple library and header file are provided for this lab.• Description

The library reads a value from an external device connected to port TA. The value is compared with the port AN is read using bean BitsIO. Also other library functions are invoked.

• FunctionsgetData – reads byte from port TA (not using Processor Expert beans)translate – converts 16 bit value to 8 bit valuemaximum – returns maximum of two valuesminimum – returns minimum of two values

Note: The library code is presented for the demonstration purposes only.

TM

66Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

► Use command: File - Startup dialog► Select Create New Project► Select ColdFire Evaluation Boards -> ColdFire V2 ->

M5211DEMO, Select P&E USB BDM Multilink, click Next

TM

67Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

► Type project name (ExtLibDemo.mcp), click Next► No additional files required, click Next► Select Processor Expert option► Click Finish

TM

68Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a new project

►Select check of “CAE66 64-pins”►Select all configurations►Select OK

TM

69Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Generate source code

►Start code generation• Select Generate Code ‘ExtLibDemo.mcp’ command

from Processor Expert menu

TM

70Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Add External Library

►Add the library to the project• Copy the library and header files

into the <project directory>/CODE These files are located in the Training directory:

– ENT_T0017/Libs/MyLib.c• Right click on the “User Modules”

folder in the Processor Expert Tab.• Select Add Files…• When the Add Files dialog appears,

choose the files and they will be added to the project.

TM

71Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Configure Processor Expert

►Configure Processor Expert to work with the library

• Double click on the CPU bean to open the Bean Inspector

• Select the Used tab• Expand I/O Ports• Select port PORTTA • Double click on the item.

“Used by external device” will appear

TM

72Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Add Processor Expert Beans

►Design the application in Processor Expert• Select the BitsIO bean in the Bean Selector• Double click on the BitsIO bean

to open the Bean Inspector• Select PORTAN. • Add Pins to 2.• Assign AN0_PAN0 to Pin0• Assign AN1_PAN1 to Pin1

Note: PORTTA is marked as User

TM

73Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Generate source code

►Start code generation• Select Generate Code ‘ExtLibDemo.mcp’ command

from Processor Expert menu

TM

74Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Add Header File

►Include the MyLib.h header file in the main module.• Open ExtLibDemo.c in the CodeWarrior project panel.• Add the following line in the include section

#include "MyLib.h"

►To use the library, check the parameter description in the header file or the library documentation

TM

75Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Write Main Code

►Write the main function codebyte a,b,c,d,t;

void main(void){

/* Write your local variable definition here */

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/PE_low_level_init();/*** End of Processor Expert internal initialization. ***/

a=getData();b=Bits1_GetVal();c=maximum( a, b );d=minimum( a, b );t=translate(32000);

/*** Don't write any code pass this line, or it will be deleted during code generation. ***//*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/for(;;){}/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/

} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END ExtLibDemo */

TM

76Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Make, debug and run application

►Make application using the Project - Make (F7) command.►Debug application using the Project - Debug (F5) command.►Run application in the debugger using the Run (F5) command.

TM

77Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Lab Summary

►Advantages• Existing library code can be used with applications developed with

Processor Expert. For example: driver for a specific external device can be used.

• Libraries written in assembly can be easily used in C applications.

►Disadvantages• If the source code is not available (only object file is available), then the

application must be developed with the same compiler.

►Conclusions• Combining existing library code with code generated by Processor

Expert will rapidly decrease cycle time. • Existing solutions can be quickly enhanced

TMFreescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Managing Code Generation

TM

79Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Code Generation

► C code is generated when…• “Generate Code” is selected in the

Processor Expert menu, or• MAKE is selected, or• DEBUG is selected

► Code in “Generated Code” folder CANNOT be modified and includes…

• C module for every Embedded Bean in the project

• IO_map.c file containing register definitions

• Vectors.c, containing the constant interrupt vector table

► Code in “User Modules” folder CAN be modified and includes…

• C module containing the main( ) function

• Events.c and Events.h for interrupt service routines

TM

80Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Managing Code Generation

►Processor Expert has the ability to stop code generation• For one module• For one Embedded Bean• For whole project• Completely disable Processor Expert

►Allows you to control code generation• Generate initial code with Process Expert• Disable code generation

Allows you to modify the generated codeProcessor Expert will NOT overwrite changes

TM

81Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Disabling Code Generation

►Disable code generation for one module►Click the right button on module and select

• Code Generation -> Don’t Write

• The bean module can’t be disabledDisable code generation for Embedded Bean instead

TM

82Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Disabling Code Generation

►Disable code generation for one bean►Click the right button on Embedded Bean and select

• Code Generation -> Don’t Write Generated Bean Modules

TM

83Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Disabling Code Generation

►Disable code generation for whole project►Use the command Processor Expert -> Freeze Generated Code

TM

84Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Disabling Code Generation

►“Freeze generated code” freezes the Processor Expert settings and disables code generation

• It is still possible to see the settings• Settings cannot be changed or manipulated (IDE items are grayed)• It’s recommended to

re-generate the code when un-freezing

TM

85Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Disabling Code Generation

►Disable Processor Expert completely►Use command Processor Expert -> Suspend Processor Expert for

<project>.mcp

TM

86Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Disabling Code Generation

►This command:• Stops code generation• Uninstalls the Processor Expert tab from project

TMFreescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Creating a Bean Template

TM

88Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Creating a Bean Template

►Every bean setting can be customized and stored as a Template

►A Template is an Embedded Bean with pre-defined settings

►In the Bean Inspector• Select Bean• Select Template• Select Save Bean Settings as Template

TM

89Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Creating a Bean Template

►Set pre-defined settings• User-defined name• Selected peripheral

TM

90Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a Bean Template

►Click on Customize Settings button to open the “Template Editor” dialog to

• Customize Bean settingsEnable/disable method generationEnable/disable event generation

• Mark items as read-only

Customized settingRead-only

item

TM

91Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2009.

Create a Bean Template

►Where is the new template stored?• In Category view of Bean Selector

Displayed in the same category as the original Embedded Bean.Templates are colored blue

• In On Chip Peripheral view of Bean SelectorDisplayed as original Embedded Bean’s sub-folderTemplates are colored blue

TM