V2.31
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : main.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Version : V1.0.2
|
||||
* Date : 2025/10/27
|
||||
* Description : Main program body.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
@@ -11,16 +11,12 @@
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
*@Note
|
||||
*IAP upgrade routine:
|
||||
*Support serial port and USB for FLASH burning
|
||||
*
|
||||
*1. The routine needs to install the CH372 driver.
|
||||
*Note: FLASH operation keeps the frequency below 100Mhz, it is recommended that the main
|
||||
*frequency of IAP be below 100Mhz
|
||||
*
|
||||
* IAP routine: this routine support USB and UART mode,
|
||||
* and you can choose the command method or the IO method to jump to the APP .
|
||||
* Key parameters: CalAddr - address in flash (same in APP), note that this address needs to be unused.
|
||||
* CheckNum - The value of 'CalAddr' that needs to be modified.
|
||||
* Tips :the routine need IAP software version 1.50.
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
#include "ch32v20x_usbfs_device.h"
|
||||
#include "iap.h"
|
||||
@@ -29,7 +25,12 @@
|
||||
#include "usb_lib.h"
|
||||
#include "hw_config.h"
|
||||
#include "usb_pwr.h"
|
||||
extern u8 End_Flag;
|
||||
extern vu8 End_Flag;
|
||||
|
||||
#define UPGRADE_MODE_COMMAND 0
|
||||
#define UPGRADE_MODE_IO 1
|
||||
|
||||
#define UPGRADE_MODE UPGRADE_MODE_COMMAND
|
||||
/*********************************************************************
|
||||
* @fn IAP_2_APP
|
||||
*
|
||||
@@ -59,6 +60,7 @@ void IAP_2_APP(void) {
|
||||
NVIC_EnableIRQ(Software_IRQn);
|
||||
NVIC_SetPendingIRQ(Software_IRQn);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn main
|
||||
*
|
||||
@@ -66,12 +68,31 @@ void IAP_2_APP(void) {
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
SystemCoreClockUpdate();
|
||||
Delay_Init();
|
||||
USART_Printf_Init(115200);
|
||||
printf("SystemClk:%d\r\n", SystemCoreClock);
|
||||
printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
|
||||
printf("IAP\r\n");
|
||||
|
||||
#if UPGRADE_MODE == UPGRADE_MODE_COMMAND
|
||||
if(*(vu32 *)FLASH_Base != 0xe339e339 )
|
||||
{
|
||||
if(*(vu32 *)CalAddr != CheckNum)
|
||||
{
|
||||
IAP_2_APP();
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
#elif UPGRADE_MODE == UPGRADE_MODE_IO
|
||||
if(PA0_Check() == 0)
|
||||
{
|
||||
IAP_2_APP();
|
||||
while(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
Set_USBConfig();
|
||||
USB_Init();
|
||||
@@ -81,18 +102,19 @@ int main(void) {
|
||||
USB_Interrupts_Config();
|
||||
|
||||
USBFS_Init();
|
||||
USART3_CFG(57600);
|
||||
USART3_CFG(460800);
|
||||
while(1)
|
||||
{
|
||||
EP2_RecData_Deal();
|
||||
if( USART_GetFlagStatus(USART3, USART_FLAG_RXNE) != RESET) {
|
||||
UART_Rx_Deal();
|
||||
}
|
||||
#if UPGRADE_MODE == UPGRADE_MODE_COMMAND
|
||||
if (End_Flag)
|
||||
{
|
||||
Delay_Ms(10);
|
||||
{
|
||||
IAP_2_APP();
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user