In this tutorial I'll describe how to generate code for an embedded ARM processor.
Our goal is:
Generate C code and call the simulink function from the main software.
I'm using Matlab 2013a x64 and Eclipse Juno, both in Windows 7 x64 environment.
My system is not modified in any major way.
1) Creating the Simulink model
This should be easy for you, if you are already trying to use the automated C/C++ coder. Generate whatever you want. This is my very simple system, a state machine:
2) Configuring the model
Open Model Configuration Parameters (Ctrl+E)
Your model must be (I'm not sure about this, but creating variable-step and continuously solved simulink models is just one more stick in your ass) discrete, with a fixed step solver.
There is at least a million ways to generate C code from simulink, this is I've used:
In the "Hardware Implementation" submenu change "Device Vendor" to "ARM Compatible" and the "Device type" to "ARM Cortex".
In the "Code Generation" submenu change the "System target file" to ert.tlc (This will invoke the embedded coder).
In the "Report" sub-submenu you shoult tick "Create code generation report" because that's always good, but it's not necessary.
In the "Interface" sub-submenu change the "Code Rerplacement Library" to GCC ARM Cortex-M3.
3) Generate the code
Right click on the subsystem you want to build. C/C++ code --> Build Subsystem
Be careful to generate only the controller, not the whole model. Remember, you only need the code for the subsystem that controls the environment you've simulated in MATLAB.
4) Create the Eclipse console project.
Create an empty ARM Cross Traget Application project with Sourcery code compiler (How to do this? I'll do a tutorial on this later, in the meantime google it or learn to speak Hungarian and read it
here).
Add a folder where you'll put the source files. Copy and paste the files generated by Simulink here. Build. Be happy.
5) Flash the built system to your STM32F4-Discovery card.
It doesn't work for me yet, but the other 4 steps are confirmed as working. Of course you'll have to add a few lines to the ert_main.c (don't change anything in the rest of them).