Files
Motor_v2/Robot_V2/sys/initial.cpp
T
cbb 7354a71c51 feat(can): 增加CAN睡眠与唤醒功能并优化通信检查逻辑
- 在CAN通信类中添加了CAN_Sleep()和CAN_Wakeup()方法,支持设备进入低功耗模式
- 优化CAN通信检查逻辑,通过解析接收数据的首字节和末字节实现多种控制命令
- 支持远程复位电机、保存角度、清零角度、进入睡眠等操作
- 解决CAN发送邮箱满时可能导致的通信阻塞问题,增加重初始化机制
- 调整mailbox不可用计数逻辑,防止持续打印错误信息

refactor(flash): 移除软件CRC计算模块,改用硬件CRC外设
- 删除自定义CRC.cpp和CRC.h文件及其相关类实现
- 使用GD32硬件CRC模块替代软件算法,提高效率和可靠性
- 更新FlashEEPROM类中的CRC校验方式,调用crc_block_data_calculate进行计算
- 修正Flash地址遍历范围以适配新CRC逻辑及页面管理策略
- 修改save_angle接口签名,不再手动传入角度值,改为内部读取FOC实时角度

feat(timer): 新增RTC闹钟中断处理函数声明

- 在Timer.h中声明rtc_set_wakeup_interval和RTC_ALARM_IRQHandler
- 为后续实现基于RTC的定时唤醒功能做准备

chore(config): 同步csolution工具版本更新并调整组件配置

- 更新RTE_Components.h生成工具版本至2.12.0
- 启用BKP、CRC、RTC等标准外设组件宏定义
- 从项目配置文件中移除旧CRC源文件引用
- 添加SystemCoreClockUpdate调用确保系统时钟同步

refactor(main): 主循环任务调度重构并增强初始化流程

- 将主循环中的任务处理提取为独立do_task函数,提升代码可读性
- 提前执行电机初始化,并根据看门狗复位标志决定是否立即进入深度睡眠
- 调整EEPROM初始化顺序,保证依赖关系正确
- 添加sys/initial.h头文件包含以支持新增系统初始化逻辑
2025-12-20 19:53:52 +08:00

94 lines
2.4 KiB
C++

#include "initial.h"
#include "gd32c10x.h"
#include "gd32c10x_gpio.h"
#include "gd32c10x_rcu.h"
#include <cstdio>
#include <stdint.h>
#include <stdio.h>
/* retarget the C library printf function to the USART */
u8 USART0_init() {
gd_eval_com_init(EVAL_COM0);
return 1;
}
/*!
\brief configure the watchdog peripheral
\param[in] none
\param[out] none
\retval none
*/
u8 watchdog_init(u32 time) {
u8 status = 0;
/* configure FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */
/* time = reload_value / clock_frequency */
status = fwdgt_config(time * 0.625, FWDGT_PSC_DIV64);
fwdgt_enable();
return status;
}
int fputc(int ch, FILE *f) throw() {
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while (RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE))
;
return ch;
}
void unused_pin_init() {
rcu_periph_clock_enable(RCU_GPIOA); // 使能GPIOA时钟
rcu_periph_clock_enable(RCU_GPIOB); // 使能GPIOB时钟
rcu_periph_clock_enable(RCU_GPIOC); // 使能GPIOC时钟
gpio_init(GPIOA, GPIO_MODE_IPU, GPIO_OSPEED_2MHZ,
GPIO_PIN_8 | GPIO_PIN_11 | GPIO_PIN_12);
gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_2MHZ,
GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_15);
gpio_init(GPIOC, GPIO_MODE_IPU, GPIO_OSPEED_2MHZ,
GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15);
gpio_bit_reset(GPIOA, GPIO_PIN_8 | GPIO_PIN_11 | GPIO_PIN_12);
gpio_bit_reset(GPIOB, GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_15);
gpio_bit_reset(GPIOC, GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15);
}
/*!
\brief 检测并打印复位源信息
\param[in] none
\param[out] none
\retval none
*/
u16 get_reset_cause(void) {
u16 cause = 0;
if (RESET != rcu_flag_get(RCU_FLAG_FWDGTRST)) {
// printf("Free Watchdog Timer Reset\r\n");
cause = RCU_FLAG_FWDGTRST;
}
if (RESET != rcu_flag_get(RCU_FLAG_EPRST)) {
// printf("External Pin Reset\r\n");
cause = RCU_FLAG_EPRST;
}
if (RESET != rcu_flag_get(RCU_FLAG_PORRST)) {
// printf("Power Reset\r\n");
cause = RCU_FLAG_PORRST;
}
if (RESET != rcu_flag_get(RCU_FLAG_WWDGTRST)) {
// printf("Window Watchdog Timer Reset\r\n");
cause = RCU_FLAG_WWDGTRST;
}
if (RESET != rcu_flag_get(RCU_FLAG_LPRST)) {
// printf("Low Power Reset\r\n");
cause = RCU_FLAG_LPRST;
}
if (RESET != rcu_flag_get(RCU_FLAG_SWRST)) {
// printf("Software Reset\r\n");
cause = RCU_FLAG_SWRST;
}
// 清除所有复位标志
rcu_all_reset_flag_clear();
// printf("cause:%d\r\n", cause);
return cause;
}