diff --git a/.gitignore b/.gitignore index 844cd0c..b1241dc 100644 --- a/.gitignore +++ b/.gitignore @@ -51,5 +51,5 @@ build ./idea .vscode/.cortex-debug.peripherals.state.json .vscode/.cortex-debug.registers.state.json -*.jdebug* +*.jdebug.user settings.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index b7cdb08..440a688 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,4 +1,5 @@ { + // 启动调试的快捷键是F5 "version": "0.2.0", "configurations": [ // 使用dap-link(如无线调试器时的参考配置) diff --git a/README.md b/README.md index 9204efe..a24fa4a 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,14 @@ > **代码参考了哈工深南宫小樱战队的框架设计,在此鸣谢。** -当前版本更新日期:2023.01.11 +当前版本更新日期:2023.02.15 **==由于当前仍然处在测试开发阶段,请定期拉取(`git pull`)获取最新更新。==** + + +[TOC] + ## 基本信息和开发规范 - **开发方式**: @@ -112,7 +116,7 @@ **编写和使用指南** -- 补充与修改:某款主控对应的BSP层应保持相同,当认为该层可能缺少部分功能或有错误时,请联系组长确认后解决并更新整个框架,**请勿自行修改提交**。 +- 补充与修改:某款主控对应的BSP层应保持相同,当认为该层可能缺少部分功能或有错误时,请联系组长确认后解决并更新整个框架,**请勿自行修改提交**。 请在你修改/增加的bsp_XXX.md中提供测试用例和使用示范以及任何其他需要注意的事项,并在代码必要的地方添加注释。 - 代码移植:BSP层也是在不同系列、型号的stm32间执行代码移植时主要需要关注的代码层。向功能更强系列移植一般只需要重配cube并重新组织BSP层的映射关系,而向功能较少的系列移植还需要去掉其不支持的功能。如果仅是对同一型号的开发板进行HAL初始化配置的修改,则BSP层**不需要**变动。 - 子文件与文件夹: - bsp.c/h:该层用于bsp基础功能初始化的文件,其中.h被include至main.c中,以实现整个代码层的初始化。include了该层所有模块的.h并调用各模块的初始化函数。**注意**,有些外设如串口和CAN不需要在bsp.c中进行模块层的初始化,他们会在module层生成实例(即C语言中的结构体)并注册到bsp层时自动进行初始化。以此达到提高运行速度避免未使用的模块被加载的问题。 @@ -154,11 +158,14 @@ Module层主要存放的是类型定义和实例指针数组,在该层没有进行实例化(定义或通过malloc分配空间),若在APP层没有实例化,则该模块的存在与否基本不会影响编译后的可执行文件,只会占用初始化和代码区所需的少量内存。module只会保存每个实例对象的指针,在没有初始化的时候仅仅占用一个指针数组的空间。因此,基于本框架的其他工程没有必要删除APP层未使用的module文件。 +务必为模块添加说明文档和使用范例,以及其他需要注意的事项(如果有)。 + > **待优化:** > > 由于C语言没有对象的概念,对于需要使用通信的module,在其.c文件下都需要保存每个实例的指针,在收到消息时遍历所有实例指针,找到收到消息的实例。这种处理方式可能会导致实时性下降,CAN接收时要遍历所有注册了CAN的实例,进入module层还需要一次遍历。用C++则可以将对象的this指针和模块的回调函数进行绑定,生成一个可调用对象然后再进行CAN的注册,使得其不需要module层的遍历。 > > 后续考虑在CAN instance中加入一个额外的`void*`域成员(成员变量),其内容为module层实例的地址。这样CAN收到消息时只需要遍历所有CAN instance,对于相同的模块,可以在其回调函数内部获取CAN instance的`void*`指针并通过强制类型转换cast成模块的实例结构体指针类型,从而访问特定的模块。 +> 这实际上是保存“对象”的parent pointer,使得实例可以访问拥有自己的实例(访问自己的父亲)。和回调函数配合,就可以防止交叉包含并为底层访问上层内容提供支持。 ## APP层(application) @@ -181,213 +188,31 @@ ROOT:. │ .gitignore # git版本管理忽略文件 │ .mxproject # CubeMX项目文件 │ basic_framework.ioc # CubeMX初始化配置文件 +| debug_ozone.jdebug # ozone debug调试配置和缓存文件 │ LICENSE # 开源协议文件 │ Makefile # 编译管理文件,为make(mingw32-make)命令的目标 │ openocd_dap.cfg # 用于OpenOCD调试使用的配置文件,dap用 │ openocd_jlink.cfg # 用于OpenOCD调试使用的配置文件,jlink用 │ README.md # 本说明文档 │ startup_stm32f407xx.s # F407汇编启动文件 -│ stm32.jflash # 烧录的配置文件,一键下载用 +│ stm32.jflash # jlink的烧录的配置文件,一键下载用 │ STM32F407.svd # F407外设地址映射文件,用于调试 -│ STM32F407IGHx_FLASH.ld # 包含了F407IGH(C板使用的MCU)的文件目标FLASH地址,用于编译(作为链接阶段的链接器),烧录和调试 +│ STM32F407IGHx_FLASH.ld # F407IGH(C板MCU)目标FLASH地址和链接规则,用于编译(作为链接阶段的链接器) +| task.ps1 # powershell脚本,一键编译并进入ozone调试/reset开发板用 │ TODO.md # 项目待完成的任务 │ VSCode+Ozone使用方法.md # 开发环境配置和前置知识介绍 │ 修改HAL配置时文件目录的更改.md # 重新配置CubeMX时的步骤和注意事项 -│ +│ 必须做&禁止做.md # 开发必看,规范和要求 +| ├─.vscode │ launch.json # 调试的配置文件 │ settings.json # 工作区配置文件,根据自己的需要配置 │ tasks.json # 任务配置文件,包括一键编译下载调试等 │ -├─application -│ │ application.md -│ │ APP层应用编写指引.md -│ │ robot.c -│ │ robot.h -│ │ robot_def.h -│ │ -│ ├─chassis -│ │ chassis.c -│ │ chassis.h -│ │ chassis.md -│ │ -│ ├─cmd -│ │ robot_cmd.c -│ │ robot_cmd.h -│ │ robot_cmd.md -│ │ -│ ├─gimbal -│ │ gimbal.c -│ │ gimbal.h -│ │ gimbal.md -│ │ -│ └─shoot -│ shoot.c -│ shoot.h -│ shoot.md -│ ├─assets # 说明文档的图片 -│ -├─bsp -│ │ bsp.md -│ │ bsp_buzzer.c -│ │ bsp_buzzer.h -│ │ bsp_init.c -│ │ bsp_init.h -│ │ bsp_led.c -│ │ bsp_led.h -│ │ bsp_spi.md -│ │ bsp_temperature.c -│ │ bsp_temperature.h -│ │ -│ ├─adc -│ │ bsp_adc.c -│ │ bsp_adc.h -│ │ bsp_adc.md -│ │ -│ ├─can -│ │ bsp_can.c -│ │ bsp_can.h -│ │ bsp_can.md -│ │ -│ ├─dwt -│ │ bsp_dwt.c -│ │ bsp_dwt.h -│ │ bsp_dwt.md -│ │ -│ ├─gpio -│ │ bsp_gpio.c -│ │ bsp_gpio.h -│ │ bsp_gpio.md -│ │ -│ ├─iic -│ │ bsp_iic.c -│ │ bsp_iic.h -│ │ bsp_iic.md -│ │ -│ ├─log -│ │ bsp_log.c -│ │ bsp_log.h -│ │ bsp_log.md -│ │ -│ ├─pwm -│ │ bsp_pwm.c -│ │ bsp_pwm.h -│ │ bsp_pwm.md -│ │ -│ ├─spi -│ │ bsp_spi.c -│ │ bsp_spi.h -│ │ -│ ├─usart -│ │ bsp_usart.c -│ │ bsp_usart.h -│ │ bsp_usart.md -│ │ -│ └─usb -└─modules - │ general_def.h - │ module.md - │ - ├─algorithm - │ algorithm.md - │ controller.c - │ controller.h - │ crc16.c - │ crc16.h - │ crc8.c - │ crc8.h - │ kalman_filter.c - │ kalman_filter.h - │ LQR.c - │ LQR.h - │ QuaternionEKF.c - │ QuaternionEKF.h - │ user_lib.c - │ user_lib.h - │ - ├─BMI088 - │ bmi088.c - │ bmi088.h - │ bmi088_regNdef.h - │ - ├─can_comm - │ can_comm.c - │ can_comm.h - │ can_comm.md - │ - ├─daemon - │ daemon.c - │ daemon.h - │ daemon.md - │ - ├─imu - │ BMI088driver.c - │ BMI088driver.h - │ BMI088Middleware.c - │ BMI088Middleware.h - │ BMI088reg.h - │ ins_task.c - │ ins_task.h - │ ins_task.md - │ - ├─led_light - │ led.md - │ led_task.c - │ led_task.h - │ - ├─master_machine - │ master_process.c - │ master_process.h - │ master_process.md - │ seasky_protocol.c - │ seasky_protocol.h - │ 湖南大学RoboMaster电控组通信协议.md - │ - ├─message_center - │ message_center.c - │ message_center.h - │ message_center.md - │ - ├─motor - │ dji_motor.c - │ dji_motor.h - │ dji_motor.md - │ HT04.c - │ HT04.h - │ LK9025.c - │ LK9025.h - │ motor_def.h - │ motor_task.c - │ motor_task.h - │ servo_motor.c - │ servo_motor.h - │ servo_motor.md - │ step_motor.c - │ step_motor.h - │ - ├─referee - │ crc.c - │ crc.h - │ referee.c - │ referee.h - │ referee.md - │ referee_communication.c - │ referee_UI.c - │ - ├─remote - │ remote.md - │ remote_control.c - │ remote_control.h - │ - ├─super_cap - │ super_cap.c - │ super_cap.h - │ super_cap.md - │ - └─vofa - vofa.c - vofa.h +├─application # 应用层 +├─bsp # 板级支持包 +└─modules # 模块层 ``` ## BSP/Module/Application介绍 @@ -416,3 +241,15 @@ HAL库初始化 --> BSP初始化 --> Application初始化 --> app调用其拥有 APP会调用其所有的模块的初始化函数(注册函数),这是因为本框架的设计思想是任何模块在被注册(构造/初始化)之前,都是不存在的,当且仅当定义了一个模块结构体(也称实例)的时候,才有一个实体的概念。 main函数唯一需要的函数是app层的`robot.c`中的`RobotInit()`函数,它首先会调用BSP初始化,然后进行所有应用的初始化;每个应用会调用对应模块的初始化;一些依赖通信外设的模块会将通信支持相关的bsp进行初始化。初始化结束之后实时系统启动。 + + + +### 程序运行流程 + +![运行](assets\总程序流程.png) + + + +### 程序数据流 + +![数据流](assets\数据流.png) \ No newline at end of file diff --git a/TODO.md b/TODO.md index 33e5fe7..fbbf138 100644 --- a/TODO.md +++ b/TODO.md @@ -6,6 +6,10 @@ **==标为黄色高亮的代表紧急程度高。==** +## assorted + +- [ ] 由于我们读写和传递的数据结构都不大,基本不会发生读写时任务切换的情况。典型的数据读写时间都是~μs,故没有对数据访问的接口添加互斥锁或关闭全局中断。后续有需求(如大量数据复制)可以添加。可以新增一个bsp_mutex或者module层的ds,提供相应支持。实际上freertos提供了一些供线程(任务)间进行数据交互的类型和函数,请查阅对应文档。 + ## BSP ### 待完成 @@ -44,6 +48,9 @@ - [ ] 增加无线网络功能,方便调试和测试 +#### bsp_log + +- [ ] 在vscode中添加rtt viewer的查看窗口,提供一键启用的task.json diff --git a/application/chassis/chassis.md b/application/chassis/chassis.md index e5256f2..6f04688 100644 --- a/application/chassis/chassis.md +++ b/application/chassis/chassis.md @@ -16,4 +16,9 @@ 6. 获取裁判系统的数据,并根据底盘功率限制对输出进行限幅 7. 由电机的反馈数据和IMU(如果有),计算底盘当前的真实运动速度 8. 设置底盘反馈数据,包括运动速度和裁判系统数据 -9. 将反馈数据推送到消息中心(如果双板则通过CANComm发送) \ No newline at end of file +9. 将反馈数据推送到消息中心(如果双板则通过CANComm发送) + + +### 后续支持平衡底盘 + +新增一个app balance_chassis \ No newline at end of file diff --git a/application/cmd/robot_cmd.h b/application/cmd/robot_cmd.h index 7e787e8..ba9f2e4 100644 --- a/application/cmd/robot_cmd.h +++ b/application/cmd/robot_cmd.h @@ -1,6 +1,7 @@ #ifndef GIMBAL_CMD_H #define GIMBAL_CMD_H + /** * @brief 机器人核心控制任务初始化,会被RobotInit()调用 * diff --git a/application/grab/grab.md b/application/grab/grab.md new file mode 100644 index 0000000..b09acba --- /dev/null +++ b/application/grab/grab.md @@ -0,0 +1 @@ +工程机器人夹爪 \ No newline at end of file diff --git a/application/lift/lift.md b/application/lift/lift.md new file mode 100644 index 0000000..60a2ab0 --- /dev/null +++ b/application/lift/lift.md @@ -0,0 +1 @@ +抬升/横移机构 \ No newline at end of file diff --git a/application/manipulator/manipulator.md b/application/manipulator/manipulator.md new file mode 100644 index 0000000..6ab8126 --- /dev/null +++ b/application/manipulator/manipulator.md @@ -0,0 +1 @@ +机械臂(不包含末端执行机构) \ No newline at end of file diff --git a/application/robot.c b/application/robot.c index 74151ff..72b014c 100644 --- a/application/robot.c +++ b/application/robot.c @@ -2,6 +2,12 @@ #include "robot.h" #include "robot_def.h" +// 编译warning,提醒开发者修改机器人参数 +#ifndef ROBOT_DEF_PARAM_WARNING +#define ROBOT_DEF_PARAM_WARNING +#warning check if you have configured the parameters in robot_def.h, IF NOT, please refer to the comments AND DO IT, otherwise the robot will have FATAL ERRORS!!! +#endif // !ROBOT_DEF_PARAM_WARNING + #if defined(ONE_BOARD) || defined(CHASSIS_BOARD) #include "chassis.h" #endif diff --git a/application/robot_def.h b/application/robot_def.h index 9c6ab16..56bbe00 100644 --- a/application/robot_def.h +++ b/application/robot_def.h @@ -16,11 +16,6 @@ #include "master_process.h" #include "stdint.h" -// 编译warning,提醒开发者修改机器人参数 -#ifndef ROBOT_DEF_PARAM_WARNING -#define ROBOT_DEF_PARAM_WARNING -#warning BE SURED THAT YOU HAVE ALREADY MODIFIED THESE PARAMETER TO FIT THE ROBOT -#endif // !ROBOT_DEF_PARAM_WARNING /* 开发板类型定义,烧录时注意不要弄错对应功能;修改定义后需要重新编译,只能存在一个定义! */ #define ONE_BOARD // 单板控制整车 diff --git a/assets/总程序流程.png b/assets/总程序流程.png new file mode 100644 index 0000000..fc9128a Binary files /dev/null and b/assets/总程序流程.png differ diff --git a/assets/数据流.png b/assets/数据流.png new file mode 100644 index 0000000..f270f67 Binary files /dev/null and b/assets/数据流.png differ diff --git a/bsp/bsp_legacy_support/bsp_buzzer.c b/bsp/bsp_legacy_support/bsp_buzzer.c index cdf2534..625d53f 100644 --- a/bsp/bsp_legacy_support/bsp_buzzer.c +++ b/bsp/bsp_legacy_support/bsp_buzzer.c @@ -1,6 +1,8 @@ #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; diff --git a/bsp/bsp_legacy_support/bsp_led.c b/bsp/bsp_legacy_support/bsp_led.c index af3f402..66628d0 100644 --- a/bsp/bsp_legacy_support/bsp_led.c +++ b/bsp/bsp_legacy_support/bsp_led.c @@ -1,6 +1,8 @@ #include "bsp_led.h" #include "main.h" +#warning this is a legacy support file, please use the new version + extern TIM_HandleTypeDef htim5; static uint8_t tmp_output_level = 0; diff --git a/bsp/bsp_legacy_support/bsp_temperature.c b/bsp/bsp_legacy_support/bsp_temperature.c index 7dcbb3a..45f0fd0 100644 --- a/bsp/bsp_legacy_support/bsp_temperature.c +++ b/bsp/bsp_legacy_support/bsp_temperature.c @@ -1,5 +1,7 @@ #include "bsp_temperature.h" +#warning this is a legacy support file, please use the new version + extern TIM_HandleTypeDef htim10; void IMUTempInit() diff --git a/bsp/iic/bsp_iic.md b/bsp/iic/bsp_iic.md index e7e5be1..2cff522 100644 --- a/bsp/iic/bsp_iic.md +++ b/bsp/iic/bsp_iic.md @@ -7,4 +7,6 @@ https://blog.csdn.net/NeoZng/article/details/128496694 https://blog.csdn.net/NeoZng/article/details/128486366 -使用序列通信则在单次通信后不会释放总线,继续占用直到调用传输函数时传入`IIC_RELEASE`参数. 这个功能只在一条总线上挂载多个主机的时候有用. \ No newline at end of file +使用序列通信则在单次通信后不会释放总线,继续占用直到调用传输函数时传入`IIC_RELEASE`参数. 这个功能只在一条总线上挂载多个主机的时候有用. + +cubemx未配置dma时请勿使用dma传输,其行为是未定义的。 \ No newline at end of file diff --git a/bsp/spi/bsp_spi.md b/bsp/spi/bsp_spi.md index e69de29..2724b9e 100644 --- a/bsp/spi/bsp_spi.md +++ b/bsp/spi/bsp_spi.md @@ -0,0 +1,3 @@ +注意,如果你没有在CubeMX中为spi分配dma通道,请不要使用dma模式 + +(后续添加安全检查,通过判断hspi的dma handler是否为空来选择模式,如果为空,则自动将DMA转为IT模式以继续传输,并通过log warning 提醒用户) \ No newline at end of file diff --git a/debug_ozone.jdebug b/debug_ozone.jdebug new file mode 100644 index 0000000..f89d1d4 --- /dev/null +++ b/debug_ozone.jdebug @@ -0,0 +1,338 @@ +/********************************************************************* +* (c) SEGGER Microcontroller GmbH * +* The Embedded Experts * +* www.segger.com * +********************************************************************** + +File : D:/Desktop/basic_framework/debug_ozone.jdebug +Created : 9 Dec 2022 17:21 +Ozone Version : V3.24 +*/ + +/********************************************************************* +* +* OnProjectLoad +* +* Function description +* Project load routine. Required. +* +********************************************************************** +*/ +void OnProjectLoad (void) { + // + // Dialog-generated settings + // + Project.SetDevice ("STM32F407IG"); + Project.SetHostIF ("USB", "805251123"); + Project.SetTargetIF ("SWD"); + Project.SetTIFSpeed ("4 MHz"); + Project.AddPathSubstitute ("D:/Desktop/basic_framework", "$(ProjectDir)"); + Project.AddPathSubstitute ("d:/desktop/basic_framework", "$(ProjectDir)"); + Project.AddSvdFile ("$(InstallDir)/Config/CPU/Cortex-M4F.svd"); + Project.AddSvdFile ("$(InstallDir)/Config/Peripherals/STM32F407IG.svd"); + // + // User settings + // + Edit.SysVar (VAR_HSS_SPEED, FREQ_100_HZ); + File.Open ("$(ProjectDir)/build/basic_framework.elf"); +} + +/********************************************************************* +* +* OnStartupComplete +* +* Function description +* Called when program execution has reached/passed +* the startup completion point. Optional. +* +********************************************************************** +*/ +//void OnStartupComplete (void) { +//} + +/********************************************************************* +* +* TargetReset +* +* Function description +* Replaces the default target device reset routine. Optional. +* +* Notes +* This example demonstrates the usage when +* debugging an application in RAM on a Cortex-M target device. +* +********************************************************************** +*/ +//void TargetReset (void) { +// +// unsigned int SP; +// unsigned int PC; +// unsigned int VectorTableAddr; +// +// VectorTableAddr = Elf.GetBaseAddr(); +// // +// // Set up initial stack pointer +// // +// if (VectorTableAddr != 0xFFFFFFFF) { +// SP = Target.ReadU32(VectorTableAddr); +// Target.SetReg("SP", SP); +// } +// // +// // Set up entry point PC +// // +// PC = Elf.GetEntryPointPC(); +// +// if (PC != 0xFFFFFFFF) { +// Target.SetReg("PC", PC); +// } else if (VectorTableAddr != 0xFFFFFFFF) { +// PC = Target.ReadU32(VectorTableAddr + 4); +// Target.SetReg("PC", PC); +// } else { +// Util.Error("Project file error: failed to set entry point PC", 1); +// } +//} + +/********************************************************************* +* +* BeforeTargetReset +* +* Function description +* Event handler routine. Optional. +* +********************************************************************** +*/ +//void BeforeTargetReset (void) { +//} + +/********************************************************************* +* +* AfterTargetReset +* +* Function description +* Event handler routine. Optional. +* The default implementation initializes SP and PC to reset values. +** +********************************************************************** +*/ +void AfterTargetReset (void) { + _SetupTarget(); +} + +/********************************************************************* +* +* DebugStart +* +* Function description +* Replaces the default debug session startup routine. Optional. +* +********************************************************************** +*/ +//void DebugStart (void) { +//} + +/********************************************************************* +* +* TargetConnect +* +* Function description +* Replaces the default target IF connection routine. Optional. +* +********************************************************************** +*/ +//void TargetConnect (void) { +//} + +/********************************************************************* +* +* BeforeTargetConnect +* +* Function description +* Event handler routine. Optional. +* +********************************************************************** +*/ +//void BeforeTargetConnect (void) { +//} + +/********************************************************************* +* +* AfterTargetConnect +* +* Function description +* Event handler routine. Optional. +* +********************************************************************** +*/ +//void AfterTargetConnect (void) { +//} + +/********************************************************************* +* +* TargetDownload +* +* Function description +* Replaces the default program download routine. Optional. +* +********************************************************************** +*/ +//void TargetDownload (void) { +//} + +/********************************************************************* +* +* BeforeTargetDownload +* +* Function description +* Event handler routine. Optional. +* +********************************************************************** +*/ +//void BeforeTargetDownload (void) { +//} + +/********************************************************************* +* +* AfterTargetDownload +* +* Function description +* Event handler routine. Optional. +* The default implementation initializes SP and PC to reset values. +* +********************************************************************** +*/ +void AfterTargetDownload (void) { + _SetupTarget(); +} + +/********************************************************************* +* +* BeforeTargetDisconnect +* +* Function description +* Event handler routine. Optional. +* +********************************************************************** +*/ +//void BeforeTargetDisconnect (void) { +//} + +/********************************************************************* +* +* AfterTargetDisconnect +* +* Function description +* Event handler routine. Optional. +* +********************************************************************** +*/ +//void AfterTargetDisconnect (void) { +//} + +/********************************************************************* +* +* AfterTargetHalt +* +* Function description +* Event handler routine. Optional. +* +********************************************************************** +*/ +//void AfterTargetHalt (void) { +//} + +/********************************************************************* +* +* BeforeTargetResume +* +* Function description +* Event handler routine. Optional. +* +********************************************************************** +*/ +//void BeforeTargetResume (void) { +//} + +/********************************************************************* +* +* OnSnapshotLoad +* +* Function description +* Called upon loading a snapshot. Optional. +* +* Additional information +* This function is used to restore the target state in cases +* where values cannot simply be written to the target. +* Typical use: GPIO clock needs to be enabled, before +* GPIO is configured. +* +********************************************************************** +*/ +//void OnSnapshotLoad (void) { +//} + +/********************************************************************* +* +* OnSnapshotSave +* +* Function description +* Called upon saving a snapshot. Optional. +* +* Additional information +* This function is usually used to save values of the target +* state which can either not be trivially read, +* or need to be restored in a specific way or order. +* Typically use: Memory Mapped Registers, +* such as PLL and GPIO configuration. +* +********************************************************************** +*/ +//void OnSnapshotSave (void) { +//} + +/********************************************************************* +* +* OnError +* +* Function description +* Called when an error ocurred. Optional. +* +********************************************************************** +*/ +//void OnError (void) { +//} + +/********************************************************************* +* +* _SetupTarget +* +* Function description +* Setup the target. +* Called by AfterTargetReset() and AfterTargetDownload(). +* +* Auto-generated function. May be overridden by Ozone. +* +********************************************************************** +*/ +void _SetupTarget(void) { + unsigned int SP; + unsigned int PC; + unsigned int VectorTableAddr; + + VectorTableAddr = Elf.GetBaseAddr(); + // + // Set up initial stack pointer + // + SP = Target.ReadU32(VectorTableAddr); + if (SP != 0xFFFFFFFF) { + Target.SetReg("SP", SP); + } + // + // Set up entry point PC + // + PC = Elf.GetEntryPointPC(); + if (PC != 0xFFFFFFFF) { + Target.SetReg("PC", PC); + } else { + Util.Error("Project script error: failed to set up entry point PC", 1); + } +} \ No newline at end of file diff --git a/modules/BMI088/bmi088.md b/modules/BMI088/bmi088.md index 2adb716..d2925f8 100644 --- a/modules/BMI088/bmi088.md +++ b/modules/BMI088/bmi088.md @@ -1,5 +1,68 @@ # BMI088 +**注意,此模块待测试** + + +## 示例 + +```c +BMI088_Init_Config_s imu_config = { + .spi_acc_config={ + .GPIO_cs=GPIOC, + .GPIO_cs=GPIO_PIN_4, + .spi_handle=&hspi1, + }, + .spi_gyro_config={ + .GPIO_cs=GPIOC, + .GPIO_cs=GPIO_PIN_4, + .spi_handle=&hspi1, + }, + .acc_int_config={ + .exti_mode=EXTI_TRIGGER_FALLING, + .GPIO_Pin=GPIO_PIN_10, + .GPIOx=GPIOA, + }, + .gyro_int_config={ + .exti_mode=EXTI_TRIGGER_FALLING, + .GPIO_Pin=GPIO_PIN_11, + .GPIOx=GPIOA, + }, + .heat_pid_config={ + .Kp=0.0f, + .Kd=0.0f, + .Ki=0.0f, + .MaxOut=0.0f, + .DeadBand=0.0f, + }, + .heat_pwm_config={ + .channel=TIM_CHANNEL_1, + .htim=&htim1, + }, + .cali_mode=BMI088_CALIBRATE_ONLINE_MODE, + .work_mode=BMI088_BLOCK_PERIODIC_MODE, + }; + +BMI088Instance* imu=BMI088Register(&imu_config); +``` + +## IT非阻塞模式下BMI088读取流程 + +数据准备完成标志位:`uint8_t BMI088_READY_FLAG` 总共8个位 也可以用位域可读性更高 + +1. 当accel int中断发生,开启DMA SPI传输,完成后将acc ready置位 +2. 当gyro int中断发生,开启DMA SPI传输,完成后将gyro ready置位 +3. 当温度数据中断(温度传感器在accel内部,也是accel int)发生,开启DMA传输,完成后将温度标志位置位 + +> 由于DMA传输非阻塞,启动传输后只有到传输完成时才会拉高片选结束SPI transfer,因此需要在callback中加入标志位置位的操作. +这可以通过条件编译完成. + +温度数据不需要和accel和gyro同步,它不参与姿态解算,可以不用管. + +当加速度数据和陀螺仪数据都准备完成之后,唤醒姿态解算任务INs_taSk,进行一次解算.唤醒可以通过软件开启EXTI中断,在中断中调用实时系统的vTaskNotifyFromISR()完成,也可以将任务ready标志位置位,当运行到对应位置时检查标志位判断是否要进行任务.时间间隔不是大问题,inS_TAsK中有dwt用于计算两次任务执行的间隔,它将会自动处理好bias的大小 + +`__HAL_GPIO_EXTI_GENERATE_SWIT()` `HAL_EXTI_GENERATE_SWI()` 可以触发软件中断 + +of course,两者的数据更新实际上可以异步进行,这里为了方便起见当两者数据都准备好以后再行融合 ## 数据读写规则(so called 16-bit protocol) 加速度计读取read: @@ -33,21 +96,3 @@ write写入: 2. 写入的数据 -## IT非阻塞模式下BMI088读取流程 - -数据准备完成标志位:`uint8_t BMI088_READY_FLAG` 总共8个位 也可以用位域可读性更高 - -1. 当accel int中断发生,开启DMA SPI传输,完成后将acc ready置位 -2. 当gyro int中断发生,开启DMA SPI传输,完成后将gyro ready置位 -3. 当温度数据中断(温度传感器在accel内部,也是accel int)发生,开启DMA传输,完成后将温度标志位置位 - -> 由于DMA传输非阻塞,启动传输后只有到传输完成时才会拉高片选结束SPI transfer,因此需要在callback中加入标志位置位的操作. -这可以通过条件编译完成. - -温度数据不需要和accel和gyro同步,它不参与姿态解算,可以不用管. - -当加速度数据和陀螺仪数据都准备完成之后,唤醒姿态解算任务INs_taSk,进行一次解算.唤醒可以通过软件开启EXTI中断,在中断中调用实时系统的vTaskNotifyFromISR()完成,也可以将任务ready标志位置位,当运行到对应位置时检查标志位判断是否要进行任务.时间间隔不是大问题,inS_TAsK中有dwt用于计算两次任务执行的间隔,它将会自动处理好bias的大小 - -`__HAL_GPIO_EXTI_GENERATE_SWIT()` `HAL_EXTI_GENERATE_SWI()` 可以触发软件中断 - -of course,两者的数据更新实际上可以异步进行,这里为了方便起见当两者数据都准备好以后再行融合 diff --git a/modules/daemon/daemon.md b/modules/daemon/daemon.md index 71be55f..103f77d 100644 --- a/modules/daemon/daemon.md +++ b/modules/daemon/daemon.md @@ -19,7 +19,7 @@ typedef struct } Daemon_Init_Config_s; ``` -`reload_count`是”喂狗“时的重载值,一般根据你希望的离线容许时间和模块接收数据/访问数据的频率确定。 +`reload_count`是”喂狗“时的重载值,一般根据你希望的离线容许时间和模块接收数据/访问数据的频率确定。daemonTask递减计数器的频率是100hz(在HAL_N_Middlewares/Src/freertos.c中查看任务),你可以据此以及模块收到数据/操作的频率设置reload_count。 `daemon_task()`会在实时系统中以1kHz的频率运行,每次运行该任务,都会将所有daemon实例当前的count进行自减操作,当count减为零,则说明模块已经很久没有上线(处于deactivated状态,即没有收到数据,也没有进行其他读写操作)。 diff --git a/modules/imu/BMI088driver.c b/modules/imu/BMI088driver.c index 5f7fe08..c4d148e 100644 --- a/modules/imu/BMI088driver.c +++ b/modules/imu/BMI088driver.c @@ -4,6 +4,8 @@ #include "bsp_dwt.h" #include +#warning this is a legacy support. test the new BMI088 module as soon as possible. + float BMI088_ACCEL_SEN = BMI088_ACCEL_6G_SEN; float BMI088_GYRO_SEN = BMI088_GYRO_2000_SEN; diff --git a/modules/imu/ins_task.md b/modules/imu/ins_task.md index 7fd972a..4c4da81 100644 --- a/modules/imu/ins_task.md +++ b/modules/imu/ins_task.md @@ -6,6 +6,7 @@ ![image-20221113212706633](assets\image-20221113212706633.png) +`times%10` 是固定相机的采集频率为100hz,请根据视觉算法实际能达到的最大帧率调整。 ## 算法解析 介绍EKF四元数姿态解算的教程在:[四元数EKF姿态更新算法](https://zhuanlan.zhihu.com/p/454155643) diff --git a/modules/ist8310/ist8310.md b/modules/ist8310/ist8310.md index b90ad21..c9bc15c 100644 --- a/modules/ist8310/ist8310.md +++ b/modules/ist8310/ist8310.md @@ -1,5 +1,5 @@ -使用示例 +## 使用示例 ```c IST8310_Init_Config_s ist8310_conf = { diff --git a/modules/led_task/led_task.c b/modules/led_task/led_task.c index a4305c7..02cffe8 100644 --- a/modules/led_task/led_task.c +++ b/modules/led_task/led_task.c @@ -10,10 +10,10 @@ * */ +#warning this is a legacy support file, please build the new 'led' module as soon as possible + #include "led_task.h" - #include - #include "bsp_led.h" #include "main.h" diff --git a/task.ps1 b/task.ps1 index 13eee81..d5f0b9e 100644 --- a/task.ps1 +++ b/task.ps1 @@ -1,4 +1,5 @@ # 推荐安装powershell7 以获得更好的shell体验! +# 可以添加task.json,或在makefile中增加伪构建目标然后运行make xxx JLinkGDBServer: