main.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 = 0;
  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,8\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((uint8_t *)&ota_message,sizeof(OTA_MESSAGE));
  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. //ota事件产生了,进入Bootloader分支
  66. ota_data=get_config_params();
  67. BootLoader_Brance(ota_data->XmodemByte);
  68. }
  69. //没有OTA事件产生跳转A区
  70. else
  71. {
  72. LOAD_A(GD32_A_SADDR);
  73. }
  74. while(1)
  75. {
  76. }
  77. }
  78. void task_fwdgt_reload(void)
  79. {
  80. /* uncock fwdgt write protect*/
  81. fwdgt_write_enable();
  82. /* feed fwdgt */
  83. fwdgt_counter_reload();
  84. }