usart.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /**
  2. ******************************************************************************
  3. * File Name : USART.h
  4. * Description : This file provides code for the configuration
  5. * of the USART instances.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __usart_H
  21. #define __usart_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "main.h"
  27. /* USER CODE BEGIN Includes */
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <stdarg.h>
  31. #include "usbd_cdc_if.h"
  32. /* USER CODE END Includes */
  33. extern UART_HandleTypeDef huart4;
  34. extern UART_HandleTypeDef huart5;
  35. #ifdef FUNC_ENABLE_USART1_RFID
  36. extern UART_HandleTypeDef huart1;
  37. #endif
  38. extern UART_HandleTypeDef huart2;
  39. extern UART_HandleTypeDef huart3;
  40. extern UART_HandleTypeDef huart6;
  41. /* USER CODE BEGIN Private defines */
  42. #ifdef FUNC_ENABLE_USART1_RFID
  43. #define RFID_USART huart1
  44. #endif
  45. #define METER_USART huart4
  46. #define IAP_USART huart3
  47. #define BLE_USART huart5
  48. #ifdef FUNC_RS485_SLAVE
  49. #define RS485_USART huart2
  50. #endif
  51. #define WIFI_USART huart5
  52. #define DEBUG_USART huart6
  53. #define UART_BUFFER_SIZE ((uint32_t)2048)
  54. #define TX_TIMEOUT ((uint32_t)0x010)
  55. #define RX_TIMEOUT ((uint32_t)0xFFFFFFFF)
  56. #ifdef FUNC_DEBUG_CONSOLE
  57. #define UART_DEBUG_BUFFER_SIZE ((uint32_t)64)
  58. #endif
  59. /*
  60. UART protocol constant declare
  61. */
  62. #define PROTOCOL_HEAD 0xaa
  63. #ifdef FUNC_RS485_SLAVE
  64. //Internal Module Communication Protocol / 2.2 Slave Address
  65. //0x01 Aux. power module Aux. power module in DC EVSE system
  66. //0x02 Fan control module System fan control module in DC EVSE system
  67. //0x03 Relay control module Output relay control module in DC EVSE system
  68. //0x04 IO Extend module IO extend module in DC EVSE system
  69. //0x05 AC mainboard module AC mainboard module in DC EVSE system (*)
  70. //0x06 LED control module LED control module in DC EVSE system
  71. //0x07 Relay RC_1 module Output relay module in 360KW Power Cabinet
  72. //0x08 Relay RC_2 module Output relay module in 360KW Power Cabinet
  73. //0x09 Relay control module Output relay module in 360KW Dispenser
  74. //0xFF Broadcast Don¡¦t need to address module or broadcast usage
  75. //#define PROTOCOL_ADDR 0x05
  76. #define PROTOCOL_ADDR 0xff
  77. #define PROTOCOL_ADDR_AC_MAINBOARD 0x05
  78. #else
  79. #define PROTOCOL_ADDR 0xff // 0x01:AUX PWR 0x02: FAN BD 0x03:RLY BD 0xff:Any
  80. #endif //FUNC_RS485_SLAVE
  81. #define PROTOCOL_ADDR_BROADCAST 0xff
  82. #define PROTOCOL_MESSAGE_QUERY_FW_VER 0x01
  83. #define PROTOCOL_MESSAGE_QUERY_HW_VER 0x02
  84. #define PROTOCOL_MESSAGE_QUERY_PRESENT_INPUT_VOLTAGE 0x03
  85. #define PROTOCOL_MESSAGE_QUERY_PRESENT_OUTPUT_VOLTAGE 0x04
  86. #define PROTOCOL_MESSAGE_QUERY_FAN_SPEED 0x05
  87. #define PROTOCOL_MESSAGE_QUERY_TEMPERATURE 0x06
  88. #define PROTOCOL_MESSAGE_QUERY_AUX_POWER_VOLTAGE 0x07
  89. #define PROTOCOL_MESSAGE_QUERY_RELAY_OUTPUT_STATUS 0x08
  90. #define PROTOCOL_MESSAGE_QUERY_GFD_ADC_VALUE 0x09
  91. #define PROTOCOL_MESSAGE_QUERY_INPUT_GPIO_STATUS 0x0A
  92. #define PROTOCOL_MESSAGE_QUERY_ALARM_LOG 0x22
  93. #define PROTOCOL_MESSAGE_QUERY_SN 0x23
  94. #define PROTOCOL_MESSAGE_QUERY_MODEL_NAME 0x24
  95. #define PROTOCOL_MESSAGE_QUERY_PARAMETER 0x25
  96. #define PROTOCOL_MESSAGE_QUERY_RTC 0x26
  97. #define PROTOCOL_MESSAGE_QUERY_PRESENT_OUTPUT_CURRENT 0x27
  98. //edward 2019_08_27
  99. #define PROTOCOL_MESSAGE_QUERY_EVSE_STATE 0x28
  100. #define PROTOCOL_MESSAGE_QUERY_EVSE_ALARM 0x29
  101. #define PROTOCOL_MESSAGE_QUERY_BLE_STATE 0x2A
  102. #define PROTOCOL_MESSAGE_QUERY_BLE_LOGIC_CENTRAL_ID 0x2B
  103. #define PROTOCOL_MESSAGE_QUERY_POWER_CONSUME 0x2C
  104. #define PROTOCOL_MESSAGE_QUERY_GUN_PLUGIN_TIMES 0x2D
  105. #define PROTOCOL_MESSAGE_QUERY_EVSE_AUTH_MODE 0x2E
  106. #define PROTOCOL_MESSAGE_QUERY_PRESENT_LEAK_CURRENT 0x2F
  107. #ifdef FUNC_METER_IC_ADE7858A
  108. #define PROTOCOL_MESSAGE_QUERY_METER_IC_MEAS_PARAMETER 0x35 //Get Meter IC measurement parameters
  109. #define PROTOCOL_MESSAGE_QUERY_METER_IC_CALI_PARAMETER 0x36 //Get Meter IC correction parameters
  110. #ifdef FUNC_METER_IC_HISTORY_IMCP_CMD
  111. #define PROTOCOL_MESSAGE_QUERY_METER_IC_CALI_HISTORY 0x37 //Get Meter IC calibration history record
  112. #endif
  113. #endif //FUNC_METER_IC_ADE7858A
  114. #ifdef FUNC_PTB_METER_WM3M4C
  115. #define PROTOCOL_MESSAGE_QUERY_PTB_METER_WM3M4C 0x39
  116. #endif
  117. #ifdef FUNC_EKM_OMNIMETER
  118. #define PROTOCOL_MESSAGE_QUERY_EKM_OMNIMETER 0x3D
  119. #endif
  120. #ifdef FUNC_WARNING_CODE
  121. #define PROTOCOL_MESSAGE_QUERY_EVSE_WARNING 0x41
  122. #endif
  123. #ifdef FUNC_CSU_PUBLIC_KEY_OPERATION
  124. #define PROTOCOL_MESSAGE_QUERY_EVSE_PUBLIC_KEY 0x43
  125. #endif
  126. #define PROTOCOL_MESSAGE_CONFIG_FAN_SPEED 0x81
  127. #define PROTOCOL_MESSAGE_CONFIG_SN 0x82
  128. #define PROTOCOL_MESSAGE_CONFIG_MODEL_NAME 0x83
  129. #define PROTOCOL_MESSAGE_CONFIG_PARAMETER 0x84
  130. #define PROTOCOL_MESSAGE_CONFIG_RELAY_OUTPUT 0x85
  131. #define PROTOCOL_MESSAGE_CONFIG_GPIO_OUTPUT 0x86
  132. #define PROTOCOL_MESSAGE_CONFIG_RTC 0x87
  133. #define PROTOCOL_MESSAGE_CONFIG_LED_ACTION_ALARM 0x88
  134. #define PROTOCOL_MESSAGE_CONFIG_MAX_CURRENT_PWM_DUTY 0x89
  135. #define PROTOCOL_MESSAGE_CONFIG_LEGACY_REQUEST 0x8A
  136. #define PROTOCOL_MESSAGE_CONFIG_MCU_RESET 0x8C
  137. #define PROTOCOL_MESSAGE_CONFIG_BREATHE_LED_TIMING 0x8D
  138. #define PROTOCOL_MESSAGE_CONFIG_LED_BRIGHTNESS 0x8E
  139. #define PROTOCOL_MESSAGE_CONFIG_EVSE_AUTH_MODE 0x8F
  140. #define PROTOCOL_MESSAGE_CONFIG_ERASE_MEMORY 0x94
  141. #define PROTOCOL_MESSAGE_CONFIG_AUX_POWER_SW 0x95
  142. #ifdef FUNC_METER_IC_ADE7858A
  143. #define PROTOCOL_MESSAGE_CONFIG_METER_IC_CALI_PARAMETER 0x96 //Set Meter IC correction parameters
  144. #endif
  145. #ifdef FUNC_PTB_METER_WM3M4C
  146. #define PROTOCOL_MESSAGE_CONFIG_PTB_METER_WM3M4C 0x97
  147. #endif
  148. #ifdef FUNC_CSU_SIGN_IN_VERIFY
  149. #define PROTOCOL_MESSAGE_CONFIG_CSU_SIGN_IN_VERIFY 0x9B
  150. #endif
  151. #ifdef FUNC_AW48_NET_LED
  152. #define PROTOCOL_MESSAGE_CONFIG_LED_ACTION_CONNECTIVITY_STATUS 0x9C
  153. #endif
  154. #ifdef FUNC_CSU_PUBLIC_KEY_OPERATION
  155. #define PROTOCOL_MESSAGE_CONFIG_EVSE_PUBLIC_KEY 0x9E
  156. #endif
  157. #ifdef FUNC_RESET_CONNECTOR_PLUGIN_TIMES
  158. #define PROTOCOL_MESSAGE_CONFIG_RESET_CONNECTOR_PLUGIN_TIMES 0xA0
  159. #endif
  160. #define PROTOCOL_MESSAGE_UPGRADE_START 0xe0
  161. #define PROTOCOL_MESSAGE_UPGRADE_ABOARD 0xe1
  162. #define PROTOCOL_MESSAGE_UPGRADE_TRANS 0xe2
  163. #define PROTOCOL_MESSAGE_UPGRADE_STOP 0xe3
  164. #define INPUT_L1_AC_VOLTAGE 0x01
  165. #define INPUT_L2_AC_VOLTAGE 0x02
  166. #define INPUT_L3_AC_VOLTAGE 0x03
  167. #define OUTPUT_L1_CURRENT 0x11
  168. #define OUTPUT_L2_CURRENT 0x12
  169. #define OUTPUT_L3_CURRENT 0x13
  170. #define LEAK_CURRENT 0x21
  171. #define GROUND_FAULT_VOLTAGE 0x31
  172. //#define ERROR_RESTORE_POINT 0xFE //Hao: Not Used
  173. //#define ERROR_TIGGER_POINT 0xFF //Hao: Not Used
  174. #define SETTING_LEGACY_REQUEST 0x01
  175. /*
  176. RFID module protocol constant declare
  177. */
  178. #define RFID_CMD_AUTO_DETECT 0x1D
  179. #define RFID_CMD_LED 0x14
  180. #define RFID_CMD_REQUEST_SN_14443A 0x20
  181. #define RFID_CMD_REQUEST_SN_14443B 0x60
  182. #define RFID_CMD_REQUEST_SN_FELICA 0x2f
  183. #define RFID_CMD_BLOCK_READ 0x21
  184. #define RFID_CMD_BLOCK_WRITE 0x22
  185. #define RFID_CMD_HALT_14443A 0x28
  186. #define RFID_CMD_HALT_14443B 0x62
  187. #define BLE_INIT_DELAY 10
  188. #define BLE_CMD_SET_RESTORE 0x00
  189. #define BLE_CMD_SET_DTR 0x01
  190. #define BLE_CMD_SET_DSR 0x02
  191. #define BLE_CMD_SET_PAIRING_MODE 0x03
  192. #define BLE_CMD_SET_SECURITY_MODE 0x04
  193. #define BLE_CMD_SET_SECURITY_TYPE 0x05
  194. #define BLE_CMD_SET_DISCOVERABILITY 0x06
  195. #define BLE_CMD_SET_CONNECTABILITY 0x07
  196. #define BLE_CMD_SET_ROLE 0x08
  197. #define BLE_CMD_SET_DATA_MODE 0x09
  198. #define BLE_CMD_SET_NAME 0x0a
  199. #define BLE_CMD_SET_MAX_POWER 0x0b
  200. #define BLE_CMD_SET_MIN_INTERVAL 0x0c
  201. #define BLE_CMD_SET_MAX_INTERVAL 0x0d
  202. #define BLE_CMD_SET_TX_PHY 0x0e
  203. #define BLE_CMD_SET_RX_PHY 0x0f
  204. #define BLE_CMD_SET_DISCONNECT_DEVICE 0x10
  205. #define BLE_CMD_GET_ADDR 0x11
  206. #define BLE_PROTOCOL_MESSAGE_SIGN_IN 0x01
  207. #define BLE_PROTOCOL_MESSAGE_PUK_REG 0x02
  208. #define BLE_PROTOCOL_MESSAGE_PIN_GET 0x03
  209. #define BLE_PROTOCOL_MESSAGE_PIN_RENEW 0x04
  210. #define BLE_PROTOCOL_MESSAGE_PIN_DEL 0x05
  211. #define BLE_PROTOCOL_MESSAGE_PIN_QUERY 0x06
  212. #define BLE_PROTOCOL_MESSAGE_CHARGING_START 0x11
  213. #define BLE_PROTOCOL_MESSAGE_CHARGING_STOP 0x12
  214. #define BLE_PROTOCOL_MESSAGE_STATUS_QUERY 0x13
  215. #define BLE_PROTOCOL_MESSAGE_RESERVATION 0x14
  216. #define BLE_PROTOCOL_MESSAGE_TIME_QUERY 0x21
  217. #define BLE_PROTOCOL_MESSAGE_TIME_CONFIG 0x22
  218. #define BLE_PROTOCOL_MESSAGE_LED_QUERY 0x23
  219. #define BLE_PROTOCOL_MESSAGE_LED_CONFIG 0x24
  220. #define BLE_PROTOCOL_MESSAGE_CURRENT_LIMIT_QUERY 0x25
  221. #define BLE_PROTOCOL_MESSAGE_CURRENT_LIMIT_CONFIG 0x26
  222. #define BLE_PROTOCOL_MESSAGE_FIRMWARE_VERSION_QUERY 0x31
  223. #define BLE_PROTOCOL_MESSAGE_FIRMWARE_UPDATE_REQ 0x32
  224. #define BLE_PROTOCOL_MESSAGE_FIRMWARE_TRANS_REQ 0x33
  225. #define BLE_PROTOCOL_MESSAGE_FIRMWARE_END_REQ 0x34
  226. #define WIFI_INIT_DELAY 10
  227. #define WIFI_CMD_SET_RESTORE 0x00
  228. #define WIFI_CMD_SET_DTR 0x01
  229. #define WIFI_CMD_SET_DSR 0x02
  230. #define WIFI_CMD_GET_ADDR 0x03
  231. #define WIFI_CMD_SET_SSID 0x04
  232. #define WIFI_CMD_SET_CHANNEL 0x05
  233. #define WIFI_CMD_SET_SECURITY_MODE 0x06
  234. #define WIFI_CMD_SET_PASSWORD 0x07
  235. #define WIFI_CMD_SET_DHCPSERVER 0x08
  236. #define WIFI_CMD_SET_TCPSETVER_CONFIG 0x09
  237. #define WIFI_CMD_SET_AP_ACTIVE 0x0a
  238. #define WIFI_CMD_SET_DATA_MODE 0x0b
  239. #define WIFI_PROTOCOL_MESSAGE_SIGN_IN 0x01
  240. #define WIFI_PROTOCOL_MESSAGE_PUK_REG 0x02
  241. #define WIFI_PROTOCOL_MESSAGE_PIN_GET 0x03
  242. #define WIFI_PROTOCOL_MESSAGE_PIN_RENEW 0x04
  243. #define WIFI_PROTOCOL_MESSAGE_PIN_DEL 0x05
  244. #define WIFI_PROTOCOL_MESSAGE_PIN_QUERY 0x06
  245. #define WIFI_PROTOCOL_MESSAGE_CHARGING_START 0x11
  246. #define WIFI_PROTOCOL_MESSAGE_CHARGING_STOP 0x12
  247. #define WIFI_PROTOCOL_MESSAGE_STATUS_QUERY 0x13
  248. #define WIFI_PROTOCOL_MESSAGE_RESERVATION 0x14
  249. #define WIFI_PROTOCOL_MESSAGE_TIME_QUERY 0x21
  250. #define WIFI_PROTOCOL_MESSAGE_TIME_CONFIG 0x22
  251. #define WIFI_PROTOCOL_MESSAGE_LED_QUERY 0x23
  252. #define WIFI_PROTOCOL_MESSAGE_LED_CONFIG 0x24
  253. #define WIFI_PROTOCOL_MESSAGE_CURRENT_LIMIT_QUERY 0x25
  254. #define WIFI_PROTOCOL_MESSAGE_CURRENT_LIMIT_CONFIG 0x26
  255. #define WIFI_PROTOCOL_MESSAGE_FIRMWARE_VERSION_QUERY 0x31
  256. #define WIFI_PROTOCOL_MESSAGE_FIRMWARE_UPDATE_REQ 0x32
  257. #define WIFI_PROTOCOL_MESSAGE_FIRMWARE_TRANS_REQ 0x33
  258. #define WIFI_PROTOCOL_MESSAGE_FIRMWARE_END_REQ 0x34
  259. /* USER CODE END Private defines */
  260. void MX_UART4_Init(void);
  261. void MX_UART5_Init(void);
  262. #ifdef FUNC_ENABLE_USART1_RFID
  263. void MX_USART1_UART_Init(void);
  264. #endif
  265. #ifdef FUNC_ENABLE_USART1_LIN_LL_LIB
  266. void MX_USART1_UART_Init(void);
  267. #endif
  268. void MX_USART2_UART_Init(void);
  269. void MX_USART3_UART_Init(void);
  270. void MX_USART6_UART_Init(void);
  271. /* USER CODE BEGIN Prototypes */
  272. void serialPutString(uint8_t *fmt, ...);
  273. extern uint8_t UART_RFID_rx_buffer[UART_BUFFER_SIZE>>4];
  274. extern uint8_t UART_RFID_recv_end_flag;
  275. extern uint16_t UART_RFID_rx_len;
  276. #ifdef FUNC_RS485_SLAVE
  277. //huart2
  278. extern uint8_t UART_RS485_rx_buffer[UART_BUFFER_SIZE];
  279. extern uint8_t UART_RS485_recv_end_flag;
  280. extern uint16_t UART_RS485_rx_len;
  281. #endif
  282. //huart3
  283. extern uint8_t UART_IAP_rx_buffer[UART_BUFFER_SIZE];
  284. extern uint8_t UART_IAP_recv_end_flag;
  285. extern uint16_t UART_IAP_rx_len;
  286. extern uint8_t isUSB_CDC_IAP;
  287. #ifdef FUNC_DEBUG_CONSOLE
  288. extern uint8_t UART_DEBUG_rx_buffer[UART_DEBUG_BUFFER_SIZE];
  289. extern uint8_t UART_DEBUG_recv_end_flag;
  290. extern uint16_t UART_DEBUG_rx_len;
  291. #endif
  292. extern uint8_t UART_BLE_rx_buffer[UART_BUFFER_SIZE];
  293. extern uint8_t UART_BLE_recv_end_flag;
  294. extern uint16_t UART_BLE_rx_len;
  295. extern uint32_t UART_BLE_Receive_Tick;
  296. extern uint8_t UART_BLE_Init_OK;
  297. extern uint8_t UART_WIFI_rx_buffer[UART_BUFFER_SIZE];
  298. extern uint8_t UART_WIFI_recv_end_flag;
  299. extern uint16_t UART_WIFI_rx_len;
  300. extern uint32_t UART_WIFI_Receive_Tick;
  301. extern uint8_t UART_WIFI_Init_OK;
  302. extern uint8_t UART_METER_rx_buffer[UART_BUFFER_SIZE];
  303. extern uint8_t UART_METER_recv_end_flag;
  304. extern uint16_t UART_METER_rx_len;
  305. extern uint32_t UART_METER_Receive_Tick;
  306. extern uint8_t UART_METER_Init_OK;
  307. extern char *BLE_CMD[];
  308. extern char *WIFI_CMD[];
  309. #ifdef RECODE_METER_PRO380
  310. void MX_UART4_Init_For_Meter_PRO380(void);
  311. #endif
  312. #ifdef FUNC_PTB_METER_WM3M4C
  313. void MX_UART4_Init_For_PTB_Meter_WM3M4C(void);
  314. #endif
  315. #ifdef FUNC_EKM_OMNIMETER
  316. void MX_UART4_Init_For_EKM_Omnimeter(void);
  317. #endif
  318. /* USER CODE END Prototypes */
  319. #ifdef __cplusplus
  320. }
  321. #endif
  322. #endif /*__ usart_H */
  323. /**
  324. * @}
  325. */
  326. /**
  327. * @}
  328. */
  329. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/