Custom code with S32 SDK integration in MBDT model for S32K144

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

Custom code with S32 SDK integration in MBDT model for S32K144

1,309 Views
manujagrawal
Contributor II

Hello,

I am trying to create "S-function builder"  blocks in the MBDT for S32K144 to call some of the S32_Platform_SDK functions to implement some of the functionalities which are not available yet with the Simulink blocks provided with the MBDT. I may also want to change how the peripherals are implemented by leveraging the SDK functions. 

However, I am facing the following issues:

  1. Since, the paths to SDK include and source folder has spaces in them; INC_PATH and SRC_PATH change (as in the attached before and after images) in the "Library/Object/Source files"  section of the "S-function builder" library dialog box when I build the model; hence, headers files are not found while building and an error is thrown.pastedImage_4.pngpastedImage_1.png
  2. Source code and Wrapper files are generated by the s-function builder just outside the folder in which the Embedded Coder generates the code, hence some macro declarations (which are found in the generated code) are not visible to the C file of the generated S-function.pastedImage_5.png
  3. The auto generated ProjectInfo.xml file for the generated code does not contain paths to the files generated by the S-function builder; thus, I am unable to find those files in the S32 design studio project when I import the generated code in it using the project xml file.

I don't have a clear understanding of the seamless way of linking and using SDK functions in the S-function-builder block.

To sum up what I am trying to implement; I would like to make a block which accepts input, process the input and take actions with the help S32 SDK and may also have an output port.

I would be very grateful for any help on this problem. 

Regards

Manuj Agrawal

dumitru-daniel.popa‌ constantinrazvan.chivu

S32sdk #mbd s32k14

Labels (1)
0 Kudos
3 Replies

992 Views
manujagrawal
Contributor II

Thank You constantinrazvan.chivu for you response.

As you have mentioned that it will not be possible to use S-Function builder blocks for implementing what I intend to; I am currently trying to do it with the alternative ways (using volatile variables) as you have suggested. However I would surely like to make custom blocks for our work; please help me with this. 

I have to to do it because the original blocks shipped with the MBDT do not support all of the functionalities and do not provide all the outputs we need. For example, in the I2C communication block I am unable to verify if a timeout occurred while receiving data; and many such things.

I am looking forward for your help with creating custom blocks. Please let me know the next steps for it.

Regards

Manuj Agrawal

0 Kudos

992 Views
constantinrazva
NXP Employee
NXP Employee

Hello manujagrawal‌,

Here is an overview of the steps you need to take in order to create your own custom Simulink library / blockset. Tell us if you have further questions on this matter.

Kind regards,

Razvan.

0 Kudos

992 Views
constantinrazva
NXP Employee
NXP Employee

Hello manujagrawal‌,

1.Since, the paths to SDK include and source folder has spaces in them; INC_PATH and SRC_PATH change (as in the attached before and after images) in the "Library/Object/Source files"  section of the "S-function builder" library dialog box when I build the model; hence, headers files are not found while building and an error is thrown.

A: You can add the paths even if they have spaces in them, using INC_PATH, etc. The only thing that I have to mention here is that they have to be on the same line - e.g.:

INC_PATH C:\ccr\mbdt_ccr\S32K\src\S32_Platform_SDK\plat form\drivers\inc

So this is a one-liner, and the next path has to be on the next line, etc.

2.Source code and Wrapper files are generated by the s-function builder just outside the folder in which the Embedded Coder generates the code, hence some macro declarations (which are found in the generated code) are not visible to the C file of the generated S-function.

A: When you click on Build inside the S-Function Builder, it generates the files (.c, .tlc, .mex, .m) inside the current folder. I'm not aware of an option from which you can select where to generate the code for your custom S-function. You can try and ask this on the mathworks forum, or you can copy the files generated (after you clicked on Build from the S-Function Builder block) to the model_name_mbd_rtw folder generated by our toolbox (manually), and then build your model.

Another thing I have to mention here is that I'm not aware of an option where you can enter compile options. For example, device_registers.h needs a define to be made (e.g: CPU_S32K144HFT0VLLT or CPU_S32K142, etc.).  Unfortunately sfunctionwizard is not officially supported (like mathworks staff member states here). 

3.The auto generated ProjectInfo.xml file for the generated code does not contain paths to the files generated by the S-function builder; thus, I am unable to find those files in the S32 design studio project when I import the generated code in it using the project xml file.

A: The ProjectInfo.xml indeed only takes files from inside the folder we generate with our toolbox. If you go for copying the files manually after generating them from the S-function builder, you can call 

mbd_s32k14_ds(gcs)

Note: call this from the folder in which you are building the model; do not enter inside the generated <modelName>_mbd_rtw folder.

Note: gcs should be the name of the model you have opened (get current Simulink system).

So if you take the following steps:

   - build the model

   - manually copy the files built by S-function builder

   - run mbd_s32k14_ds(gcs)

You should be able to import successfully the whole project (including your custom blocks) to S32 Design Studio.

As you can see, you'll be unable to do this exactly as you intend to, using S-function builder. The lack of compiler options and generation path settings is a notable drawback. I'll try and get an answer from Mathworks and get back to you on this matter.

Now lets talk alternatives:

First of all, the simplest way to add custom code is by using System blocks:

- System Start - inserts custom code inside of the Start function - function used for initialization, is ran only once, at the beginning

- System Outputs - inserts custom code inside of the Step function - function that is called in a loop - if it's inside the top model, it will be ran in the main loop (at whatever fixed step you have set); if it's inside a subsystem triggered by an ISR block, it will insert code to be ran on that interrupt.

On all of these blocks you have 3 zones:

   - Declaration

   - Execution

   - Exit

Basically Simulink coder uses these 3 'buffers' / zones for Start/Step functions. Declaration is the first, upper zone; Execution is the middle zone while Exit is last. So you can use any of these 2 blocks, with any of these 3 zones to insert custom code, as per your needs. The limitation with this approach is that you can't have inputs/outputs. You can declare data store memory blocks, setting the Storage class to Volatile, to make sure they will be visible and will have the same name as you set them in Simulink. Then you can just use those variables inside the custom code, and set them in Simulink. By doing this, you can have inputs/outputs to your custom code. 

Note: you should edit mbd_s32k14_user_copy_required_files.m script to copy whatever files you need for building your code.

Another option is to make a custom library with custom blocks, similar to the library we ship within our MBDT releases. This would be the best option as it provides the flexibility you are looking for, but for details on how to do this we should have some sort of meeting as there are more steps you'll need to be taking and there is the problem of IPs. I'll need to be checking this beforehand.

Hope this helps,

Razvan.

0 Kudos