feat(device): 添加早期诊断功能并优化SPI通信实现
- 在startup_gd32e50x_cl.s中添加USART0早期诊断代码,在Reset_Handler中 发送'R'字符以确认启动过程 - 修改system_gd32e50x.c中的时钟初始化逻辑,支持动态检测当前时钟源 (PLL或IRC8M)并相应调整串口波特率设置 - 在系统时钟配置函数中添加HXTAL故障诊断输出,当外部晶振启动失败时 通过USART0输出"HXTAL FAIL"错误信息 - 在AppSpiCommand类中实现DMA传输机制,使用DMA0_CH2进行SPI0数据发送, 提升传输效率并与BOOT端保持一致 - 重构SPI命令处理逻辑,优化PING命令响应格式,包含APP和BOOT版本信息 以及运行时间统计 - 添加事务过滤机制,忽略全0xFF或全0x00的数据包以及短帧 - 更新配置文件定义APP固件版本号和OTA配置页面地址 - 修复region配置文件中的ROM大小数值精度问题 - 调整NVIC中断优先级设置,优化SPI中断处理
This commit is contained in:
@@ -162,7 +162,7 @@ static void _soft_delay_(uint32_t time)
|
||||
*/
|
||||
void SystemInit (void)
|
||||
{
|
||||
/* ===== DIAG: raw USART0 output at IRC8M (8MHz) ===== */
|
||||
/* ===== DIAG: raw USART0 output — detect current clock for baudrate ===== */
|
||||
/* Enable AFIO + GPIOA + USART0 clocks via raw register */
|
||||
*((volatile uint32_t *)0x40021018U) |= (1U << 14) | (1U << 2) | (1U << 0);
|
||||
/* PA9 = AF_PP, 50MHz (CTL=0b11, MD=0b11) -> CTL1 bit[4..7]=0b1011 */
|
||||
@@ -172,8 +172,18 @@ void SystemInit (void)
|
||||
ctl |= (0xBU << 4); /* AF_PP 50MHz */
|
||||
*((volatile uint32_t *)0x40010804U) = ctl;
|
||||
}
|
||||
/* USART0 baud: BAUD = 8000000/115200 = 69 */
|
||||
*((volatile uint32_t *)0x40013808U) = 69U;
|
||||
/* Detect current system clock: if PLL is selected, assume 180MHz; otherwise IRC8M=8MHz.
|
||||
* This handles both cold boot (IRC8M) and BOOT jump (PLL 180MHz). */
|
||||
{
|
||||
uint32_t scss = (*((volatile uint32_t *)0x40021000U) >> 2) & 0x3U; /* RCU_CFG0 SCSS bits */
|
||||
uint32_t baud_div;
|
||||
if (scss == 0x2U) { /* PLL selected as system clock -> 180MHz */
|
||||
baud_div = 180000000U / 115200U; /* = 1562 */
|
||||
} else { /* IRC8M or HXTAL -> 8MHz */
|
||||
baud_div = 8000000U / 115200U; /* = 69 */
|
||||
}
|
||||
*((volatile uint32_t *)0x40013808U) = baud_div;
|
||||
}
|
||||
/* USART0 CTL0: TE + EN = bit3 + bit13 */
|
||||
*((volatile uint32_t *)0x40013800U) = (1U << 3) | (1U << 13);
|
||||
/* Send "APP" via USART0 DATA register */
|
||||
@@ -647,8 +657,18 @@ static void system_clock_hxtal(void)
|
||||
|
||||
/* if fail */
|
||||
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
|
||||
while(1){
|
||||
}
|
||||
/* HXTAL failed: output diagnostic via USART0 at IRC8M */
|
||||
*((volatile uint32_t *)0x40021018U) |= (1U << 2) | (1U << 0);
|
||||
{ volatile uint32_t _ctl = *((volatile uint32_t *)0x40010804U);
|
||||
_ctl &= ~(0xFU << 4); _ctl |= (0xBU << 4);
|
||||
*((volatile uint32_t *)0x40010804U) = _ctl; }
|
||||
*((volatile uint32_t *)0x40013808U) = 69U; /* 8MHz/115200 */
|
||||
*((volatile uint32_t *)0x40013800U) = (1U << 3) | (1U << 13);
|
||||
{ const char *_msg = "HXTAL FAIL\r\n";
|
||||
for(int i=0; _msg[i]; i++){
|
||||
*((volatile uint32_t *)0x40013804U) = _msg[i];
|
||||
while((*((volatile uint32_t *)0x40013800U) & (1U << 7)) == 0U) {} } }
|
||||
while(1){ }
|
||||
}
|
||||
|
||||
/* AHB = SYSCLK */
|
||||
@@ -693,8 +713,18 @@ static void system_clock_72m_hxtal(void)
|
||||
|
||||
/* if fail */
|
||||
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
|
||||
while(1){
|
||||
}
|
||||
/* HXTAL failed: output diagnostic via USART0 at IRC8M */
|
||||
*((volatile uint32_t *)0x40021018U) |= (1U << 2) | (1U << 0);
|
||||
{ volatile uint32_t _ctl = *((volatile uint32_t *)0x40010804U);
|
||||
_ctl &= ~(0xFU << 4); _ctl |= (0xBU << 4);
|
||||
*((volatile uint32_t *)0x40010804U) = _ctl; }
|
||||
*((volatile uint32_t *)0x40013808U) = 69U; /* 8MHz/115200 */
|
||||
*((volatile uint32_t *)0x40013800U) = (1U << 3) | (1U << 13);
|
||||
{ const char *_msg = "HXTAL FAIL\r\n";
|
||||
for(int i=0; _msg[i]; i++){
|
||||
*((volatile uint32_t *)0x40013804U) = _msg[i];
|
||||
while((*((volatile uint32_t *)0x40013800U) & (1U << 7)) == 0U) {} } }
|
||||
while(1){ }
|
||||
}
|
||||
|
||||
FMC_WS = (FMC_WS & (~FMC_WS_WSCNT)) | WS_WSCNT(1);
|
||||
@@ -801,8 +831,18 @@ static void system_clock_120m_hxtal(void)
|
||||
|
||||
/* if fail */
|
||||
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
|
||||
while(1){
|
||||
}
|
||||
/* HXTAL failed: output diagnostic via USART0 at IRC8M */
|
||||
*((volatile uint32_t *)0x40021018U) |= (1U << 2) | (1U << 0);
|
||||
{ volatile uint32_t _ctl = *((volatile uint32_t *)0x40010804U);
|
||||
_ctl &= ~(0xFU << 4); _ctl |= (0xBU << 4);
|
||||
*((volatile uint32_t *)0x40010804U) = _ctl; }
|
||||
*((volatile uint32_t *)0x40013808U) = 69U; /* 8MHz/115200 */
|
||||
*((volatile uint32_t *)0x40013800U) = (1U << 3) | (1U << 13);
|
||||
{ const char *_msg = "HXTAL FAIL\r\n";
|
||||
for(int i=0; _msg[i]; i++){
|
||||
*((volatile uint32_t *)0x40013804U) = _msg[i];
|
||||
while((*((volatile uint32_t *)0x40013800U) & (1U << 7)) == 0U) {} } }
|
||||
while(1){ }
|
||||
}
|
||||
|
||||
FMC_WS = (FMC_WS & (~FMC_WS_WSCNT)) | WS_WSCNT(3);
|
||||
@@ -910,8 +950,18 @@ static void system_clock_168m_hxtal(void)
|
||||
|
||||
/* if fail */
|
||||
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
|
||||
while(1){
|
||||
}
|
||||
/* HXTAL failed: output diagnostic via USART0 at IRC8M */
|
||||
*((volatile uint32_t *)0x40021018U) |= (1U << 2) | (1U << 0);
|
||||
{ volatile uint32_t _ctl = *((volatile uint32_t *)0x40010804U);
|
||||
_ctl &= ~(0xFU << 4); _ctl |= (0xBU << 4);
|
||||
*((volatile uint32_t *)0x40010804U) = _ctl; }
|
||||
*((volatile uint32_t *)0x40013808U) = 69U; /* 8MHz/115200 */
|
||||
*((volatile uint32_t *)0x40013800U) = (1U << 3) | (1U << 13);
|
||||
{ const char *_msg = "HXTAL FAIL\r\n";
|
||||
for(int i=0; _msg[i]; i++){
|
||||
*((volatile uint32_t *)0x40013804U) = _msg[i];
|
||||
while((*((volatile uint32_t *)0x40013800U) & (1U << 7)) == 0U) {} } }
|
||||
while(1){ }
|
||||
}
|
||||
|
||||
FMC_WS = (FMC_WS & (~FMC_WS_WSCNT)) | WS_WSCNT(4);
|
||||
@@ -1019,8 +1069,18 @@ static void system_clock_180m_hxtal(void)
|
||||
|
||||
/* if fail */
|
||||
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
|
||||
while(1){
|
||||
}
|
||||
/* HXTAL failed: output diagnostic via USART0 at IRC8M */
|
||||
*((volatile uint32_t *)0x40021018U) |= (1U << 2) | (1U << 0);
|
||||
{ volatile uint32_t _ctl = *((volatile uint32_t *)0x40010804U);
|
||||
_ctl &= ~(0xFU << 4); _ctl |= (0xBU << 4);
|
||||
*((volatile uint32_t *)0x40010804U) = _ctl; }
|
||||
*((volatile uint32_t *)0x40013808U) = 69U; /* 8MHz/115200 */
|
||||
*((volatile uint32_t *)0x40013800U) = (1U << 3) | (1U << 13);
|
||||
{ const char *_msg = "HXTAL FAIL\r\n";
|
||||
for(int i=0; _msg[i]; i++){
|
||||
*((volatile uint32_t *)0x40013804U) = _msg[i];
|
||||
while((*((volatile uint32_t *)0x40013800U) & (1U << 7)) == 0U) {} } }
|
||||
while(1){ }
|
||||
}
|
||||
|
||||
FMC_WS = (FMC_WS & (~FMC_WS_WSCNT)) | WS_WSCNT(4);
|
||||
|
||||
Reference in New Issue
Block a user