Top Banner
MQX RTOS—Lab Tutorials Freescale Solutions Freescale MQX Software Solutions Enabling Embedded Systems—Accelerating Success
16
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

headhead

Freescale Solutions

Freescale MQX Software SolutionsEnabling Embedded Systems—Accelerating Success

Page 2: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

2 www.freescale.com/mqx

Table of ContentsThe following lab tutorials are applicable to both the

M52259EVB and M52259DEMOKIT

LAB

1

HVAC Controller, Freescale MQX RTOS for MCF52259. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

LAB

2

USB Functionality, Freescale MQX USB and MFS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7

LAB

3

Telnet and FTP Operation, Freescale MQX RTCS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9

LAB

4

Web-Enabled HVAC System, Freescale MQX RTCS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

LAB

5

Finding an Error Using Task Aware Debugging (TAD) in CodeWarrior. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

LAB

6

Ethernet to Serial Bridge, Freescale MQX RTCS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Page 3: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

www.freescale.com/mqx 3

5. Open the Lab Project by selecting the

File > Open menu item:• ForM52259EVBboard,openfile:

c:\Program Files\Freescale MQX 3.0\demo\hvac\codewarrior\hvac_m52259evb.mcp

• ForM52259DEMOboard,openfile:

c:\Program Files\Freescale MQX 3.0\demo\hvac\codewarrior\hvac_m52259demo.mcp

LAB

1

HVAC Controller, Freescale MQX RTOS for MCF52259Covers both M52259EVB and M52259DEMOKIT

Thislabwillguideyouthroughthegeneral

useofFreescaleMQXoperatingsystemunder

theCodeWarrior™environmenttofamiliarize

youwiththegeneralcompileanddownload

processaswellasprovideanunderstanding

oftheapplication.

Demonstrates

• MQXprojectinCodeWarriorIDE

• Projectbuild,downloadandrunin

CodeWarriorIDE

• MQXShellandseriallineconsole

• MQXGPIOdriver(pushbuttonandLEDs)

Step by Step Instructions

1. Makethefollowingconnectionsfromthe

MCF52259boardtothecomputer.See

Figure1totheright,orFigure2below.a.USBdebuggerconnectiontoa

USBportonPC

b.SerialPort0(UART0)toaSerial Port on PC

c.Attachpowercableandturnontheboard’spowerswitch(M52259EVBonly)

2. ThefirsttimeyouconnecttheUSB

debuggercabletoyourPC,Windowswill

installadriverforthedebugger.Followthe

promptstoautomaticallydetectandinstall

thedriver.

3. Installthe7.1.1(orlater)updatepatchfor

CodeWarriorforColdFire®V7.1ifithas

notalreadybeeninstalled.Then,open

CodeWarriorforColdFireV7.1.

4. IfyoudidnotinstalltheMQXprojectin

thedefaultC:\Program Files\Freescale

MQX 3.0\directoryduringinstallation,

youmustfirstrecompiletheMQXlibraries

toreflectthenewpathname.Seethe

releasenotesformoreinformationbefore

continuing on with the lab.

CPLD programer connector

USBconnectorfordebugger

CFcardconnector

5Vpowerconnector

USB

Power switch

Ethernet

RS232

MRAM

AlteraMaxII CPLD

Figure 1: M52259EVB board layout

Ethernet

USB

RS232

USBconnectorfordebugger(OSBDM)

Figure 2: M52259DEMO board layout

Page 4: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

4 www.freescale.com/mqx

6. Intheprojectpane,select“HVAC—Int.

FlashDebug”buildtarget.SeeFigure3

to the right.

7. CompiletheprojectbypressingtheF7

keyorbyclickingtheMake icon on the

project pane toolbar.

8. Openthe“FlashProgrammer”toolinthe

Toolsmenu.Makesurethe“Usecustom

Settings”checkboxisnotselected

(i.e.theconfigurationwillbetakenfrom

theproject).SeeFigure4below.

9. Clickthe“LoadSettings”buttonand

select MCF52259_INTFLASH.xml.

10. Select the Erase/Blank Checkpage,

select“AllSectors”andclickErase.

See Figure 5 below.

11. Select the Program/Verifypageandclick

Program.Uponsuccessfulprogramming,

thestatuswilldisplay“Completed

Successfully.”

12.Nowstartdebuggerandexecute

theapplicationbyclickingthe

Debug icon. This icon is

identifiedinFigure 3 on right.

Figure 3: Project Loaded in the CodeWarrior IDE

NOTE:WithM52259EVBboard,youcanuseMRAMmemorytostoretheexecutablecodeinsteadoftheflash.Select“HVAC—Ext.MRAMDebug”andskiptheFlashProgrammersteps8–11.Thecodewillbe downloadedtoMRAMautomaticallybythedebugger.

Figure 4: Opening Flash Programmer Tool

Figure 5: Downloading Code with Flash Programmer Tool

Page 5: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

www.freescale.com/mqx 5

HVAC

Shell Commands

Control

MODE FAN

HEAT

COOL

OFF

ON

AUTOMATIC

Desired Temp 25ºC

Actual Temp 21ºC

MQX HVAC Control Panel Thermostat

“temp xx”

“hvac heat”

“hvac cool”

“hvac off”

PushButtons

Virtual Temp.Sensor

“fan on” “fan off”

Status Lights

Fan Furnace A/C

LED1 LED2 LED3

The furnace turns ON if the desired temperature is above the actual temperature and the HVAC is set to HEAT.

The A/C turns ON if the desired temperature is below the actual temperature and the HVAC is set to COOL.

16. Press Enterintheterminalwindowonthe

PC.Youshouldseetheshell> prompt.

Statusupdateswillappearevery15

secondsintheterminalwindow.

15.Setitfor115200baud,noparity,8bits

andclickOK.

13.Oncethedebugsessionstartsyouwill

seetheMQXentry-pointfunctioninthe

codewindowasseeninFigure6.Click

the Debugiconagaintorunthecode,

whichwilllooklikeFigure7.

14.StartHyperTerminalonthePC

(Start menu->Programs->Accessories-

>Communications).Makeaconnection

totheserialportthatisconnectedtothe

board(usuallywillbeCOM1)

Figure 8: HyperTerminal Console Window

Figure 9: HyperTerminal Console Window

Figure 10: Help command in HyperTerminal Console Window

Figure 11: Info command in Hyperterminal Console WindowFigure 7: Running MQX code

Figure 6: MQX Debug entry point

Page 6: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

6 www.freescale.com/mqx

20.Usethefancommand(fan onandfan

off)tocontrolthefan(LED1).Useinfo at

anytimetoconfirmthestatus.Thefan on

commandforcesthefantobeon,while

fan offputsthefanintoautomaticmode

sothatthefanisonlyonwhentheHVAC

needstochangetemperature.

21.Sincethedefaultsettingsforthedemo

havethe“desiredtemp”and“actual

temp”at20oC,boththefurnaceortheAC

donotneedtobeturnedon.

22.Turnthefanofftoputitinautomatic

mode,andputtheHVACintoheatmode

using the hvaccommand(hvac heat).

Thisturnsonthefurnace,andwiththefan

inautomaticmode,thefanwillonlyturn

onwhenthedesiredtemperatureishigher

than the actual temperature.

23.PushbuttonsSW1andSW2onthe

boardareusedtochangethedesired

temperature.SW1increasesthedesired

tempandSW2lowersit.PressSW1once

andthentypeinfo in the shell.

24.PressSW1again,typeinfoandseethat

thefurnacehasturnedonandthefan

hasautomaticallyturnedon.Thefurnace

andfanLEDsshouldbeontoindicate

this status.

17.Typehelptoseethelistofavailable

commands.Usetheinfocommand

todisplaythecurrentsettings

(SeeFigures10and11).

18.AsimpleHVACcontrollerhasbeen

implementedastheexampleapplication

todemonstratethefeaturesofthe

software.TheHVACsystemoperates

perthediagramonpage5.

19.TheLEDsrepresentthecurrentstate

oftheHVAC:a.WhenusingtheEVB,

D10onEVBrepresentsFan ON/OFF

D11onEVBrepresentsFurnace ON/OFF D12onEVBrepresentsA/C ON/OFF

b.WhenusingtheDEMOKIT,

LED1representsFan ON/OFF

LED2representsFurnace ON/OFF LED3representsA/C ON/OFF

Figure 14: Push buttons on the DEMO and EVB boards

SW1

SW1

SW2

SW2

Figure 13: DEMOKIT LEDs

Fan Furnace AC

Figure 12: EVB LEDs

25.UseSW2tolowerthedesiredtempsuch

thatthefurnaceandthefanturnoff.Use

the tempcommandtochangethedesired

temperatureto24oC(temp 24).Thefan

andthefurnaceshouldturnbackon.

26.Experimentonyourownwithchanging

temperatureandfansettings.

27.Terminatethedebugsessionbypressing

Shift-F5orbyselectingDebug>Kill in

CodeWarrior.

Fan Furnace AC

Page 7: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

www.freescale.com/mqx 7

LAB

2

USB functionality, Freescale MQX USB and MFSCovers both M52259EVB and M52259DEMOKIT

Thislabwillguideyouthroughtheuseofthe

USBStack,theMFSFileSystem,andthe

loggingofdatatothememorystick.

Demonstrates

• USBhostfunctionalitywithmassstorage

class support

• USBdrivereadandwriteaccessbyusing

theMFSfilesystemcomponent

Step by Step Instructions

1. StoptheapplicationinCodeWarriorif

itiscurrentlyrunning(Debug>Kill)

2. Openhvac.hinCodeWarrior

3. EnabletheUSBsupportbychanging:

#define DEMOCFG_ENABLE_USB_FILESYSTEM 0to:

#define DEMOCFG_ENABLE_USB_FILESYSTEM 1

4. Recompilethecode,download,andrun

theapplicationaswasdoneinsteps6to

13ofLab1.

5. InserttheUSBmemorystickintotheUSB

connectorontheboard.Youwillneedthe

miniUSB-Badaptorplug.SeeFigure2

onthenextpage.

Figure 1: MQX Source Tree

6. OntheHyperTerminalconsoleyoushould

seetextthatindicatesthattheUSB

memorystickwasfound,thetypeof

memorystickthatwasfound,theUSB

massstoragedevicewasopened,the

partitionmanagerwasinstalled,andthat

thefilesystemwasinstalledandopened.

Itmaytakeseveralsecondstofullyinstall

thememorystick.ItwilllooklikeFigure3.

Figure 3: Inserting a USB mass storage device

Page 8: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

8 www.freescale.com/mqx

14.Deletethelogfileusingthedelcommand

(del hvac_log.txt).Onceagainviewthe

directorylistingtoverifythatthefilehas

beenremoved.

15.Within15seconds(orafterSW1/SW2key

press)youshouldseethatthelogfilehas

beenrecreated.Usethetypecommand

onthelogfile(type hvac_log.txt)tosee

the latest entry.

10.Thelogginginformationisnowbeingsent

tothememorystickinfilehvac_log.txt

insteadofbeingprintedtotheserialport.

Youshouldseethisfileinthedirectory

listing.Notethefilesizeofhvac_log.txt.

11.PressSW1andSW2afewtimeseachto

changethedesiredtemperature.

12.Typediragainintheshellandnotethefile

sizeofhvac_log.txt.Itshouldbebigger

thanbeforeindicatingthatthechanged

parametersarebeingloggedtothe

memorystick.

13. Use the typecommandtodisplaythe

contentsofthelogfilelocatedonthe

memorystick(type hvac_log.txt).Itwill

looklikeFigure5.

7. PressreturnonthePCtogetthe

shell> prompt.

8. Type helptoseethelistofcommands.

Youshouldseeadditionalcommands

availableasseeninFigure4.Youcanuse

thecommandstoexercisethememory

stickattached.

9. Typedirtoseethememorystick

directorylisting.

Figure 2: Plugging the USB stick into the M52259DEMO and M52259EVB

Mini-USB-B

Figure 4: Shell commands with USB functionality enabled

Figure 5: HVAC log file contents

Page 9: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

www.freescale.com/mqx 9

LAB

3

Telnet and FTP Operation, Freescale MQX RTCSCovers both M52259EVB and M52259DEMOKIT

ThislabwillintroduceyoutotheuseofTelnet

andFTPtoaccessaproductremotelyvia

EthernetandTCP/IPprotocols.

Demonstrates

• MQXRTCSTCP/IPnetworkstack

• Telnetserverfunctionality

• FTPserverfunctionality

Step by Step Instructions

1. Stoptheapplicationifitiscurrently

running(Debug>Kill).

2. ConnectacrossoverEthernetcable

betweentheboardandanEthernet

port on your computer

3. ThedefaultIPaddressoftheboardis

169.254.3.3.Typically,whenyouconnect

yourcomputerdirectlytotheboard,

thecomputerwilldefaulttoanautoIP

addressonthesamesubnetastheboard

(169.254.x.x),thereforerequiringnosetup.

Note:ThePCmaytakeafewminutesto

defaulttotheautoIPaddressandmake

the connection.

However,ifyouhavetroubleconnecting,

youmayconfiguretheIPaddressof

the computer manually. Select Start >

Settings>NetworkConnections>Local

AreaConnection.NoteyouroriginalTCP/

IPsettings,andthensetyourIPaddress

to169.254.3.4andyoursubnetmaskto

255.255.0.0.

4. Open the HVAC.hfileintheCodeWarrior

window.Double-clickthefileitemlocated

inthe“Source/HVAC”groupinthe

CodeWarriorprojecttree.

5. Locatethelineofcodestartingwith

#define ENET_IPADDRandspecifyyour

targetIPaddressbyusingtheIPADDR

macro.UsetheIPaddress169.254.3.3if

ithasnotalreadybeenset:

#define ENET_IPADDR IPADDR(169,254,3,3)

6. DothesamewiththeIPaddressmask

valueENET_IPMASK:

#define ENET_IPMASK IPADDR(255,255,0,0)

7. InthesameHVAC.hfile,enableRTCS

andTelnetserversbychangingthis:

#define DEMOCFG_ENABLE_RTCS 0

#define DEMOCFG_ENABLE_FTP_SERVER 0

#define DEMOCFG_ENABLE_TELNET_SERVER 0

to this:

#define DEMOCFG_ENABLE_RTCS 1

#define DEMOCFG_ENABLE_FTP_SERVER 0

#define DEMOCFG_ENABLE_TELNET_SERVER 1

8. Recompilethecode,download,andrun

theapplicationaswasdoneinsteps6to

13ofLab1.ThenplugintheUSBstickas

doneinLab2.

Page 10: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

10 www.freescale.com/mqx

16. Start the ftp session by typing the

followingintheWindowscommand

prompt:

>ftp 169.254.3.3

Fortheusername,press

Entertoleaveitblank.

User (169.254.3.3(none)):

17.GettheUSBmemorystickdirectorylisting

intheftpsessionbythelscommand.

18. Use get hvac_log.txtcommandintheftp

sessiontoretrievethelogfile.Thefilewill

becopiedtothelocalworkingdirectory

c:\Freescale.Openthelocalfilewith

notepadtoverifythatthefilewas

copiedproperly.

Figure 3: Communicating with FTP

11.Thetelnetshellhasitsowncommand

set,whichissimilartotheterminalshell

commandsasinthepreviouslabs.

Try the helpandinfocommands.

12.Trythelogcommandtoprintcontentof

the hvac_log.txtfiletothetelnetconsole.

13.InthesameHVAC.hfile,disable

TelnetandenabletheFTPserverby

changing this:

#define DEMOCFG_ENABLE_RTCS 1

#define DEMOCFG_ENABLE_FTP_SERVER 0

#define DEMOCFG_ENABLE_TELNET_SERVER 1

to this:

#define DEMOCFG_ENABLE_RTCS 1

#define DEMOCFG_ENABLE_FTP_SERVER 1

#define DEMOCFG_ENABLE_TELNET_SERVER 0

14.Recompilethecode,download,andrun

theapplicationaswasdoneinsteps6

to13ofLab1.

15.Openasecondcommandprompt(Start >

All Programs > Accessories > Command

Prompt)andchangetheworkingdirectory

fortheprompttothec:\Freescalefolder

(type“c:”, “cd \”, “mkdir Freescale”and

“cd Freescale”commands).SeeFigure3

belowforanexample.

9. OpenaCommandPromptonthePC

(Start > Programs > Accessories >

Command Prompt)

10.Atthepromptinvokeatelnetsessiontothe

boardbytypingtelnet 169.254.3.3 you will

beconnectedtotheMQXshellviatelnet.

Figure 1: Connect to telnet

Figure 2: Using shell commands over telnet

Page 11: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

www.freescale.com/mqx 11

CPLD programer connector

USBconnectorfordebugger

CFcardconnector

5Vpowerconnector

USB

Power switch

Ethernet

RS232

MRAM

AlteraMaxII CPLD

Figure 1: M52259EVB board layout

4. ThedefaultIPaddressoftheboardis

169.254.3.3.Typically,whenyouconnect

yourcomputerdirectlytotheboard,

thecomputerwilldefaulttoanautoIP

addressonthesamesubnetastheboard

(169.254.x.x),thereforerequiringnosetup.

Note:ThePCmaytakeafewminutesto

defaulttotheautoIPaddressandmake

the connection.

3. Open the Lab Project by selecting the

File > Open menu item:• ForM52259EVBboard,openfile:

c:\Program Files\Freescale MQX 3.0\demo\web_hvac\codewarrior\web_hvac_m52259evb.mcp

• ForM52259DEMOboard,openfile:

c:\Program Files\Freescale MQX 3.0\demo\web_hvac\codewarrior\web_

hvac_m52259demo.mcp

LAB

4

Web-Enabled HVAC System, Freescale MQX RTCSCovers both M52259EVB and M52259DEMOKIT

ThislabextendstheHVACapplication

describedinLabs1–3andaddsWebserver

functionality.ThedynamicWebpagesserve

asagraphicaluser’sinterfacetotheHVAC

application.

Demonstrates

• MQXRTCSTCP/IPnetworkstack

• HTTPserverfunctionality

Step by Step Instructions

1. Makethefollowingconnectionsfromthe

MCF52259boardtothecomputer.See

Figure 1 on right.a.USBdebuggerconnectiontoa

USBportonPC

b.SerialPort0(UART0)toa Serial Port on PC

c.AcrossoverEthernetcablebetweentheboardandanEthernetporton

your computer

d.Attachpowercableandturnonthe

board’spowerswitch(M52259EVBonly)

2. ThefirsttimeyouconnecttheUSB

debuggercabletoyourPC,Windowswill

installadriverforthedebugger.Follow

thepromptstoautomaticallydetectand

installthedriver.

Ethernet

USB

RS232

USBconnectorfordebugger(OSBDM)

Figure 2: M52259DEMO board layout

Page 12: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

12 www.freescale.com/mqx

12. SimilarlyasinLabs1-3,youcancontrolthe

HVACapplicationbySW1andSW2push

buttons.Youshouldseethedesiredtemper-

aturechangedonHVACstatusWebpage.

13.ReturntotheWebserver’shomepage,

byclickingthe“WebserverHome”link.

14. InserttheUSBMemoryStickthat

isincludedinyourkitintotheUSB

connectorontheEVB.Youwillneedthe

miniUSB-Badaptorplug.SeeFigure6.

15.ReloadtheWebserver

home page by pressing

F5inthebrowserwindow.

Youshouldnowsee

the“BrowseUSBMass

StorageDevice”linkon

thelefthandsideasshownhere.

16.Clickthe“BrowseUSBMassStorage

Device”link.Youshouldseetheweb

pagesshowninFigure8,thatarelocated

ontheUSBmemorystick.

11.NavigatetotheHVACcontrolpageby

movingyourmouseovertheHVACDemo

linkonthelefthandside,andselecting

the“ChangeSettings”link.Youcan

changetheHVACsettingsviathatWeb

page.Figure5demonstrateshowthat

webpagewilllook.

However,ifyouhavetroubleconnecting,

youmayconfiguretheIPaddressof

the computer manually. Select Start >

Settings>NetworkConnections>

LocalAreaConnection.Noteyouroriginal

TCP/IPsettings,andthensetyourIP

addressto169.254.3.4andyoursubnet

maskto255.255.0.0.

5. Open the HVAC.hfileintheCodeWarrior

window.Double-clickthefileitemlocated

inthe“Source/HVAC”groupinthe

CodeWarriorprojecttree.

6. Locatethelineofcodestartingwith

#define ENET_IPADDRandspecifyyour

targetIPaddressbyusingtheIPADDR

macro.Setthetargetaddressto

169.254.3.3,andthelinewillbe:

#define ENET_IPADDR IPADDR(169,254,3,3)

7. DothesamewiththeIPaddressmask

valueENET_IPMASK:

#define ENET_IPMASK IPADDR(255,255,0,0)

8. Compile,download,andruntheapplication

andopenaHyperTerminalwindowaswas

doneinsteps6to13ofLab1.

9. StartyourInternetbrowserandnavigate

tothetargetdeviceaddress.Inthiscase,

169.254.3.3.

10.YoushouldseetheWeb-serverwelcome

pageinthebrowserwindow,asseenin

Figure 4.

Mini-USB-B

Figure 8: Browsing Web pages stored on USB mass storage device

Figure 7.

Figure 4: HVAC Web demo page running from internal memory

Figure 3: MQX Source Tree

Figure 5: Change HVAC setting via Website.

Figure 6: USB adapter plug on M52259DEMO and M52259EVB

Page 13: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

www.freescale.com/mqx 13

8. Yourjobnowistousethetaskaware

debugging(TAD)featuretocheckfor

errorstodeterminewhythiserroris

happening.ToseetheTADdata,pause

theapplicationbyclickingontheBreak

icon(whichisaredsquare)orby

selecting Break in the Debug menu.

4. Thenchangetheautologgingdefine:

#define DEMOCFG_ENABLE_AUTO_LOGGING 0

to this:

#define DEMOCFG_ENABLE_AUTO_LOGGING 1

5. Noticethattheimpactedfileshavea

redcheckmarkbesidethemtoindicate

thattheyneedtobere-compiled,orare

‘touched’.Compile,download,andrun

theapplicationaswasdoneinsteps6

to13ofLab1.

6. GototheshellconsoleinHyperTerminal.

Notethatastringoflogginginformation

willbeprintedoutevery15seconds.It

willalsobeprintedoutwhenthereisan

updatetoanyoftheparameterssuchas

thedesiredtemperature.Youcantestthis

bypressingSW1.

7. PressSW1untilthedesiredtemperature

getsto24°CandthenuseSW2tobring

itbackdownto20°C.Youshouldnotice

thattheloggingwilleventuallystopand

thatnomoreupdatesareprinted.

LAB

5

Finding an Error Using Task Aware Debugging (TAD) in CodeWarriorCovers both M52259EVB and M52259DEMOKIT

Thislabwillshowyouthepowerofusing

task-awaredebuggingtotroubleshootyour

application.Anerrorhaspurposelybeen

introducedintothisproject,andthislabwill

showyouhowtofindandsolvethaterror.

Demonstrates

• Sendingmessagesbetweentasks

(loggingtask)

• CodeWarriortask-awaredebugging

windows

Step by Step Instructions

1. Stoptheapplicationifitiscurrently

running(Debug>Kill)

2. OpentheLabProjectbyselectingthe

File > Open menu item:• ForM52259EVBboard,openfile:

c:\Program Files\Freescale MQX 3.0\demo\ hvac_error \codewarrior\hvac_error_m52259evb.mcp

• ForM52259DEMOboard,openfile:

c:\Program Files\Freescale MQX 3.0\demo\ hvac_error\codewarrior\hvac_error_m52259demo.mcp

3. EnabletheAutoLoggingfeature.Thisis

donebyopeningthehvac.hfile

Figure 1: MQX Source Tree

Figure 2: Up to 24, on the way down it stops logging

Figure 3: Break application execution

Page 14: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

14 www.freescale.com/mqx

Themessagepoolisexhausted.The

problemisonthereceivingside,asitis

alwaysthemessagereceiver’sresponsibility

toreusethemessageobjectorfreeitwhen

nomoreneeded.

LookingattheLogging_task()function,

locatedinLogging_Task.c,youcanseethe

messageisreceivedby

msg_ptr = _msgq_receive(log_qid, 0);

andfurtherthedataofthemessage

(thelogtext)isprinted

printf(msg_ptr->MESSAGE);

Whatismissingisdeletionofthemessage

afterthelogtextisprinted:

_msg_free(msg_ptr);

Addthisline,recompileandrunthe

application. The message memory will now be

releasedafterthemessageisprintedout.

Solution

TheHVACtaskisusingMQXmessages

tosenddatatotheLogtask(seeHVAC_

LogCurrentState()andtheLog()functions)in

HVAC_Util.candLogging_Task.c.TheHVAC

task,asthemessagesender,assumeseach

messageis“consumed”bytheLogtaskand

removedfromthemessagepoolafterthetext

isprintedtotheconsole.

FromtheHVACtaskerrorcodefoundinthe

TaskSummaryTADwindowseeninFigure5,it

isapparentthatamessagecouldnotbesent

becausethemessagepoolisfull.Youcanverify

thisassumptionbyshowingtheMessagePools

TADwindow(Figure6)anddouble-clickingon

theoneandonlymessagepoolentrytobring

upthewindowshowninFigure7.

Figure 4: MQX Task-Aware Debugging menu

9. ThenclickontheMQXpulldownmenu.

Readdownthelistofavailableinformation

windowsandselecttheone(s)thatyou

mightthinkwouldbeagoodindicationas

towhathappened.

10.OneoftheTADwindowswhichwill

quicklyhelpyoutogetanapplication

statusoverviewisTaskSummaryor

CheckforErrors.

Figure 5: Task Summary TAD window

Figure 6: Message Pool Summary TAD window

Figure 8: Correct code

Figure 7: Message Pool Examined (after double-clicking the pool entry)

Page 15: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

www.freescale.com/mqx 15

4. ThedefaultIPaddressoftheboardis

169.254.3.3.Typically,whenyouconnect

yourcomputerdirectlytotheboard,

thecomputerwilldefaulttoanautoIP

addressonthesamesubnetastheboard

(169.254.x.x),thereforerequiringnosetup.

Note:ThePCmaytakeafewminutesto

defaulttotheautoIPaddressandmake

the connection.

However,ifyouhavetroubleconnecting,

youmayconfiguretheIPaddressof

the computer manually. Select Start >

Settings>NetworkConnections>Local

AreaConnection.NoteyouroriginalTCP/

IPsettings,andthensetyourIPaddress

to169.254.3.4andyoursubnetmaskto

255.255.0.0.

Figure 1: M52259EVB board layout

CPLD programer connector

USBconnectorfordebugger

CFcardconnector

5Vpowerconnector

USB

Power switch

Ethernet

RS232

MRAM

AlteraMaxII CPLD

3. Open the Lab Project by selecting the

File > Open menu item:• ForM52259EVBboard,openfile:

c:\Program Files\Freescale MQX 3.0\demo\telnet_to_serial\codewarrior\telnet2ser_m52259evb.mcp

• ForM52259DEMOboard,openfile:

c:\Program Files\Freescale MQX 3.0\demo\telnet_to_serial\codewarrior\telnet2ser_m52259demo.mcp

LAB

6

Ethernet to Serial Bridge, Freescale MQX RTCSCovers both M52259EVB and M52259DEMOKIT

Thislabdemonstrateshowtocreateabridge

betweenaTCP/IP(telnet)connectionanda

serial line.

Demonstrates

• MQXRTCSTCP/IPnetworkstack

• Customtelnetserverimplementation

• Re-directingSTDINandSTDOUToutput

withinanMQXtask

Step by Step Instructions

1. Makethefollowingconnectionsfromthe

MCF52259boardtothecomputer.See

Figure1andFigure2.a.USBdebuggerconnectiontoa

USBportonPC

b.SerialPort0(UART0)toa Serial Port on PC

c.AcrossoverEthernetcablebetween theboardandanEthernetporton

your computer

d.Attachpowercableandturnonthe

board’spowerswitch(M52259EVBonly)

2. ThefirsttimeyouconnecttheUSB

debuggercabletoyourPC,Windowswill

installadriverforthedebugger.Follow

thepromptstoautomaticallydetectand

installthedriver.

Ethernet

USB

RS232

USBconnectorfordebugger(OSBDM)

Figure 2: M52259DEMO board layout

Page 16: MQXTUTORIALLAB

MQX RTOS—Lab Tutorials

5. Open the config.hfileintheCodeWarrior

windowasshowninFigure3.Doubleclick

thefileitemlocatedinthe“Source”group

intheCodeWarriorprojecttree.

6. Locatethelineofcodestartingwith

#define ENET_IPADDRandspecify

yourtargetIPaddressbyusingthe

IPADDRmacro.Setthetargetaddressto

169.254.3.3,andthelinewillbe:

#define ENET_IPADDR IPADDR(169,254,3,3)

7. DothesamewiththeIPaddressmask

valueENET_IPMASK:

#define ENET_IPMASK IPADDR(255,255,0,0)

8. Compile,download,andrunthe

applicationandopenaHyperTerminal

windowaswasdoneinsteps6

to13ofLab1.

9. OpenaCommandPromptonthePC

(Start > All Programs > Accessories >

Command Prompt).Atthepromptinvoke

atelnetsessiontotheboardbytyping

telnet 169.254.3.3Youwillbeconnected

totheMQXshellviatelnet.

10.Nowtheserialconsoleandthetelnet

sessionsshouldbe“bridged.”Typesome

charactersintothetelnetsession,andyou

shouldseethecharactersappearingon

theconsoleterminalwindow.SeeFigure4

forhowitwillappear.

11. Then try typing into the console terminal

window,andyoushouldseethe

characters appearing in the telnet session.

FreescaleandtheFreescalelogoaretrademarksorregisteredtrademarksofFreescaleSemiconductor,Inc. intheU.S.andothercountries.Allotherproductorservicenamesarethepropertyoftheirrespectiveowners. ©FreescaleSemiconductor,Inc.2008.

DocumentNumber:MQXTUTORIALLAB REV0

Learn More: FormoreinformationaboutMQXandFreescaleSolutions,pleasevisit www.freescale.com/mqx.

Figure 4: Ethernet to Serial BridgeFigure 3: MQX Source Tree