⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 STR71X系列ARM微控制器原理与实践配套光盘
💻 C
字号:
#include "Main.h"
#include "Buffer.h"
#include "Xmodem.h"
#include "FlashProg.h"

static char *itoa(u32 n)
{
	static char buf[12], *p = buf + 11;
	*p = 0;
	if(n)
		do {
			*--p = n % 10 + '0';
			n /= 10;
		} while(n);
	else
		*--p = '0';
	return p;
}

static void Init(void)
{
#ifdef DEBUG
	debug();
#endif

	RCCU_Div2Config(ENABLE);						// Enable DIV2
	RCCU_MCLKConfig(RCCU_DEFAULT);					// Configure MCLK = RCLK
	RCCU_FCLKConfig(RCCU_DEFAULT);					// Configure FCLK = RCLK
	RCCU_PCLKConfig(RCCU_DEFAULT);					// Configure PCLK = RCLK
	RCCU_PLL1Config(RCCU_PLL1_Mul_12, RCCU_Div_2) ;		// Configure the PLL1 ( * 12 , / 2 )
	
	while(RCCU_FlagStatus(RCCU_PLL1_LOCK) == RESET);// Wait PLL to lock
	
	RCCU_RCLKSourceConfig(RCCU_PLL1_Output) ;		// Select PLL1_Output as RCLK clock
	// at this step the CKOUT signal should be equal to 48 Mhz

	// Configure the GPIO pins
	GPIO_Config(GPIO0, UARTX_Tx_Pin, GPIO_AF_PP);
	GPIO_Config(GPIO0, UARTX_Rx_Pin, GPIO_IN_TRI_CMOS);

	// Configure the UART X
	UART_OnOffConfig(UARTX, ENABLE);		// Turn UARTX on
	UART_FifoConfig(UARTX, DISABLE);		// Disable FIFOs
	UART_FifoReset(UARTX, UART_RxFIFO);		// Reset the UART_RxFIFO
	UART_FifoReset(UARTX, UART_TxFIFO);		// Reset the UART_TxFIFO
	UART_LoopBackConfig(UARTX, DISABLE);	// Disable Loop Back
		/* Configure the UARTX as following:
			- Baudrate = 115200 Bps
			- No parity
			- 8 data bits
			- 1 stop bit */
	UART_Config(UARTX, 115200, UART_NO_PARITY, UART_1_StopBits, UARTM_8D);
	UART_RxConfig(UARTX, ENABLE);          // Enable Rx

	Flash_Init();
}

void __main(void)
{
	u8 c=0;
	int MoreData, Overflowd, ProgState;
	Init();

	UART_StringSend(UARTX, (u8 *)"STR710F Flash Programmer V0.2\r\n"
		"\t0 -- Program Internal Flash (256KB)\r\n"
		"\t1 -- Program External Flash (2MB)\r\n"
		"\tSelect(0 -- 1): ");
	
	do {
		UART_ByteReceive(UARTX, &c, 0xFF);
	} while(c < '0' || c > '1');
	UART_ByteSend(UARTX, &c);
	UART_StringSend(UARTX, (u8 *)"\r\nPlease send file using Xmodem protocol...\r\n");
	Buf_Init();
	Xmodem_Reset();
	FlashProg_Reset(c - '0');
	MoreData = 1;
	Overflowd = 0;
	do {
		if(MoreData && Xmodem_Action())
			MoreData = 0;
		ProgState = FlashProg_Action();
		if(ProgState < 0)
			Overflowd = 1;
	} while(MoreData || ProgState <= 0);
	UART_StringSend(UARTX, (u8 *)"\r\nFile received successfully(");
	UART_StringSend(UARTX, (u8 *)itoa(Xmodem_RecvSize));
	UART_StringSend(UARTX, (u8 *)" bytes).\r\n");

	UART_StringSend(UARTX, (u8 *)itoa(FlashProg_GetSize()));
	UART_StringSend(UARTX, (u8 *)" bytes programmed.");
	if(Overflowd)
		UART_StringSend(UARTX, (u8 *)"(Overflowed)");
	UART_StringSend(UARTX, (u8 *)"\r\n");
	UART_StringSend(UARTX, (u8 *)itoa(FlashProg_ErrSize));
	UART_StringSend(UARTX, (u8 *)" bytes were not correct.\r\n");
	while(1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -