新增:首次提交
首次提交,上传Launcher工程
This commit is contained in:
185
User/main.c
Normal file
185
User/main.c
Normal file
@@ -0,0 +1,185 @@
|
||||
/********************************** (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>
|
||||
|
||||
uint32_t test_tick = 0;
|
||||
|
||||
/*********************************************************************
|
||||
* @fn main
|
||||
*
|
||||
* @brief Main program.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
uint8_t sys_reset = 0;
|
||||
uint32_t wdt_reste_tick = 0;
|
||||
unsigned char Buffer;
|
||||
|
||||
unsigned long DATA_ROM_ADDR;
|
||||
|
||||
SystemCoreClockUpdate(); //ϵͳ<CFB5><CDB3>ʼ<EFBFBD><CABC>
|
||||
Systick_Init();
|
||||
|
||||
UARTx_Init(UART_0,512000);
|
||||
UARTx_Init(UART_1,512000);
|
||||
UARTx_Init(UART_2,512000);
|
||||
UARTx_Init(UART_3,512000);
|
||||
|
||||
SYS_LED_Init();
|
||||
|
||||
SPI_SRAM_Init();
|
||||
|
||||
SPI_FLASH_Init();
|
||||
|
||||
Get_Flash_Size(&Buffer);
|
||||
|
||||
if(Buffer){
|
||||
DATA_ROM_ADDR = 0x70000;
|
||||
}else {
|
||||
DATA_ROM_ADDR = 0x30000;
|
||||
}
|
||||
|
||||
DBG_SYS_Printf("RTC_Init \r\n");
|
||||
|
||||
RTC_Init();
|
||||
|
||||
DBG_SYS_Printf("EEPROM_Init - DATA_ROM_ADDR:%x\r\n",DATA_ROM_ADDR);
|
||||
|
||||
EEPROM_Init();
|
||||
|
||||
DBG_SYS_Printf("G PARA \r\n");
|
||||
|
||||
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("G_SYS_FEATURE_T : %d \r\n",sizeof(G_SYS_FEATURE_T));
|
||||
|
||||
sys_reset = RCC_GET_GLOB_RST_KEEP();
|
||||
if(sys_reset == 0x00)
|
||||
{
|
||||
DBG_SYS_Printf("<EFBFBD>ϵ縴λ \r\n");
|
||||
}else if(sys_reset == 0x02){
|
||||
|
||||
DBG_SYS_Printf("<EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD>λ \r\n");
|
||||
}else {
|
||||
DBG_SYS_Printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ \r\n");
|
||||
}
|
||||
|
||||
RCC_SET_GLOB_RST_KEEP(0x01);
|
||||
g_jump_flag = Read_APP_Feature();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
if(g_jump_flag == 2) {
|
||||
MCU_APP_Write(); //MCU<43><55>Ҫд<D2AA><D0B4>
|
||||
g_jump_flag = 0;
|
||||
|
||||
// printf("Jump APP 1\r\n");
|
||||
//
|
||||
// Delay_Ms(1000);
|
||||
//
|
||||
// __disable_irq();
|
||||
// Jump_APP(g_mcu_app_feature.app_start_addr);
|
||||
|
||||
NVIC_EnableIRQ( Software_IRQn );
|
||||
Delay_Ms( 20 );
|
||||
NVIC_SetPendingIRQ( Software_IRQn );
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
SYS_LED_Task();
|
||||
|
||||
Uart0_Task();
|
||||
|
||||
UART1_RECEIVE();
|
||||
UART2_RECEIVE();
|
||||
UART3_RECEIVE();
|
||||
|
||||
RTC_TASK();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
if(SysTick_1ms - g_Boot_Tick >= 5000)
|
||||
{
|
||||
g_Boot_Tick = SysTick_1ms;
|
||||
|
||||
if(g_jump_flag == 0x00) //APP У<><D0A3><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>תAPP
|
||||
{
|
||||
printf("Jump APP 2\r\n");
|
||||
|
||||
Delay_Ms(1000);
|
||||
|
||||
NVIC_EnableIRQ( Software_IRQn );
|
||||
Delay_Ms( 20 );
|
||||
NVIC_SetPendingIRQ( Software_IRQn );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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_<53><5F><EFBFBD><EFBFBD>HardFault<6C><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˼· : 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);
|
||||
}
|
||||
|
||||
void SW_Handler(void) {
|
||||
printf("SW_Handler Jump App\r\n");
|
||||
Delay_Ms( 100 );
|
||||
|
||||
__disable_irq();
|
||||
__asm volatile("li a6, 0x07000");
|
||||
__asm volatile("jr a6");
|
||||
while(1);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user