2. External Mode - LED, PWM, ADC
- Matlab R2017 x64 for Windows
- STM32MatTarget_4.4.2_setup.exe https://github.com/freshhope/STM32_PIL_Example_Simulink/releases/download/v0.1/STM32MatTarget_4.4.2_setup.exe
- Keil uVision5
- STM32CubeMX
- Any STM32 hardware board
- Install all the required packages
- Set matlab path, add with sub folders of STM32MatTarget installation folder
- Click "Save" button, from now on STM32MatTarget is fully functional
- Set current path of Matlab, such as "\Filter\work"
- Open Test_PIL_IIR_Filter.slx from repository
- solver
- data import
- data import is used for test data inject, when the slx is loaded into memory, Matlab workspace automatically loads the input file: testdata.txt
- the testdata.txt is automatically loaded by callback of top model
- hardware implementation, stm32.tlc is used
- code generation page
- code interface page
- STM32 options
- STM32 project files
- Check the configuration of upper reference model, which is run in PIL mode
- Check the configuration of lower reference model, which is run in normal mode, note, the two reference model point to the same file "IIR_Filter_int32.slx", the only difference is "Simulation Mode" of each block parameters
- finally, the test block is ready to run
- Click the run button on the top model, the compilation begins
- NMake error may appear complaining file 'IIR_Filter_int32.mk' not found
- A quick fix to the error maybe, first find this make file location, and add this path to Matlab invoke VS path:
setenv('VSCMD_START_DIR','slprj\sim\IIR_Filter_int32')
- Click the run button on the top model, this time compilation will complete without errors
- The next step is to select COM port, such as COM3, 115200, n, 8, 1
- Selection of MCU, such as STM32F407VETx running at 168MHz
- Selection of UART port of MCU, in the current configuration, USART1 is used
- Until now the code generation is complete for MCU
- Selection of toolchain, in this example Keil V5 is used
- Until now, Simulink is waiting for firmware ready
- Meanwhile, STM32CubeMX is invoked with configuration already done by Simulink, if ST-Link V2 is used, the "SYS.Debug" property should be properly assigned to "Serial Wire", otherwise the MCU cannot be programmed in the future
- in clock configuration, set HCLK to 168 MHz for STM32F407VETx, note: different clock speed is assigned here for different MCU type
- in STM32CubeMX project settings, set default firmware location to a specified path, or just download as prompted
- Generate code, and then open the generated project in Keil
- Build the firmware in Keil
- Configure ST-Link V2
- Load program, now the firmware is running
- Click "Continue" button on Simulink, PIL is running
- Profile results