第一版代码,为了在EEPROM保存参数的时候走STM32的CRC,让Codex修改了一下,现在的效果是无法存储,codex表示原因是CRC方法不同,修改到一半今天的额度使用完了,有待后续解决CRC的bug
This commit is contained in:
16
Common/Com_debug.c
Normal file
16
Common/Com_debug.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "Com_debug.h"
|
||||
|
||||
/**
|
||||
* @brief 日志输出初始化
|
||||
*
|
||||
*/
|
||||
void Com_debug_init(void)
|
||||
{
|
||||
// MX_USART1_UART_Init();
|
||||
}
|
||||
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
HAL_UART_Transmit(&huart5, (uint8_t *)&ch, 1, 0xFFFF);
|
||||
return ch;
|
||||
}
|
||||
31
Common/Com_debug.h
Normal file
31
Common/Com_debug.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef __COM_DEBUG__
|
||||
#define __COM_DEBUG__
|
||||
|
||||
#include "usart.h"
|
||||
#include "stdio.h"
|
||||
#include "stdarg.h"
|
||||
#include "string.h"
|
||||
#define DEBUG_ENABLE
|
||||
|
||||
#ifdef DEBUG_ENABLE
|
||||
|
||||
// 修改输出文件的全路径名称 => 只有文件名
|
||||
#define __FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
|
||||
#define __FILENAME__ (strrchr(__FILENAME, '\\') ? strrchr(__FILENAME, '\\') + 1 : __FILENAME)
|
||||
|
||||
// 调用宏定义打印的时候 => 需要打印出日志输出的文件和行号
|
||||
#define debug_printf(format, ...) printf("[%s:%d] " format "\r\n", __FILENAME__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
#define debug_printf(format, ...)
|
||||
|
||||
#endif // DEBUG_ENABLE
|
||||
|
||||
/**
|
||||
* @brief 日志输出初始化
|
||||
*
|
||||
*/
|
||||
void Com_debug_init(void);
|
||||
|
||||
#endif // __COM_DEBUG__
|
||||
83
Common/Com_type.h
Normal file
83
Common/Com_type.h
Normal file
@@ -0,0 +1,83 @@
|
||||
#ifndef __COM_TYPE_H__
|
||||
#define __COM_TYPE_H__
|
||||
|
||||
#include "stdint.h"
|
||||
#include "gpio.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32_t pulses; // 脉冲数
|
||||
uint8_t dir; // 方向
|
||||
uint16_t overflow; // 溢出次数
|
||||
uint16_t z; // Z相触发次数
|
||||
} Encoder_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// 电机运动状态 0:加速 1:匀速 2:减速 3:停止
|
||||
ACCELERATE = 0,
|
||||
CONSTANT,
|
||||
DECELERATE,
|
||||
STOP,
|
||||
|
||||
} Stepper_state_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GPIO_PinState dir; // 前进方向
|
||||
float distance; // 距离
|
||||
uint16_t speed; // 前进速度,单位mm/s
|
||||
uint8_t run_flag; // 运行标志
|
||||
|
||||
// 梯形算法参数(加减速对称)
|
||||
float start_speed; // 启动速度
|
||||
uint32_t current_step; // 当前步数
|
||||
uint16_t acc; // 加速度,单位mm/s^2
|
||||
uint16_t dec; // 减速度,单位mm/s^2
|
||||
uint32_t acc_step; // 加速步数
|
||||
uint32_t constant_step; // 匀速步数
|
||||
uint32_t total_step; // 总步数
|
||||
uint16_t interval; // 步间隔
|
||||
Stepper_state_t state; // 电机运动状态
|
||||
|
||||
uint32_t step_count; // 实时记录已走的步数 (用来和 acc_step 比较)
|
||||
float current_speed; // 当前实时速度 (浮点型,用于计算中间值)
|
||||
float speed_inc; // 每一步的速度增量 (用于中断里累加)
|
||||
|
||||
uint8_t step_loss_flag;
|
||||
uint8_t x_zero; // X轴零点标志
|
||||
} Stepper_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KEY_NONE,
|
||||
KEY_1,
|
||||
KEY_2,
|
||||
KEY_3,
|
||||
KEY_4,
|
||||
KEY_5
|
||||
} Key_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KEY_EVT_NONE = 0,
|
||||
KEY_EVT_CLICK,
|
||||
KEY_EVT_LONG_START,
|
||||
KEY_EVT_LONG_HOLD,
|
||||
KEY_EVT_RELEASE
|
||||
} KeyEvt_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Key_t key;
|
||||
KeyEvt_t evt;
|
||||
} KeyAction_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t acc_mm_s2;
|
||||
uint16_t dec_mm_s2;
|
||||
float step_loss_threshold_mm;
|
||||
} App_RunParams_t;
|
||||
|
||||
#endif /* __COM_TYPE_H__ */
|
||||
Reference in New Issue
Block a user