Setting up a PIL Simulation for MCU 5643L in Matlab, CodeWarrior Classic

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setting up a PIL Simulation for MCU 5643L in Matlab, CodeWarrior Classic

7,059 Views
dynexdave
Contributor II

Hi,

I have a Matlab Simulink model from which I generate C code using Matlab Embedded coder. I'd like to run processor in the loop (PIL) simulations using my target MCU (NXP 5643L) from Matlab using the auto-generated code. The compiler I'm using for the target is CodeWarrior Development Studio for MPC55xx/MPC56xx (Classic IDE) v2.10 (from within software it's version 5.9.0, build 3510), I believe this also needs to be used in the process to build the generated code?

I've done some on target testing previously using the 5643L, in that case I set up a project in CodeWarrior, then the auto-generated files would overwrite the project source files and I initiated build and execute processes using a batch file.This doesn't constitute PIL though, I'm struggling to see how to set it up to work from Matlab.

Does anyone have any experience of setting up a Matlab PIL simulation for a 5643L or similar? How can I integrate CodeWarrior into the process to re-build the project using the new auto-generated code? I assume this all needs to be set up from the Matlab side? Does anybody have any material that would help that they could possibly share with me? I was thinking to save some time I'd use the Lauterbach TRACE32 simulator instead of the actual target initially.

Any help much appreciated. Thanks!

Best regards,

David

21 Replies

3,655 Views
dynexdave
Contributor II

Hi paulvlase‌,

How is the toolbox porting coming along? Do you have an idea of when this work might be completed?

Thanks and best regards,

David

0 Kudos

3,658 Views
dynexdave
Contributor II

Hi dumitru-daniel.popa paulvlase

Have you had chance to look into the MemUnit_T issue? 

Thanks and best regards,

David

0 Kudos

3,658 Views
paulvlase
NXP Employee
NXP Employee

Hi dynexdave‌,

I can confirm the issue. This happens because the toolbox was released for older Matlab versions, and in the meantime Matlab did some updates to its PIL support.

I started to port the toolbox to the latest Matlab versions.

3,656 Views
damarandei
Contributor I

I am running into a very similar issue as well with Matlab/Simulink 2018a, version 2 of the MBD Toolbox.

I added C:\MATLAB\global\R2018a\toolbox\rtw\targets\pil\c to Custom Code tab in Code Generation to get past not finding xil_interface_lib.h but I get 

"C:\MATLAB\global\R2018a\toolbox\rtw\targets\pil\c\xil_interface_lib.h", line 27: error #20: identifier "MemUnit_T" is undefined uint32_T serverFcnId, MemUnit_T xilResponseId,

It looks like MemUnit_T didn't change with the updates so I am not sure how to fix it:

pastedImage_1.png

0 Kudos

3,658 Views
dynexdave
Contributor II

Hi paulvlase, dumitru-daniel.popa,

I think I've made some progress by adding the file location (enclosed in " ") into the build include search path in Matlab (Simulation -> Model Configuration Parameters -> code generation -> custom code -> Additional build information -> include directories...).

I'm now seeing the following error:

dv2.JPG

I've looked in xil_interface_common.h and I can see the use of MemUnit_T but it isn't defined. I've traced back through the header files but can't find a definition. It seems as though there is an issue in setting paths as this must be defined somewhere. Not sure whether this is down to Matlab version? I'm on 2016a. Do you know if this type is defined in one of your header files? Any ideas?

Best regards,

David

0 Kudos

3,658 Views
dynexdave
Contributor II

Update: I've found the header file location, I see that it is a Matlab file. Why would it have an issue finding this? the folder where the file is located should be in the search path. How can I tell the build process to include this file location as an include directory?

Thanks

Best regards,

David

0 Kudos

3,661 Views
dumitru-daniel_
NXP Employee
NXP Employee

paulvlase‌,

Can you have a look to this please?

Thank you!

Daniel

0 Kudos

3,661 Views
dynexdave
Contributor II

Hi dumitru-daniel.popa,

Thanks, I managed to solve the last issue by re-installing CodeWarrior in a directory without spaces :smileyhappy:

I've now run into a new issue... There is a header file that it cant seem to open, see diagnostics below

dv.JPG

I believe this header file is required for the serial communication. Not sure where the file should be or why it is unable to pull it though. I'm guessing somewhere you must be able to tell the build process (from Matlab) what additional include directories should be used? Is this header file something NXP supply?

Getting there slowly :smileyhappy:

Thanks

David

0 Kudos

3,661 Views
dynexdave
Contributor II

Hi dumitru-daniel.popa,

I've reverted to Matlab 2016a to try and test this. I can now click on the blue box and that runs the script that sets default values.

I've also installed the virtual COM port driver and that is working.

However, when I try and run the demoParkInvSILModelRef PIL simulation (with target attached to PC) I get the following error:

pastedImage_1.png

I'm not really sure what the problem is... doesnt seem to like 'C:/"Program ' but I can't see why. If you have any ideas can you please let me know?

By the way, my environment variable is set to:

MW_TOOL = C:/"Program Files (x86)"/Freescale/"CW for MPC55xx and MPC56xx 2.10"

Thanks

Best regards,

David

0 Kudos

3,661 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi David, 

Your issue is similar with this one: https://community.nxp.com/message/922658?commentID=922658#comment-922658 

Most likely is due to 8dot3 mode.

You could try that solution - hope it will work in your case too.

Best regards,

Daniel

0 Kudos

3,660 Views
dynexdave
Contributor II

Hi dumitru-daniel.popa‌,

In general, if the build error message is not clear - my advice is to have a look at build_exception.mathttps://community.nxp.com/thread/449904#comment-902087

Paul Vlase

Can you have a look over this ? As far as i can remember the PIL simulation from older toolboxed does not work with MATLAB 2016b or newer. Is it something we can patch ?

Thank you!

I've looked at the build_exception.mat file, it reports the following error:

Error when creating the model reference code generation target for '<a href="matlab:open_system ('PILTest1')">PILTest1</a>'.  The System Target File (STF) is not declared to be model reference compliant.  For more information, in the Simulink Coder documentation, see the section about <a href="matlab:helpview(fullfile(docroot,'toolbox','rtw','helptargets.map'), 'modelReferenceCompliant_selfcompliance')">declaring model reference compliance</a>.

From the model configuration parameters I see that the STF file being used is rappid564xl.tlc  

Recall that the model I'm working with is demoParkInvPILModelRef. If you have any ideas on this it would help a lot!

On a slightly separate note, I'm a little confused about RBA and RBF files for the boot-loader utility. The Motor Control development toolbox user manual discusses preparing the MCU by downloading an RBF file into flash memory. A colleague mentioned RBA, If I use an RBA do I need to worry about loading an RBF file into flash first/at all?

Thanks

Best regards,

David

0 Kudos

3,661 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi David, 

I checked the PIL model on my side and it works fine until 2016a. Starting with 2016b the MATLAB changed the PIL interface and some updates are needed to enable the support for newer version. We will try to prepare a patch in the coming days. If you could downgrade the MATLAB to an older version you could have the PIL models running as is.

Regarding the bootloader support - this processor comes from factory with RBA in ROM. Once you install the USB2UART driver you should be able to communicate with the board immediately after reset. You can try a simple project directly from Simulink.

Best regards,
Daniel

0 Kudos

3,661 Views
dynexdave
Contributor II

Hi dumitru-daniel.popa

After successfully running the demoParkInvSILModelRef demo and resolving a hardware issue with our target I'm ready to try the demoParkInvPILModelRef PIL demo simulation :smileyhappy: I tried it but ran into problems.

  • The target I'm using is the evaluation board supplied with the dual motor kit Dual 3-phase PMSM Kit with MPC5643L MCU|NXP It is currently disconnected from the rest of the evaluation kit so I only have the control board.

  • I have a USB cable connected directly between the PC and the USB port on the evaluation board. This is what I see in the device manager: 

PILdm.jpg

The device is listed under 'Other devices', the COM ports don't change at all. I was expecting to see a COM port occupied as that's what I need to enter into the RAppID Target Setup Box. Am I doing something wrong here?

  • In the demoParkInvPILModelRef model, if I click on the blue box as instructed I get the following error:

PILblue_err.jpg

I believe clicking this box just sets some configuration parameters. I've checked and as far as I could tell all these parameters are correctly set anyway but I thought I'd mention it.

  • When I try and run the model I get the following error:

PILcompile_err.jpg

I've checked the model rebuild setting for the top level and PILTest1 models. Both were set to only rebuild if changes were detected. I've changed these to Always rebuild. Not sure what else could be causing this. Any ideas?

  • One final note, In the compiler setup section of the manual it says to set the following envirnment variable:

MW_TOOL = C:/Freescale/"CW for MPC55xx and MPC56xx 2.8"

but I had to use 

MW_TOOL = C:/"Program Files (x86)"/Freescale/"CW for MPC55xx and MPC56xx 2.10"

Is 2.10 compatible?

I'm sorry if my questions are a little stupid. I'm no expert in this area so learning as I go :smileyhappy:

Thanks in advance

Best regards,

David 

0 Kudos

3,661 Views
dynexdave
Contributor II

Seems as though there were some lines in the header files (located in C:\MCToolbox\rappid564xl\MCLIB for MPC564xL\include) that were commented out with //. When at the code generation stage these were causing a problem. I've modified these files and kept a copy of the old ones just in case. I'm now able to run the demoSIL model so can move onto PIL! :smileyhappy:

Best regards,

David

0 Kudos

3,661 Views
dynexdave
Contributor II

Hi dumitru-daniel.popa,

Sorry, I have been pretty busy this last few days! I went back to the RAppID examples today. There are two that I think are particularly useful: demoParkInvSILModelRef and demoParkInvPILModelRef, these contain SITTest1 and PILTest1 respectively. I started with the SIL model demo (which I think should be independant of hardware), when I click on the blue box on the model root/home page I get the following error message:

SILTest1.jpg

 

I assume clicking on the blue box is supposed to make apply some configuration/setup?

Similarly if I just try to run the model I get an error in the Matlab Diagnostic viewer saying:

Error evaluating 'InitFcn' callback of RAppID_EC_564xL block (mask) 'SILTest1/RAppID_564xL_Config'.
Callback string is 'rappid_564xl_set_cur_model(bdroot(gcs));
rappid_564xl_update_model('init');
rappid_564xl_check('RAppID_EC_564xL');
rappid_564xl_consistency_checks( bdroot(gcs));'
Caused by:
Undefined function 'slsfnagctlr' for input arguments of type 'char'.
Variable 'slsfnagctlr' does not exist.

 

I have no idea what this variable is for or what it should be set to. I'm thinking that if I first get the SIL demo working then I can move onto the PIL demo (which incidentally has the same problem).

Also how is the progress on the PIL model harness creation video going?

Best regards,

David

0 Kudos

3,661 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi David, 

Please have a look here: https://community.nxp.com/thread/467975 

Thank you!

Daniel

0 Kudos

3,661 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi dynexdave‌,

Lets break down the thread and address each of the questions.

I have a Matlab Simulink model from which I generate C code using Matlab Embedded coder. I'd like to run processor in the loop (PIL) simulations using my target MCU (NXP 5643L) from Matlab using the auto-generated code. The compiler I'm using for the target is CodeWarrior Development Studio for MPC55xx/MPC56xx (Classic IDE) v2.10 (from within software it's version 5.9.0, build 3510), I believe this also needs to be used in the process to build the generated code?

Any code that needs to be executed on MPC5643L must be cross compiled with one of the 4 compilers supported by the NXP MATLAB Toolbox. These compilers are:

  • GHS_TOOL = C:/ghs/multi517
  • DIAB_TOOL = C:/WindRiver/diab
  • MW_TOOL = C:/"Program Files"/Freescale/"CW for MPC55xx and MPC56xx 2.8"
  • CW_TOOL = C:/Freescale/"CW MCU v10.6"

where <COMPILER_STRING>_TOOL is a system variable

Therefore, the answer for your first question is - YES - you will need to ensure a proper compiler is set in order to build the generated code from MATLAB to obtain the ELF/MOT/BIN or HEX file that must be loaded into the MPC5643L FLASH or RAM memory.

I've done some on target testing previously using the 5643L, in that case I set up a project in CodeWarrior, then the auto-generated files would overwrite the project source files and I initiated build and execute processes using a batch file.This doesn't constitute PIL though, I'm struggling to see how to set it up to work from Matlab

You will need to clarify this a little bit more. 

So, you have a project that contains some C-source file and now you wish to include the C-files generated from MATLAB into this CodeWarrrior project ? 

Do you want to achieve something like a hybrid project (part of the sources are custom + part of the source generated from MATLAB ?

You should be aware that the NXP Toolbox is configure to generated a standalone project ready to run on the target. All you can do is to have an intermediate step that will copy the files from the generated folder into the CW project folder. Most likely you can do that automatically as a prebuild command using the makefile.

Does anyone have any experience of setting up a Matlab PIL simulation for a 5643L or similar?

Converting any Simulink Model to run as PIL should not be an issue. You could find examples on Mathworks or you can watch this video  Video Link : 7845 to see the main steps of START to PIL model conversion. Please note that is for a slightly different processor and toolbox but the "philosophy" behind is the same.

How can I integrate CodeWarrior into the process to re-build the project using the new auto-generated code? I assume this all needs to be set up from the Matlab side? Does anybody have any material that would help that they could possibly share with me? I was thinking to save some time I'd use the Lauterbach TRACE32 simulator instead of the actual target initially.

PIL is a co-simulation. Part of the simulink model will be executed on the Host PC and part of it will be executed on the real HW: MPC5643L. The NXP's Matlab Toolbox will generate the appropriate files for the XIL interface (Serial Comm between MATLAB and the MPC5643L) and the Linker files needed to compile the project. Then will download the ELF to the target and finally the MATLAB will control the simulation via XIL interface. 

In the c:\MCToolbox\rappid564xl\Examples\ folder you can find an example ready to be run on the MPC5643L for PIL simulation.

Please keep in mind that the toolbox was designed to use the real HW for the PIL simulation - therefore using a simulator will not help you.

Hope this helps!

Daniel

3,661 Views
dynexdave
Contributor II

Hi dumitrupopa

Thanks for taking the time to respond :smileyhappy: some very helpful answers there. I think my compiler is CW for MPC55xx and MPC56xx v2.10... but we'll worry about that later!

You refer to the NXP MATLAB Toolbox... I don't currently have it. So I don't go down the wrong path, please could you confirm this is the toolbox I need: Model-Based Design Toolbox|NXP 

dumitru-daniel.popa wrote:

I've done some on target testing previously using the 5643L, in that case I set up a project in CodeWarrior, then the auto-generated files would overwrite the project source files and I initiated build and execute processes using a batch file.This doesn't constitute PIL though, I'm struggling to see how to set it up to work from Matlab

You will need to clarify this a little bit more. 

So, you have a project that contains some C-source file and now you wish to include the C-files generated from MATLAB into this CodeWarrrior project ? 

Do you want to achieve something like a hybrid project (part of the sources are custom + part of the source generated from MATLAB ?

You should be aware that the NXP Toolbox is configure to generated a standalone project ready to run on the target. All you can do is to have an intermediate step that will copy the files from the generated folder into the CW project folder. Most likely you can do that automatically as a prebuild command using the makefile.

Yes, currently the generated code contains functions that I call from main.c. It is already a hybrid project if you like, featuring auto-generated code and hand-code that stitches it all together. It was manually created by myself. Having an automatically generated project should be fine. It sounds like with the toolbox it should all be achievable. 

Best regards,

David

0 Kudos

3,661 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi dynexdave

Yes, that is the correct link to the Toolbox main page.

You need to click on "Download Eval" Button and then you will reach to a page like this:

pastedImage_1.png

Select the link highlighted, and you will see this.

pastedImage_2.png

Download and install it and have fun!!!

Best regards,
Daniel

PS: direct link to the MPC564xL Toolbox is: https://nxp.flexnetoperations.com/control/frse/download?agree=Accept&element=6107501 

0 Kudos

3,661 Views
dynexdave
Contributor II

Hi dumitrupopa,

Thanks for the links, I've managed to get it installed OK. Now I'm trying to now figure out how to connect everything up to the PC to try it :smileyhappy: Are there any guides/documentation to go with the toolbox?

I'm looking at the MPC564xL_FOC_PIL example (from c:\MCToolbox\rappid564xl\Examples\). I have a few questions:

1. Currently in our manual build process, for the toolchain we use a PE micro multilink and download to flash. Is this how it would/could work in this example? I.e. I just hook our MPC5643L up to the PC via the PEmicro and I'm away? We don't have JTAG capability on our board. Inoticed the target type in the example is RAM. 

2. Looking at the FOC_PIL there are some input and output ports to the model that aren't connected to anything. What should I be expecting the simulation to do? Without a connected input I don't think it will do anything but I cant see if/how this is routed to anything in the MCU. In my mind I'd thought that the PIL model in Matlab would be referenced model and connected to a test harness with stimulus signals and scopes on the outputs. This doesn't seem to be the case here.

Thanks in advance 

Best regards,

David

0 Kudos