How to use custom code in MBDT 1.4.0

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to use custom code in MBDT 1.4.0

2,762 次查看
SuperBeginner
Contributor III

Dear NXP,

I'm trying out some basic software for an ADC driver to call the functionality of the S32K312.

I refer to the following:

However, it didn't go as smoothly as expected.

I don't know how to create a custom function from the driver.

I think I need some help. 

Could you provide examples to help me, please?

 

Thanks in advance

 

0 项奖励
回复
11 回复数

2,744 次查看
dragostoma
NXP Employee
NXP Employee

Hi, @SuperBeginner,

Did you check the articles and examples I mentioned in the previous thread? Because in the post I'm talking about there are specified Simulink models that use custom code and that you can use as a reference in your application? As well as the threads where the use of custom code is explained step by step.

What problems did you encounter when trying to use the custom code?

Let us know if you managed to use custom code in your application.

 

Best regards,

Dragos

 

0 项奖励
回复

2,662 次查看
SuperBeginner
Contributor III

Dear @dragostoma ,

I tried following the tutorial you provided to configure the custom code.

https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/SENT-Protocol-Support-in-S32K3-MBDT/m-p...

It works fine when I use model headers and system initialization for DIO configuration interrupts.

SuperBeginner_0-1727675281378.png

 

But unfortunately, it is not convenient for people to use BLOCK to view.

I can successfully build the program to the S32K312EVB-Q172, but my interrupt function is not working.

ADC_Config.PNG

ADC_Config_function.PNG

I think this must be a configuration error caused by my unfamiliarity.

I upload my ADC config file "1_SimulinkCoder_ADC", can you help me to solve this problem?

 

BTW, I can use the coder.ceval with Matlab function to call my own c code externally.

However, if I want to call the driver code generated by the S32CT, do I need to include all ADC related the .c and .h file in Matlab function?

For example, if I want to use the adc function, do I still need to call the ADC function in the matlab function like this?

 

if (coder.target('RTW'))
    coder.cinclude('Adc.h');
    coder.updateBuildInfo('addSourceFiles', 'Adc.c');
    %% Call ADC function
    coder.ceval(Adc_SetupResultBuffer(Adc1Group_0, Adc1Group0_ResultBuffer));
end

 

Or do I just need to call the adc driver function like this

if (coder.target('RTW'))
    %% Call ADC function
    coder.ceval(Adc_SetupResultBuffer(Adc1Group_0, Adc1Group0_ResultBuffer));
end

 

In addition, I also tried to use C caller and S-Function for configuration on Simulink, but neither of them could realize the ADC configuration.

Can I use them for development?

I saw these two articles mentioned methods, but I'm not sure if they can be used to call the ADC Driver.

https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/C-code-integration/td-p/1640618

https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/Driver-integration-using-C-Caller-or-C-...

 

Thanks in advance

0 项奖励
回复

2,633 次查看
SuperBeginner
Contributor III
BTW, My goal is to change the ADC value by changing the variable resistor (PTA11) on the S32K312EVB-Q172.

Thanks
0 项奖励
回复

2,596 次查看
SuperBeginner
Contributor III

Dear @dragostoma ,

Do you have any suggestions for solutions regarding ADC configuration?

Thanks

0 项奖励
回复

2,579 次查看
dragostoma
NXP Employee
NXP Employee

Hi, @SuperBeginner,

First of all, why do you want to use custom code to use the ADC functionality, because these functions are already implemented in the ADC block. Thus you can already use the ADC models that are already in the toolbox, the models that have the prefix s32k3xx are generally valid for several hardware parts, including S32K312.

So if, for example, in the s32k3xx_adc_single_read_s32ct model you set the hardware part S32K312-Q172, you can use the functionality mentioned in your application, without having to use custom code. The use of custom code is recommended when you want to use drivers that are not implemented in the Simulink library blocks.

In this way, you reduce the potential errors that may arise from improper use of custom code and your application may not meet your expectations.

I recommend that you initially use the already existing models, together with going through the help of the models and to learn more about the functionalities you want to use in the Reference Manual.

Let us know how it works.

 

Best regards,

Dragos

 

0 项奖励
回复

2,549 次查看
SuperBeginner
Contributor III

Dear @dragostoma ,

When I use the Example project - s32k3xx_adc_single_read_s32ct, it works fine.

The ADC value can change with the resistor on my EVB. I can also see value changes in FreeMaster.

As for the reason why I will use custom code to develop the ADC function, it is because I think it is a relatively uncomplicated function on EVB.

This may allow me to become familiar with how to use Custom Code to call programs from S32CT.

Because I need to implement many functions that are currently not supported by MBDT, such as DMA, WDG, RTE, SENT, RTOS, etc., and even I2C (MBDT 1.4.0).

As for why I didn’t choose DIO for learning, it’s because I can easily use Model Header and System Initialzation to achieve the functions I need.

I think this is because it is too simple, so I tested it with ADC.

I checked some articles: such as the implementation of WDG and RTOS on MBDT.

At present, it is recommended to use Model Header and System initialization to implement it.

There is no example project provided yet, so I think I need to understand and be familiar with how to call the program generated by S32CT.

This allows me to use the relevant functions correctly.

If I can't even call the adc function correctly, I think it will be difficult for me to conduct follow-up research at all.

All that said, this is why I don't use the adc example project.

I'm very sorry for any inconvenience caused to you.

I can also follow your suggestion and call the program from s32ct through the Model Header and System Initialization.

But I think I still need to understand why I can't implement the adc function through the Model Header and System Initialization now.

To simplify the problem, I only reserved the ADC_POT0 channel to read the ADC with interrupt.

In my opinion it should reproduce the same results as Example Project - s32k3xx_adc_single_read_s32ct.

Could you tell me reason, please?

I think this is a great help to me.

Thanks

0 项奖励
回复

2,527 次查看
SuperBeginner
Contributor III

Dear @dragostoma ,

I looked at the example project - "s32k3xx_adc_single_read_s32ct" c code to figure out why I couldn't use the custom code correctly.

Thank you for your suggestion.

I'm attaching my configuration here, hoping it can help anyone in need.

ADC_Config.PNG

Thanks

 

 

0 项奖励
回复

2,502 次查看
SuperBeginner
Contributor III

Dear @dragostoma ,

Sorry, please forgive me for interrupting again.

I have a question about custom code with Matlab function (coder.ceval).

In order to facilitate people's viewing, I want to implement ADC function configuration on Matlab Function.

But I don't know how I can call "ADC1Group0" configured under S32CT.

If using Model Header and System Initialize Function, I always just enter the name of Adc directly, such as "Adc1Group_0".

So how should I do it on Matlab Function to set ADC Group?

SuperBeginner_0-1728028495905.png

 

Thanks in advance

0 项奖励
回复

2,437 次查看
SuperBeginner
Contributor III

Dear @dragostoma@Irina_Costachescu@CristinaB ,@Adrian_Gherca ,

Could you please help explain how I can call variables from S32CT through Matlab function (coder.ceval)?

For example,  I just enter "Adc_EnableGroupNotification(Adc1Group_0)" in System Initialize Block (Simulink Coder) that I can call custom code to enable Adc1Group_0.

So what should I do if I want to use Matlab function to access Adc1Group_0?

Can I visually access Adc1Group_0 through a block like data store memory?

Please forgive me for tagging every engineer who has helped me previously, I really want to know the answer.

Thanks in advance

0 项奖励
回复

2,432 次查看
Irina_Costachescu
NXP Employee
NXP Employee

Hi @SuperBeginner 

Please check the following article to find out more information on how to use custom C code inside your Simulink application. https://community.nxp.com/t5/NXP-Model-Based-Design-Tools/How-to-use-your-own-C-code-in-our-Toolbox-...

The information in this article should be helpful for achieving your use case.

Regards,

Irina

0 项奖励
回复

2,423 次查看
SuperBeginner
Contributor III

Dear @Irina_Costachescu ,

Thank you for your reply.

I have viewed the website you provided before. It is really helpful for calling my own c code and I also can call it successfully.

But my question is how to configure variables from S32CT in a visual way, like Adc1Group_0?

Neither the website nor the program mentions any way to visually configure variables from S32CT/EB_Tresos.

Could you provide any additional suggestions, please?

Thanks

0 项奖励
回复