Skip to content

freshhope/STM32_PIL_Example_Simulink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STM32 PIL (Processor in the loop) Example

For other sub examples, please visit:

1. Generic - Toggle LED

2. External Mode - LED, PWM, ADC

Environment

Configuration of Matlab

  1. Install all the required packages
  2. Set matlab path, add with sub folders of STM32MatTarget installation folder set path
  3. Click "Save" button, from now on STM32MatTarget is fully functional
  4. Set current path of Matlab, such as "\Filter\work"
  5. Open Test_PIL_IIR_Filter.slx from repository

Configuration of top model

  • solver solver
  • data import 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 data import
  • the testdata.txt is automatically loaded by callback of top model data import
  • hardware implementation, stm32.tlc is used data import
  • code generation page data import
  • code interface page data import
  • STM32 options data import
  • STM32 project files data import
  • Check the configuration of upper reference model, which is run in PIL mode data import
  • 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 data import
  • finally, the test block is ready to run data import

Code Generation for PIL

  1. Click the run button on the top model, the compilation begins
  2. NMake error may appear complaining file 'IIR_Filter_int32.mk' not found data import
  3. 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')

  1. Click the run button on the top model, this time compilation will complete without errors
  2. The next step is to select COM port, such as COM3, 115200, n, 8, 1 data import
  3. Selection of MCU, such as STM32F407VETx running at 168MHz data import
  4. Selection of UART port of MCU, in the current configuration, USART1 is used data import
  5. Until now the code generation is complete for MCU data import data import

Prepare hardware for PIL

  1. Selection of toolchain, in this example Keil V5 is used data import
  2. Until now, Simulink is waiting for firmware ready data import
  3. 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 data import
  4. in clock configuration, set HCLK to 168 MHz for STM32F407VETx, note: different clock speed is assigned here for different MCU type data import
  5. in STM32CubeMX project settings, set default firmware location to a specified path, or just download as prompted data import
  6. Generate code, and then open the generated project in Keil data import
  7. Build the firmware in Keil data import
  8. Configure ST-Link V2 data import data import data import
  9. Load program, now the firmware is running data import
  10. Click "Continue" button on Simulink, PIL is running data import
  11. Profile results data import