116 lines
2.9 KiB
C
116 lines
2.9 KiB
C
|
|
/********************************** (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;
|
|||
|
|
uint8_t test_buff[10] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A};
|
|||
|
|
|
|||
|
|
/*********************************************************************
|
|||
|
|
* @fn main
|
|||
|
|
*
|
|||
|
|
* @brief Main program.
|
|||
|
|
*
|
|||
|
|
* @return none
|
|||
|
|
*/
|
|||
|
|
int main(void)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
SystemCoreClockUpdate();
|
|||
|
|
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();
|
|||
|
|
|
|||
|
|
WCHNET_LIB_Init();
|
|||
|
|
|
|||
|
|
Dbg_Println(DBG_BIT_SYS_STATUS_bit,"MCU Start!! 2025-11-03-10:42\r\n");
|
|||
|
|
Dbg_Println(DBG_BIT_SYS_STATUS_bit,"SystemClk:%d\r\n", SystemCoreClock);
|
|||
|
|
|
|||
|
|
while (1)
|
|||
|
|
{
|
|||
|
|
SYS_LED_Task();
|
|||
|
|
|
|||
|
|
UART0_RECEIVE();
|
|||
|
|
UART1_RECEIVE();
|
|||
|
|
UART2_RECEIVE();
|
|||
|
|
UART3_RECEIVE();
|
|||
|
|
|
|||
|
|
if(SysTick_1ms - test_tick >= 10000){
|
|||
|
|
test_tick = SysTick_1ms;
|
|||
|
|
|
|||
|
|
Dbg_Println(DBG_BIT_SYS_STATUS_bit,"RUN PYH:%x...\r\n",ETH_ReadPHYRegister(PHY_ADDRESS, PHY_BSR));
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
NetWork_Task();
|
|||
|
|
|
|||
|
|
WCHNET_MainTask();
|
|||
|
|
|
|||
|
|
if(WCHNET_QueryGlobalInt())
|
|||
|
|
{
|
|||
|
|
WCHNET_HandleGlobalInt();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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();
|
|||
|
|
|
|||
|
|
Dbg_Println(DBG_BIT_SYS_STATUS_bit,"mepc:%x\n",v_mepc);
|
|||
|
|
Dbg_Println(DBG_BIT_SYS_STATUS_bit,"mcause:%x\n",v_mcause);
|
|||
|
|
Dbg_Println(DBG_BIT_SYS_STATUS_bit,"mtval:%x\n",v_mtval);
|
|||
|
|
while(1);
|
|||
|
|
}
|
|||
|
|
|