STM32L4xx_HAL_Driver  1.14.0
Initialization and de-initialization Functions

Initialization and de-initialization functions. More...

Functions

HAL_StatusTypeDef HAL_Init (void)
 Configure the Flash prefetch, the Instruction and Data caches, the time base source, NVIC and any required global low level hardware by calling the HAL_MspInit() callback function to be optionally defined in user file stm32l4xx_hal_msp.c. More...
 
HAL_StatusTypeDef HAL_DeInit (void)
 De-initialize common part of the HAL and stop the source of time base. More...
 
void HAL_MspInit (void)
 Initialize the MSP. More...
 
void HAL_MspDeInit (void)
 DeInitialize the MSP. More...
 
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
 This function configures the source of the time base: The time source is configured to have 1ms time base with a dedicated Tick interrupt priority. More...
 

Detailed Description

Initialization and de-initialization functions.

 ===============================================================================
              ##### Initialization and de-initialization functions #####
 ===============================================================================
    [..]  This section provides functions allowing to:
      (+) Initialize the Flash interface, the NVIC allocation and initial time base
          clock configuration.
      (+) De-initialize common part of the HAL.
      (+) Configure the time base source to have 1ms time base with a dedicated
          Tick interrupt priority.
        (++) SysTick timer is used by default as source of time base, but user
             can eventually implement his proper time base source (a general purpose
             timer for example or other time source), keeping in mind that Time base
             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
             handled in milliseconds basis.
        (++) Time base configuration function (HAL_InitTick ()) is called automatically
             at the beginning of the program after reset by HAL_Init() or at any time
             when clock is configured, by HAL_RCC_ClockConfig().
        (++) Source of time base is configured  to generate interrupts at regular
             time intervals. Care must be taken if HAL_Delay() is called from a
             peripheral ISR process, the Tick interrupt line must have higher priority
            (numerically lower) than the peripheral interrupt. Otherwise the caller
            ISR process will be blocked.
       (++) functions affecting time base configurations are declared as __weak
             to make  override possible  in case of other  implementations in user file.

Function Documentation

◆ HAL_DeInit()

HAL_StatusTypeDef HAL_DeInit ( void  )

De-initialize common part of the HAL and stop the source of time base.

Note
This function is optional.
Return values
HALstatus

Definition at line 196 of file stm32l4xx_hal.c.

197 {
198  /* Reset of all peripherals */
199  __HAL_RCC_APB1_FORCE_RESET();
200  __HAL_RCC_APB1_RELEASE_RESET();
201 
202  __HAL_RCC_APB2_FORCE_RESET();
203  __HAL_RCC_APB2_RELEASE_RESET();
204 
205  __HAL_RCC_AHB1_FORCE_RESET();
206  __HAL_RCC_AHB1_RELEASE_RESET();
207 
208  __HAL_RCC_AHB2_FORCE_RESET();
209  __HAL_RCC_AHB2_RELEASE_RESET();
210 
211  __HAL_RCC_AHB3_FORCE_RESET();
212  __HAL_RCC_AHB3_RELEASE_RESET();
213 
214  /* De-Init the low level hardware */
215  HAL_MspDeInit();
216 
217  /* Return function status */
218  return HAL_OK;
219 }
void HAL_MspDeInit(void)
DeInitialize the MSP.
return HAL_OK

◆ HAL_Init()

HAL_StatusTypeDef HAL_Init ( void  )

Configure the Flash prefetch, the Instruction and Data caches, the time base source, NVIC and any required global low level hardware by calling the HAL_MspInit() callback function to be optionally defined in user file stm32l4xx_hal_msp.c.

Note
HAL_Init() function is called at the beginning of program after reset and before the clock configuration.
In the default implementation the System Timer (Systick) is used as source of time base. The Systick configuration is based on MSI clock, as MSI is the clock used after a system Reset and the NVIC configuration is set to Priority group 4. Once done, time base tick starts incrementing: the tick variable counter is incremented each 1ms in the SysTick_Handler() interrupt handler.
Return values
HALstatus

Definition at line 152 of file stm32l4xx_hal.c.

153 {
154  HAL_StatusTypeDef status = HAL_OK;
155 
156  /* Configure Flash prefetch, Instruction cache, Data cache */
157  /* Default configuration at reset is: */
158  /* - Prefetch disabled */
159  /* - Instruction cache enabled */
160  /* - Data cache enabled */
161 #if (INSTRUCTION_CACHE_ENABLE == 0)
162  __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
163 #endif /* INSTRUCTION_CACHE_ENABLE */
164 
165 #if (DATA_CACHE_ENABLE == 0)
166  __HAL_FLASH_DATA_CACHE_DISABLE();
167 #endif /* DATA_CACHE_ENABLE */
168 
169 #if (PREFETCH_ENABLE != 0)
170  __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
171 #endif /* PREFETCH_ENABLE */
172 
173  /* Set Interrupt Group Priority */
174  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
175 
176  /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is MSI) */
177  if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
178  {
179  status = HAL_ERROR;
180  }
181  else
182  {
183  /* Init the low level hardware */
184  HAL_MspInit();
185  }
186 
187  /* Return function status */
188  return status;
189 }
return HAL_OK
void HAL_MspInit(void)
Initialize the MSP.
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
This function configures the source of the time base: The time source is configured to have 1ms time ...
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
Set the priority grouping field (pre-emption priority and subpriority) using the required unlock sequ...

◆ HAL_InitTick()

__weak HAL_StatusTypeDef HAL_InitTick ( uint32_t  TickPriority)

This function configures the source of the time base: The time source is configured to have 1ms time base with a dedicated Tick interrupt priority.

Note
This function is called automatically at the beginning of program after reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
In the default implementation, SysTick timer is the source of time base. It is used to generate interrupts at regular time intervals. Care must be taken if HAL_Delay() is called from a peripheral ISR process, The SysTick interrupt must have higher priority (numerically lower) than the peripheral interrupt. Otherwise the caller ISR process will be blocked. The function is declared as __weak to be overwritten in case of other implementation in user file.
Parameters
TickPriorityTick interrupt priority.
Return values
HALstatus

Definition at line 259 of file stm32l4xx_hal.c.

260 {
261  HAL_StatusTypeDef status = HAL_OK;
262 
263  if (uwTickFreq != 0U)
264  {
265  /*Configure the SysTick to have interrupt in 1ms time basis*/
266  if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) == 0U)
267  {
268  /* Configure the SysTick IRQ priority */
269  if (TickPriority < (1UL << __NVIC_PRIO_BITS))
270  {
271  HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
272  uwTickPrio = TickPriority;
273  }
274  else
275  {
276  status = HAL_ERROR;
277  }
278  }
279  else
280  {
281  status = HAL_ERROR;
282  }
283  }
284  else
285  {
286  status = HAL_ERROR;
287  }
288 
289  /* Return function status */
290  return status;
291 }
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
Initialize the System Timer with interrupt enabled and start the System Tick Timer (SysTick): Counter...
return HAL_OK
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
Set the priority of an interrupt.
uint32_t uwTickFreq
Definition: stm32l4xx_hal.c:92
uint32_t uwTickPrio
Definition: stm32l4xx_hal.c:91

◆ HAL_MspDeInit()

__weak void HAL_MspDeInit ( void  )

DeInitialize the MSP.

Return values
None

Definition at line 236 of file stm32l4xx_hal.c.

237 {
238  /* NOTE : This function should not be modified, when the callback is needed,
239  the HAL_MspDeInit could be implemented in the user file
240  */
241 }

◆ HAL_MspInit()

__weak void HAL_MspInit ( void  )

Initialize the MSP.

Return values
None

Definition at line 225 of file stm32l4xx_hal.c.

226 {
227  /* NOTE : This function should not be modified, when the callback is needed,
228  the HAL_MspInit could be implemented in the user file
229  */
230 }