stm32sprog.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * srm32sprog.h
  3. *
  4. * Created on: Apr 12, 2016
  5. * Author: jesstr
  6. */
  7. #ifndef SRM32SPROG_H_
  8. #define SRM32SPROG_H_
  9. #include "stm32f4xx_usart.h"
  10. #include "gpio_io.h"
  11. #include "serial.h"
  12. #include "sys/types.h"
  13. #define MAX_CONNECT_RETRIES 3
  14. #define DEFAULT_BAUD 57600
  15. #define MAX_BLOCK_SIZE 256
  16. static const uint8_t ACK = 0x79;
  17. typedef enum {
  18. CMD_GET_VERSION = 0x00,
  19. CMD_GET_READ_STATUS = 0x01,
  20. CMD_GET_ID = 0x02,
  21. CMD_READ_MEM = 0x11,
  22. CMD_GO = 0x21,
  23. CMD_WRITE_MEM = 0x31,
  24. CMD_ERASE = 0x43,
  25. CMD_EXTENDED_ERASE = 0x44,
  26. CMD_WRITE_PROTECT = 0x63,
  27. CMD_WRITE_UNPROTECT = 0x73,
  28. CMD_READ_PROTECT = 0x82,
  29. CMD_READ_UNPROTECT = 0x92
  30. } Command;
  31. #define NUM_COMMANDS_KNOWN 12
  32. enum {
  33. ID_LOW_DENSITY = 0x0412,
  34. ID_MED_DENSITY = 0x0410,
  35. ID_HI_DENSITY = 0x0414,
  36. ID_CONNECTIVITY = 0x0418,
  37. ID_VALUE = 0x0420,
  38. ID_HI_DENSITY_VALUE = 0x0428,
  39. ID_XL_DENSITY = 0x0430,
  40. ID_MED_DENSITY_ULTRA_LOW_POWER = 0x0436,
  41. ID_HI_DENSITY_ULTRA_LOW_POWER = 0x0416
  42. };
  43. typedef struct {
  44. uint8_t bootloaderVer;
  45. bool commands[NUM_COMMANDS_KNOWN];
  46. uint32_t flashBeginAddr;
  47. uint32_t flashEndAddr;
  48. int flashPagesPerSector;
  49. size_t flashPageSize;
  50. useconds_t eraseDelay;
  51. useconds_t writeDelay;
  52. } DeviceParameters;
  53. int stm32sprog_test(void);
  54. void usleep(uint32_t us);
  55. void stmRebootForFlash(void);
  56. void stmReboot(void);
  57. uint32_t stmCalcFlashCrc(void (* periodic_handler)(uint8_t));
  58. uint32_t stmReadFlashCrc(void);
  59. bool stmConnect(void);
  60. bool stmGetDevParams(void);
  61. bool stmEraseFlash(void);
  62. bool stmEraseFW(void);
  63. bool stmWriteBlock(uint32_t addr, const uint8_t *buff, size_t size);
  64. void stmProg( uint32_t* addr, uint8_t * ptr, uint32_t len);
  65. #endif /* SRM32SPROG_H_ */