text: /******************************************************************//**
  * @file   main.c
  * @brief  Write a program to configure Time from user and display
  * @version  v1.0
  * @date   May 30, 2015
  * @author Bhavin R. Darji
  **********************************************************************/
  
  
  /* Includes ------------------------------------------------------------------*/
  #include "stm32f4xx_hal.h"
  #include "gpio.h"
  
  /* USER CODE BEGIN Includes */
  #include "stm32f4_global.h"
  #include "stm32f4_discovery_uart.h"
  #include "stm32f4_discovery_vcp.h"
  //#include "stm32f4_discovery.h"
  //#include "stm32f4_ask25.h"
  #include "stm32f4_discovery_rtc.h"
  
  
  
  /* USER CODE END Includes */
  
  /* Private variables ---------------------------------------------------------*/
  
  /* USER CODE BEGIN PV */
  
  /* USER CODE END PV */
  
  /* Private function prototypes -----------------------------------------------*/
  void SystemClock_Config(void);
  
  /* USER CODE BEGIN PFP */
  
  /* USER CODE END PFP */
  
  /* USER CODE BEGIN 0 */
  
  /* USER CODE END 0 */
  
  int main(void)
  {
  
    /* USER CODE BEGIN 1 */
    trace_printf("Hello\n");
    RTC_TimeTypeDef Tim;
    RTC_DateTypeDef Dat;
    /* USER CODE END 1 */
  
    /* MCU Configuration----------------------------------------------------------*/
  
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();
  
    /* Configure the system clock */
    SystemClock_Config();
  
    /* Initialize all configured peripherals */
    MX_GPIO_Init();
  
    /* USER CODE BEGIN 2 */
  
    /* Initialize RTC */
    BSP_RTC_Init();
    /* Initialize UART with 115200 baud rate */
    BSP_UART_Init(115200);
    uprintf("Set Time: ");
    BSP_RTC_Change_Time();
    /* USER CODE END 2 */
  
    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    while (1)
    {
    /* USER CODE END WHILE */
  
    /* USER CODE BEGIN 3 */
      HAL_RTC_GetTime(&hrtc_bsp,&Tim,FORMAT_BIN);
      HAL_RTC_GetDate(&hrtc_bsp,&Dat,FORMAT_BIN);
      Tim.SubSeconds = 1000 - ((hrtc_bsp.Instance->SSR*1000)/hrtc_bsp.Init.SynchPrediv);                // Count msec
      uprintf("\x1b[3;1H %d02 : %d02 : %d02 : %d04",Tim.Hours,Tim.Minutes,Tim.Seconds,Tim.SubSeconds);
  
  
    }
    /* USER CODE END 3 */
  
  }
  
  
  /** System Clock Configuration
  */
  void SystemClock_Config(void)
  {
  
    RCC_OscInitTypeDef RCC_OscInitStruct;
    RCC_ClkInitTypeDef RCC_ClkInitStruct;
    RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
  
    __PWR_CLK_ENABLE();
  
    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLM = 8;
    RCC_OscInitStruct.PLL.PLLN = 336;
    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
    RCC_OscInitStruct.PLL.PLLQ = 7;
    HAL_RCC_OscConfig(&RCC_OscInitStruct);
  
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
                                |RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
  
    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
    PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV8;
    HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
  }
  
  /* USER CODE BEGIN 4 */
  
  /* USER CODE END 4 */
  
  #ifdef USE_FULL_ASSERT
  
  /**
     * @brief Reports the name of the source file and the source line number
     * where the assert_param error has occurred.
     * @param file: pointer to the source file name
     * @param line: assert_param error line source number
     * @retval None
     */
  void assert_failed(uint8_t* file, uint32_t line)
  {
    /* USER CODE BEGIN 6 */
    /* User can add his own implementation to report the file name and line number,
      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
    /* USER CODE END 6 */
  
  }
  
  #endif
  
  /**
    * @}
    */
  
  /**
    * @}
  */
  
  /*****END OF FILE****/
  