diff --git a/MATLAB/MCU_STM32_Matlab/Drivers/CMSIS/arm_defines.h b/MATLAB/MCU_STM32_Matlab/Drivers/CMSIS/arm_defines.h index 0ade789..435f76c 100644 --- a/MATLAB/MCU_STM32_Matlab/Drivers/CMSIS/arm_defines.h +++ b/MATLAB/MCU_STM32_Matlab/Drivers/CMSIS/arm_defines.h @@ -1,5 +1,7 @@ #include "mcu_wrapper_conf.h" +#ifdef ARM_MATH_LOOPUNROLL #include "dsp/none.h" +#endif #define __disable_irq() diff --git a/MATLAB/MCU_STM32_Matlab/Drivers/STM32_SIMULINK/stm32_matlab_tim.c b/MATLAB/MCU_STM32_Matlab/Drivers/STM32_SIMULINK/stm32_matlab_tim.c index 6c46c76..4c2c92a 100644 --- a/MATLAB/MCU_STM32_Matlab/Drivers/STM32_SIMULINK/stm32_matlab_tim.c +++ b/MATLAB/MCU_STM32_Matlab/Drivers/STM32_SIMULINK/stm32_matlab_tim.c @@ -131,13 +131,14 @@ void CC_PWM_Ch1_Simulation(TIM_TypeDef *TIMx, struct TIM_Sim *TIMS) } if (TIMx->DIER & TIM_IT_CC1) { - TIMx->SR |= TIM_SR_CC1IF; if (((TIMS->tx_cnt - TIMS->tx_step) < TIMx->CCR1) && (TIMS->tx_cnt >= TIMx->CCR1)) { + TIMx->SR |= TIM_SR_CC1IF; TIM_Call_IRQHandller(TIMx); } else if (((TIMS->tx_cnt - TIMS->tx_step) > TIMx->CCR1) && (TIMS->tx_cnt <= TIMx->CCR1)) { + TIMx->SR |= TIM_SR_CC1IF; TIM_Call_IRQHandller(TIMx); } } @@ -184,20 +185,21 @@ void CC_PWM_Ch2_Simulation(TIM_TypeDef *TIMx, struct TIM_Sim *TIMS) } if (TIMx->DIER & TIM_IT_CC2) { - TIMx->SR |= TIM_SR_CC2IF; if (((TIMS->tx_cnt - TIMS->tx_step) < TIMx->CCR2) && (TIMS->tx_cnt >= TIMx->CCR2)) { + TIMx->SR |= TIM_SR_CC2IF; TIM_Call_IRQHandller(TIMx); } else if (((TIMS->tx_cnt - TIMS->tx_step) > TIMx->CCR2) && (TIMS->tx_cnt <= TIMx->CCR2)) { + TIMx->SR |= TIM_SR_CC2IF; TIM_Call_IRQHandller(TIMx); } } } void CC_PWM_Ch3_Simulation(TIM_TypeDef *TIMx, struct TIM_Sim *TIMS) { // определяет режим канала - switch (TIMx->CCMR2 & TIM_CCMR1_OC1M) + switch (TIMx->CCMR2 & TIM_CCMR2_OC3M) { case (TIM_OCMODE_ACTIVE): // ACTIVE mode if (abs(TIMx->CNT - TIMx->CCR3) < 2*TIMS->tx_step) @@ -237,20 +239,21 @@ void CC_PWM_Ch3_Simulation(TIM_TypeDef *TIMx, struct TIM_Sim *TIMS) } if (TIMx->DIER & TIM_IT_CC3) { - TIMx->SR |= TIM_SR_CC3IF; if (((TIMS->tx_cnt - TIMS->tx_step) < TIMx->CCR3) && (TIMS->tx_cnt >= TIMx->CCR3)) { + TIMx->SR |= TIM_SR_CC3IF; TIM_Call_IRQHandller(TIMx); } else if (((TIMS->tx_cnt - TIMS->tx_step) > TIMx->CCR3) && (TIMS->tx_cnt <= TIMx->CCR3)) { + TIMx->SR |= TIM_SR_CC3IF; TIM_Call_IRQHandller(TIMx); } } } void CC_PWM_Ch4_Simulation(TIM_TypeDef *TIMx, struct TIM_Sim *TIMS) { // определяет режим канала - switch (TIMx->CCMR2 & TIM_CCMR1_OC2M) + switch (TIMx->CCMR2 & TIM_CCMR2_OC4M) { case ((TIM_OCMODE_ACTIVE) << (TIM_OCMODE_SECOND_SHIFT)): // ACTIVE mode if (abs(TIMx->CNT - TIMx->CCR4) < 2*TIMS->tx_step) @@ -290,13 +293,14 @@ void CC_PWM_Ch4_Simulation(TIM_TypeDef *TIMx, struct TIM_Sim *TIMS) } if (TIMx->DIER & TIM_IT_CC4) { - TIMx->SR |= TIM_SR_CC4IF; if (((TIMS->tx_cnt - TIMS->tx_step) < TIMx->CCR4) && (TIMS->tx_cnt >= TIMx->CCR4)) { + TIMx->SR |= TIM_SR_CC4IF; TIM_Call_IRQHandller(TIMx); } else if (((TIMS->tx_cnt - TIMS->tx_step) > TIMx->CCR4) && (TIMS->tx_cnt <= TIMx->CCR4)) { + TIMx->SR |= TIM_SR_CC4IF; TIM_Call_IRQHandller(TIMx); } } @@ -649,9 +653,13 @@ __weak void TIM8_BRK_TIM12_IRQHandler(void) {} __weak void TIM8_TRG_COM_TIM14_IRQHandler(void) {} //#endif + + /* Вызов прерывания */ void TIM_Call_IRQHandller(TIM_TypeDef* TIMx) { // calling HANDLER + SR_STORE(TIMx, SR); + if ((TIMx == TIM1) || (TIMx == TIM10)) TIM1_UP_TIM10_IRQHandler(); else if (TIMx == TIM2) @@ -676,5 +684,7 @@ void TIM_Call_IRQHandller(TIM_TypeDef* TIMx) TIM8_BRK_TIM12_IRQHandler(); else if ((TIMx == TIM8) || (TIMx == TIM14)) TIM8_TRG_COM_TIM14_IRQHandler(); + + SR_PROCESS(TIMx, SR); } //------------------------------------------------------------------// diff --git a/MATLAB/MCU_STM32_Matlab/stm32_matlab_conf.h b/MATLAB/MCU_STM32_Matlab/stm32_matlab_conf.h index 34e81e8..05cea5a 100644 --- a/MATLAB/MCU_STM32_Matlab/stm32_matlab_conf.h +++ b/MATLAB/MCU_STM32_Matlab/stm32_matlab_conf.h @@ -147,4 +147,14 @@ static void ADC_SIM_DEINIT() {} //-----------------------------------------------------------------------// + + +#define SR_STORE(periph, srname) \ +uint32_t sr_origin = periph->srname; \ +uint32_t sr_new = periph->srname; + +#define SR_PROCESS(periph, srname) \ +sr_new = sr_origin & periph->srname; \ +periph->srname = sr_new; + #endif // _MATLAB_SETUP_H_ diff --git a/MATLAB/MCU_Wrapper/run_mex.bat b/MATLAB/MCU_Wrapper/run_mex.bat index add764a..c30c29f 100644 --- a/MATLAB/MCU_Wrapper/run_mex.bat +++ b/MATLAB/MCU_Wrapper/run_mex.bat @@ -54,33 +54,6 @@ set code_PERIPH=.\MCU_STM32_Matlab\stm32_matlab_conf.c^ .\MCU_STM32_Matlab\Drivers\STM32_SIMULINK\stm32_matlab_gpio.c^ .\MCU_STM32_Matlab\Drivers\STM32_SIMULINK\stm32_matlab_dma.c^ .\MCU_STM32_Matlab\Drivers\STM32_SIMULINK\stm32_periph_registers.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\BasicMathFunctions\BasicMathFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\BasicMathFunctions\BasicMathFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\BayesFunctions\BayesFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\BayesFunctions\BayesFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\CommonTables\CommonTables.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\CommonTables\CommonTablesF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\ComplexMathFunctions\ComplexMathFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\ComplexMathFunctions\ComplexMathFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\ControllerFunctions\ControllerFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\DistanceFunctions\DistanceFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\FastMathFunctions\FastMathFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\FastMathFunctions\FastMathFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\FilteringFunctions\FilteringFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\FilteringFunctions\FilteringFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\InterpolationFunctions\InterpolationFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\InterpolationFunctions\InterpolationFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\MatrixFunctions\MatrixFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\MatrixFunctions\MatrixFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\QuaternionMathFunctions\QuaternionMathFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\StatisticsFunctions\StatisticsFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\StatisticsFunctions\StatisticsFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\SupportFunctions\SupportFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\SupportFunctions\SupportFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\SVMFunctions\SVMFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\SVMFunctions\SVMFunctionsF16.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\TransformFunctions\TransformFunctions.c^ - .\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\TransformFunctions\TransformFunctionsF16.c^ .\MCU_STM32_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c^ .\MCU_STM32_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc.c^ .\MCU_STM32_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc_ex.c^ @@ -102,24 +75,7 @@ set includes_PERIPH=-I".\MCU_STM32_Matlab\."^ -I".\MCU_STM32_Matlab\Drivers\CMSIS"^ -I".\MCU_STM32_Matlab\Drivers\CMSIS\Device\STM32F4xx"^ -I".\MCU_STM32_Matlab\Drivers\STM32F4xx_HAL_Driver\Inc"^ - -I".\MCU_STM32_Matlab\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Include"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\PrivateInclude"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\BasicMathFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\BayesFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\CommonTables"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\ComplexMathFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\ControllerFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\DistanceFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\FastMathFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\FilteringFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\InterpolationFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\MatrixFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\QuaternionMathFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\StatisticsFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\SupportFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\SVMFunctions"^ - -I".\MCU_STM32_Matlab\Drivers\CMSIS\DSP\Source\TransformFunctions" + -I".\MCU_STM32_Matlab\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy" :: PERIPH BAT END ::------------------------------------------------------------------------- diff --git a/MATLAB/app_wrapper/app_io.c b/MATLAB/app_wrapper/app_io.c index e627662..6a06c4e 100644 --- a/MATLAB/app_wrapper/app_io.c +++ b/MATLAB/app_wrapper/app_io.c @@ -82,9 +82,20 @@ void app_writeOutputBuffer(real_T* Buffer) { int nn = 0; - WriteOutputArray(upp.hangle.htim->Instance->CNT, 2, nn++); - WriteOutputArray(upp.hangle.htim->Instance->CCR1, 2, nn++); - WriteOutputArray(upp.hangle.htim->Instance->CCR2, 2, nn++); - WriteOutputArray(upp.hangle.htim->Instance->CCR3, 2, nn++); + //WriteOutputArray(upp.hangle.htim->Instance->CNT, 2, nn++); + //WriteOutputArray((long long)(upp.hangle.htim->Instance->CCR1) - upp.hangle.htim->Instance->CNT, 2, nn++); + //WriteOutputArray((long long)(upp.hangle.htim->Instance->CCR2) - upp.hangle.htim->Instance->CNT, 2, nn++); + //WriteOutputArray((long long)(upp.hangle.htim->Instance->CCR3) - upp.hangle.htim->Instance->CNT, 2, nn++); + + //WriteOutputArray(dbg[0], 2, nn++); + //WriteOutputArray(dbg[1], 2, nn++); + //WriteOutputArray(dbg[2], 2, nn++); + + //WriteOutputArray(upp.hpwm.AllPhases[PHASE_A_POS].State, 2, nn++); + //WriteOutputArray(upp.hpwm.AllPhases[PHASE_A_NEG].State, 2, nn++); + //WriteOutputArray(upp.hpwm.AllPhases[PHASE_B_POS].State, 2, nn++); + //WriteOutputArray(upp.hpwm.AllPhases[PHASE_B_NEG].State, 2, nn++); + //WriteOutputArray(upp.hpwm.AllPhases[PHASE_C_POS].State, 2, nn++); + //WriteOutputArray(upp.hpwm.AllPhases[PHASE_C_NEG].State, 2, nn++); // USER APP OUTPUT END } \ No newline at end of file diff --git a/MATLAB/upp_r2023.slx b/MATLAB/upp_r2023.slx index d83512b..2f48cc2 100644 Binary files a/MATLAB/upp_r2023.slx and b/MATLAB/upp_r2023.slx differ diff --git a/UPP/AllLibs/PeriphGeneral b/UPP/AllLibs/PeriphGeneral index b3f118b..1cc886a 160000 --- a/UPP/AllLibs/PeriphGeneral +++ b/UPP/AllLibs/PeriphGeneral @@ -1 +1 @@ -Subproject commit b3f118b074951fa827e5a692e9da7637b5397a98 +Subproject commit 1cc886aa8dc5c2fcfdad93a21207793b2cd85fab diff --git a/UPP/Core/UPP/angle_control.c b/UPP/Core/UPP/angle_control.c index de0ee4f..767edaf 100644 --- a/UPP/Core/UPP/angle_control.c +++ b/UPP/Core/UPP/angle_control.c @@ -104,18 +104,18 @@ HAL_StatusTypeDef Angle_Start(Angle_Handle_t *hangle, UPP_Phase_t Phase, float A switch(Phase) { case UPP_PHASE_A: - __HAL_TIM_ENABLE_IT(hangle->htim, TIM_IT_CC1); __HAL_TIM_SET_COMPARE(hangle->htim, ANGLE_CHANNEL_1, ccr_ticks); + __HAL_TIM_ENABLE_IT(hangle->htim, TIM_IT_CC1); break; case UPP_PHASE_B: - __HAL_TIM_ENABLE_IT(hangle->htim, TIM_IT_CC2); __HAL_TIM_SET_COMPARE(hangle->htim, ANGLE_CHANNEL_2, ccr_ticks); + __HAL_TIM_ENABLE_IT(hangle->htim, TIM_IT_CC2); break; case UPP_PHASE_C: - __HAL_TIM_ENABLE_IT(hangle->htim, TIM_IT_CC3); __HAL_TIM_SET_COMPARE(hangle->htim, ANGLE_CHANNEL_3, ccr_ticks); + __HAL_TIM_ENABLE_IT(hangle->htim, TIM_IT_CC3); break; case UPP_PHASE_UNKNOWN: