Subversion Repositories LedShow

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f1xx_ll_utils.h
  4.   * @author  MCD Application Team
  5.   * @brief   Header file of UTILS LL module.
  6.   @verbatim
  7.   ==============================================================================
  8.                      ##### How to use this driver #####
  9.   ==============================================================================
  10.     [..]
  11.     The LL UTILS driver contains a set of generic APIs that can be
  12.     used by user:
  13.       (+) Device electronic signature
  14.       (+) Timing functions
  15.       (+) PLL configuration functions
  16.  
  17.   @endverbatim
  18.   ******************************************************************************
  19.   * @attention
  20.   *
  21.   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  22.   *
  23.   * Redistribution and use in source and binary forms, with or without modification,
  24.   * are permitted provided that the following conditions are met:
  25.   *   1. Redistributions of source code must retain the above copyright notice,
  26.   *      this list of conditions and the following disclaimer.
  27.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  28.   *      this list of conditions and the following disclaimer in the documentation
  29.   *      and/or other materials provided with the distribution.
  30.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  31.   *      may be used to endorse or promote products derived from this software
  32.   *      without specific prior written permission.
  33.   *
  34.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  35.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  36.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  37.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  38.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  39.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  40.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  41.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  42.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  43.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44.   *
  45.   ******************************************************************************
  46.   */
  47.  
  48. /* Define to prevent recursive inclusion -------------------------------------*/
  49. #ifndef __STM32F1xx_LL_UTILS_H
  50. #define __STM32F1xx_LL_UTILS_H
  51.  
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55.  
  56. /* Includes ------------------------------------------------------------------*/
  57. #include "stm32f1xx.h"
  58.  
  59. /** @addtogroup STM32F1xx_LL_Driver
  60.   * @{
  61.   */
  62.  
  63. /** @defgroup UTILS_LL UTILS
  64.   * @{
  65.   */
  66.  
  67. /* Private types -------------------------------------------------------------*/
  68. /* Private variables ---------------------------------------------------------*/
  69.  
  70. /* Private constants ---------------------------------------------------------*/
  71. /** @defgroup UTILS_LL_Private_Constants UTILS Private Constants
  72.   * @{
  73.   */
  74.  
  75. /* Max delay can be used in LL_mDelay */
  76. #define LL_MAX_DELAY                  0xFFFFFFFFU
  77.  
  78. /**
  79.  * @brief Unique device ID register base address
  80.  */
  81. #define UID_BASE_ADDRESS              UID_BASE
  82.  
  83. /**
  84.  * @brief Flash size data register base address
  85.  */
  86. #define FLASHSIZE_BASE_ADDRESS        FLASHSIZE_BASE
  87.  
  88. /**
  89.   * @}
  90.   */
  91.  
  92. /* Private macros ------------------------------------------------------------*/
  93. /** @defgroup UTILS_LL_Private_Macros UTILS Private Macros
  94.   * @{
  95.   */
  96. /**
  97.   * @}
  98.   */
  99. /* Exported types ------------------------------------------------------------*/
  100. /** @defgroup UTILS_LL_ES_INIT UTILS Exported structures
  101.   * @{
  102.   */
  103. /**
  104.   * @brief  UTILS PLL structure definition
  105.   */
  106. typedef struct
  107. {
  108.   uint32_t PLLMul;   /*!< Multiplication factor for PLL VCO input clock.
  109.                           This parameter can be a value of @ref RCC_LL_EC_PLL_MUL
  110.  
  111.                           This feature can be modified afterwards using unitary function
  112.                           @ref LL_RCC_PLL_ConfigDomain_SYS(). */
  113.  
  114.   uint32_t Prediv;   /*!< Division factor for HSE used as PLL clock source.
  115.                           This parameter can be a value of @ref RCC_LL_EC_PREDIV_DIV
  116.  
  117.                           This feature can be modified afterwards using unitary function
  118.                           @ref LL_RCC_PLL_ConfigDomain_SYS(). */
  119. } LL_UTILS_PLLInitTypeDef;
  120.  
  121. /**
  122.   * @brief  UTILS System, AHB and APB buses clock configuration structure definition
  123.   */
  124. typedef struct
  125. {
  126.   uint32_t AHBCLKDivider;         /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  127.                                        This parameter can be a value of @ref RCC_LL_EC_SYSCLK_DIV
  128.  
  129.                                        This feature can be modified afterwards using unitary function
  130.                                        @ref LL_RCC_SetAHBPrescaler(). */
  131.  
  132.   uint32_t APB1CLKDivider;        /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  133.                                        This parameter can be a value of @ref RCC_LL_EC_APB1_DIV
  134.  
  135.                                        This feature can be modified afterwards using unitary function
  136.                                        @ref LL_RCC_SetAPB1Prescaler(). */
  137.  
  138.   uint32_t APB2CLKDivider;        /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
  139.                                        This parameter can be a value of @ref RCC_LL_EC_APB2_DIV
  140.  
  141.                                        This feature can be modified afterwards using unitary function
  142.                                        @ref LL_RCC_SetAPB2Prescaler(). */
  143.  
  144. } LL_UTILS_ClkInitTypeDef;
  145.  
  146. /**
  147.   * @}
  148.   */
  149.  
  150. /* Exported constants --------------------------------------------------------*/
  151. /** @defgroup UTILS_LL_Exported_Constants UTILS Exported Constants
  152.   * @{
  153.   */
  154.  
  155. /** @defgroup UTILS_EC_HSE_BYPASS HSE Bypass activation
  156.   * @{
  157.   */
  158. #define LL_UTILS_HSEBYPASS_OFF        0x00000000U       /*!< HSE Bypass is not enabled                */
  159. #define LL_UTILS_HSEBYPASS_ON         0x00000001U       /*!< HSE Bypass is enabled                    */
  160. /**
  161.   * @}
  162.   */
  163.  
  164. /**
  165.   * @}
  166.   */
  167.  
  168. /* Exported macro ------------------------------------------------------------*/
  169.  
  170. /* Exported functions --------------------------------------------------------*/
  171. /** @defgroup UTILS_LL_Exported_Functions UTILS Exported Functions
  172.   * @{
  173.   */
  174.  
  175. /** @defgroup UTILS_EF_DEVICE_ELECTRONIC_SIGNATURE DEVICE ELECTRONIC SIGNATURE
  176.   * @{
  177.   */
  178.  
  179. /**
  180.   * @brief  Get Word0 of the unique device identifier (UID based on 96 bits)
  181.   * @retval UID[31:0]
  182.   */
  183. __STATIC_INLINE uint32_t LL_GetUID_Word0(void)
  184. {
  185.   return (uint32_t)(READ_REG(*((uint32_t *)UID_BASE_ADDRESS)));
  186. }
  187.  
  188. /**
  189.   * @brief  Get Word1 of the unique device identifier (UID based on 96 bits)
  190.   * @retval UID[63:32]
  191.   */
  192. __STATIC_INLINE uint32_t LL_GetUID_Word1(void)
  193. {
  194.   return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 4U))));
  195. }
  196.  
  197. /**
  198.   * @brief  Get Word2 of the unique device identifier (UID based on 96 bits)
  199.   * @retval UID[95:64]
  200.   */
  201. __STATIC_INLINE uint32_t LL_GetUID_Word2(void)
  202. {
  203.   return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 8U))));
  204. }
  205.  
  206. /**
  207.   * @brief  Get Flash memory size
  208.   * @note   This bitfield indicates the size of the device Flash memory expressed in
  209.   *         Kbytes. As an example, 0x040 corresponds to 64 Kbytes.
  210.   * @retval FLASH_SIZE[15:0]: Flash memory size
  211.   */
  212. __STATIC_INLINE uint32_t LL_GetFlashSize(void)
  213. {
  214.   return (uint16_t)(READ_REG(*((uint32_t *)FLASHSIZE_BASE_ADDRESS)));
  215. }
  216.  
  217.  
  218. /**
  219.   * @}
  220.   */
  221.  
  222. /** @defgroup UTILS_LL_EF_DELAY DELAY
  223.   * @{
  224.   */
  225.  
  226. /**
  227.   * @brief  This function configures the Cortex-M SysTick source of the time base.
  228.   * @param  HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro)
  229.   * @note   When a RTOS is used, it is recommended to avoid changing the SysTick
  230.   *         configuration by calling this function, for a delay use rather osDelay RTOS service.
  231.   * @param  Ticks Number of ticks
  232.   * @retval None
  233.   */
  234. __STATIC_INLINE void LL_InitTick(uint32_t HCLKFrequency, uint32_t Ticks)
  235. {
  236.   /* Configure the SysTick to have interrupt in 1ms time base */
  237.   SysTick->LOAD  = (uint32_t)((HCLKFrequency / Ticks) - 1UL);  /* set reload register */
  238.   SysTick->VAL   = 0UL;                                       /* Load the SysTick Counter Value */
  239.   SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
  240.                    SysTick_CTRL_ENABLE_Msk;                   /* Enable the Systick Timer */
  241. }
  242.  
  243. void        LL_Init1msTick(uint32_t HCLKFrequency);
  244. void        LL_mDelay(uint32_t Delay);
  245.  
  246. /**
  247.   * @}
  248.   */
  249.  
  250. /** @defgroup UTILS_EF_SYSTEM SYSTEM
  251.   * @{
  252.   */
  253.  
  254. void        LL_SetSystemCoreClock(uint32_t HCLKFrequency);
  255. ErrorStatus LL_PLL_ConfigSystemClock_HSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct,
  256.                                          LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
  257. ErrorStatus LL_PLL_ConfigSystemClock_HSE(uint32_t HSEFrequency, uint32_t HSEBypass,
  258.                                          LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
  259.  
  260. /**
  261.   * @}
  262.   */
  263.  
  264. /**
  265.   * @}
  266.   */
  267.  
  268. /**
  269.   * @}
  270.   */
  271.  
  272. /**
  273.   * @}
  274.   */
  275.  
  276. #ifdef __cplusplus
  277. }
  278. #endif
  279.  
  280. #endif /* __STM32F1xx_LL_UTILS_H */
  281.  
  282. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  283.