main.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.h
  5. * @brief : Header for main.c file.
  6. * This file contains the common defines of the application.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2023 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef __MAIN_H
  22. #define __MAIN_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "stm32f1xx_hal.h"
  28. /* Private includes ----------------------------------------------------------*/
  29. /* USER CODE BEGIN Includes */
  30. #include "stdio.h"
  31. #include "string.h"
  32. #include "iap.h"
  33. /* USER CODE END Includes */
  34. /* Exported types ------------------------------------------------------------*/
  35. /* USER CODE BEGIN ET */
  36. extern void __set_FAULTMASK(uint32_t faultMask);
  37. #define iap_ 1
  38. #if 1
  39. #define IR_ROM1 0x8000000
  40. #else
  41. #define IR_ROM1 0x8020000
  42. #endif
  43. /* USER CODE END ET */
  44. /* Exported constants --------------------------------------------------------*/
  45. /* USER CODE BEGIN EC */
  46. /* USER CODE END EC */
  47. /* Exported macro ------------------------------------------------------------*/
  48. /* USER CODE BEGIN EM */
  49. extern uint16_t initial_address;
  50. extern int nameLength;
  51. extern int sizeLength ;
  52. extern int md5Length;
  53. extern uint32_t System_version;
  54. // ¶¨ÒåÊý×é´óС
  55. #define ARRAY_SIZE 1024
  56. /* USER CODE END EM */
  57. /* Exported functions prototypes ---------------------------------------------*/
  58. void Error_Handler(void);
  59. /* USER CODE BEGIN EFP */
  60. uint16_t read_flash_16(uint32_t addr);
  61. void read_new_address(uint32_t addr);
  62. void Write_Information(uint32_t addr, uint8_t* rx_buffer, uint8_t buffer_index);
  63. void ModBus(void);
  64. void receive_modbus_9_1(uint16_t addr, uint8_t funcode, uint16_t startaddr, uint16_t reg, uint8_t byteNum);
  65. void receive_modbus_4(uint16_t addr, uint8_t funcode);
  66. void clear_buf(void);
  67. void erase_flash(uint32_t ADDR_FLASH);
  68. uint32_t read_flash_32(uint32_t addr);
  69. /* USER CODE END EFP */
  70. /* Private defines -----------------------------------------------------------*/
  71. #define adc0_Pin GPIO_PIN_0
  72. #define adc0_GPIO_Port GPIOC
  73. #define adc1_Pin GPIO_PIN_1
  74. #define adc1_GPIO_Port GPIOC
  75. #define adc2_Pin GPIO_PIN_2
  76. #define adc2_GPIO_Port GPIOC
  77. #define input0_Pin GPIO_PIN_0
  78. #define input0_GPIO_Port GPIOA
  79. #define input1_Pin GPIO_PIN_1
  80. #define input1_GPIO_Port GPIOA
  81. #define input2_Pin GPIO_PIN_2
  82. #define input2_GPIO_Port GPIOA
  83. #define input3_Pin GPIO_PIN_3
  84. #define input3_GPIO_Port GPIOA
  85. #define input4_Pin GPIO_PIN_4
  86. #define input4_GPIO_Port GPIOA
  87. #define input5_Pin GPIO_PIN_5
  88. #define input5_GPIO_Port GPIOA
  89. #define input6_Pin GPIO_PIN_6
  90. #define input6_GPIO_Port GPIOA
  91. #define input7_Pin GPIO_PIN_7
  92. #define input7_GPIO_Port GPIOA
  93. #define kmg_Pin GPIO_PIN_0
  94. #define kmg_GPIO_Port GPIOB
  95. #define usart3_tx_Pin GPIO_PIN_10
  96. #define usart3_tx_GPIO_Port GPIOB
  97. #define usart3_rx_Pin GPIO_PIN_11
  98. #define usart3_rx_GPIO_Port GPIOB
  99. #define led_Pin GPIO_PIN_12
  100. #define led_GPIO_Port GPIOB
  101. #define usart1_tx_Pin GPIO_PIN_9
  102. #define usart1_tx_GPIO_Port GPIOA
  103. #define usart1_rx_Pin GPIO_PIN_10
  104. #define usart1_rx_GPIO_Port GPIOA
  105. #define output0_Pin GPIO_PIN_3
  106. #define output0_GPIO_Port GPIOB
  107. #define output1_Pin GPIO_PIN_4
  108. #define output1_GPIO_Port GPIOB
  109. #define output2_Pin GPIO_PIN_5
  110. #define output2_GPIO_Port GPIOB
  111. #define output3_Pin GPIO_PIN_6
  112. #define output3_GPIO_Port GPIOB
  113. /* USER CODE BEGIN Private defines */
  114. #define FILTER_LENGTH 10
  115. #define DEBOUNCE_COUNT 10
  116. #define Modbus 1
  117. #define addr_FLASH_ADDR ((uint32_t)0x8070000) // address
  118. #define pbstatus_FLASH_ADDR ((uint32_t)0x8070800) // PbStatus
  119. #define baudrate_FLASH_ADDR ((uint32_t)0x8071000) // Baudrate
  120. #define ADC1_FLASH_ADDR ((uint32_t)0x8071800) // Adc2_Calibration 4-20mA
  121. #define ADC2_FLASH_ADDR ((uint32_t)0x8072000) // Adc3_Calibration 4-20mA
  122. #define SYSVERSION_ADDR ((uint32_t)0x8072800)
  123. #define CURaddr_PACKAGE_ADDR ((uint32_t)0x8073000)
  124. #define VERSION_ADDR ((uint32_t)0x8074000)
  125. #define LENGTH_ADDR ((uint32_t)0x8074800)
  126. #define MD5_ADDR ((uint32_t)0x8075000)
  127. /* USER CODE END Private defines */
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif /* __MAIN_H */