From ea6163a48dae2096cbda59bef0da32040a4ed797 Mon Sep 17 00:00:00 2001 From: chenfu <2412777093@qq.com> Date: Thu, 22 Jun 2023 16:22:38 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E7=A7=BB=E6=A4=8D=E5=AE=98=E6=96=B9C?= =?UTF-8?q?=E6=9D=BFflahs=E4=BE=8B=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 1 + bsp/log/bsp_flash.c | 289 ++++++++++++++++++++++++++++++++++++++++++++ bsp/log/bsp_flash.h | 80 ++++++++++++ 3 files changed, 370 insertions(+) create mode 100644 bsp/log/bsp_flash.c create mode 100644 bsp/log/bsp_flash.h diff --git a/Makefile b/Makefile index 96a72d2..c9c229f 100644 --- a/Makefile +++ b/Makefile @@ -119,6 +119,7 @@ bsp/can/bsp_can.c \ bsp/usart/bsp_usart.c \ bsp/usb/bsp_usb.c \ bsp/log/bsp_log.c \ +bsp/log/bsp_flash.c \ bsp/bsp_init.c \ modules/algorithm/controller.c \ modules/algorithm/kalman_filter.c \ diff --git a/bsp/log/bsp_flash.c b/bsp/log/bsp_flash.c new file mode 100644 index 0000000..dfdf9a9 --- /dev/null +++ b/bsp/log/bsp_flash.c @@ -0,0 +1,289 @@ +#include "bsp_flash.h" +#include "main.h" +#include "string.h" + +static uint32_t ger_sector(uint32_t address); + +/** + * @brief erase flash + * @param[in] address: flash address + * @param[in] len: page num + * @retval none + */ +/** + * @brief 擦除flash + * @param[in] address: flash 地址 + * @param[in] len: 页数量 + * @retval none + */ +void flash_erase_address(uint32_t address, uint16_t len) +{ + FLASH_EraseInitTypeDef flash_erase; + uint32_t error; + + flash_erase.Sector = ger_sector(address); + flash_erase.TypeErase = FLASH_TYPEERASE_SECTORS; + flash_erase.VoltageRange = FLASH_VOLTAGE_RANGE_3; + flash_erase.NbSectors = len; + + HAL_FLASH_Unlock(); + HAL_FLASHEx_Erase(&flash_erase, &error); + HAL_FLASH_Lock(); +} + +/** + * @brief write data to one page of flash + * @param[in] start_address: flash address + * @param[in] buf: data point + * @param[in] len: data num + * @retval success 0, fail -1 + */ +/** + * @brief 往一页flash写数据 + * @param[in] start_address: flash 地址 + * @param[in] buf: 数据指针 + * @param[in] len: 数据长度 + * @retval success 0, fail -1 + */ +int8_t flash_write_single_address(uint32_t start_address, uint32_t *buf, uint32_t len) +{ + static uint32_t uw_address; + static uint32_t end_address; + static uint32_t *data_buf; + static uint32_t data_len; + + HAL_FLASH_Unlock(); + + uw_address = start_address; + end_address = get_next_flash_address(start_address); + data_buf = buf; + data_len = 0; + + while (uw_address <= end_address) + { + + if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,uw_address, *data_buf) == HAL_OK) + { + uw_address += 4; + data_buf++; + data_len++; + if (data_len == len) + { + break; + } + } + else + { + HAL_FLASH_Lock(); + return -1; + } + } + + HAL_FLASH_Lock(); + return 0; +} + +/** + * @brief write data to some pages of flash + * @param[in] start_address: flash start address + * @param[in] end_address: flash end address + * @param[in] buf: data point + * @param[in] len: data num + * @retval success 0, fail -1 + */ +/** + * @brief 往几页flash写数据 + * @param[in] start_address: flash 开始地址 + * @param[in] end_address: flash 结束地址 + * @param[in] buf: 数据指针 + * @param[in] len: 数据长度 + * @retval success 0, fail -1 + */ +int8_t flash_write_muli_address(uint32_t start_address, uint32_t end_address, uint32_t *buf, uint32_t len) +{ + uint32_t uw_address = 0; + uint32_t *data_buf; + uint32_t data_len; + + HAL_FLASH_Unlock(); + + uw_address = start_address; + data_buf = buf; + data_len = 0; + while (uw_address <= end_address) + { + if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,uw_address, *data_buf) == HAL_OK) + { + uw_address += 4; + data_buf++; + data_len++; + if (data_len == len) + { + break; + } + } + else + { + HAL_FLASH_Lock(); + return -1; + } + } + + HAL_FLASH_Lock(); + return 0; +} + + +/** + * @brief read data for flash + * @param[in] address: flash address + * @param[out] buf: data point + * @param[in] len: data num + * @retval none + */ +/** + * @brief 从flash读数据 + * @param[in] start_address: flash 地址 + * @param[out] buf: 数据指针 + * @param[in] len: 数据长度 + * @retval none + */ +void flash_read(uint32_t address, uint32_t *buf, uint32_t len) +{ + memcpy(buf, (void*)address, len *4); +} + + +/** + * @brief get the sector number of flash + * @param[in] address: flash address + * @retval sector number + */ +/** + * @brief 获取flash的sector号 + * @param[in] address: flash 地址 + * @retval sector号 + */ +static uint32_t ger_sector(uint32_t address) +{ + uint32_t sector = 0; + if ((address < ADDR_FLASH_SECTOR_1) && (address >= ADDR_FLASH_SECTOR_0)) + { + sector = FLASH_SECTOR_0; + } + else if ((address < ADDR_FLASH_SECTOR_2) && (address >= ADDR_FLASH_SECTOR_1)) + { + sector = FLASH_SECTOR_1; + } + else if ((address < ADDR_FLASH_SECTOR_3) && (address >= ADDR_FLASH_SECTOR_2)) + { + sector = FLASH_SECTOR_2; + } + else if ((address < ADDR_FLASH_SECTOR_4) && (address >= ADDR_FLASH_SECTOR_3)) + { + sector = FLASH_SECTOR_3; + } + else if ((address < ADDR_FLASH_SECTOR_5) && (address >= ADDR_FLASH_SECTOR_4)) + { + sector = FLASH_SECTOR_4; + } + else if ((address < ADDR_FLASH_SECTOR_6) && (address >= ADDR_FLASH_SECTOR_5)) + { + sector = FLASH_SECTOR_5; + } + else if ((address < ADDR_FLASH_SECTOR_7) && (address >= ADDR_FLASH_SECTOR_6)) + { + sector = FLASH_SECTOR_6; + } + else if ((address < ADDR_FLASH_SECTOR_8) && (address >= ADDR_FLASH_SECTOR_7)) + { + sector = FLASH_SECTOR_7; + } + else if ((address < ADDR_FLASH_SECTOR_9) && (address >= ADDR_FLASH_SECTOR_8)) + { + sector = FLASH_SECTOR_8; + } + else if ((address < ADDR_FLASH_SECTOR_10) && (address >= ADDR_FLASH_SECTOR_9)) + { + sector = FLASH_SECTOR_9; + } + else if ((address < ADDR_FLASH_SECTOR_11) && (address >= ADDR_FLASH_SECTOR_10)) + { + sector = FLASH_SECTOR_10; + } + else if ((address < ADDR_FLASH_SECTOR_12) && (address >= ADDR_FLASH_SECTOR_11)) + { + sector = FLASH_SECTOR_11; + } + else + { + sector = FLASH_SECTOR_11; + } + + return sector; +} + +/** + * @brief get the next page flash address + * @param[in] address: flash address + * @retval next page flash address + */ +/** + * @brief 获取下一页flash地址 + * @param[in] address: flash 地址 + * @retval 下一页flash地址 + */ +uint32_t get_next_flash_address(uint32_t address) +{ + uint32_t sector = 0; + + if ((address < ADDR_FLASH_SECTOR_1) && (address >= ADDR_FLASH_SECTOR_0)) + { + sector = ADDR_FLASH_SECTOR_1; + } + else if ((address < ADDR_FLASH_SECTOR_2) && (address >= ADDR_FLASH_SECTOR_1)) + { + sector = ADDR_FLASH_SECTOR_2; + } + else if ((address < ADDR_FLASH_SECTOR_3) && (address >= ADDR_FLASH_SECTOR_2)) + { + sector = ADDR_FLASH_SECTOR_3; + } + else if ((address < ADDR_FLASH_SECTOR_4) && (address >= ADDR_FLASH_SECTOR_3)) + { + sector = ADDR_FLASH_SECTOR_4; + } + else if ((address < ADDR_FLASH_SECTOR_5) && (address >= ADDR_FLASH_SECTOR_4)) + { + sector = ADDR_FLASH_SECTOR_5; + } + else if ((address < ADDR_FLASH_SECTOR_6) && (address >= ADDR_FLASH_SECTOR_5)) + { + sector = ADDR_FLASH_SECTOR_6; + } + else if ((address < ADDR_FLASH_SECTOR_7) && (address >= ADDR_FLASH_SECTOR_6)) + { + sector = ADDR_FLASH_SECTOR_7; + } + else if ((address < ADDR_FLASH_SECTOR_8) && (address >= ADDR_FLASH_SECTOR_7)) + { + sector = ADDR_FLASH_SECTOR_8; + } + else if ((address < ADDR_FLASH_SECTOR_9) && (address >= ADDR_FLASH_SECTOR_8)) + { + sector = ADDR_FLASH_SECTOR_9; + } + else if ((address < ADDR_FLASH_SECTOR_10) && (address >= ADDR_FLASH_SECTOR_9)) + { + sector = ADDR_FLASH_SECTOR_10; + } + else if ((address < ADDR_FLASH_SECTOR_11) && (address >= ADDR_FLASH_SECTOR_10)) + { + sector = ADDR_FLASH_SECTOR_11; + } + else /*(address < FLASH_END_ADDR) && (address >= ADDR_FLASH_SECTOR_23))*/ + { + sector = FLASH_END_ADDR; + } + return sector; +} diff --git a/bsp/log/bsp_flash.h b/bsp/log/bsp_flash.h new file mode 100644 index 0000000..ed4a83f --- /dev/null +++ b/bsp/log/bsp_flash.h @@ -0,0 +1,80 @@ +#ifndef _BSP_FLASH_H +#define _BSP_FLASH_H +#include "main.h" + +/* Base address of the Flash sectors */ +#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base address of Sector 0, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base address of Sector 1, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base address of Sector 2, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base address of Sector 3, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base address of Sector 4, 64 Kbytes */ +#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base address of Sector 5, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base address of Sector 6, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base address of Sector 7, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base address of Sector 8, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base address of Sector 9, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base address of Sector 10, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base address of Sector 11, 128 Kbytes */ + +#define FLASH_END_ADDR ((uint32_t)0x08100000) /* Base address of Sector 23, 128 Kbytes */ + + +#define ADDR_FLASH_SECTOR_12 ((uint32_t)0x08100000) /* Base address of Sector 12, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_13 ((uint32_t)0x08104000) /* Base address of Sector 13, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_14 ((uint32_t)0x08108000) /* Base address of Sector 14, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_15 ((uint32_t)0x0810C000) /* Base address of Sector 15, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_16 ((uint32_t)0x08110000) /* Base address of Sector 16, 64 Kbytes */ +#define ADDR_FLASH_SECTOR_17 ((uint32_t)0x08120000) /* Base address of Sector 17, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_18 ((uint32_t)0x08140000) /* Base address of Sector 18, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_19 ((uint32_t)0x08160000) /* Base address of Sector 19, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_20 ((uint32_t)0x08180000) /* Base address of Sector 20, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_21 ((uint32_t)0x081A0000) /* Base address of Sector 21, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_22 ((uint32_t)0x081C0000) /* Base address of Sector 22, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_23 ((uint32_t)0x081E0000) /* Base address of Sector 23, 128 Kbytes */ + + + +/** + * @brief erase flash + * @param[in] address: flash address + * @param[in] len: page num + * @retval none + */ +void flash_erase_address(uint32_t address, uint16_t len); + +/** + * @brief write data to one page of flash + * @param[in] start_address: flash address + * @param[in] buf: data point + * @param[in] len: data num + * @retval success 0, fail -1 + */ +int8_t flash_write_single_address(uint32_t start_address, uint32_t *buf, uint32_t len); + + +/** + * @brief write data to some pages of flash + * @param[in] start_address: flash start address + * @param[in] end_address: flash end address + * @param[in] buf: data point + * @param[in] len: data num + * @retval success 0, fail -1 + */ +int8_t flash_write_muli_address(uint32_t start_address, uint32_t end_address, uint32_t *buf, uint32_t len); + +/** + * @brief read data for flash + * @param[in] address: flash address + * @param[out] buf: data point + * @param[in] len: data num + * @retval none + */ +void flash_read(uint32_t address, uint32_t *buf, uint32_t len); + +/** + * @brief get the next page flash address + * @param[in] address: flash address + * @retval next page flash address + */ +uint32_t get_next_flash_address(uint32_t address); +#endif From 4a45331d311265fc6c5e0b646518587279e46fba Mon Sep 17 00:00:00 2001 From: NeoZng Date: Thu, 22 Jun 2023 21:52:46 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=A4=A7?= =?UTF-8?q?=E9=87=8F=E8=B0=83=E8=AF=95log=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E4=BA=86dwt=E8=AE=A1=E6=97=B6=E5=AE=8F=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86USB=E8=BD=AF=E4=BB=B6=E5=A4=8D=E4=BD=8D?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E4=B8=BB=E6=8E=A7=E5=A4=8D=E4=BD=8D=E5=90=8E?= =?UTF-8?q?=E4=B8=8A=E4=BD=8D=E6=9C=BA=E6=97=A0=E6=B3=95=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?usb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/stm32f4xx_it.h | 1 + Src/freertos.c | 4 +- Src/stm32f4xx_hal_msp.c | 5 ++ Src/stm32f4xx_it.c | 14 +++ Src/usbd_conf.c | 8 +- application/cmd/robot_cmd.c | 5 ++ application/robot_task.h | 19 ++++ basic_framework.ioc | 1 + bsp/can/bsp_can.c | 16 ++-- bsp/dwt/bsp_dwt.c | 9 +- bsp/dwt/bsp_dwt.h | 37 +++++--- bsp/dwt/bsp_dwt.md | 30 ++++++- bsp/log/bsp_log.h | 6 +- bsp/log/bsp_log.md | 1 - bsp/usart/bsp_usart.c | 16 ++-- bsp/usart/bsp_usart.md | 4 +- bsp/usb/bsp_usb.c | 5 +- modules/BMI088/bmi088.c | 34 ++++--- modules/BMI088/bmi088.md | 14 +-- modules/can_comm/can_comm.c | 10 ++- modules/imu/BMI088driver.c | 14 ++- modules/master_machine/master_process.c | 45 ++++++---- modules/motor/DJImotor/dji_motor.c | 35 ++++---- modules/motor/HTmotor/HT04.c | 12 ++- modules/motor/HTmotor/HT04.md | 2 + modules/motor/LKmotor/LK9025.c | 9 +- modules/ps_handle/ps_handle.c | 115 ------------------------ modules/ps_handle/ps_handle.h | 38 -------- modules/ps_handle/ps_handle.md | 3 - modules/referee/rm_referee.c | 8 +- modules/remote/remote_control.c | 2 + 31 files changed, 247 insertions(+), 275 deletions(-) delete mode 100644 modules/ps_handle/ps_handle.c delete mode 100644 modules/ps_handle/ps_handle.h delete mode 100644 modules/ps_handle/ps_handle.md diff --git a/Inc/stm32f4xx_it.h b/Inc/stm32f4xx_it.h index fdd3cc6..86acaac 100644 --- a/Inc/stm32f4xx_it.h +++ b/Inc/stm32f4xx_it.h @@ -52,6 +52,7 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); +void FLASH_IRQHandler(void); void EXTI3_IRQHandler(void); void EXTI4_IRQHandler(void); void DMA1_Stream1_IRQHandler(void); diff --git a/Src/freertos.c b/Src/freertos.c index f6e1a25..1ff4a6b 100644 --- a/Src/freertos.c +++ b/Src/freertos.c @@ -123,9 +123,9 @@ void MX_FREERTOS_Init(void) void StartDefaultTask(void const *argument) { /* init code for USB_DEVICE */ - MX_USB_DEVICE_Init(); // USB??? + MX_USB_DEVICE_Init(); // 榛樿usb鍚姩浠诲姟鐨勪綅缃 /* USER CODE BEGIN StartDefaultTask */ - vTaskDelete(NULL); // ??????,????CPU + vTaskDelete(NULL); // 閬垮厤绌虹疆鍜屽垏鎹㈠崰鐢╟pu /* USER CODE END StartDefaultTask */ } diff --git a/Src/stm32f4xx_hal_msp.c b/Src/stm32f4xx_hal_msp.c index ed524b2..f569c97 100644 --- a/Src/stm32f4xx_hal_msp.c +++ b/Src/stm32f4xx_hal_msp.c @@ -73,6 +73,11 @@ void HAL_MspInit(void) /* PendSV_IRQn interrupt configuration */ HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); + /* Peripheral interrupt init */ + /* FLASH_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(FLASH_IRQn, 6, 0); + HAL_NVIC_EnableIRQ(FLASH_IRQn); + /* USER CODE BEGIN MspInit 1 */ /* USER CODE END MspInit 1 */ diff --git a/Src/stm32f4xx_it.c b/Src/stm32f4xx_it.c index 62b6f5c..fb06c6d 100644 --- a/Src/stm32f4xx_it.c +++ b/Src/stm32f4xx_it.c @@ -183,6 +183,20 @@ void DebugMon_Handler(void) /* please refer to the startup file (startup_stm32f4xx.s). */ /******************************************************************************/ +/** + * @brief This function handles Flash global interrupt. + */ +void FLASH_IRQHandler(void) +{ + /* USER CODE BEGIN FLASH_IRQn 0 */ + + /* USER CODE END FLASH_IRQn 0 */ + HAL_FLASH_IRQHandler(); + /* USER CODE BEGIN FLASH_IRQn 1 */ + + /* USER CODE END FLASH_IRQn 1 */ +} + /** * @brief This function handles EXTI line3 interrupt. */ diff --git a/Src/usbd_conf.c b/Src/usbd_conf.c index 128246a..4d67d2a 100644 --- a/Src/usbd_conf.c +++ b/Src/usbd_conf.c @@ -27,7 +27,7 @@ #include "usbd_cdc.h" /* USER CODE BEGIN Includes */ - +#include "bsp_dwt.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -95,7 +95,11 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0); HAL_NVIC_EnableIRQ(OTG_FS_IRQn); /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ - + // 涓婄數鍚庨噸鏂版灇涓緐sb璁惧 + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); + DWT_Delay(100); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); + DWT_Delay(100); /* USER CODE END USB_OTG_FS_MspInit 1 */ } } diff --git a/application/cmd/robot_cmd.c b/application/cmd/robot_cmd.c index 7f2edb7..8188dc3 100644 --- a/application/cmd/robot_cmd.c +++ b/application/cmd/robot_cmd.c @@ -8,6 +8,9 @@ #include "message_center.h" #include "general_def.h" #include "dji_motor.h" +// bsp +#include "bsp_dwt.h" +#include "bsp_log.h" // 绉佹湁瀹,鑷姩灏嗙紪鐮佸櫒杞崲鎴愯搴﹀ #define YAW_ALIGN_ANGLE (YAW_CHASSIS_ALIGN_ECD * ECD_ANGLE_COEF_DJI) // 瀵归綈鏃剁殑瑙掑害,0-360 @@ -266,12 +269,14 @@ static void EmergencyHandler() shoot_cmd_send.shoot_mode = SHOOT_OFF; shoot_cmd_send.friction_mode = FRICTION_OFF; shoot_cmd_send.load_mode = LOAD_STOP; + LOGERROR("[CMD] emergency stop!"); } // 閬ユ帶鍣ㄥ彸渚у紑鍏充负[涓奭,鎭㈠姝e父杩愯 if (switch_is_up(rc_data[TEMP].rc.switch_right)) { robot_state = ROBOT_READY; shoot_cmd_send.shoot_mode = SHOOT_ON; + LOGINFO("[CMD] reinstate, robot ready"); } } diff --git a/application/robot_task.h b/application/robot_task.h index 1b09e81..743c1cc 100644 --- a/application/robot_task.h +++ b/application/robot_task.h @@ -13,6 +13,8 @@ #include "daemon.h" #include "HT04.h" +#include "bsp_log.h" + osThreadId insTaskHandle; osThreadId robotTaskHandle; osThreadId motorTaskHandle; @@ -54,12 +56,15 @@ void StartINSTASK(void const *argument) { static float ins_start, ins_dt; INS_Init(); // 纭繚BMI088琚纭垵濮嬪寲. + LOGINFO("[freeRTOS] INS Task Start"); while (1) { // 1kHz ins_start = DWT_GetTimeline_ms(); INS_Task(); ins_dt = DWT_GetTimeline_ms() - ins_start; + if (ins_dt > 1) + LOGERROR("[freeRTOS] INS Task is being DELAY! dt = [%f]", &ins_dt); VisionSend(); // 瑙g畻瀹屾垚鍚庡彂閫佽瑙夋暟鎹,浣嗘槸褰撳墠鐨勫疄鐜颁笉澶紭闆,鍚庣画鑻ユ坊鍔犵‖浠惰Е鍙戦渶瑕侀噸鏂拌冭檻缁撴瀯鐨勭粍缁 osDelay(1); } @@ -68,21 +73,30 @@ void StartINSTASK(void const *argument) void StartMOTORTASK(void const *argument) { static float motor_dt, motor_start; + LOGINFO("[freeRTOS] MOTOR Task Start"); while (1) { motor_start = DWT_GetTimeline_ms(); MotorControlTask(); motor_dt = DWT_GetTimeline_ms() - motor_start; + if (motor_dt > 1) + LOGERROR("[freeRTOS] MOTOR Task is being DELAY! dt = [%f]", &motor_dt); osDelay(1); } } void StartDAEMONTASK(void const *argument) { + static float daemon_dt, daemon_start; + LOGINFO("[freeRTOS] Daemon Task Start"); while (1) { // 100Hz + daemon_start = DWT_GetTimeline_ms(); DaemonTask(); + daemon_dt = DWT_GetTimeline_ms() - daemon_start; + if (daemon_dt > 10) + LOGERROR("[freeRTOS] Daemon Task is being DELAY! dt = [%f]", &daemon_dt); osDelay(10); } } @@ -90,19 +104,24 @@ void StartDAEMONTASK(void const *argument) void StartROBOTTASK(void const *argument) { static float robot_dt, robot_start; + LOGINFO("[freeRTOS] ROBOT core Task Start"); // 200Hz-500Hz,鑻ユ湁棰濆鐨勬帶鍒朵换鍔″骞宠 姝ュ叺鍙兘闇瑕佹彁鍗囪嚦1kHz while (1) { robot_start = DWT_GetTimeline_ms(); RobotTask(); robot_dt = DWT_GetTimeline_ms() - robot_start; + if (robot_dt > 5) + LOGERROR("[freeRTOS] ROBOT core Task is being DELAY! dt = [%f]", &robot_dt); osDelay(5); } } void StartUITASK(void const *argument) { + LOGINFO("[freeRTOS] UI Task Start"); MyUIInit(); + LOGINFO("[freeRTOS] UI Init Done, communication with ref has established"); while (1) { // 姣忕粰瑁佸垽绯荤粺鍙戦佷竴鍖呮暟鎹細鎸傝捣涓娆,璇﹁UITask鍑芥暟鐨剅efereeSend() diff --git a/basic_framework.ioc b/basic_framework.ioc index db6d55a..ebde68e 100644 --- a/basic_framework.ioc +++ b/basic_framework.ioc @@ -308,6 +308,7 @@ NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:fals NVIC.EXTI3_IRQn=true\:5\:0\:true\:false\:true\:true\:true\:true\:true NVIC.EXTI4_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true NVIC.EXTI9_5_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true +NVIC.FLASH_IRQn=true\:6\:0\:true\:false\:true\:true\:true\:true\:true NVIC.ForceEnableDMAVector=true NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false NVIC.I2C2_ER_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true diff --git a/bsp/can/bsp_can.c b/bsp/can/bsp_can.c index 051dc31..992cde4 100644 --- a/bsp/can/bsp_can.c +++ b/bsp/can/bsp_can.c @@ -65,15 +65,20 @@ CANInstance *CANRegister(CAN_Init_Config_s *config) if (!idx) { CANServiceInit(); // 绗竴娆℃敞鍐,鍏堣繘琛岀‖浠跺垵濮嬪寲 + LOGINFO("[bsp_can] CAN Service Init"); } if (idx >= CAN_MX_REGISTER_CNT) // 瓒呰繃鏈澶у疄渚嬫暟 + { while (1) - ; + LOGERROR("[bsp_can] CAN instance exceeded MAX num, consider balance the load of CAN bus"); + } for (size_t i = 0; i < idx; i++) { // 閲嶅娉ㄥ唽 | id閲嶅 if (can_instance[i]->rx_id == config->rx_id && can_instance[i]->can_handle == config->can_handle) + { while (1) - ; + LOGERROR("[}bsp_can] CAN id crash ,tx [%d] or rx [%d] already registered", &config->tx_id, &config->rx_id); + } } CANInstance *instance = (CANInstance *)malloc(sizeof(CANInstance)); // 鍒嗛厤绌洪棿 @@ -107,7 +112,7 @@ uint8_t CANTransmit(CANInstance *_instance, float timeout) { if (DWT_GetTimeline_ms() - dwt_start > timeout) // 瓒呮椂 { - LOGWARNING("CAN BUSY sending! cnt:%d", busy_count); + LOGWARNING("[bsp_can] CAN MAILbox full! failed to add msg to mailbox. Cnt [%d]", busy_count); busy_count++; return 0; } @@ -116,7 +121,7 @@ uint8_t CANTransmit(CANInstance *_instance, float timeout) // tx_mailbox浼氫繚瀛樺疄闄呭~鍏ヤ簡杩欎竴甯ф秷鎭殑閭,浣嗘槸鐭ラ亾鏄摢涓偖绠卞彂鐨勪技涔庝篃娌″暐鐢 if (HAL_CAN_AddTxMessage(_instance->can_handle, &_instance->txconf, _instance->tx_buff, &_instance->tx_mailbox)) { - LOGWARNING("CAN BUSY bus! cnt:%d", busy_count); + LOGWARNING("[bsp_can] CAN bus BUS! cnt:%d", busy_count); busy_count++; return 0; } @@ -125,9 +130,10 @@ uint8_t CANTransmit(CANInstance *_instance, float timeout) void CANSetDLC(CANInstance *_instance, uint8_t length) { + // 鍙戦侀暱搴﹂敊璇!妫鏌ヨ皟鐢ㄥ弬鏁版槸鍚﹀嚭閿,鎴栧嚭鐜伴噹鎸囬拡/瓒婄晫璁块棶 if (length > 8 || length == 0) // 瀹夊叏妫鏌 while (1) - ; // 鍙戦侀暱搴﹂敊璇!妫鏌ヨ皟鐢ㄥ弬鏁版槸鍚﹀嚭閿,鎴栧嚭鐜伴噹鎸囬拡/瓒婄晫璁块棶 + LOGERROR("[bsp_can] CAN DLC error! check your code or wild pointer"); _instance->txconf.DLC = length; } diff --git a/bsp/dwt/bsp_dwt.c b/bsp/dwt/bsp_dwt.c index ce2e4fa..61d95d6 100644 --- a/bsp/dwt/bsp_dwt.c +++ b/bsp/dwt/bsp_dwt.c @@ -21,8 +21,8 @@ static osMutexId DWT_MUTEX; /** * @brief 绉佹湁鍑芥暟,鐢ㄤ簬妫鏌WT CYCCNT瀵勫瓨鍣ㄦ槸鍚︽孩鍑,骞舵洿鏂癈YCCNT_RountCount * @attention 姝ゅ嚱鏁板亣璁句袱娆¤皟鐢ㄤ箣闂寸殑鏃堕棿闂撮殧涓嶈秴杩囦竴娆℃孩鍑 - * - * @todo 鏇村ソ鐨勬柟妗堟槸涓篸wt鐨勬椂闂存洿鏂板崟鐙缃竴涓换鍔 + * + * @todo 鏇村ソ鐨勬柟妗堟槸涓篸wt鐨勬椂闂存洿鏂板崟鐙缃竴涓换鍔? * 涓嶈繃,浣跨敤dwt鐨勫垵琛锋槸瀹氭椂涓嶈涓柇/浠诲姟绛夊洜绱犲奖鍝,鍥犳璇ュ疄鐜颁粛鐒舵湁鍏跺瓨鍦ㄧ殑鎰忎箟 * */ @@ -31,7 +31,7 @@ static void DWT_CNT_Update(void) if (__get_CONTROL()) // 涓嶅湪涓柇涓,浣跨敤浜掓枼閿;鍦ㄤ腑鏂垯鐩存帴鎵ц鍗冲彲,鏈鏋跺皢鎵鏈変腑鏂紭鍏堢骇璁剧疆涓虹浉鍚,鏁呬笉浼氳鍏朵粬涓柇閲嶅叆 if (osOK != osMutexWait(DWT_MUTEX, 0)) return; - + volatile uint32_t cnt_now = DWT->CYCCNT; if (cnt_now < CYCCNT_LAST) CYCCNT_RountCount++; @@ -131,6 +131,5 @@ void DWT_Delay(float Delay) float wait = Delay; while ((DWT->CYCCNT - tickstart) < wait * (float)CPU_FREQ_Hz) - { - } + ; } diff --git a/bsp/dwt/bsp_dwt.h b/bsp/dwt/bsp_dwt.h index 5233c09..b1a223d 100644 --- a/bsp/dwt/bsp_dwt.h +++ b/bsp/dwt/bsp_dwt.h @@ -2,7 +2,8 @@ ****************************************************************************** * @file bsp_dwt.h * @author Wang Hongxi - * @version V1.1.0 + * @author modified by NeoZng + * @version V1.2.0 * @date 2022/3/8 * @brief ****************************************************************************** @@ -15,6 +16,7 @@ #include "main.h" #include "stdint.h" +#include "bsp_log.h" typedef struct { @@ -23,17 +25,30 @@ typedef struct uint16_t us; } DWT_Time_t; +/** + * @brief 璇ュ畯鐢ㄤ簬璁$畻浠g爜娈垫墽琛屾椂闂,鍗曚綅涓虹/s,杩斿洖鍊间负float绫诲瀷 + * 棣栧厛闇瑕佸垱寤轰竴涓猣loat绫诲瀷鐨勫彉閲,鐢ㄤ簬瀛樺偍鏃堕棿闂撮殧 + * 璁$畻寰楀埌鐨勬椂闂撮棿闅斿悓鏃惰繕浼氶氳繃RTT鎵撳嵃鍒版棩蹇楃粓绔,浣犱篃鍙互灏嗕綘鐨刣t鍙橀噺娣诲姞鍒版煡鐪 + */ +#define TIME_ELAPSE(dt, code) \ + do \ + { \ + float tstart = DWT_GetTimeline_s(); \ + code; \ + dt = DWT_GetTimeline_s() - tstart; \ + LOGINFO("[DWT] " #dt " = %f s\r\n", dt); \ + } while (0) /** * @brief 鍒濆鍖朌WT,浼犲叆鍙傛暟涓篊PU棰戠巼,鍗曚綅MHz - * + * * @param CPU_Freq_mHz c鏉夸负168MHz,A鏉夸负180MHz */ void DWT_Init(uint32_t CPU_Freq_mHz); /** * @brief 鑾峰彇涓ゆ璋冪敤涔嬮棿鐨勬椂闂撮棿闅,鍗曚綅涓虹/s - * + * * @param cnt_last 涓婁竴娆¤皟鐢ㄧ殑鏃堕棿鎴 * @return float 鏃堕棿闂撮殧,鍗曚綅涓虹/s */ @@ -41,7 +56,7 @@ float DWT_GetDeltaT(uint32_t *cnt_last); /** * @brief 鑾峰彇涓ゆ璋冪敤涔嬮棿鐨勬椂闂撮棿闅,鍗曚綅涓虹/s,楂樼簿搴 - * + * * @param cnt_last 涓婁竴娆¤皟鐢ㄧ殑鏃堕棿鎴 * @return double 鏃堕棿闂撮殧,鍗曚綅涓虹/s */ @@ -49,22 +64,22 @@ double DWT_GetDeltaT64(uint32_t *cnt_last); /** * @brief 鑾峰彇褰撳墠鏃堕棿,鍗曚綅涓虹/s,鍗冲垵濮嬪寲鍚庣殑鏃堕棿 - * + * * @return float 鏃堕棿杞 */ float DWT_GetTimeline_s(void); /** * @brief 鑾峰彇褰撳墠鏃堕棿,鍗曚綅涓烘绉/ms,鍗冲垵濮嬪寲鍚庣殑鏃堕棿 - * - * @return float + * + * @return float */ float DWT_GetTimeline_ms(void); /** * @brief 鑾峰彇褰撳墠鏃堕棿,鍗曚綅涓哄井绉/us,鍗冲垵濮嬪寲鍚庣殑鏃堕棿 - * - * @return uint64_t + * + * @return uint64_t */ uint64_t DWT_GetTimeline_us(void); @@ -72,7 +87,7 @@ uint64_t DWT_GetTimeline_us(void); * @brief DWT寤舵椂鍑芥暟,鍗曚綅涓虹/s * @attention 璇ュ嚱鏁颁笉鍙椾腑鏂槸鍚﹀紑鍚殑褰卞搷,鍙互鍦ㄤ复鐣屽尯鍜屽叧闂腑鏂椂浣跨敤 * @note 绂佹鍦╛_disable_irq()鍜宊_enable_irq()涔嬮棿浣跨敤HAL_Delay()鍑芥暟,搴斾娇鐢ㄦ湰鍑芥暟 - * + * * @param Delay 寤舵椂鏃堕棿,鍗曚綅涓虹/s */ void DWT_Delay(float Delay); @@ -83,6 +98,4 @@ void DWT_Delay(float Delay); */ void DWT_SysTimeUpdate(void); - - #endif /* BSP_DWT_H_ */ diff --git a/bsp/dwt/bsp_dwt.md b/bsp/dwt/bsp_dwt.md index f6677d5..921245f 100644 --- a/bsp/dwt/bsp_dwt.md +++ b/bsp/dwt/bsp_dwt.md @@ -2,8 +2,6 @@ DWT鏄痵tm32鍐呴儴鐨勪竴涓"闅愯棌璧勬簮",浠栫殑鐢ㄩ旀槸缁欎笅杞藉櫒鎻愪緵鍑嗙‘鐨勫畾鏃,浠庤屼负璋冭瘯淇℃伅鍔犱笂鏃堕棿鎴.骞跺湪鍥哄畾鐨勬椂闂撮棿闅斿皢璋冭瘯鏁版嵁鍙戦佸埌浣犵殑xxlink涓. - - ## 甯哥敤鍔熻兘 ### 璁$畻涓ゆ杩涘叆鍚屼竴涓嚱鏁扮殑鏃堕棿闂撮殧 @@ -23,8 +21,34 @@ start=DWT_DetTimeline_ms(); // some proc to go... for(uint8_t i=0;i<10;i++) - foo(); + foo(); end = DWT_DetTimeline_ms()-start; ``` +鎴戜滑杩樻彁渚涗簡涓涓畯鐢ㄤ簬璋冭瘯璁℃椂: + +```c +#define TIME_ELAPSE(dt, code) \ + do \ + { \ + float tstart = DWT_GetTimeline_s(); \ + code; \ + dt = DWT_GetTimeline_s() - tstart; \ + LOGINFO("[DWT] " #dt " = %f s\r\n", dt); \ + } while (0) + +``` + +浼犲叆涓涓猣loat绫诲瀷鐨勫彉閲,骞跺皢浣犺鎵ц鐨勪唬鐮佸啓鍏ョ浜屼釜鍙傛暟: + +```c + static float my_func_dt; + TIME_ELAPSE(my_func_dt, + Function1(vara); + Function2(some, var); + Function3(your,param); + // something more + ); + // my_func_dt can be used for other purpose then; +``` diff --git a/bsp/log/bsp_log.h b/bsp/log/bsp_log.h index d5f0b2a..7709ffe 100644 --- a/bsp/log/bsp_log.h +++ b/bsp/log/bsp_log.h @@ -36,11 +36,11 @@ void BSPLogInit(); /* 鏈夐鑹叉牸寮忔棩蹇楄緭鍑,寤鸿浣跨敤杩欎簺瀹忔潵杈撳嚭鏃ュ織 */ // information level -#define LOGINFO(format,...) LOG_PROTO("I", RTT_CTRL_TEXT_BRIGHT_GREEN , format, ##__VA_ARGS__) +#define LOGINFO(format,...) LOG_PROTO("I:", RTT_CTRL_TEXT_BRIGHT_GREEN , format, ##__VA_ARGS__) // warning level -#define LOGWARNING(format,...) LOG_PROTO("W", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__) +#define LOGWARNING(format,...) LOG_PROTO("W:", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__) // error level -#define LOGERROR(format,...) LOG_PROTO("E", RTT_CTRL_TEXT_BRIGHT_RED , format, ##__VA_ARGS__) +#define LOGERROR(format,...) LOG_PROTO("E:", RTT_CTRL_TEXT_BRIGHT_RED , format, ##__VA_ARGS__) /** * @brief 閫氳繃segger RTT鎵撳嵃鏃ュ織,鏀寔鏍煎紡鍖栬緭鍑,鏍煎紡鍖栬緭鍑虹殑瀹炵幇鍙傝僷rintf. diff --git a/bsp/log/bsp_log.md b/bsp/log/bsp_log.md index a72c2b5..64be4a3 100644 --- a/bsp/log/bsp_log.md +++ b/bsp/log/bsp_log.md @@ -5,7 +5,6 @@ > TODO: > > 1. 鍦ㄦ湭鎺ュ叆璋冭瘯鍣ㄧ殑鏃跺欙紝灏嗘棩蹇楀啓鍏lash涓紝骞舵彁渚涙帴鍙h鍙 -> 2. 澧炲姞鏃ュ織鍒嗙骇锛屾彁渚沬nfo銆亀arning銆乪rror涓変釜绛夌骇鐨勬棩蹇 ## 浣跨敤璇存槑 diff --git a/bsp/usart/bsp_usart.c b/bsp/usart/bsp_usart.c index f1c0a97..ccefeb3 100644 --- a/bsp/usart/bsp_usart.c +++ b/bsp/usart/bsp_usart.c @@ -9,6 +9,7 @@ * */ #include "bsp_usart.h" +#include "bsp_log.h" #include "stdlib.h" #include "memory.h" @@ -38,7 +39,13 @@ USARTInstance *USARTRegister(USART_Init_Config_s *init_config) { if (idx >= DEVICE_USART_CNT) // 瓒呰繃鏈澶у疄渚嬫暟 while (1) - ; + LOGERROR("[bsp_usart] USART exceed max instance count!"); + + for (uint8_t i = 0; i < idx; i++) // 妫鏌ユ槸鍚﹀凡缁忔敞鍐岃繃 + if (usart_instance[i]->usart_handle == init_config->usart_handle) + while (1) + LOGERROR("[bsp_usart] USART instance already registered!"); + USARTInstance *instance = (USARTInstance *)malloc(sizeof(USARTInstance)); memset(instance, 0, sizeof(USARTInstance)); @@ -75,14 +82,10 @@ void USARTSend(USARTInstance *_instance, uint8_t *send_buf, uint16_t send_size, /* 涓插彛鍙戦佹椂,gstate浼氳璁句负BUSY_TX */ uint8_t USARTIsReady(USARTInstance *_instance) { - if(_instance->usart_handle->gState | HAL_UART_STATE_BUSY_TX) - { + if (_instance->usart_handle->gState | HAL_UART_STATE_BUSY_TX) return 0; - } else - { return 1; - } } /** @@ -129,6 +132,7 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) { HAL_UARTEx_ReceiveToIdle_DMA(usart_instance[i]->usart_handle, usart_instance[i]->recv_buff, usart_instance[i]->recv_buff_size); __HAL_DMA_DISABLE_IT(usart_instance[i]->usart_handle->hdmarx, DMA_IT_HT); + LOGWARNING("[bsp_usart] USART error callback triggered, instance idx [%d]", i); return; } } diff --git a/bsp/usart/bsp_usart.md b/bsp/usart/bsp_usart.md index e42607e..532df57 100644 --- a/bsp/usart/bsp_usart.md +++ b/bsp/usart/bsp_usart.md @@ -11,9 +11,9 @@ 闇瑕佸湪涓插彛瀹炰緥涓嬭瀹氭帴鏀剁殑鏁版嵁鍖呯殑闀垮害锛屽疄渚嬪搴旂殑涓插彛纭欢锛堥氳繃`UART_HandleTypeDef`鎸囧畾锛屽`&huart1`锛夛紝瑙f瀽鎺ユ敹鏁版嵁瀵瑰簲鐨勫洖璋冨嚱鏁拌繖涓変釜鍙傛暟銆傜劧鍚庯紝璋冪敤`USARTRegister()`骞朵紶鍏ラ厤缃ソ鐨刞usart_instance`鎸囬拡鍗冲彲銆 -鑻ヨ鍙戦佹暟鎹紝璋冪敤`USARTSend()`銆傛敞鎰廱uffsize鍔″繀灏忎簬buff鐨勫ぇ灏忥紝鍚﹀垯閫犳垚鎸囬拡瓒婄晫鍚庢灉鏈煡銆 +鑻ヨ鍙戦佹暟鎹紝璋冪敤`USARTSend()`銆傛敞鎰廱uffsize鍔″繀灏忎簬浣犲垱寤虹殑buff鐨勫ぇ灏忥紝鍚﹀垯閫犳垚鎸囬拡瓒婄晫鍚庢灉鏈煡銆 -涓插彛纭欢鏀跺埌鏁版嵁鏃讹紝浼氬皢鍏跺瓨鍏usart_instance.recv_buff[]`涓紝褰撴敹鍒板畬鏁翠竴鍖呮暟鎹紝浼氳皟鐢ㄨ瀹氱殑鍥炶皟鍑芥暟`module_callback`锛堝嵆浣犳彁渚涚殑瑙f瀽鍑芥暟锛夈傚湪姝ゅ嚱鏁颁腑锛屼綘鍙互閫氳繃`usart_instance.recv_buff[]`璁块棶涓插彛鏀跺埌鐨勬暟鎹 +涓插彛纭欢鏀跺埌鏁版嵁鏃讹紝浼氬皢鍏跺瓨鍏usart_instance.recv_buff[]`涓紝褰撴敹鍒板畬鏁翠竴鍖呮暟鎹紝浼氳皟鐢ㄨ瀹氱殑鍥炶皟鍑芥暟`module_callback`锛堝嵆浣犳敞鍐屾椂鎻愪緵鐨勮В鏋愬嚱鏁帮級銆傚湪姝ゅ嚱鏁颁腑锛屼綘鍙互閫氳繃`usart_instance.recv_buff[]`璁块棶涓插彛鏀跺埌鐨勬暟鎹 ## 浠g爜缁撴瀯 diff --git a/bsp/usb/bsp_usb.c b/bsp/usb/bsp_usb.c index af71281..9c4ad2f 100644 --- a/bsp/usb/bsp_usb.c +++ b/bsp/usb/bsp_usb.c @@ -11,16 +11,17 @@ #include "bsp_usb.h" #include "bsp_log.h" +#include "bsp_dwt.h" static uint8_t *bsp_usb_rx_buffer; // 鎺ユ敹鍒扮殑鏁版嵁浼氳鏀惧湪杩欓噷,buffer size涓2048 // 娉ㄦ剰usb鍗曚釜鏁版嵁鍖(Full speed妯″紡涓)鏈澶т负64byte,瓒呭嚭鍙兘浼氬嚭鐜颁涪鍖呮儏鍐 uint8_t *USBInit(USB_Init_Config_s usb_conf) { - // 涓婄數鍚庨噸鏂版灇涓緐sb璁惧 - LOGINFO("USB init success"); + // usb鐨勮蒋浠跺浣(妯℃嫙鎷旀彃)鍦╱sbd_conf.c涓殑HAL_PCD_MspInit()涓 bsp_usb_rx_buffer = CDCInitRxbufferNcallback(usb_conf.tx_cbk, usb_conf.rx_cbk); // 鑾峰彇鎺ユ敹鏁版嵁鎸囬拡 // usb鐨勬帴鏀跺洖璋冨嚱鏁颁細鍦ㄨ繖閲岃璁剧疆,骞跺皢鏁版嵁淇濆瓨鍦╞sp_usb_rx_buffer涓 + LOGINFO("USB init success"); return bsp_usb_rx_buffer; } diff --git a/modules/BMI088/bmi088.c b/modules/BMI088/bmi088.c index b59bc36..2126cec 100644 --- a/modules/BMI088/bmi088.c +++ b/modules/BMI088/bmi088.c @@ -55,9 +55,7 @@ static void BMI088GyroRead(BMI088Instance *bmi088, uint8_t reg, uint8_t *dataptr */ static void BMI088AccelWriteSingleReg(BMI088Instance *bmi088, uint8_t reg, uint8_t data) { - static uint8_t tx[2]; - tx[0] = reg; - tx[1] = data; + uint8_t tx[2] = {reg, data}; SPITransmit(bmi088->spi_acc, tx, 2); } @@ -71,17 +69,15 @@ static void BMI088AccelWriteSingleReg(BMI088Instance *bmi088, uint8_t reg, uint8 */ static void BMI088GyroWriteSingleReg(BMI088Instance *bmi088, uint8_t reg, uint8_t data) { - static uint8_t tx[2]; - tx[0] = reg; - tx[1] = data; + uint8_t tx[2] = {reg, data}; SPITransmit(bmi088->spi_gyro, tx, 2); } // -------------------------浠ヤ笂涓虹鏈夊嚱鏁,灏佽浜咮MI088瀵勫瓨鍣ㄨ鍐欏嚱鏁,blocking--------------------------------// // -------------------------浠ヤ笅涓虹鏈夊嚱鏁,鐢ㄤ簬鍒濆鍖朆MI088acc鍜実yro鐨勭‖浠跺拰閰嶇疆--------------------------------// -#define REG 0 -#define DATA 1 -#define ERROR 2 +#define BMI088REG 0 +#define BMI088DATA 1 +#define BMI088ERROR 2 // BMI088鍒濆鍖栭厤缃暟缁刦or accel,绗竴鍒椾负reg鍦板潃,绗簩鍒椾负鍐欏叆鐨勯厤缃,绗笁鍒椾负閿欒鐮(濡傛灉鍑洪敊) static uint8_t BMI088_Accel_Init_Table[BMI088_WRITE_ACCEL_REG_NUM][3] = { @@ -106,7 +102,7 @@ static uint8_t BMI088_Gyro_Init_Table[BMI088_WRITE_GYRO_REG_NUM][3] = * @brief 鍒濆鍖朆MI088鍔犻熷害璁,鎻愰珮鍙鎬у垎鎷嗗姛鑳 * * @param bmi088 寰呭垵濮嬪寲鐨凚MI088瀹炰緥 - * @return uint8_t ERROR CODE if any problems here + * @return uint8_t BMI088ERROR CODE if any problems here */ static uint8_t BMI088AccelInit(BMI088Instance *bmi088) { @@ -130,14 +126,14 @@ static uint8_t BMI088AccelInit(BMI088Instance *bmi088) // 浣跨敤sizeof鑰屼笉鏄痬agic number,杩欐牱濡傛灉淇敼浜嗘暟缁勫ぇ灏,涓嶇敤淇敼杩欓噷鐨勪唬鐮;鎴栬呬娇鐢ㄥ畯瀹氫箟 for (uint8_t i = 0; i < sizeof(BMI088_Accel_Init_Table) / sizeof(BMI088_Accel_Init_Table[0]); i++) { - reg = BMI088_Accel_Init_Table[i][REG]; - data = BMI088_Accel_Init_Table[i][DATA]; + reg = BMI088_Accel_Init_Table[i][BMI088REG]; + data = BMI088_Accel_Init_Table[i][BMI088DATA]; BMI088AccelWriteSingleReg(bmi088, reg, data); // 鍐欏叆瀵勫瓨鍣 DWT_Delay(0.01); BMI088AccelRead(bmi088, reg, &data, 1); // 鍐欏畬涔嬪悗绔嬪埢璇诲洖妫鏌 DWT_Delay(0.01); - if (data != BMI088_Accel_Init_Table[i][DATA]) - error |= BMI088_Accel_Init_Table[i][ERROR]; + if (data != BMI088_Accel_Init_Table[i][BMI088DATA]) + error |= BMI088_Accel_Init_Table[i][BMI088ERROR]; //{i--;} 鍙互璁剧疆retry娆℃暟,濡傛灉retry娆℃暟鐢ㄥ畬浜,鍒欒繑鍥瀍rror } return error; @@ -147,7 +143,7 @@ static uint8_t BMI088AccelInit(BMI088Instance *bmi088) * @brief 鍒濆鍖朆MI088闄铻轰华,鎻愰珮鍙鎬у垎鎷嗗姛鑳 * * @param bmi088 寰呭垵濮嬪寲鐨凚MI088瀹炰緥 - * @return uint8_t ERROR CODE + * @return uint8_t BMI088ERROR CODE */ static uint8_t BMI088GyroInit(BMI088Instance *bmi088) { @@ -169,14 +165,14 @@ static uint8_t BMI088GyroInit(BMI088Instance *bmi088) // 浣跨敤sizeof鑰屼笉鏄痬agic number,杩欐牱濡傛灉淇敼浜嗘暟缁勫ぇ灏,涓嶇敤淇敼杩欓噷鐨勪唬鐮;鎴栬呬娇鐢ㄥ畯瀹氫箟 for (uint8_t i = 0; i < sizeof(BMI088_Gyro_Init_Table) / sizeof(BMI088_Gyro_Init_Table[0]); i++) { - reg = BMI088_Gyro_Init_Table[i][REG]; - data = BMI088_Gyro_Init_Table[i][DATA]; + reg = BMI088_Gyro_Init_Table[i][BMI088REG]; + data = BMI088_Gyro_Init_Table[i][BMI088DATA]; BMI088GyroWriteSingleReg(bmi088, reg, data); // 鍐欏叆瀵勫瓨鍣 DWT_Delay(0.001); BMI088GyroRead(bmi088, reg, &data, 1); // 鍐欏畬涔嬪悗绔嬪埢璇诲洖瀵瑰簲瀵勫瓨鍣ㄦ鏌ユ槸鍚﹀啓鍏ユ垚鍔 DWT_Delay(0.001); - if (data != BMI088_Gyro_Init_Table[i][DATA]) - error |= BMI088_Gyro_Init_Table[i][ERROR]; + if (data != BMI088_Gyro_Init_Table[i][BMI088DATA]) + error |= BMI088_Gyro_Init_Table[i][BMI088ERROR]; //{i--;} 鍙互璁剧疆retry娆℃暟,灏濊瘯閲嶆柊鍐欏叆.濡傛灉retry娆℃暟鐢ㄥ畬浜,鍒欒繑鍥瀍rror } diff --git a/modules/BMI088/bmi088.md b/modules/BMI088/bmi088.md index d226a1b..88a42a2 100644 --- a/modules/BMI088/bmi088.md +++ b/modules/BMI088/bmi088.md @@ -7,24 +7,24 @@ ```c BMI088_Init_Config_s imu_config = { .spi_acc_config={ - .GPIOx=GPIOC, + .GPIOx=GPIOA, .GPIOx=GPIO_PIN_4, .spi_handle=&hspi1, }, .spi_gyro_config={ - .GPIOx=GPIOC, - .GPIOx=GPIO_PIN_4, + .GPIOx=GPIOB, + .GPIOx=GPIO_PIN_0, .spi_handle=&hspi1, }, .acc_int_config={ .exti_mode=EXTI_TRIGGER_FALLING, - .GPIO_Pin=GPIO_PIN_10, - .GPIOx=GPIOA, + .GPIO_Pin=GPIO_PIN_4, + .GPIOx=GPIOC, }, .gyro_int_config={ .exti_mode=EXTI_TRIGGER_FALLING, - .GPIO_Pin=GPIO_PIN_11, - .GPIOx=GPIOA, + .GPIO_Pin=GPIO_PIN_5, + .GPIOx=GPIOC, }, .heat_pid_config={ .Kp=0.0f, diff --git a/modules/can_comm/can_comm.c b/modules/can_comm/can_comm.c index f000dd9..415a67d 100644 --- a/modules/can_comm/can_comm.c +++ b/modules/can_comm/can_comm.c @@ -3,6 +3,7 @@ #include "stdlib.h" #include "crc8.h" #include "bsp_dwt.h" +#include "bsp_log.h" /** * @brief 閲嶇疆CAN comm鐨勬帴鏀剁姸鎬佸拰buffer @@ -59,7 +60,7 @@ static void CANCommRxCallback(CANInstance *_instance) if (comm->raw_recvbuf[comm->recv_buf_len - 2] == crc_8(comm->raw_recvbuf + 2, comm->recv_data_len)) { // 鏁版嵁閲忓ぇ鐨勮瘽鑰冭檻浣跨敤DMA memcpy(comm->unpacked_recv_data, comm->raw_recvbuf + 2, comm->recv_data_len); - comm->update_flag = 1; // 鏁版嵁鏇存柊flag缃负1 + comm->update_flag = 1; // 鏁版嵁鏇存柊flag缃负1 DaemonReload(comm->comm_daemon); // 閲嶈浇daemon,閬垮厤鏁版嵁鏇存柊鍚庝竴鐩翠笉琚鍙栬屽鑷存暟鎹洿鏂颁笉鍙婃椂 } } @@ -69,6 +70,13 @@ static void CANCommRxCallback(CANInstance *_instance) } } +static void CANCommLostCallback(void *cancomm) +{ + CANCommInstance *comm = (CANCommInstance *)cancomm; + CANCommResetRx(comm); + LOGWARNING("[can_comm] can comm rx[%d] lost, reset rx state.", &comm->can_ins->rx_id); +} + CANCommInstance *CANCommInit(CANComm_Init_Config_s *comm_config) { CANCommInstance *ins = (CANCommInstance *)malloc(sizeof(CANCommInstance)); diff --git a/modules/imu/BMI088driver.c b/modules/imu/BMI088driver.c index 4772204..ad3ec05 100644 --- a/modules/imu/BMI088driver.c +++ b/modules/imu/BMI088driver.c @@ -2,6 +2,7 @@ #include "BMI088reg.h" #include "BMI088Middleware.h" #include "bsp_dwt.h" +#include "bsp_log.h" #include #warning this is a legacy support. test the new BMI088 module as soon as possible. @@ -129,7 +130,7 @@ void Calibrate_MPU_Offset(IMU_Data_t *bmi088) startTime = DWT_GetTimeline_s(); do { - if (DWT_GetTimeline_s() - startTime > 10) + if (DWT_GetTimeline_s() - startTime > 12) { // 锟斤拷???? bmi088->GyroOffset[0] = GxOFFSET; @@ -137,6 +138,7 @@ void Calibrate_MPU_Offset(IMU_Data_t *bmi088) bmi088->GyroOffset[2] = GzOFFSET; bmi088->gNorm = gNORM; bmi088->TempWhenCali = 40; + LOGERROR("[BMI088] Calibrate Failed! Use offline params"); break; } @@ -206,7 +208,11 @@ void Calibrate_MPU_Offset(IMU_Data_t *bmi088) gyroDiff[0] > 0.15f || gyroDiff[1] > 0.15f || gyroDiff[2] > 0.15f) + { + LOGWARNING("[bmi088] calibration was interrupted\n"); break; + } + DWT_Delay(0.0005); } @@ -252,7 +258,10 @@ uint8_t bmi088_accel_init(void) // check the "who am I" if (res != BMI088_ACC_CHIP_ID_VALUE) + { + LOGERROR("[bmi088] Can not read bmi088 acc chip id"); return BMI088_NO_SENSOR; + } // set accel sonsor config and check for (write_reg_num = 0; write_reg_num < BMI088_WRITE_ACCEL_REG_NUM; write_reg_num++) @@ -294,7 +303,10 @@ uint8_t bmi088_gyro_init(void) // check the "who am I" if (res != BMI088_GYRO_CHIP_ID_VALUE) + { + LOGERROR("[bmi088] Can not read bmi088 gyro chip id"); return BMI088_NO_SENSOR; + } // set gyro sonsor config and check for (write_reg_num = 0; write_reg_num < BMI088_WRITE_GYRO_REG_NUM; write_reg_num++) diff --git a/modules/master_machine/master_process.c b/modules/master_machine/master_process.c index 91b96a3..057c8fd 100644 --- a/modules/master_machine/master_process.c +++ b/modules/master_machine/master_process.c @@ -10,11 +10,13 @@ */ #include "master_process.h" #include "seasky_protocol.h" +#include "daemon.h" #include "bsp_log.h" #include "robot_def.h" static Vision_Recv_s recv_data; static Vision_Send_s send_data; +static DaemonInstance *vision_daemon_instance; void VisionSetFlag(Enemy_Color_e enemy_color, Work_Mode_e work_mode, Bullet_Speed_e bullet_speed) { @@ -30,13 +32,26 @@ void VisionSetAltitude(float yaw, float pitch, float roll) send_data.roll = roll; } +/** + * @brief 绂荤嚎鍥炶皟鍑芥暟,灏嗗湪daemon.c涓daemon task璋冪敤 + * @attention 鐢变簬HAL搴撶殑璁捐闂,涓插彛寮鍚疍MA鎺ユ敹涔嬪悗鍚屾椂鍙戦佹湁姒傜巼鍑虹幇__HAL_LOCK()瀵艰嚧鐨勬閿,浣垮緱鏃犳硶 + * 杩涘叆鎺ユ敹涓柇.閫氳繃daemon鍒ゆ柇鏁版嵁鏇存柊,閲嶆柊璋冪敤鏈嶅姟鍚姩鍑芥暟浠ヨВ鍐虫闂. + * + * @param id vision_usart_instance鐨勫湴鍧,姝ゅ娌$敤. + */ +static void VisionOfflineCallback(void *id) +{ +#ifdef VISION_USE_UART + USARTServiceInit(vision_usart_instance); +#endif // !VISION_USE_UART + LOGWARNING("[vision] vision offline, restart communication."); +} + #ifdef VISION_USE_UART #include "bsp_usart.h" -#include "daemon.h" static USARTInstance *vision_usart_instance; -static DaemonInstance *vision_daemon_instance; /** * @brief 鎺ユ敹瑙e寘鍥炶皟鍑芥暟,灏嗗湪bsp_usart.c涓usart rx callback璋冪敤 @@ -51,21 +66,8 @@ static void DecodeVision() // TODO: code to resolve flag_register; } -/** - * @brief 绂荤嚎鍥炶皟鍑芥暟,灏嗗湪daemon.c涓daemon task璋冪敤 - * @attention 鐢变簬HAL搴撶殑璁捐闂,涓插彛寮鍚疍MA鎺ユ敹涔嬪悗鍚屾椂鍙戦佹湁姒傜巼鍑虹幇__HAL_LOCK()瀵艰嚧鐨勬閿,浣垮緱鏃犳硶 - * 杩涘叆鎺ユ敹涓柇.閫氳繃daemon鍒ゆ柇鏁版嵁鏇存柊,閲嶆柊璋冪敤鏈嶅姟鍚姩鍑芥暟浠ヨВ鍐虫闂. - * - * @param id vision_usart_instance鐨勫湴鍧,姝ゅ娌$敤. - */ -static void VisionOfflineCallback(void *id) -{ - USARTServiceInit(vision_usart_instance); -} - Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle) { -#ifdef VISION_USE_UART USART_Init_Config_s conf; conf.module_callback = DecodeVision; conf.recv_buff_size = VISION_RECV_SIZE; @@ -79,7 +81,6 @@ Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle) .reload_count = 10, }; vision_daemon_instance = DaemonRegister(&daemon_conf); -#endif // VISION_USE_UART return &recv_data; } @@ -125,9 +126,17 @@ static void DecodeVision(uint16_t recv_len) Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle) { UNUSED(_handle); // 浠呬负浜嗘秷闄よ鍛 - USB_Init_Config_s conf = {0}; - conf.rx_cbk = DecodeVision; + USB_Init_Config_s conf = {.rx_cbk = DecodeVision}; vis_recv_buff = USBInit(conf); + + // 涓簃aster process娉ㄥ唽daemon,鐢ㄤ簬鍒ゆ柇瑙嗚閫氫俊鏄惁绂荤嚎 + Daemon_Init_Config_s daemon_conf = { + .callback = VisionOfflineCallback, // 绂荤嚎鏃惰皟鐢ㄧ殑鍥炶皟鍑芥暟,浼氶噸鍚覆鍙f帴鏀 + .owner_id = NULL, + .reload_count = 5, // 50ms + }; + vision_daemon_instance = DaemonRegister(&daemon_conf); + return &recv_data; } diff --git a/modules/motor/DJImotor/dji_motor.c b/modules/motor/DJImotor/dji_motor.c index 1f88cc6..73dc080 100644 --- a/modules/motor/DJImotor/dji_motor.c +++ b/modules/motor/DJImotor/dji_motor.c @@ -4,14 +4,15 @@ #include "bsp_log.h" static uint8_t idx = 0; // register idx,鏄鏂囦欢鐨勫叏灞鐢垫満绱㈠紩,鍦ㄦ敞鍐屾椂浣跨敤 - /* DJI鐢垫満鐨勫疄渚,姝ゅ浠呬繚瀛樻寚閽,鍐呭瓨鐨勫垎閰嶅皢閫氳繃鐢垫満瀹炰緥鍒濆鍖栨椂閫氳繃malloc()杩涜 */ -static DJIMotorInstance *dji_motor_instance[DJI_MOTOR_CNT] = {NULL}; +static DJIMotorInstance *dji_motor_instance[DJI_MOTOR_CNT] = {NULL}; // 浼氬湪control浠诲姟涓亶鍘嗚鎸囬拡鏁扮粍杩涜pid璁$畻 /** * @brief 鐢变簬DJI鐢垫満鍙戦佷互鍥涗釜涓缁勭殑褰㈠紡杩涜,鏁呭鍏惰繘琛岀壒娈婂鐞,鐢6涓(2can*3group)can_instance涓撻棬璐熻矗鍙戦 * 璇ュ彉閲忓皢鍦 DJIMotorControl() 涓娇鐢,鍒嗙粍鍦 MotorSenderGrouping()涓繘琛 * + * @note 鍥犱负鍙敤浜庡彂閫,鎵浠ヤ笉闇瑕佸湪bsp_can涓敞鍐 + * * C610(m2006)/C620(m3508):0x1ff,0x200; * GM6020:0x1ff,0x2ff * 鍙嶉(rx_id): GM6020: 0x204+id ; C610/C620: 0x200+id @@ -69,9 +70,10 @@ static void MotorSenderGrouping(DJIMotorInstance *motor, CAN_Init_Config_s *conf { if (dji_motor_instance[i]->motor_can_instance->can_handle == config->can_handle && dji_motor_instance[i]->motor_can_instance->rx_id == config->rx_id) { - LOGERROR("[dji_motor] ID crash. Check in debug mode, add dji_motor_instance to watch to get more information."); // 鍚庣画鍙互鎶奿d鍜孋AN鎵撳嵃鍑烘潵 - while (1) - ; // 6020鐨刬d 1-4鍜2006/3508鐨刬d 5-8浼氬彂鐢熷啿绐(鑻ユ湁娉ㄥ唽,鍗1!5,2!6,3!7,4!8) (1!5!,LTC! (((涓嶆槸) + LOGERROR("[dji_motor] ID crash. Check in debug mode, add dji_motor_instance to watch to get more information."); + uint16_t can_bus = config->can_handle == &hcan1 ? 1 : 2; + while (1) // 鍚庣画鍙互鎶奿d鍜孋AN鎵撳嵃鍑烘潵 // 6020鐨刬d 1-4鍜2006/3508鐨刬d 5-8浼氬彂鐢熷啿绐(鑻ユ湁娉ㄥ唽,鍗1!5,2!6,3!7,4!8) (1!5!,LTC! (((涓嶆槸) + LOGERROR("[dji_motor] id [%d], can_bus [%d]", config->rx_id, can_bus); } } break; @@ -98,16 +100,16 @@ static void MotorSenderGrouping(DJIMotorInstance *motor, CAN_Init_Config_s *conf if (dji_motor_instance[i]->motor_can_instance->can_handle == config->can_handle && dji_motor_instance[i]->motor_can_instance->rx_id == config->rx_id) { LOGERROR("[dji_motor] ID crash. Check in debug mode, add dji_motor_instance to watch to get more information."); - while (1) - ; // 6020鐨刬d 1-4鍜2006/3508鐨刬d 5-8浼氬彂鐢熷啿绐(鑻ユ湁娉ㄥ唽,鍗1!5,2!6,3!7,4!8) + uint16_t can_bus = config->can_handle == &hcan1 ? 1 : 2; + while (1) // 鍚庣画鍙互鎶奿d鍜孋AN鎵撳嵃鍑烘潵 // 6020鐨刬d 1-4鍜2006/3508鐨刬d 5-8浼氬彂鐢熷啿绐(鑻ユ湁娉ㄥ唽,鍗1!5,2!6,3!7,4!8) (1!5!,LTC! (((涓嶆槸) + LOGERROR("[dji_motor] id [%d], can_bus [%d]", config->rx_id, can_bus); } } break; default: // other motors should not be registered here - LOGERROR("You must not register other motors using the API of DJI motor."); while (1) - ; // 鍏朵粬鐢垫満涓嶅簲璇ュ湪杩欓噷娉ㄥ唽 + LOGERROR("[dji_motor]You must not register other motors using the API of DJI motor."); // 鍏朵粬鐢垫満涓嶅簲璇ュ湪杩欓噷娉ㄥ唽 } } @@ -148,6 +150,9 @@ static void DecodeDJIMotor(CANInstance *_instance) static void DJIMotorLostCallback(void *motor_ptr) { + DJIMotorInstance *motor = (DJIMotorInstance *)motor_ptr; + uint16_t can_bus = motor->motor_can_instance->can_handle == &hcan1 ? 1 : 2; + LOGWARNING("[dji_motor] Motor lost, can bus [%d] , id [%d]", can_bus, motor->motor_can_instance->tx_id); } // 鐢垫満鍒濆鍖,杩斿洖涓涓數鏈哄疄渚 @@ -182,7 +187,7 @@ DJIMotorInstance *DJIMotorInit(Motor_Init_Config_s *config) Daemon_Init_Config_s daemon_config = { .callback = DJIMotorLostCallback, .owner_id = instance, - .reload_count = 1, // 10ms鏈敹鍒版暟鎹垯涓㈠け + .reload_count = 2, // 20ms鏈敹鍒版暟鎹垯涓㈠け }; instance->daemon = DaemonRegister(&daemon_config); @@ -195,17 +200,11 @@ DJIMotorInstance *DJIMotorInit(Motor_Init_Config_s *config) void DJIMotorChangeFeed(DJIMotorInstance *motor, Closeloop_Type_e loop, Feedback_Source_e type) { if (loop == ANGLE_LOOP) - { motor->motor_settings.angle_feedback_source = type; - } else if (loop == SPEED_LOOP) - { motor->motor_settings.speed_feedback_source = type; - } else - { LOGERROR("[dji_motor] loop type error, check memory access and func param"); // 妫鏌ユ槸鍚︿紶鍏ヤ簡姝g‘鐨凩OOP绫诲瀷,鎴栧彂鐢熶簡鎸囬拡瓒婄晫 - } } void DJIMotorStop(DJIMotorInstance *motor) @@ -299,11 +298,9 @@ void DJIMotorControl() sender_assignment[group].tx_buff[2 * num] = (uint8_t)(set >> 8); // 浣庡叓浣 sender_assignment[group].tx_buff[2 * num + 1] = (uint8_t)(set & 0x00ff); // 楂樺叓浣 - // 鐢垫満鏄惁鍋滄杩愯 + // 鑻ヨ鐢垫満澶勪簬鍋滄鐘舵,鐩存帴灏哹uff缃浂 if (motor->stop_flag == MOTOR_STOP) - { // 鑻ヨ鐢垫満澶勪簬鍋滄鐘舵,鐩存帴灏哹uff缃浂 memset(sender_assignment[group].tx_buff + 2 * num, 0, 16u); - } } // 閬嶅巻flag,妫鏌ユ槸鍚﹁鍙戦佽繖涓甯ф姤鏂 diff --git a/modules/motor/HTmotor/HT04.c b/modules/motor/HTmotor/HT04.c index 4057290..a7ce0b4 100644 --- a/modules/motor/HTmotor/HT04.c +++ b/modules/motor/HTmotor/HT04.c @@ -6,6 +6,7 @@ #include "string.h" #include "daemon.h" #include "stdlib.h" +#include "bsp_log.h" static uint8_t idx; static HTMotorInstance *ht_motor_instance[HT_MOTOR_CNT]; @@ -64,17 +65,14 @@ static void HTMotorDecode(CANInstance *motor_can) tmp = (uint16_t)(((rxbuff[4] & 0x0f) << 8) | rxbuff[5]); measure->real_current = CURRENT_SMOOTH_COEF * uint_to_float(tmp, T_MIN, T_MAX, 12) + (1 - CURRENT_SMOOTH_COEF) * measure->real_current; - - } static void HTMotorLostCallback(void *motor_ptr) { HTMotorInstance *motor = (HTMotorInstance *)motor_ptr; - if (motor->stop_flag == MOTOR_STOP) - return; + LOGWARNING("[ht_motor] motor %d lost\n", motor->motor_can_instace->tx_id); if (++motor->lost_cnt % 10 != 0) - HTMotorSetMode(CMD_MOTOR_MODE, motor); // 鑻ヤ笉鍦ㄥ仠姝㈡ā寮,灏濊瘯閲嶆柊璁╃數鏈鸿繘鍏ユ帶鍒舵ā寮 + HTMotorSetMode(CMD_MOTOR_MODE, motor); // 灏濊瘯閲嶆柊璁╃數鏈鸿繘鍏ユ帶鍒舵ā寮 } /* 娴锋嘲鐢垫満涓鐢熼粦,浠涔堝瀮鍦惧崗璁! */ @@ -99,7 +97,7 @@ void HTMotorCalibEncoder(HTMotorInstance *motor) memcpy(zero_buff, buf, 6); // 鍒濆鍖栫殑鏃跺欒嚦灏戣皟鐢ㄤ竴娆,鏁呭皢鍏朵粬鎸囦护涓0鏃跺彂閫佺殑鎶ユ枃淇濆瓨涓涓,璇﹁ht04鐢垫満璇存槑 CANTransmit(motor->motor_can_instace, 1); DWT_Delay(0.005); - HTMotorSetMode(CMD_ZERO_POSITION, motor); + HTMotorSetMode(CMD_ZERO_POSITION, motor); // sb 鐜╂剰鏍″噯瀹屼簡缂栫爜鍣ㄤ篃涓嶄负0 DWT_Delay(0.005); // HTMotorSetMode(CMD_MOTOR_MODE, motor); } @@ -215,7 +213,7 @@ void HTMotorControlInit() char ht_id_buff[2] = {0}; __itoa(i, ht_id_buff, 10); strcat(ht_task_name, ht_id_buff); // 浼间箮娌′粈涔堝悐鐢,osthreaddef浼氭妸绗竴涓彉閲忓綋浣滃畯瀛楃涓蹭紶鍏,浣滀负浠诲姟鍚 - // todo 杩橀渶瑕佷竴涓洿浼橀泤鐨勬柟妗堟潵鍖哄垎涓嶅悓鐨勭數鏈轰换鍔 + // @todo 杩橀渶瑕佷竴涓洿浼橀泤鐨勬柟妗堟潵鍖哄垎涓嶅悓鐨勭數鏈轰换鍔 osThreadDef(ht_task_name, HTMotorTask, osPriorityNormal, 0, 128); ht_task_handle[i] = osThreadCreate(osThread(ht_task_name), ht_motor_instance[i]); } diff --git a/modules/motor/HTmotor/HT04.md b/modules/motor/HTmotor/HT04.md index ab6af23..2f3ba49 100644 --- a/modules/motor/HTmotor/HT04.md +++ b/modules/motor/HTmotor/HT04.md @@ -40,3 +40,5 @@ static void HTMotorDecode(CANInstance *motor_can) } } ``` + +绗竴娆℃敹鍒版暟鎹椂榛樿鐢垫満澶勪簬闄愪綅澶,灏嗛熷害鍜岃搴﹂兘璁剧疆涓洪浂,璁板綍褰撳墠鐨勭紪鐮佸櫒鏁版嵁,涔嬪悗姣忔鏀跺埌閮藉噺鍘昏鍊. diff --git a/modules/motor/LKmotor/LK9025.c b/modules/motor/LKmotor/LK9025.c index 2323734..103faac 100644 --- a/modules/motor/LKmotor/LK9025.c +++ b/modules/motor/LKmotor/LK9025.c @@ -3,6 +3,7 @@ #include "general_def.h" #include "daemon.h" #include "bsp_dwt.h" +#include "bsp_log.h" static uint8_t idx; static LKMotorInstance *lkmotor_instance[LK_MOTOR_MX_CNT] = {NULL}; @@ -43,6 +44,12 @@ static void LKMotorDecode(CANInstance *_instance) measure->total_angle = measure->total_round * 360 + measure->angle_single_round; } +static void LKMotorLostCallback(void *motor_ptr) +{ + LKMotorInstance *motor = (LKMotorInstance *)motor_ptr; + LOGWARNING("[LKMotor] motor lost, id: %d", motor->motor_can_ins->tx_id); +} + LKMotorInstance *LKMotorInit(Motor_Init_Config_s *config) { LKMotorInstance *motor = (LKMotorInstance *)malloc(sizeof(LKMotorInstance)); @@ -75,7 +82,7 @@ LKMotorInstance *LKMotorInit(Motor_Init_Config_s *config) Daemon_Init_Config_s daemon_config = { .callback = NULL, .owner_id = motor, - .reload_count = 5, // 0.05绉 + .reload_count = 5, // 50ms }; motor->daemon = DaemonRegister(&daemon_config); diff --git a/modules/ps_handle/ps_handle.c b/modules/ps_handle/ps_handle.c deleted file mode 100644 index 8928512..0000000 --- a/modules/ps_handle/ps_handle.c +++ /dev/null @@ -1,115 +0,0 @@ -#include "ps_handle.h" -uint8_t PS2_RawData[9] = {0}; -PS2_Instance PS2_Data = {0}; -void PS2_CS(uint8_t Val) -{ - if (Val) - HAL_GPIO_WritePin(PS2_CS_GPIOx, PS2_CS_Pin, GPIO_PIN_SET); - else - HAL_GPIO_WritePin(PS2_CS_GPIOx, PS2_CS_Pin, GPIO_PIN_RESET); -} -void PS2_CLK(uint8_t Val) -{ - if (Val) - HAL_GPIO_WritePin(PS2_CLK_GPIOx, PS2_CLK_Pin, GPIO_PIN_SET); - else - HAL_GPIO_WritePin(PS2_CLK_GPIOx, PS2_CLK_Pin, GPIO_PIN_RESET); -} -void PS2_DO(uint8_t Val) -{ - if (Val) - HAL_GPIO_WritePin(PS2_DO_GPIOx, PS2_DO_Pin, GPIO_PIN_SET); - else - HAL_GPIO_WritePin(PS2_DO_GPIOx, PS2_DO_Pin, GPIO_PIN_RESET); -} -uint8_t PS2_Read_DI() -{ - return HAL_GPIO_ReadPin(PS2_DI_GPIOx, PS2_DI_Pin); -} -void PS2_Delay() -{ - for (int i = 0; i < 0xBf; i++) - __NOP(); -} -uint8_t PS2_ReadWrite_Byte(uint8_t TxData) -{ - uint8_t TX = TxData; - uint8_t RX = 0; - for (int i = 0; i < 8; i++) - { - if (TX & 0x01) - PS2_DO(1); - else - PS2_DO(0); - TX >>= 1; - PS2_CLK(1); - PS2_Delay(); - PS2_CLK(0); - RX >>= 1; - RX |= (PS2_Read_DI() << 7); - PS2_Delay(); - PS2_CLK(1); - PS2_Delay(); - } - return RX; -} - -static void PS2_Decode() -{ - if (PS2_RawData[2] == 0x5A) - { - PS2_Data.Key_Select = (~PS2_RawData[3] >> 0) & 0x01; //閫夋嫨閿 - PS2_Data.Key_Start = (~PS2_RawData[3] >> 3) & 0x01; //寮濮嬮敭 - - //宸︿晶鎸夐敭 - PS2_Data.Key_L_Up = (~PS2_RawData[3] >> 4) & 0x01; - PS2_Data.Key_L_Right = (~PS2_RawData[3] >> 5) & 0x01; - PS2_Data.Key_L_Down = (~PS2_RawData[3] >> 6) & 0x01; - PS2_Data.Key_L_Left = (~PS2_RawData[3] >> 7) & 0x01; - - //鍚庝晶鎸夐敭 - PS2_Data.Key_L2 = (~PS2_RawData[4] >> 0) & 0x01; - PS2_Data.Key_R2 = (~PS2_RawData[4] >> 1) & 0x01; - PS2_Data.Key_L1 = (~PS2_RawData[4] >> 2) & 0x01; - PS2_Data.Key_R1 = (~PS2_RawData[4] >> 3) & 0x01; - - //鍙充晶鎸夐敭 - PS2_Data.Key_R_Up = (~PS2_RawData[4] >> 4) & 0x01; - PS2_Data.Key_R_Right = (~PS2_RawData[4] >> 5) & 0x01; - PS2_Data.Key_R_Down = (~PS2_RawData[4] >> 6) & 0x01; - PS2_Data.Key_R_Left = (~PS2_RawData[4] >> 7) & 0x01; - - if (PS2_RawData[1] == 0x41) - { //鏃犵伅妯″紡(鎽囨潌鍊煎叓鍚) - PS2_Data.Rocker_LX = 127 * (PS2_Data.Key_L_Right - PS2_Data.Key_L_Left); - PS2_Data.Rocker_LY = 127 * (PS2_Data.Key_L_Up - PS2_Data.Key_L_Down); - - PS2_Data.Rocker_RX = 127 * (PS2_Data.Key_R_Right - PS2_Data.Key_R_Left); - PS2_Data.Rocker_RY = 127 * (PS2_Data.Key_R_Up - PS2_Data.Key_R_Down); - } - else if (PS2_RawData[1] == 0x73) - { //绾㈢伅妯″紡(鎽囨潌鍊兼ā鎷) - - //鎽囨潌鎸夐敭 - PS2_Data.Key_Rocker_Left = (~PS2_RawData[3] >> 1) & 0x01; - PS2_Data.Key_Rocker_Right = (~PS2_RawData[3] >> 2) & 0x01; - - //鎽囨潌鍊 - PS2_Data.Rocker_LX = PS2_RawData[7] - 0x80; - PS2_Data.Rocker_LY = -1 - (PS2_RawData[8] - 0x80); - PS2_Data.Rocker_RX = PS2_RawData[5] - 0x80; - PS2_Data.Rocker_RY = -1 - (PS2_RawData[6] - 0x80); - } - } -} -void PS2_Read_Data(void) -{ - PS2_CS(0); - PS2_RawData[0] = PS2_ReadWrite_Byte(0x01); // 0 - PS2_RawData[1] = PS2_ReadWrite_Byte(0x42); // 1 - for (int i = 2; i < 9; i++) - PS2_RawData[i] = PS2_ReadWrite_Byte(0xff); - PS2_CS(1); - PS2_Decode(); -} - diff --git a/modules/ps_handle/ps_handle.h b/modules/ps_handle/ps_handle.h deleted file mode 100644 index bd35311..0000000 --- a/modules/ps_handle/ps_handle.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef PS_HANDLE_H -#define PS_HANDLE_H - -#include "bsp_spi.h" -#include "bsp_gpio.h" -#include "bsp_dwt.h" - -#define PS2_CS_GPIOx GPIOB -#define PS2_CS_Pin GPIO_PIN_12 - -#define PS2_CLK_GPIOx GPIOB -#define PS2_CLK_Pin GPIO_PIN_13 - -#define PS2_DO_GPIOx GPIOB -#define PS2_DO_Pin GPIO_PIN_15 - -#define PS2_DI_GPIOx GPIOB -#define PS2_DI_Pin GPIO_PIN_14 - -typedef struct -{ - uint8_t A_D; //妯℃嫙(绾㈢伅)涓1 鏁板瓧(鏃犵伅)涓0 - int8_t Rocker_RX, Rocker_RY, Rocker_LX, Rocker_LY; //鎽囨潌鍊(妯℃嫙鐘舵佷负瀹為檯鍊0-0xFF)(鏁板瓧鎬佷负绛夋晥鐨勫0,0x80,0xFF) - //鎸夐敭鍊0涓烘湭瑙﹀彂,1涓鸿Е鍙戞 - uint8_t Key_L1, Key_L2, Key_R1, Key_R2; //鍚庝晶澶ф寜閿 - uint8_t Key_L_Right, Key_L_Left, Key_L_Up, Key_L_Down; //宸︿晶鎸夐敭 - uint8_t Key_R_Right, Key_R_Left, Key_R_Up, Key_R_Down; //鍙充晶鎸夐敭 - uint8_t Key_Select; //閫夋嫨閿 - uint8_t Key_Start; //寮濮嬮敭 - uint8_t Key_Rocker_Left, Key_Rocker_Right; //鎽囨潌鎸夐敭 - -} PS2_Instance; - - - - - -#endif // !PS_HANDLE_H#define PS_HANDLE_H diff --git a/modules/ps_handle/ps_handle.md b/modules/ps_handle/ps_handle.md deleted file mode 100644 index 81cf423..0000000 --- a/modules/ps_handle/ps_handle.md +++ /dev/null @@ -1,3 +0,0 @@ -# ps_handle - -鎻愪緵ps鎵嬫焺鐨勬敮鎸,鍏堕氫俊鍗忚鍜宻pi绫讳技,鍙互浣跨敤bsp_spi鏉ュ吋瀹.寰呯紪鍐. \ No newline at end of file diff --git a/modules/referee/rm_referee.c b/modules/referee/rm_referee.c index 4a31da5..d76c6cf 100644 --- a/modules/referee/rm_referee.c +++ b/modules/referee/rm_referee.c @@ -15,8 +15,9 @@ #include "bsp_usart.h" #include "task.h" #include "daemon.h" +#include "bsp_log.h" -#define RE_RX_BUFFER_SIZE 200 +#define RE_RX_BUFFER_SIZE 255u // 瑁佸垽绯荤粺鎺ユ敹缂撳啿鍖哄ぇ灏 static USARTInstance *referee_usart_instance; // 瑁佸垽绯荤粺涓插彛瀹炰緥 static DaemonInstance *referee_daemon; // 瑁佸垽绯荤粺瀹堟姢杩涚▼ @@ -114,6 +115,7 @@ static void RefereeRxCallback() static void RefereeLostCallback(void *arg) { USARTServiceInit(referee_usart_instance); + LOGWARNING("[rm_ref] lost referee data"); } /* 瑁佸垽绯荤粺閫氫俊鍒濆鍖 */ @@ -122,7 +124,7 @@ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) USART_Init_Config_s conf; conf.module_callback = RefereeRxCallback; conf.usart_handle = referee_usart_handle; - conf.recv_buff_size = RE_RX_BUFFER_SIZE; + conf.recv_buff_size = RE_RX_BUFFER_SIZE; // mx 255(u8) referee_usart_instance = USARTRegister(&conf); Daemon_Init_Config_s daemon_conf = { @@ -143,5 +145,5 @@ void RefereeSend(uint8_t *send, uint16_t tx_len) { static TickType_t xLastWakeTime; USARTSend(referee_usart_instance, send, tx_len, USART_TRANSFER_DMA); - vTaskDelayUntil(&xLastWakeTime, 120); + vTaskDelayUntil(&xLastWakeTime, 120); // 瑁佸垽绯荤粺鎺ユ敹ui鏁版嵁鍜屽鏈洪氫俊鏈澶ф敮鎸侀鐜囦负10Hz } diff --git a/modules/remote/remote_control.c b/modules/remote/remote_control.c index 239403d..4035304 100644 --- a/modules/remote/remote_control.c +++ b/modules/remote/remote_control.c @@ -4,6 +4,7 @@ #include "memory.h" #include "stdlib.h" #include "daemon.h" +#include "bsp_log.h" #define REMOTE_CONTROL_FRAME_SIZE 18u // 閬ユ帶鍣ㄦ帴鏀剁殑buffer澶у皬 @@ -104,6 +105,7 @@ static void RCLostCallback(void *id) { memset(rc_ctrl, 0, sizeof(rc_ctrl)); // 娓呯┖閬ユ帶鍣ㄦ暟鎹 USARTServiceInit(rc_usart_instance); // 灏濊瘯閲嶆柊鍚姩鎺ユ敹 + LOGWARNING("[rc] remote control lost"); } RC_ctrl_t *RemoteControlInit(UART_HandleTypeDef *rc_usart_handle) From b4d4228ccca9b2821cf7c3a719f0e6cbd7297008 Mon Sep 17 00:00:00 2001 From: NeoZng Date: Fri, 23 Jun 2023 15:56:20 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86freertos?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81include=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86daemon=E7=9A=84=E4=B8=8A=E7=BA=BF=E7=AD=89=E5=BE=85?= =?UTF-8?q?=E6=97=B6=E9=97=B4=EF=BC=8C=E5=A2=9E=E5=8A=A0pid=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=95=B4=E5=AE=9A=E6=8C=87=E5=8D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/FreeRTOSConfig.h | 1 + Makefile | 3 ++- application/cmd/robot_cmd.c | 10 +--------- basic_framework.ioc | 3 ++- bsp/{log => flash}/bsp_flash.c | 0 bsp/{log => flash}/bsp_flash.h | 0 bsp/flash/bsp_flash.md | 0 modules/BMI088/bmi088.c | 2 +- modules/algorithm/user_lib.c | 5 ++--- modules/algorithm/user_lib.h | 4 +--- modules/daemon/daemon.c | 3 ++- modules/daemon/daemon.h | 1 + modules/led/led.c | 2 +- 鍚堢悊鍦拌繘琛孭ID鍙傛暟鏁村畾.md | 3 +++ 14 files changed, 17 insertions(+), 20 deletions(-) rename bsp/{log => flash}/bsp_flash.c (100%) rename bsp/{log => flash}/bsp_flash.h (100%) create mode 100644 bsp/flash/bsp_flash.md create mode 100644 鍚堢悊鍦拌繘琛孭ID鍙傛暟鏁村畾.md diff --git a/Inc/FreeRTOSConfig.h b/Inc/FreeRTOSConfig.h index a7de255..49e09e9 100644 --- a/Inc/FreeRTOSConfig.h +++ b/Inc/FreeRTOSConfig.h @@ -69,6 +69,7 @@ #define configUSE_16_BIT_TICKS 0 #define configUSE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 8 +#define configUSE_COUNTING_SEMAPHORES 1 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 /* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */ /* Defaults to size_t for backward compatibility, but can be changed diff --git a/Makefile b/Makefile index c9c229f..7d22a54 100644 --- a/Makefile +++ b/Makefile @@ -119,7 +119,7 @@ bsp/can/bsp_can.c \ bsp/usart/bsp_usart.c \ bsp/usb/bsp_usb.c \ bsp/log/bsp_log.c \ -bsp/log/bsp_flash.c \ +bsp/flash/bsp_flash.c \ bsp/bsp_init.c \ modules/algorithm/controller.c \ modules/algorithm/kalman_filter.c \ @@ -244,6 +244,7 @@ C_INCLUDES = \ -Ibsp/spi \ -Ibsp/iic \ -Ibsp/log \ +-Ibsp/flash \ -Ibsp/pwm \ -Ibsp/bsp_legacy_support \ -Ibsp \ diff --git a/application/cmd/robot_cmd.c b/application/cmd/robot_cmd.c index 8188dc3..6a989ce 100644 --- a/application/cmd/robot_cmd.c +++ b/application/cmd/robot_cmd.c @@ -132,16 +132,8 @@ static void RemoteControlSet() { // 鎸夌収鎽囨潌鐨勮緭鍑哄ぇ灏忚繘琛岃搴﹀閲,澧炵泭绯绘暟闇璋冩暣 gimbal_cmd_send.yaw += 0.005f * (float)rc_data[TEMP].rc.rocker_l_; gimbal_cmd_send.pitch += 0.001f * (float)rc_data[TEMP].rc.rocker_l1; - // 鎽囨潌鎺у埗鐨勮蒋浠堕檺浣 - // if (gimbal_cmd_send.pitch <= PITCH_MIN_ECD) - // { - // gimbal_cmd_send.pitch = PITCH_MIN_ECD; - // } - // else if (gimbal_cmd_send.pitch >= PITCH_MAX_ECD) - // { - // gimbal_cmd_send.pitch = PITCH_MAX_ECD; - // } } + // 浜戝彴杞欢闄愪綅 // 搴曠洏鍙傛暟,鐩墠娌℃湁鍔犲叆灏忛檧铻(璋冭瘯浼间箮鏆傛椂娌℃湁蹇呰),绯绘暟闇瑕佽皟鏁 chassis_cmd_send.vx = 10.0f * (float)rc_data[TEMP].rc.rocker_r_; // _姘村钩鏂瑰悜 diff --git a/basic_framework.ioc b/basic_framework.ioc index ebde68e..3cb82bd 100644 --- a/basic_framework.ioc +++ b/basic_framework.ioc @@ -174,11 +174,12 @@ Dma.USART6_TX.1.PeriphInc=DMA_PINC_DISABLE Dma.USART6_TX.1.Priority=DMA_PRIORITY_HIGH Dma.USART6_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst FREERTOS.INCLUDE_vTaskDelayUntil=1 -FREERTOS.IPParameters=Tasks01,configENABLE_FPU,configMAX_TASK_NAME_LEN,configUSE_TIMERS,configUSE_POSIX_ERRNO,INCLUDE_vTaskDelayUntil,configTOTAL_HEAP_SIZE +FREERTOS.IPParameters=Tasks01,configENABLE_FPU,configMAX_TASK_NAME_LEN,configUSE_TIMERS,configUSE_POSIX_ERRNO,INCLUDE_vTaskDelayUntil,configTOTAL_HEAP_SIZE,configUSE_COUNTING_SEMAPHORES FREERTOS.Tasks01=defaultTask,0,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL FREERTOS.configENABLE_FPU=1 FREERTOS.configMAX_TASK_NAME_LEN=32 FREERTOS.configTOTAL_HEAP_SIZE=20000 +FREERTOS.configUSE_COUNTING_SEMAPHORES=1 FREERTOS.configUSE_POSIX_ERRNO=0 FREERTOS.configUSE_TIMERS=0 File.Version=6 diff --git a/bsp/log/bsp_flash.c b/bsp/flash/bsp_flash.c similarity index 100% rename from bsp/log/bsp_flash.c rename to bsp/flash/bsp_flash.c diff --git a/bsp/log/bsp_flash.h b/bsp/flash/bsp_flash.h similarity index 100% rename from bsp/log/bsp_flash.h rename to bsp/flash/bsp_flash.h diff --git a/bsp/flash/bsp_flash.md b/bsp/flash/bsp_flash.md new file mode 100644 index 0000000..e69de29 diff --git a/modules/BMI088/bmi088.c b/modules/BMI088/bmi088.c index 2126cec..fb0ec46 100644 --- a/modules/BMI088/bmi088.c +++ b/modules/BMI088/bmi088.c @@ -382,7 +382,7 @@ void BMI088CalibrateIMU(BMI088Instance *_bmi088) BMI088Instance *BMI088Register(BMI088_Init_Config_s *config) { // 鐢宠鍐呭瓨 - BMI088Instance *bmi088_instance = (BMI088Instance *)zero_malloc(sizeof(BMI088Instance)); + BMI088Instance *bmi088_instance = (BMI088Instance *)zmalloc(sizeof(BMI088Instance)); // 浠庡彸鍚戝乏璧嬪,璁゜sp instance淇濆瓨鎸囧悜bmi088_instance鐨勬寚閽(鐖舵寚閽),渚夸簬鍦ㄥ簳灞備腑鏂腑璁块棶bmi088_instance config->acc_int_config.id = config->gyro_int_config.id = diff --git a/modules/algorithm/user_lib.c b/modules/algorithm/user_lib.c index eb3b021..b511bb9 100644 --- a/modules/algorithm/user_lib.c +++ b/modules/algorithm/user_lib.c @@ -23,9 +23,7 @@ #define user_malloc malloc #endif -uint8_t GlobalDebugMode = 7; - -void *zero_malloc(size_t size) +void *zmalloc(size_t size) { void *ptr = malloc(size); memset(ptr, 0, size); @@ -207,3 +205,4 @@ float AverageFilter(float new_data, float *buf, uint8_t len) sum += new_data; return sum / len; } + diff --git a/modules/algorithm/user_lib.h b/modules/algorithm/user_lib.h index 4404c46..fc90e5a 100644 --- a/modules/algorithm/user_lib.h +++ b/modules/algorithm/user_lib.h @@ -23,8 +23,6 @@ #define mcos(x) (arm_cos_f32(x)) -extern uint8_t GlobalDebugMode; - #ifndef user_malloc #ifdef _CMSIS_OS_H #define user_malloc pvPortMalloc @@ -89,7 +87,7 @@ extern uint8_t GlobalDebugMode; * @param size 鍒嗛厤澶у皬 * @return void* */ -void *zero_malloc(size_t size); +void *zmalloc(size_t size); // 锟斤拷锟劫匡拷锟斤拷 float Sqrt(float x); diff --git a/modules/daemon/daemon.c b/modules/daemon/daemon.c index 85cf752..01b4f87 100644 --- a/modules/daemon/daemon.c +++ b/modules/daemon/daemon.c @@ -13,8 +13,9 @@ DaemonInstance *DaemonRegister(Daemon_Init_Config_s *config) memset(instance, 0, sizeof(DaemonInstance)); instance->owner_id = config->owner_id; - instance->reload_count = config->reload_count == 0 ? 100 : config->reload_count; + instance->reload_count = config->reload_count == 0 ? 100 : config->reload_count; // 榛樿鍊间负100 instance->callback = config->callback; + instance->temp_count = config->init_count == 0 ? 100 : config->init_count; // 榛樿鍊间负100,鍒濆璁℃暟 daemon_instances[idx++] = instance; return instance; diff --git a/modules/daemon/daemon.h b/modules/daemon/daemon.h index e729c96..a3a42cc 100644 --- a/modules/daemon/daemon.h +++ b/modules/daemon/daemon.h @@ -22,6 +22,7 @@ typedef struct daemon_ins typedef struct { uint16_t reload_count; // 瀹為檯涓婅繖鏄痑pp鍞竴闇瑕佽缃殑鍊? + uint16_t init_count; // 涓婄嚎绛夊緟鏃堕棿,鏈変簺妯″潡闇瑕佹敹鍒颁富鎺х殑鎸囦护鎵嶄細鍙嶉鎶ユ枃,鎴杙c绛夐渶瑕佸紑鏈烘椂闂 offline_callback callback; // 寮傚父澶勭悊鍑芥暟,褰撴ā鍧楀彂鐢熷紓甯告椂浼氳璋冪敤 void *owner_id; // id鍙栨嫢鏈塪aemon鐨勫疄渚嬬殑鍦板潃,濡侱JIMotorInstance*,cast鎴恦oid*绫诲瀷 } Daemon_Init_Config_s; diff --git a/modules/led/led.c b/modules/led/led.c index f3f4a38..6140fc0 100644 --- a/modules/led/led.c +++ b/modules/led/led.c @@ -8,7 +8,7 @@ static LEDInstance *bsp_led_ins[LED_MAX_NUM] = {NULL}; LEDInstance *LEDRegister(LED_Init_Config_s *led_config) { - LEDInstance *led_ins = (LEDInstance *)zero_malloc(sizeof(LEDInstance)); + LEDInstance *led_ins = (LEDInstance *)zmalloc(sizeof(LEDInstance)); // 鍓╀笅鐨勫兼殏鏃堕兘琚疆闆 led_ins->led_pwm = PWMRegister(&led_config->pwm_config); led_ins->led_switch = led_config->init_swtich; diff --git a/鍚堢悊鍦拌繘琛孭ID鍙傛暟鏁村畾.md b/鍚堢悊鍦拌繘琛孭ID鍙傛暟鏁村畾.md new file mode 100644 index 0000000..17195b2 --- /dev/null +++ b/鍚堢悊鍦拌繘琛孭ID鍙傛暟鏁村畾.md @@ -0,0 +1,3 @@ +# 鍒╃敤Ozone杩涜model-based PID tunning + +Ozone鐨勫疄鏃跺彉閲忓彲瑙嗗寲鐩戞祴(绀烘尝鍣)鍔熻兘鍙互寰堝ソ鍦板府鍔╂垜浠瀵熸帶鍒跺櫒鍦ㄦ椂鍩熺殑琛ㄧ幇锛屽吀鍨嬬殑鏈変笂鍗囨椂闂淬佽秴璋冮噺鍜岀ǔ鎬佹椂闂寸瓑銆 \ No newline at end of file From c85c13f959683be63bb74286aea1ede77810bbf4 Mon Sep 17 00:00:00 2001 From: chenfu <2412777093@qq.com> Date: Fri, 23 Jun 2023 17:05:55 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=B0=86=E8=AD=A6=E6=8A=A5=E5=A3=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=B0DaemonTask?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 ++ bsp/bsp_init.c | 4 ++-- bsp/bsp_legacy_support/bsp_buzzer.c | 28 ---------------------------- bsp/bsp_legacy_support/bsp_buzzer.h | 10 ---------- bsp/pwm/bsp_pwm.c | 10 +++++++--- modules/daemon/daemon.c | 11 ++++++++++- modules/daemon/daemon.h | 23 +++++++++++++++++++++-- 7 files changed, 42 insertions(+), 46 deletions(-) diff --git a/Makefile b/Makefile index c9c229f..8b71b87 100644 --- a/Makefile +++ b/Makefile @@ -153,6 +153,7 @@ modules/can_comm/can_comm.c \ modules/message_center/message_center.c \ modules/daemon/daemon.c \ modules/vofa/vofa.c \ +modules/alarm/buzzer.c \ application/gimbal/gimbal.c \ application/chassis/chassis.c \ application/shoot/shoot.c \ @@ -268,6 +269,7 @@ C_INCLUDES = \ -Imodules/message_center \ -Imodules/daemon \ -Imodules/vofa \ +-Imodules/alarm \ -Imodules diff --git a/bsp/bsp_init.c b/bsp/bsp_init.c index d85f809..1166f09 100644 --- a/bsp/bsp_init.c +++ b/bsp/bsp_init.c @@ -2,7 +2,7 @@ #include "bsp_log.h" #include "bsp_dwt.h" #include "bsp_usb.h" -#include "bsp_buzzer.h" +#include "buzzer.h" #include "bsp_led.h" #include "bsp_temperature.h" @@ -16,5 +16,5 @@ void BSPInit() // legacy support锛屽緟鍒犻櫎,灏嗗湪瀹炵幇浜唋ed/tempctrl/buzzer鐨刴odule涔嬪悗绉诲姩鍒癮pp灞傝繘琛孹XXRegister() LEDInit(); IMUTempInit(); - BuzzerInit(); + buzzer_init(); } \ No newline at end of file diff --git a/bsp/bsp_legacy_support/bsp_buzzer.c b/bsp/bsp_legacy_support/bsp_buzzer.c index 625d53f..e69de29 100644 --- a/bsp/bsp_legacy_support/bsp_buzzer.c +++ b/bsp/bsp_legacy_support/bsp_buzzer.c @@ -1,28 +0,0 @@ -#include "bsp_buzzer.h" -#include "main.h" - -#warning this is a legacy support file, please use the new version - -extern TIM_HandleTypeDef htim4; -static uint8_t tmp_warning_level = 0; - -void BuzzerInit() -{ - HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); -} - -void BuzzerOn(uint16_t psc, uint16_t pwm, uint8_t level) -{ - if (level > tmp_warning_level) - { - tmp_warning_level = level; - __HAL_TIM_PRESCALER(&htim4, psc); - __HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_3, pwm); - } -} - -void BuzzerOff(void) -{ - __HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_3, 0); - tmp_warning_level = 0; -} diff --git a/bsp/bsp_legacy_support/bsp_buzzer.h b/bsp/bsp_legacy_support/bsp_buzzer.h index cc09a68..e69de29 100644 --- a/bsp/bsp_legacy_support/bsp_buzzer.h +++ b/bsp/bsp_legacy_support/bsp_buzzer.h @@ -1,10 +0,0 @@ -#ifndef BSP_BUZZER_H -#define BSP_BUZZER_H - -#include - -void BuzzerInit(); -extern void BuzzerOn(uint16_t psc, uint16_t pwm, uint8_t level); -extern void BuzzerOff(void); - -#endif diff --git a/bsp/pwm/bsp_pwm.c b/bsp/pwm/bsp_pwm.c index 410992b..9e56ef8 100644 --- a/bsp/pwm/bsp_pwm.c +++ b/bsp/pwm/bsp_pwm.c @@ -15,7 +15,7 @@ void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) { for (uint8_t i = 0; i < idx; i++) { // 鏉ヨ嚜鍚屼竴涓畾鏃跺櫒鐨勪腑鏂笖閫氶亾鐩稿悓 - if (pwm_instance[i]->htim == htim && htim->Channel == pwm_instance[i]->channel) + if (pwm_instance[i]->htim == htim && htim->Channel == (1<<(pwm_instance[i]->channel/4))) { if (pwm_instance[i]->callback) // 濡傛灉鏈夊洖璋冨嚱鏁 pwm_instance[i]->callback(pwm_instance[i]); @@ -39,7 +39,7 @@ PWMInstance *PWMRegister(PWM_Init_Config_s *config) pwm->callback = config->callback; pwm->id = config->id; // 鍚姩PWM - HAL_TIM_PWM_Start(pwm->htim, pwm->channel); + HAL_TIM_PWM_Start_IT(pwm->htim, pwm->channel); __HAL_TIM_SetCompare(pwm->htim, pwm->channel, pwm->pulse); // 璁剧疆鍗犵┖姣 pwm_instance[idx++] = pwm; @@ -65,7 +65,11 @@ void PWMSetPulse(PWMInstance *pwm, uint32_t pulse) pwm->pulse = pulse; __HAL_TIM_SetCompare(pwm->htim, pwm->channel, pwm->pulse); } - +void PWMSetPeriod(PWMInstance *pwm, uint32_t period) +{ + pwm->period = period; + __HAL_TIM_PRESCALER(pwm->htim, pwm->period); +} /* 鍙槸瀵笻AL鐨勫嚱鏁拌繘琛屼簡褰㈠紡涓婄殑灏佽 */ void PWMStartDMA(PWMInstance *pwm, uint32_t *pData, uint32_t Size) { diff --git a/modules/daemon/daemon.c b/modules/daemon/daemon.c index 85cf752..00a4ec2 100644 --- a/modules/daemon/daemon.c +++ b/modules/daemon/daemon.c @@ -2,6 +2,7 @@ #include "bsp_dwt.h" // 鍚庣画閫氳繃瀹氭椂鍣ㄦ潵璁℃椂? #include "stdlib.h" #include "memory.h" +#include "buzzer.h" // 鐢ㄤ簬淇濆瓨鎵鏈夌殑daemon instance static DaemonInstance *daemon_instances[DAEMON_MX_CNT] = {NULL}; @@ -15,7 +16,9 @@ DaemonInstance *DaemonRegister(Daemon_Init_Config_s *config) instance->owner_id = config->owner_id; instance->reload_count = config->reload_count == 0 ? 100 : config->reload_count; instance->callback = config->callback; - + instance->alarm_state = config->alarm_state; + instance->alarm_level = config->alarm_level; + instance->temp_count = config->reload_count; daemon_instances[idx++] = instance; return instance; } @@ -36,6 +39,7 @@ void DaemonTask() DaemonInstance *dins; // 鎻愰珮鍙鎬у悓鏃堕檷浣庤瀛樺紑閿 for (size_t i = 0; i < idx; ++i) { + dins = daemon_instances[i]; if (dins->temp_count > 0) // 濡傛灉璁℃暟鍣ㄨ繕鏈夊,璇存槑涓婁竴娆″杺鐙楀悗杩樻病鏈夎秴鏃,鍒欒鏁板櫒鍑忎竴 dins->temp_count--; @@ -43,6 +47,11 @@ void DaemonTask() { dins->callback(dins->owner_id); // module鍐呭彲浠ュ皢owner_id寮哄埗绫诲瀷杞崲鎴愯嚜韬被鍨嬩粠鑰岃皟鐢ㄧ壒瀹歮odule鐨刼ffline callback // @todo 涓鸿渹楦e櫒/led绛夊鍔犵绾挎姤璀︾殑鍔熻兘,闈炲父鍏抽敭! + if(dins->alarm_state == ALARM_ON) + { + BuzzerPlay(dins->alarm_level); + } + } } } diff --git a/modules/daemon/daemon.h b/modules/daemon/daemon.h index e729c96..d99fdff 100644 --- a/modules/daemon/daemon.h +++ b/modules/daemon/daemon.h @@ -2,18 +2,34 @@ #define MONITOR_H #include "stdint.h" +#include "string.h" #define DAEMON_MX_CNT 64 /* 妯″潡绂荤嚎澶勭悊鍑芥暟鎸囬拡 */ typedef void (*offline_callback)(void *); - +typedef enum +{ + ALARM_OFF = 0, + ALARM_ON = 1, +}alarm_state_e; +typedef enum +{ + ALARM_LEVEL_LOW = 0, + ALARM_LEVEL_BELOW_MEDIUM = 1, + ALARM_LEVEL_MEDIUM = 2, + ALARM_LEVEL_ABOVE_MEDIUM = 3, + ALARM_LEVEL_HIGH = 4, + ALARM_OFFLINE = 5, +}alarm_level_e; /* daemon缁撴瀯浣撳畾涔 */ typedef struct daemon_ins { uint16_t reload_count; // 閲嶈浇鍊 offline_callback callback; // 寮傚父澶勭悊鍑芥暟,褰撴ā鍧楀彂鐢熷紓甯告椂浼氳璋冪敤 - + alarm_state_e alarm_state; // 铚傞福鍣ㄧ姸鎬 + alarm_level_e alarm_level; //璀︽姤绾у埆 + uint16_t temp_count; // 褰撳墠鍊,鍑忎负闆惰鏄庢ā鍧楃绾挎垨寮傚父 void *owner_id; // daemon瀹炰緥鐨勫湴鍧,鍒濆鍖栫殑鏃跺欏~鍏 } DaemonInstance; @@ -23,6 +39,9 @@ typedef struct { uint16_t reload_count; // 瀹為檯涓婅繖鏄痑pp鍞竴闇瑕佽缃殑鍊? offline_callback callback; // 寮傚父澶勭悊鍑芥暟,褰撴ā鍧楀彂鐢熷紓甯告椂浼氳璋冪敤 + alarm_state_e alarm_state; // 铚傞福鍣ㄧ姸鎬 + alarm_level_e alarm_level; //璀︽姤绾у埆 + void *owner_id; // id鍙栨嫢鏈塪aemon鐨勫疄渚嬬殑鍦板潃,濡侱JIMotorInstance*,cast鎴恦oid*绫诲瀷 } Daemon_Init_Config_s; From f51b6fec3dba2fcf91da07f04a83a4d885881aa8 Mon Sep 17 00:00:00 2001 From: chenfu <2412777093@qq.com> Date: Fri, 23 Jun 2023 17:11:10 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=9C=82=E9=B8=A3=E5=99=A8=E7=A7=BB?= =?UTF-8?q?=E6=A4=8D=E5=88=B0modules=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/alarm/buzzer.c | 88 ++++++++++++++++++++++++++++++++++++++++++ modules/alarm/buzzer.h | 7 ++++ 2 files changed, 95 insertions(+) create mode 100644 modules/alarm/buzzer.c create mode 100644 modules/alarm/buzzer.h diff --git a/modules/alarm/buzzer.c b/modules/alarm/buzzer.c new file mode 100644 index 0000000..b768058 --- /dev/null +++ b/modules/alarm/buzzer.c @@ -0,0 +1,88 @@ +#include "bsp_pwm.h" +#include "buzzer.h" +#include "bsp_dwt.h" + +static PWMInstance *buzzer; + +static alarm_level_e now_alarm_level = ALARM_OFFLINE; + +void BuzzerOn(PWMInstance *buzzer ); +/** +* +* @brief 铚傞福鍣ㄦ姤璀﹀嚱鏁 +* @param alarm_level 鎶ヨ绾у埆 +*/ +void BuzzerPlay(alarm_level_e alarm_level) +{ + static alarm_level_e last_alarm_level = ALARM_LEVEL_LOW; + + if(((int)DWT_GetTimeline_s() % 5)<1) //姣5绉掓鏌ヤ竴娆 + { + last_alarm_level = ALARM_LEVEL_LOW; + now_alarm_level = ALARM_OFFLINE; + } + + if(last_alarm_level <= now_alarm_level) //濡傛灉褰撳墠鎶ヨ绾у埆澶т簬绛変簬涓婁竴娆℃姤璀︾骇鍒,鍒欐洿鏂版姤璀︾骇鍒 + { + now_alarm_level = alarm_level; + } + last_alarm_level = alarm_level; + +} + +/** + * @brief 铚傞福鍣ㄥ垵濮嬪寲 + * + */ +void buzzer_init() +{ + PWM_Init_Config_s buzzer_config = { + .htim = &htim4, + .channel= TIM_CHANNEL_3, + .period = 1, + .pulse = 10000, + .callback = BuzzerOn, + }; + buzzer = PWMRegister(&buzzer_config); +} +/** + * @brief 寮鍚渹楦e櫒 + * + * @param buzzer + */ +//*@todo: 浼樺寲鎶ヨ澹帮紝搴旂被浼糄__,DDD,B__,BBB绛夋姤璀﹀0 +void BuzzerOn(PWMInstance *buzzer ) +{ + switch (now_alarm_level) + { + case ALARM_LEVEL_LOW: + PWMSetPeriod(buzzer, 1); + PWMSetPulse(buzzer, 10000); + break; + case ALARM_LEVEL_BELOW_MEDIUM: + PWMSetPeriod(buzzer, 2); + PWMSetPulse(buzzer, 10000); + break; + case ALARM_LEVEL_MEDIUM: + PWMSetPeriod(buzzer, 3); + PWMSetPulse(buzzer, 10000); + break; + case ALARM_LEVEL_ABOVE_MEDIUM: + PWMSetPeriod(buzzer, 4); + PWMSetPulse(buzzer, 10000); + break; + case ALARM_LEVEL_HIGH: + PWMSetPeriod(buzzer, 5); + PWMSetPulse(buzzer, 10000); + break; + + default: + PWMSetPulse(buzzer, 0); + break; + } +} + + + + + diff --git a/modules/alarm/buzzer.h b/modules/alarm/buzzer.h new file mode 100644 index 0000000..3a8668e --- /dev/null +++ b/modules/alarm/buzzer.h @@ -0,0 +1,7 @@ +#ifndef BUZZER_H +#define BUZZER_H +#include "daemon.h" +void buzzer_init(); + + +#endif // !BUZZER_H From 9ef46e2f8816f7d4ded5d489e0286f676ea467cf Mon Sep 17 00:00:00 2001 From: NeoZng Date: Sat, 24 Jun 2023 20:29:57 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E7=BC=96=E8=AF=91=E4=BC=98=E5=8C=96=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86log=E4=BD=BF=E7=94=A8=E6=96=87=E6=A1=A3?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86user=5Flib?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 12 ++++++----- Src/main.c | 2 ++ bsp/log/bsp_log.h | 39 +++++++++++++++++++----------------- bsp/log/bsp_log.md | 17 ++++------------ bsp/pwm/bsp_pwm.c | 2 ++ modules/algorithm/user_lib.c | 6 ++++++ modules/algorithm/user_lib.h | 25 +++++++++++++---------- 鍚堢悊鍦拌繘琛孭ID鍙傛暟鏁村畾.md | 6 +++++- 8 files changed, 61 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 1d537ce..456a6bd 100644 --- a/Makefile +++ b/Makefile @@ -199,7 +199,7 @@ FPU = -mfpu=fpv4-sp-d16 FLOAT-ABI = -mfloat-abi=hard # mcu -MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) +MCU = $(CPU) -mthumb -mthumb-interwork $(FPU) $(FLOAT-ABI) # macros for gcc # AS defines @@ -211,7 +211,9 @@ C_DEFS = \ -DSTM32F407xx \ -DARM_MATH_CM4 \ -DARM_MATH_MATRIX_CHECK \ --DARM_MATH_ROUNDING +-DARM_MATH_ROUNDING \ +-DARM_MATH_LOOPUNROLL \ +-DISABLEFLOAT16 # AS includes AS_INCLUDES = \ @@ -277,7 +279,7 @@ C_INCLUDES = \ # compile gcc flags ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -fdata-sections -ffunction-sections -CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -fdata-sections -ffunction-sections +CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -fdata-sections -ffunction-sections -fmessage-length=0 ifeq ($(DEBUG), 1) CFLAGS += -g -gdwarf-2 @@ -299,7 +301,7 @@ LIBS = -lc -lm -lnosys \ -l:libarm_cortexM4lf_math.a LIBDIR = \ -LMiddlewares/ST/ARM/DSP/Lib -LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections +LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -flto # default action: build all all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin @@ -339,7 +341,7 @@ $(BUILD_DIR): # clean up ####################################### clean: - rd /s/q $(BUILD_DIR) + rd $(BUILD_DIR) /s/q ####################################### diff --git a/Src/main.c b/Src/main.c index 5a1f4b0..ce57ebb 100644 --- a/Src/main.c +++ b/Src/main.c @@ -36,6 +36,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "robot.h" +#include "bsp_log.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -120,6 +121,7 @@ int main(void) MX_DAC_Init(); /* USER CODE BEGIN 2 */ RobotInit(); // 鍞竴鐨勫垵濮嬪寲鍑芥暟 + LOGINFO("[main] SystemInit() and RobotInit() done"); /* USER CODE END 2 */ /* Call init function for freertos objects (in freertos.c) */ diff --git a/bsp/log/bsp_log.h b/bsp/log/bsp_log.h index 7709ffe..002be77 100644 --- a/bsp/log/bsp_log.h +++ b/bsp/log/bsp_log.h @@ -7,44 +7,46 @@ #define BUFFER_INDEX 0 - - /** * @brief 鏃ュ織绯荤粺鍒濆鍖 - * + * */ void BSPLogInit(); /** * @brief 鏃ュ織鍔熻兘鍘熷瀷,渚涗笅闈㈢殑LOGI,LOGW,LOGE绛変娇鐢 - * + * */ -#define LOG_PROTO(type,color,format,...) \ - SEGGER_RTT_printf(BUFFER_INDEX," %s%s"format"\r\n%s", \ - color, \ - type, \ - ##__VA_ARGS__, \ +#define LOG_PROTO(type, color, format, ...) \ + SEGGER_RTT_printf(BUFFER_INDEX, " %s%s" format "\r\n%s", \ + color, \ + type, \ + ##__VA_ARGS__, \ RTT_CTRL_RESET) -/*------涓嬮潰鏄棩蹇楄緭鍑虹殑鎺ュ彛--------*/ +/*----------------------------------------涓嬮潰鏄棩蹇楄緭鍑虹殑鎺ュ彛-------------------------------------------------*/ /* 娓呭睆 */ -#define LOG_CLEAR() SEGGER_RTT_WriteString(0, " "RTT_CTRL_CLEAR) +#define LOG_CLEAR() SEGGER_RTT_WriteString(0, " " RTT_CTRL_CLEAR) /* 鏃犻鑹叉棩蹇楄緭鍑 */ -#define LOG(format,...) LOG_PROTO("","",format,##__VA_ARGS__) +#define LOG(format, ...) LOG_PROTO("", "", format, ##__VA_ARGS__) -/* 鏈夐鑹叉牸寮忔棩蹇楄緭鍑,寤鸿浣跨敤杩欎簺瀹忔潵杈撳嚭鏃ュ織 */ +/** + * 鏈夐鑹叉牸寮忔棩蹇楄緭鍑,寤鸿浣跨敤杩欎簺瀹忔潵杈撳嚭鏃ュ織 + * @attention 娉ㄦ剰杩欎簺鎺ュ彛涓嶆敮鎸佹诞鐐规牸寮忓寲杈撳嚭,鑻ユ湁闇瑕,璇蜂娇鐢‵loat2Str()鍑芥暟杩涜杞崲鍚庡啀鎵撳嵃 + */ // information level -#define LOGINFO(format,...) LOG_PROTO("I:", RTT_CTRL_TEXT_BRIGHT_GREEN , format, ##__VA_ARGS__) +#define LOGINFO(format, ...) LOG_PROTO("I:", RTT_CTRL_TEXT_BRIGHT_GREEN, format, ##__VA_ARGS__) // warning level -#define LOGWARNING(format,...) LOG_PROTO("W:", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__) +#define LOGWARNING(format, ...) LOG_PROTO("W:", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__) // error level -#define LOGERROR(format,...) LOG_PROTO("E:", RTT_CTRL_TEXT_BRIGHT_RED , format, ##__VA_ARGS__) +#define LOGERROR(format, ...) LOG_PROTO("E:", RTT_CTRL_TEXT_BRIGHT_RED, format, ##__VA_ARGS__) /** * @brief 閫氳繃segger RTT鎵撳嵃鏃ュ織,鏀寔鏍煎紡鍖栬緭鍑,鏍煎紡鍖栬緭鍑虹殑瀹炵幇鍙傝僷rintf. - * + * @attention !! 姝ゅ嚱鏁颁笉鏀寔娴偣鏍煎紡鍖,鑻ユ湁闇瑕,璇蜂娇鐢‵loat2Str()鍑芥暟杩涜杞崲鍚庡啀鎵撳嵃 !! + * * @param fmt 鏍煎紡瀛楃涓 * @param ... 鍙傛暟鍒楄〃 * @return int 鎵撳嵃鐨刲og瀛楃鏁 @@ -53,7 +55,8 @@ int PrintLog(const char *fmt, ...); /** * @brief 鍒╃敤sprintf(),灏唂loat杞崲涓哄瓧绗︿覆杩涜鎵撳嵃 - * + * @attention 娴偣鏁伴渶瑕佽浆鎹负瀛楃涓插悗鎵嶈兘閫氳繃RTT鎵撳嵃 + * * @param str 杞崲鍚庣殑瀛楃涓 * @param va 寰呰浆鎹㈢殑float */ diff --git a/bsp/log/bsp_log.md b/bsp/log/bsp_log.md index 64be4a3..259c296 100644 --- a/bsp/log/bsp_log.md +++ b/bsp/log/bsp_log.md @@ -2,10 +2,6 @@

neozng1@hnu.edu.cn

-> TODO: -> -> 1. 鍦ㄦ湭鎺ュ叆璋冭瘯鍣ㄧ殑鏃跺欙紝灏嗘棩蹇楀啓鍏lash涓紝骞舵彁渚涙帴鍙h鍙 - ## 浣跨敤璇存槑 bsp_log鏄熀浜巗egger RTT瀹炵幇鐨勬棩蹇楁墦鍗版ā鍧椼 @@ -18,11 +14,11 @@ bsp_log鏄熀浜巗egger RTT瀹炵幇鐨勬棩蹇楁墦鍗版ā鍧椼 #define LOGERROR(format,...) ``` -鍒嗗埆鐢ㄤ簬杈撳嚭涓嶅悓绛夌骇鐨勬棩蹇椼 +鍒嗗埆鐢ㄤ簬杈撳嚭涓嶅悓绛夌骇鐨勬棩蹇椼傛敞鎰廟TT涓嶆敮鎸佺洿鎺ヤ娇鐢╜%f`杩涜娴偣鏍煎紡鍖,瑕佷娇鐢╜void Float2Str(char *str, float va);`杞寲鎴愬瓧绗︿覆涔嬪悗鍐嶅彂閫併 -**鑻ユ兂鍚敤RTT锛屽繀椤婚氳繃`launch.json`鐨刞debug-jlink`鍚姩璋冭瘯锛堜笉璁轰娇鐢ㄤ粈涔堣皟璇曞櫒锛夈** +**鑻ユ兂鍚敤RTT锛屽繀椤婚氳繃`launch.json`鐨刞debug-jlink`鍚姩璋冭瘯锛堜笉璁轰娇鐢ㄤ粈涔堣皟璇曞櫒锛夈** 鎸夌収`VSCode+Ozone鐜閰嶇疆`瀹屾垚閰嶇疆涔嬪悗鐨刢msis dap鍜宒aplink鏄彲浠ユ敮鎸丣link鍏ㄥ妗剁殑銆 -娉ㄦ剰锛岃嫢浣犱娇鐢ㄧ殑鏄痗msis-dap鍜宒aplink锛**璇峰湪璋冭瘯浠诲姟鍚姩涔嬪悗鍐嶆墦寮`log`浠诲姟銆**锛堝潎鍦ㄩ」鐩枃浠跺す涓嬬殑.vsocde/task.json涓紝鏈夋敞閲婅嚜琛屾煡鐪嬶級銆 +鍙﹀锛岃嫢浣犱娇鐢ㄧ殑鏄痗msis-dap鍜宒aplink锛**璇峰湪 *jlink* 璋冭瘯浠诲姟鍚姩涔嬪悗鍐嶆墦寮`log`浠诲姟銆**锛堝潎鍦ㄩ」鐩枃浠跺す涓嬬殑.vsocde/task.json涓紝鏈夋敞閲婅嚜琛屾煡鐪嬶級銆傚惁鍒欏彲鑳藉嚭绾縍TT viewer鏃犳硶杩炴帴瀹㈡埛绔殑鎯呭喌銆 鍦╫zone涓煡鐪媗og杈撳嚭锛岀洿鎺ユ墦寮console璋冭瘯浠诲姟鍙板拰terminal璋冭瘯涓柇渚垮彲鐪嬪埌璋冭瘯杈撳嚭銆 @@ -34,7 +30,7 @@ bsp_log鏄熀浜巗egger RTT瀹炵幇鐨勬棩蹇楁墦鍗版ā鍧椼 ```c int printf_log(const char *fmt, ...); -void Float2Str(char *str, float va); +void Float2Str(char *str, float va); // 杈撳嚭娴偣闇瑕佸厛鐢ㄦ鍑芥暟杩涜杞崲 ``` 璋冪敤绗竴涓嚱鏁帮紝鍙互閫氳繃jlink鎴杁ap-link鍚戣皟璇曞櫒杩炴帴鐨勪笂浣嶆満鍙戦佷俊鎭紝鏍煎紡鍜宲rintf鐩稿悓锛岀ず渚嬪涓嬶細 @@ -52,8 +48,3 @@ char* str_buff[64]; Float2Str(str_buff,current_feedback); printf_log("Motor %d met some problem, error code %d!\n",3,1); ``` - -鎴栫洿鎺ラ氳繃`%f`鏍煎紡绗︾洿鎺ヤ娇鐢╜printf_log()`鍙戦佹棩蹇楋紝鍙互璁剧疆灏忔暟鐐逛綅鏁颁互闄嶄綆甯﹀寮閿銆 - - - diff --git a/bsp/pwm/bsp_pwm.c b/bsp/pwm/bsp_pwm.c index 9e56ef8..403b75c 100644 --- a/bsp/pwm/bsp_pwm.c +++ b/bsp/pwm/bsp_pwm.c @@ -8,6 +8,8 @@ static PWMInstance *pwm_instance[PWM_DEVICE_CNT] = {NULL}; // 鎵鏈夌殑pwm insta /** * @brief pwm dma浼犺緭瀹屾垚鍥炶皟鍑芥暟 + * @attention 鐢变簬HAL搴撶殑璁捐闂,褰撲竴涓猵ulse瀹屾垚(鍗硉im鐨勮鏁拌秴杩囨瘮杈冨瘎瀛樺櫒)涔熶細璋冪敤姝ゅ嚱鏁 + * 鏁呭浜庨偅浜涘紑鍚簡PWM鐨凾IM,鍔″繀鍏抽棴鍏跺叏灞涓柇,浠呬繚鎸丏MA浼犺緭瀹屾垚涓柇鎵撳紑 * * @param htim 鍙戠敓涓柇鐨勫畾鏃跺櫒鍙ユ焺 */ diff --git a/modules/algorithm/user_lib.c b/modules/algorithm/user_lib.c index b511bb9..5029109 100644 --- a/modules/algorithm/user_lib.c +++ b/modules/algorithm/user_lib.c @@ -206,3 +206,9 @@ float AverageFilter(float new_data, float *buf, uint8_t len) return sum / len; } +void MatInit(mat *m, uint8_t row, uint8_t col) +{ + m->numCols = col; + m->numRows = row; + m->pData = (float *)zmalloc(row * col * sizeof(float)); +} diff --git a/modules/algorithm/user_lib.h b/modules/algorithm/user_lib.h index fc90e5a..9a15097 100644 --- a/modules/algorithm/user_lib.h +++ b/modules/algorithm/user_lib.h @@ -13,14 +13,11 @@ #ifndef _USER_LIB_H #define _USER_LIB_H - #include "stdint.h" #include "main.h" #include "cmsis_os.h" - - -#define msin(x) (arm_sin_f32(x)) -#define mcos(x) (arm_cos_f32(x)) +#include "stm32f407xx.h" +#include "arm_math.h" #ifndef user_malloc @@ -31,6 +28,18 @@ #endif #endif +#define msin(x) (arm_sin_f32(x)) +#define mcos(x) (arm_cos_f32(x)) + +typedef arm_matrix_instance_f32 mat; +// 鑻ヨ繍绠楅熷害涓嶅,鍙互浣跨敤q31浠f浛f32,浣嗘槸绮惧害浼氶檷浣 +#define MatAdd arm_mat_add_f32 +#define MatSubtract arm_mat_sub_f32 +#define MatMultiply arm_mat_mult_f32 +#define MatTranspose arm_mat_trans_f32 +#define MatInverse arm_mat_inverse_f32 +void MatInit(mat *m, uint8_t row, uint8_t col); + /* boolean type definitions */ #ifndef TRUE #define TRUE 1 /**< boolean true */ @@ -40,12 +49,6 @@ #define FALSE 0 /**< boolean fails */ #endif -/* math relevant */ -/* radian coefficient */ -#ifndef RADIAN_COEF -#define RADIAN_COEF 57.295779513f -#endif - /* circumference ratio */ #ifndef PI #define PI 3.14159265354f diff --git a/鍚堢悊鍦拌繘琛孭ID鍙傛暟鏁村畾.md b/鍚堢悊鍦拌繘琛孭ID鍙傛暟鏁村畾.md index 17195b2..59ea115 100644 --- a/鍚堢悊鍦拌繘琛孭ID鍙傛暟鏁村畾.md +++ b/鍚堢悊鍦拌繘琛孭ID鍙傛暟鏁村畾.md @@ -1,3 +1,7 @@ # 鍒╃敤Ozone杩涜model-based PID tunning -Ozone鐨勫疄鏃跺彉閲忓彲瑙嗗寲鐩戞祴(绀烘尝鍣)鍔熻兘鍙互寰堝ソ鍦板府鍔╂垜浠瀵熸帶鍒跺櫒鍦ㄦ椂鍩熺殑琛ㄧ幇锛屽吀鍨嬬殑鏈変笂鍗囨椂闂淬佽秴璋冮噺鍜岀ǔ鎬佹椂闂寸瓑銆 \ No newline at end of file +Ozone鐨勫疄鏃跺彉閲忓彲瑙嗗寲鐩戞祴(绀烘尝鍣)鍔熻兘鍙互寰堝ソ鍦板府鍔╂垜浠瀵熸帶鍒跺櫒鍦ㄦ椂鍩熺殑琛ㄧ幇锛屽吀鍨嬬殑鏈変笂鍗囨椂闂淬佽秴璋冮噺鍜岀ǔ鎬佹椂闂寸瓑銆 + +## 璋冭瘯椤哄簭 + +鍏堝唴鐜紝鍚庡鐜傝嫢鏈夊凡鐭ョ殑澶栭儴鎵板姩濡傞樆鍔涖侀噸鍔涚瓑鍙互鍦**淇濇寔kp涓嶅彉**鐨勬儏鍐典笅娣诲姞绉垎鐜妭锛屽苟鏌ョ湅杈惧埌绋虫佹椂绉垎鐨勮緭鍑猴紝璇ヨ緭鍑哄煎彲浠ヤ綔涓**鍓嶉**浣滅敤閫氳繃feedforward_ptr涓鍚岄佸叆涓嬩竴涓覆绾ф帶鍒跺櫒銆 \ No newline at end of file