diff --git a/project/cmake/toolchain-arm-none-eabi.cmake b/project/cmake/toolchain-arm-none-eabi.cmake index 67e0a9d..a3e7a62 100644 --- a/project/cmake/toolchain-arm-none-eabi.cmake +++ b/project/cmake/toolchain-arm-none-eabi.cmake @@ -38,7 +38,9 @@ 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 "${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") diff --git a/src/App/main.c b/src/App/main.c index 66af4d8..3c8aff6 100644 --- a/src/App/main.c +++ b/src/App/main.c @@ -9,7 +9,6 @@ */ /* Includes ------------------------------------------------------------------*/ -#include #include "main.h" @@ -56,13 +55,11 @@ int main(void) // alphabeta_t Valphabeta = math_rev_park(foc_handle.Vqd, hall_handle.control_elec_angle); // // 计算SVPWM输出 // // svmpw() + while (1) { // 测试PWM输出 - // __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 42 * 1000000 / 16000); - - // printf("direction is %d", hall_handle.direction); - + printf("direction is %d\n", hall_handle.direction); led_ctrl(1); HAL_Delay(500); led_ctrl(0); @@ -70,20 +67,37 @@ int main(void) } } -/// 重定向c库函数printf到串口DEBUG_USART,重定向后可使用printf函数 -int fputc(int ch, FILE *f) +#ifdef __GNUC__ +// #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 *)&ch, 1, 0xFFFF); - return (ch); + HAL_UART_Transmit(&huart1, (uint8_t *)ptr, len, 0xFFFF); + fflush(stdout); + return len; } -/// 重定向c库函数scanf到串口DEBUG_USART,重写向后可使用scanf、getchar等函数 -int fgetc(FILE *f) -{ - int ch; - HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, 0xFFFF); - return (ch); -} +#endif + +// /// 重定向c库函数printf到串口DEBUG_USART,重定向后可使用printf函数 +// int fputc(int ch, FILE *f) +// { +// /* 发送一个字节数据到串口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 ---------------------------------------------------------------*/ diff --git a/src/App/main.h b/src/App/main.h index c5134b1..b22c2f8 100644 --- a/src/App/main.h +++ b/src/App/main.h @@ -17,14 +17,14 @@ extern "C" #endif /* Includes ------------------------------------------------------------------*/ - +#include #include "board.h" /* Functions ----------------------------------------------------------------*/ extern hall_handle_t hall_handle; extern foc_handle_t foc_handle; - + extern int _write(int fd, char *ptr, int len); #ifdef __cplusplus } #endif diff --git a/src/Foc/hall.c b/src/Foc/hall.c index 88a0080..01227e1 100644 --- a/src/Foc/hall.c +++ b/src/Foc/hall.c @@ -113,4 +113,5 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state) break; } + handle->state = new_state; } \ No newline at end of file