Hi:
Since there is no SWT in the MBDT library, I configure the watchdog through the register r/w module, but what if I configure ISR for SWT because there is no related module in the library?
best wishes;
zhang.
Hello Zhang,
Can you tell me please, which MCU are you using?
Regards,
Marius
Hi Marius,
The MCU I use is MPC5744P, and the version of MBDT is 3.0.0.
Best Regards
Zhang
Hello @Yunhe ,
Well, in this case, you shall implement the interrupt using custom code.
First of all, you have to create a handler in a C file in which you can include the interrupt custom function. The following article might be a good tutorial on how to do that: https://community.nxp.com/t5/NXP-Model-Based-Design-Tools/How-to-use-your-own-C-code-in-our-Toolbox-...
Now you need to enable and assign a priority for the interrupt and assign a handler. For that you can use some of the functions defined in the interrupt_manager_MPC57xx.c file, which is automatically copied in the final project as default:
INT_SYS_EnableIRQ(SWT0_IRQn);
INT_SYS_SetPriority(SWT0_IRQn, priority);
INT_SYS_InstallHandler(SWT0_IRQn, C_function_handler, NULL);
One more note: the latest release of the MBDT for the MPC57xx is 3.2.0 so I strongly recommend you to update to the latest version.
Hope this helps,
Marius
Hi Marius,
Your answers and articles have benefited me a lot. Based on your article, I not only embed the SWT ISR as C code into Simulink, but also embed the SWT initialization code into Simulink based on the SWT code generated by the S32DS SDK, and It is working. But in this process, I encountered a problem, I hope you can answer it. Since SWT requires swt_hw_access.h, swt_driver.h and swt_driver.c, swt_hw_access.c, I added the corresponding path and file in MATLAB:
(If do not specify the path of the header file, then S32DS will report an error when compiling the code and the corresponding header file cannot be found. e.g. Cpu.h No such file or directory)
Add source file path:
Then execute the initialization function "init1" , in the function, initialize and configure the SWT ISR.
When I generated the code and compiled it in S32DS, some errors appeared. These errors were resolved when I dragged the corresponding source files (main.c, swt_driver.c, swt_hw_access.c) into the project:
And worked successfully.
But I think this is a bit troublesome, so I want to ask if there is a way to automatically add the corresponding source files to the generated code.
In addition, I want to talk about the C code of SWT initialization and interrupt configuration encapsulated as Simulink modules and added to the Simulink library. I would like to ask you if there are any corresponding posts on the forum.
Best Regards
Zhang
Hello @Yunhe,
In case you want to automatically copy inside the generated code some files, you can use our script mbd_mpc574x_user_copy_required_files. This is an m file that can be modified on your side to automatically copy some files when the code is generated.
You can access the swt driver files from our toolbox using the following line: fullfile(mbd_find_mpc_root, 'MPC_Platform_SDK', 'platform', 'drivers', 'src', 'swt')
Please let me know if the above approach worked on your side.
Hope this helps,
Marius
Hi Marius,
One problem when I use mbd_mpc574x_user_copy_required_files,That is to generate an error when generating the code:
I declared a function called copy1 directly below the SWT init function:
To pass compilation, I added coder.extrinsic('fullfile');But another error occurred:
So again I use the coder.extrinsic function:
Finally no error occurred,But there is no "swt_driver.c" I copied in the folder where the code is generated.
I think it may be due to the existence of the coder.extrinsic function in the process of generating the code, and the copy1 function is not run, the help document of MATLAB may explain this problem:
Actually, I may have misunderstood what you mean, you may mean to make me write a script that copies files by referring to script mbd_mpc574x_user_copy_required_files. Because the script that copies the files doesn't have to generate code, and I did:
In order to automatically run this script, I use it as a callback function:
According to the CallbackTracing function of Simulink, can see that the copy function does run:
But there is still no copied source file in the code generated file:
I think maybe the copy function needs to be executed after the generated code is done, but I don't know how to automate it
If I run it manually, copy the source file to the folder where the code is generated, and then import it into S32DS through the XML file, the copied source file cannot actually be imported into the project, so I have to run it manually and copy the source file to Under the directory of the S32DS project.
But I wonder if there is a way to make the script run automatically?
Best Regards
Zhang