fix
This commit is contained in:
parent
cfde78e9dc
commit
b5f566c940
@ -6,8 +6,6 @@ SET(CMAKE_CXX_COMPILER_WORKS TURE)
|
|||||||
|
|
||||||
project(stm32_template)
|
project(stm32_template)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ENABLE_LANGUAGE(ASM C)
|
ENABLE_LANGUAGE(ASM C)
|
||||||
|
|
||||||
add_definitions(
|
add_definitions(
|
||||||
@ -15,22 +13,11 @@ add_definitions(
|
|||||||
-DUSE_HAL_DRIVER
|
-DUSE_HAL_DRIVER
|
||||||
)
|
)
|
||||||
|
|
||||||
set(MCU_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections")
|
|
||||||
|
|
||||||
set(CMAKE_ASM_FLAGS "-c ${MCU_FLAGS} -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2")
|
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "${MCU_FLAGS} -Dgcc -w -Wno-unknown-pragmas -O0 -gdwarf-2 -g")
|
|
||||||
set(CMAKE_C_FLAGS_DEBUG "-O0 -gdwarf-2 -g")
|
|
||||||
set(CMAKE_C_FLAGS_RELEASE "-O3")
|
|
||||||
|
|
||||||
set(LINKER_SCRIPT STM32F407ZGTX_FLASH.ld)
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${MCU_FLAGS} -Wl,--gc-sections,-Map=${PROJECT_NAME}.map,--cref,-u,Reset_Handler -T${LINKER_SCRIPT}")
|
|
||||||
#set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs -specs=nosys.specs -nostartfiles -T${LINKER_SCRIPT} -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map,--cref -Wl,--gc-sections")
|
|
||||||
|
|
||||||
set(SRC_PATH ../../src)
|
set(SRC_PATH ../../src)
|
||||||
|
|
||||||
include_directories(${SRC_PATH}/App)
|
include_directories(${SRC_PATH}/App)
|
||||||
include_directories(${SRC_PATH}/Bsp)
|
include_directories(${SRC_PATH}/Bsp)
|
||||||
|
include_directories(${SRC_PATH}/Foc)
|
||||||
include_directories(${SRC_PATH}/Common)
|
include_directories(${SRC_PATH}/Common)
|
||||||
include_directories(${SRC_PATH}/CMSIS/Include)
|
include_directories(${SRC_PATH}/CMSIS/Include)
|
||||||
include_directories(${SRC_PATH}/CMSIS/Device/ST/STM32F4xx/Include)
|
include_directories(${SRC_PATH}/CMSIS/Device/ST/STM32F4xx/Include)
|
||||||
@ -100,9 +87,16 @@ set(Bsp_SRC
|
|||||||
${SRC_PATH}/Bsp/board.c
|
${SRC_PATH}/Bsp/board.c
|
||||||
${SRC_PATH}/Bsp/gpio.c
|
${SRC_PATH}/Bsp/gpio.c
|
||||||
${SRC_PATH}/Bsp/usart.c
|
${SRC_PATH}/Bsp/usart.c
|
||||||
|
${SRC_PATH}/Bsp/timer.c
|
||||||
${SRC_PATH}/Bsp/stm32f4xx_it.c
|
${SRC_PATH}/Bsp/stm32f4xx_it.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(Foc_SRC
|
||||||
|
${SRC_PATH}/Foc/math.c
|
||||||
|
${SRC_PATH}/Foc/hall.c
|
||||||
|
${SRC_PATH}/Foc/svpwm.c
|
||||||
|
)
|
||||||
|
|
||||||
set(Common_SRC
|
set(Common_SRC
|
||||||
|
|
||||||
)
|
)
|
||||||
@ -114,8 +108,8 @@ ${SRC_PATH}/App/main.c
|
|||||||
add_executable(${PROJECT_NAME}.elf
|
add_executable(${PROJECT_NAME}.elf
|
||||||
${CMSIS_SRC}
|
${CMSIS_SRC}
|
||||||
${STM32F4xx_HAL_Driver_SRC}
|
${STM32F4xx_HAL_Driver_SRC}
|
||||||
${RTThread_SRC}
|
#${RTThread_SRC}
|
||||||
${FinSH_SRC}
|
#${FinSH_SRC}
|
||||||
${Common_SRC}
|
${Common_SRC}
|
||||||
${Bsp_SRC}
|
${Bsp_SRC}
|
||||||
${App_SRC}
|
${App_SRC}
|
||||||
|
@ -28,16 +28,16 @@ elseif(UNIX)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# set(MCU_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections")
|
set(MCU_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections")
|
||||||
#
|
|
||||||
# set(CMAKE_ASM_FLAGS "-c ${MCU_FLAGS} -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2")
|
set(CMAKE_ASM_FLAGS "-c ${MCU_FLAGS} -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2")
|
||||||
#
|
|
||||||
# set(CMAKE_C_FLAGS "${MCU_FLAGS} -Dgcc -w -Wno-unknown-pragmas -O0 -gdwarf-2 -g")
|
set(CMAKE_C_FLAGS "${MCU_FLAGS} -Dgcc -w -Wno-unknown-pragmas -O0 -gdwarf-2 -g")
|
||||||
# set(CMAKE_C_FLAGS_DEBUG "-O0 -gdwarf-2 -g")
|
set(CMAKE_C_FLAGS_DEBUG "-O0 -gdwarf-2 -g")
|
||||||
# set(CMAKE_C_FLAGS_RELEASE "-O3")
|
set(CMAKE_C_FLAGS_RELEASE "-O3")
|
||||||
#
|
|
||||||
# set(LINKER_SCRIPT STM32F407ZGTX_FLASH.ld)
|
set(LINKER_SCRIPT STM32F407ZGTX_FLASH.ld)
|
||||||
# set(CMAKE_EXE_LINKER_FLAGS "${MCU_FLAGS} -Wl,--gc-sections,-Map=${PROJECT_NAME}.map,--cref,-u,Reset_Handler -T${LINKER_SCRIPT}")
|
set(CMAKE_EXE_LINKER_FLAGS "${MCU_FLAGS} -Wl,--gc-sections,-Map=${PROJECT_NAME}.map,--cref,-u,Reset_Handler -T${LINKER_SCRIPT}")
|
||||||
#set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs -specs=nosys.specs -nostartfiles -T${LINKER_SCRIPT} -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map,--cref -Wl,--gc-sections")
|
#set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs -specs=nosys.specs -nostartfiles -T${LINKER_SCRIPT} -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map,--cref -Wl,--gc-sections")
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,6 +35,11 @@ int main(void)
|
|||||||
// // svmpw()
|
// // svmpw()
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
// hall_handle.control_elec_angle++;
|
||||||
|
// foc_handle.Valphabeta = math_rev_park(foc_handle.Vqd, hall_handle.control_elec_angle);
|
||||||
|
// svmpw(foc_handle);
|
||||||
|
// 测试PWM输出
|
||||||
|
|
||||||
led_ctrl(1);
|
led_ctrl(1);
|
||||||
HAL_Delay(500);
|
HAL_Delay(500);
|
||||||
led_ctrl(0);
|
led_ctrl(0);
|
||||||
|
@ -61,6 +61,32 @@ void SystemClock_Config(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief NVIC Configuration.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_NVIC_Init(void)
|
||||||
|
{
|
||||||
|
/* ADC_IRQn interrupt configuration */
|
||||||
|
// HAL_NVIC_SetPriority(ADC_IRQn, 2, 0);
|
||||||
|
// HAL_NVIC_EnableIRQ(ADC_IRQn);
|
||||||
|
/* TIM1_UP_TIM10_IRQn interrupt configuration */
|
||||||
|
// HAL_NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 0, 0);
|
||||||
|
// HAL_NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn);
|
||||||
|
/* TIM1_BRK_TIM9_IRQn interrupt configuration */
|
||||||
|
// HAL_NVIC_SetPriority(TIM1_BRK_TIM9_IRQn, 4, 1);
|
||||||
|
// HAL_NVIC_EnableIRQ(TIM1_BRK_TIM9_IRQn);
|
||||||
|
/* TIM3_IRQn interrupt configuration */
|
||||||
|
HAL_NVIC_SetPriority(TIM3_IRQn, 3, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
||||||
|
/* USART1_IRQn interrupt configuration */
|
||||||
|
// HAL_NVIC_SetPriority(USART1_IRQn, 3, 1);
|
||||||
|
// HAL_NVIC_EnableIRQ(USART1_IRQn);
|
||||||
|
/* EXTI2_IRQn interrupt configuration */
|
||||||
|
// HAL_NVIC_SetPriority(EXTI2_IRQn, 3, 0);
|
||||||
|
// HAL_NVIC_EnableIRQ(EXTI2_IRQn);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function will initial your board.
|
* This function will initial your board.
|
||||||
*/
|
*/
|
||||||
@ -74,6 +100,8 @@ void board_init(void)
|
|||||||
SystemCoreClockUpdate();
|
SystemCoreClockUpdate();
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
MX_USART1_UART_Init();
|
MX_USART1_UART_Init();
|
||||||
|
// MX_TIM1_Init();
|
||||||
|
MX_TIM3_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +23,7 @@ extern "C"
|
|||||||
|
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
#include "foc.h"
|
#include "foc.h"
|
||||||
|
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __FOC_H__
|
||||||
|
#define __FOC_H__
|
||||||
|
|
||||||
#include "stm32f407xx.h"
|
#include "stm32f407xx.h"
|
||||||
|
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
@ -20,6 +23,7 @@ typedef struct
|
|||||||
uint8_t sector; // 扇区
|
uint8_t sector; // 扇区
|
||||||
|
|
||||||
qd_t Vqd;
|
qd_t Vqd;
|
||||||
|
alphabeta_t Valphabeta;
|
||||||
|
|
||||||
uint16_t pwmA;
|
uint16_t pwmA;
|
||||||
uint16_t pwmB;
|
uint16_t pwmB;
|
||||||
@ -27,3 +31,5 @@ typedef struct
|
|||||||
uint16_t pwm_period;
|
uint16_t pwm_period;
|
||||||
|
|
||||||
} foc_handle_t;
|
} foc_handle_t;
|
||||||
|
|
||||||
|
#endif /* __FOC_H__ */
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
*
|
*
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __FOC_HALL_H__
|
||||||
|
#define __FOC_HALL_H__
|
||||||
|
|
||||||
#include "stm32f407xx.h"
|
#include "stm32f407xx.h"
|
||||||
|
|
||||||
#define HALL_STATE_0 (uint8_t)0
|
#define HALL_STATE_0 (uint8_t)0
|
||||||
@ -39,3 +43,5 @@ typedef struct
|
|||||||
int16_t control_elec_angle; // 控制转子电角度
|
int16_t control_elec_angle; // 控制转子电角度
|
||||||
|
|
||||||
} hall_handle_t;
|
} hall_handle_t;
|
||||||
|
|
||||||
|
#endif /* __FOC_HALL_H__ */
|
||||||
|
@ -1,3 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @file math.h
|
||||||
|
* @author jimingqing
|
||||||
|
* @date 2023-08-29
|
||||||
|
* @version 0.0.1
|
||||||
|
* @copyright XiazhiTech Copyright (c) 2023
|
||||||
|
*
|
||||||
|
* @brief
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __FOC_MATH_H__
|
||||||
|
#define __FOC_MATH_H__
|
||||||
|
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
|
|
||||||
#define SQRT_2 1.4142
|
#define SQRT_2 1.4142
|
||||||
@ -51,3 +64,5 @@ alphabeta_t math_rev_park(qd_t Input, int16_t Theta);
|
|||||||
* @retval int32_t Square root of Input (0 if Input<0)
|
* @retval int32_t Square root of Input (0 if Input<0)
|
||||||
*/
|
*/
|
||||||
int32_t math_sqrt(int32_t wInput);
|
int32_t math_sqrt(int32_t wInput);
|
||||||
|
|
||||||
|
#endif /* __FOC_MATH_H__ */
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#include "foc.h"
|
#include "foc.h"
|
||||||
|
|
||||||
void svpwm(foc_handle_t *handle, alphabeta_t v)
|
void svpwm(foc_handle_t *handle)
|
||||||
{
|
{
|
||||||
int32_t wX, wY, wZ, wUAlpha, wUBeta, wTimePhA, wTimePhB, wTimePhC;
|
int32_t wX, wY, wZ, wUAlpha, wUBeta, wTimePhA, wTimePhB, wTimePhC;
|
||||||
|
|
||||||
// 后续还要根据该变量算三相占空比,所以这里乘以了周期T
|
// 后续还要根据该变量算三相占空比,所以这里乘了系数2T
|
||||||
wUAlpha = v.alpha * (int32_t)(1.732051f * handle->pwm_period) * 2;
|
wUAlpha = handle->Valphabeta.alpha * (int32_t)(1.732051f * handle->pwm_period) * 2;
|
||||||
wUBeta = -(v.beta * (int32_t)(handle->pwm_period)) * 2;
|
wUBeta = -(handle->Valphabeta.beta * (int32_t)(handle->pwm_period)) * 2;
|
||||||
|
|
||||||
wX = wUBeta;
|
wX = wUBeta;
|
||||||
wY = (wUBeta + wUAlpha) / 2;
|
wY = (wUBeta + wUAlpha) / 2;
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __FOC_SVPWM_H__
|
||||||
|
#define __FOC_SVPWM_H__
|
||||||
|
|
||||||
#include "stm32f407xx.h"
|
#include "stm32f407xx.h"
|
||||||
|
|
||||||
#define SECTOR_1 0u
|
#define SECTOR_1 0u
|
||||||
@ -17,3 +20,4 @@
|
|||||||
#define SECTOR_5 4u
|
#define SECTOR_5 4u
|
||||||
#define SECTOR_6 5u
|
#define SECTOR_6 5u
|
||||||
|
|
||||||
|
#endif /* __FOC_SVPWM_H__ */
|
@ -1,5 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* @file type.h
|
||||||
|
* @author jimingqing
|
||||||
|
* @date 2023-08-29
|
||||||
|
* @version 0.0.1
|
||||||
|
* @copyright XiazhiTech Copyright (c) 2023
|
||||||
|
*
|
||||||
|
* @brief
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __FOC_TYPE_H__
|
||||||
|
#define __FOC_TYPE_H__
|
||||||
|
|
||||||
#include "stm32f407xx.h"
|
#include "stm32f407xx.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Two components q, d type definition
|
* @brief Two components q, d type definition
|
||||||
*/
|
*/
|
||||||
@ -24,3 +39,5 @@ typedef struct
|
|||||||
int16_t alpha;
|
int16_t alpha;
|
||||||
int16_t beta;
|
int16_t beta;
|
||||||
} alphabeta_t;
|
} alphabeta_t;
|
||||||
|
|
||||||
|
#endif /* __FOC_TYPE_H__ */
|
Loading…
Reference in New Issue
Block a user