cancel
Showing results for 
Search instead for 
Did you mean: 

Integrate Motor driver c-code to simulink

tired
Associate II

hi,

i'm currently working on a project where i want to control a stepper motor via the STM32F446RE board and X-NUCLEO-IHM-03A1 expansion board.

To benefit from the X-CUBE-SPN3 software package, i would like to integrate the external c-code to matlab/simulink and use it in my model with the ccaller-block.

At this moment i am able to include the necessary .c and .h files, but cannot build the code.

I uploaded the occuring error.

Thanks for your help.

Best Regards

Tom

12 REPLIES 12
Amigo
Associate III

To my knowledge, these libraries are designed to work very tightly with the various Timers, which have to be configured in a certain way. Did you configure all the timers and the IO for the communication in the model? I cannot see from the screenshots if you did. Moreover, these libraries may also set up a few MACROs, one of which is the target, which leads you to the error message you get. You may have to define the macro STM32F446RE somewhere in your MATLAB project, such that it can resolve the inclusiong of the right header file within Simulink, before even getting to the generated project, where these macros would be defined.

tired
Associate II

Hi,

Thank you for replying.

i've already tried to define those macros in matlab.

This works just fine until the error message shown in the following screenshot.

No i haven't configured any IO's or timers since i wanted to see if i'm able to generate the code from simulink at first.

Is there perhaps any way to deactivate those macros?0693W000001rDzWQAU.jpg

Amigo
Associate III

It certainly has something to do with the fact that Simulink does parse the code in the absence of a full project in an IDE. The first of the error messages, caused by stm32f4xx.h in line 175 was because there was no target MCU defined, which leads to an error. The latest error is caused by the same issue, but this time with the issue of the target compiler not being defined.

For the first error code needs to define the macro STM32F446xx in order to parse correctly, and in the second case the macro associated with the compiler you use.

I would personally have a look at the header file dependency in the libraries from ST, identify the highest level header, i.e. the header file that is included in all the other files, and change it to add

#define STM32F446xx /* file st32f4xx.h line 157 now parsed*/

#define __GNUC__ /* or whatever tollchain you plan to use */

That should add the required information to parse the files correctly, and if they match what the toolchain would do there would be no issues.

tired
Associate II

Found a fitting .h file which seems to solve the second error.

Now i'm getting this one.

(sorry i'm not familiar with c code)

Btw: I'm using SW4STM32 as my toolchain.0693W000001rEGhQAM.jpg0693W000001rEGcQAM.jpg

Amigo
Associate III

I am afraid that you may have run into C code which uses C language extensions not recognised by Simulink. It says in the begining of the second screenshot—which may actually be the first—that you have an option to disable "Import Custom Code", which may be defined precisely for this reason. Might be worth a try.

Laurent Ca...
Lead II

Dear @tired​ 

Did the @Amigo​ 's answer solve your problem?

Best regards

Laurent Ca...

tired
Associate II

Hello,

no i'm afraid it certainly didn't work.

After i disabled "Import Custom Code" i wasn't able to use any of the c code in my project which defeats the purpose of this thread.

I hope that you have any further suggestions, to help with my problem.

Best regards

Tom

Laurent Ca...
Lead II

Dear @tired​ 

Did you checked your .h header calls tree?

According to your error logs, I am not sure than "packed" and /or"T_INT32" are recognized where used for the first time.

Best regards

Laurent Ca...

tired
Associate II

I'm sorry i don't know where to check.

Also i just copied the .c and .h files from the STM32CubeExpansion SPN3 Software, so i guess there shouldn't be any definitions missing.

Best regards

Tom