text: /**
    *******************************************************************************
    * @file    Projects/Multi/Examples/IKS01A2/DataLog/Src/cube_hal_l4.c
    * @author  CL
    * @version V4.0.0
    * @date    1-May-2017
    * @brief   Specific Cube settings for STM32L4 Nucleo boards
    *******************************************************************************
    * @attention
    *
    * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
    *
    * Redistribution and use in source and binary forms, with or without modification,
    * are permitted provided that the following conditions are met:
    *   1. Redistributions of source code must retain the above copyright notice,
    *      this list of conditions and the following disclaimer.
    *   2. Redistributions in binary form must reproduce the above copyright notice,
    *      this list of conditions and the following disclaimer in the documentation
    *      and/or other materials provided with the distribution.
    *   3. Neither the name of STMicroelectronics nor the names of its contributors
    *      may be used to endorse or promote products derived from this software
    *      without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    * ******************************************************************************
    */
  
  /* Includes ------------------------------------------------------------------*/
  #include "cube_hal.h"
  #include "com.h"
  
  /** @addtogroup X_NUCLEO_IKS01A2_Examples
    * @{
    */
  
  /** @addtogroup DATALOG
    * @{
    */
  
  /**
   * @brief  System Clock Configuration
   * @param  None
   * @retval None
   */
  void SystemClock_Config(void)
  {
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  
    /* MSI is enabled after System reset, activate PLL with MSI as source */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
    RCC_OscInitStruct.MSIState = RCC_MSI_ON;
    RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
    RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
    RCC_OscInitStruct.PLL.PLLM = 1;
    RCC_OscInitStruct.PLL.PLLN = 40;
    RCC_OscInitStruct.PLL.PLLR = 2;
    RCC_OscInitStruct.PLL.PLLP = 7;
    RCC_OscInitStruct.PLL.PLLQ = 4;
    if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
    {
      /* Initialization Error */
      Error_Handler();
    }
  
    /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
       clocks dividers */
    RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
    if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
    {
      /* Initialization Error */
      Error_Handler();
    }
  }
  
  
  /**
   * @brief  Get the DMA Stream pending flags
   * @param  handle_dma DMA handle
   * @retval The state of FLAG (SET or RESET)
   */
  uint32_t Get_DMA_Flag_Status(DMA_HandleTypeDef *handle_dma)
  {
    return (__HAL_DMA_GET_FLAG(handle_dma, __HAL_DMA_GET_TE_FLAG_INDEX(handle_dma)));
  }
  
  /**
   * @brief  Returns the number of remaining data units in the current DMAy Streamx transfer
   * @param  handle_dma DMA handle
   * @retval The number of remaining data units in the current DMA Stream transfer
   */
  uint32_t Get_DMA_Counter(DMA_HandleTypeDef *handle_dma)
  {
    return (handle_dma->Instance->CNDTR);
  }
  
  /**
   * @brief  Configure the DMA handler for transmission process
   * @param  handle_dma DMA handle
   * @retval None
   */
  void Config_DMA_Handler(DMA_HandleTypeDef *handle_dma)
  {
    handle_dma->Instance                 = DMA1_Channel6;
    handle_dma->Init.Direction           = DMA_PERIPH_TO_MEMORY;
    handle_dma->Init.PeriphInc           = DMA_PINC_DISABLE;
    handle_dma->Init.MemInc              = DMA_MINC_ENABLE;
    handle_dma->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
    handle_dma->Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
    handle_dma->Init.Mode                = DMA_CIRCULAR;
    handle_dma->Init.Priority            = DMA_PRIORITY_VERY_HIGH;
    handle_dma->Init.Request             = DMA_REQUEST_2;
  }
  
  /**
  * @}
  */
  
  /**
  * @}
  */
  
  /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  