diff --git a/App/Inc/app_line_seek.h b/App/Inc/app_line_seek.h new file mode 100644 index 0000000..f1d1bf2 --- /dev/null +++ b/App/Inc/app_line_seek.h @@ -0,0 +1,6 @@ +#ifndef __APP_LINE_SEEK_H +#define __APP_LINE_SEEK_H + +void App_LineSeek(void); + +#endif \ No newline at end of file diff --git a/App/Src/app_line_seek.c b/App/Src/app_line_seek.c new file mode 100644 index 0000000..31d27d0 --- /dev/null +++ b/App/Src/app_line_seek.c @@ -0,0 +1,47 @@ + +#include "app_line_seek.h" + +#include "line_seek.h" +#include "main.h" +#include "motor.h" +#include "syscalls.h" + +void App_LineSeek(void) +{ + int LineL1 = 1, LineL2 = 1, LineR1 = 1, LineR2 = 1; + + LineSeek_Get(&LineL1, &LineL2, &LineR1, &LineR2); // 获取黑线检测状态 + + if ((LineL1 == LOW || LineL2 == LOW) && LineR2 == LOW) // 左大弯 + { + MOTOR_SetDuty(-30, 30); // 左旋 + HAL_Delay(80); + } + else if (LineL1 == LOW && (LineR1 == LOW || LineR2 == LOW)) // 右大弯 + { + MOTOR_SetDuty(30, -30); // 右旋 + HAL_Delay(80); + } + else if (LineL1 == LOW) // 左最外侧检测 + { + MOTOR_SetDuty(-50, 50); // 左旋 + HAL_Delay(10); + } + else if (LineR2 == LOW) // 右最外侧检测 + { + MOTOR_SetDuty(50, -50); // 右旋 + HAL_Delay(10); + } + else if (LineL2 == LOW && LineR1 == HIGH) // 中间黑线上的传感器微调车左转 + { + MOTOR_SetDuty(0, 50); // 左转 + } + else if (LineL2 == HIGH && LineR1 == LOW) // 中间黑线上的传感器微调车右转 + { + MOTOR_SetDuty(50, 0); // 右转 + } + else if (LineL2 == LOW && LineR1 == LOW) // 都是黑色, 加速前进 + { + MOTOR_SetDuty(50, 50); // 直走 + } +} diff --git a/CAR.ioc b/CAR.ioc index 6e324ba..d149822 100644 --- a/CAR.ioc +++ b/CAR.ioc @@ -31,34 +31,38 @@ Mcu.IP9=USART2 Mcu.IPNb=10 Mcu.Name=STM32F103C(8-B)Tx Mcu.Package=LQFP48 -Mcu.Pin0=PD0-OSC_IN -Mcu.Pin1=PD1-OSC_OUT -Mcu.Pin10=PB11 -Mcu.Pin11=PA9 -Mcu.Pin12=PA10 -Mcu.Pin13=PA12 -Mcu.Pin14=PA13 -Mcu.Pin15=PA14 -Mcu.Pin16=PA15 -Mcu.Pin17=PB4 -Mcu.Pin18=PB5 -Mcu.Pin19=PB6 -Mcu.Pin2=PA0-WKUP -Mcu.Pin20=PB7 -Mcu.Pin21=PB8 -Mcu.Pin22=PB9 -Mcu.Pin23=VP_SYS_VS_Systick -Mcu.Pin24=VP_TIM2_VS_ClockSourceINT -Mcu.Pin25=VP_TIM3_VS_ClockSourceINT -Mcu.Pin26=VP_TIM4_VS_ClockSourceINT -Mcu.Pin3=PA1 -Mcu.Pin4=PA2 -Mcu.Pin5=PA3 -Mcu.Pin6=PA7 -Mcu.Pin7=PB0 -Mcu.Pin8=PB1 -Mcu.Pin9=PB10 -Mcu.PinsNb=27 +Mcu.Pin0=PC13-TAMPER-RTC +Mcu.Pin1=PC14-OSC32_IN +Mcu.Pin10=PB0 +Mcu.Pin11=PB1 +Mcu.Pin12=PB10 +Mcu.Pin13=PB11 +Mcu.Pin14=PB12 +Mcu.Pin15=PA9 +Mcu.Pin16=PA10 +Mcu.Pin17=PA12 +Mcu.Pin18=PA13 +Mcu.Pin19=PA14 +Mcu.Pin2=PC15-OSC32_OUT +Mcu.Pin20=PA15 +Mcu.Pin21=PB4 +Mcu.Pin22=PB5 +Mcu.Pin23=PB6 +Mcu.Pin24=PB7 +Mcu.Pin25=PB8 +Mcu.Pin26=PB9 +Mcu.Pin27=VP_SYS_VS_Systick +Mcu.Pin28=VP_TIM2_VS_ClockSourceINT +Mcu.Pin29=VP_TIM3_VS_ClockSourceINT +Mcu.Pin3=PD0-OSC_IN +Mcu.Pin30=VP_TIM4_VS_ClockSourceINT +Mcu.Pin4=PD1-OSC_OUT +Mcu.Pin5=PA0-WKUP +Mcu.Pin6=PA1 +Mcu.Pin7=PA2 +Mcu.Pin8=PA3 +Mcu.Pin9=PA7 +Mcu.PinsNb=31 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F103C8Tx @@ -134,6 +138,11 @@ PB11.GPIO_Label=MPU6050_SDA PB11.Locked=true PB11.Mode=I2C PB11.Signal=I2C2_SDA +PB12.GPIOParameters=GPIO_PuPd,GPIO_Label +PB12.GPIO_Label=LineSeek_R2 +PB12.GPIO_PuPd=GPIO_PULLUP +PB12.Locked=true +PB12.Signal=GPIO_Input PB4.GPIOParameters=GPIO_Label PB4.GPIO_Label=R_FORWARD PB4.Locked=true @@ -157,6 +166,21 @@ PB9.GPIOParameters=GPIO_Label PB9.GPIO_Label=L_FORWARD PB9.Locked=true PB9.Signal=GPIO_Output +PC13-TAMPER-RTC.GPIOParameters=GPIO_PuPd,GPIO_Label +PC13-TAMPER-RTC.GPIO_Label=LineSeek_L2 +PC13-TAMPER-RTC.GPIO_PuPd=GPIO_PULLUP +PC13-TAMPER-RTC.Locked=true +PC13-TAMPER-RTC.Signal=GPIO_Input +PC14-OSC32_IN.GPIOParameters=GPIO_PuPd,GPIO_Label +PC14-OSC32_IN.GPIO_Label=LineSeek_L1 +PC14-OSC32_IN.GPIO_PuPd=GPIO_PULLUP +PC14-OSC32_IN.Locked=true +PC14-OSC32_IN.Signal=GPIO_Input +PC15-OSC32_OUT.GPIOParameters=GPIO_PuPd,GPIO_Label +PC15-OSC32_OUT.GPIO_Label=LineSeek_R1 +PC15-OSC32_OUT.GPIO_PuPd=GPIO_PULLUP +PC15-OSC32_OUT.Locked=true +PC15-OSC32_OUT.Signal=GPIO_Input PD0-OSC_IN.Mode=HSE-External-Oscillator PD0-OSC_IN.Signal=RCC_OSC_IN PD1-OSC_OUT.Mode=HSE-External-Oscillator @@ -185,7 +209,7 @@ ProjectManager.ProjectBuild=false ProjectManager.ProjectFileName=CAR.ioc ProjectManager.ProjectName=CAR ProjectManager.ProjectStructure= -ProjectManager.RegisterCallBack=TIM +ProjectManager.RegisterCallBack=TIM,USART ProjectManager.StackSize=0x400 ProjectManager.TargetToolchain=Makefile ProjectManager.ToolChainLocation= @@ -247,12 +271,13 @@ TIM4.Period=100 TIM4.Prescaler=720 - 1 TIM4.Pulse-PWM\ Generation1\ CH1=100 TIM4.Pulse-PWM\ Generation2\ CH2=100 -USART1.BaudRate=115200 +USART1.BaudRate=9600 USART1.IPParameters=VirtualMode,BaudRate,Parity,WordLength USART1.Parity=PARITY_NONE USART1.VirtualMode=VM_ASYNC USART1.WordLength=WORDLENGTH_8B -USART2.IPParameters=VirtualMode +USART2.BaudRate=9600 +USART2.IPParameters=VirtualMode,BaudRate USART2.VirtualMode=VM_ASYNC VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Signal=SYS_VS_Systick diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 495fe9c..27e5206 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -57,6 +57,12 @@ void Error_Handler(void); /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ +#define LineSeek_L2_Pin GPIO_PIN_13 +#define LineSeek_L2_GPIO_Port GPIOC +#define LineSeek_L1_Pin GPIO_PIN_14 +#define LineSeek_L1_GPIO_Port GPIOC +#define LineSeek_R1_Pin GPIO_PIN_15 +#define LineSeek_R1_GPIO_Port GPIOC #define FM_K2_POWERC_Pin GPIO_PIN_0 #define FM_K2_POWERC_GPIO_Port GPIOA #define FAN_GS_Pin GPIO_PIN_1 @@ -71,6 +77,8 @@ void Error_Handler(void); #define MPU6050_SCL_GPIO_Port GPIOB #define MPU6050_SDA_Pin GPIO_PIN_11 #define MPU6050_SDA_GPIO_Port GPIOB +#define LineSeek_R2_Pin GPIO_PIN_12 +#define LineSeek_R2_GPIO_Port GPIOB #define Echo_Pin GPIO_PIN_12 #define Echo_GPIO_Port GPIOA #define Echo_EXTI_IRQn EXTI15_10_IRQn @@ -90,7 +98,8 @@ void Error_Handler(void); #define L_FORWARD_GPIO_Port GPIOB /* USER CODE BEGIN Private defines */ - +#define LOW (0) +#define HIGH (1) /* USER CODE END Private defines */ #ifdef __cplusplus diff --git a/Core/Inc/syscalls.h b/Core/Inc/syscalls.h index 5a1d735..744a463 100644 --- a/Core/Inc/syscalls.h +++ b/Core/Inc/syscalls.h @@ -6,44 +6,14 @@ #include #include #include -#include #include #include +#include "usart.h" #define HUART1 (&huart1) #define HUART2 (&huart2) -extern UART_HandleTypeDef huart1; - -extern int __io_putchar(int ch) __attribute__((weak)); -extern int __io_getchar(void) __attribute__((weak)); - -__attribute__((weak)) int _read(int file, char *ptr, int len) -{ - (void)file; - int DataIdx; - - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - *ptr++ = __io_getchar(); - } - - return len; -} - -__attribute__((weak)) int _write(int file, char *ptr, int len) -{ - (void)file; - int DataIdx; - - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - __io_putchar(*ptr++); - } - return len; -} - -// 条件编译 +// 条件编译,适配不同平台 (GNU, GCC) #ifdef __GNUC__ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #define GETCHAR_PROTOTYPE int __io_getchar(void) @@ -52,58 +22,13 @@ __attribute__((weak)) int _write(int file, char *ptr, int len) #define GETCHAR_PROTOTYPE int fgetc(FILE *f) #endif /* __GNUC__ */ -/** - * @brief 重定向 C 标准库 printf 函数到串口 huart1 - * @author Suroy - * @param ch - * @param f - * @return int - * - * @usage printf("USART1_Target:\r\n"); - */ -PUTCHAR_PROTOTYPE -{ - HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY); // 阻塞式无限等待 - return ch; -} +int _read(int file, char *ptr, int len); +int _write(int file, char *ptr, int len); -/** - * @brief 重定向 c库函数 getchar,scanf到 DEBUG_USARTx - * 重定向 C 标准库 scanf 函数到串口 huart1 - * 注意以 空格 为结束 - * @param f - * @return int - * - * @usage scanf("%c", &RecData); - */ -GETCHAR_PROTOTYPE -{ - uint8_t ch = 0; - HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY); - return ch; -} +PUTCHAR_PROTOTYPE; +GETCHAR_PROTOTYPE; -void delay_us(uint16_t us) -{ - uint32_t delay = (HAL_RCC_GetHCLKFreq() / 4000000 * us); - while (delay--); -} - -/** - * @brief 自定义printf - * @param huart, buf - * @return void - * - * @usage my_printf(HUART1, "USART1_Target:\r\n"); - */ -void my_printf(UART_HandleTypeDef *huart, const char *buf, ...) -{ - char str[255] = {0}; - va_list v; - va_start(v, buf); - vsprintf(str, buf, v); - HAL_UART_Transmit(huart, (const uint8_t *)str, strlen(str), 0xff); - va_end(v); -} +void delay_us(uint16_t us); +void my_printf(UART_HandleTypeDef *huart, const char *buf, ...); #endif diff --git a/Core/Src/main.c b/Core/Src/main.c index 6934fe1..c01329c 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -27,6 +27,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "bluetooth.h" #include "hcsr04.h" #include "led.h" #include "motor.h" @@ -72,7 +73,8 @@ void SystemClock_Config(void); * @brief The application entry point. * @retval int */ -int main(void) { +int main(void) +{ /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ @@ -102,9 +104,9 @@ int main(void) { MX_TIM4_Init(); MX_USART2_UART_Init(); MX_USART1_UART_Init(); - /* USER CODE BEGIN 2 */ HC_SR04_Init(); + BLUETOOTH_Init(); /* USER CODE BEGIN 2 */ @@ -112,14 +114,14 @@ int main(void) { /* Infinite loop */ /* USER CODE BEGIN WHILE */ - while (1) { - printf("test\n"); + while (1) + { + my_printf(HUART1, "test huart1 \r\n"); + my_printf(HUART2, "test huart2\r\n"); - if (sonor_state == 0) { - sonar_mm(); - } + // App_LineSeek(); - HAL_Delay(300); // 延时300毫秒 + // HAL_Delay(300); // 延时300毫秒 /* USER CODE END WHILE */ @@ -132,7 +134,8 @@ int main(void) { * @brief System Clock Configuration * @retval None */ -void SystemClock_Config(void) { +void SystemClock_Config(void) +{ RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; @@ -146,7 +149,8 @@ void SystemClock_Config(void) { RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { Error_Handler(); } @@ -158,7 +162,8 @@ void SystemClock_Config(void) { RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) + { Error_Handler(); } } @@ -171,11 +176,13 @@ void SystemClock_Config(void) { * @brief This function is executed in case of error occurrence. * @retval None */ -void Error_Handler(void) { +void Error_Handler(void) +{ /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); - while (1) { + while (1) + { } /* USER CODE END Error_Handler_Debug */ } @@ -188,7 +195,8 @@ void Error_Handler(void) { * @param line: assert_param error line source number * @retval None */ -void assert_failed(uint8_t *file, uint32_t line) { +void assert_failed(uint8_t *file, uint32_t line) +{ /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ diff --git a/Core/Src/syscalls.c b/Core/Src/syscalls.c index e33a849..970afaa 100644 --- a/Core/Src/syscalls.c +++ b/Core/Src/syscalls.c @@ -1,176 +1,86 @@ -/** - ****************************************************************************** - * @file syscalls.c - * @author Auto-generated by STM32CubeMX - * @brief Minimal System calls file - * - * For more information about which c-functions - * need which of these lowlevel functions - * please consult the Newlib libc-manual - ****************************************************************************** - * @attention - * - * Copyright (c) 2020-2024 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* Includes */ -#include -#include -#include -#include -#include -#include -#include -#include +#include "syscalls.h" +extern UART_HandleTypeDef huart1; -/* Variables */ -extern int __io_putchar(int ch) __attribute__((weak)); -extern int __io_getchar(void) __attribute__((weak)); - - -char *__env[1] = { 0 }; -char **environ = __env; - - -/* Functions */ -void initialise_monitor_handles() -{ -} - -int _getpid(void) -{ - return 1; -} - -int _kill(int pid, int sig) -{ - (void)pid; - (void)sig; - errno = EINVAL; - return -1; -} - -void _exit (int status) -{ - _kill(status, -1); - while (1) {} /* Make sure we hang here */ -} - +// 条件编译,适配不同平台 (GNU, GCC) +#ifdef __GNUC__ __attribute__((weak)) int _read(int file, char *ptr, int len) { - (void)file; - int DataIdx; + (void)file; + int DataIdx; - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - *ptr++ = __io_getchar(); - } + for (DataIdx = 0; DataIdx < len; DataIdx++) + { + *ptr++ = __io_getchar(); + } - return len; + return len; } __attribute__((weak)) int _write(int file, char *ptr, int len) { - (void)file; - int DataIdx; + (void)file; + int DataIdx; - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - __io_putchar(*ptr++); - } - return len; + for (DataIdx = 0; DataIdx < len; DataIdx++) + { + __io_putchar(*ptr++); + } + return len; } +#endif -int _close(int file) +/** + * @brief 重定向 C 标准库 printf 函数到串口 huart1 + * @author Suroy + * @param ch + * @param f + * @return int + * + * @usage printf("USART1_Target:\r\n"); + */ +PUTCHAR_PROTOTYPE { - (void)file; - return -1; + HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY); // 阻塞式无限等待 + return ch; } - -int _fstat(int file, struct stat *st) +/** + * @brief 重定向 c库函数 getchar,scanf到 DEBUG_USARTx + * 重定向 C 标准库 scanf 函数到串口 huart1 + * 注意以 空格 为结束 + * @param f + * @return int + * + * @usage scanf("%c", &RecData); + */ +GETCHAR_PROTOTYPE { - (void)file; - st->st_mode = S_IFCHR; - return 0; + uint8_t ch = 0; + HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY); + return ch; } -int _isatty(int file) +void delay_us(uint16_t us) { - (void)file; - return 1; + uint32_t delay = (HAL_RCC_GetHCLKFreq() / 4000000 * us); + while (delay--); } -int _lseek(int file, int ptr, int dir) +/** + * @brief 自定义printf + * @param huart, buf + * @return void + * + * @usage my_printf(HUART1, "USART1_Target:\r\n"); + */ +void my_printf(UART_HandleTypeDef *huart, const char *buf, ...) { - (void)file; - (void)ptr; - (void)dir; - return 0; -} - -int _open(char *path, int flags, ...) -{ - (void)path; - (void)flags; - /* Pretend like we always fail */ - return -1; -} - -int _wait(int *status) -{ - (void)status; - errno = ECHILD; - return -1; -} - -int _unlink(char *name) -{ - (void)name; - errno = ENOENT; - return -1; -} - -int _times(struct tms *buf) -{ - (void)buf; - return -1; -} - -int _stat(char *file, struct stat *st) -{ - (void)file; - st->st_mode = S_IFCHR; - return 0; -} - -int _link(char *old, char *new) -{ - (void)old; - (void)new; - errno = EMLINK; - return -1; -} - -int _fork(void) -{ - errno = EAGAIN; - return -1; -} - -int _execve(char *name, char **argv, char **env) -{ - (void)name; - (void)argv; - (void)env; - errno = ENOMEM; - return -1; + char str[255] = {0}; + va_list v; + va_start(v, buf); + vsprintf(str, buf, v); + HAL_UART_Transmit(huart, (const uint8_t *)str, strlen(str), 0xff); + va_end(v); } diff --git a/MDK-ARM/CAR.uvguix.lenovo b/MDK-ARM/CAR.uvguix.lenovo index 0550102..ac660df 100644 --- a/MDK-ARM/CAR.uvguix.lenovo +++ b/MDK-ARM/CAR.uvguix.lenovo @@ -110,8 +110,8 @@ 0 - 533 - 01000000040000000100000001000000010000000100000000000000020000000000000001000000010000000000000028000000280000000100000003000000010000000100000061443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C436F72655C5372635C73797374656D5F73746D3332663178782E63000000001273797374656D5F73746D3332663178782E6300000000C5D4F200FFFFFFFF55443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C436F72655C5372635C6D61696E2E6300000000066D61696E2E6300000000FFDC7800FFFFFFFF5A443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C557365725C5372635C626C7565746F6F74682E63000000000B626C7565746F6F74682E6300000000BECEA100FFFFFFFF0100000010000000C5D4F200FFDC7800BECEA100F0A0A100BCA8E1009CC1B600F7B88600D9ADC200A5C2D700B3A6BE00EAD6A300F6FA7D00B5E99D005FC3CF00C1838300CACAD500010000000000000002000000F300000066000000B705000020020000 + 1348 + 01000000040000000100000001000000010000000100000000000000020000000000000001000000010000000000000028000000280000000100000008000000010000000100000061443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C436F72655C5372635C73797374656D5F73746D3332663178782E63000000001273797374656D5F73746D3332663178782E6300000000C5D4F200FFFFFFFF55443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C436F72655C5372635C6D61696E2E6300000000066D61696E2E6300000000FFDC7800FFFFFFFF5A443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C557365725C5372635C626C7565746F6F74682E63000000000B626C7565746F6F74682E6300000000BECEA100FFFFFFFF7D443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C447269766572735C53544D3332463178785F48414C5F4472697665725C496E635C73746D3332663178785F68616C5F7263635F65782E68000000001673746D3332663178785F68616C5F7263635F65782E6800000000F0A0A100FFFFFFFF7C443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C447269766572735C53544D3332463178785F48414C5F4472697665725C496E635C73746D3332663178785F68616C5F666C6173682E68000000001573746D3332663178785F68616C5F666C6173682E6800000000BCA8E100FFFFFFFF7F443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C447269766572735C53544D3332463178785F48414C5F4472697665725C496E635C73746D3332663178785F68616C5F666C6173685F65782E68000000001873746D3332663178785F68616C5F666C6173685F65782E68000000009CC1B600FFFFFFFF7A443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C447269766572735C53544D3332463178785F48414C5F4472697665725C496E635C73746D3332663178785F68616C5F646D612E68000000001373746D3332663178785F68616C5F646D612E6800000000F7B88600FFFFFFFF7A443A5C4F6E6544726976655C4F6E654472697665202D206D792E73776A74752E6564752E636E5C446174615C70726F6772616D20636F64655C50726F6A656374735C4361725C447269766572735C53544D3332463178785F48414C5F4472697665725C496E635C73746D3332663178785F68616C5F7263632E68000000001373746D3332663178785F68616C5F7263632E6800000000D9ADC200FFFFFFFF0100000010000000C5D4F200FFDC7800BECEA100F0A0A100BCA8E1009CC1B600F7B88600D9ADC200A5C2D700B3A6BE00EAD6A300F6FA7D00B5E99D005FC3CF00C1838300CACAD500010000000000000002000000F300000066000000B705000020020000 @@ -1806,7 +1806,7 @@ File 2580 - 00200000010000002800FFFF01001100434D4643546F6F6C426172427574746F6E00E100000000000000000000000000000000000000000000000100000001000000018001E100000000000001000000000000000000000000000000000100000001000000018003E1000000000000020000000000000000000000000000000001000000010000000180CD7F0000000000000300000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000018023E100000000040004000000000000000000000000000000000100000001000000018022E100000000040005000000000000000000000000000000000100000001000000018025E10000000000000600000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001802BE10000000000000700000000000000000000000000000000010000000100000001802CE10000000004000800000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001807A8A0000000000000900000000000000000000000000000000010000000100000001807B8A0000000004000A00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180D3B00000000000000B000000000000000000000000000000000100000001000000018015B10000000004000C0000000000000000000000000000000001000000010000000180F4B00000000004000D000000000000000000000000000000000100000001000000018036B10000000004000E00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180FF88000000000400460000000000000000000000000000000001000000010000000180FE880000000004004500000000000000000000000000000000010000000100000001800B810000000004001300000000000000000000000000000000010000000100000001800C810000000004001400000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180F0880000020000000F000000000000000000000000000000000100000001000000FFFF0100120043555646696E64436F6D626F427574746F6EE803000000000000000000000000000000000000000000000001000000010000009600000002002050000000001348414C5F54494D5F4D7370506F7374496E6974960000000000000001001348414C5F54494D5F4D7370506F7374496E697400000000018024E10000000000001100000000000000000000000000000000010000000100000001800A810000000000001200000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6E2280000002000000150000002153746172742F53746F70202644656275672053657373696F6E094374726C2B46350000000000000000000000000100000001000000000000000000000001000000020021802280000000000000150000002153746172742F53746F70202644656275672053657373696F6E094374726C2B4635000000000000000000000000010000000100000000000000000000000100000000002180E0010000000000007500000021456E65726779204D6561737572656D656E742026776974686F75742044656275670000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180C488000000000000160000000000000000000000000000000001000000010000000180C988000000000400180000000000000000000000000000000001000000010000000180C788000000000000190000000000000000000000000000000001000000010000002180C8880000000000001700000027264B696C6C20416C6C20427265616B706F696E747320696E2043757272656E7420546172676574000000000000000000000000010000000100000000000000000000000100000003002180C8880000000000001700000027264B696C6C20416C6C20427265616B706F696E747320696E2043757272656E7420546172676574000000000000000000000000010000000100000000000000000000000100000000002180E50100000000000078000000264B696C6C20416C6C20427265616B706F696E747320696E204163746976652050726F6A656374000000000000000000000000010000000100000000000000000000000100000000002180E601000000000000790000002F4B696C6C20416C6C20427265616B706F696E747320696E204D756C74692D50726F6A65637420576F726B73706163650000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000021804C010000020001001A0000000F2650726F6A6563742057696E646F77000000000000000000000000010000000100000000000000000000000100000008002180DD880000000000001A0000000750726F6A656374000000000000000000000000010000000100000000000000000000000100000000002180DC8B0000000000003A00000005426F6F6B73000000000000000000000000010000000100000000000000000000000100000000002180E18B0000000000003B0000000946756E6374696F6E73000000000000000000000000010000000100000000000000000000000100000000002180E28B000000000000400000000954656D706C6174657300000000000000000000000001000000010000000000000000000000010000000000218018890000000000003D0000000E536F757263652042726F777365720000000000000000000000000100000001000000000000000000000001000000000021800000000000000400FFFFFFFF00000000000000000001000000000000000100000000000000000000000100000000002180D988000000000000390000000C4275696C64204F7574707574000000000000000000000000010000000100000000000000000000000100000000002180E38B000000000000410000000B46696E64204F75747075740000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180FB7F0000000000001B000000000000000000000000000000000100000001000000000000000446696C65C6030000 + 00200000010000002800FFFF01001100434D4643546F6F6C426172427574746F6E00E100000000000000000000000000000000000000000000000100000001000000018001E100000000000001000000000000000000000000000000000100000001000000018003E1000000000000020000000000000000000000000000000001000000010000000180CD7F0000000000000300000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000018023E100000000040004000000000000000000000000000000000100000001000000018022E100000000040005000000000000000000000000000000000100000001000000018025E10000000000000600000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001802BE10000000004000700000000000000000000000000000000010000000100000001802CE10000000004000800000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001807A8A0000000000000900000000000000000000000000000000010000000100000001807B8A0000000004000A00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180D3B00000000000000B000000000000000000000000000000000100000001000000018015B10000000004000C0000000000000000000000000000000001000000010000000180F4B00000000004000D000000000000000000000000000000000100000001000000018036B10000000004000E00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180FF88000000000400460000000000000000000000000000000001000000010000000180FE880000000004004500000000000000000000000000000000010000000100000001800B810000000004001300000000000000000000000000000000010000000100000001800C810000000004001400000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180F0880000020000000F000000000000000000000000000000000100000001000000FFFF0100120043555646696E64436F6D626F427574746F6EE803000000000000000000000000000000000000000000000001000000010000009600000002002050000000001348414C5F54494D5F4D7370506F7374496E6974960000000000000001001348414C5F54494D5F4D7370506F7374496E697400000000018024E10000000000001100000000000000000000000000000000010000000100000001800A810000000000001200000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6E2280000002000000150000002153746172742F53746F70202644656275672053657373696F6E094374726C2B46350000000000000000000000000100000001000000000000000000000001000000020021802280000000000000150000002153746172742F53746F70202644656275672053657373696F6E094374726C2B4635000000000000000000000000010000000100000000000000000000000100000000002180E0010000000000007500000021456E65726779204D6561737572656D656E742026776974686F75742044656275670000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180C488000000000000160000000000000000000000000000000001000000010000000180C988000000000400180000000000000000000000000000000001000000010000000180C788000000000000190000000000000000000000000000000001000000010000002180C8880000000000001700000027264B696C6C20416C6C20427265616B706F696E747320696E2043757272656E7420546172676574000000000000000000000000010000000100000000000000000000000100000003002180C8880000000000001700000027264B696C6C20416C6C20427265616B706F696E747320696E2043757272656E7420546172676574000000000000000000000000010000000100000000000000000000000100000000002180E50100000000000078000000264B696C6C20416C6C20427265616B706F696E747320696E204163746976652050726F6A656374000000000000000000000000010000000100000000000000000000000100000000002180E601000000000000790000002F4B696C6C20416C6C20427265616B706F696E747320696E204D756C74692D50726F6A65637420576F726B73706163650000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000021804C010000020001001A0000000F2650726F6A6563742057696E646F77000000000000000000000000010000000100000000000000000000000100000008002180DD880000000000001A0000000750726F6A656374000000000000000000000000010000000100000000000000000000000100000000002180DC8B0000000000003A00000005426F6F6B73000000000000000000000000010000000100000000000000000000000100000000002180E18B0000000000003B0000000946756E6374696F6E73000000000000000000000000010000000100000000000000000000000100000000002180E28B000000000000400000000954656D706C6174657300000000000000000000000001000000010000000000000000000000010000000000218018890000000000003D0000000E536F757263652042726F777365720000000000000000000000000100000001000000000000000000000001000000000021800000000000000400FFFFFFFF00000000000000000001000000000000000100000000000000000000000100000000002180D988000000000000390000000C4275696C64204F7574707574000000000000000000000000010000000100000000000000000000000100000000002180E38B000000000000410000000B46696E64204F75747075740000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180FB7F0000000000001B000000000000000000000000000000000100000001000000000000000446696C65C6030000 1423 @@ -1822,7 +1822,7 @@ Build 966 - 00200000010000001000FFFF01001100434D4643546F6F6C426172427574746F6ECF7F0000000000001C0000000000000000000000000000000001000000010000000180D07F0000000002001D000000000000000000000000000000000100000001000000018030800000000000001E000000000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6EC7040000000000006A0000000C4261746368204275696C2664000000000000000000000000010000000100000000000000000000000100000004000580C7040000000000006A0000000C4261746368204275696C266400000000000000000000000001000000010000000000000000000000010000000000058046070000000000006B0000000D42617463682052656275696C640000000000000000000000000100000001000000000000000000000001000000000005804707000000000000FFFFFFFF0B426174636820436C65616E0100000000000000000000000100000001000000000000000000000001000000000005809E8A0000000000001F0000000F4261746326682053657475702E2E2E000000000000000000000000010000000100000000000000000000000100000000000180D17F0000000004002000000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001804C8A0000000000002100000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000FFFF01001900434D4643546F6F6C426172436F6D626F426F78427574746F6EBA0000000000000000000000000000000000000000000000000100000001000000960000000300205000000000034341529600000000000000010003434152000000000180EB880000000000002200000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180C07F000000000000230000000000000000000000000000000001000000010000000180B08A000000000400240000000000000000000000000000000001000000010000000180A8010000000000004E00000000000000000000000000000000010000000100000001807202000000000000530000000000000000000000000000000001000000010000000180BE010000000000005000000000000000000000000000000000010000000100000000000000054275696C64DC010000 + 00200000010000001000FFFF01001100434D4643546F6F6C426172427574746F6ECF7F0000000000001C0000000000000000000000000000000001000000010000000180D07F0000000000001D000000000000000000000000000000000100000001000000018030800000000002001E000000000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6EC7040000000000006A0000000C4261746368204275696C2664000000000000000000000000010000000100000000000000000000000100000004000580C7040000000000006A0000000C4261746368204275696C266400000000000000000000000001000000010000000000000000000000010000000000058046070000000000006B0000000D42617463682052656275696C640000000000000000000000000100000001000000000000000000000001000000000005804707000000000000FFFFFFFF0B426174636820436C65616E0100000000000000000000000100000001000000000000000000000001000000000005809E8A0000000000001F0000000F4261746326682053657475702E2E2E000000000000000000000000010000000100000000000000000000000100000000000180D17F0000000004002000000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001804C8A0000000000002100000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000FFFF01001900434D4643546F6F6C426172436F6D626F426F78427574746F6EBA0000000000000000000000000000000000000000000000000100000001000000960000000300205000000000034341529600000000000000010003434152000000000180EB880000000000002200000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180C07F000000000000230000000000000000000000000000000001000000010000000180B08A000000000400240000000000000000000000000000000001000000010000000180A8010000000000004E00000000000000000000000000000000010000000100000001807202000000000000530000000000000000000000000000000001000000010000000180BE010000000000005000000000000000000000000000000000010000000100000000000000054275696C64DC010000 583 @@ -1874,18 +1874,63 @@ ../Core/Src/main.c - 9 - 104 - 125 + 0 + 106 + 114 1 0 ..\User\Src\bluetooth.c - 25 - 17 - 28 + 0 + 42 + 64 + 1 + + 0 + + + ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h + 0 + 1835 + 1857 + 1 + + 0 + + + ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h + 0 + 254 + 274 + 1 + + 0 + + + ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h + 0 + 726 + 748 + 1 + + 0 + + + ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h + 0 + 354 + 376 + 1 + + 0 + + + ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h + 0 + 1132 + 1154 1 0 diff --git a/MDK-ARM/CAR.uvoptx b/MDK-ARM/CAR.uvoptx index 283f72d..2c48a98 100644 --- a/MDK-ARM/CAR.uvoptx +++ b/MDK-ARM/CAR.uvoptx @@ -344,7 +344,7 @@ - Application/User/Core + Core 1 0 0 @@ -445,6 +445,18 @@ 0 0 + + 2 + 10 + 1 + 0 + 0 + 0 + ..\Core\Src\syscalls.c + syscalls.c + 0 + 0 + @@ -455,7 +467,7 @@ 0 3 - 10 + 11 1 0 0 @@ -467,7 +479,7 @@ 3 - 11 + 12 1 0 0 @@ -479,7 +491,7 @@ 3 - 12 + 13 1 0 0 @@ -491,7 +503,7 @@ 3 - 13 + 14 1 0 0 @@ -503,7 +515,7 @@ 3 - 14 + 15 1 0 0 @@ -515,7 +527,7 @@ 3 - 15 + 16 1 0 0 @@ -527,7 +539,7 @@ 3 - 16 + 17 1 0 0 @@ -539,7 +551,7 @@ 3 - 17 + 18 1 0 0 @@ -551,7 +563,7 @@ 3 - 18 + 19 1 0 0 @@ -563,7 +575,7 @@ 3 - 19 + 20 1 0 0 @@ -575,7 +587,7 @@ 3 - 20 + 21 1 0 0 @@ -587,7 +599,7 @@ 3 - 21 + 22 1 0 0 @@ -599,7 +611,7 @@ 3 - 22 + 23 1 0 0 @@ -611,7 +623,7 @@ 3 - 23 + 24 1 0 0 @@ -623,7 +635,7 @@ 3 - 24 + 25 1 0 0 @@ -643,7 +655,7 @@ 0 4 - 25 + 26 1 0 0 @@ -656,14 +668,14 @@ - Application/User/Service + User 1 0 0 0 5 - 26 + 27 1 0 0 @@ -675,7 +687,7 @@ 5 - 27 + 28 1 0 0 @@ -687,7 +699,7 @@ 5 - 28 + 29 1 0 0 @@ -699,7 +711,7 @@ 5 - 29 + 30 1 0 0 @@ -711,7 +723,7 @@ 5 - 30 + 31 1 0 0 @@ -721,6 +733,38 @@ 0 0 + + 5 + 32 + 1 + 0 + 0 + 0 + ..\User\Src\line_seek.c + line_seek.c + 0 + 0 + + + + + App + 0 + 0 + 0 + 0 + + 6 + 33 + 1 + 0 + 0 + 0 + ..\App\Src\app_line_seek.c + app_line_seek.c + 0 + 0 + diff --git a/MDK-ARM/CAR.uvprojx b/MDK-ARM/CAR.uvprojx index 8f96e6a..2bbd6d4 100644 --- a/MDK-ARM/CAR.uvprojx +++ b/MDK-ARM/CAR.uvprojx @@ -339,7 +339,7 @@ USE_HAL_DRIVER,STM32F103xB - ../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;../User/Inc + ../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;../User/Inc;../App/Inc @@ -391,7 +391,7 @@ - Application/User/Core + Core main.c @@ -484,6 +484,11 @@ 1 ../Core/Src/stm32f1xx_hal_msp.c + + syscalls.c + 1 + ..\Core\Src\syscalls.c + @@ -577,7 +582,7 @@ - Application/User/Service + User bluetooth.c @@ -604,6 +609,21 @@ 1 ..\User\Src\motor.c + + line_seek.c + 1 + ..\User\Src\line_seek.c + + + + + App + + + app_line_seek.c + 1 + ..\App\Src\app_line_seek.c + diff --git a/Makefile b/Makefile index efa4cc4..616ba71 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ C_SOURCES = \ Core/Src/main.c \ Core/Src/gpio.c \ Core/Src/i2c.c \ +Core/Src/syscalls.c \ Core/Src/tim.c \ Core/Src/dma.c \ Core/Src/usart.c \ @@ -61,12 +62,13 @@ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \ Core/Src/system_stm32f1xx.c \ Core/Src/sysmem.c \ -Core/Src/hcsr04.c \ -Core/Src/motor.c \ -Core/Src/led.c \ -Core/Src/syscalls.c \ -Core/Src/bluetooth.c \ -Core/Src/control.c +User/Src/hcsr04.c \ +User/Src/motor.c \ +User/Src/led.c \ +User/Src/bluetooth.c \ +User/Src/control.c \ +User/Src/line_seek.c \ +App/Src/app_line_seek.c # ASM sources ASM_SOURCES = \ @@ -127,6 +129,8 @@ AS_INCLUDES = # C includes C_INCLUDES = \ -ICore/Inc \ +-IUser/Inc \ +-IApp/Inc \ -IDrivers/STM32F1xx_HAL_Driver/Inc \ -IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \ -IDrivers/CMSIS/Device/ST/STM32F1xx/Include \ diff --git a/User/Inc/line_seek.h b/User/Inc/line_seek.h new file mode 100644 index 0000000..1ff2bdb --- /dev/null +++ b/User/Inc/line_seek.h @@ -0,0 +1,7 @@ +#ifndef __LINE_SEEK_H__ +#define __LINE_SEEK_H__ + +// 获取巡线状态 +void LineSeek_Get(int *p_iL1, int *p_iL2, int *p_iR1, int *p_iR2); + +#endif \ No newline at end of file diff --git a/User/Src/line_seek.c b/User/Src/line_seek.c new file mode 100644 index 0000000..4c16608 --- /dev/null +++ b/User/Src/line_seek.c @@ -0,0 +1,17 @@ + +#include "line_seek.h" + +#include "main.h" + +/** + * @brief 获取巡线状态 + * @param[in] int *p_iL1, int *p_iL2, int *p_iR1, int *p_iR2 四路巡线位指针 + * @retval void + */ +void LineSeek_Get(int *p_iL1, int *p_iL2, int *p_iR1, int *p_iR2) +{ + *p_iL1 = HAL_GPIO_ReadPin(LineSeek_L1_GPIO_Port, LineSeek_L1_Pin); + *p_iL2 = HAL_GPIO_ReadPin(LineSeek_L2_GPIO_Port, LineSeek_L2_Pin); + *p_iR1 = HAL_GPIO_ReadPin(LineSeek_R1_GPIO_Port, LineSeek_R1_Pin); + *p_iR2 = HAL_GPIO_ReadPin(LineSeek_R2_GPIO_Port, LineSeek_R2_Pin); +}