This commit is contained in:
MQjehovah 2023-09-06 10:28:44 +08:00
parent b600aa6357
commit 7195ddea0a
4 changed files with 37 additions and 20 deletions

View File

@ -38,7 +38,9 @@ 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} --specs=nano.specs -specs=nosys.specs -Wl,--gc-sections,-Map=${PROJECT_NAME}.map,--cref,-u,Reset_Handler -T${LINKER_SCRIPT}")
# LDFLAGS += -lc -lrdimon -u _printf_float
#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")

View File

@ -9,7 +9,6 @@
*/ */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "main.h" #include "main.h"
@ -56,13 +55,11 @@ int main(void)
// alphabeta_t Valphabeta = math_rev_park(foc_handle.Vqd, hall_handle.control_elec_angle); // alphabeta_t Valphabeta = math_rev_park(foc_handle.Vqd, hall_handle.control_elec_angle);
// // 计算SVPWM输出 // // 计算SVPWM输出
// // svmpw() // // svmpw()
while (1) while (1)
{ {
// 测试PWM输出 // 测试PWM输出
// __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 42 * 1000000 / 16000); printf("direction is %d\n", hall_handle.direction);
// printf("direction is %d", hall_handle.direction);
led_ctrl(1); led_ctrl(1);
HAL_Delay(500); HAL_Delay(500);
led_ctrl(0); led_ctrl(0);
@ -70,20 +67,37 @@ int main(void)
} }
} }
/// 重定向c库函数printf到串口DEBUG_USART重定向后可使用printf函数 #ifdef __GNUC__
int fputc(int ch, FILE *f) // #pragma import(__use_no_semihosting)
// void _sys_exit(int x)
// {
// x = x;
// }
int _write(int fd, char *ptr, int len)
{ {
/* 发送一个字节数据到串口DEBUG_USART */ HAL_UART_Transmit(&huart1, (uint8_t *)ptr, len, 0xFFFF);
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); fflush(stdout);
return (ch); return len;
} }
/// 重定向c库函数scanf到串口DEBUG_USART重写向后可使用scanf、getchar等函数 #endif
int fgetc(FILE *f)
{ // /// 重定向c库函数printf到串口DEBUG_USART重定向后可使用printf函数
int ch; // int fputc(int ch, FILE *f)
HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, 0xFFFF); // {
return (ch); // /* 发送一个字节数据到串口DEBUG_USART */
} // HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
// return (ch);
// }
// /// 重定向c库函数scanf到串口DEBUG_USART重写向后可使用scanf、getchar等函数
// int fgetc(FILE *f)
// {
// int ch;
// HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
// return (ch);
// }
/* END OF FILE ---------------------------------------------------------------*/ /* END OF FILE ---------------------------------------------------------------*/

View File

@ -17,14 +17,14 @@ extern "C"
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "board.h" #include "board.h"
/* Functions ----------------------------------------------------------------*/ /* Functions ----------------------------------------------------------------*/
extern hall_handle_t hall_handle; extern hall_handle_t hall_handle;
extern foc_handle_t foc_handle; extern foc_handle_t foc_handle;
extern int _write(int fd, char *ptr, int len);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -113,4 +113,5 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
break; break;
} }
handle->state = new_state;
} }