Example #1
0
/*******************************************************************************
* Function Name  : GetInputString
* Description    : Get Input string from the HyperTerminal
* Input          : - buffP: The input string
* Output         : None
* Return         : None
*******************************************************************************/
void GetInputString (u8 * buffP)
{
  u32 bytes_read = 0;
  u8 c = 0;
  do
  {
    c = GetKey();
    if (c == '\r'){
			break;
		}
    if (c == '\b'){ /* Backspace */
      if (bytes_read > 0){
        SerialPutString("\b \b");
        bytes_read --;
      }
      continue;
    }
    if (bytes_read >= CMD_STRING_SIZE ){
      SerialPutString("Command string size overflow\r\n");
      bytes_read = 0;
      continue;
    }
    if (c >= 0x20 && c <= 0x7E){
      buffP[bytes_read++] = c;
      SerialPutChar(c);
    }
  }
  while (1);
  SerialPutString("\n\r");
  buffP[bytes_read] = '\0';
}
Example #2
0
File: PM2.5.c Project: hnulong/C51
/***********************************************
*                       打电话
************************************************/
void DialVoiceCall()
{
    SerialPutString("AT+COLP=1\r\n");//dial the number
    delay(2000);
    SerialPutString("ATD15200831527;\r\n");//dial the number
    delay(2000);
}
Example #3
0
int main()
{
	pFunction Jump_To_Application;
	uint32_t JumpAddress;

	SystemInit();		/* 配置系统时钟为72M */	
	NVIC_Configuration();

	watchdog_init();
	delay_init(72);	//72M
	w25x64_init();

	InitSerial();
	Signel_led_init();
	TIM_init();
	SerialPutString("BootLoader Runing...\n");
	SerialPutString("BootLoader for ");
	SerialPutString(SYSTEM_NAME);
	SerialPutString("\n");
	ymodem();

	iap();
	SerialPutString("Load App!\n");

	TIM_Cmd(TIM2,DISABLE);
	if (((*(__IO uint32_t*)APP_LOCATION) & 0x2FFE0000 ) == 0x20000000)
	{
		JumpAddress = *(__IO uint32_t*) (APP_LOCATION + 4);
		Jump_To_Application = (pFunction) JumpAddress;
		__set_MSP(*(__IO uint32_t*) APP_LOCATION);
		Jump_To_Application();
	}
	return 0;
}
Example #4
0
/**
  * @brief  Upload a file via serial port.
  * @param  None
  * @retval None
  */
void SerialUpload(void)
{
  uint32_t status = 0; 

  SerialPutString("\n\n\rSelect Receive File ... (press any key to abort)\n\r");

  if (GetKey() == CRC16)
  {
    /* Transmit the flash image through ymodem protocol */
    status = Ymodem_Transmit((uint8_t*)ApplicationAddress, (const uint8_t*)"UploadedFlashImage.bin", FLASH_IMAGE_SIZE);

    if (status != 0) 
    {
      SerialPutString("\n\rError Occured while Transmitting File\n\r");
    }
    else
    {
      SerialPutString("\n\rFile Trasmitted Successfully \n\r");
    }
  }
  else
  {
    SerialPutString("\r\n\nAborted by user.\n\r");  
  }
 
}
Example #5
0
File: PM2.5.c Project: hnulong/C51
/***********************************************
*                       发送短信
************************************************/
void sendsms()
{
    SerialPutString(s1);
    delay(2000);
    SerialPutString(s2);
    delay(3000);
    SerialPutString(s3);
    delay(2000);
    SerialPutString(&s4);
    delay(2000);
}
Example #6
0
/*******************************************************************************
* Function Name  : FLASH_DisableWriteProtectionPages
* Description    : Disable the write protection of desired pages
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void FLASH_DisableWriteProtectionPages(void)
{
  u32 useroptionbyte = 0, WRPR = 0;
  u16 var1 = OB_IWDG_SW, var2 = OB_STOP_NoRST, var3 = OB_STDBY_NoRST;
  FLASH_Status status = FLASH_BUSY;

  WRPR = FLASH_GetWriteProtectionOptionByte();

  /* Test if user memory is write protected */
  if ((WRPR & UserMemoryMask) != UserMemoryMask){
    useroptionbyte = FLASH_GetUserOptionByte();

    UserMemoryMask |= WRPR;

    status = FLASH_EraseOptionBytes();

    if(UserMemoryMask != 0xFFFFFFFF){
      status = FLASH_EnableWriteProtection((u32)~UserMemoryMask);
    }

    /* Test if user Option Bytes are programmed */
    if((useroptionbyte & 0x07) != 0x07){ /* Restore user Option Bytes */
      if((useroptionbyte & 0x01) == 0x0){
        var1 = OB_IWDG_HW;
      }
      if((useroptionbyte & 0x02) == 0x0){
        var2 = OB_STOP_RST;
      }
      if((useroptionbyte & 0x04) == 0x0){
        var3 = OB_STDBY_RST;
      }

      FLASH_UserOptionByteConfig(var1, var2, var3);	
    }

    if (status == FLASH_COMPLETE){
      SerialPutString("Write Protection disabled...\r\n");

      SerialPutString("...and a System Reset will be generated to re-load the new option bytes\r\n");

      /* Enable WWDG clock */
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

       /* Generate a system Reset to re-load the new option bytes: enable WWDG and set
         counter value to 0x4F, as T6 bit is cleared this will generate a WWDG reset */
      WWDG_Enable(0x4F);
    }else{
      SerialPutString("Error: Flash write unprotection failed...\r\n");
    }
  }else{
    SerialPutString("Flash memory not write protected\r\n");
  }
}
Example #7
0
File: DHT11.C Project: hnulong/C51
void main()
{
	uchar len,i;
	uchar xdata Tvalue[6],Hvalue[6];
	SerialInit();
	LCDInit();
	while(1)
	{ 
	    RH();
		SerialPutString(buff);
		sprintf(Tvalue,"%2.2f",temperature);
		sprintf(Hvalue,"%2.2f%%",humidity);
		LCDWriteCom(0x01);//ÇåÆÁ
		LCDWriteCom(0x80);
		len=strlen(info1);
		//дÊý¾Ýµ½LCD1602
		for(i=0;i<len;i++)
			LCDWriteData(info1[i]);
		len=strlen(Tvalue);
		for(i=0;i<len;i++)
			LCDWriteData(Tvalue[i]);
		LCDWriteData((uchar)223);
		LCDWriteData('C');
		LCDWriteCom(0x80+0x43);
		len=strlen(info2);
		for(i=0;i<len;i++)
			LCDWriteData(info2[i]);
		len=strlen(Hvalue);
		for(i=0;i<len;i++)
			LCDWriteData(Hvalue[i]);
	   //
	   Delay(10000);
	}

}
Example #8
0
/*
*******************************************************************************
*
* FUNCTION:         ExecCommandline
*
* DESCRIPTION:      This function is used to process an input string, split the
*                   input string into command and parameter strings, find a command
*                   structure in the command list array and execute the command.
*
* INPUT PARAMETERS: cmdListP   is a pointer to the command list array.
*                   cmdStringP is a pointer to the input string.
*
* RETURNS:          none.
*******************************************************************************
*/
void ExecCommandline (CommandListEntry_T * cmdListP, char * inputStringP)
{
    CommandListEntry_T * cmdListEntryP;
	int argc;
	char *argv[16];
	char *resid;

	while (*inputStringP) {
		memset(argv, 0, sizeof(argv));
		parseargs(inputStringP, &argc, argv, &resid);
		if (argc > 0)
		{
		    if ((cmdListEntryP=findCmd(cmdListP, argv[0])) == NULL)
		    {
		        SerialPutString("Command is not found\r\n");
		    }
		    else
		    {
			    cmdListEntryP->func(argc, (const char **)argv);
		    }
		}	
		inputStringP = resid;
	}

}
Example #9
0
void main()
{
 //delay(10000);
 SerialInit();  //串口初始化,用以向调试终端发送数据
 while(1)
 {
 SerialPutString("yahoo!!!"); //发送一个测试字符串
 }
/*
 MMC_Init(); //SD卡初始化
 delay(10000);
 MMC_get_volume_info();	  //获得SD卡相关信息,输出到终端
 FAT32_Init(&Init_Arg);	  //FAT32文件系统初始化,装入参数
 Printf("BPB_Sector_No"  ,Init_Arg.BPB_Sector_No);
 Printf("Total_Size"     ,Init_Arg.Total_Size   );
 Printf("FirstDirClust"  ,Init_Arg.FirstDirClust); 
 Printf("FirstDataSector",Init_Arg.FirstDataSector); 
 Printf("BytesPerSector" ,Init_Arg.BytesPerSector); 
 Printf("FATsectors"     ,Init_Arg.FATsectors); 
 Printf("SectorsPerClust",Init_Arg.SectorsPerClust);
 Printf("FirstFATSector" ,Init_Arg.FirstFATSector); 
 Printf("FirstDirSector" ,Init_Arg.FirstDirSector);   //以上几个语句用以输出参数值到终端
 Printf("FAT32_OpenFile" ,(FAT32_OpenFile("\\TEST.TXT"))->FileSize); //打开根目录下的TEST.TXT文件,并输出文件大小 
 FAT32_ReadFile(&FileInfo);  //读取文件数据,输出到终端
*/
// while(1);
}
Example #10
0
/*----------------------------------------------------------------------
*  Get Input string from the console. 
*/
void GetInputString (char * buffP)
{
    int bytes_read = 0;
    char c;

    do {
    	c = GetKey();
    	if (c == '\r')   	break;
    	if (c == '\b')	//backspace
    	{
			if (bytes_read > 0)
			{
				SerialPutString("\b \b");
		    	bytes_read --;
    		}
    		continue;
    	}
    	if (bytes_read >= CMD_STRING_SIZE )
    	{
    		SerialPutString("Command string size overflow\r\n");
    		bytes_read = 0;
    		continue;
    	}
		
    	/*
    	if (c == UP_KEY || c==DOWN_KEY || c==LEFT_KEY ||c==RIGHT_KEY)
    	{
    		c = BEEP_KEY;
    		SerialPutChar(c);
    		continue;
    	}*/

    	if (c >= 0x20 && c<= 0x7E)
    	{
    		buffP[bytes_read++] = c;
    		SerialPutChar(c);
    	}	
    	
    }while (1);
    SerialPutString("\n\r");
    buffP[bytes_read] = '\0';

}
Example #11
0
/*----------------------------------------------------------------------
 * Serial printf.
 */
void SerialPrintf (char * fmt, ...)
{
    char buffer[256];
    va_list ap;

    va_start(ap,fmt);
    //doPrint(buffer,fmt,ap);
    vsprintf(buffer, fmt, ap);
    SerialPutString(buffer);
}
Example #12
0
/*******************************************************************************
* Function Name  : GetIntegerInput
* Description    : Get an integer from the HyperTerminal
* Input          : - num: The inetger
* Output         : None
* Return         : 1: Correct
*                  0: Error
*******************************************************************************/
u32 GetIntegerInput(s32 * num)
{
  u8 inputstr[16];

  while (1)
  {
    GetInputString(inputstr);
    if (inputstr[0] == '\0') continue;
    if ((inputstr[0] == 'a' || inputstr[0] == 'A') && inputstr[1] == '\0'){
      SerialPutString("User Cancelled \r\n");
      return 0;
    }

    if (Str2Int(inputstr, num) == 0){
      SerialPutString("Error, Input again: \r\n");
    }else{
      return 1;
    }
  }
}
Example #13
0
/**
  * @brief  Upload a file via serial port.
  * @param  None
  * @retval None
  */
void SerialUpload(void)
{
  uint8_t status = 0 ; 

  SerialPutString("\n\n\rSelect Receive File\n\r");

  if (GetKey() == CRC16)
  {
    /* Transmit the flash image through ymodem protocol */
    status = Ymodem_Transmit((uint8_t*)APPLICATION_ADDRESS, (const uint8_t*)"UploadedFlashImage.bin", USER_FLASH_SIZE);

    if (status != 0) 
    {
      SerialPutString("\n\rError Occurred while Transmitting File\n\r");
    }
    else
    {
      SerialPutString("\n\rFile uploaded successfully \n\r");
    }
  }
}
Example #14
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;

  /* Flash unlock */
  FLASH_Unlock();

  /* Judge STM3210b-LK1 Key2 - PD3 */
  /* Enable GPIOD clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
  
  /* Configure PD.00 pin as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* Test if Key push-button on STM3210X-EVAL Board is pressed */
  if (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) == 0x00)
  { 
    /* If Key is pressed */
    /* Execute the IAP driver in order to re-program the Flash */
    IAP_Init();
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n=              (C) COPYRIGHT 2010 STMicroelectronics                 =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=     In-Application Programming Application  (Version 3.3.0)        =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=                                   By MCD Application Team          =");
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n\r\n");
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "ApplicationAddress" */
    if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
    { 
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
      Jump_To_Application = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) ApplicationAddress);
      Jump_To_Application();
    }
  }

  while (1)
  {}
}
Example #15
0
/*******************************************************************************
* Function Name  : Main_Menu
* Description    : Display/Manage a Menu on HyperTerminal Window
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Main_Menu(void)
{
	static char choice[3];
	int i;
	
	
  	while (1)
	{
		SerialPutString("\r\n==========================================================\r\n");
		SerialPutString("                          APPLICATION MENU :\r\n");
		SerialPutString("\r\n==========================================================\r\n\n");
       		SerialPutString(" 1 - FTP Client Start \r\n");

                
                SerialPutString("Enter your choice : ");
                GetInputString(choice);
		
		for( i=0; i<3; i++)
		{
		  printf("\r\n TEST STR = %c", choice[i]);
		}
                
	} /* While(1)*/
}/* Main_Menu */
Example #16
0
void CommandMode(void * arg, char * dummyP)
{
    char inputString[CMD_STRING_SIZE];
    
    inputString[CMD_STRING_SIZE-1]= '\0';

	SerialPutString("Command line mode...:\r\n");
	while(1)
	{
		SerialPutChar('>');

        // Process a command string.
		GetInputString (inputString);
        if (strcmp(inputString,"EXIT")==0 || strcmp(inputString,"exit")==0)
        	return;
		ExecCommandline (PlatformCmdList, inputString);
	}
}
Example #17
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Flash unlock */
  FLASH_Unlock();

  /* Initialize Key Button mounted on STM3210X-EVAL board */       
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);   

  /* Test if Key push-button on STM3210X-EVAL Board is pressed */
  if (STM_EVAL_PBGetState(BUTTON_KEY)  == 0x00)
  { 
    /* If Key is pressed */
    /* Execute the IAP driver in order to re-program the Flash */
    IAP_Init();
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n=              (C) COPYRIGHT 2010 STMicroelectronics                 =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=     In-Application Programming Application  (Version 3.3.0)        =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=                                   By MCD Application Team          =");
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n\r\n");
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "ApplicationAddress" */
    if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
    { 
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
      Jump_To_Application = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) ApplicationAddress);
      Jump_To_Application();
    }
  }

  while (1)
  {}
}
Example #18
0
/*****************************************************************

Routine:   SerialPutChar

Inputs:
	unsigned char uch - the char to be placed in the COM Port
	out buffer

Returns:
	int

Description:
	This routine takes a single character and places it in the output
	buffer to be sent ot the attached hardware.
*****************************************************************/
int Comm32Port::SerialPutChar(unsigned char uch)
{
	int
		nRes = 0;

	unsigned char 
		szString[1];
	
	szString[0] = uch;

	nRes = SerialPutString(szString, 1);
	
	if (nRes < 0)
		return nRes;
	else
		return COMM_OK;

} /* SerialPutChar */
Example #19
0
File: PM2.5.c Project: hnulong/C51
/***********************************************
*                       GPRS采集数据
************************************************/
void ConnectGPRS(float dust,float t,float h)
{
// char temp[40];
    /*
    SerialPutString("AT+CGCLASS=\"B\"\r\n");
    delay(2000);
    SerialPutString("AT+CGDCONT=1,\"IP\",\"CMNET\"\r\n");
    delay(2000);
    SerialPutString("AT+CGATT=1\r\n");
    delay(2000);
    SerialPutString("AT+CIPCSGP=1,\"CMNET\"\r\n");
    delay(2000);
    SerialPutString("AT+CIPCSGP=0\r\n");
    delay(2000);
    SerialPutString("AT+CDNSCFG=\"211.91.216.129\"\r\n");
    delay(2000);
    */
    SerialPutString("AT+CLPORT=\"UDP\",\"3033\"\r\n");//set a port
    delay(2000);
    SerialPutString("AT+CIPSTART=\"UDP\",\"125.221.182.95\",\"8080\"\r\n");//set destination IP
    delay(2000);
    SerialPutString("AT+CIPSEND\r\n");//dial the number
    delay(2000);
    //mySerial.print("PM2.5 value:");
    sprintf(sensor,"%.2f",dust);//
    SerialPutString(sensor);
    sprintf(sensor,",%.2f",t);//
    SerialPutString(sensor);
    sprintf(sensor,",%.2f",h);//
    SerialPutString(sensor);
    SerialPutByte(s4);
    delay(2000);
    SerialPutString("AT+CIPCLOSE\r\n");//dial the number
    delay(2000);
    SerialPutString("AT+CIPSHUT\r\n");
    delay(2000);
}
Example #20
0
/**
  * @brief  Display the Main Menu on to HyperTerminal
  * @param  None
  * @retval None
  */
void Main_Menu(void)
{
  uint8_t key = 0;
  
  /* Get the number of block (4 or 2 pages) from where the user program will be loaded */
  BlockNbr = (FlashDestination - 0x08000000) >> 12;

  /* Compute the mask to test if the Flash memory, where the user program will be
     loaded, is write protected */
#if defined (STM32F10X_MD) || defined (STM32F10X_MD_VL)
  UserMemoryMask = ((uint32_t)~((1 << BlockNbr) - 1));
#else /* USE_STM3210E_EVAL */
  if (BlockNbr < 62)
  {
    UserMemoryMask = ((uint32_t)~((1 << BlockNbr) - 1));
  }
  else
  {
    UserMemoryMask = ((uint32_t)0x80000000);
  }
#endif /* (STM32F10X_MD) || (STM32F10X_MD_VL) */


  /* Test if any page of Flash memory where program user will be loaded is write protected */
  if ((FLASH_GetWriteProtectionOptionByte() & UserMemoryMask) != UserMemoryMask)
  {
    FlashProtection = 1;
  }
  else
  {
    FlashProtection = 0;
  }

  while (1)
  {
    SerialPutString("\r\n================== Main Menu ============================\r\n\n");
    SerialPutString("  Download Image To the STM32F10x Internal Flash ------- 1\r\n\n");
    SerialPutString("  Upload Image From the STM32F10x Internal Flash ------- 2\r\n\n");
    SerialPutString("  Execute The New Program ------------------------------ 3\r\n\n");
    
    if(FlashProtection != 0)
    {
      SerialPutString("  Disable the write protection ------------------------- 4\r\n\n");
    }
    
    SerialPutString("==========================================================\r\n\n");
    
    key = GetKey();

    if (key == 0x31)
    {
      /* Download user application in the Flash */
			SerialPutString(" File --> Transfer --> YMODEM --> Send... \r\n\n");
      SerialDownload();
    }
    else if (key == 0x32)
    {
      /* Upload user application from the Flash */
      SerialUpload();
    }
    else if (key == 0x33)
    {
      JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);

      /* Jump to user application */
      Jump_To_Application = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) ApplicationAddress);
      Jump_To_Application();
    }
    else if ((key == 0x34) && (FlashProtection == 1))
    {
      /* Disable the write protection of desired pages */
      FLASH_DisableWriteProtectionPages();
    }
    else
    {
      if (FlashProtection == 0)
      {
        SerialPutString("Invalid Number ! ==> The number should be either 1, 2 or 3\r");
      }
      else
      {
        SerialPutString("Invalid Number ! ==> The number should be either 1, 2, 3 or 4\r");
      } 
    }
  }
}
Example #21
0
/**
  * @brief  Download a file via serial port
  * @param  None
  * @retval None
  */
void SerialDownload(void)
{
    uint8_t Number[10] = "          ";
    int32_t Size = 0;

    SerialPutString("Waiting for the file to be sent ... (press 'a' to abort)\n\r");
    Size = Ymodem_Receive(&tab_1024[0]);
    if (Size > 0)
    {
        SerialPutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: ");
        SerialPutString(file_name);
        Int2Str(Number, Size);
        SerialPutString("\n\r Size: ");
        SerialPutString(Number);
        SerialPutString(" Bytes\r\n");
        SerialPutString("-------------------\n");
    }
    else if (Size == -1)
    {
        SerialPutString("\n\n\rThe image size is higher than the allowed space memory!\n\r");
    }
    else if (Size == -2)
    {
        SerialPutString("\n\n\rVerification failed!\n\r");
    }
    else if (Size == -3)
    {
        SerialPutString("\r\n\nAborted by user.\n\r");
    }
    else
    {
        SerialPutString("\n\rFailed to receive the file!\n\r");
    }
}
Example #22
0
/*******************************************************************************
* Function Name  : Main_Menu
* Description    : Display the Main Menu on to HyperTerminal
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Main_Menu(void)
{
  u8 key = 0;
  
  /* Get the number of block (4 pages) from where the user program will be loaded */
  BlockNbr = (FlashDestination - 0x08000000) >> 12;

  /* Compute the mask to test if the Flash memory, where the user program will be
     loaded, is write protected */
  UserMemoryMask = ((u32)~((1<<BlockNbr)-1));
  
  /* Test if any page of Flash memory where program user will be loaded is write protected */
  if ((FLASH_GetWriteProtectionOptionByte() & UserMemoryMask) != UserMemoryMask)
  {
    FlashProtection = TRUE;
    SerialPutString("\r\n================== Main Menu ============================\r\n\n");
    SerialPutString("  Download Image To the STM32F10x Internal Flash ------- 1\r\n\n");
    SerialPutString("  Execute The New Program ------------------------------ 2\r\n\n");
    SerialPutString("  Disable the write protection ------------------------- 3\r\n\n");
    SerialPutString("==========================================================\r\n\n");
  }
  else
  {
    FlashProtection = FALSE;
    SerialPutString("\r\n================== Main Menu ============================\r\n\n");
    SerialPutString("  Download Image To the STM32F10x Internal Flash ------- 1\r\n\n");
    SerialPutString("  Execute The New Program ------------------------------ 2\r\n\n");
    SerialPutString("==========================================================\r\n\n");
  }
    
  while (1)
  {
//		SerialPutString("ready to get choice\r\n");
    key = GetKey();
//		SerialPutString("\r\n");
//		SerialPutChar(key);
//		SerialPutString("\r\nget choice\r\n");
    if (key == 0x31)
    {
      /* Download user application in the Flash */
      SerialDownload();
    }
    else if (key == 0x32)
    {
      JumpAddress = *(vu32*) (ApplicationAddress + 4);  //the address value

      /* Jump to user application */
      Jump_To_Application = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
			__set_MSP(*(vu32*) ApplicationAddress);
      Jump_To_Application();
    }
    else if ((key == 0x33)&& (FlashProtection == TRUE))
    {
      /* Disable the write protection of desired pages */
      FLASH_DisableWriteProtectionPages();
    } 
    else
    {
      if(FlashProtection == FALSE)
      {
        SerialPutString("Invalid Number ! ==> The number should be either 1 or 2\r\n");
      }
      else
      {
        SerialPutString("Invalid Number ! ==> The number should be either 1, 2 or 3\r\n");
      }
    }
  }
}
Example #23
0
/*******************************************************************************
* 函数名称: refresh_flash
* 输入参数: 
* 输出参数: 
* --返回值: 
* 函数功能: --
*******************************************************************************/
static void refresh_flash(void)
{
    uint8_t Number[10] = "          ";
    int32_t Size = 0;
    
    MFS_UARTSWRst(UartUSBCh);  //reset UART
    UARTConfigMode(UartUSBCh, &tUARTModeConfigT);
    MFS_UARTEnableTX(UartUSBCh);
    MFS_UARTEnableRX(UartUSBCh);
    
    SerialPutString("Waiting for the file to be sent ...\n\r");
    Size = Ymodem_Receive(&tab_1024[0]);
    
//    MFS_UARTDisableRX(UartUSBCh);
//    MFS_UARTDisableTX(UartUSBCh);
    
    if (Size > 0)
    {
        SerialPutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: ");
        SerialPutString(file_name);
        Int2Str(Number, Size);
        SerialPutString("\n\r Size: ");
        SerialPutString(Number);
        SerialPutString(" Bytes\r\n");
        SerialPutString("--------------------------------\r\n");
        
        //oneSound(10,0);
        
        /* read extern Flash(MX25L4006) verify image */
//#define  TEST_IMAGE
#ifdef   TEST_IMAGE     
        uint32_t i = 0;
        uint32_t j = ApplicationAddress; 
        memset(&tab_1024[0], 0, PACKET_SIZE);
        for (i=0u; i<1056; i++) /* (132*1024)/128 0-32 sector */
        {
            MX25L3206_Read((uint8_t *)tab_1024, j, PACKET_SIZE);
            j += PACKET_SIZE;
            printHex(tab_1024,PACKET_SIZE);
        }          
#endif        
        /* check CRC32 */
        //...
        /* updata image complete, jump application routine */
        //Jump_To_app();  
        //while (1);  
    }
    else if (Size == -1)
    {
        SerialPutString("\n\n\rThe image size is higher than the allowed space memory!\n\r");
    }
    else if (Size == -2)
    {
        SerialPutString("\n\n\rVerification failed!\n\r");
    }
    else if (Size == -3)
    {
        SerialPutString("\r\n\nAborted by user.\n\r");
    }
    else
    {
        SerialPutString("\n\rFailed to receive the file!\n\r");
    }/* end if (Size > 0) Ymodem Rev */
    
    if (Size > 0)
    {
        oneSound(10,0);
    }
    else
    {
        oneSound(10, 300);  /* BUZZER 201 error buzz */
    }    
    
    bFM3_GPIO_PDOR0_PD = 1u; /* LED 201 light off */
    bFM3_GPIO_PDOR0_PC = 1u; /* LED 202 light off */
}
Example #24
0
/*******************************************************************************
* 函数名称: download_program_to_meter
* 输入参数: 
* 输出参数: 
* --返回值: 
* 函数功能: --
*******************************************************************************/
static void download_program_to_meter(void)
{
    uint32_t status = 0u; 
    uint8_t tick_C = 0u;
    uint8_t Rev_flag = 0u;
    uint8_t read_flash_check_flag = 0u;
    uint8_t file_size[FILE_SIZE_LENGTH] = {0};
    
    /* wait for meter send 'C', meter printf something before send 'C' */
    delay_ms(5000);  /* 存在很低的概率, 会出现在进入升级的时候会停滞几秒 */
    
    MFS_UARTErrorClr(UartUSBCh);  //CLR error flag
    MFS_UARTSWRst(UART52_Ch);  //reset UART
    UARTConfigMode(UART52_Ch, &tUARTModeConfigT);
    MFS_UARTEnableRX(UART52_Ch);
    MFS_UARTEnableTX(UART52_Ch);
    
    //SerialPutString("\n\n\rSelect Receive File ... \n\r");
    
    Rev_flag = Receive_Byte(UART52_Ch , &tick_C, Rev_timeout); 
    if (0u == Rev_flag)
    {
        if (tick_C == CRC16)
        {
            printf("Rev C. \r\n");
        }    
    }    
    else
    {
		SerialPutString("\r\n no Rev 'C' .\r\n");  
    }    
    
    if (tick_C == CRC16)
    {
        SerialPutString("downlod image .bin ... \r\n");
        
        read_flash_check_flag = 0u;
        read_flash_check_flag = MX25L3206_Read((uint8_t*)(file_size),
                                               (uint32_t)FLASH_IMAGE_SIZE_ADDRESS,
                                               FILE_SIZE_LENGTH);
        if (OK != read_flash_check_flag)
        {
            __NOP();
        }  
        else
        {
            Str2Int(file_size, &flash_image_size);  /* str to hex */

            /* Transmit the flash image through ymodem protocol */
            status = Ymodem_Transmit((uint8_t*)ApplicationAddress,   //!!!!Note
                     (const uint8_t*)"DownloadFlashImage.bin",
                     flash_image_size);  /* , ,FLASH_IMAGE_MAX_SIZE */

            MFS_UARTDisableRX(UART52_Ch);  //

            if (status != 0) 
            {
                SerialPutString("\n\rError Occured while Transmitting File\n\r");
                oneSound(10, 300);  /* BUZZER 201 error buzz */
            }
            else
            {
                SerialPutString("\n\rFile Trasmitted Successfully \n\r");
                oneSound(10, 0);  /* BUZZER 201 buzz */
            }
        }//end if flash check    
    }
    else
    {
        SerialPutString("\r\n\nAborted by user or no Rev 'C' .\n\r");  
        oneSound(10, 300);  /* BUZZER 201 error buzz */
        //while(1);  //test!!! 
    }
    
    bFM3_GPIO_PDOR0_PD = 1u; /* LED 201 light off */
    bFM3_GPIO_PDOR0_PC = 1u; /* LED 202 light off */
    MFS_UARTDisableRX(UART52_Ch);
    MFS_UARTDisableTX(UART52_Ch);
}
Example #25
0
/*******************************************************************************
* Function Name  : Main_Menu
* Description    : Display/Manage a Menu on HyperTerminal Window
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Main_Menu(void)
{
	static char choice[3];
	static char subject[32], msg[256], sender[32], passwd[32], recipient[32], encodedText[256];
	static bool bTreat;
	static u8 Sip[4];
	static char key = 0;
	static wiz_NetInfo netinfo;
	
	
	while (1)
	{
		/* Display Menu on HyperTerminal Window */
		bTreat = (bool)RESET ;
   	        SerialPutString("\r\n====================== STM32-Discovery ===================\r\n");
		SerialPutString("This Application is basic example of UART interface with\r\n");
		SerialPutString("Windows Hyper Terminal. \r\n");
		SerialPutString("\r\n==========================================================\r\n");
		SerialPutString("                          APPLICATION MENU :\r\n");
		SerialPutString("\r\n==========================================================\r\n\n");
		SerialPutString(" 1 - Set LD1 on \r\n");
		SerialPutString(" 2 - Set LD1 off \r\n");
		SerialPutString(" 3 - Show network setting\r\n");
		SerialPutString(" 4 - Set  network setting\r\n");
		SerialPutString(" 5 - Run TCP Loopback\r\n");
		SerialPutString(" 6 - Run UDP Loopback\r\n");
		SerialPutString(" 7 - DNS test\r\n");
		SerialPutString(" 8 - BASE64 test\r\n");
		SerialPutString(" 9 - Send Mail\r\n");
		
		SerialPutString("Enter your choice : ");
		GetInputString(choice);
		/* Set LD1 on */
		if (strcmp(choice,"1")== 0)
		{
			bTreat = (bool)SET;
			LED3_onoff(ON);
			LED4_onoff(ON);
		}
		/* Set LD1 off */
		if ((strcmp(choice,"2") == 0))
		{
			bTreat = (bool)SET;
			LED3_onoff(OFF);
			LED4_onoff(OFF);
		}
		if (strcmp(choice,"3") == 0)
		{
			bTreat = (bool)SET;
			GetNetInfo(&netinfo);
			printf("\r\nIP : %d.%d.%d.%d", netinfo.IP[0],netinfo.IP[1],netinfo.IP[2],netinfo.IP[3]);
			printf("\r\nSN : %d.%d.%d.%d", netinfo.Subnet[0],netinfo.Subnet[1],netinfo.Subnet[2],netinfo.Subnet[3]);
			printf("\r\nGW : %d.%d.%d.%d", netinfo.Gateway[0],netinfo.Gateway[1],netinfo.Gateway[2],netinfo.Gateway[3]);
			printf("\r\nDNS server : %d.%d.%d.%d", netinfo.DNSServerIP[0],netinfo.DNSServerIP[1],netinfo.DNSServerIP[2],netinfo.DNSServerIP[3]);

		}

		if (strcmp(choice,"4") == 0)
		{
			bTreat = (bool)SET;
			// IP address
			SerialPutString("\r\nIP address : ");
			GetInputString(msg);
			if(!VerifyIPAddress(msg, netinfo.IP))
			{
				SerialPutString("\aInvalid.");
			}

			// Subnet mask
			SerialPutString("\r\nSubnet mask : ");
			GetInputString(msg);
			if(!VerifyIPAddress(msg, netinfo.Subnet))
			{
				SerialPutString("\aInvalid.");
			}
			
			// gateway address
			SerialPutString("\r\nGateway address : ");
			GetInputString(msg);
			if(!VerifyIPAddress(msg, netinfo.Gateway))
			{
				SerialPutString("\aInvalid.");
			}

			// DNS address
			SerialPutString("\r\nDNS address : ");
			GetInputString(msg);
			if(!VerifyIPAddress(msg, netinfo.DNSServerIP))
			{
				SerialPutString("\aInvalid.");
			}

			printf("\r\nIP : %d.%d.%d.%d", netinfo.IP[0],netinfo.IP[1],netinfo.IP[2],netinfo.IP[3]);
			printf("\r\nSN : %d.%d.%d.%d", netinfo.Subnet[0],netinfo.Subnet[1],netinfo.Subnet[2],netinfo.Subnet[3]);
			printf("\r\nGW : %d.%d.%d.%d", netinfo.Gateway[0],netinfo.Gateway[1],netinfo.Gateway[2],netinfo.Gateway[3]);
			printf("\r\nDNS server : %d.%d.%d.%d", netinfo.DNSServerIP[0],netinfo.DNSServerIP[1],netinfo.DNSServerIP[2],netinfo.DNSServerIP[3]);

			SetNetInfo(&netinfo);
		}
		

		if (strcmp(choice,"5") == 0)
		{
			bTreat = (bool)SET;
		  
			SerialPutString("\r\nRun TCP loopback");
			printf("\r\nRun TCP loopback, port number [%d] is listened", (u16)TCP_LISTEN_PORT);
			SerialPutString("\r\nTo Exit, press [Q]");
			
		  while(1) {

			if ((SerialKeyPressed((char*)&key) == 1) && (key == 'Q')) {
				SerialPutString("\r\n Stop ");
				
				break;
			}

			loopback_tcps(7, (u16)TCP_LISTEN_PORT);
		  }
		  

		}


		if (strcmp(choice,"6") == 0)
		{
			bTreat = (bool)SET;
		  
			SerialPutString("\r\nRun UDP loopback");
			printf("\r\nRun UDP loopback, port number [%d] is listened", (u16)UDP_LISTEN_PORT);
			SerialPutString("\r\nTo Exit, press [Q]");
			
			while(1) {

				if ((SerialKeyPressed((char*)&key) == 1) && (key == 'Q')) {
					SerialPutString("\r\n Stop ");
				
					break;

				}

				loopback_udp(7, (u16)UDP_LISTEN_PORT);
			}

		}


		if (strcmp(choice,"7")== 0)
		{
		  	bTreat = (bool)SET;
			
			SerialPutString("\r\nServer address : ");
			GetInputString(msg);

			SerialPutString("URL = ");
			SerialPutString(msg);
			  	
			if (dns_query(SOCK_DNS, (void *)msg, Sip) == 1) {

				printf("\r\nSIP : %d.%d.%d.%d", (u16)Sip[0],(u16)Sip[1],(u16)Sip[2],(u16)Sip[3]);

			}else {
				SerialPutString("\n\r DNS fail");

			}

			
		}


		if (strcmp(choice,"8")== 0)
		{
			bTreat = (bool)SET;
			
			memset(encodedText, '\0', 256);

			SerialPutString("\r\n");
			SerialPutString(" 1 - BASE64 Encode \r\n");
			SerialPutString(" 2 - BASE64 Decode \r\n");
			SerialPutString("Enter your choice : ");
			GetInputString(choice);

			if (strcmp(choice,"1")== 0) {

				SerialPutString("Type Plain Text\r\n");
				GetInputString(msg);
				base64_encode(msg, strlen(msg)+1, encodedText);
				SerialPutString("Encoded Text\r\n");
				printf("%s\r\n", encodedText);

			}else if(strcmp(choice,"2")== 0){

				SerialPutString("Type Encoded Text\r\n");
				GetInputString(msg);
				base64_decode(msg, (void *)encodedText, strlen(msg));
				SerialPutString("Decoded Text\r\n");
				printf("%s\r\n", encodedText);

			}

		}


		if (strcmp(choice,"9")== 0) {
		  	bTreat = (bool)SET;

			SerialPutString("\r\nServer address : ");
			GetInputString(msg);

			SerialPutString("URL = ");
			SerialPutString(msg);

			// DNS
			if (dns_query(SOCK_DNS, (void *)msg, Sip) == 1) {
				printf("\r\nSIP : %d.%d.%d.%d", (u16)Sip[0],(u16)Sip[1],(u16)Sip[2],(u16)Sip[3]);

				while(1) {

					SerialPutString("\r\nType a Sender: ");
					GetInputString(sender);

					SerialPutString("Type a Password: "******"Type a Recipient: ");
					GetInputString(recipient);

					SerialPutString("Type a Subject: ");
					GetInputString(subject);

					SerialPutString("Type a message: ");
					GetInputString(msg);

					send_mail(SOCK_SMTP, (void *)sender, (void *) passwd, (void *)recipient, (void *)subject, (void *)msg, Sip);

					SerialPutString("\r\nIf you want send another message? [YES]: any key, [NO]: Q");
					key = GetKey();

					if (key == 'Q') {
						SerialPutString("\r\n Stop ");

						break;

					}

				}

			}else {
				SerialPutString("\r\nDNS error");

			}
		}


		/* OTHERS CHOICE*/
		if (bTreat == (bool)RESET)
		{
			SerialPutString(" wrong choice  \r\n");
		}			
	} /* While(1)*/
}/* Main_Menu */
Example #26
0
/**
  * @brief  Display the Main Menu on HyperTerminal
  * @param  None
  * @retval None
  */
void Main_Menu(void)
{
  uint8_t key = 0;

  SerialPutString("\r\n======================================================================");
  SerialPutString("\r\n=              (C) COPYRIGHT 2011 STMicroelectronics                 =");
  SerialPutString("\r\n=                                                                    =");
  SerialPutString("\r\n=  STM32F4xx In-Application Programming Application  (Version 1.0.0) =");
  SerialPutString("\r\n=                                                                    =");
  SerialPutString("\r\n=                                   By MCD Application Team          =");
  SerialPutString("\r\n======================================================================");
  SerialPutString("\r\n\r\n");

  /* Test if any sector of Flash memory where user application will be loaded is write protected */
  if (FLASH_If_GetWriteProtectionStatus() == 0)   
  {
    FlashProtection = 1;
  }
  else
  {
    FlashProtection = 0;
  }

  while (1)
  {
    SerialPutString("\r\n================== Main Menu ============================\r\n\n");
    SerialPutString("  Download Image To the STM32F4xx Internal Flash ------- 1\r\n\n");
    SerialPutString("  Upload Image From the STM32F4xx Internal Flash ------- 2\r\n\n");
    SerialPutString("  Execute The New Program ------------------------------ 3\r\n\n");

    if(FlashProtection != 0)
    {
      SerialPutString("  Disable the write protection ------------------------- 4\r\n\n");
    }

    SerialPutString("==========================================================\r\n\n");

    /* Receive key */
    key = GetKey();

    if (key == 0x31)
    {
      /* Download user application in the Flash */
      SerialDownload();
    }
    else if (key == 0x32)
    {
      /* Upload user application from the Flash */
      SerialUpload();
    }
    else if (key == 0x33) /* execute the new program */
    {
      JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
      /* Jump to user application */
      Jump_To_Application = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
      Jump_To_Application();
    }
    else if ((key == 0x34) && (FlashProtection == 1))
    {
      /* Disable the write protection */
      switch (FLASH_If_DisableWriteProtection())
      {
        case 1:
        {
          SerialPutString("Write Protection disabled...\r\n");
          FlashProtection = 0;
          break;
        }
        case 2:
        {
          SerialPutString("Error: Flash write unprotection failed...\r\n");
          break;
        }
        default:
        {
        }
      }
    }
    else
    {
      if (FlashProtection == 0)
      {
        SerialPutString("Invalid Number ! ==> The number should be either 1, 2 or 3\r");
      }
      else
      {
        SerialPutString("Invalid Number ! ==> The number should be either 1, 2, 3 or 4\r");
      }
    }
  }
}
int serialCommunicator::SerialPutChar( unsigned char uch, unsigned int msTimeout )
{
    std::string character(1, uch);

    return SerialPutString(character, character.length(), msTimeout);
}
Example #28
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*Clock initialization. */
  clock_init();

  /* Flash unlock */
  FLASH_Unlock();


  /*GPIO Initialization. */
  /*GPIOA, GPIOB on APB2 bus clock enable. */
  	  RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN;

  	  /*PA0, PA1, PA2, PA3 in output mode general purpose push-pull. */
  	  GPIOA->CRL =(0x03 << (3 * 4)) | (0x03 << (2 * 4)) | (0x03 << (1 * 4)) | (0x03 << (0 * 4));

  	  /*PB0, PB1 in floating input mode. */
  	  GPIOB->CRL = (0x08 << (1 * 4)) | (0x08 << (0 * 4));

  	  /*why do we do this?. */
  	  GPIOB->ODR |= GPIO_ODR_ODR0 | GPIO_ODR_ODR1;

  	  /*Light up all leds by resetting the output bits. */
  	  GPIOA->BSRR |= GPIO_BSRR_BR0 | GPIO_BSRR_BR1 | GPIO_BSRR_BR2 | GPIO_BSRR_BR3;

  /* Initialize Key Button mounted on STM3210X-EVAL board */       
  //STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);

  /* Test if button on the board is pressed during reset. */
  if ((GPIOB->IDR & GPIO_IDR_IDR1) == 0x00)
  { 
    /* If Key is pressed */
    /* Execute the IAP driver in order to re-program the Flash */
    IAP_Init();
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n=              (C) COPYRIGHT 2010 STMicroelectronics                 =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=     In-Application Programming Application  (Version 3.3.0)        =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=                                   By MCD Application Team          =");
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n\r\n");
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "ApplicationAddress" */
	uint32_t pippo1, pippo2;
	pippo1 = (*(__IO uint32_t*)ApplicationAddress); // 0x08000000   what is this value
	pippo2 = pippo1 & 0x2FFE0000;
    if (pippo2 == 0x20000000)
    { 
      /* Jump to user application */
      /* JumpAddress is not a pointer type. */
      /* ApplicationAddress+4 casted to a pointer to uin32_t. Jump address is the content
       * of the cell pointed by ApplicationAddress
       * Though wouldn't this be correct: JumpAddress = ApplicationAddress+4;
       * or! why does it dereferences it?
       */
      JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);

      /*Jump_To_Application now points to the same address = JumpAddress through casting. */
      Jump_To_Application = (pFunction) JumpAddress;

      /* Initialize user application's Stack Pointer */
      /* __set_MSP implemented in CMSIS (as all the functions __* like). */
      __set_MSP(*(__IO uint32_t*) ApplicationAddress);
      Jump_To_Application();
    }
  }

  while (1)
  {}
}
Example #29
0
/**
  * @brief  Disable the write protection of desired pages
  * @param  None
  * @retval None
  */
void FLASH_DisableWriteProtectionPages(void)
{
  uint32_t useroptionbyte = 0, WRPR = 0;
  uint16_t var1 = OB_IWDG_SW, var2 = OB_STOP_NoRST, var3 = OB_STDBY_NoRST;
  FLASH_Status status = FLASH_BUSY;

  WRPR = FLASH_GetWriteProtectionOptionByte();

  /* Test if user memory is write protected */
  if ((WRPR & UserMemoryMask) != UserMemoryMask)
  {
    useroptionbyte = FLASH_GetUserOptionByte();

    UserMemoryMask |= WRPR;

    status = FLASH_EraseOptionBytes();

    if (UserMemoryMask != 0xFFFFFFFF)
    {
      status = FLASH_EnableWriteProtection((uint32_t)~UserMemoryMask);
    }

    /* Test if user Option Bytes are programmed */
    if ((useroptionbyte & 0x07) != 0x07)
    { 
      /* Restore user Option Bytes */
      if ((useroptionbyte & 0x01) == 0x0)
      {
        var1 = OB_IWDG_HW;
      }
      if ((useroptionbyte & 0x02) == 0x0)
      {
        var2 = OB_STOP_RST;
      }
      if ((useroptionbyte & 0x04) == 0x0)
      {
        var3 = OB_STDBY_RST;
      }

      FLASH_UserOptionByteConfig(var1, var2, var3);
    }

    if (status == FLASH_COMPLETE)
    {
      SerialPutString("Write Protection disabled...\r\n");

      SerialPutString("...and a System Reset will be generated to re-load the new option bytes\r\n");

      /* Generate System Reset to load the new option byte values */
      NVIC_SystemReset();
    }
    else
    {
      SerialPutString("Error: Flash write unprotection failed...\r\n");
    }
  }
  else
  {
    SerialPutString("Flash memory not write protected\r\n");
  }
}
Example #30
0
/*******************************************************************************
  * @函数名称	main
  * @函数说明   主函数
  * @输入参数   无
  * @输出参数   无
  * @返回参数   无
*******************************************************************************/
int main(void)
{
		uint8_t fuf=0;
		uint8_t fu_e=1;			//固件更新使能
	  uint8_t i=0;
	

		uint8_t hui[32]=
		{0x04,0x04,0xF4,0x54,0x54,0x54,0x54,0xFF,0x54,0x54,0x54,0x54,0xF4,0x04,0x04,0x00,
		0x40,0x30,0x01,0x01,0x39,0x41,0x41,0x45,0x59,0x41,0x41,0x71,0x01,0x08,0x30,0x00};/*"恵",0*/	
	
	
	
	
		SystemTick_Init();
		NVIC_Configuration();
	
	
	
	
	
		oled_control_Init();
		OLED_ON;	
	
		OLED_Init();
	
		SPI_FLASH_Init();		//SPI接口初始化
	
    
    FLASH_Unlock();			//STM32内部Flash 解锁
	
	
    //LED_Configuration();
	
	
    //配置按键
    KEY_Configuration();//按钮对应的PB5脚初始化	
		
    IAP_Init();					//即串口1初始化,但是没有串口中断程序
	
	
		buzzer_control_Init();
		coil_control_Init();
	
	
	
	
// 		OLED_Clear();
// 		OLED_ShowUnite(24,2,"if updata");
// 		OLED_ShowUnite(28,4,"press OK");		
// 	  delay_ms(500);










// 		while(i<5)
// 		{
// 			OLED_Clear();	
// 			OLED_DrawBMP(32,2,48,4,hui);
// 			OLED_ShowUnite(48,2,"  科  ");
// 			OLED_ShowUnite(32,4,"  合  技");	
// 			delay_ms(500);	
// 			
// 			OLED_Clear();		
// 			OLED_ShowUnite(32,2,"  合  技");	
// 			OLED_DrawBMP(32,4,48,6,hui);			
// 			OLED_ShowUnite(48,4,"  科  ");
// 			delay_ms(500);		
// 	
// 			i++;
// 		}
		
		
// 		OLED_Clear();	
// 		OLED_DrawBMP(32,2,48,4,hui);
// 		OLED_ShowUnite(48,2,"合科技");		
// 		delay_ms(800);
		
		
		//测试发送
// 		while(1)
// 		{
// 			Send_Byte(ACK);			//收到上位机发送的第0帧之后发送ACK命令
// 			Send_Byte(CRC16);		//接着再发送C,表示等待上位机发送数据帧
// 		}
	
    //按键是否按下
    //if (GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)  == 0x00)
		
		
		
		/*
		出厂时,下载程序的步骤:
					1.下载字库
					2.下载IAP
					3.下载应用程序
		
		*/
		
		


		//在下载字库时,先将FIRMWARE_UPGRADE_FLAG标志置为1,所以再下载IAP程序时会直接进入固件更新
		
		
		SPI_FLASH_Read(&fuf,FIRMWARE_UPGRADE_FLAG,1);
		if(fuf==1)
    {
			
				OLED_Clear();
				//OLED_ShowUnite(16,2,"固件更新中...");
			  OLED_ShowUnite(32,2,"to updata");		
				delay_ms(500);
  

  			//假如按键按下
        //执行IAP驱动程序更新Flash程序

        SerialPutString("\r\n======================================================================");
        SerialPutString("\r\n=              (C) COPYRIGHT 2011 Lierda                             =");
        SerialPutString("\r\n=                                                                    =");
        SerialPutString("\r\n=     In-Application Programming Application  (Version 1.0.0)        =");
        SerialPutString("\r\n=                                                                    =");
        SerialPutString("\r\n=                                   By wuguoyan                      =");
        SerialPutString("\r\n======================================================================");
        SerialPutString("\r\n\r\n");
        Main_Menu();
    }
    //否则执行用户程序
    else
    {
			/*		
			在程序里#define ApplicationAddress    0x8003000 ,*(__IO uint32_t*)ApplicationAddress)
			即取0x8003000开始到0x8003003 的4个字节的值, 因为我们的应用程序APP中设置把 中断向
			量表 放置在0x08003000 开始的位置;而中断向量表里第一个放的就是栈顶地址的值
			也就是说,这句话即通过判断栈顶地址值是否正确(是否在0x2000 0000 - 0x 2000 2000之间)
			来判断是否应用程序已经下载了,因为应用程序的启动文件刚开始就去初始化化栈空间,
			如果栈顶值对了,说应用程已经下载了启动文件的初始化也执行了;				
			*/

			
        //判断用户是否已经下载程序,因为正常情况下此地址是栈地址。
        //若没有这一句的话,即使没有下载程序也会进入而导致跑飞。
			
				//*(__IO uint32_t*)ApplicationAddress 与 __vector_table[0]是一样的
				//__vector_table[0]是应用程序栈的顶
			
				//X=*(__IO uint32_t*)ApplicationAddress
        //if (( X & 0x2FFE0000 ) == 0x20000000)			
				//X只有在0x20000000与0x2001FFFF之间时,才可能有(X&0x2FFE0000) == 0x20000000成立
			
				//即栈顶是不是在以0x20000000开始的128K的范围内,这里便是STM32的RAM区域
			
        if (( ( *(__IO uint32_t*)ApplicationAddress ) & 0x2FFE0000 ) == 0x20000000)
        {
					
// 						OLED_Clear();
// 						OLED_ShowUnite(4,2,"Execute Program");
// 						delay_ms(500);							
					
					
					
            //SerialPutString("Execute Program\r\n\n");
            //跳转至用户代码
            JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
            Jump_To_Application = (pFunction) JumpAddress;

            //初始化用户程序的堆栈指针
            __set_MSP(*(__IO uint32_t*) ApplicationAddress);
            Jump_To_Application();		//执行复位中断函数
        }
        else
        {
						OLED_Clear();
						OLED_ShowUnite(4,2,"no user Program");
						delay_ms(500);							
										
            SerialPutString("no user Program\r\n\n");
        }
    }

// 		OLED_Clear();
// 		OLED_ShowUnite(16,2,"please reboot");
// 		delay_ms(500);		
// 		
// 		SerialPutString("please reboot\r\n\n");
//     while (1)
//     {
//     }
}