main.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "at32f403a_407.h"
  2. #include "at32f403a_407_board.h"
  3. #include "at32f403a_407_clock.h"
  4. #include "common_config.h"
  5. #include "FreeRTOS.h"
  6. #include "task.h"
  7. #include "queue.h"
  8. #include "semphr.h"
  9. #include "usb_eth.h"
  10. #include "mux.h"
  11. #include "misc.h"
  12. #include "spi_common.h"
  13. #include "extended_sram.h"
  14. #include "modbus.h"
  15. #include "common_gpio.h"
  16. #include "io.h"
  17. #include "input.h"
  18. #include "wdt.h"
  19. #include <stdio.h>
  20. #include <stdbool.h>
  21. #include <string.h>
  22. //
  23. void jump_to_app(uint32_t address);
  24. void (*pftarget)(void);
  25. int main()
  26. {
  27. nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
  28. system_clock_config();
  29. delay_init();
  30. uart_print_init(115200);
  31. printf("IAP starting...\r\n");
  32. printf("Go to main FW\r\n");
  33. jump_to_app(0x08021000);
  34. #if 0
  35. // Check if valid stack address (RAM address) then jump to user application
  36. if (((*(__IO uint32_t*)USER_FLASH_FIRST_PAGE_ADDRESS) & 0x2FFD0000) == 0x20000000) {
  37. jump_to_app(0x08021000);
  38. } else {
  39. // Флеш пустая, нечего загружать, висим в аварийном режиме
  40. printf("\n\rFW empty. Started bootloader\n\r");
  41. }
  42. #endif
  43. while (1) {}
  44. }
  45. //
  46. void jump_to_app(uint32_t address)
  47. {
  48. uint32_t stkptr, jumpaddr;
  49. stkptr = *(uint32_t *)address;
  50. jumpaddr = *(uint32_t *)(address + sizeof(uint32_t));
  51. __set_MSP(stkptr);
  52. pftarget = (void (*) (void))jumpaddr;
  53. pftarget();
  54. }