iap.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef __IAP_H
  2. #define __IAP_H
  3. #include "global.h"
  4. #include <stm32f4xx.h>
  5. #define IAP_FLASH_UP_LEN 0x8080000
  6. #define IAP_FLASH_UP_ADDR 0X8080004
  7. #define IAP_RUN_START_SECTOR 0x8010000
  8. #define IAP_DOWN_BEGIN_ADDR 0x8080000 // iap代码下载起始地址
  9. #define IAP_BACKUP_SECTOR1 10
  10. #define IAP_BACKUP_SECTOR2 11
  11. #define IAP_PC_BEGINE_FRAME 0x18CFD0EF
  12. #define IAP_PC_DATA_FRAME 0x18CED0EF
  13. #define IAP_MCU_BIGEN_FRAME 0x18CFEFD0
  14. #define IAP_MCU_DATA_FRAME 0x18CEEFD0
  15. #define IAP_CMD_CHECK 0x01 // 请求校验
  16. #define IAP_CMD_DOWNLOAD 0x02 // 数据下载
  17. #define IAP_CMD_DOWNLOAD_END 0x03 // 下载代码完成
  18. #define IAP_CMD_READ 0x04 // 读取下发帧内容
  19. #define IAP_CMD_DOWNLOAD_SUC 0X05 // 下载成功
  20. #define IAP_BUF_SIZE 0x40
  21. #define MAX_PACK_NUM 0x17
  22. #define MCU_DOWNLOAD_SUCC 0x01
  23. #define MCU_DOWNLOAD_FAIL 0x02
  24. #define IAP_UP_BEGINNING 0x37377373
  25. #define IAP_UP_SUCCESS 0x59599595
  26. #define IAP_UP_FAIL 0x6A6AA6A6
  27. // FLASH 扇区的起始地址
  28. #define ADDR_FLASH_SECTOR_0 ((u32)0x08000000) // 扇区0起始地址, 16 Kbytes
  29. #define ADDR_FLASH_SECTOR_1 ((u32)0x08004000) // 扇区1起始地址, 16 Kbytes
  30. #define ADDR_FLASH_SECTOR_2 ((u32)0x08008000) // 扇区2起始地址, 16 Kbytes
  31. #define ADDR_FLASH_SECTOR_3 ((u32)0x0800C000) // 扇区3起始地址, 16 Kbytes
  32. #define ADDR_FLASH_SECTOR_4 ((u32)0x08010000) // 扇区4起始地址, 64 Kbytes
  33. #define ADDR_FLASH_SECTOR_5 ((u32)0x08020000) // 扇区5起始地址, 128 Kbytes
  34. #define ADDR_FLASH_SECTOR_6 ((u32)0x08040000) // 扇区6起始地址, 128 Kbytes
  35. #define ADDR_FLASH_SECTOR_7 ((u32)0x08060000) // 扇区7起始地址, 128 Kbytes
  36. #define ADDR_FLASH_SECTOR_8 ((u32)0x08080000) // 扇区8起始地址, 128 Kbytes
  37. #define ADDR_FLASH_SECTOR_9 ((u32)0x080A0000) // 扇区9起始地址, 128 Kbytes
  38. #define ADDR_FLASH_SECTOR_10 ((u32)0x080C0000) // 扇区10起始地址,128 Kbytes
  39. #define ADDR_FLASH_SECTOR_11 ((u32)0x080E0000) // 扇区11起始地址,128 Kbytes
  40. #define ADDR_FLASH_SECTOR_END ((u32)0x080FFFFF)
  41. typedef enum
  42. {
  43. DISCONNECT = 0,
  44. HANDSHAKE,
  45. PROGRAMING,
  46. PROGRAMFinish,
  47. } workmode;
  48. typedef union
  49. {
  50. u8 value[4];
  51. u32 cmd;
  52. } IAP_Union;
  53. void iap_process(CanData_TypeDef *rx_msg);
  54. u8 flash_up_is_ok(void);
  55. void iap_from_flash(void);
  56. #endif