中级会员
- 积分
- 404
- 金钱
- 404
- 注册时间
- 2016-8-23
- 在线时间
- 50 小时
|
楼主 |
发表于 2016-9-12 12:48:25
|
显示全部楼层
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "stmflash.h"
#include "iap.h"
u8 res;
u8 USART_RX_BUF[USART_REC_LEN];
//ALIENTEKÕ½½¢STM32¿a·¢°åêμÑé48
//IAPêμÑé Bootloader V1.0 ′úÂë
//¼¼êõÖ§3Ö£owww.openedv.com
//1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾
int main(void)
{
u8 len;
u8 t;
u8 key;
u16 oldcount=0; //àÏμÄ′®¿ú½óêÕêy¾YÖμ
u16 applenth=0; //½óêÕμ½μÄapp′úÂë3¤¶è
u8 clearflag=0;
uart_init(256000); //′®¿ú3õê¼»ˉÎa256000
delay_init(); //Ñóê±3õê¼»ˉ
LCD_Init();
LED_Init(); //3õê¼»ˉóëLEDᬽóμÄó2¼t½ó¿ú
KEY_Init(); //°′¼ü3õê¼»ˉ
POINT_COLOR=RED;//éèÖÃ×ÖìåÎaoìé«
LCD_ShowString(60,50,200,16,16,"Warship STM32");
LCD_ShowString(60,70,200,16,16,"IAP TEST");
LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(60,110,200,16,16,"2012/9/24");
LCD_ShowString(60,130,200,16,16,"WK_UP:Copy APP2FLASH");
LCD_ShowString(60,150,200,16,16,"KEY1:Erase SRAM APP");
LCD_ShowString(60,170,200,16,16,"KEY0:Run SRAM APP");
LCD_ShowString(60,190,200,16,16,"KEY2:Run FLASH APP");
POINT_COLOR=BLUE;
//ÏÔê¾ìáê¾DÅÏ¢
POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶
while(1)
{
// if(USART_RX_STA&0x8000)
// {
// len=USART_RX_STA&0x3fff;//μÃμ½′Ë′νóêÕμ½μÄêy¾Y3¤¶è
// printf("\r\nÄú·¢ËíμÄÏûÏ¢Îa:\r\n\r\n");
// for(t=0;t<len;t++)
// {
// USART_SendData(USART1, USART_RX_BUF[t]);//Ïò′®¿ú1·¢Ëíêy¾Y
// while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//μè′y·¢Ëí½áêø
// }
// res = USART_RX_BUF[0];
// if(res==0x31)
// LED1=0;
// if(res==0x30)
// LED1=1;
//
// printf("\r\n\r\n");//2åèë»»DD
// USART_RX_STA=0;
// }
//
if(USART_RX_CNT)
{
if(oldcount==USART_RX_CNT)//DÂÖüÆúÄú,ûóDêÕμ½èÎoÎêy¾Y,èÏÎa±¾′Îêy¾Y½óêÕíê3é.
{
applenth=USART_RX_CNT;
oldcount=0;
USART_RX_CNT=0;
printf("óû§3ìDò½óêÕíê3é!\r\n");
printf("′úÂë3¤¶è:%dBytes\r\n",applenth);
}else oldcount=USART_RX_CNT;
}
t++;
delay_ms(10);
if(t==30)
{
LED0=!LED0;
t=0;
if(clearflag)
{
clearflag--;
if(clearflag==0)LCD_Fill(60,210,240,210+16,WHITE);//Çå3yÏÔê¾
}
}
key=KEY_Scan(0);
if(key==KEY_UP)
{
if(applenth)
{
printf("¿a꼸üDÂ1ì¼t...\r\n");
LCD_ShowString(60,210,200,16,16,"Copying APP2FLASH...");
if(((*(vu32*)(0X20001000+4))&0xFF000000)==0x08000000)//ÅD¶ÏêÇ·ñÎa0X08XXXXXX.
{
iap_write_appbin(FLASH_APP1_ADDR,USART_RX_BUF,applenth);//¸üDÂFLASH′úÂë
delay_ms(100);
LCD_ShowString(60,210,200,16,16,"Copy APP Successed!!");
printf("1ì¼t¸üDÂíê3é!\r\n");
}else
{
LCD_ShowString(60,210,200,16,16,"Illegal FLASH APP! ");
printf("·ÇFLASHó|óÃ3ìDò!\r\n");
}
}else
{
printf("ûóD¿éòÔ¸üDÂμÄ1ì¼t!\r\n");
LCD_ShowString(60,210,200,16,16,"No APP!");
}
clearflag=7;//±êÖ¾¸üDÂáËÏÔê¾,2¢ÇòéèÖÃ7*300msoóÇå3yÏÔê¾
}
if(key==KEY_DOWN)
{
if(applenth)
{
printf("1ì¼tÇå3yíê3é!\r\n");
LCD_ShowString(60,210,200,16,16,"APP Erase Successed!");
applenth=0;
}else
{
printf("ûóD¿éòÔÇå3yμÄ1ì¼t!\r\n");
LCD_ShowString(60,210,200,16,16,"No APP!");
}
clearflag=7;//±êÖ¾¸üDÂáËÏÔê¾,2¢ÇòéèÖÃ7*300msoóÇå3yÏÔê¾
}
if(key==KEY_LEFT)
{
printf("¿aê¼Ö′DDFLASHóû§′úÂë!!\r\n");
if(((*(vu32*)(FLASH_APP1_ADDR+4))&0xFF000000)==0x08000000)//ÅD¶ÏêÇ·ñÎa0X08XXXXXX.
{
iap_load_app(FLASH_APP1_ADDR);//Ö′DDFLASH APP′úÂë
}else
{
printf("·ÇFLASHó|óÃ3ìDò,ÎT·¨Ö′DD!\r\n");
LCD_ShowString(60,210,200,16,16,"Illegal FLASH APP!");
}
clearflag=7;//±êÖ¾¸üDÂáËÏÔê¾,2¢ÇòéèÖÃ7*300msoóÇå3yÏÔê¾
}
// if(key==KEY_RIGHT)
// {
// printf("¿aê¼Ö′DDSRAMóû§′úÂë!!\r\n");
// if(((*(vu32*)(0X20001000+4))&0xFF000000)==0x20000000)//ÅD¶ÏêÇ·ñÎa0X20XXXXXX.
// {
// iap_load_app(0X20001000);//SRAMμØÖ·
// }else
// {
// printf("·ÇSRAMó|óÃ3ìDò,ÎT·¨Ö′DD!\r\n");
// LCD_ShowString(60,210,200,16,16,"Illegal SRAM APP!");
// }
// clearflag=7;//±êÖ¾¸üDÂáËÏÔê¾,2¢ÇòéèÖÃ7*300msoóÇå3yÏÔê¾
// }
}
}
这个是IAPmain.c |
|