You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. #include "math.h"
  23. #include "stdbool.h"
  24. /* Private includes ----------------------------------------------------------*/
  25. /* USER CODE BEGIN Includes */
  26. /* USER CODE END Includes */
  27. /* Private typedef -----------------------------------------------------------*/
  28. /* USER CODE BEGIN PTD */
  29. /* USER CODE END PTD */
  30. /* Private define ------------------------------------------------------------*/
  31. /* USER CODE BEGIN PD */
  32. /* USER CODE END PD */
  33. /* Private macro -------------------------------------------------------------*/
  34. /* USER CODE BEGIN PM */
  35. /* USER CODE END PM */
  36. /* Private variables ---------------------------------------------------------*/
  37. RTC_HandleTypeDef hrtc;
  38. UART_HandleTypeDef huart2;
  39. RTC_TimeTypeDef sTime;
  40. RTC_DateTypeDef sDate;
  41. RTC_AlarmTypeDef sAlarm;
  42. //Nuernberg coordinates
  43. int latitude_nbg = 49;
  44. int longitude_nbg = 11;
  45. //German UTC time,summer (+2) and winter (+1)
  46. int UTC_DER_sum = 2;
  47. int UTC_DER_win = 1;
  48. bool winterTime = true;
  49. /* USER CODE BEGIN PV */
  50. /* USER CODE END PV */
  51. /* Private function prototypes -----------------------------------------------*/
  52. void SystemClock_Config(void);
  53. static void MX_GPIO_Init(void);
  54. static void MX_USART2_UART_Init(void);
  55. static void MX_RTC_Init(void);
  56. /* USER CODE BEGIN PFP */
  57. /* USER CODE END PFP */
  58. /* Private user code ---------------------------------------------------------*/
  59. /* USER CODE BEGIN 0 */
  60. /*******************************************************************************
  61. * Function Name : deg_to_rad
  62. * Description : converts degrees to radians
  63. * Return : angle in radians
  64. *******************************************************************************/
  65. double deg_to_rad(double deg)
  66. {
  67. double rad = deg*(M_PI/180);
  68. return rad;
  69. }
  70. /*******************************************************************************
  71. * Function Name : rad_to_deg
  72. * Description : converts radians to degrees
  73. * Return : angle in degrees
  74. *******************************************************************************/
  75. double rad_to_deg(double rad)
  76. {
  77. double deg = rad*(180/M_PI);
  78. return deg;
  79. }
  80. /*******************************************************************************
  81. * Function Name : leap_year_check
  82. * Description : checks if year is a leap year
  83. * Return : false: no leap year, true: leap year
  84. *******************************************************************************/
  85. int leap_year_check(int year)
  86. {
  87. if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
  88. {
  89. return true;
  90. }
  91. return false;
  92. }
  93. /*******************************************************************************
  94. * Function Name : calc_day_of_year
  95. * Description : calculates the day of year
  96. * Return : day of year (1.1.. = 1, 2.1.. = 2,...)
  97. * Source : https://overiq.com/c-examples/c-program-to-calculate-the-day-of-year-from-the-date/
  98. *******************************************************************************/
  99. int calc_day_of_year(int day, int mon, int year)
  100. {
  101. int days_in_feb = 28;
  102. int doy = day; //day of year
  103. // check for leap year
  104. bool leap_year = leap_year_check(year);
  105. if(leap_year == true)
  106. {
  107. days_in_feb = 29;
  108. }
  109. switch(mon)
  110. {
  111. case 2:
  112. doy += 31;
  113. break;
  114. case 3:
  115. doy += 31+days_in_feb;
  116. break;
  117. case 4:
  118. doy += days_in_feb+62;
  119. break;
  120. case 5:
  121. doy += days_in_feb+92;
  122. break;
  123. case 6:
  124. doy += days_in_feb+123;
  125. break;
  126. case 7:
  127. doy += days_in_feb+153;
  128. break;
  129. case 8:
  130. doy += days_in_feb+184;
  131. break;
  132. case 9:
  133. doy += days_in_feb+215;
  134. break;
  135. case 10:
  136. doy += days_in_feb+245;
  137. break;
  138. case 11:
  139. doy += days_in_feb+276;
  140. break;
  141. case 12:
  142. doy += days_in_feb+306;
  143. break;
  144. }
  145. return doy;
  146. }
  147. /*******************************************************************************
  148. * Function Name : calc_sunrise_sunset
  149. * Description : calculates the sunrise and sunset time of a specific date
  150. * Source : General Solar Position Calculations, NOAA Global Monitoring Division
  151. *******************************************************************************/
  152. void calc_sunrise_sunset(int date, int month, int year, int sunrise_time[2], int sunset_time[2])
  153. {
  154. double gamma = 0;
  155. bool leap_year;
  156. double eqtime = 0;
  157. double decl = 0;
  158. double decl_deg = 0;
  159. double zenith_sun = 0;
  160. double lat_nbg_rad = 0;
  161. double ha = 0;
  162. double sunrise = 0;
  163. double sunset = 0;
  164. double ha_deg = 0;
  165. int sunrise_h = 0;
  166. int sunset_h = 0;
  167. double sunrise_min = 0;
  168. double sunset_min = 0;
  169. int int_sunrise_min = 0;
  170. int int_sunset_min = 0;
  171. //day of year calculation
  172. int day_of_year = calc_day_of_year(date, month, year);
  173. // fractional year (γ) in radians
  174. // check for leap year
  175. leap_year = leap_year_check(year);
  176. if(leap_year == false)
  177. {
  178. //The back part of the formula was omitted, because there is no difference in the result
  179. gamma = ((2 * M_PI)/365)*(day_of_year - 1);
  180. } else {
  181. //The back part of the formula was omitted, because there is no difference in the result
  182. gamma = ((2 * M_PI)/366)*(day_of_year - 1);
  183. }
  184. //Equation of time in minutes
  185. eqtime = 229.18*(0.000075 + 0.001868*cos(gamma) - 0.032077*sin(gamma) - 0.014615*cos(2*gamma) - 0.040849*sin(2*gamma));
  186. //Solar declination angle in radians
  187. decl = 0.006918 - 0.399912*cos(gamma) + 0.070257*sin(gamma) - 0.006758*cos(2*gamma) + 0.000907*sin(2*gamma) - 0.002697*cos(3*gamma) + 0.00148*sin(3*gamma);
  188. //Solar declination angle in degrees
  189. decl_deg = rad_to_deg(decl);
  190. //Hour angle in degrees, positive number corresponds to sunrise, negative to sunset
  191. //special case of sunrise or sunset, the zenith is set to 90.833Deg
  192. zenith_sun = deg_to_rad(90.833);
  193. //Latitude of Nuernberg in rad
  194. lat_nbg_rad = deg_to_rad(latitude_nbg);
  195. ha = acos((cos(zenith_sun)/(cos(lat_nbg_rad)*cos(decl)))-(tan(lat_nbg_rad)*tan(decl)));
  196. ha_deg = rad_to_deg(ha);
  197. //UTC time of sunrise (or sunset) in minutes
  198. sunrise = (720-4*(longitude_nbg+ha_deg)-eqtime);
  199. sunset = 720-4*(longitude_nbg-ha_deg)-eqtime;
  200. //Convert sunrise (or sunset) UTC time in hours
  201. sunrise = sunrise/60;
  202. sunset = sunset/60;
  203. //Seperate hours and minutes
  204. sunrise_h = floor(sunrise);
  205. sunrise_min = sunrise - sunrise_h;
  206. //Cut off after two decimal places
  207. int_sunrise_min = floor(sunrise_min * 100.0);
  208. if (int_sunrise_min >= 60)
  209. {
  210. sunrise_h = sunrise_h + 1;
  211. int_sunrise_min = int_sunrise_min - 60;
  212. }
  213. sunset_h = floor(sunset);
  214. sunset_min = sunset - sunset_h;
  215. //Cut off after two decimal places
  216. int_sunset_min = floor(sunset_min * 100.0);
  217. if (int_sunset_min >= 60)
  218. {
  219. sunset_h = sunset_h + 1;
  220. int_sunset_min = int_sunset_min - 60;
  221. }
  222. //Add time difference from German time to UTC Time
  223. //Private variable winterTime must be initialized accordingly
  224. if (winterTime)
  225. {
  226. sunrise_h = sunrise_h + UTC_DER_win;
  227. sunset_h = sunset_h + UTC_DER_win;
  228. } else {
  229. sunrise_h = sunrise_h + UTC_DER_sum;
  230. sunset_h = sunset_h + UTC_DER_sum;
  231. }
  232. sunrise_time[0] = sunrise_h;
  233. sunrise_time[1] = int_sunrise_min;
  234. sunset_time[0] = sunset_h;
  235. sunset_time[1] = int_sunset_min;
  236. }
  237. /*******************************************************************************
  238. * Function Name : calc_tomorrows_date
  239. * Description : calculates tomorrow's date
  240. * Source : https://github.com/vyacht/stm32/blob/master/vynmea/rtc.c
  241. *******************************************************************************/
  242. void calc_tomorrows_date(int day, int wday, int month, int year, int DaysInMonth[12], int tomorrows_date[4])
  243. {
  244. bool leap_year;
  245. day++; // next day
  246. wday++; // next weekday
  247. if(wday == 8)
  248. {
  249. wday = 1; // Monday
  250. }
  251. if(day > DaysInMonth[month-1])
  252. { // next month
  253. day = 1;
  254. month++;
  255. }
  256. if(day > 31 && month == 12) // next year
  257. {
  258. day = 1;
  259. month = 1;
  260. year++;
  261. }
  262. tomorrows_date[0] = day;
  263. tomorrows_date[1] = wday;
  264. tomorrows_date[2] = month;
  265. tomorrows_date[3] = year;
  266. }
  267. /*******************************************************************************
  268. * Function Name : set_Alarm
  269. * Description : sets the wake up Alarm
  270. *******************************************************************************/
  271. void set_Alarm(int h, int min, int weekDay)
  272. {
  273. /** Enable the Alarm A*/
  274. sAlarm.AlarmTime.Hours = h;
  275. sAlarm.AlarmTime.Minutes = min;
  276. sAlarm.AlarmTime.Seconds = 0;
  277. sAlarm.AlarmTime.SubSeconds = 0;
  278. sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  279. sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
  280. sAlarm.AlarmMask = RTC_ALARMMASK_NONE; //only by specific time
  281. sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
  282. sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY;
  283. sAlarm.AlarmDateWeekDay = weekDay;
  284. sAlarm.Alarm = RTC_ALARM_A;
  285. if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK)
  286. {
  287. Error_Handler();
  288. }
  289. }
  290. // sending to UART
  291. void transmit_uart(char *string){
  292. uint8_t len = strlen(string);
  293. HAL_UART_Transmit(&huart2, (uint8_t*) string, len, 200);
  294. }
  295. /* USER CODE END 0 */
  296. /**
  297. * @brief The application entry point.
  298. * @retval int
  299. */
  300. int main(void)
  301. {
  302. /* USER CODE BEGIN 1 */
  303. /* USER CODE END 1 */
  304. /* MCU Configuration--------------------------------------------------------*/
  305. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  306. HAL_Init();
  307. /* USER CODE BEGIN Init */
  308. /* USER CODE END Init */
  309. /* Configure the system clock */
  310. SystemClock_Config();
  311. /* USER CODE BEGIN SysInit */
  312. /* USER CODE END SysInit */
  313. /* Initialize all configured peripherals */
  314. MX_GPIO_Init();
  315. MX_USART2_UART_Init();
  316. MX_RTC_Init();
  317. /* USER CODE BEGIN 2 */
  318. int hours = 0;
  319. int minutes = 0;
  320. int seconds = 0;
  321. int weekDay = 0;
  322. int month = 0;
  323. int date = 0;
  324. int year = 0;
  325. int sunrise_h = 0;
  326. int sunset_h = 0;
  327. int int_sunrise_min = 0;
  328. int int_sunset_min = 0;
  329. int sunrise_time[2] = {0};
  330. int sunset_time[2] = {0};
  331. int tomorrows_date[4] = {0};
  332. int DaysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  333. int DaysInMonthLeapYear[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  334. bool leap_year = false;
  335. /* USER CODE END 2 */
  336. /* Infinite loop */
  337. /* USER CODE BEGIN WHILE */
  338. while (1)
  339. {
  340. //Get Time and Date
  341. if (HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN) == HAL_OK)
  342. {
  343. hours = sTime.Hours;
  344. minutes = sTime.Minutes;
  345. seconds = sTime.Seconds;
  346. }
  347. if (HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN) == HAL_OK)
  348. {
  349. weekDay = sDate.WeekDay;
  350. month = sDate.Month;
  351. date = sDate.Date;
  352. year = 2000 + sDate.Year;
  353. }
  354. // check for leap year
  355. leap_year = leap_year_check(year);
  356. if (leap_year)
  357. {
  358. //Calculate tomorrow's date
  359. calc_tomorrows_date(date, weekDay, month, year, DaysInMonthLeapYear, tomorrows_date);
  360. } else {
  361. //Calculate tomorrow's date
  362. calc_tomorrows_date(date, weekDay, month, year, DaysInMonth, tomorrows_date);
  363. }
  364. //Calculate sunrise and sunset time for tomorrow
  365. calc_sunrise_sunset(tomorrows_date[0], tomorrows_date[2], tomorrows_date[3], sunrise_time, sunset_time);
  366. set_Alarm(16, 22, 1);
  367. HAL_Delay(5000);
  368. transmit_uart("Ich gehe schlafen!\r\n");
  369. // Suspend Tick increment to prevent wake up by Systick interrupt
  370. HAL_SuspendTick();
  371. HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); //Interrupt for wake up
  372. HAL_ResumeTick();
  373. transmit_uart("Bin wieder wach!\r\n");
  374. }
  375. /* USER CODE END 3 */
  376. }
  377. /**
  378. * @brief System Clock Configuration
  379. * @retval None
  380. */
  381. void SystemClock_Config(void)
  382. {
  383. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  384. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  385. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  386. /** Configure the main internal regulator output voltage
  387. */
  388. __HAL_RCC_PWR_CLK_ENABLE();
  389. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
  390. /** Initializes the RCC Oscillators according to the specified parameters
  391. * in the RCC_OscInitTypeDef structure.
  392. */
  393. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
  394. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  395. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  396. RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  397. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  398. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  399. RCC_OscInitStruct.PLL.PLLM = 16;
  400. RCC_OscInitStruct.PLL.PLLN = 336;
  401. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  402. RCC_OscInitStruct.PLL.PLLQ = 7;
  403. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  404. {
  405. Error_Handler();
  406. }
  407. /** Initializes the CPU, AHB and APB buses clocks
  408. */
  409. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  410. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  411. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  412. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  413. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  414. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  415. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  416. {
  417. Error_Handler();
  418. }
  419. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  420. PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  421. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  422. {
  423. Error_Handler();
  424. }
  425. }
  426. /**
  427. * @brief RTC Initialization Function
  428. * @param None
  429. * @retval None
  430. */
  431. static void MX_RTC_Init(void)
  432. {
  433. /* USER CODE BEGIN RTC_Init 0 */
  434. /* USER CODE END RTC_Init 0 */
  435. /* USER CODE BEGIN RTC_Init 1 */
  436. /* USER CODE END RTC_Init 1 */
  437. /** Initialize RTC Only
  438. */
  439. hrtc.Instance = RTC;
  440. hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  441. hrtc.Init.AsynchPrediv = 127;
  442. hrtc.Init.SynchPrediv = 255;
  443. hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  444. hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  445. hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  446. if (HAL_RTC_Init(&hrtc) != HAL_OK)
  447. {
  448. Error_Handler();
  449. }
  450. /* USER CODE BEGIN Check_RTC_BKUP */
  451. /* USER CODE END Check_RTC_BKUP */
  452. /** Initialize RTC and set the Time and Date
  453. */
  454. sTime.Hours = 16;
  455. sTime.Minutes = 20;
  456. sTime.Seconds = 30;
  457. sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  458. sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  459. if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
  460. {
  461. Error_Handler();
  462. }
  463. sDate.WeekDay = RTC_WEEKDAY_MONDAY;
  464. sDate.Month = RTC_MONTH_JANUARY;
  465. sDate.Date = 11;
  466. sDate.Year = 21;
  467. if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
  468. {
  469. Error_Handler();
  470. }
  471. /* USER CODE BEGIN RTC_Init 2 */
  472. /* USER CODE END RTC_Init 2 */
  473. }
  474. /**
  475. * @brief USART2 Initialization Function
  476. * @param None
  477. * @retval None
  478. */
  479. static void MX_USART2_UART_Init(void)
  480. {
  481. /* USER CODE BEGIN USART2_Init 0 */
  482. /* USER CODE END USART2_Init 0 */
  483. /* USER CODE BEGIN USART2_Init 1 */
  484. /* USER CODE END USART2_Init 1 */
  485. huart2.Instance = USART2;
  486. huart2.Init.BaudRate = 115200;
  487. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  488. huart2.Init.StopBits = UART_STOPBITS_1;
  489. huart2.Init.Parity = UART_PARITY_NONE;
  490. huart2.Init.Mode = UART_MODE_TX_RX;
  491. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  492. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  493. if (HAL_UART_Init(&huart2) != HAL_OK)
  494. {
  495. Error_Handler();
  496. }
  497. /* USER CODE BEGIN USART2_Init 2 */
  498. /* USER CODE END USART2_Init 2 */
  499. }
  500. /**
  501. * @brief GPIO Initialization Function
  502. * @param None
  503. * @retval None
  504. */
  505. static void MX_GPIO_Init(void)
  506. {
  507. GPIO_InitTypeDef GPIO_InitStruct = {0};
  508. /* GPIO Ports Clock Enable */
  509. __HAL_RCC_GPIOC_CLK_ENABLE();
  510. __HAL_RCC_GPIOH_CLK_ENABLE();
  511. __HAL_RCC_GPIOA_CLK_ENABLE();
  512. __HAL_RCC_GPIOB_CLK_ENABLE();
  513. /*Configure GPIO pin Output Level */
  514. HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
  515. /*Configure GPIO pin : B1_Pin */
  516. GPIO_InitStruct.Pin = B1_Pin;
  517. GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  518. GPIO_InitStruct.Pull = GPIO_NOPULL;
  519. HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
  520. /*Configure GPIO pin : LD2_Pin */
  521. GPIO_InitStruct.Pin = LD2_Pin;
  522. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  523. GPIO_InitStruct.Pull = GPIO_NOPULL;
  524. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  525. HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
  526. }
  527. /* USER CODE BEGIN 4 */
  528. /* USER CODE END 4 */
  529. /**
  530. * @brief This function is executed in case of error occurrence.
  531. * @retval None
  532. */
  533. void Error_Handler(void)
  534. {
  535. /* USER CODE BEGIN Error_Handler_Debug */
  536. /* User can add his own implementation to report the HAL error return state */
  537. __disable_irq();
  538. while (1)
  539. {
  540. }
  541. /* USER CODE END Error_Handler_Debug */
  542. }
  543. /**
  544. * @brief Alarm callback
  545. * @param hrtc: RTC handle
  546. * @retval None
  547. */
  548. void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
  549. {
  550. /* Alarm generation */
  551. transmit_uart("Alarm!!!!\r\n");
  552. }
  553. #ifdef USE_FULL_ASSERT
  554. /**
  555. * @brief Reports the name of the source file and the source line number
  556. * where the assert_param error has occurred.
  557. * @param file: pointer to the source file name
  558. * @param line: assert_param error line source number
  559. * @retval None
  560. */
  561. void assert_failed(uint8_t *file, uint32_t line)
  562. {
  563. /* USER CODE BEGIN 6 */
  564. /* User can add his own implementation to report the file name and line number,
  565. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  566. /* USER CODE END 6 */
  567. }
  568. #endif /* USE_FULL_ASSERT */
  569. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/