симулируется упп на stm32f103

This commit is contained in:
2025-05-10 01:20:08 +03:00
parent c6269ca448
commit 08719ffc05
397 changed files with 516 additions and 30524 deletions

View File

@@ -779,33 +779,33 @@ HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
return tmp_hal_status;
}
/**
* @brief Initializes the ADC MSP.
* @param hadc: ADC handle
* @retval None
*/
__weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hadc);
/* NOTE : This function should not be modified. When the callback is needed,
function HAL_ADC_MspInit must be implemented in the user file.
*/
}
///**
// * @brief Initializes the ADC MSP.
// * @param hadc: ADC handle
// * @retval None
// */
//__weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
//{
// /* Prevent unused argument(s) compilation warning */
// UNUSED(hadc);
// /* NOTE : This function should not be modified. When the callback is needed,
// function HAL_ADC_MspInit must be implemented in the user file.
// */
//}
/**
* @brief DeInitializes the ADC MSP.
* @param hadc: ADC handle
* @retval None
*/
__weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hadc);
/* NOTE : This function should not be modified. When the callback is needed,
function HAL_ADC_MspDeInit must be implemented in the user file.
*/
}
///**
// * @brief DeInitializes the ADC MSP.
// * @param hadc: ADC handle
// * @retval None
// */
//__weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
//{
// /* Prevent unused argument(s) compilation warning */
// UNUSED(hadc);
// /* NOTE : This function should not be modified. When the callback is needed,
// function HAL_ADC_MspDeInit must be implemented in the user file.
// */
//}
#if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
/**

View File

@@ -1,36 +1,36 @@
#include "stm32f1xx_matlab_gpio.h"
void __GPIO_BSRR_Sim(GPIO_TypeDef* port);
void GPIO_to_SFUNC(real_T *disc)
void Simulate_GPIO_BSRR(void)
{
for (int i = 0; i < PORT_WIDTH; i++)
{
if (GPIOA->ODR & (1 << i))
{
disc[i] = 1;
}
if (GPIOB->ODR & (1 << i))
{
disc[PORT_WIDTH + i] = 1;
}
}
#ifdef GPIOA
__GPIO_BSRR_Sim(GPIOA);
#endif
#ifdef GPIOB
__GPIO_BSRR_Sim(GPIOB);
#endif
#ifdef GPIOC
__GPIO_BSRR_Sim(GPIOC);
#endif
#ifdef GPIOD
__GPIO_BSRR_Sim(GPIOD);
#endif
}
void SFUNC_to_GPIO(real_T* in)
void __GPIO_BSRR_Sim(GPIO_TypeDef* port)
{
for (int i = 0; i < PORT_WIDTH; i++)
{
if (in[i] > 0.5)
{
GPIOA->IDR |= (1 << i);
}
else
{
GPIOA->IDR &= ~(1 << i);
}
}
// Сохраняем значение регистра BSRR
uint32_t bsrr = port->BSRR;
// Нижние 16 бит — установка соответствующих битов ODR
port->ODR |= (uint16_t)(bsrr & 0xFFFF);
// Верхние 16 бит — сброс соответствующих битов ODR
port->ODR &= ~(uint16_t)((bsrr >> 16) & 0xFFFF);
// Обнуляем BSRR после обработки (в реальных STM32 он не сохраняет значение)
port->BSRR = 0;
}

View File

@@ -16,7 +16,8 @@
void SFUNC_to_GPIO(real_T* disc);
void GPIO_to_SFUNC(real_T* in);
void Simulate_GPIO_BSRR(void);
void WriteFromSFunc(real_T* disc);
void ReadToSFunc(real_T* in);
#endif // _MATLAB_GPIO_H_

View File

@@ -582,8 +582,8 @@ void TIM_SIM_DEINIT(void)
/* Вызов прерывания */
void call_IRQHandller(TIM_TypeDef* TIMx)
{ // calling HANDLER
if (TIMx == TIM1)
TIM1_UP_IRQHandler();
//if (TIMx == TIM1)
// TIM1_UP_IRQHandler();
//if ((TIMx == TIM1) || (TIMx == TIM10))
// TIM1_UP_TIM10_IRQHandler();
//else if (TIMx == TIM2)

View File

@@ -85,7 +85,7 @@ void Init_TIM_SIM(void)
{
#ifdef USE_TIM1
tim1s.tx_cnt = TIM1->CNT;
tim1s.tx_step = SIM_Sample_Time * ABP2_TIMS_Value;
tim1s.tx_step = hmcu.SIM_Sample_Time * ABP2_TIMS_Value;
tim1s.Channels.OC1_GPIOx = GPIOA;
tim1s.Channels.OC1_PIN_SHIFT = 8;
@@ -98,7 +98,7 @@ void Init_TIM_SIM(void)
#endif
#ifdef USE_TIM2
tim2s.tx_cnt = TIM2->CNT;
tim2s.tx_step = SIM_Sample_Time * ABP1_TIMS_Value;
tim2s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;
tim2s.Channels.OC1_GPIOx = GPIOA;
tim2s.Channels.OC1_PIN_SHIFT = 5;
@@ -111,7 +111,7 @@ void Init_TIM_SIM(void)
#endif
#ifdef USE_TIM3
tim3s.tx_cnt = TIM3->CNT;
tim3s.tx_step = SIM_Sample_Time * ABP1_TIMS_Value;
tim3s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;
tim3s.Channels.OC1_GPIOx = GPIOB;
tim3s.Channels.OC1_PIN_SHIFT = 4;
@@ -124,7 +124,7 @@ void Init_TIM_SIM(void)
#endif
#ifdef USE_TIM4
tim4s.tx_cnt = TIM4->CNT;
tim4s.tx_step = SIM_Sample_Time * ABP1_TIMS_Value;
tim4s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;
tim4s.Channels.OC1_GPIOx = GPIOD;
tim4s.Channels.OC1_PIN_SHIFT = 12;
@@ -137,7 +137,7 @@ void Init_TIM_SIM(void)
#endif
#ifdef USE_TIM5
tim5s.tx_cnt = TIM5->CNT;
tim5s.tx_step = SIM_Sample_Time * ABP1_TIMS_Value;
tim5s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;
tim5s.Channels.OC1_GPIOx = GPIOA;
tim5s.Channels.OC1_PIN_SHIFT = 0;
@@ -150,7 +150,7 @@ void Init_TIM_SIM(void)
#endif
#ifdef USE_TIMx
tim6s.tx_cnt = TIMx->CNT;
tim6s.tx_step = SIM_Sample_Time * ABP1_TIMS_Value;
tim6s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;
tim6s.Channels.OC1_GPIOx = GPIOA;
tim6s.Channels.OC1_PIN_SHIFT = 0;

View File

@@ -11,9 +11,9 @@
// DEFINES (UNCOMMENT WHAT YOU WILL SIMULATE)
// TIMS
#define USE_TIM1
//#define USE_TIM1
#define USE_TIM2
#define USE_TIM3
//#define USE_TIM3
//#define USE_TIM4
//#define USE_TIM5
//#define USE_TIM6