1 /**
2   ******************************************************************************
3   * @file    stm32c0xx_ll_utils.h
4   * @author  MCD Application Team
5   * @brief   Header file of UTILS LL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 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   @verbatim
18   ==============================================================================
19                      ##### How to use this driver #####
20   ==============================================================================
21     [..]
22     The LL UTILS driver contains a set of generic APIs that can be
23     used by user:
24       (+) Device electronic signature
25       (+) Timing functions
26 
27   @endverbatim
28   */
29 
30 /* Define to prevent recursive inclusion -------------------------------------*/
31 #ifndef STM32C0xx_LL_UTILS_H
32 #define STM32C0xx_LL_UTILS_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* Includes ------------------------------------------------------------------*/
39 #include "stm32c0xx.h"
40 
41 /** @addtogroup STM32C0xx_LL_Driver
42   * @{
43   */
44 
45 /** @defgroup UTILS_LL UTILS
46   * @{
47   */
48 
49 /* Private types -------------------------------------------------------------*/
50 /* Private variables ---------------------------------------------------------*/
51 
52 /* Private constants ---------------------------------------------------------*/
53 /** @defgroup UTILS_LL_Private_Constants UTILS Private Constants
54   * @{
55   */
56 
57 /* Max delay can be used in LL_mDelay */
58 #define LL_MAX_DELAY                  0xFFFFFFFFU
59 
60 /**
61   * @brief Unique device ID register base address
62   */
63 #define UID_BASE_ADDRESS              UID_BASE
64 
65 /**
66   * @brief Flash size data register base address
67   */
68 #define FLASHSIZE_BASE_ADDRESS        FLASHSIZE_BASE
69 
70 /**
71   * @brief Package data register base address
72   */
73 #define PACKAGE_BASE_ADDRESS          PACKAGE_BASE
74 
75 /**
76   * @}
77   */
78 
79 /* Private macros ------------------------------------------------------------*/
80 /** @defgroup UTILS_LL_Private_Macros UTILS Private Macros
81   * @{
82   */
83 /**
84   * @}
85   */
86 /* Exported types ------------------------------------------------------------*/
87 /* Exported constants --------------------------------------------------------*/
88 /** @defgroup UTILS_LL_Exported_Constants UTILS Exported Constants
89   * @{
90   */
91 
92 /** @defgroup UTILS_EC_PACKAGETYPE PACKAGE TYPE
93   * @{
94   */
95 #if defined(STM32C011xx)
96 #define LL_UTILS_PACKAGETYPE_SO8           0x0001U /*!< SO8 package type      */
97 #define LL_UTILS_PACKAGETYPE_WLCSP12       0x0002U /*!< WLCSP12 package type  */
98 #define LL_UTILS_PACKAGETYPE_UFQFPN20      0x0003U /*!< UFQFPN20 package type */
99 #define LL_UTILS_PACKAGETYPE_TSSOP20       0x0004U /*!< TSSOP20 package type  */
100 #elif defined(STM32C031xx)
101 #define LL_UTILS_PACKAGETYPE_TSSOP20        0x0002U /*!< TSSOP20 package type             */
102 #define LL_UTILS_PACKAGETYPE_UFQFPN28       0x0003U /*!< UFQFPN28 package type            */
103 #define LL_UTILS_PACKAGETYPE_QFN32          0x0004U /*!< UFQFPN32 / LQFP32  package type  */
104 #define LL_UTILS_PACKAGETYPE_QFN48          0x0005U /*!< UFQFPN48 / LQFP48  package type  */
105 #elif defined(STM32C071xx)
106 #define LL_UTILS_PACKAGETYPE_WLCSP19_GP     0x0001U /*!< WLCSP19 (GP) package type                           */
107 #define LL_UTILS_PACKAGETYPE_WLCSP19_N      0x0002U /*!< WLCSP19 (N) package type                            */
108 #define LL_UTILS_PACKAGETYPE_TSSOP20_GP     0x0003U /*!< TSSOP20 (GP) package type                           */
109 #define LL_UTILS_PACKAGETYPE_TSSOP20_N      0x0004U /*!< TSSOP20 (N) package type                            */
110 #define LL_UTILS_PACKAGETYPE_UFQFPN28_GP    0x0005U /*!< UFQFPN28 (GP) package type                          */
111 #define LL_UTILS_PACKAGETYPE_UFQFPN28_N     0x0006U /*!< UFQFPN28 (GP) package type                          */
112 #define LL_UTILS_PACKAGETYPE_QFN32_GP       0x0007U /*!< UFQFPN32 / LQFP32 general purpose (GP) package type */
113 #define LL_UTILS_PACKAGETYPE_QFN32_N        0x0008U /*!< UFQFPN32 / LQFP32 general purpose (N) package type  */
114 #define LL_UTILS_PACKAGETYPE_QFN48_GP       0x0009U /*!< UFQFPN48 / LQFP48 general purpose (GP) package type */
115 #define LL_UTILS_PACKAGETYPE_QFN48_N        0x000AU /*!< UFQFPN32 / LQFP48 general purpose (N) package type  */
116 #define LL_UTILS_PACKAGETYPE_LQFP64_GP      0x000BU /*!< UFQFPN64 / LQFP64 general purpose (GP) package type */
117 #define LL_UTILS_PACKAGETYPE_LQFP64_N       0x0008U /*!< UFQFPN64 / LQFP64 general purpose (N) package type  */
118 #define LL_UTILS_PACKAGETYPE_UFBGA64_GP     0x000DU /*!< UFBGA64 (GP) package type                           */
119 #define LL_UTILS_PACKAGETYPE_UFBGA64_N      0x000EU /*!< UFBGA64 (N) package type                            */
120 #endif /* STM32C0xx */
121 /**
122   * @}
123   */
124 
125 /**
126   * @}
127   */
128 
129 /* Exported macro ------------------------------------------------------------*/
130 
131 /* Exported functions --------------------------------------------------------*/
132 /** @defgroup UTILS_LL_Exported_Functions UTILS Exported Functions
133   * @{
134   */
135 
136 /** @defgroup UTILS_EF_DEVICE_ELECTRONIC_SIGNATURE DEVICE ELECTRONIC SIGNATURE
137   * @{
138   */
139 
140 /**
141   * @brief  Get Word0 of the unique device identifier (UID based on 96 bits)
142   * @retval UID[31:0]: X and Y coordinates on the wafer expressed in BCD format
143   */
LL_GetUID_Word0(void)144 __STATIC_INLINE uint32_t LL_GetUID_Word0(void)
145 {
146   return (uint32_t)(READ_REG(*((uint32_t *)UID_BASE_ADDRESS)));
147 }
148 
149 /**
150   * @brief  Get Word1 of the unique device identifier (UID based on 96 bits)
151   * @retval UID[63:32]: Wafer number (UID[39:32]) & LOT_NUM[23:0] (UID[63:40])
152   */
LL_GetUID_Word1(void)153 __STATIC_INLINE uint32_t LL_GetUID_Word1(void)
154 {
155   return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 4U))));
156 }
157 
158 /**
159   * @brief  Get Word2 of the unique device identifier (UID based on 96 bits)
160   * @retval UID[95:64]: Lot number (ASCII encoded) - LOT_NUM[55:24]
161   */
LL_GetUID_Word2(void)162 __STATIC_INLINE uint32_t LL_GetUID_Word2(void)
163 {
164   return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 8U))));
165 }
166 
167 /**
168   * @brief  Get Flash memory size
169   * @note   This bitfield indicates the size of the device Flash memory expressed in
170   *         Kbytes. As an example, 0x040 corresponds to 64 Kbytes.
171   * @retval FLASH_SIZE[15:0]: Flash memory size
172   */
LL_GetFlashSize(void)173 __STATIC_INLINE uint32_t LL_GetFlashSize(void)
174 {
175   return (uint32_t)(READ_REG(*((uint32_t *)FLASHSIZE_BASE_ADDRESS)) & 0x0000FFFFUL);
176 }
177 
178 /**
179   * @brief  Get Package type
180   * @retval Returned value can be one of the following values:
181   *         @arg @ref LL_UTILS_PACKAGETYPE_SO8 (*)
182   *         @arg @ref LL_UTILS_PACKAGETYPE_WLCSP12 (*)
183   *         @arg @ref LL_UTILS_PACKAGETYPE_UFQFPN20 (*)
184   *         @arg @ref LL_UTILS_PACKAGETYPE_TSSOP20 (*)
185   *         @arg @ref LL_UTILS_PACKAGETYPE_UFQFPN28 (*)
186   *         @arg @ref LL_UTILS_PACKAGETYPE_QFN32 (*)
187   *         @arg @ref LL_UTILS_PACKAGETYPE_QFN48 (*)
188   *         @arg @ref LL_UTILS_PACKAGETYPE_WLCSP19 (*)
189   *         @arg @ref LL_UTILS_PACKAGETYPE_WLCSP15 (*)
190   *         @arg @ref LL_UTILS_PACKAGETYPE_UFBGA64 (*)
191   *         @arg @ref LL_UTILS_PACKAGETYPE_LQFP64 (*)
192   *
193   * @note  (*) Availability depends on devices.
194   *
195   */
LL_GetPackageType(void)196 __STATIC_INLINE uint32_t LL_GetPackageType(void)
197 {
198   return (uint32_t)(READ_REG(*((uint32_t *)PACKAGE_BASE_ADDRESS)) & 0xFU);
199 }
200 
201 /**
202   * @}
203   */
204 
205 /** @defgroup UTILS_LL_EF_DELAY DELAY
206   * @{
207   */
208 
209 /**
210   * @brief  This function configures the Cortex-M SysTick source of the time base.
211   * @param  HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro)
212   * @note   When a RTOS is used, it is recommended to avoid changing the SysTick
213   *         configuration by calling this function, for a delay use rather osDelay RTOS service.
214   * @param  Ticks Number of ticks
215   * @retval None
216   */
LL_InitTick(uint32_t HCLKFrequency,uint32_t Ticks)217 __STATIC_INLINE void LL_InitTick(uint32_t HCLKFrequency, uint32_t Ticks)
218 {
219   /* Configure the SysTick to have interrupt in 1ms time base */
220   SysTick->LOAD  = (uint32_t)((HCLKFrequency / Ticks) - 1UL);  /* set reload register */
221   SysTick->VAL   = 0UL;                                       /* Load the SysTick Counter Value */
222   SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
223                    SysTick_CTRL_ENABLE_Msk;                   /* Enable the Systick Timer */
224 }
225 
226 void        LL_Init1msTick(uint32_t HCLKFrequency);
227 void        LL_mDelay(uint32_t Delay);
228 
229 /**
230   * @}
231   */
232 
233 /** @defgroup UTILS_EF_SYSTEM SYSTEM
234   * @{
235   */
236 void        LL_SetSystemCoreClock(uint32_t HCLKFrequency);
237 ErrorStatus LL_SetFlashLatency(uint32_t HCLK_Frequency);
238 /* alias for backward compatibility */
239 #define UTILS_SetFlashLatency LL_SetFlashLatency
240 
241 /**
242   * @}
243   */
244 
245 /**
246   * @}
247   */
248 
249 /**
250   * @}
251   */
252 
253 /**
254   * @}
255   */
256 
257 #ifdef __cplusplus
258 }
259 #endif
260 
261 #endif /* STM32C0xx_LL_UTILS_H */
262 
263