main.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "gd32f10x.h"
  2. #include "main.h"
  3. #include "delay.h"
  4. #include "fmc.h"
  5. #include "ota_message.h"
  6. #include "usart.h"
  7. #include "ec800m.h"
  8. #include "boot.h"
  9. #include "w25q32.h"
  10. void task_fwdgt_reload(void);
  11. OTA_STRUCT UpDataA; //A区更新用到的结构体
  12. void my_test(void) //往UFS写好文件
  13. {
  14. static OTA_MESSAGE ota_message = {0};
  15. char str[100];
  16. char string[] = "{\"otaflag\":1,\"XmodemByte\":102400}";
  17. uint32_t i = 0;
  18. ota_message.otaflag = 1;
  19. ota_message.XmodemByte = 200 * 1024;
  20. memcpy(str,string,strlen(string)+1);
  21. char OPEN_FILE[] = "AT+QFOPEN=\"otaMSG.txt\",0\r\n";
  22. char OPEN_NEW_FILE[] = "AT+QFOPEN=\"otaMSG.txt\",1\r\n";
  23. char WRITEFILE[] = "AT+QFWRITE=1,33\r\n";
  24. char CLOSEFILE[] = "AT+QFCLOSE=1\r\n";
  25. char LOADFILE[] = "AT+QFDWL=otaMSG.txt\r\n";
  26. // GD32_EraseFlash(420,1);
  27. // GD32_WriteFlash(0x08069000,(uint32_t *)&ota_message,sizeof(OTA_MESSAGE));
  28. // i = *(uint32_t*)(0x08069000);
  29. // i = *(uint32_t*)(0x08069004);
  30. EC800MSendCmd(OPEN_NEW_FILE,strlen(OPEN_NEW_FILE));
  31. memset(str,0,sizeof(str));
  32. strcpy(str,(char *)&UART0_RX_BUF);
  33. i = WaitResponse("QFOPEN:", 2000);
  34. EC800MSendCmd(WRITEFILE,strlen(WRITEFILE));
  35. memset(str,0,sizeof(str));
  36. strcpy(str,(char *)&UART0_RX_BUF);
  37. i = WaitResponse("CONNECT", 2000);
  38. EC800MSendCmd(string,strlen(string));
  39. memset(str,0,sizeof(str));
  40. strcpy(str,(char *)&UART0_RX_BUF);
  41. i = WaitResponse("QFWRITE", 2000);
  42. EC800MSendCmd(CLOSEFILE,strlen(CLOSEFILE));
  43. memset(str,0,sizeof(str));
  44. strcpy(str,(char *)&UART0_RX_BUF);
  45. i = WaitResponse("OK", 2000);
  46. free(str);
  47. Delay_Ms(10);
  48. }
  49. int main(void)
  50. {
  51. Delay_Init();
  52. /* 弃用w25q32改用EC800存储ota文件 */
  53. // W25Q32_Init();
  54. nvic_config();
  55. gd_com_init(COM_EC800);
  56. dma_config();
  57. gd_EC800M_pin_init();
  58. EC800MPwoerOn();
  59. EC800MWaitReady();
  60. OTA_MESSAGE *ota_data;
  61. task_fwdgt_reload();
  62. my_test();
  63. if(load_ota_message_config_params()==0)
  64. {
  65. while(1){Delay_Ms(1000);};
  66. //ota事件产生了,进入Bootloader分支
  67. ota_data=get_config_params();
  68. BootLoader_Brance(ota_data->XmodemByte);
  69. }
  70. //没有OTA事件产生跳转A区
  71. else
  72. {
  73. while(1){Delay_Ms(1000);};
  74. LOAD_A(GD32_A_SADDR);
  75. }
  76. while(1)
  77. {
  78. }
  79. }
  80. void task_fwdgt_reload(void)
  81. {
  82. /* uncock fwdgt write protect*/
  83. fwdgt_write_enable();
  84. /* feed fwdgt */
  85. fwdgt_counter_reload();
  86. }