Custom simulink block for MPC574xR

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

Custom simulink block for MPC574xR

2,915 Views
raghurajappa
Contributor IV

Has anyone tried to make simulink block for MPC574xR? NXP has not yet released for this controller (maybe they would do so in 2019). So I was wondering if someone has tried this? If yes, could you please share your insights/direction? 

I am currently stuck without RappID initialisation block for MPC574xR and also looking into atleast step-1 which is GPIO pin toggle.  

Labels (2)
6 Replies

2,404 Views
constantinrazva
NXP Employee
NXP Employee

Hello raghurajappa‌,

First of all, sorry for the delayed answer. We don't have any plans to release a MPC574xR toolbox yet. If you are having trouble with setting up peripherals/clocks etc, you can post your questions on the MPC5xxx  community. 

Hope this helps,

Razvan.

0 Kudos

2,404 Views
raghurajappa
Contributor IV

Hi Razvan,

I am aware that NXP is not planning on releasing MPC574xR toolbox yet. But if I could get some support with the toolchain for this, it would helpful as we (our team) are planning on making custom blocks by ourselves for this microcontroller.

The goal is to get from C code (drivers) to Simulink blocks to C code to be flashed on the MPC5745R microcontroller. I can see that the RappID is not available for this microcontroller. I can also see that as a consequence, most likely FreeMaster would also not be available. 
But at this moment, how can I make this workflow happen?? (C to simulink to C for this controller). We're willing to make the developmental efforts ourselves. But I am stuck with get this workflow clear in my head. Does it mean, that we need to develop our own tool to flash (from Simulink), to debug in SIL/PIL mode? 

I just need help in getting the workflow clear and if possible a small example of a single GPIO pin toggle or something.


Kind Regards,
Raghu

0 Kudos

2,403 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi Raghu, 

To get from C-code to Simulink blocks/models, we are using TLC (Target Language Compiler - see the pdf attached).

To create a custom block is quite easy. Let us suppose you wish to build your own Simulink Library with custom blocks for a specific processor.

STEP1: Create a Simulink Library model

pastedImage_1.png

STEP2: Create a slblocks.m file in the same folder to describe various parameters of the library. This is how you make it visible in Simulink Standard Libraries list. Let us presume you want Simulink to display your collection of blocks as "CustomMBDT" library

% SLBLOCKS Defines the block library for a specific Toolbox or Blockset.
function blkStruct = slblocks

    blkStruct.Name = ['Custom MBDT' sprintf('\n')]; 
    blkStruct.OpenFcn = 'CustomMBDT';
    blkStruct.MaskDisplay = '';
    Browser(1).Library = 'CustomMBDT';
    Browser(1).Name    = 'CustomMBDT';
    Browser(1).IsFlat  = 0;
    Browser(1).Choice  = 1;
    blkStruct.Browser = Browser;
end

This is how it will look:

pastedImage_2.png

STEP3: Add a standard S-function Simulink block into your customMBDT.mdl file

pastedImage_3.png

Now comes the tricky parts: you need to create your own User Interface and Custom Code when this S-function block is used in a model.

STEP4: Create or associate a S-Function Level 2 file with your block. This will tell Simulink what are the inputs/outputs and other various parameters of your block.

pastedImage_4.png

E.g.: supposing i want to create a Simulink block that allow to read a GPIO. The block has no input ports but it has 1 output ports which i'll define as Boolean.

static void mdlInitializeSizes(SimStruct *S)
{
    /*------------------------------------
       Number of expected parameters
    --------------------------------------*/
    ssSetNumSFcnParams(S, 0);

    /*-----------------------------------------------------
       Parameter mismatch will be reported by Simulink
    --------------------------------------------------------*/
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        return;
    }

     /*-------------------------
     Set the input/Output ports
    ---------------------------*/
    ssSetNumInputPorts(S, 0);  /* Define 0 Inputs required */
    ssSetNumOutputPorts(S, 1);  /* Define 1 outputs required */
    ssSetOutputPortWidth(S, 0, 1);
    ssSetOutputPortDataType(S, 0, SS_BOOLEAN);

     /*---------------------------------------
        Set Work Sizes
    -------------------------------------------*/
    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);
    ssSetNumIWork(S, 0);

     /*------------------------------
       Set the number of states
    --------------------------------*/
    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);

    /*---------------------------------------
         Other OPtions for Code Generation
    ------------------------------------------*/
    ssSetOptions(S, SS_OPTION_USE_TLC_WITH_ACCELERATOR      |
                    SS_OPTION_SFUNCTION_INLINED_FOR_RTW     |
                    SS_OPTION_WORKS_WITH_CODE_REUSE         |
                    SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME |
                    SS_OPTION_RUNTIME_EXCEPTION_FREE_CODE   |
                    SS_OPTION_CAN_BE_CALLED_CONDITIONALLY   |
                    SS_OPTION_CALL_TERMINATE_ON_EXIT);
}

STEP5: create a MEX file from the c file used as S-Function. You can used the default LCC compiler to create the mex file: mex myfile.c

 

STEP6: attached a TLC file with the same name as the S-Function so that you can inject whatever code you wish when the block is used. It is very impfrtant that the TLC file has the same name as the S-function C file and also to contain the syntax as first line below.

%implements io_input "C"

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% function executes once per block type before code generation begins
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function BlockTypeSetup(block, system) void
    %%user include files
     %<LibAddToCommonIncludes("pins.h")>
%endfunction

Inside this file, you can have any function supported by the TLC (see the attachment). It allows you to add include files, inject code in various places in the Simulink generated files, etc.

E.g. If you need to call your custom driver implemented in C:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% function executes at each step
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function Outputs(block, system) Output
   %assign pinInfo = FEVAL("io_pin_info", block.Name)
   %with pinInfo.user_config
   /* GPI%<port>%<pin> signal update */
   %<LibBlockOutputSignal(0,"","",0)> = (PINS_DRV_ReadPins(%<pt>) >> %<pin>) & 0x01;
   %endwith
%endfunction

STEP7: build your own User Interface to allow custom code customization. Use right click on the block and select Edit Mask to implement your own user interface.

pastedImage_8.png

This will show something like this: 

pastedImage_9.png

STEP8. Save the block into the Simulink custom library model you have created at step 1 and you should have your own block that allows you to call your custom code into the Simulink environment.

pastedImage_10.png

This is the basic flow that allows you to call any custom code into a Simulink environment. You can find attached an example for this part.

In respect with the other questions:

I can see that the RappID is not available for this microcontroller.

We can't help you with that. You need to contact the S32Design Studio team via a NXP Official Support and ask for that support to be enabled.

I can also see that as a consequence, most likely FreeMaster would also not be available. 

FreeMASTER should not be an issue. The FreeMASTER embedded driver can be easily ported on any MPC platform. 

(C to simulink to C for this controller). We're willing to make the developmental efforts ourselves. But I am stuck with get this workflow clear in my head. Does it mean, that we need to develop our own tool to flash (from Simulink), to debug in SIL/PIL mode? 

The easiest way to do that, would be to start from an NXP existing toolbox like MPC574xP since it contains all the additional TLC files for e200 code generation. You will face some issues since not all the m-file are available for end-user but starting from MPC574xP should give you an idea about what you need to change or implement by yourself.

Hope this help!

Daniel

1,247 Views
saurabhkulkarni123
Contributor II

Hello @dumitru-daniel_ ,

We want to build custom block for s32k148 nxp controller. I follow the steps what you given before for MPC series but I'm not able to build it like it generate multiple errors. I don't know how to write TLC file and what kind of files required to design custom block. please suggest me complete steps for this.

0 Kudos

2,403 Views
erinctopdemir
Contributor I

Can someone share converted sample model for Matlab 2017a? 

0 Kudos

2,403 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi Erinc,

You can convert it by yourself. Just open the *.mld file as a text file and change the model version to a 8.9 and then save.

Library {
 Name "CustomMBDT"
 Version 9.2
 SavedCharacterEncoding "windows-1252"
 DiagnosticSuppressor "on"

Hope this helps!

Daniel