9
Building a COFFEE POT simulation on CCESS 2.2.0 for Blackfin BF533 Introduction for Lab0 and Assignment 1 CCES is based on Eclipse There is an ARM IAR plugin for Eclipse which allows the same approach to occur there (Discovery board and MPEG boards) Starting a CCES project Step 1 – Activate CCES and select H:ENCM511_2016Workspace directory and then dismiss “Help” window Step 2 – Set the project Name My_CoffeePot_2016Assignment Labs are done groupwise Assignments are individual Step 3 – Set processor type Step 4 – T.A.D.B. Take a deep breath to control the excitement How to set processor type changes Then ST Then ST32 Then ST32F40X Then ST32F407 Then ST32F407VF Ditto for EiE boards See JEADI articles for details Build a CCES project continued – 5 to 7 5) Click on Configure Project then Template code screen Change to “add default” C++ You will need to delete the project and start again if you click on default C because of the different calling procedures found between C and C++ You will experience the effect of C++ Name mangling to handle function overloading in Ass. 1 Click Finish 6) Click FINISH on Projects and Settings Window” (Slow when writing to USB) 7) Click on little triangle next to the Project name My_CoffeePot_2016Assignment, and expand all directories also click on Console tab Click on app_startup.s file Possible Quiz question What is thepurpose of the C++ files automatically placed inside the directory startup_ldf? What is the tab Startup Code / LDF? What happens if you click on system.svc?

Starting a CCES projectpeople.ucalgary.ca/~smithmr/2016webs/encm511_16... · Now do RUN | RESUME PSP – Check that program has made a VALID EXIT and did not do “unknown” crash

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Starting a CCES projectpeople.ucalgary.ca/~smithmr/2016webs/encm511_16... · Now do RUN | RESUME PSP – Check that program has made a VALID EXIT and did not do “unknown” crash

Building a COFFEE POT simulation on CCESS 2.2.0 for Blackfin BF533

Introduction for Lab0 and Assignment 1CCES is based on Eclipse

There is an ARM IAR plug‐in for Eclipsewhich allows the same approach to occur there

(Discovery board and MPEG boards)

Starting a CCES project• Step 1 – Activate CCES and select 

H:ENCM511_2016Workspace directory and then dismiss “Help” window

• Step 2 – Set the project NameMy_CoffeePot_2016Assignment

Labs are done group‐wiseAssignments are individual

• Step 3 – Set processor type

• Step 4 – T.A.D.B.Take a deep breath to control the excitement

How to set processor type changes

Then ST Then ST32

Then ST32F40XThen ST32F407

Then ST32F407VF

Ditto for EiE boardsSee JEADI articles for details

Build a CCES project continued – 5 to 75) Click on Configure Project then Template code screen

– Change to “add default” C++ – You will need to delete the project and start again if 

you click on default C because of the different calling procedures found between C and C++ 

– You will experience the effect of C++ Name manglingto handle function overloading in Ass. 1

– Click Finish

6) Click FINISH on Projects and Settings Window” (Slow when writing to USB)

7) Click on little triangle next to  the Project name My_CoffeePot_2016Assignment, and expand all directories

– also click on Console tab– Click on app_startup.s file

Possible Quiz question • What is thepurpose of the C++ files automatically 

placed inside the directory startup_ldf?• What is the tab Startup Code / LDF?• What happens if you click on system.svc?

Page 2: Starting a CCES projectpeople.ucalgary.ca/~smithmr/2016webs/encm511_16... · Now do RUN | RESUME PSP – Check that program has made a VALID EXIT and did not do “unknown” crash

Find (later modify) LDFDo something equivalent (perhaps not similar) if using Eclipse IAR MIPS plugin)

8) Right click on system.svc file and   then on OPEN

MAGIC – W.A.I.L. of why this file is needed later

– Click on tab – LDF– W.A.D.N. ‐‐Will need this when we want 

to “Add a simulated coffeepot to the address and data busses of the “real Blackfin processor.

– W.A.I.L. – How does changing the LDF match to “REAL” hardware

LDF – loader descriptor file – Used by developer to describe to the IDE  where the LINKER places program code and program data in the microprocessor memory 

W.A.D.N.  ‐‐ worry about detail nowW.A.I.L.  ‐‐ worry about it laterW.A.I.L. – P.N.  ‐‐W.A.I.L – perhaps never

CoffeePot_2016Assignment

‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐

Add “your” files to the project 10) Check you can build the project11) Right click on “src” folder icon

• Go inside  My_CoffeePot_2016Assignment1.cpp and comment out main( )• Rebuild the project – Check the error message – this is what happens if you forget to add a 

main( ).  Note the error message on your PSP check list. Put back main( )12. Rename My_CoffeePot_2016Assignment1.cpp  to My_CoffeePot_2016main.cpp 

andMy_CoffeePot_2016Assignment1.h  to CoffeePot_2016main.h and rebuildThis MAY cause hidden bug – fix the bug ‐‐ Add to PSP check list 

• NEW | File from template • MyCoffeePotFunctions_forCPP.h• MyCoffeePotFunctions_forASM.h• MyCoffeePotFunctions_CPP.cpp• My_WaterControlCode_CPP.cpp• My_WaterControlCode_ASM.asm• My_HeaterControlCode_CPP.cpp• My_HeaterControlCode_ASM.asm

• Using _CPP.cpp and _ASM_asmis part if my PSP when I mix CPP and ASM code

• All these files are currently empty and need to be filled

RISK MANAGEMENT– Learn a little aboutwhat the correct ASM format looks like• Click on My_WaterControlCode_ASM.asm icon to open the file inside the editor

• Add the information we had from previous presentation – see next slide (Cut‐and‐paste from pdf)

• Right click on My_WaterControlCode_ASM.asm icon and select – Build Selected File(s)– Click on Console tab to see errors– Expect errors – should see them as markers against each line in editor

– Comment out all error lines– Build with no errors

When writing ASM or CPP turn on editor lines number so can discuss

Page 3: Starting a CCES projectpeople.ucalgary.ca/~smithmr/2016webs/encm511_16... · Now do RUN | RESUME PSP – Check that program has made a VALID EXIT and did not do “unknown” crash

Cut‐and‐pasted from class notesThen reformatted, and updated

• FORMATTING IS A COURSE  REQUIREMENT TO MAKE MARKING AND HELPING YOU EASIER. 

• FORMATTING  IS MARKED IN LABS, ASSIGN, EXAMS

NOTE COLOUR CHANGES IN TEXT

PSP: DO READ THROUGH AND WALK THROUGH

LOOK FOR WHERE THINGS LOOK DIFFERENT

3 OBVIOUS SYNTAX ERRORS

SyntaxDefects found after build

Meansproblem at assemblersource file

DEFECT RECOGNIZED BY COMPILER“ASSEMBLER”

NOT YET REACHED THELINKER STAGEwhich groups files together into executable)stage  “Assembler”  Likes “.section” but without the “;” (perhaps)

We say “perhaps” because this line is when assembler knew something was wrong – problems perhaps earlier

Assembler  says “LDF” is defined to put “code” in “.section program”

Problem is not with “extern” but with the line before

Practice  “Reading the error message”The assembler is unhappy with everything 

BEFORE  ;

This problem MIGHT be fixed if we fix the earlier problems 

Look up “correct” assembly code syntax

• Use last year’s notes• Or Download BF533 Assembly Language manualhttp://www.analog.com/en/processors‐dsp/blackfin/products/manuals/resources/index.html

– Link is available from ENCM511 website

Page 4: Starting a CCES projectpeople.ucalgary.ca/~smithmr/2016webs/encm511_16... · Now do RUN | RESUME PSP – Check that program has made a VALID EXIT and did not do “unknown” crash

Wants  .section data1We have placed a variable in data1 and initialized it

CrossCore has decided we might be doing assembly code – and has started showing error in margin

LINE 30:  FIX ME BEFORE PROCEEDING

LINE 31: FMBP

ASSEMBLER REQUIRESEACH FUNCTION HAVE A BEGIN LABEL _NAME:AND AN END LABEL_NAME.END:NOTE UNDERSCORES as a standard practice in coding

LINE 34: FMBP

After those fixes• Build the project. We will successfully pass the COMPILER stage

• We now have linker errors – where we promised (using .extern) that certain functions exist in other files – but apparently they don’t (although we can see their code  in other files)

FIX “main” error

Understanding linker errors

• CCES can handle many processors or multi‐core systems (p0, p1, p2 etc..– This LINKER error message says the “processor p0” code is missing two functions

• Different from a COMPILER error message which might complain about compiler error  with REGISTER P0

– .doj extension indicates an object file – a file that has undergone the conversion C++  asm almost machine code or  asm almost machine code(performed by compiler and assembler)       (performed by assembler)

– Many .doj files linked together form executable program .dxe that can be downloaded to the board (or run in the BF533 simulator)

– Function UpDateSimulationDisplay needed in  file DoSimulation_ASM.doj (object file you wrote)

– Function main( ) needed in file app_startup.doj• app_startup.doj is an object file from a C++ / C / asm file you did not write, but was placed 

into your project automatically when you made a project  • Probably a system file that makes the C++ environment work – do not change or delete this

Let’s add a “does‐system‐still‐work”main( ) to CoffeePot_main.cpp

• Before clicking “Build project”– Do a CODE REVIEW BEFORE compiling (PSP ‐‐ Personal Software Process)– Fix all syntax errors that editor is telling you about– The number of syntax not found – indicates possible logical mistakes 

(now DEFECTS) left behind in your code – not found by you or compiler

LOGICAL DEFECTS willtake MUCH timeto correct as youDON’T KNOWwhen you made them,where they are,and what “knock‐on”effect they are having

Page 5: Starting a CCES projectpeople.ucalgary.ca/~smithmr/2016webs/encm511_16... · Now do RUN | RESUME PSP – Check that program has made a VALID EXIT and did not do “unknown” crash

Build is improving Coding mistakes found before moving onto next 

phase are called Coding ErrorsDesign mistakes found before moving onto next phase are called Design Errors.Design mistakes not found before moving onto next phrase are Design DefectsDEFECTS are expensive to fix as you don’t know where you made them

REMEMBER

Don’t use print statements as they will cause problems when debugging real‐time code and must be 

removed when given to customer (screens cost 

money)

Too many things wrong with the .asmfile – Let’s exclude it  for now (not remove it as we need it later)

• Right click on .asm file – select properties

• Click on C++ Build• Click on Settings• Click on “Exclude resource from 

build”• Click “OK”• So Project | Clean 

(Recommended)• Rebuild Project

(F7)

Outside A301 / A305  ‐‐ you can run project using a  simulator session

Inside A301 / A305 ‐‐ you can ALSO run project using a emulator session

• If built with no errors• Right click Project name 

– Select Debug as | CrossCore application• In Select Processor window – chose Blackfin ADSP‐BF533 then NEXT

• In Select Connection type  ‐‐ choose Emulator then FINISH

• In Create, Manage and Run window,  select CoffeePot_.... Program, click APPLY, click DEBUG

• In CONFIRM Perspective Switch SHOULD WE click Yes or No to switching to Debug display mode

HINT:  Either close ALL projects except the one you are working on, or carefully check 

which project CCES want to run

Page 6: Starting a CCES projectpeople.ucalgary.ca/~smithmr/2016webs/encm511_16... · Now do RUN | RESUME PSP – Check that program has made a VALID EXIT and did not do “unknown” crash

Now do RUN | RESUME

PSP – Check that program has made a VALID EXIT and did not do “unknown”crash When program stops, click on white arrow icon,Select current program counterCHECK STOPPED AT ___lib_prog_term

My Personal Software Process (PSP)

• Never have code that occupies more than a screen (Turn screen long ways is only a partial fix)

• If code occupies more than a screen – then move code portions into a subroutine / function – Abstraction

• Plan the project in parts• Fix things in order – make code readable

– main( ) – series of calls to functions (flow, 7 +‐ 2); – Add YOUR function prototypes (interface) into header– Add stubs (placeholder code) for all your functions– Compile, Link, Download, Run  and(IYAG) move to next stage 

Plan Ahead in small chunks 

• Tell simulator how many coffeepots to simulate• Check that it did so• Find out where the “plug‐and‐play” control system placed the coffeepots you requested

• Control whether you do simulation using C / C++ code or using Assembly code

• Find out about some hints for doing Assignment 2

• Learn how to recognize some standard LSD issues– LSD are Little Stupid Details causing catastrophic errors 

How to waste BEACOUP de tempin assignments and laboratories

• Ignore all the warning message from the IDE tools that code is wrong

• Just activate “Build project” command and watch the defects appear, and waste time fixing them, rather than avoiding them

Get into PSP habit of “Code Review” as you go along

Page 7: Starting a CCES projectpeople.ucalgary.ca/~smithmr/2016webs/encm511_16... · Now do RUN | RESUME PSP – Check that program has made a VALID EXIT and did not do “unknown” crash

Fixes and why• Is it a COMPILER, LINKER or RUN‐TIME error

– Need to recognize which – different solutions– Look in Console window for answer (P.Q.1.Q.)

• X‐error ‐‐ Header file  not found “CoffeePot2015Assignment1.h” – We changed some file names. – Would using “CCES refactor | rename” option have prevented this error?

• Click on “Bug” icon – Unresolved error– Have not included “system” header file (.h), “your project” header file, or did not do CODE REVIEW and catch typo errors

Demonstrate main.cpp to control 1 POT

SKIP TO NEXT SLIDEJUST A REMINDER THAT THERE WAS A LOT OF CODE GIVEN IN 

THE LAST LECTURE

How to recognize other error types and how to fix them

• Init_CoffeePotSimulation( )  used incorrectly– May be due the “2015” update that has occurred

• What other functions are used incorrectly or just unknown

Will let you fix these DEFECTS(Called DEFECTS as got past CODE REVIEW)

• DEFECT ‐‐‐ Humpheys calls them  “ERRORS OUT OF PHASE”, meaning mistakes introduced in an earlier part of the project and not caught when introduced

• Moved onto new type of problem

FATAL LINKER ISSUES

NOTE: “NAME MANGLING” is occurring, which is the way C++ handles “Overloaded functions” when generating the “assembly code” needed for the project. Name mangling does not occur withC functions or C++ functions declared with “extern C”

C++ function void UpdateSimulationDisplay(void) is NOT activated in ASM by using CALL _UpdateSimulationDisplay;   but by  CALL _ _ Z3 UpdateSimulationDisplay v (no spaces)

Page 8: Starting a CCES projectpeople.ucalgary.ca/~smithmr/2016webs/encm511_16... · Now do RUN | RESUME PSP – Check that program has made a VALID EXIT and did not do “unknown” crash

Fixing Linker errors• Add “Library” .dlb (See Lab0 Familiarization) to fix other linker errors

• When you build successfully – run the project in simulator (Fake a BF533 processor running inside Windows 7) or by using emulator (on the actual board – in A301/A305)

Oh!!  We all had a tragic accidentRemember: Embedded Systems are safety critical,

so “Practice Safe Programming” habits

• Real World ‐‐ Nobody remembered to plug in coffeepot – embedded system crashed

• Embedded World – Program tried to access non‐existent memory.  – This caused an EXCEPTION– No EXCEPTION HANDLER was provided so EVERYTHING FAILE!

• Remainder of slides are a reminder of what discussed about C++ code I have provided for you to use during the Coffeepot Assignment

Add main.cpp to project, build and check that you get the Compiler error messages expected

To stop COMPILER error messages about functions not defined –generate MyCopyPotFunctions.h

Here is how to prototupe ASM called from C++

ASM itself does not use prototype

SKIP TO NEXT SLIDEJUST A REMINDER THAT THERE WAS A LOT OF CODE GIVEN IN 

THE LAST LECTURE

Page 9: Starting a CCES projectpeople.ucalgary.ca/~smithmr/2016webs/encm511_16... · Now do RUN | RESUME PSP – Check that program has made a VALID EXIT and did not do “unknown” crash

Add My_CoffeePotFunctions.cpp with  function STUBS

STUBS built cut‐and‐pasted from “.h” fileProject should now build and run 

SKIP TO NEXT SLIDE

DO PSP AND FIND THE MAJOR SYNTAX ERROR BEFORE DOING BUILD

If you don’t know how to do something  ‐‐ call a subroutine and fix later 

Top‐down programming ‐‐. P.P.PBuild a function stub

Build a function stub

If you builda function stubvoid Name(….) { }Then you can check 

that the code you have so far built while build 

and link

SKIP TO NEXT SLIDE

Pseudo Code details

35

SKIP TO NEXT SLIDE