main.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2024 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. #include "adc.h"
  22. #include "dma.h"
  23. #include "rtc.h"
  24. #include "tim.h"
  25. #include "usart.h"
  26. #include "gpio.h"
  27. /* Private includes ----------------------------------------------------------*/
  28. /* USER CODE BEGIN Includes */
  29. #include "stdlib.h"
  30. #include "stdio.h"
  31. #include "string.h"
  32. #include "lora_comm.h"
  33. /* USER CODE END Includes */
  34. /* Private typedef -----------------------------------------------------------*/
  35. /* USER CODE BEGIN PTD */
  36. /* USER CODE END PTD */
  37. /* Private define ------------------------------------------------------------*/
  38. /* USER CODE BEGIN PD */
  39. /* USER CODE END PD */
  40. /* Private macro -------------------------------------------------------------*/
  41. /* USER CODE BEGIN PM */
  42. #define ENABLE_RTC_ALARM 0
  43. #define ENABLE_SRAND_DELAY 0
  44. #define ENABLE_TIMER_COUNT 0
  45. #define ENABLE_TIMER_CALLBACK 0
  46. #define DEV_MAC "01:02:03:04"
  47. #define MAC_ADDR_CHAR_1 'A'
  48. #define MAC_ADDR_CHAR_2 'D'
  49. //RF TX packet
  50. //$ABlora1,1E#,(地址AB:0xF1234)
  51. /* USER CODE END PM */
  52. /* Private variables ---------------------------------------------------------*/
  53. /* USER CODE BEGIN PV */
  54. #define UART_RXBUF_LEN 64
  55. #define UART_RXBUF_REV_LEN 24
  56. uint8_t RX_recv_dma_buf[UART_RXBUF_LEN] = {0};
  57. uint8_t RX_recv_buf[UART_RXBUF_LEN] = {0};
  58. volatile uint16_t event_bits = 0;
  59. volatile uint8_t rx_gateway_reps_flag = 0;
  60. #define MAC_ADDR_LEN 2
  61. #define RF_RXBUF_LEN 14
  62. char MAC_ADDR[MAC_ADDR_LEN] = {'A', 'B'};
  63. uint8_t RF_TX_Buf[RF_RXBUF_LEN] = {'$', 0x12, 0x34, 'L', 'O', 'R', 'A', '7', ',', '1', 'F', '#', 0x0D, 0x0A};
  64. uint8_t key_type = VALUE_SOS;
  65. uint8_t key_value = KEY_EVENT_1;
  66. uint8_t send_cnt = RX_RE_SEND_CNT;
  67. uint8_t standby_flag = 0;
  68. uart_comm uart1;
  69. extern DMA_HandleTypeDef hdma_usart1_rx;
  70. /* USER CODE END PV */
  71. /* Private function prototypes -----------------------------------------------*/
  72. void SystemClock_Config(void);
  73. /* USER CODE BEGIN PFP */
  74. /* USER CODE END PFP */
  75. /* Private user code ---------------------------------------------------------*/
  76. /* USER CODE BEGIN 0 */
  77. /*
  78. * The following is UART interpent handle functions.
  79. */
  80. void uart_error_restore(UART_HandleTypeDef *huart)
  81. {
  82. if (huart->ErrorCode)
  83. {
  84. __HAL_UART_CLEAR_PEFLAG(huart);
  85. __HAL_UART_CLEAR_FEFLAG(huart);
  86. __HAL_UART_CLEAR_NEFLAG(huart);
  87. __HAL_UART_CLEAR_OREFLAG(huart);
  88. HAL_UART_DeInit(huart);
  89. if (huart == &huart1)
  90. {
  91. MX_USART1_UART_Init();
  92. }
  93. }
  94. }
  95. /*
  96. * Todo: optimize huart variable the darkest sense in a interrupt handle.
  97. * xfli
  98. */
  99. void HAL_UART_RxIdleCallback(UART_HandleTypeDef *huart)
  100. {
  101. uint32_t temp;
  102. uint8_t ret;
  103. uart_error_restore(huart);
  104. if (RESET != __HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE))
  105. {
  106. if (huart == uart1.uart)
  107. {
  108. __HAL_UART_CLEAR_IDLEFLAG(huart);
  109. temp = __HAL_DMA_GET_COUNTER(uart1.dma);
  110. temp = uart1.rxtotal - temp;
  111. uart1.rxcnt = temp - uart1.rxoff;
  112. if (uart1.rxcnt)
  113. {
  114. temp = uart1.rxtotal - uart1.rxoff;
  115. if (temp >= uart1.rxcnt)
  116. {
  117. memcpy(RX_recv_buf, uart1.rxbuf+uart1.rxoff, uart1.rxcnt);
  118. }
  119. else
  120. {
  121. memcpy(RX_recv_buf, uart1.rxbuf+uart1.rxoff, temp);
  122. memcpy(RX_recv_buf+temp, uart1.rxbuf, uart1.rxcnt - temp);
  123. }
  124. uart1.rxoff += uart1.rxcnt;
  125. if(RX_recv_buf[16] == 0x0D && RX_recv_buf[17] == 0x0A)
  126. {
  127. //len = sizeof(RX_recv_buf);
  128. if(RX_recv_buf[0] == '$' && RX_recv_buf[15] == '#')
  129. {
  130. //To check if the received data is sended to current device.
  131. if(RX_recv_buf[1] == MAC_ADDR[0] && RX_recv_buf[2] == MAC_ADDR[1])
  132. {
  133. //char str[8];
  134. //memcpy(str, RX_recv_buf+3, 7);
  135. //Todo parse received data and if is valid.!!!
  136. //ret = strcmp(str, "CALLLED");
  137. //if(ret == 0)
  138. {
  139. rx_gateway_reps_flag = 1;
  140. // key_type = VALUE_SOS;
  141. //key_value = KEY_EVENT_1;
  142. }
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
  150. #if ENABLE_TIMER_CALLBACK
  151. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  152. {
  153. if(htim != &htim14)
  154. {
  155. printf("Timer is htim14!\r\n");
  156. return;
  157. }
  158. ///Todo needed code process...
  159. return;
  160. }
  161. #endif
  162. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  163. {
  164. // 刚从STOP模式唤醒时钟默认使用内部高速8M时钟,所以需要重新配置时钟)
  165. SystemClock_Config();
  166. // 如果使用了WKUP引脚唤醒则需要清除这个WKUP唤醒标记
  167. __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  168. switch(GPIO_Pin)
  169. {
  170. case EMEGENCY_KEY_Pin:
  171. //printf("WKUP_Pin.\r\n");
  172. break;
  173. case CANCEL_Pin:
  174. //printf("CANCEL_Pin.\r\n");
  175. break;
  176. default:
  177. break;
  178. }
  179. return;
  180. }
  181. void Delay_500ns(uint32_t us)
  182. {
  183. while (us--)
  184. {
  185. __NOP();
  186. __NOP();
  187. __NOP();
  188. __NOP();
  189. __NOP();
  190. __NOP();
  191. __NOP();
  192. __NOP();
  193. __NOP();
  194. __NOP();
  195. __NOP();
  196. __NOP();
  197. __NOP();
  198. __NOP();
  199. __NOP();
  200. __NOP();
  201. }
  202. }
  203. uint32_t srand_delay(void)
  204. {
  205. #define RANDOM_MAX 500 //随机数最大值
  206. #define RANDOM_MIN 50 //随机数最小值
  207. uint32_t random_value = 0;
  208. #if ENABLE_SRAND_DELAY
  209. RTC_DateTypeDef date_info;
  210. RTC_TimeTypeDef time_info;
  211. HAL_RTC_GetTime(&hrtc, &time_info, RTC_FORMAT_BIN);
  212. HAL_RTC_GetDate(&hrtc, &date_info, RTC_FORMAT_BIN);
  213. //printf("当前时间:%2d:%2d:%2d", time_info.Hours, time_info.Minutes, time_info.Seconds);
  214. #if ENABLE_TIMER_COUNT
  215. //HAL_TIM_Base_Start(&htim14);
  216. srand(time_info.Hours+time_info.Minutes+time_info.Seconds+__HAL_TIM_GET_COUNTER(&htim14));//随机数种子设置
  217. #endif
  218. random_value = rand() % (RANDOM_MAX + 1 - RANDOM_MIN) + RANDOM_MIN;//随机数生成
  219. //printf(" 当前随机数为:%d\r\n", random_value);
  220. #endif
  221. return random_value;
  222. }
  223. #if ENABLE_RTC_ALARM
  224. void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
  225. {
  226. uint8_t i;
  227. // STOP模式唤醒后默认时钟主频为内部8M时钟,所以要先初始化时钟配置
  228. SystemClock_Config();
  229. //printf("3s时间到,唤醒!\r\n");
  230. //唤醒后红灯提示报警发生
  231. for(i=0; i<LED_GREEN_FLUSH_COUNT; i++)
  232. {
  233. LED_GREEN_ON();
  234. HAL_Delay(LED_FLUSH_TIME_DELAY);
  235. LED_GREEN_OFF();
  236. HAL_Delay(LED_FLUSH_TIME_DELAY);
  237. }
  238. return;
  239. }
  240. void RTC_AlarmStart(void)
  241. {
  242. RTC_TimeTypeDef tim = {0};
  243. RTC_AlarmTypeDef sAlarm = {0};
  244. // 获取当前时间
  245. //RTC_GetTime(&tim);
  246. HAL_RTC_GetTime(&hrtc, &tim, RTC_FORMAT_BIN);
  247. sAlarm.AlarmTime.Hours = tim.Hours;
  248. sAlarm.AlarmTime.Minutes = tim.Minutes;
  249. sAlarm.AlarmTime.Seconds = tim.Seconds + 60; /* 设置下次闹钟提醒时间是当前时间的3s之后 */
  250. sAlarm.Alarm = RTC_ALARM_A;
  251. // 启动闹钟中断事件
  252. HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN);
  253. }
  254. #endif
  255. void sys_enter_stop_mode(void)
  256. {
  257. // 使能PWR时钟
  258. __HAL_RCC_PWR_CLK_ENABLE();
  259. HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
  260. // 清除唤醒标记
  261. __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  262. // 如果使用WK-UP引脚唤醒那么需要使能
  263. HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
  264. // 进入STOP模式
  265. HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
  266. }
  267. void sys_enter_standby_mode(void)
  268. {
  269. // 使能PWR时钟
  270. __HAL_RCC_PWR_CLK_ENABLE();
  271. HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
  272. // 清除唤醒标记
  273. __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  274. // 如果使用WK-UP引脚唤醒那么需要使能
  275. HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
  276. // 进入待机模式
  277. HAL_PWR_EnterSTANDBYMode();
  278. }
  279. /*
  280. void sys_enter_stop_mode(void)
  281. {
  282. __HAL_RCC_PWR_CLK_ENABLE(); // 使能PWR时钟
  283. __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // 清除唤醒标记
  284. HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); // 进入STOP模式
  285. }
  286. void sys_enter_standby_mode(void)
  287. {
  288. __HAL_RCC_PWR_CLK_ENABLE(); // 使能PWR时钟
  289. __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // 清除唤醒标记
  290. HAL_PWR_EnterSTANDBYMode(); // 进入待机模式
  291. }
  292. */
  293. void uart_comm_init(void)
  294. {
  295. /*Init UART1 RX for ECG DATA CHANNEL*/
  296. uart1.uart = &huart1;
  297. uart1.dma = &hdma_usart1_rx;
  298. uart1.rxbuf = RX_recv_dma_buf;
  299. uart1.rxcnt = 0;
  300. uart1.rxoff = 0;
  301. uart1.rxtotal = UART_RXBUF_LEN;
  302. __HAL_UART_ENABLE_IT(uart1.uart, UART_IT_IDLE);
  303. HAL_UART_Receive_DMA(uart1.uart, uart1.rxbuf, uart1.rxtotal);
  304. }
  305. void RF_send_event(uint8_t key_type, uint8_t key_value, uint8_t send_cnt)
  306. {
  307. uint8_t i;
  308. uint16_t delay;
  309. //uint8_t crc_t = 0;
  310. for(i=0; i<MAC_ADDR_LEN; i++)
  311. {
  312. RF_TX_Buf[i+1] = MAC_ADDR[i];
  313. }
  314. RF_TX_Buf[RF_RXBUF_LEN - 7] = key_type;
  315. RF_TX_Buf[RF_RXBUF_LEN - 5] = key_value;
  316. /*
  317. for(i=1; i<RF_RXBUF_LEN-2; i++)
  318. {
  319. crc_t += RF_RXBUF_LEN[i]
  320. }
  321. */
  322. for(i=0; i<send_cnt; i++)
  323. {
  324. delay = srand_delay();
  325. //HAL_UART_Transmit_DMA(uart1.uart, RF_TX_Buf, RF_RXBUF_LEN);
  326. HAL_UART_Transmit(uart1.uart, RF_TX_Buf, RF_RXBUF_LEN, 100);
  327. HAL_Delay(delay+send_cnt*15);
  328. }
  329. return;
  330. }
  331. uint8_t read_flash_get_MAC(void)
  332. {
  333. uint8_t i, ret = 0;
  334. //get MAC address from flash specical page.
  335. //????
  336. #if 0
  337. for(i=0; i<MAC_ADDR_LEN; i++)
  338. {
  339. MAC_ADDR[i] = read_flash_get_MAC();
  340. }
  341. #else
  342. MAC_ADDR[0] = MAC_ADDR_CHAR_1;
  343. MAC_ADDR[1] = MAC_ADDR_CHAR_2;
  344. #endif
  345. return ret;
  346. }
  347. /* USER CODE END 0 */
  348. /**
  349. * @brief The application entry point.
  350. * @retval int
  351. */
  352. int main(void)
  353. {
  354. /* USER CODE BEGIN 1 */
  355. /* USER CODE END 1 */
  356. /* MCU Configuration--------------------------------------------------------*/
  357. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  358. HAL_Init();
  359. /* USER CODE BEGIN Init */
  360. /* USER CODE END Init */
  361. /* Configure the system clock */
  362. SystemClock_Config();
  363. /* USER CODE BEGIN SysInit */
  364. /* USER CODE END SysInit */
  365. /* Initialize all configured peripherals */
  366. MX_GPIO_Init();
  367. MX_DMA_Init();
  368. MX_ADC_Init();
  369. MX_USART1_UART_Init();
  370. MX_RTC_Init();
  371. MX_TIM14_Init();
  372. /* USER CODE BEGIN 2 */
  373. //printf("Hello word!! I'm main Ctroller board.\r\n");
  374. LED_GREEN_OFF();
  375. LED_RED_OFF();
  376. HAL_Delay(20);
  377. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);
  378. HAL_GPIO_WritePin(GPIOA, CE_Pin|RLED2_Pin|GLED1_Pin, GPIO_PIN_SET);
  379. HAL_GPIO_WritePin(GPIOA, RESET_Pin, GPIO_PIN_RESET);
  380. /*Configure GPIO pin Output Level */
  381. uart_comm_init();
  382. #if ENABLE_TIMER_COUNT
  383. HAL_TIM_Base_Start(&htim14);
  384. #endif
  385. uint8_t i;
  386. key_type = VALUE_SOS;
  387. key_value = KEY_EVENT_1;
  388. send_cnt = 0;
  389. standby_flag = 0;
  390. //printf("second\r\n");
  391. HAL_Delay(LED_FLUSH_TIME_DELAY);
  392. //Todo read the device MAC address from the indicated page in flash and to save.
  393. read_flash_get_MAC();
  394. HAL_Delay(50);
  395. //Todo Set LORA module...
  396. //81 ---开启透传模式
  397. //82 ---关闭透传模式,即 AT 命令模式
  398. set_work_mode(0);
  399. //485125000Hz
  400. //483200000Hz
  401. set_work_freq(1);
  402. //6 ---速率 1868bps
  403. set_rf_rate(6);
  404. //set_rf_tx_power(int index);
  405. HAL_Delay(20);
  406. set_work_mode(1);
  407. HAL_Delay(50);
  408. /* USER CODE END 2 */
  409. /* Infinite loop */
  410. /* USER CODE BEGIN WHILE */
  411. while (1)
  412. {
  413. /* USER CODE END WHILE */
  414. /* USER CODE BEGIN 3 */
  415. //唤醒后红灯提示报警发生
  416. HAL_Delay(800);
  417. LED_RED_ON();
  418. HAL_Delay(100);
  419. LED_RED_OFF();
  420. HAL_Delay(400);
  421. BEEP_ON();
  422. HAL_Delay(200);
  423. BEEP_OFF();
  424. //printf("BEEP_ON.\r\n");
  425. //HAL_Delay(LED_FLUSH_TIME_DELAY);
  426. //Todo read battery volume...
  427. //Send the alarm message by RF channel
  428. send_cnt++;
  429. RF_send_event(key_type, key_value, send_cnt);
  430. if(rx_gateway_reps_flag)
  431. {
  432. rx_gateway_reps_flag = 0;
  433. //To parse data from ... RX_recv_buf
  434. //唤醒后红灯提示报警发生
  435. for(i=0; i<LED_GREEN_FLUSH_COUNT; i++)
  436. {
  437. //LED_GREEN_ON();
  438. HAL_Delay(LED_FLUSH_TIME_DELAY);
  439. //LED_GREEN_OFF();
  440. HAL_Delay(LED_FLUSH_TIME_DELAY);
  441. }
  442. standby_flag = 1;
  443. }
  444. if(standby_flag == 1 || send_cnt >= RX_RE_SEND_CNT)
  445. {
  446. standby_flag = 0;
  447. send_cnt = 0;
  448. //配置下次唤醒的闹钟时间
  449. //HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 5, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
  450. //RTC_AlarmStart();
  451. //sys_enter_stop_mode();
  452. set_work_mode(0);
  453. set_work_mode(5); //TC-037模块进入休眠
  454. HAL_Delay(20);
  455. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
  456. HAL_Delay(20);
  457. sys_enter_standby_mode();
  458. }
  459. }
  460. /* USER CODE END 3 */
  461. }
  462. /**
  463. * @brief System Clock Configuration
  464. * @retval None
  465. */
  466. void SystemClock_Config(void)
  467. {
  468. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  469. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  470. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  471. /** Initializes the RCC Oscillators according to the specified parameters
  472. * in the RCC_OscInitTypeDef structure.
  473. */
  474. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI14|RCC_OSCILLATORTYPE_LSI
  475. |RCC_OSCILLATORTYPE_HSE;
  476. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  477. RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
  478. RCC_OscInitStruct.HSI14CalibrationValue = 16;
  479. RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  480. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  481. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  482. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  483. RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  484. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  485. {
  486. Error_Handler();
  487. }
  488. /** Initializes the CPU, AHB and APB buses clocks
  489. */
  490. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  491. |RCC_CLOCKTYPE_PCLK1;
  492. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  493. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  494. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  495. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  496. {
  497. Error_Handler();
  498. }
  499. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_RTC;
  500. PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
  501. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  502. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  503. {
  504. Error_Handler();
  505. }
  506. }
  507. /* USER CODE BEGIN 4 */
  508. /* USER CODE END 4 */
  509. /**
  510. * @brief This function is executed in case of error occurrence.
  511. * @retval None
  512. */
  513. void Error_Handler(void)
  514. {
  515. /* USER CODE BEGIN Error_Handler_Debug */
  516. /* User can add his own implementation to report the HAL error return state */
  517. __disable_irq();
  518. while (1)
  519. {
  520. }
  521. /* USER CODE END Error_Handler_Debug */
  522. }
  523. #ifdef USE_FULL_ASSERT
  524. /**
  525. * @brief Reports the name of the source file and the source line number
  526. * where the assert_param error has occurred.
  527. * @param file: pointer to the source file name
  528. * @param line: assert_param error line source number
  529. * @retval None
  530. */
  531. void assert_failed(uint8_t *file, uint32_t line)
  532. {
  533. /* USER CODE BEGIN 6 */
  534. /* User can add his own implementation to report the file name and line number,
  535. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  536. /* USER CODE END 6 */
  537. }
  538. #endif /* USE_FULL_ASSERT */