iap.h 2.3 KB

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