Files
RCU_C1P_Launcher/User/main.c
caocong 5e9338cee4 新增:串口通讯避障功能
​ 1、Launcher中的串口只使用串口0(调试串口)、串口2(主动RS485端口);串口1与串口3不使用,且不初始化。将串口通讯缓冲区修改为1100Byte。

​  目的:CH564由于将Launcher代码搬运到RAM中运行,因此可使用的变量大小只有32Kbyte。不使用的串口将不初始化,同时使用的通讯缓冲区将节约出来,否则RAM空间不够使用。

​ 2、串口2 - 增加RS485使能,同时通讯增加避障功能。
2026-01-19 16:39:22 +08:00

207 lines
5.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/********************************** (C) COPYRIGHT *******************************
* File Name : main.c
* Author : WCH
* Version : V1.0.0
* Date : 2024/05/05
* Description : Main program body.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "includes.h"
#include <stdio.h>
#include <string.h>
const char Prject_File_Name[] __attribute__((section(".project_info"))) = Project_Version;
uint32_t test_tick = 0;
/*********************************************************************
* @fn main
*
* @brief Main program.
*
* @return none
*/
int main(void)
{
uint8_t sys_reset = 0;
unsigned char Buffer;
/* - 上电前需要关闭看门狗
* - 原因:如果开启看门狗后,软件进行复位还看门狗存在,会一直产生复位
* */
WDT_Reinit();
SystemCoreClockUpdate(); //系统初始化
Systick_Init();
UARTx_Init(UART_0,512000);
UARTx_Init(UART_2,512000);
SYS_LED_Init();
SPI_SRAM_Init();
SPI_FLASH_Init();
Get_Flash_Size(&Buffer);
if(Buffer){
DBG_SYS_Printf("CH564 ROMA :0x0 - 0x6FFFF");
DBG_SYS_Printf("CH564 EEPROM :0x70000 - 0x77FFF");
}else {
DBG_SYS_Printf("CH564 ROMA :0x0 - 0x2FFFF");
DBG_SYS_Printf("CH564 EEPROM :0x30000 - 0x37FFF");
}
EEPROM_Init();
memset((uint8_t *)&g_app_feature,0,sizeof(G_SYS_FEATURE_T));
memset((uint8_t *)&g_mcu_app_feature,0,sizeof(G_SYS_FEATURE_T));
memset((uint8_t *)&g_update_recode,0,sizeof(UPDATE_RECORD_T));
DBG_SYS_Printf("Project Name:%s",Prject_File_Name);
sys_reset = RCC_GET_GLOB_RST_KEEP(); //复位保持寄存器
if(sys_reset == 0x00)
{
DBG_SYS_Printf("上电复位 \r\n");
g_Boot_Time = 10000;
}else if(sys_reset == 0x02){
DBG_SYS_Printf("软件复位 \r\n");
g_Boot_Time = 30000;
}else if(sys_reset == 0x03){
DBG_SYS_Printf("MCU Flash软件复位 \r\n");
g_Boot_Time = 3000;
}else {
DBG_SYS_Printf("异常复位 \r\n");
g_Boot_Time = 30000;
}
RCC_SET_GLOB_RST_KEEP(0x01);
g_jump_flag = Read_APP_Feature();
//测试使用的 - 不是最终状态
if(g_jump_flag == 2) {
MCU_APP_Write(); //MCU需要写入
DBG_SYS_Printf("进行MCU Flash软件复位 \r\n");
//WDT_Init();
//RCC_SET_GLOB_RST_KEEP(0x03);
Delay_Ms(1000);
// - 进行全局复位让芯片重新转载Code Flash
RCC_GlobleRstCFG(RB_GLOB_FORCE_RST, ENABLE);
while(1);
}
WDT_Init();
while (1)
{
WDT_Feed();
SYS_LED_Task();
Uart0_Task();
Uart2_Task();
//测试使用的 - 不是最终状态
if(g_jump_flag == 0x00)
{
if(SysTick_1ms - g_Boot_Tick >= 5000)
{
g_Boot_Tick = SysTick_1ms;
DBG_SYS_Printf("Jump APP 2\r\n");
Delay_Ms(1000);
WDT_Reinit();
NVIC_EnableIRQ( Software_IRQn );
Delay_Ms( 20 );
HSI_ON();
CLKSEL_HSI();
SYSCLK_SOURCE_SELECT(SYSCLK_SOURCE_HSI_HSE);
RCC_UNLOCK_SAFE_ACCESS();
BITS_CFG( R32_EXTEN_CTLR0 , RB_FLASH_PRE_EN , DISABLE );
RCC_LOCK_SAFE_ACCESS();
NVIC_SetPendingIRQ( Software_IRQn );
}
}else {
if(SysTick_1ms - g_Boot_Tick >= g_Boot_Time)
{
DBG_SYS_Printf("进行软件复位 ....");
RCC_SET_GLOB_RST_KEEP(0x02);
Delay_Ms(1000);
RCC_GlobleRstCFG(RB_GLOB_FORCE_RST, ENABLE);
while(1);
}
}
}
}
void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
/*********************************************************************
* @fn NMI_Handler
*
* @brief This function handles NMI exception.
*
* @return none
*/
void NMI_Handler(void)
{
while (1)
{
}
}
/*********************************************************************
* @fn HardFault_Handler
*
* @brief This function handles Hard Fault exception.
*
* @return none
*/
void HardFault_Handler(void)
{
/* MRS_关于HardFault问题查找思路 : https://www.cnblogs.com/wchmcu/p/17545931.html */
uint32_t v_mepc,v_mcause,v_mtval;
//Dbg_Println(DBG_BIT_SYS_STATUS_bit,"hardfault\n");
v_mepc = __get_MEPC();
v_mcause = __get_MCAUSE();
v_mtval = __get_MTVAL();
printf("boot mepc:%x\n",v_mepc);
printf("boot mcause:%x\n",v_mcause);
printf("boot mtval:%x\n",v_mtval);
while(1);
}
/* - 跳转APP 程序必须在SW_Handler中断中跳转
* - 因为进入SW_Handler中断后芯片会进入机器模式才允许跳转APP */
void SW_Handler(void) {
__asm volatile("li a6, 0x01000");
__asm volatile("jr a6");
while(1);
}