Симуляция генерации синусоидального шим и управление по модбас

note:
- модбас не моделируется,  в s-function просто передаются константы режимов.
- лишние файлы убраны в outdate.
- два канала одной фазы переключаются немного криво: на один такт симуляции проскакивает высокий уровень предыдущего канала и только потом включается текущий канал
This commit is contained in:
alexey
2024-08-21 12:58:52 +03:00
parent fcc3e72824
commit 0958cb80c7
682 changed files with 871653 additions and 0 deletions

169
MCU_Wrapper/MCU.c Normal file
View File

@@ -0,0 +1,169 @@
#define S_FUNCTION_NAME MCU
#define S_FUNCTION_LEVEL 2
#include "mcu_wrapper_conf.h"
double SIM_Sample_Time;
#define MDL_UPDATE
/* Function: mdlUpdate ====================================================
* Abstract:
* This function is called once for every major integration time step.
* Discrete states are typically updated here, but this function is useful
* for performing any tasks that should only take place once per
* integration step.
*/
static void mdlUpdate(SimStruct *S, int_T tid)
{
// get time of simulation
time_T TIME = ssGetT(S);
//---------------SIMULATE MCU---------------
MCU_Step_Simulation(S, TIME); // SIMULATE MCU
//------------------------------------------
}//end mdlUpdate
/* Function: mdlOutputs ===================================================
* Abstract:
* In this function, you compute the outputs of your S-function
* block. Generally outputs are placed in the output vector(s),
* ssGetOutputPortSignal.
*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
SIM_writeOutputs(S);
}//end mdlOutputs
#define MDL_CHECK_PARAMETERS /* Change to #undef to remove function */
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
static void mdlCheckParameters(SimStruct *S)
{
int i;
// Проверяем и принимаем параметры и разрешаем или запрещаем их менять
// в процессе моделирования
for (i=0; i<1; i++)
{
// Input parameter must be scalar or vector of type double
if (!mxIsDouble(ssGetSFcnParam(S,i)) || mxIsComplex(ssGetSFcnParam(S,i)) ||
mxIsEmpty(ssGetSFcnParam(S,i)))
{
ssSetErrorStatus(S,"Input parameter must be of type double");
return;
}
// Параметр м.б. только скаляром, вектором или матрицей
if (mxGetNumberOfDimensions(ssGetSFcnParam(S,i)) > 2)
{
ssSetErrorStatus(S,"Параметр м.б. только скаляром, вектором или матрицей");
return;
}
// sim_dt = mxGetPr(ssGetSFcnParam(S,0))[0];
// Parameter not tunable
// ssSetSFcnParamTunable(S, i, SS_PRM_NOT_TUNABLE);
// Parameter tunable (we must create a corresponding run-time parameter)
ssSetSFcnParamTunable(S, i, SS_PRM_TUNABLE);
// Parameter tunable only during simulation
// ssSetSFcnParamTunable(S, i, SS_PRM_SIM_ONLY_TUNABLE);
}//for (i=0; i<NPARAMS; i++)
}//end mdlCheckParameters
#endif //MDL_CHECK_PARAMETERS
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 1);
// Кол-во ожидаемых и фактических параметров должно совпадать
if(ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S))
{
// Проверяем и принимаем параметры
mdlCheckParameters(S);
}
else
{
return;// Parameter mismatch will be reported by Simulink
}
// set up discrete states
ssSetNumContStates(S, 0); // number of continuous states
ssSetNumDiscStates(S, DISC_STATES_WIDTH); // number of discrete states
// set up input port
if (!ssSetNumInputPorts(S, 1)) return;
for (int i = 0; i < IN_PORT_NUMB; i++)
ssSetInputPortWidth(S, i, IN_PORT_WIDTH);
ssSetInputPortDirectFeedThrough(S, 0, 0);
ssSetInputPortRequiredContiguous(S, 0, 1); // direct input signal access
// set up output port
if (!ssSetNumOutputPorts(S, OUT_PORT_NUMB)) return;
for (int i = 0; i < OUT_PORT_NUMB; i++)
ssSetOutputPortWidth(S, i, OUT_PORT_WIDTH);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork( S, 5); // number of real work vector elements
ssSetNumIWork( S, 5); // number of integer work vector elements
ssSetNumPWork( S, 0); // number of pointer work vector elements
ssSetNumModes( S, 0); // number of mode work vector elements
ssSetNumNonsampledZCs( S, 0); // number of nonsampled zero crossings
ssSetRuntimeThreadSafetyCompliance(S, RUNTIME_THREAD_SAFETY_COMPLIANCE_TRUE);
/* Take care when specifying exception free code - see sfuntmpl.doc */
ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
}
#define MDL_START /* Change to #undef to remove function */
#if defined(MDL_START)
/* Function: mdlStart =====================================================
* Abstract:
* This function is called once at start of model execution. If you
* have states that should be initialized once, this is the place
* to do it.
*/
static void mdlStart(SimStruct *S)
{
SIM_Initialize_Simulation();
}
#endif // MDL_START
/* Function: mdlInitializeSampleTimes =========================================
* Abstract:
* This function is used to specify the sample time(s) for your
* S-function. You must register the same number of sample times as
* specified in ssSetNumSampleTimes.
*/
static void mdlInitializeSampleTimes(SimStruct *S)
{
// Шаг дискретизации
SIM_Sample_Time = mxGetPr(ssGetSFcnParam(S,NPARAMS-1))[0];
// Register one pair for each sample time
ssSetSampleTime(S, 0, SIM_Sample_Time);
ssSetOffsetTime(S, 0, 0.0);
}
/* Function: mdlTerminate =====================================================
* Abstract:
* In this function, you should perform any actions that are necessary
* at the termination of a simulation. For example, if memory was
* allocated in mdlStart, this is the place to free it.
*/
static void mdlTerminate(SimStruct *S)
{
hmcu.MCU_Stop = 1;
ResumeThread(hmcu.hMCUThread);
WaitForSingleObject(hmcu.hMCUThread, 10000);
SIM_deInitialize_Simulation();
mexUnlock();
}
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a
MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration
function */
#endif

154
MCU_Wrapper/mcu_wrapper.c Normal file
View File

@@ -0,0 +1,154 @@
/**************************************************************************
Äàííûé ôàéë ñîäåðæèò ôóíêöèè äëÿ ñèìóëÿöèè ÌÊ â Simulink (S-Function).
**************************************************************************/
#include "mcu_wrapper_conf.h"
SIM__MCUHandleTypeDef hmcu; // äëÿ óïðàâëåíèÿ êîíòåêñòîì ïðîãðàììû ÌÊ
double SystemClockDouble = 0; // äëÿ ñèìóëÿöèè ñèñòåìíûõ òèêîâ, ïðîêà ïðîñòî ïî ïðèêîëó
double SystemClock_step = 0; // äëÿ ñèìóëÿöèè ñèñòåìíûõ òèêîâ, ïðîêà ïðîñòî ïî ïðèêîëó
uint64_t SystemClock; // äëÿ ñèìóëÿöèè ñèñòåìíûõ òèêîâ, ïðîêà ïðîñòî ïî ïðèêîëó
//-------------------------------------------------------------//
//-----------------CONTROLLER SIMULATE FUNCTIONS---------------//
/** THREAD FOR MCU APP */
/**
* @brief Thread that run MCU code.
* @note Ïîòîê, êîòîðûé çàïóñêàåò è âûïîëíÿåò êîä ÌÊ.
*/
extern int main(void); // extern while from main.c
unsigned __stdcall MCU_App_Thread(void) {
main(); // run MCU code
return 0; // end thread
// note: this return will reached only at the end of simulation, when all whiles will be skipped due to @ref sim_while
}
/** SIMULATE MCU FOR ONE SIMULATION STEP */
/**
* @brief Read from simulink S-Block Inputs and write to MCU I/O ports.
* @param time - current time of simulation (in second).
* @note Âûçûâàåò ãëàâíóþ ôóíêöèþ main èç ïîëüçîâàòåëüñêîãî êîäà è óïðàâëÿåò å¸ õîäîì:
* Ïðåðûâàåò å¸, åñëè îíà ïîïàëà â áåñêîíå÷íûé while, ñèìóëèðóåò ïåðèôåðèþ
* è âîçâðàùàåò â òî÷êó îñòàíîâêè íà ñëåäóþùåì øàãå.
*/
void MCU_Step_Simulation(SimStruct* S, time_T time)
{
MCU_readInputs(S); // ñ÷èòûâàíèå ïîðòîâ
MCU_Periph_Simulation(); // simulate peripheral
ResumeThread(hmcu.hMCUThread);
for (int i = DEKSTOP_CYCLES_FOR_MCU_APP; i > 0; i--)
{
}
SuspendThread(hmcu.hMCUThread);
MCU_writeOutputs(S); // çàïèñü ïîðòîâ (ïî ôàêòó çàïèñü â áóôåð. çàïèñü â ïîðòû â mdlOutputs)
}
/** SIMULATE MCU PERIPHERAL */
/**
* @brief Simulate peripheral of MCU
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé ñèìóëèðóåò ðàáîòó ïåðèôåðèè ÌÊ.
*/
void MCU_Periph_Simulation(void)
{
SystemClockDouble += SystemClock_step; // emulate core clock
SystemClock = SystemClockDouble;
uwTick = SystemClock / (SystemCoreClock / 1000);
Simulate_TIMs();
}
/** READ INPUTS S-FUNCTION TO MCU REGS */
/**
* @brief Read from simulink S-Block Inputs and write to MCU I/O ports.
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé çàïèñûâàåò â ïîðòû ââîäà-âûâîäà èç disc.
*/
void MCU_readInputs(SimStruct* S)
{
/* Get S-Function inputs */
real_T* IN = ssGetInputPortRealSignal(S, 0);
SFUNC_to_GPIO(IN);
}
/** WRITE OUTPUTS BUFFER S-FUNCTION FROM MCU REGS*/
/**
* @brief Read from MCU I/O ports and write to simulink S-Block Outputs Buffer.
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé çàïèñûâàåò â disc ïîðòû ââîäà-âûâîäà.
*/
void MCU_writeOutputs(SimStruct* S)
{
/* Get S-Function descrete array */
real_T* DISC = ssGetDiscStates(S);
GPIO_to_SFUNC(DISC);
}
//-----------------CONTROLLER SIMULATE FUNCTIONS---------------//
//-------------------------------------------------------------//
//-------------------------------------------------------------//
//----------------------SIMULINK FUNCTIONS---------------------//
/** WRITE OUTPUTS OF S-BLOCK */
/**
* @brief Write S-Function Output ports to inputs.
* @param disc - discrete array of S-Function. Outputs would be written from disc.
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé çàïèñûâàåò âûõîäû S-Function.
*/
void SIM_writeOutputs(SimStruct* S)
{
real_T* GPIO;
real_T* DISC = ssGetDiscStates(S);
//-------------WRITTING GPIOS---------------
for (int j = 0; j < PORT_NUMB; j++)
{
GPIO = ssGetOutputPortRealSignal(S, j);
for (int i = 0; i < PORT_WIDTH; i++)
{
GPIO[i] = DISC[j * PORT_WIDTH + i];
DISC[j * PORT_WIDTH + i] = 0;
}
}
//------------------------------------------
}
/** MCU WRAPPER DEINITIALIZATION */
/**
* @brief Initialize structures and variables for simulating MCU.
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé áóäåò íàñòðàèâàòü âñå ñòðóêòóðû äëÿ ñèìóëÿöèè.
*/
void SIM_Initialize_Simulation(void)
{
/* user initialization */
Initialize_Periph_Sim();
/* wrapper initialization */
SystemClock_step = SystemCoreClock * SIM_Sample_Time; // set system clock step
// èíèöèàëèçàöèÿ ïîòîêà, êîòîðûé áóäåò âûïîëíÿòü êîä ÌÊ
hmcu.hMCUThread = (HANDLE)CreateThread(NULL, 0, MCU_App_Thread, 0, CREATE_SUSPENDED, &hmcu.idMCUThread);
}
/** MCU WRAPPER DEINITIALIZATION */
/**
* @brief Deinitialize structures and variables for simulating MCU.
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé áóäåò î÷èùàòü âñå ñòðóêòóðû ïîñëå îêîí÷àíèÿ ñèìóëÿöèè.
*/
void SIM_deInitialize_Simulation(void)
{
// simulate structures of peripheral deinitialization
deInitialize_Periph_Sim();
// mcu peripheral memory deinitialization
deInitialize_MCU();
}
//-------------------------------------------------------------//
////-----------INIT WRAPPER-----------
//if (hmcu.MCU_Start) // åñëè íàäî ïîëó÷òü óêàçàòåëü íà "íà÷àëî" ñòåêà
//{ // ñáðîñ ôëàøà, ÷òîáû ñþäà áîëüøå íå ïîïàäàòü
// hmcu.MCU_Start = 0;
// // èíèöèàëèçàöèÿ ïîòîêà, êîòîðûé áóäåò âûïîëíÿòü êîä ÌÊ
// hmcu.hMCUThread = (HANDLE)_beginthreadex(NULL, 0, MCU_App_Thread, 0, 0x00000004, &hmcu.idMCUThread); /* 0x00000004 - CREATE_SUSPENDED */
//}
////----------------------------------

View File

@@ -0,0 +1,147 @@
/**************************************************************************
Ãëàâíûé çàãîëîâî÷íûé ôàéë äëÿ ìàòëàáà. Âêëþ÷àåò äåéôàéíû äëÿ S-Function,
îáúÿâëÿåò áàçîâûå ôóíêöèè äëÿ ñèìóëÿöèè ÌÊ è ïîäêëþ÷àåò áàçîâûå áèáëèîòåêè:
äëÿ ñèìóëÿöèè "stm32fxxx_matlab_conf.h"
äëÿ S-Function "simstruc.h"
äëÿ ïîòîêîâ <process.h>
**************************************************************************/
#ifndef _CONTROLLER_H_
#define _CONTROLLER_H_
// Includes
#include "stm32f4xx_matlab_conf.h" // For stm simulate functions
#include "simstruc.h" // For S-Function variables
#include <process.h> // For threads
// Parametrs of MCU simulator
#define CREATE_SUSPENDED 0x00000004 // define from WinBase.h
// We dont wanna include "Windows.h" or smth like this, because a lot of redefine errors appear.
#define DEKSTOP_CYCLES_FOR_MCU_APP 0xFFFF // number of for() cycles after which MCU thread would be suspended
#define PORT_WIDTH 16 // width of one port
#define PORT_NUMB 3 // amount of ports
// Parameters of S_Function
#define NPARAMS 1 // number of input parametrs (only Ts)
#define IN_PORT_WIDTH (8) // width of input ports
#define IN_PORT_NUMB 1 // number of input ports
#define OUT_PORT_WIDTH PORT_WIDTH // width of output ports
#define OUT_PORT_NUMB PORT_NUMB // number of output ports
#define DISC_STATES_WIDTH PORT_WIDTH*PORT_NUMB // width of discrete states array
// Externs
extern double SIM_Sample_Time; // sample time
/** MCU HANDLE STRUCTURE */
/**
* @brief MCU handle Structure definition.
* @vars MCU Thread - handle for MCUThread and id of MCUThread (unused).
* @vars Flags and counters - flags and counter that control MCU app.
*
*/
typedef void* HANDLE;
typedef struct _DEL_MCUHandleTypeDef {
// MCU Thread
HANDLE hMCUThread; /* Õåíäë äëÿ ïîòîêà ÌÊ */
uint32_t idMCUThread; /* id ïîòîêà ÌÊ (unused) */
// Flags
unsigned MCU_Stop : 1; /* ôëàã äëÿ âûõîäà èç ïîòîêà ïðîãðàììû ÌÊ */
}SIM__MCUHandleTypeDef;
extern SIM__MCUHandleTypeDef hmcu; /* extern äëÿ âèäèìîñòè ïåðåìåííîé âî âñåõ ôàéëàõ */
//-------------------------------------------------------------//
//------------------ SIMULINK WHILE DEFINES -----------------//
/** DEFINE TO WHILE WITH SIMULINK WHILE */
/**
* @brief Redefine C while statement with sim_while() macro.
* @param _expression_ - expression for while.
* @note @ref sim_while äëÿ ïîäðîáíîñòåé.
*/
#define while(_expression_) sim_while(_expression_) /* while êîòîðûé áóäåò èñïîëüçîâàòüñÿ â ñèìóëèíêå */
/** SIMULINK WHILE */
/**
* @brief While statement for emulate MCU code in Simulink.
* @param _expression_ - expression for while.
* @note Äàííûé while íåîáõîäèì, ÷òîáû â êîíöå ñèìóëÿöèè, çàâåðøèòü ïîòîê ÌÊ:
* Ïðè âûñòàâëåíèè ôëàãà îêîí÷àíèÿ ñèìóëÿöèè, âñå while áóäóò ïðîïóñêàòüñÿ
* è ïîòîê ñìîæåò äîéòè äî êîíöà ñâîåé ôóíêöèè è çàâåðøèòü ñåáÿ.
*/
#define sim_while(_expression_) while((_expression_)&&(hmcu.MCU_Stop == 0))
/** DEFAULT WHILE */
/**
* @brief Default/Native C while statement.
* @param _expression_ - expression for while.
* @note Äàííûé while - àíàëîã îáû÷íîãî while, áåç äîïîëíèòåëüíîãî ôóíêöèîíàëà.
*/
#define native_while(_expression_) for(; (_expression_); )
/***************************************************************/
//------------------ SIMULINK WHILE DEFINES -----------------//
//-------------------------------------------------------------//
//-------------------------------------------------------------//
//---------------- SIMULATE FUNCTIONS PROTOTYPES -------------//
/** SIMULATE MCU STEP */
/**
* @brief Read from simulink S-Block Inputs and write to MCU I/O ports.
* @param in - inputs of S-Function.
* @param disc - discrete array of S-Function. Outputs would be written from disc.
* @param time - current time of simulation (in second).
* @note Çàïóñêàåò ïîòîê, êîòîðûé âûïîëíÿåò êîä ÌÊ è óïðàâëÿåò õîäîì ïîòîêà:
* Åñëè ïðîøåë òàéìàóò, ïîòîê ïðåðûâàåòñÿ, ñèìóëèðóåòñÿ ïåðèôåðèÿ
* è íà ñëåäóþùåì øàãå ïîòîê âîçîáíàâëÿåòñÿ.
*/
void MCU_Step_Simulation(SimStruct *S, time_T time); /* step simulation */
/** SIMULATE MCU PERIPHERAL */
/**
* @brief Simulate peripheral of MCU
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé ñèìóëèðóåò ðàáîòó ïåðèôåðèè ÌÊ.
*/
void MCU_Periph_Simulation(void); /* MCU peripheral simulation */
/** MCU WRAPPER INITIALIZATION */
/**
* @brief Initialize structures and variables for simulating MCU.
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé áóäåò íàñòðàèâàòü âñå ñòðóêòóðû.
*/
void SIM_Initialize_Simulation(void); /* initialize MCU simulation */
/** MCU WRAPPER DEINITIALIZATION */
/**
* @brief Deinitialize structures and variables for simulating MCU.
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé áóäåò î÷èùàòü âñå ñòðóêòóðû.
*/
void SIM_deInitialize_Simulation(void); /* SIM_deInitialize_Simulation MCU simulation */
/** READ INPUTS S-FUNCTION */
/**
* @brief Read from simulink S-Block Inputs and write to MCU I/O ports.
* @param in - inputs of S-Function.
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé çàïèñûâàåò â ïîðòû ââîäà-âûâîäà èç disc.
*/
void MCU_readInputs(real_T* in);
/** WRITE OUTPUTS S-FUNCTION */
/**
* @brief Read from MCU I/O ports and write to simulink S-Block Outputs.
* @param disc - discrete array of S-Function. Outputs would be written from disc.
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé çàïèñûâàåò â disc ïîðòû ââîäà-âûâîäà.
*/
void MCU_writeOutputs(real_T* disc);
/** WRITE OUTPUTS OF S-BLOCK */
/**
* @brief Write S-Function Output ports to inputs.
* @param disc - discrete array of S-Function. Outputs would be written from disc.
* @note Ïîëüçîâàòåëüñêèé êîä, êîòîðûé çàïèñûâàåò âûõîäû S-Function.
*/
void SIM_writeOutput(SimStruct* S);
//---------------- SIMULATE FUNCTIONS PROTOTYPES -------------//
//-------------------------------------------------------------//
#endif // _CONTROLLER_H_

92
MCU_Wrapper/run_mex.bat Normal file
View File

@@ -0,0 +1,92 @@
@echo off
set defines=-D"STM32F407xx" -D"USE_HAL_DRIVER"^
-D"MATLAB"^
-D"__sizeof_ptr=8"
:: -------------------------USERS PATHS AND CODE---------------------------
:: заголовочные файлы (не добавлять CMSIS и HAL, они добавлены ниже)
set includes_USER= -I".\Code\Core\Inc" -I".\Code\GENERAL"^
-I".\Code\Modbus" -I".\Code\PWM"
:: исходный код
setlocal enabledelayedexpansion
set code_USER=
for %%f in (.\Code\Core\Src\*.c) do (
set code_USER=!code_USER! %%f
)
for %%f in (.\Code\GENERAL\*.c) do (
set code_USER=!code_USER! %%f
)
for %%f in (.\Code\Modbus\*.c) do (
set code_USER=!code_USER! %%f
)
for %%f in (.\Code\PWM\*.c) do (
set code_USER=!code_USER! %%f
)
::-------------------------------------------------------------------------
:: -----------------------MCU LIBRARIES & SIMULATOR------------------------
:: -----MCU LIBRARIES STUFF----
:: заголовочные файлы
set includes_MCU= -I".\MCU_STM32F4xx_Matlab"^
-I".\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_SIMULINK"^
-I".\MCU_STM32F4xx_Matlab\Drivers\CMSIS"^
-I".\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Inc"^
-I".\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy"
:: код библиотек МК, переделанный для матлаб
set code_MCU=.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_uart.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_exti.c
:: .\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c^
:: .\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c^
:: .\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c^
:: .\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c^
:: --------MCU SIMULATOR-------
:: код, которая будет симулировать перефирию МК в симулинке
set code_MCU_Sim= .\MCU_STM32F4xx_Matlab\stm32f4xx_matlab_conf.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_SIMULINK\stm32f4xx_matlab_gpio.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_SIMULINK\stm32f4xx_matlab_tim.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_SIMULINK\stm32f4xx_periph_registers.c
::-------------------------------------------------------------------------
:: -------------------------WRAPPER PATHS AND CODE---------------------------
:: оболочка, которая будет моделировать работу МК в симулинке
set includes_WRAPPER= -I".\MCU_Wrapper"
set code_WRAPPER= .\MCU_Wrapper\MCU.c^
.\MCU_Wrapper\mcu_wrapper.c
::-------------------------------------------------------------------------
:: ---------------------SET PARAMS FOR MEX COMPILING-----------------------
:: --------ALL INCLUDES--------
set includes= %includes_USER% %includes_MCU% %includes_WRAPPER%
set codes= %code_WRAPPER% %code_USER% %code_MCU% %code_MCU_Sim%
:: -------OUTPUT FOLDER--------
set output= -outdir "."
:: если нужен дебаг, до запускаем run mex с припиской debug
IF [%1]==[debug] (set debug= -g)
::-------------------------------------------------------------------------
::------START COMPILING-------
echo Compiling...
mex %output% %defines% %includes% %codes% %debug%

View File

@@ -0,0 +1,76 @@
@echo off
set defines=-D"STM32F103xB" -D"USE_HAL_DRIVER"^
-D"MATLAB"^
-D"__sizeof_ptr=8"
:: -------------------------USERS PATHS AND CODE---------------------------
:: заголовочные файлы (не добавлять CMSIS и HAL, они добавлены ниже)
set includes_USER= -I".\Core\Inc"
:: исходный код
setlocal enabledelayedexpansion
set code_USER=
for %%f in (.\Core\Src\*.c) do (
set code_USER=!code_USER! %%f
)
::-------------------------------------------------------------------------
:: -----------------------MCU LIBRARIES & SIMULATOR------------------------
:: -----MCU LIBRARIES STUFF----
:: заголовочные файлы
set includes_MCU= -I".\MCU_STM32F1xx_Matlab"^
-I".\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_SIMULINK"^
-I".\MCU_STM32F1xx_Matlab\Drivers\CMSIS"^
-I".\MCU_STM32F1xx_Matlab\Drivers\CMSIS\Device\STM32F1xx"^
-I".\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Inc"^
-I".\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Inc\Legacy"
:: код библиотек МК, переделанный для матлаб
set code_MCU= .\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c
:: .\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ramfunc.c^
:: .\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c^
:: .\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c^
:: .\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c^
:: --------MCU SIMULATOR-------
:: код, которая будет симулировать перефирию МК в симулинке
set code_MCU_Sim= .\MCU_STM32F1xx_Matlab\stm32f1xx_matlab_conf.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_SIMULINK\stm32f1xx_matlab_gpio.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_SIMULINK\stm32f1xx_matlab_tim.c^
.\MCU_STM32F1xx_Matlab\Drivers\STM32F1xx_SIMULINK\stm32f1xx_periph_registers.c
::-------------------------------------------------------------------------
:: -------------------------WRAPPER PATHS AND CODE---------------------------
:: оболочка, которая будет моделировать работу МК в симулинке
set includes_WRAPPER= -I".\MCU_Wrapper"
set code_WRAPPER= .\MCU_Wrapper\MCU.c^
.\MCU_Wrapper\mcu_wrapper.c
::-------------------------------------------------------------------------
:: ---------------------SET PARAMS FOR MEX COMPILING-----------------------
:: --------ALL INCLUDES--------
set includes= %includes_USER% %includes_MCU% %includes_WRAPPER%
set codes= %code_WRAPPER% %code_USER% %code_MCU% %code_MCU_Sim%
:: -------OUTPUT FOLDER--------
set output= -outdir "."
:: если нужен дебаг, до запускаем run mex с припиской debug
IF [%1]==[debug] (set debug= -g)
::-------------------------------------------------------------------------
::------START COMPILING-------
echo Compiling...
mex %output% %defines% %includes% %codes% %debug%

View File

@@ -0,0 +1,90 @@
@echo off
set defines=-D"STM32F407xx" -D"USE_HAL_DRIVER"^
-D"MATLAB"^
-D"__sizeof_ptr=8"
:: -------------------------USERS PATHS AND CODE---------------------------
:: заголовочные файлы (не добавлять CMSIS и HAL, они добавлены ниже)
set includes_USER= -I".\Core\Inc"
:: исходный код
set code_USER=.\Core\Src\main.c^
.\Core\Src\tim.c^
.\Core\Src\gpio.c^
.\Core\Src\stm32f4xx_it.c^
.\Core\Src\system_stm32f4xx.c
:: .\Core\Src\stm32f4xx_hal_msp.c^
::-------------------------------------------------------------------------
:: -----------------------MCU LIBRARIES & SIMULATOR------------------------
:: -----MCU LIBRARIES STUFF----
:: заголовочные файлы
set includes_MCU= -I".\MCU_STM32F4xx_Matlab"^
-I".\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_SIMULINK"^
-I".\MCU_STM32F4xx_Matlab\Drivers\CMSIS"^
-I".\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Inc"^
-I".\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy"
:: код библиотек МК, переделанный для матлаб
set code_MCU=.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_exti.c
:: .\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c^
:: .\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c^
:: .\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c^
:: .\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c^
:: --------MCU SIMULATOR-------
:: код, которая будет симулировать перефирию МК в симулинке
set code_MCU_Sim= .\MCU_STM32F4xx_Matlab\stm32f4xx_matlab_conf.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_SIMULINK\stm32f4xx_matlab_gpio.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_SIMULINK\stm32f4xx_matlab_tim.c^
.\MCU_STM32F4xx_Matlab\Drivers\STM32F4xx_SIMULINK\stm32f4xx_periph_registers.c
::-------------------------------------------------------------------------
:: -------------------------WRAPPER PATHS AND CODE---------------------------
:: оболочка, которая будет моделировать работу МК в симулинке
set includes_WRAPPER= -I".\MCU_Wrapper"
set code_WRAPPER= .\MCU_Wrapper\Outputs\asmjmp.obj^
.\MCU_Wrapper\MCU.c^
.\MCU_Wrapper\controller.c
:: оболочка, которая будет моделировать работу МК в симулинке
set asm_WRAPPER=asmjmp
set output_folder=.\MCU_Wrapper\Outputs\
set asm_source=.\MCU_Wrapper\%asm_WRAPPER%.asm
set asm_obj=%output_folder%%asm_WRAPPER%.obj
::-------------------------------------------------------------------------
:: ---------------------SET PARAMS FOR MEX COMPILING-----------------------
:: --------ALL INCLUDES--------
set includes= %includes_USER% %includes_MCU% %includes_WRAPPER%
set codes= %code_WRAPPER% %code_USER% %code_MCU% %code_MCU_Sim%
:: -------OUTPUT FOLDER--------
set output= -outdir "."
:: если нужен дебаг, до запускаем run mex с припиской debug
IF [%1]==[debug] (set debug= -g)
::-------------------------------------------------------------------------
::------START COMPILING-------
set asm_exe= "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\ml64.exe"
set asm_command= /c /Zi /Fo %asm_obj% %asm_source%
%asm_exe% %asm_command%
echo.
echo Compiling...
mex %output% %defines% %includes% %codes% %debug%