Skip to content

Instantly share code, notes, and snippets.

@rikka0w0
Last active May 10, 2019 20:18
Show Gist options
  • Save rikka0w0/e4b4d8dbefc3d9edfba17a55303a2838 to your computer and use it in GitHub Desktop.
Save rikka0w0/e4b4d8dbefc3d9edfba17a55303a2838 to your computer and use it in GitHub Desktop.
How to run the Test_PIL_IIR_Filter demo of STM32-Mat Target 4.4.2

STM32-MAT Script Fixes:

  1. Comment line 256: fprintf('\n### Code Format : %s\n',buildOpts.codeFormat);
    buildOpts.codeFormat doesnt exist, the execution of this line throws an error and halt the code generation. I'm using Matlab 2019a, Windows 10 1803 x64, Stm32CubeMX 4.25 and STM32MatTarget_4.4.2_setup.exe
  2. Search for "extModeIocUsartUpdate" and add "ioc_info = ioc_parse(ioc_path);" in the next line.
    Note: this is a potential bug, the script creates a new ioc file if it cant find an existing one, but it doesnt read the new ioc file after creation.
  3. Comment below (around line 164):
            cset.set_param ('ExtMode','on');            
            cset.set_param ('ExtModeTransport',0); 
            cset.set_param('ExtModeMexFile','ext_serial_win32_comm');

to avoid:

The current "ExtModeMexFile" value, "ext_comm", does not match "ext_serial_win32_comm", which is the value expected by the current external mode transport layer, "stm32_serial". This transport layer is specified by the 'ExtModeTransport' value, "0". This error can occur when you change the way you register external mode transport layers in Simulink. Refresh "ExtModeMexFile" by reselecting the required external mode transport layer.

Then goto "Model Configuration Parameters" -> "Code Generation" -> Interface -> "Data Exchange Interface", make sure"External Mode" is checked, "Transport Layer" is "stm32_serial" and "MEX-file" is "ext_serial_win32_comm". Changing "Transport Layer" automatically changes "MEX-file". Looks like cset.set_param ('ExtModeTransport',0); is hard coded index for selecting "stm32_serial" but some how it breaks. Ref: https://community.st.com/s/question/0D50X00009XkX71SAF/failed-to-connecting-to-the-target-through-matlab-simulink

Eclipse Project Fixes:

  1. Project Properties -> C/C++ Build -> Settings -> Tab "Tool Setting" -> Node "MCU GCC Compiler" -> Includes:
    Fix all "" to "
  2. Add (as Link) to the project:
    ${PARENT-4-PROJECT_LOC}\slprj\stm32\IIR_Filter_int32\coderassumptions\IIR_Filter_int32_ca.c
    C:\Program Files\MATLAB\R2019a\toolbox\rtw\targets\pil\c\coder_assumptions_hwimpl.c
    C:\Program Files\MATLAB\R2019a\toolbox\rtw\targets\pil\c\coder_assumptions_flt.c
    
  3. Project Properties -> C/C++ Build -> Settings -> Tab "Tool Setting" -> Node "MCU GCC Compiler" -> Preprocessor:
    Define a macro: CA_CHECK_DAZ_ENABLED

Notes:
Use Normal mode rather than PIL or external Mode!
The STM32-Mat should be a out-of-box experience, especially for the demos! Why do I have to spend 2 days figuring out how to even run the demo?! ST, you should really test your demos on the different versions of Matlab before you release them!

rtiostream.h: (Sometimes the code generator doesnt copy this file?!)

/*
 * Copyright 2007-2012 The MathWorks, Inc.
 *
 * File: rtiostream.h     
 *
 * Abstract:
 *  Function prototypes and defines for rtIOStream API.
 */

#ifndef RTIOSTREAM_H
#define RTIOSTREAM_H

#include <stddef.h>

#define RTIOSTREAM_ERROR (-1)
#define RTIOSTREAM_NO_ERROR (0)

/* Note: if the functions declared in this file should be compiled into a shared
 * library (e.g. a .dll file on Windows), you must ensure that the functions are
 * externally visible. The procedure to achieve this depends on the compiler and
 * linker you are using. For example, on Windows, you may need to provide an
 * exports definition .def file that lists all of the functions to be
 * exported; see ./rtiostream/rtiostream_pc.def for a suitable .def file.
 */

#ifndef RTIOSTREAMAPI
#define RTIOSTREAMAPI 
#endif 

RTIOSTREAMAPI int rtIOStreamOpen(
    int    argc,
    void * argv[]
);

RTIOSTREAMAPI int rtIOStreamSend(
    int          streamID,
    const void * src, 
    size_t       size,
    size_t     * sizeSent
    );

RTIOSTREAMAPI int rtIOStreamRecv(
    int      streamID,
    void   * dst, 
    size_t   size,
    size_t * sizeRecvd
    );

RTIOSTREAMAPI int rtIOStreamClose(
    int streamID
    );


#endif /* #ifndef RTIOSTREAM_H */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment