重构bsp层,bsp层将和HAL的配置一致,修改CubeMX之后不需要修改bsp。重构bmi088。

This commit is contained in:
NeoZng
2022-12-30 23:39:04 +08:00
parent ab1a9726b1
commit a3631a5ca5
39 changed files with 842 additions and 256 deletions

34
bsp/log/bsp_log.c Normal file
View File

@@ -0,0 +1,34 @@
#include "bsp_log.h"
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
#include <stdio.h>
#define BUFFER_INDEX 0
void BSPLogInit()
{
SEGGER_RTT_Init();
}
int PrintLog(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
int n = SEGGER_RTT_vprintf(BUFFER_INDEX, fmt, &args);
va_end(args);
return n;
}
void Float2Str(char *str, float va)
{
int flag = va < 0;
int head = (int)va;
int point = (int)((va - head) * 1000);
head = abs(head);
point = abs(point);
if (flag)
sprintf(str, "-%d.%d", head, point);
else
sprintf(str, "%d.%d", head, point);
}

10
bsp/log/bsp_log.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef _BSP_LOG_H
#define _BSP_LOG_H
void BSPLogInit();
int PrintLog(const char *fmt, ...);
void Float2Str(char *str, float va);
#endif

35
bsp/log/bsp_log.md Normal file
View File

@@ -0,0 +1,35 @@
# bsp_log
<p align='right'>neozng1@hnu.edu.cn</p>
> TODO:
>
> 1. 在未接入调试器的时候将日志写入flash中并提供接口读取
> 2. 增加日志分级提供info、warning、error三个等级的日志
## 使用说明
bsp_log是基于segger RTT实现的日志打印模块。
```c
int printf_log(const char *fmt, ...);
void Float2Str(char *str, float va);
```
调用第一个函数可以通过jlink或dap-link向调试器连接的上位机发送信息格式和printf相同示例如下
```c
printf_log("Hello World!\n");
printf_log("Motor %d met some problem, error code %d!\n",3,1);
```
第二个函数可以将浮点类型转换成字符串以方便发送:
```c
float current_feedback=114.514;
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()`发送日志,可以设置小数点位数以降低带宽开销。