main.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /* USER CODE END Includes */
  33. /* Exported types ------------------------------------------------------------*/
  34. /* USER CODE BEGIN ET */
  35. /* USER CODE END ET */
  36. /* Exported constants --------------------------------------------------------*/
  37. /* USER CODE BEGIN EC */
  38. /* USER CODE END EC */
  39. /* Exported macro ------------------------------------------------------------*/
  40. /* USER CODE BEGIN EM */
  41. #define Rx_Max 1024
  42. #define Version_sys 0x23051700
  43. extern uint8_t receive_buffer[30]; // 定义接收缓存,这里假设最多可以接收100个字节
  44. extern uint8_t flag ;
  45. extern uint16_t Adc2_CalibrationValue ;
  46. extern uint16_t Adc3_CalibrationValue ;
  47. extern uint8_t gpioaStatus ;
  48. extern uint8_t gpiobStatus ;
  49. extern uint8_t Rx_Flag;
  50. extern uint16_t Rx_Len;
  51. extern uint8_t Rx_Buf[Rx_Max];
  52. /* USER CODE END EM */
  53. /* Exported functions prototypes ---------------------------------------------*/
  54. void Error_Handler(void);
  55. /* USER CODE BEGIN EFP */
  56. uint16_t read_flash_16(uint32_t flash_address);
  57. void read_new_address_from_flash(uint32_t flash_address);
  58. void erase_flash(uint32_t ADDR_FLASH);
  59. void write_flash_address(uint8_t* rx_buffer);
  60. void write_flash_PbStatus(uint8_t* rx_buffer);
  61. void write_flash_autoAdc(uint32_t ADDR_FLASH);
  62. void CoverADC(uint32_t ADDR);
  63. void write_flash_Baudrate(uint8_t* rx_buffer);
  64. /* USER CODE END EFP */
  65. /* Private defines -----------------------------------------------------------*/
  66. /* USER CODE BEGIN Private defines */
  67. #define FILTER_LENGTH 10
  68. #define DEBOUNCE_COUNT 10
  69. #define Modbus 1
  70. #define ADDR_FLASH_PAGE_61 ((uint32_t)0x0800A000) // Flash扇区61的起始地址 address
  71. #define ADDR_FLASH_PAGE_62 ((uint32_t)0x0800C000) // Flash扇区62的起始地址 PbStatus
  72. #define ADDR_FLASH_PAGE_63 ((uint32_t)0x0800E000) // Flash扇区63的起始地址 Baudrate
  73. #define ADDR_FLASH_PAGE_64 ((uint32_t)0x0800EC00) // Flash扇区64的起始地址 Adc2_Calibration 4-20mA
  74. #define ADDR_FLASH_PAGE_65 ((uint32_t)0x0800F000) // Flash扇区65的起始地址 Adc3_Calibration 4-20mA
  75. #define ADDR_FLASH_PAGE_66 ((uint32_t)0x0800FC00) // Flash扇区66的起始地址
  76. /* USER CODE END Private defines */
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /* __MAIN_H */