Index: Boot/prj/MDK/YC3121_Keil.uvprojx
===================================================================
--- /YC3121_demo/ModuleDemo/updata_app/Boot/prj/MDK/YC3121_Keil.uvprojx	(revision 793)
+++ /YC3121_demo/ModuleDemo/updata_app/Boot/prj/MDK/YC3121_Keil.uvprojx	(working copy)
@@ -338,7 +338,7 @@
               <MiscControls></MiscControls>
               <Define>__USEKEILCOMPILE__</Define>
               <Undefine></Undefine>
-              <IncludePath>..\..\..\..\..\Librarier\core;..\..\..\..\..\Librarier\sdk</IncludePath>
+              <IncludePath>..\..\..\..\..\Librarier\core;..\..\..\..\..\Librarier\sdk;..\..\user;..\..\..\..\..\Librarier\sdk\yc_usb\scpu_usb_hid_Device_Demo;..\..\..\..\..\Librarier\sdk\yc_usb\libraries\harward_Der;..\..\..\..\..\Librarier\sdk\yc_usb\libraries\SCPU_USB_Device_Library\class\HID;..\..\..\..\..\Librarier\sdk\yc_usb\scpu_usb_hid_Device_Demo;..\..\..\..\..\Librarier\sdk\yc_usb\libraries\SCPU_USB_Device_Library\core</IncludePath>
             </VariousControls>
           </Cads>
           <Aads>
@@ -392,6 +392,11 @@
               <FileType>1</FileType>
               <FilePath>..\..\..\..\..\Librarier\core\system.c</FilePath>
             </File>
+            <File>
+              <FileName>bt_code.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\core\bt_code.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>
@@ -403,9 +408,19 @@
               <FilePath>..\..\user\main.c</FilePath>
             </File>
             <File>
-              <FileName>bt_code.c</FileName>
+              <FileName>ota_ble.c</FileName>
               <FileType>1</FileType>
-              <FilePath>..\..\user\bt_code.c</FilePath>
+              <FilePath>..\..\user\ota_ble.c</FilePath>
+            </File>
+            <File>
+              <FileName>halUSB.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\user\halUSB.c</FilePath>
+            </File>
+            <File>
+              <FileName>otausb.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\user\otausb.c</FilePath>
             </File>
           </Files>
         </Group>
@@ -427,6 +442,46 @@
               <FileType>1</FileType>
               <FilePath>..\..\..\..\..\Librarier\sdk\yc_systick.c</FilePath>
             </File>
+            <File>
+              <FileName>yc_encflash_bulk.lib</FileName>
+              <FileType>4</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_encflash_bulk.lib</FilePath>
+            </File>
+            <File>
+              <FileName>yc_timer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_timer.c</FilePath>
+            </File>
+            <File>
+              <FileName>yc_qspi.lib</FileName>
+              <FileType>4</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_qspi.lib</FilePath>
+            </File>
+            <File>
+              <FileName>yc_bt.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_bt.c</FilePath>
+            </File>
+            <File>
+              <FileName>yc_otp.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_otp.c</FilePath>
+            </File>
+            <File>
+              <FileName>yc_ipc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_ipc.c</FilePath>
+            </File>
+            <File>
+              <FileName>yc_lpm.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_lpm.c</FilePath>
+            </File>
+            <File>
+              <FileName>yc_sysctrl.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_sysctrl.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>
@@ -444,6 +499,61 @@
             </File>
           </Files>
         </Group>
+        <Group>
+          <GroupName>USB</GroupName>
+          <Files>
+            <File>
+              <FileName>usb_core.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_usb\libraries\harward_Der\usb_core.c</FilePath>
+            </File>
+            <File>
+              <FileName>Usb_dcd.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_usb\libraries\harward_Der\Usb_dcd.c</FilePath>
+            </File>
+            <File>
+              <FileName>Usb_dcd_init.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_usb\libraries\harward_Der\Usb_dcd_init.c</FilePath>
+            </File>
+            <File>
+              <FileName>usbd_core.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_usb\libraries\SCPU_USB_Device_Library\core\usbd_core.c</FilePath>
+            </File>
+            <File>
+              <FileName>usbd_ioreq.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_usb\libraries\SCPU_USB_Device_Library\core\usbd_ioreq.c</FilePath>
+            </File>
+            <File>
+              <FileName>usbd_req.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_usb\libraries\SCPU_USB_Device_Library\core\usbd_req.c</FilePath>
+            </File>
+            <File>
+              <FileName>usb_main.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_usb\scpu_usb_hid_Device_Demo\usb_main.c</FilePath>
+            </File>
+            <File>
+              <FileName>usbd_desc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_usb\scpu_usb_hid_Device_Demo\usbd_desc.c</FilePath>
+            </File>
+            <File>
+              <FileName>usbd_usr.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_usb\scpu_usb_hid_Device_Demo\usbd_usr.c</FilePath>
+            </File>
+            <File>
+              <FileName>usbd_hid_core.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_usb\libraries\SCPU_USB_Device_Library\class\HID\usbd_hid_core.c</FilePath>
+            </File>
+          </Files>
+        </Group>
       </Groups>
     </Target>
   </Targets>
Index: Boot/user/main.c
===================================================================
--- /YC3121_demo/ModuleDemo/updata_app/Boot/user/main.c	(revision 793)
+++ /YC3121_demo/ModuleDemo/updata_app/Boot/user/main.c	(working copy)
@@ -1,6 +1,6 @@
 /**
   ******************************************************************************
-  * @file    3121Demo\ModuleDemo\UART\UART_TX_Sendbuf\user\main.c 
+  * @file    3121Demo\ModuleDemo\UART\UART_TX_Sendbuf\user\main.c
   * @author  Yichip Application Team
   * @version V1.0.0
   * @date    15-July-2019
@@ -10,12 +10,12 @@
   *
   * COPYRIGHT 2019 Yichip Microelectronics
   *
-  * The purpose of this firmware is to provide guidance to customers engaged in 
-	* programming work to guide them smoothly to product development, 
+  * The purpose of this firmware is to provide guidance to customers engaged in
+	* programming work to guide them smoothly to product development,
 	* so as to save their time.
 	*
-	* Therefore, Yichip microelectronics shall not be responsible for any direct, 
-	* indirect or consequential damages caused by any content of this gu jiang 
+	* Therefore, Yichip microelectronics shall not be responsible for any direct,
+	* indirect or consequential damages caused by any content of this gu jiang
 	* and/or contained in this code used by the customer in its products.
   *
   ******************************************************************************
@@ -25,41 +25,31 @@
 #include "yc3121.h"
 #include "yc_gpio.h"
 #include "yc_uart.h"
+#include "yc_ipc.h"
+#include "usb_main.h"
+#include "halUSB.h"
+#include "yc_qspi.h"
+#include "yc_encflash_bulk.h"
+#include "ota_ble.h"
+#include "yc_bt.h"
 #include "yc_systick.h"
+#include "yc_qspi.h"
+#include "otausb.h"
+#include "board_config.h"
 
 /* Private typedef -----------------------------------------------------------*/
 /* Private define ------------------------------------------------------------*/
-#define uartBaud 115200
 
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 /* Private function prototypes -----------------------------------------------*/
 void UART_Configuration(void);
-void UART_Sendbuf_test(void);
-extern void start_app(void);
-
 
-char cmd[2]={0,0};
-void UART0_IRQHandler(void)
-{
-	MyPrintf("\nboot UART0_IRQHandler");
-	while(UART_IsRXFIFONotEmpty(UART0))
-	{
-		cmd[0] = cmd[1];
-		cmd[1] = UART_ReceiveData(UART0); 
-		MyPrintf("\r%02x ",cmd[1]);
-	}
-
-}
+extern void start_app(void);
+uint8_t  rx_buffer_boot[32] = {0};
+extern _Bool  bBacktoAppFlag;
 
-void SYSTICK_IRQHandler(void)
-{
-	 static uint32_t times = 0;
-	 if((times++)%1000 == 0)
-	 {
-			MyPrintf("\n boot SYSTICK_IRQHandler");
-	 }
-}
+uint32_t APPWRITEADDR = 0x1020000;
 /**
   * @brief  Main program
   * @param  None
@@ -67,22 +57,55 @@
   */
 int main(void)
 {
-	UART_Configuration();
-	UART_Sendbuf_test();
-
-  MyPrintf("boot UART TX Sendbuf Demo !\n\n");
-	UART_SetRxITNum(UART0,1);
-	UART_SetITTimeout(UART0,10);
-	enable_intr(INTR_UART0);
-	SysTick_Config(48000);
-	while (1)
-	{
-		if('U' == cmd[0] && 'P' == cmd[1])
-		{
-			MyPrintf("\nJUMP to app");
-			start_app();                   
-		}
-	}
+    UART_Configuration();
+    MyPrintf("YC3121 OTA BOOT Demo\n");
+    enc_read_flash(0x1000120, rx_buffer_boot, 32);
+    delay_ms(20);
+    if ((rx_buffer_boot[0] == 0xAA) && (rx_buffer_boot[1] == 0x55) && (rx_buffer_boot[2] == 0xAA) && (rx_buffer_boot[3] == 0x55))
+    {
+        /*USB OTA 0xAA55AA55*/
+        IpcInit();
+
+        enc_write_flash_bulk_init();
+
+        enc_earse_flash_app_area(APPWRITEADDR, 320 * 1024);
+
+        MyPrintf("USB HID OTA Demo !\n\n");
+
+        halUsbInit(USB_MODE_HID);
+
+        while (1)
+        {
+            Cmd_check();
+            BackToApp(bBacktoAppFlag);
+        }
+    }
+    else if ((rx_buffer_boot[0] == 0xA5) && (rx_buffer_boot[1] == 0x5A) && (rx_buffer_boot[2] == 0xA5) && (rx_buffer_boot[3] == 0x5A))
+    {
+        /*BT OTA 0xA55AA55A*/
+        enc_write_flash_bulk_init();
+        enc_earse_flash_app_area(APPWRITEADDR, 320 * 1024);
+        MyPrintf("BT OTA Demo !\n\n");
+        BleInit();
+        while (1)
+        {
+            BT_Progress();
+            Ble_Cmd_check();
+            if (BleOtaUpdateStatus())
+            {
+                disable_intr(INTR_BT);
+                MyPrintf("Run App\n");
+                delay_ms(10);
+                enc_erase_flash_32byte(0x1000120);
+                start_app();
+            }
+
+        }
+    }
+    else
+    {
+        start_app();
+    }
 }
 
 /**
@@ -92,40 +115,27 @@
   */
 void UART_Configuration(void)
 {
-	UART_InitTypeDef UART_InitStruct;
+    UART_InitTypeDef UART_InitStruct;
 
-	/* Configure serial ports 0 RX and TX for IO. */
-	GPIO_Config(GPIOA, GPIO_Pin_1, GPCFG_UART0_TXD);
-	GPIO_Config(GPIOA, GPIO_Pin_0, GPCFG_UART0_RXD);
-
-	/* USARTx configured as follow:
-  - BaudRate = 115200 baud  
-  - Word Length = 8 Bits
-  - Stop Bit = 1 Stop Bit
-  - Parity = No Parity
-  - Hardware flow control disabled (RTS and CTS signals)
-  - Receive and transmit enabled
-  */
-	UART_InitStruct.BaudRate = uartBaud;			//Configure serial port baud rate, the baud rate defaults to 128000.
-	UART_InitStruct.DataBits = Databits_8b;
-	UART_InitStruct.StopBits = StopBits_1;
-	UART_InitStruct.Parity = Parity_None;
-	UART_InitStruct.FlowCtrl = FlowCtrl_None;
-	UART_InitStruct.Mode = Mode_duplex;
-	
-	UART_Init(UART0, &UART_InitStruct);
-}
-
-/**
-  * @brief  Serial port 0 string data send test function.
-  * @param  None
-  * @retval None
-  */
-void UART_Sendbuf_test(void)
-{
-	uint8_t buf[] = {"\rThis is serial port 0 string data send test program!\n"};
-	
-	UART_SendBuf(UART0, buf, sizeof(buf)-1);
+    /* Configure serial ports 0 RX and TX for IO. */
+    GPIO_Config(UART0_TX_PORT, UART0_TX_PIN, GPCFG_UART0_TXD);
+    GPIO_Config(UART0_RX_PORT, UART0_RX_PIN, GPCFG_UART0_RXD);
+
+    /* USARTx configured as follow:
+    - BaudRate = 115200 baud
+    - Word Length = 8 Bits
+    - Stop Bit = 1 Stop Bit
+    - Parity = No Parity
+    - Hardware flow control disabled (RTS and CTS signals)
+    - Receive and transmit enabled
+    */
+    UART_InitStruct.BaudRate = UARTBAUD;			//Configure serial port baud rate, the baud rate defaults to 128000.
+    UART_InitStruct.DataBits = Databits_8b;
+    UART_InitStruct.StopBits = StopBits_1;
+    UART_InitStruct.Parity = Parity_None;
+    UART_InitStruct.FlowCtrl = FlowCtrl_None;
+    UART_InitStruct.Mode = Mode_duplex;
+    UART_Init(UART0, &UART_InitStruct);
 }
 
-/************************ (C) COPYRIGHT Yichip Microelectronics *****END OF FILE****/
\ No newline at end of file
+/************************ (C) COPYRIGHT Yichip Microelectronics *****END OF FILE****/
Index: app/prj/MDK/YC3121_Keil.uvprojx
===================================================================
--- /YC3121_demo/ModuleDemo/updata_app/app/prj/MDK/YC3121_Keil.uvprojx	(revision 793)
+++ /YC3121_demo/ModuleDemo/updata_app/app/prj/MDK/YC3121_Keil.uvprojx	(working copy)
@@ -405,7 +405,7 @@
             <File>
               <FileName>bt_code.c</FileName>
               <FileType>1</FileType>
-              <FilePath>..\..\user\bt_code.c</FilePath>
+              <FilePath>..\..\..\..\..\Librarier\core\bt_code.c</FilePath>
             </File>
           </Files>
         </Group>
@@ -422,6 +422,21 @@
               <FileType>1</FileType>
               <FilePath>..\..\..\..\..\Librarier\sdk\yc_uart.c</FilePath>
             </File>
+            <File>
+              <FileName>yc_encflash_bulk.lib</FileName>
+              <FileType>4</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_encflash_bulk.lib</FilePath>
+            </File>
+            <File>
+              <FileName>yc_qspi.lib</FileName>
+              <FileType>4</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_qspi.lib</FilePath>
+            </File>
+            <File>
+              <FileName>yc_otp.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\..\Librarier\sdk\yc_otp.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>
Index: app/user/main.c
===================================================================
--- /YC3121_demo/ModuleDemo/updata_app/app/user/main.c	(revision 793)
+++ /YC3121_demo/ModuleDemo/updata_app/app/user/main.c	(working copy)
@@ -1,6 +1,6 @@
 /**
   ******************************************************************************
-  * @file    3121Demo\ModuleDemo\UART\UART_TX_Sendbuf\user\main.c 
+  * @file    3121Demo\ModuleDemo\UART\UART_TX_Sendbuf\user\main.c
   * @author  Yichip Application Team
   * @version V1.0.0
   * @date    15-July-2019
@@ -10,12 +10,12 @@
   *
   * COPYRIGHT 2019 Yichip Microelectronics
   *
-  * The purpose of this firmware is to provide guidance to customers engaged in 
-	* programming work to guide them smoothly to product development, 
+  * The purpose of this firmware is to provide guidance to customers engaged in
+	* programming work to guide them smoothly to product development,
 	* so as to save their time.
 	*
-	* Therefore, Yichip microelectronics shall not be responsible for any direct, 
-	* indirect or consequential damages caused by any content of this gu jiang 
+	* Therefore, Yichip microelectronics shall not be responsible for any direct,
+	* indirect or consequential damages caused by any content of this gu jiang
 	* and/or contained in this code used by the customer in its products.
   *
   ******************************************************************************
@@ -25,56 +25,75 @@
 #include "yc3121.h"
 #include "..\sdk\yc_gpio.h"
 #include "..\sdk\yc_uart.h"
+#include "yc_qspi.h"
+#include "yc_encflash_bulk.h"
+#include "board_config.h"
 
 /* Private typedef -----------------------------------------------------------*/
 /* Private define ------------------------------------------------------------*/
-#define uartBaud 115200
+
 
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 /* Private function prototypes -----------------------------------------------*/
 void UART_Configuration(void);
-void UART_Sendbuf_test(void);
-
-
-void UART0_IRQHandler(void)
-{
-	MyPrintf("\napp UART0_IRQHandler");
-	while(UART_IsRXFIFONotEmpty(UART0))
-	{
-		MyPrintf("\r%02x ",UART_ReceiveData(UART0));
-	}
-
-}
-
-void SYSTICK_IRQHandler(void)
-{
-	 static uint32_t times = 0;
-	 if((times++)%1000 == 0)
-	 {
-			MyPrintf("\n app SYSTICK_IRQHandler");
-	 }
-}
 /**
   * @brief  Main program
   * @param  None
   * @retval None
   */
+
+uint8_t tx_buffer_boot[32] = {0};
+
 int main(void)
 {
 	UART_Configuration();
-	UART_Sendbuf_test();
-
-  MyPrintf("app UART TX Sendbuf Demo !\n\n");
-	UART_SetRxITNum(UART0,1);
-	UART_SetITTimeout(UART0,10);
-	enable_intr(INTR_UART0);
+	MyPrintf("YC3121 OTA APP Demo\n");
+	MyPrintf("/*************************/\n");
+	MyPrintf("Please input 'B' or 'U'\n");
+	MyPrintf("B: BLE OTA Updata\n");
+	MyPrintf("U: USB HID OTA Updata\n");
+    MyPrintf("/************************/\n");
+	uint8_t uartretval;
 	while (1)
 	{
-		
+        if(UART_IsRXFIFONotEmpty(UART0))
+        {
+            uartretval = UART_ReceiveData(UART0);
+            if(uartretval == 'U')
+            {
+                MyPrintf("This is USB OTA Update Init\n");
+                enc_erase_flash_32byte(0x1000120);
+                tx_buffer_boot[0] = 0xAA;
+                tx_buffer_boot[1] = 0x55;
+                tx_buffer_boot[2] = 0xAA;
+                tx_buffer_boot[3] = 0x55;
+
+                for (int i = 4; i < 32; i++)
+                {
+                    tx_buffer_boot[i] = 0xFF;
+                }
+                enc_write_flash(0x1000120, tx_buffer_boot, 32);
+                soft_reset();
+            }
+            else if(uartretval == 'B')
+            {
+                MyPrintf("This is BLE OTA Update Init\n");
+                enc_erase_flash_32byte(0x1000120);
+                tx_buffer_boot[0] = 0xA5;
+                tx_buffer_boot[1] = 0x5A;
+                tx_buffer_boot[2] = 0xA5;
+                tx_buffer_boot[3] = 0x5A;
+                for (int i = 4; i < 32; i++)
+                {
+                    tx_buffer_boot[i] = 0xFF;
+                }
+                enc_write_flash(0x1000120, tx_buffer_boot, 32);
+                soft_reset();
+            }
+        }
 	}
 }
-
 /**
   * @brief  Serial port 0 initialization function.
   * @param  None
@@ -85,37 +104,25 @@
 	UART_InitTypeDef UART_InitStruct;
 
 	/* Configure serial ports 0 RX and TX for IO. */
-	GPIO_Config(GPIOA, GPIO_Pin_1, GPCFG_UART0_TXD);
-	GPIO_Config(GPIOA, GPIO_Pin_0, GPCFG_UART0_RXD);
+	GPIO_Config(UART0_TX_PORT, UART0_TX_PIN, GPCFG_UART0_TXD);
+	GPIO_Config(UART0_RX_PORT, UART0_RX_PIN, GPCFG_UART0_RXD);
 
 	/* USARTx configured as follow:
-  - BaudRate = 115200 baud  
-  - Word Length = 8 Bits
-  - Stop Bit = 1 Stop Bit
-  - Parity = No Parity
-  - Hardware flow control disabled (RTS and CTS signals)
-  - Receive and transmit enabled
-  */
-	UART_InitStruct.BaudRate = uartBaud;			//Configure serial port baud rate, the baud rate defaults to 128000.
+     - BaudRate = 115200 baud
+     - Word Length = 8 Bits
+     - Stop Bit = 1 Stop Bit
+     - Parity = No Parity
+     - Hardware flow control disabled (RTS and CTS signals)
+     - Receive and transmit enabled
+    */
+	UART_InitStruct.BaudRate = UARTBAUD;			//Configure serial port baud rate, the baud rate defaults to 128000.
 	UART_InitStruct.DataBits = Databits_8b;
 	UART_InitStruct.StopBits = StopBits_1;
 	UART_InitStruct.Parity = Parity_None;
 	UART_InitStruct.FlowCtrl = FlowCtrl_None;
 	UART_InitStruct.Mode = Mode_duplex;
-	
-	UART_Init(UART0, &UART_InitStruct);
-}
 
-/**
-  * @brief  Serial port 0 string data send test function.
-  * @param  None
-  * @retval None
-  */
-void UART_Sendbuf_test(void)
-{
-	uint8_t buf[] = {"\rThis is serial port 0 string data send test program!\n"};
-	
-	UART_SendBuf(UART0, buf, sizeof(buf)-1);
+	UART_Init(UART0, &UART_InitStruct);
 }
 
 /************************ (C) COPYRIGHT Yichip Microelectronics *****END OF FILE****/
\ No newline at end of file
