main.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "gd32f10x.h"
  2. #include "main.h"
  3. #include "delay.h"
  4. #include "fmc.h"
  5. #include "ota_message.h"
  6. #include "boot.h"
  7. #include "w25q32.h"
  8. void task_fwdgt_reload(void);
  9. OTA_STRUCT UpDataA; //A区更新用到的结构体
  10. void my_test(void)
  11. {
  12. static OTA_MESSAGE ota_message = {0};
  13. uint32_t i = 0;
  14. ota_message.otaflag = 1;
  15. ota_message.XmodemByte = 200 * 1024;
  16. //往地址0x08070000写OTA_MESSAGE结构体
  17. // GD32_WriteFlash(OTA_EVENT_START_ADDR,&ota_message,sizeof(OTA_MESSAGE));
  18. fmc_state_enum state;
  19. // state = fmc_word_program((uint32_t)0x08070000,(uint32_t)(1));
  20. // fmc_flag_clear(FMC_FLAG_BANK0_END | FMC_FLAG_BANK0_WPERR | FMC_FLAG_BANK0_PGERR);
  21. // state = fmc_word_program((uint32_t)0x08070004,(uint32_t)(100 * 1024));
  22. // fmc_flag_clear(FMC_FLAG_BANK0_END | FMC_FLAG_BANK0_WPERR | FMC_FLAG_BANK0_PGERR);
  23. // FLASH_WriteNotErase(0x08070000,&ota_message,sizeof(OTA_MESSAGE)/2);
  24. // FLASH_ErasePage(0x08069000,1);
  25. GD32_EraseFlash(210,1);
  26. FLASH_Write(0x08069000,&ota_message,sizeof(OTA_MESSAGE)/2);
  27. i = *(uint32_t*)(0x08069000);
  28. i = *(uint32_t*)(0x08069004);
  29. // FLASH_Write(0x08069008,&ota_message,sizeof(OTA_MESSAGE)/2);
  30. Delay_Ms(100);
  31. }
  32. int main(void)
  33. {
  34. Delay_Init();
  35. W25Q32_Init(); //弃用w25q32改用fmc存储
  36. OTA_MESSAGE *ota_data;
  37. task_fwdgt_reload();
  38. // my_test();
  39. if(load_ota_message_config_params()==0)
  40. {
  41. //ota事件产生了,进入Bootloader分支
  42. ota_data=get_config_params();
  43. BootLoader_Brance(ota_data->XmodemByte);
  44. }
  45. //没有OTA事件产生跳转A区
  46. else
  47. {
  48. LOAD_A(GD32_A_SADDR);
  49. }
  50. while(1)
  51. {
  52. }
  53. }
  54. void task_fwdgt_reload(void)
  55. {
  56. /* uncock fwdgt write protect*/
  57. fwdgt_write_enable();
  58. /* feed fwdgt */
  59. fwdgt_counter_reload();
  60. }