generated code, added drawings on Silkscreen
This commit is contained in:
		
							
								
								
									
										532
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										532
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,532 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   HAL module driver.
 | 
			
		||||
  *          This is the common part of the HAL initialization
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file
 | 
			
		||||
  * in the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  @verbatim
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
                     ##### How to use this driver #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
    [..]
 | 
			
		||||
    The common HAL driver contains a set of generic and common APIs that can be
 | 
			
		||||
    used by the PPP peripheral drivers and the user to start using the HAL.
 | 
			
		||||
    [..]
 | 
			
		||||
    The HAL contains two APIs categories:
 | 
			
		||||
         (+) HAL Initialization and de-initialization functions
 | 
			
		||||
         (+) HAL Control functions
 | 
			
		||||
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup HAL HAL
 | 
			
		||||
  * @brief HAL module driver.
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef HAL_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private define ------------------------------------------------------------*/
 | 
			
		||||
/** @defgroup HAL_Private Constants
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
/**
 | 
			
		||||
 * @brief STM32F3xx HAL Driver version number V1.5.7
 | 
			
		||||
   */
 | 
			
		||||
#define __STM32F3xx_HAL_VERSION_MAIN   (0x01U) /*!< [31:24] main version */
 | 
			
		||||
#define __STM32F3xx_HAL_VERSION_SUB1   (0x05U) /*!< [23:16] sub1 version */
 | 
			
		||||
#define __STM32F3xx_HAL_VERSION_SUB2   (0x07U) /*!< [15:8]  sub2 version */
 | 
			
		||||
#define __STM32F3xx_HAL_VERSION_RC     (0x00U) /*!< [7:0]  release candidate */
 | 
			
		||||
#define __STM32F3xx_HAL_VERSION         ((__STM32F3xx_HAL_VERSION_MAIN << 24U)\
 | 
			
		||||
                                        |(__STM32F3xx_HAL_VERSION_SUB1 << 16U)\
 | 
			
		||||
                                        |(__STM32F3xx_HAL_VERSION_SUB2 << 8U )\
 | 
			
		||||
                                        |(__STM32F3xx_HAL_VERSION_RC))
 | 
			
		||||
 | 
			
		||||
#define IDCODE_DEVID_MASK    (0x00000FFFU)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
/* Private macro -------------------------------------------------------------*/
 | 
			
		||||
/* Exported variables --------------------------------------------------------*/
 | 
			
		||||
/** @defgroup HAL_Exported_Variables HAL Exported Variables
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
__IO uint32_t uwTick;
 | 
			
		||||
uint32_t uwTickPrio   = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
 | 
			
		||||
HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT;  /* 1KHz */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/* Exported functions ---------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/** @defgroup HAL_Exported_Functions HAL Exported Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions 
 | 
			
		||||
 *  @brief    Initialization and de-initialization functions
 | 
			
		||||
 *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
              ##### Initialization and de-initialization functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    [..]  This section provides functions allowing to:
 | 
			
		||||
      (+) Initializes the Flash interface, the NVIC allocation and initial clock 
 | 
			
		||||
          configuration. It initializes the systick also when timeout is needed
 | 
			
		||||
          and the backup domain when enabled.
 | 
			
		||||
      (+) de-Initializes 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.
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  This function configures the Flash prefetch, 
 | 
			
		||||
  *         Configures time base source, NVIC and Low level hardware
 | 
			
		||||
  * @note   This function is called at the beginning of program after reset and before 
 | 
			
		||||
  *         the clock configuration
 | 
			
		||||
  *             
 | 
			
		||||
  * @note   The Systick configuration is based on HSI clock, as HSI is the clock
 | 
			
		||||
  *         used after a system Reset and the NVIC configuration is set to Priority group 4 
 | 
			
		||||
  *            
 | 
			
		||||
  * @note   The time base configuration is based on MSI clock when exiting from Reset.
 | 
			
		||||
  *         Once done, time base tick start incrementing.
 | 
			
		||||
  *         In the default implementation,Systick is used as source of time base.
 | 
			
		||||
  *       The tick variable is incremented each 1ms in its ISR.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_Init(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Configure Flash prefetch */
 | 
			
		||||
#if (PREFETCH_ENABLE != 0U)
 | 
			
		||||
  __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
 | 
			
		||||
#endif /* PREFETCH_ENABLE */
 | 
			
		||||
 | 
			
		||||
  /* Set Interrupt Group Priority */
 | 
			
		||||
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
 | 
			
		||||
 | 
			
		||||
  /* Enable systick and configure 1ms tick (default clock after Reset is HSI) */
 | 
			
		||||
  HAL_InitTick(TICK_INT_PRIORITY);
 | 
			
		||||
 | 
			
		||||
  /* Init the low level hardware */
 | 
			
		||||
  HAL_MspInit();
 | 
			
		||||
 | 
			
		||||
  /* Return function status */
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  This function de-Initializes common part of the HAL and stops the systick.
 | 
			
		||||
  * @note This function is optional.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_DeInit(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Reset of all peripherals */
 | 
			
		||||
  __HAL_RCC_APB1_FORCE_RESET();
 | 
			
		||||
  __HAL_RCC_APB1_RELEASE_RESET();
 | 
			
		||||
 | 
			
		||||
  __HAL_RCC_APB2_FORCE_RESET();
 | 
			
		||||
  __HAL_RCC_APB2_RELEASE_RESET();
 | 
			
		||||
 | 
			
		||||
  __HAL_RCC_AHB_FORCE_RESET();
 | 
			
		||||
  __HAL_RCC_AHB_RELEASE_RESET();
 | 
			
		||||
 | 
			
		||||
  /* De-Init the low level hardware */
 | 
			
		||||
  HAL_MspDeInit();
 | 
			
		||||
 | 
			
		||||
  /* Return function status */
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Initialize the MSP.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_MspInit(void)
 | 
			
		||||
{
 | 
			
		||||
  /* NOTE : This function should not be modified, when the callback is needed,
 | 
			
		||||
            the HAL_MspInit could be implemented in the user file
 | 
			
		||||
   */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  DeInitialize the MSP.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_MspDeInit(void)
 | 
			
		||||
{
 | 
			
		||||
  /* NOTE : This function should not be modified, when the callback is needed,
 | 
			
		||||
            the HAL_MspDeInit could be implemented in the user file
 | 
			
		||||
   */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  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(). 
 | 
			
		||||
  * @note   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.
 | 
			
		||||
  * @param TickPriority Tick interrupt priority.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
 | 
			
		||||
{
 | 
			
		||||
  /* Configure the SysTick to have interrupt in 1ms time basis*/
 | 
			
		||||
  if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U)
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Configure the SysTick IRQ priority */
 | 
			
		||||
  if (TickPriority < (1UL << __NVIC_PRIO_BITS))
 | 
			
		||||
  {
 | 
			
		||||
    HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
 | 
			
		||||
    uwTickPrio = TickPriority;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
   /* Return function status */
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup HAL_Exported_Functions_Group2 HAL Control functions 
 | 
			
		||||
 *  @brief    HAL Control functions
 | 
			
		||||
 *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                      ##### HAL Control functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    [..]  This section provides functions allowing to:
 | 
			
		||||
      (+) Provide a tick value in millisecond
 | 
			
		||||
      (+) Provide a blocking delay in millisecond
 | 
			
		||||
      (+) Suspend the time base source interrupt
 | 
			
		||||
      (+) Resume the time base source interrupt
 | 
			
		||||
      (+) Get the HAL API driver version
 | 
			
		||||
      (+) Get the device identifier
 | 
			
		||||
      (+) Get the device revision identifier
 | 
			
		||||
      (+) Enable/Disable Debug module during Sleep mode
 | 
			
		||||
      (+) Enable/Disable Debug module during STOP mode
 | 
			
		||||
      (+) Enable/Disable Debug module during STANDBY mode
 | 
			
		||||
      
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  This function is called to increment  a global variable "uwTick"
 | 
			
		||||
  *         used as application time base.
 | 
			
		||||
  * @note In the default implementation, this variable is incremented each 1ms
 | 
			
		||||
  *         in SysTick ISR.
 | 
			
		||||
  * @note This function is declared as __weak to be overwritten in case of other 
 | 
			
		||||
  *         implementations  in user file.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_IncTick(void)
 | 
			
		||||
{
 | 
			
		||||
  uwTick += uwTickFreq;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Povides a tick value in millisecond.
 | 
			
		||||
  * @note   The function is declared as __Weak  to be overwritten  in case of other 
 | 
			
		||||
  *         implementations  in user file.
 | 
			
		||||
  * @retval tick value
 | 
			
		||||
  */
 | 
			
		||||
__weak uint32_t HAL_GetTick(void)
 | 
			
		||||
{
 | 
			
		||||
  return uwTick;  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function returns a tick priority.
 | 
			
		||||
  * @retval tick priority
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_GetTickPrio(void)
 | 
			
		||||
{
 | 
			
		||||
  return uwTickPrio;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Set new tick Freq.
 | 
			
		||||
  * @retval status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status  = HAL_OK;
 | 
			
		||||
  HAL_TickFreqTypeDef prevTickFreq;
 | 
			
		||||
 | 
			
		||||
  assert_param(IS_TICKFREQ(Freq));
 | 
			
		||||
 | 
			
		||||
  if (uwTickFreq != Freq)
 | 
			
		||||
  {
 | 
			
		||||
    /* Back up uwTickFreq frequency */
 | 
			
		||||
    prevTickFreq = uwTickFreq;
 | 
			
		||||
 | 
			
		||||
    /* Update uwTickFreq global variable used by HAL_InitTick() */
 | 
			
		||||
    uwTickFreq = Freq;
 | 
			
		||||
 | 
			
		||||
    /* Apply the new tick Freq */
 | 
			
		||||
    status = HAL_InitTick(uwTickPrio);
 | 
			
		||||
 | 
			
		||||
    if (status != HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
      /* Restore previous tick frequency */
 | 
			
		||||
      uwTickFreq = prevTickFreq;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Return tick frequency.
 | 
			
		||||
  * @retval Tick frequency.
 | 
			
		||||
  *         Value of @ref HAL_TickFreqTypeDef.
 | 
			
		||||
  */
 | 
			
		||||
HAL_TickFreqTypeDef HAL_GetTickFreq(void)
 | 
			
		||||
{
 | 
			
		||||
  return uwTickFreq;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  This function provides accurate delay (in milliseconds) based
 | 
			
		||||
  *         on variable incremented.
 | 
			
		||||
  * @note   In the default implementation , SysTick timer is the source of time base. 
 | 
			
		||||
  *         It is used to generate interrupts at regular time intervals where uwTick
 | 
			
		||||
  *         is incremented.
 | 
			
		||||
  *         The function is declared as __Weak  to be overwritten  in case of other
 | 
			
		||||
  *         implementations  in user file.
 | 
			
		||||
  * @param  Delay specifies the delay time length, in milliseconds.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_Delay(uint32_t Delay)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t tickstart = HAL_GetTick();
 | 
			
		||||
  uint32_t wait = Delay;
 | 
			
		||||
  
 | 
			
		||||
  /* Add freq to guarantee minimum wait */
 | 
			
		||||
  if (wait < HAL_MAX_DELAY)
 | 
			
		||||
  {
 | 
			
		||||
    wait += (uint32_t)(uwTickFreq);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  while((HAL_GetTick() - tickstart) < wait)
 | 
			
		||||
  {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Suspend Tick increment.
 | 
			
		||||
  * @note   In the default implementation , SysTick timer is the source of time base. It is  
 | 
			
		||||
  *         used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
 | 
			
		||||
  *         is called, the the SysTick interrupt will be disabled and so Tick increment 
 | 
			
		||||
  *         is suspended.
 | 
			
		||||
  * @note This function is declared as __weak to be overwritten in case of other
 | 
			
		||||
  *         implementations  in user file.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_SuspendTick(void)
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
  /* Disable SysTick Interrupt */
 | 
			
		||||
  SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
 | 
			
		||||
                                                   
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Resume Tick increment.
 | 
			
		||||
  * @note   In the default implementation , SysTick timer is the source of time base. It is  
 | 
			
		||||
  *         used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
 | 
			
		||||
  *         is called, the the SysTick interrupt will be enabled and so Tick increment 
 | 
			
		||||
  *         is resumed.
 | 
			
		||||
  *         The function is declared as __Weak  to be overwritten  in case of other
 | 
			
		||||
  *         implementations  in user file.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_ResumeTick(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Enable SysTick Interrupt */
 | 
			
		||||
  SysTick->CTRL  |= SysTick_CTRL_TICKINT_Msk;
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  This function returns the HAL revision
 | 
			
		||||
  * @retval version 0xXYZR (8bits for each decimal, R for RC)
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_GetHalVersion(void)
 | 
			
		||||
{
 | 
			
		||||
 return __STM32F3xx_HAL_VERSION;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Returns the device revision identifier.
 | 
			
		||||
  * @retval Device revision identifier
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_GetREVID(void)
 | 
			
		||||
{
 | 
			
		||||
  return((DBGMCU->IDCODE) >> 16U);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Returns the device identifier.
 | 
			
		||||
  * @retval Device identifier
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_GetDEVID(void)
 | 
			
		||||
{
 | 
			
		||||
  return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Returns first word of the unique device identifier (UID based on 96 bits)
 | 
			
		||||
  * @retval Device identifier
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_GetUIDw0(void)
 | 
			
		||||
{
 | 
			
		||||
   return(READ_REG(*((uint32_t *)UID_BASE)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Returns second word of the unique device identifier (UID based on 96 bits)
 | 
			
		||||
  * @retval Device identifier
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_GetUIDw1(void)
 | 
			
		||||
{
 | 
			
		||||
   return(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Returns third word of the unique device identifier (UID based on 96 bits)
 | 
			
		||||
  * @retval Device identifier
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_GetUIDw2(void)
 | 
			
		||||
{
 | 
			
		||||
   return(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Enable the Debug Module during SLEEP mode
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_DBGMCU_EnableDBGSleepMode(void)
 | 
			
		||||
{
 | 
			
		||||
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Disable the Debug Module during SLEEP mode
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_DBGMCU_DisableDBGSleepMode(void)
 | 
			
		||||
{
 | 
			
		||||
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Enable the Debug Module during STOP mode
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_DBGMCU_EnableDBGStopMode(void)
 | 
			
		||||
{
 | 
			
		||||
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Disable the Debug Module during STOP mode
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_DBGMCU_DisableDBGStopMode(void)
 | 
			
		||||
{
 | 
			
		||||
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Enable the Debug Module during STANDBY mode
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_DBGMCU_EnableDBGStandbyMode(void)
 | 
			
		||||
{
 | 
			
		||||
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Disable the Debug Module during STANDBY mode
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_DBGMCU_DisableDBGStandbyMode(void)
 | 
			
		||||
{
 | 
			
		||||
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif /* HAL_MODULE_ENABLED */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1203
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_adc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1203
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_adc.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										2421
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_can.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2421
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_can.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -0,0 +1,511 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal_cortex.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   CORTEX HAL module driver.
 | 
			
		||||
  *          This file provides firmware functions to manage the following
 | 
			
		||||
  *          functionalities of the CORTEX:
 | 
			
		||||
  *           + Initialization and de-initialization functions
 | 
			
		||||
  *           + Peripheral Control functions
 | 
			
		||||
  *
 | 
			
		||||
  *  @verbatim
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
                        ##### How to use this driver #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
    [..]
 | 
			
		||||
    *** How to configure Interrupts using CORTEX HAL driver ***
 | 
			
		||||
    ===========================================================
 | 
			
		||||
    [..]
 | 
			
		||||
    This section provides functions allowing to configure the NVIC interrupts (IRQ).
 | 
			
		||||
    The Cortex-M4 exceptions are managed by CMSIS functions.
 | 
			
		||||
 | 
			
		||||
    (#) Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGrouping() function
 | 
			
		||||
 | 
			
		||||
     (#)  Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority()
 | 
			
		||||
 | 
			
		||||
     (#)  Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
     -@- When the NVIC_PRIORITYGROUP_0 is selected, IRQ pre-emption is no more possible.
 | 
			
		||||
         The pending IRQ priority will be managed only by the sub priority.
 | 
			
		||||
 | 
			
		||||
     -@- IRQ priority order (sorted by highest to lowest priority):
 | 
			
		||||
        (+@) Lowest pre-emption priority
 | 
			
		||||
        (+@) Lowest sub priority
 | 
			
		||||
        (+@) Lowest hardware priority (IRQ number)
 | 
			
		||||
 | 
			
		||||
    [..]
 | 
			
		||||
    *** How to configure Systick using CORTEX HAL driver ***
 | 
			
		||||
    ========================================================
 | 
			
		||||
    [..]
 | 
			
		||||
    Setup SysTick Timer for time base 
 | 
			
		||||
           
 | 
			
		||||
   (+) The HAL_SYSTICK_Config()function calls the SysTick_Config() function which
 | 
			
		||||
       is a CMSIS function that:
 | 
			
		||||
        (++) Configures the SysTick Reload register with value passed as function parameter.
 | 
			
		||||
        (++) Configures the SysTick IRQ priority to the lowest value (0x0FU).
 | 
			
		||||
        (++) Resets the SysTick Counter register.
 | 
			
		||||
        (++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK).
 | 
			
		||||
        (++) Enables the SysTick Interrupt.
 | 
			
		||||
        (++) Starts the SysTick Counter.
 | 
			
		||||
    
 | 
			
		||||
   (+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro
 | 
			
		||||
       __HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the
 | 
			
		||||
       HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined
 | 
			
		||||
       inside the stm32f3xx_hal_cortex.h file.
 | 
			
		||||
 | 
			
		||||
   (+) You can change the SysTick IRQ priority by calling the
 | 
			
		||||
       HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function 
 | 
			
		||||
       call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function.
 | 
			
		||||
 | 
			
		||||
   (+) To adjust the SysTick time base, use the following formula:
 | 
			
		||||
 | 
			
		||||
       Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s)
 | 
			
		||||
       (++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function
 | 
			
		||||
       (++) Reload Value should not exceed 0xFFFFFF
 | 
			
		||||
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file in
 | 
			
		||||
  * the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
  Additional Tables: CORTEX_NVIC_Priority_Table
 | 
			
		||||
     The table below gives the allowed values of the pre-emption priority and subpriority according
 | 
			
		||||
     to the Priority Grouping configuration performed by HAL_NVIC_SetPriorityGrouping() function
 | 
			
		||||
       ==========================================================================================================================
 | 
			
		||||
         NVIC_PriorityGroup   | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority  |       Description
 | 
			
		||||
       ==========================================================================================================================
 | 
			
		||||
        NVIC_PRIORITYGROUP_0  |                0                  |            0U-15             | 0 bits for pre-emption priority
 | 
			
		||||
                              |                                   |                             | 4 bits for subpriority
 | 
			
		||||
       --------------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
        NVIC_PRIORITYGROUP_1  |                0U-1                |            0U-7              | 1 bits for pre-emption priority
 | 
			
		||||
                              |                                   |                             | 3 bits for subpriority
 | 
			
		||||
       --------------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
        NVIC_PRIORITYGROUP_2  |                0U-3                |            0U-3              | 2 bits for pre-emption priority
 | 
			
		||||
                              |                                   |                             | 2 bits for subpriority
 | 
			
		||||
       --------------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
        NVIC_PRIORITYGROUP_3  |                0U-7                |            0U-1              | 3 bits for pre-emption priority
 | 
			
		||||
                              |                                   |                             | 1 bits for subpriority
 | 
			
		||||
       --------------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
        NVIC_PRIORITYGROUP_4  |                0U-15               |            0                | 4 bits for pre-emption priority
 | 
			
		||||
                              |                                   |                             | 0 bits for subpriority
 | 
			
		||||
       ==========================================================================================================================
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup CORTEX CORTEX
 | 
			
		||||
  * @brief CORTEX CORTEX HAL module driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef HAL_CORTEX_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private define ------------------------------------------------------------*/
 | 
			
		||||
/* Private macro -------------------------------------------------------------*/
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/* Exported functions ---------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
 | 
			
		||||
 *  @brief    Initialization and Configuration functions
 | 
			
		||||
 *
 | 
			
		||||
@verbatim
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
              ##### Initialization and de-initialization functions #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
    [..]
 | 
			
		||||
      This section provides the CORTEX HAL driver functions allowing to configure Interrupts
 | 
			
		||||
      Systick functionalities
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Sets the priority grouping field (pre-emption priority and subpriority)
 | 
			
		||||
  *         using the required unlock sequence.
 | 
			
		||||
  * @param  PriorityGroup The priority grouping bits length.
 | 
			
		||||
  *         This parameter can be one of the following values:
 | 
			
		||||
  *         @arg NVIC_PRIORITYGROUP_0: 0 bits for pre-emption priority
 | 
			
		||||
  *                                    4 bits for subpriority
 | 
			
		||||
  *         @arg NVIC_PRIORITYGROUP_1: 1 bits for pre-emption priority
 | 
			
		||||
  *                                    3 bits for subpriority
 | 
			
		||||
  *         @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority
 | 
			
		||||
  *                                    2 bits for subpriority
 | 
			
		||||
  *         @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority
 | 
			
		||||
  *                                    1 bits for subpriority
 | 
			
		||||
  *         @arg NVIC_PRIORITYGROUP_4: 4 bits for pre-emption priority
 | 
			
		||||
  *                                    0 bits for subpriority
 | 
			
		||||
  * @note   When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible.
 | 
			
		||||
  *         The pending IRQ priority will be managed only by the subpriority.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
 | 
			
		||||
 | 
			
		||||
  /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
 | 
			
		||||
  NVIC_SetPriorityGrouping(PriorityGroup);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Sets the priority of an interrupt.
 | 
			
		||||
  * @param  IRQn External interrupt number
 | 
			
		||||
  *         This parameter can be an enumerator of IRQn_Type enumeration
 | 
			
		||||
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f3xxxx.h))
 | 
			
		||||
  * @param  PreemptPriority The pre-emption priority for the IRQn channel.
 | 
			
		||||
  *         This parameter can be a value between 0 and 15 as described in the table CORTEX_NVIC_Priority_Table
 | 
			
		||||
  *         A lower priority value indicates a higher priority
 | 
			
		||||
  * @param  SubPriority the subpriority level for the IRQ channel.
 | 
			
		||||
  *         This parameter can be a value between 0 and 15 as described in the table CORTEX_NVIC_Priority_Table
 | 
			
		||||
  *         A lower priority value indicates a higher priority.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t prioritygroup = 0x00U;
 | 
			
		||||
  
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_NVIC_SUB_PRIORITY(SubPriority));
 | 
			
		||||
  assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));
 | 
			
		||||
  
 | 
			
		||||
  prioritygroup = NVIC_GetPriorityGrouping();
 | 
			
		||||
  
 | 
			
		||||
  NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Enables a device specific interrupt in the NVIC interrupt controller.
 | 
			
		||||
  * @note   To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
 | 
			
		||||
  *         function should be called before.
 | 
			
		||||
  * @param  IRQn External interrupt number
 | 
			
		||||
  *         This parameter can be an enumerator of IRQn_Type enumeration
 | 
			
		||||
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f3xxxx.h))
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
 | 
			
		||||
  
 | 
			
		||||
  /* Enable interrupt */
 | 
			
		||||
  NVIC_EnableIRQ(IRQn);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Disables a device specific interrupt in the NVIC interrupt controller.
 | 
			
		||||
  * @param  IRQn External interrupt number
 | 
			
		||||
  *         This parameter can be an enumerator of IRQn_Type enumeration
 | 
			
		||||
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f3xxxx.h))
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
 | 
			
		||||
  
 | 
			
		||||
  /* Disable interrupt */
 | 
			
		||||
  NVIC_DisableIRQ(IRQn);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Initiates a system reset request to reset the MCU.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_NVIC_SystemReset(void)
 | 
			
		||||
{
 | 
			
		||||
  /* System Reset */
 | 
			
		||||
  NVIC_SystemReset();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Initializes the System Timer and its interrupt, and starts the System Tick Timer.
 | 
			
		||||
  *         Counter is in free running mode to generate periodic interrupts.
 | 
			
		||||
  * @param  TicksNumb Specifies the ticks Number of ticks between two interrupts.
 | 
			
		||||
  * @retval status:  - 0  Function succeeded.
 | 
			
		||||
  *                  - 1  Function failed.
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
 | 
			
		||||
{
 | 
			
		||||
   return SysTick_Config(TicksNumb);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
 | 
			
		||||
 *  @brief   Cortex control functions
 | 
			
		||||
 *
 | 
			
		||||
@verbatim
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
                      ##### Peripheral Control functions #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
    [..]
 | 
			
		||||
      This subsection provides a set of functions allowing to control the CORTEX
 | 
			
		||||
      (NVIC, SYSTICK, MPU) functionalities.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#if (__MPU_PRESENT == 1U)
 | 
			
		||||
	
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Disables the MPU also clears the HFNMIENA bit (ARM recommendation) 
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_MPU_Disable(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Disable fault exceptions */
 | 
			
		||||
  SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
 | 
			
		||||
  
 | 
			
		||||
  /* Disable the MPU */
 | 
			
		||||
  MPU->CTRL = 0U;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Enables the MPU
 | 
			
		||||
  * @param  MPU_Control Specifies the control mode of the MPU during hard fault, 
 | 
			
		||||
  *          NMI, FAULTMASK and privileged access to the default memory 
 | 
			
		||||
  *          This parameter can be one of the following values:
 | 
			
		||||
  *            @arg MPU_HFNMI_PRIVDEF_NONE
 | 
			
		||||
  *            @arg MPU_HARDFAULT_NMI
 | 
			
		||||
  *            @arg MPU_PRIVILEGED_DEFAULT
 | 
			
		||||
  *            @arg MPU_HFNMI_PRIVDEF
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_MPU_Enable(uint32_t MPU_Control)
 | 
			
		||||
{
 | 
			
		||||
  /* Enable the MPU */
 | 
			
		||||
  MPU->CTRL   = MPU_Control | MPU_CTRL_ENABLE_Msk;
 | 
			
		||||
  
 | 
			
		||||
  /* Enable fault exceptions */
 | 
			
		||||
  SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
 | 
			
		||||
}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
  * @brief  Initializes and configures the Region and the memory to be protected.
 | 
			
		||||
  * @param  MPU_Init Pointer to a MPU_Region_InitTypeDef structure that contains
 | 
			
		||||
  *                the initialization and configuration information.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
 | 
			
		||||
  assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
 | 
			
		||||
 | 
			
		||||
  /* Set the Region number */
 | 
			
		||||
  MPU->RNR = MPU_Init->Number;
 | 
			
		||||
 | 
			
		||||
  if ((MPU_Init->Enable) != RESET)
 | 
			
		||||
  {
 | 
			
		||||
    /* Check the parameters */
 | 
			
		||||
    assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
 | 
			
		||||
    assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
 | 
			
		||||
    assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField));
 | 
			
		||||
    assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable));
 | 
			
		||||
    assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable));
 | 
			
		||||
    assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable));
 | 
			
		||||
    assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable));
 | 
			
		||||
    assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
 | 
			
		||||
    
 | 
			
		||||
    MPU->RBAR = MPU_Init->BaseAddress;
 | 
			
		||||
    MPU->RASR = ((uint32_t)MPU_Init->DisableExec             << MPU_RASR_XN_Pos)   |
 | 
			
		||||
                ((uint32_t)MPU_Init->AccessPermission        << MPU_RASR_AP_Pos)   |
 | 
			
		||||
                ((uint32_t)MPU_Init->TypeExtField            << MPU_RASR_TEX_Pos)  |
 | 
			
		||||
                ((uint32_t)MPU_Init->IsShareable             << MPU_RASR_S_Pos)    |
 | 
			
		||||
                ((uint32_t)MPU_Init->IsCacheable             << MPU_RASR_C_Pos)    |
 | 
			
		||||
                ((uint32_t)MPU_Init->IsBufferable            << MPU_RASR_B_Pos)    |
 | 
			
		||||
                ((uint32_t)MPU_Init->SubRegionDisable        << MPU_RASR_SRD_Pos)  |
 | 
			
		||||
                ((uint32_t)MPU_Init->Size                    << MPU_RASR_SIZE_Pos) |
 | 
			
		||||
                ((uint32_t)MPU_Init->Enable                  << MPU_RASR_ENABLE_Pos);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    MPU->RBAR = 0x00U;
 | 
			
		||||
    MPU->RASR = 0x00U;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
#endif /* __MPU_PRESENT */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Gets the priority grouping field from the NVIC Interrupt Controller.
 | 
			
		||||
  * @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_NVIC_GetPriorityGrouping(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Get the PRIGROUP[10:8] field value */
 | 
			
		||||
  return NVIC_GetPriorityGrouping();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Gets the priority of an interrupt.
 | 
			
		||||
  * @param  IRQn External interrupt number
 | 
			
		||||
  *         This parameter can be an enumerator of IRQn_Type enumeration
 | 
			
		||||
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f3xxxx.h))
 | 
			
		||||
  * @param   PriorityGroup: the priority grouping bits length.
 | 
			
		||||
  *         This parameter can be one of the following values:
 | 
			
		||||
  *           @arg NVIC_PRIORITYGROUP_0: 0 bits for pre-emption priority
 | 
			
		||||
  *                                      4 bits for subpriority
 | 
			
		||||
  *           @arg NVIC_PRIORITYGROUP_1: 1 bits for pre-emption priority
 | 
			
		||||
  *                                      3 bits for subpriority
 | 
			
		||||
  *           @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority
 | 
			
		||||
  *                                      2 bits for subpriority
 | 
			
		||||
  *           @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority
 | 
			
		||||
  *                                      1 bits for subpriority
 | 
			
		||||
  *           @arg NVIC_PRIORITYGROUP_4: 4 bits for pre-emption priority
 | 
			
		||||
  *                                      0 bits for subpriority
 | 
			
		||||
  * @param  pPreemptPriority Pointer on the Preemptive priority value (starting from 0).
 | 
			
		||||
  * @param  pSubPriority Pointer on the Subpriority value (starting from 0).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
 | 
			
		||||
  /* Get priority for Cortex-M system or device specific interrupts */
 | 
			
		||||
  NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Sets Pending bit of an external interrupt.
 | 
			
		||||
  * @param  IRQn External interrupt number
 | 
			
		||||
  *         This parameter can be an enumerator of IRQn_Type enumeration
 | 
			
		||||
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f3xxxx.h))
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
 | 
			
		||||
{
 | 
			
		||||
  /* Set interrupt pending */
 | 
			
		||||
  NVIC_SetPendingIRQ(IRQn);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Gets Pending Interrupt (reads the pending register in the NVIC
 | 
			
		||||
  *         and returns the pending bit for the specified interrupt).
 | 
			
		||||
  * @param  IRQn External interrupt number
 | 
			
		||||
  *         This parameter can be an enumerator of IRQn_Type enumeration
 | 
			
		||||
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f3xxxx.h))
 | 
			
		||||
  * @retval status: - 0  Interrupt status is not pending.
 | 
			
		||||
  *                 - 1  Interrupt status is pending.
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
 | 
			
		||||
{
 | 
			
		||||
  /* Return 1 if pending else 0U */
 | 
			
		||||
  return NVIC_GetPendingIRQ(IRQn);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Clears the pending bit of an external interrupt.
 | 
			
		||||
  * @param  IRQn External interrupt number
 | 
			
		||||
  *         This parameter can be an enumerator of IRQn_Type enumeration
 | 
			
		||||
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f3xxxx.h))
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
 | 
			
		||||
{
 | 
			
		||||
  /* Clear pending interrupt */
 | 
			
		||||
  NVIC_ClearPendingIRQ(IRQn);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Gets active interrupt ( reads the active register in NVIC and returns the active bit).
 | 
			
		||||
  * @param  IRQn External interrupt number
 | 
			
		||||
  *         This parameter can be an enumerator of IRQn_Type enumeration
 | 
			
		||||
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f3xxxx.h))
 | 
			
		||||
  * @retval status: - 0  Interrupt status is not pending.
 | 
			
		||||
  *                 - 1  Interrupt status is pending.
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
 | 
			
		||||
{
 | 
			
		||||
  /* Return 1 if active else 0U */
 | 
			
		||||
  return NVIC_GetActive(IRQn);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Configures the SysTick clock source.
 | 
			
		||||
  * @param  CLKSource specifies the SysTick clock source.
 | 
			
		||||
  *         This parameter can be one of the following values:
 | 
			
		||||
  *             @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
 | 
			
		||||
  *             @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
 | 
			
		||||
  if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
 | 
			
		||||
  {
 | 
			
		||||
    SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  This function handles SYSTICK interrupt request.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_SYSTICK_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  HAL_SYSTICK_Callback();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  SYSTICK callback.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_SYSTICK_Callback(void)
 | 
			
		||||
{
 | 
			
		||||
  /* NOTE : This function Should not be modified, when the callback is needed,
 | 
			
		||||
            the HAL_SYSTICK_Callback could be implemented in the user file
 | 
			
		||||
   */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,898 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal_dma.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   DMA HAL module driver.
 | 
			
		||||
  *    
 | 
			
		||||
  *         This file provides firmware functions to manage the following 
 | 
			
		||||
  *         functionalities of the Direct Memory Access (DMA) peripheral:
 | 
			
		||||
  *           + Initialization and de-initialization functions
 | 
			
		||||
  *           + IO operation functions
 | 
			
		||||
  *           + Peripheral State and errors functions
 | 
			
		||||
  @verbatim     
 | 
			
		||||
  ==============================================================================      
 | 
			
		||||
                        ##### How to use this driver #####
 | 
			
		||||
  ============================================================================== 
 | 
			
		||||
  [..]
 | 
			
		||||
   (#) Enable and configure the peripheral to be connected to the DMA Channel
 | 
			
		||||
       (except for internal SRAM / FLASH memories: no initialization is 
 | 
			
		||||
       necessary). Please refer to Reference manual for connection between peripherals
 | 
			
		||||
       and DMA requests .
 | 
			
		||||
 | 
			
		||||
   (#) For a given Channel, program the required configuration through the following parameters:   
 | 
			
		||||
       Transfer Direction, Source and Destination data formats, 
 | 
			
		||||
       Circular or Normal mode, Channel Priority level, Source and Destination Increment mode, 
 | 
			
		||||
       using HAL_DMA_Init() function.
 | 
			
		||||
 | 
			
		||||
   (#) Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error 
 | 
			
		||||
       detection.
 | 
			
		||||
                    
 | 
			
		||||
   (#) Use HAL_DMA_Abort() function to abort the current transfer
 | 
			
		||||
                   
 | 
			
		||||
     -@-   In Memory-to-Memory transfer mode, Circular mode is not allowed.
 | 
			
		||||
     *** Polling mode IO operation ***
 | 
			
		||||
     =================================   
 | 
			
		||||
    [..] 
 | 
			
		||||
      (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source 
 | 
			
		||||
          address and destination address and the Length of data to be transferred
 | 
			
		||||
      (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this  
 | 
			
		||||
          case a fixed Timeout can be configured by User depending from his application.
 | 
			
		||||
 | 
			
		||||
     *** Interrupt mode IO operation ***    
 | 
			
		||||
     =================================== 
 | 
			
		||||
    [..]
 | 
			
		||||
      (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority()
 | 
			
		||||
      (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ() 
 | 
			
		||||
      (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of  
 | 
			
		||||
          Source address and destination address and the Length of data to be transferred. 
 | 
			
		||||
          In this case the DMA interrupt is configured 
 | 
			
		||||
      (+) Use HAL_DMA_Channel_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine
 | 
			
		||||
      (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can 
 | 
			
		||||
          add his own function by customization of function pointer XferCpltCallback and 
 | 
			
		||||
          XferErrorCallback (i.e a member of DMA handle structure). 
 | 
			
		||||
 | 
			
		||||
     *** DMA HAL driver macros list ***
 | 
			
		||||
     ============================================= 
 | 
			
		||||
     [..]
 | 
			
		||||
       Below the list of most used macros in DMA HAL driver.
 | 
			
		||||
 | 
			
		||||
     [..] 
 | 
			
		||||
      (@) You can refer to the DMA HAL driver header file for more useful macros  
 | 
			
		||||
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file in
 | 
			
		||||
  * the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */ 
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup DMA DMA
 | 
			
		||||
  * @brief DMA HAL module driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef HAL_DMA_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private define ------------------------------------------------------------*/
 | 
			
		||||
/* Private macro -------------------------------------------------------------*/
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/** @defgroup DMA_Private_Functions DMA Private Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
 | 
			
		||||
static void DMA_CalcBaseAndBitshift(DMA_HandleTypeDef *hdma);
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Exported functions ---------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/** @defgroup DMA_Exported_Functions DMA Exported Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup DMA_Exported_Functions_Group1 Initialization and de-initialization functions
 | 
			
		||||
 *  @brief   Initialization and de-initialization functions 
 | 
			
		||||
 *
 | 
			
		||||
@verbatim   
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
             ##### Initialization and de-initialization functions  #####
 | 
			
		||||
 ===============================================================================  
 | 
			
		||||
    [..]
 | 
			
		||||
    This section provides functions allowing to initialize the DMA Channel source
 | 
			
		||||
    and destination addresses, incrementation and data sizes, transfer direction, 
 | 
			
		||||
    circular/normal mode selection, memory-to-memory mode selection and Channel priority value.
 | 
			
		||||
    [..]
 | 
			
		||||
    The HAL_DMA_Init() function follows the DMA configuration procedures as described in
 | 
			
		||||
    reference manual.  
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Initialize the DMA according to the specified
 | 
			
		||||
  *         parameters in the DMA_InitTypeDef and initialize the associated handle.
 | 
			
		||||
  * @param  hdma Pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *               the configuration information for the specified DMA Channel.  
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
 | 
			
		||||
{ 
 | 
			
		||||
  uint32_t tmp = 0U;
 | 
			
		||||
  
 | 
			
		||||
  /* Check the DMA handle allocation */
 | 
			
		||||
  if(NULL == hdma)
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
 | 
			
		||||
  assert_param(IS_DMA_DIRECTION(hdma->Init.Direction));
 | 
			
		||||
  assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc));
 | 
			
		||||
  assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc));
 | 
			
		||||
  assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment));
 | 
			
		||||
  assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment));
 | 
			
		||||
  assert_param(IS_DMA_MODE(hdma->Init.Mode));
 | 
			
		||||
  assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
 | 
			
		||||
  
 | 
			
		||||
  /* Change DMA peripheral state */
 | 
			
		||||
  hdma->State = HAL_DMA_STATE_BUSY;
 | 
			
		||||
 | 
			
		||||
  /* Get the CR register value */
 | 
			
		||||
  tmp = hdma->Instance->CCR;
 | 
			
		||||
  
 | 
			
		||||
  /* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR bits */
 | 
			
		||||
  tmp &= ((uint32_t)~(DMA_CCR_PL    | DMA_CCR_MSIZE  | DMA_CCR_PSIZE  | \
 | 
			
		||||
                      DMA_CCR_MINC  | DMA_CCR_PINC   | DMA_CCR_CIRC   | \
 | 
			
		||||
                      DMA_CCR_DIR));
 | 
			
		||||
  
 | 
			
		||||
  /* Prepare the DMA Channel configuration */
 | 
			
		||||
  tmp |=  hdma->Init.Direction        |
 | 
			
		||||
          hdma->Init.PeriphInc           | hdma->Init.MemInc           |
 | 
			
		||||
          hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
 | 
			
		||||
          hdma->Init.Mode                | hdma->Init.Priority;
 | 
			
		||||
 | 
			
		||||
  /* Write to DMA Channel CR register */
 | 
			
		||||
  hdma->Instance->CCR = tmp;  
 | 
			
		||||
  
 | 
			
		||||
  /* Initialize DmaBaseAddress and ChannelIndex parameters used 
 | 
			
		||||
     by HAL_DMA_IRQHandler() and HAL_DMA_PollForTransfer() */
 | 
			
		||||
  DMA_CalcBaseAndBitshift(hdma);
 | 
			
		||||
  
 | 
			
		||||
  /* Initialise the error code */
 | 
			
		||||
  hdma->ErrorCode = HAL_DMA_ERROR_NONE;
 | 
			
		||||
 | 
			
		||||
  /* Initialize the DMA state*/
 | 
			
		||||
  hdma->State = HAL_DMA_STATE_READY;
 | 
			
		||||
  
 | 
			
		||||
  /* Allocate lock resource and initialize it */
 | 
			
		||||
  hdma->Lock = HAL_UNLOCKED;
 | 
			
		||||
  
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}  
 | 
			
		||||
  
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  DeInitialize the DMA peripheral 
 | 
			
		||||
  * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *               the configuration information for the specified DMA Channel.  
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the DMA handle allocation */
 | 
			
		||||
  if(NULL == hdma)
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
 | 
			
		||||
 | 
			
		||||
  /* Disable the selected DMA Channelx */
 | 
			
		||||
  hdma->Instance->CCR &= ~DMA_CCR_EN;
 | 
			
		||||
 | 
			
		||||
  /* Reset DMA Channel control register */
 | 
			
		||||
  hdma->Instance->CCR  = 0U;
 | 
			
		||||
 | 
			
		||||
  /* Reset DMA Channel Number of Data to Transfer register */
 | 
			
		||||
  hdma->Instance->CNDTR = 0U;
 | 
			
		||||
 | 
			
		||||
  /* Reset DMA Channel peripheral address register */
 | 
			
		||||
  hdma->Instance->CPAR  = 0U;
 | 
			
		||||
  
 | 
			
		||||
  /* Reset DMA Channel memory address register */
 | 
			
		||||
  hdma->Instance->CMAR = 0U;
 | 
			
		||||
 | 
			
		||||
  /* Get DMA Base Address */  
 | 
			
		||||
  DMA_CalcBaseAndBitshift(hdma);
 | 
			
		||||
 | 
			
		||||
  /* Clear all flags */
 | 
			
		||||
  hdma->DmaBaseAddress->IFCR = DMA_FLAG_GL1 << hdma->ChannelIndex;
 | 
			
		||||
 | 
			
		||||
  /* Clean callbacks */
 | 
			
		||||
  hdma->XferCpltCallback = NULL;
 | 
			
		||||
  hdma->XferHalfCpltCallback = NULL;
 | 
			
		||||
  hdma->XferErrorCallback = NULL;
 | 
			
		||||
  hdma->XferAbortCallback = NULL;
 | 
			
		||||
 | 
			
		||||
  /* Reset the error code */
 | 
			
		||||
  hdma->ErrorCode = HAL_DMA_ERROR_NONE;
 | 
			
		||||
 | 
			
		||||
  /* Reset the DMA state */
 | 
			
		||||
  hdma->State = HAL_DMA_STATE_RESET;
 | 
			
		||||
 | 
			
		||||
  /* Release Lock */
 | 
			
		||||
  __HAL_UNLOCK(hdma);
 | 
			
		||||
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup DMA_Exported_Functions_Group2 Input and Output operation functions 
 | 
			
		||||
 *  @brief   I/O operation functions  
 | 
			
		||||
 *
 | 
			
		||||
@verbatim   
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                      #####  IO operation functions  #####
 | 
			
		||||
 ===============================================================================  
 | 
			
		||||
    [..]  This section provides functions allowing to:
 | 
			
		||||
      (+) Configure the source, destination address and data length and Start DMA transfer
 | 
			
		||||
      (+) Configure the source, destination address and data length and 
 | 
			
		||||
          Start DMA transfer with interrupt
 | 
			
		||||
      (+) Abort DMA transfer
 | 
			
		||||
      (+) Poll for transfer complete
 | 
			
		||||
      (+) Handle DMA interrupt request  
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Start the DMA Transfer.
 | 
			
		||||
  * @param  hdma      : pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *                     the configuration information for the specified DMA Channel.  
 | 
			
		||||
  * @param  SrcAddress The source memory Buffer address
 | 
			
		||||
  * @param  DstAddress The destination memory Buffer address
 | 
			
		||||
  * @param  DataLength The length of data to be transferred from source to destination
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
 | 
			
		||||
{
 | 
			
		||||
	HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_DMA_BUFFER_SIZE(DataLength));
 | 
			
		||||
  
 | 
			
		||||
  /* Process locked */
 | 
			
		||||
  __HAL_LOCK(hdma);
 | 
			
		||||
  
 | 
			
		||||
  if(HAL_DMA_STATE_READY == hdma->State)
 | 
			
		||||
  {
 | 
			
		||||
  	/* Change DMA peripheral state */  
 | 
			
		||||
  	hdma->State = HAL_DMA_STATE_BUSY;
 | 
			
		||||
  	
 | 
			
		||||
  	hdma->ErrorCode = HAL_DMA_ERROR_NONE;
 | 
			
		||||
  	
 | 
			
		||||
  	/* Disable the peripheral */
 | 
			
		||||
  	hdma->Instance->CCR &= ~DMA_CCR_EN;  
 | 
			
		||||
  	
 | 
			
		||||
  	/* Configure the source, destination address and the data length */
 | 
			
		||||
  	DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
 | 
			
		||||
  	
 | 
			
		||||
  	/* Enable the Peripheral */
 | 
			
		||||
  	hdma->Instance->CCR |= DMA_CCR_EN;  
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
  	/* Process Unlocked */
 | 
			
		||||
  	__HAL_UNLOCK(hdma);
 | 
			
		||||
  	
 | 
			
		||||
  	/* Remain BUSY */
 | 
			
		||||
  	status = HAL_BUSY;
 | 
			
		||||
  }  
 | 
			
		||||
 | 
			
		||||
  return status; 
 | 
			
		||||
} 
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Start the DMA Transfer with interrupt enabled.
 | 
			
		||||
  * @param  hdma       pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *                     the configuration information for the specified DMA Channel.  
 | 
			
		||||
  * @param  SrcAddress The source memory Buffer address
 | 
			
		||||
  * @param  DstAddress The destination memory Buffer address
 | 
			
		||||
  * @param  DataLength The length of data to be transferred from source to destination
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
 | 
			
		||||
{
 | 
			
		||||
	HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_DMA_BUFFER_SIZE(DataLength));
 | 
			
		||||
  
 | 
			
		||||
  /* Process locked */
 | 
			
		||||
  __HAL_LOCK(hdma);
 | 
			
		||||
  
 | 
			
		||||
  if(HAL_DMA_STATE_READY == hdma->State)
 | 
			
		||||
  {
 | 
			
		||||
  	/* Change DMA peripheral state */  
 | 
			
		||||
  	hdma->State = HAL_DMA_STATE_BUSY;
 | 
			
		||||
  	
 | 
			
		||||
  	hdma->ErrorCode = HAL_DMA_ERROR_NONE;
 | 
			
		||||
  	
 | 
			
		||||
  	/* Disable the peripheral */
 | 
			
		||||
  	hdma->Instance->CCR &= ~DMA_CCR_EN;
 | 
			
		||||
  	
 | 
			
		||||
  	/* Configure the source, destination address and the data length */  
 | 
			
		||||
  	DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
 | 
			
		||||
  	
 | 
			
		||||
  	/* Enable the transfer complete, & transfer error interrupts */
 | 
			
		||||
  	/* Half transfer interrupt is optional: enable it only if associated callback is available */
 | 
			
		||||
    if(NULL != hdma->XferHalfCpltCallback )
 | 
			
		||||
    {
 | 
			
		||||
      hdma->Instance->CCR |= (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE);
 | 
			
		||||
    }
 | 
			
		||||
  	else
 | 
			
		||||
  	{
 | 
			
		||||
  		hdma->Instance->CCR |= (DMA_IT_TC | DMA_IT_TE);
 | 
			
		||||
  		hdma->Instance->CCR &= ~DMA_IT_HT;
 | 
			
		||||
  	}
 | 
			
		||||
  	
 | 
			
		||||
  	/* Enable the Peripheral */
 | 
			
		||||
  	hdma->Instance->CCR |= DMA_CCR_EN;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
  	/* Process Unlocked */
 | 
			
		||||
    __HAL_UNLOCK(hdma); 
 | 
			
		||||
  
 | 
			
		||||
    /* Remain BUSY */
 | 
			
		||||
    status = HAL_BUSY;
 | 
			
		||||
  }     
 | 
			
		||||
  
 | 
			
		||||
  return status;    
 | 
			
		||||
} 
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Abort the DMA Transfer.
 | 
			
		||||
  * @param  hdma  : pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *                 the configuration information for the specified DMA Channel.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
 | 
			
		||||
{
 | 
			
		||||
  if(hdma->State != HAL_DMA_STATE_BUSY)
 | 
			
		||||
  {
 | 
			
		||||
    /* no transfer ongoing */
 | 
			
		||||
    hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
 | 
			
		||||
    
 | 
			
		||||
    /* Process Unlocked */
 | 
			
		||||
    __HAL_UNLOCK(hdma);
 | 
			
		||||
    
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    /* Disable DMA IT */
 | 
			
		||||
     hdma->Instance->CCR &= ~(DMA_IT_TC | DMA_IT_HT | DMA_IT_TE);
 | 
			
		||||
    
 | 
			
		||||
    /* Disable the channel */
 | 
			
		||||
    hdma->Instance->CCR &= ~DMA_CCR_EN;
 | 
			
		||||
    
 | 
			
		||||
    /* Clear all flags */
 | 
			
		||||
    hdma->DmaBaseAddress->IFCR = (DMA_FLAG_GL1 << hdma->ChannelIndex);
 | 
			
		||||
  }
 | 
			
		||||
  /* Change the DMA state*/
 | 
			
		||||
  hdma->State = HAL_DMA_STATE_READY; 
 | 
			
		||||
  
 | 
			
		||||
  /* Process Unlocked */
 | 
			
		||||
  __HAL_UNLOCK(hdma);
 | 
			
		||||
  
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Abort the DMA Transfer in Interrupt mode.
 | 
			
		||||
  * @param  hdma  : pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *                 the configuration information for the specified DMA Stream.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
 | 
			
		||||
{  
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
  
 | 
			
		||||
  if(HAL_DMA_STATE_BUSY != hdma->State)
 | 
			
		||||
  {
 | 
			
		||||
    /* no transfer ongoing */
 | 
			
		||||
    hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
 | 
			
		||||
        
 | 
			
		||||
    status = HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  { 
 | 
			
		||||
  
 | 
			
		||||
    /* Disable DMA IT */
 | 
			
		||||
    hdma->Instance->CCR &= ~(DMA_IT_TC | DMA_IT_HT | DMA_IT_TE);
 | 
			
		||||
    
 | 
			
		||||
    /* Disable the channel */
 | 
			
		||||
    hdma->Instance->CCR &= ~DMA_CCR_EN;
 | 
			
		||||
    
 | 
			
		||||
    /* Clear all flags */
 | 
			
		||||
    hdma->DmaBaseAddress->IFCR = DMA_FLAG_GL1 << hdma->ChannelIndex;
 | 
			
		||||
    
 | 
			
		||||
    /* Change the DMA state */
 | 
			
		||||
    hdma->State = HAL_DMA_STATE_READY;
 | 
			
		||||
    
 | 
			
		||||
    /* Process Unlocked */
 | 
			
		||||
    __HAL_UNLOCK(hdma);
 | 
			
		||||
    
 | 
			
		||||
    /* Call User Abort callback */ 
 | 
			
		||||
    if(hdma->XferAbortCallback != NULL)
 | 
			
		||||
    {
 | 
			
		||||
      hdma->XferAbortCallback(hdma);
 | 
			
		||||
    } 
 | 
			
		||||
  }
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Polling for transfer complete.
 | 
			
		||||
  * @param  hdma    pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *                  the configuration information for the specified DMA Channel.
 | 
			
		||||
  * @param  CompleteLevel Specifies the DMA level complete.  
 | 
			
		||||
  * @param  Timeout       Timeout duration.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t temp;
 | 
			
		||||
  uint32_t tickstart = 0U;
 | 
			
		||||
  
 | 
			
		||||
  if(HAL_DMA_STATE_BUSY != hdma->State)
 | 
			
		||||
  {
 | 
			
		||||
    /* no transfer ongoing */
 | 
			
		||||
    hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
 | 
			
		||||
    __HAL_UNLOCK(hdma);
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Polling mode not supported in circular mode */
 | 
			
		||||
  if (RESET != (hdma->Instance->CCR & DMA_CCR_CIRC))
 | 
			
		||||
  {
 | 
			
		||||
    hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Get the level transfer complete flag */
 | 
			
		||||
  if(HAL_DMA_FULL_TRANSFER == CompleteLevel)
 | 
			
		||||
  {
 | 
			
		||||
    /* Transfer Complete flag */
 | 
			
		||||
    temp = DMA_FLAG_TC1 << hdma->ChannelIndex;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    /* Half Transfer Complete flag */
 | 
			
		||||
    temp = DMA_FLAG_HT1 << hdma->ChannelIndex;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Get tick */
 | 
			
		||||
  tickstart = HAL_GetTick();
 | 
			
		||||
 | 
			
		||||
  while(RESET == (hdma->DmaBaseAddress->ISR & temp))
 | 
			
		||||
  {
 | 
			
		||||
    if(RESET != (hdma->DmaBaseAddress->ISR & (DMA_FLAG_TE1 << hdma->ChannelIndex)))
 | 
			
		||||
    {      
 | 
			
		||||
      /* When a DMA transfer error occurs */
 | 
			
		||||
      /* A hardware clear of its EN bits is performed */
 | 
			
		||||
      /* Clear all flags */
 | 
			
		||||
      hdma->DmaBaseAddress->IFCR = DMA_FLAG_GL1 << hdma->ChannelIndex;
 | 
			
		||||
      
 | 
			
		||||
      /* Update error code */
 | 
			
		||||
      hdma->ErrorCode = HAL_DMA_ERROR_TE;
 | 
			
		||||
 | 
			
		||||
      /* Change the DMA state */
 | 
			
		||||
      hdma->State= HAL_DMA_STATE_READY;       
 | 
			
		||||
      
 | 
			
		||||
      /* Process Unlocked */
 | 
			
		||||
      __HAL_UNLOCK(hdma);
 | 
			
		||||
      
 | 
			
		||||
      return HAL_ERROR;      
 | 
			
		||||
    }      
 | 
			
		||||
    /* Check for the Timeout */
 | 
			
		||||
    if(Timeout != HAL_MAX_DELAY)
 | 
			
		||||
    {
 | 
			
		||||
      if((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
 | 
			
		||||
      {
 | 
			
		||||
        /* Update error code */
 | 
			
		||||
        hdma->ErrorCode = HAL_DMA_ERROR_TIMEOUT;
 | 
			
		||||
        
 | 
			
		||||
        /* Change the DMA state */
 | 
			
		||||
        hdma->State = HAL_DMA_STATE_READY;
 | 
			
		||||
 | 
			
		||||
        /* Process Unlocked */
 | 
			
		||||
        __HAL_UNLOCK(hdma);
 | 
			
		||||
 | 
			
		||||
        return HAL_ERROR;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if(HAL_DMA_FULL_TRANSFER == CompleteLevel)
 | 
			
		||||
  {
 | 
			
		||||
    /* Clear the transfer complete flag */
 | 
			
		||||
    hdma->DmaBaseAddress->IFCR = DMA_FLAG_TC1 << hdma->ChannelIndex;
 | 
			
		||||
 | 
			
		||||
    /* The selected Channelx EN bit is cleared (DMA is disabled and 
 | 
			
		||||
    all transfers are complete) */
 | 
			
		||||
    hdma->State = HAL_DMA_STATE_READY;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  { 
 | 
			
		||||
    /* Clear the half transfer complete flag */
 | 
			
		||||
    hdma->DmaBaseAddress->IFCR = DMA_FLAG_HT1 << hdma->ChannelIndex;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Process unlocked */
 | 
			
		||||
  __HAL_UNLOCK(hdma);  
 | 
			
		||||
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Handle DMA interrupt request.
 | 
			
		||||
  * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *               the configuration information for the specified DMA Channel.  
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t flag_it = hdma->DmaBaseAddress->ISR;
 | 
			
		||||
  uint32_t source_it = hdma->Instance->CCR;
 | 
			
		||||
          
 | 
			
		||||
  /* Half Transfer Complete Interrupt management ******************************/
 | 
			
		||||
  if ((RESET != (flag_it & (DMA_FLAG_HT1 << hdma->ChannelIndex))) && (RESET != (source_it & DMA_IT_HT)))
 | 
			
		||||
  {
 | 
			
		||||
  	/* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
 | 
			
		||||
  	if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
 | 
			
		||||
  	{
 | 
			
		||||
  		/* Disable the half transfer interrupt */
 | 
			
		||||
  		hdma->Instance->CCR &= ~DMA_IT_HT;
 | 
			
		||||
  	}
 | 
			
		||||
  	
 | 
			
		||||
  	/* Clear the half transfer complete flag */
 | 
			
		||||
  	hdma->DmaBaseAddress->IFCR = DMA_FLAG_HT1 << hdma->ChannelIndex;
 | 
			
		||||
  	
 | 
			
		||||
  	/* DMA peripheral state is not updated in Half Transfer */
 | 
			
		||||
  	/* State is updated only in Transfer Complete case */
 | 
			
		||||
  	
 | 
			
		||||
  	if(hdma->XferHalfCpltCallback != NULL)
 | 
			
		||||
  	{
 | 
			
		||||
  		/* Half transfer callback */
 | 
			
		||||
  		hdma->XferHalfCpltCallback(hdma);
 | 
			
		||||
  	}
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Transfer Complete Interrupt management ***********************************/
 | 
			
		||||
  else if ((RESET != (flag_it & (DMA_FLAG_TC1 << hdma->ChannelIndex))) && (RESET != (source_it & DMA_IT_TC)))
 | 
			
		||||
  {
 | 
			
		||||
  	if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
 | 
			
		||||
  	{
 | 
			
		||||
  		/* Disable the transfer complete  & transfer error interrupts */
 | 
			
		||||
  		/* if the DMA mode is not CIRCULAR */
 | 
			
		||||
  		hdma->Instance->CCR &= ~(DMA_IT_TC | DMA_IT_TE);
 | 
			
		||||
  		
 | 
			
		||||
  		/* Change the DMA state */
 | 
			
		||||
  		hdma->State = HAL_DMA_STATE_READY;
 | 
			
		||||
  	}
 | 
			
		||||
  	
 | 
			
		||||
  	/* Clear the transfer complete flag */
 | 
			
		||||
  	hdma->DmaBaseAddress->IFCR = DMA_FLAG_TC1 << hdma->ChannelIndex;
 | 
			
		||||
  	
 | 
			
		||||
  	/* Process Unlocked */
 | 
			
		||||
  	__HAL_UNLOCK(hdma);
 | 
			
		||||
  	
 | 
			
		||||
  	if(hdma->XferCpltCallback != NULL)
 | 
			
		||||
  	{
 | 
			
		||||
  		/* Transfer complete callback */
 | 
			
		||||
  		hdma->XferCpltCallback(hdma);
 | 
			
		||||
  	}
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Transfer Error Interrupt management ***************************************/
 | 
			
		||||
  else if (( RESET != (flag_it & (DMA_FLAG_TE1 << hdma->ChannelIndex))) && (RESET != (source_it & DMA_IT_TE)))
 | 
			
		||||
  {
 | 
			
		||||
  	/* When a DMA transfer error occurs */
 | 
			
		||||
    /* A hardware clear of its EN bits is performed */
 | 
			
		||||
    /* Then, disable all DMA interrupts */
 | 
			
		||||
    hdma->Instance->CCR &= ~(DMA_IT_TC | DMA_IT_HT | DMA_IT_TE);
 | 
			
		||||
    
 | 
			
		||||
    /* Clear all flags */
 | 
			
		||||
    hdma->DmaBaseAddress->IFCR = DMA_FLAG_GL1 << hdma->ChannelIndex;
 | 
			
		||||
    
 | 
			
		||||
    /* Update error code */
 | 
			
		||||
    hdma->ErrorCode = HAL_DMA_ERROR_TE;
 | 
			
		||||
    
 | 
			
		||||
    /* Change the DMA state */
 | 
			
		||||
    hdma->State = HAL_DMA_STATE_READY;    
 | 
			
		||||
    
 | 
			
		||||
    /* Process Unlocked */
 | 
			
		||||
    __HAL_UNLOCK(hdma); 
 | 
			
		||||
    
 | 
			
		||||
    if(hdma->XferErrorCallback != NULL)
 | 
			
		||||
    {
 | 
			
		||||
    	/* Transfer error callback */
 | 
			
		||||
    	hdma->XferErrorCallback(hdma);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Register callbacks
 | 
			
		||||
  * @param  hdma                 pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *                               the configuration information for the specified DMA Stream.
 | 
			
		||||
  * @param  CallbackID           User Callback identifier
 | 
			
		||||
  *                               a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
 | 
			
		||||
  * @param  pCallback            pointer to private callback function which has pointer to 
 | 
			
		||||
  *                               a DMA_HandleTypeDef structure as parameter.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */                          
 | 
			
		||||
HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)( DMA_HandleTypeDef * _hdma))
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
  
 | 
			
		||||
  /* Process locked */
 | 
			
		||||
  __HAL_LOCK(hdma);
 | 
			
		||||
  
 | 
			
		||||
  if(HAL_DMA_STATE_READY == hdma->State)
 | 
			
		||||
  {
 | 
			
		||||
    switch (CallbackID)
 | 
			
		||||
    {
 | 
			
		||||
     case  HAL_DMA_XFER_CPLT_CB_ID:
 | 
			
		||||
           hdma->XferCpltCallback = pCallback;
 | 
			
		||||
           break;
 | 
			
		||||
       
 | 
			
		||||
     case  HAL_DMA_XFER_HALFCPLT_CB_ID:
 | 
			
		||||
           hdma->XferHalfCpltCallback = pCallback;
 | 
			
		||||
           break;         
 | 
			
		||||
 | 
			
		||||
     case  HAL_DMA_XFER_ERROR_CB_ID:
 | 
			
		||||
           hdma->XferErrorCallback = pCallback;
 | 
			
		||||
           break;         
 | 
			
		||||
           
 | 
			
		||||
     case  HAL_DMA_XFER_ABORT_CB_ID:
 | 
			
		||||
           hdma->XferAbortCallback = pCallback;
 | 
			
		||||
           break; 
 | 
			
		||||
           
 | 
			
		||||
     default:
 | 
			
		||||
           status = HAL_ERROR;
 | 
			
		||||
           break;                                                            
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    status = HAL_ERROR;
 | 
			
		||||
  } 
 | 
			
		||||
  
 | 
			
		||||
  /* Release Lock */
 | 
			
		||||
  __HAL_UNLOCK(hdma);
 | 
			
		||||
  
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  UnRegister callbacks
 | 
			
		||||
  * @param  hdma                 pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *                               the configuration information for the specified DMA Stream.
 | 
			
		||||
  * @param  CallbackID           User Callback identifier
 | 
			
		||||
  *                               a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */              
 | 
			
		||||
HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
 | 
			
		||||
    /* Process locked */
 | 
			
		||||
  __HAL_LOCK(hdma);
 | 
			
		||||
  
 | 
			
		||||
  if(HAL_DMA_STATE_READY == hdma->State)
 | 
			
		||||
  {
 | 
			
		||||
    switch (CallbackID)
 | 
			
		||||
    {
 | 
			
		||||
     case  HAL_DMA_XFER_CPLT_CB_ID:
 | 
			
		||||
           hdma->XferCpltCallback = NULL;
 | 
			
		||||
           break;
 | 
			
		||||
       
 | 
			
		||||
     case  HAL_DMA_XFER_HALFCPLT_CB_ID:
 | 
			
		||||
           hdma->XferHalfCpltCallback = NULL;
 | 
			
		||||
           break;         
 | 
			
		||||
 | 
			
		||||
     case  HAL_DMA_XFER_ERROR_CB_ID:
 | 
			
		||||
           hdma->XferErrorCallback = NULL;
 | 
			
		||||
           break;         
 | 
			
		||||
           
 | 
			
		||||
     case  HAL_DMA_XFER_ABORT_CB_ID:
 | 
			
		||||
           hdma->XferAbortCallback = NULL;
 | 
			
		||||
           break; 
 | 
			
		||||
     
 | 
			
		||||
    case   HAL_DMA_XFER_ALL_CB_ID:
 | 
			
		||||
           hdma->XferCpltCallback = NULL;
 | 
			
		||||
           hdma->XferHalfCpltCallback = NULL;
 | 
			
		||||
           hdma->XferErrorCallback = NULL;
 | 
			
		||||
           hdma->XferAbortCallback = NULL;
 | 
			
		||||
           break; 
 | 
			
		||||
     
 | 
			
		||||
    default:
 | 
			
		||||
           status = HAL_ERROR;
 | 
			
		||||
           break;                                                            
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    status = HAL_ERROR;
 | 
			
		||||
  } 
 | 
			
		||||
  
 | 
			
		||||
  /* Release Lock */
 | 
			
		||||
  __HAL_UNLOCK(hdma);
 | 
			
		||||
  
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup DMA_Exported_Functions_Group3 Peripheral State functions
 | 
			
		||||
 *  @brief    Peripheral State functions 
 | 
			
		||||
 *
 | 
			
		||||
@verbatim   
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                    ##### State and Errors functions #####
 | 
			
		||||
 ===============================================================================  
 | 
			
		||||
    [..]
 | 
			
		||||
    This subsection provides functions allowing to
 | 
			
		||||
      (+) Check the DMA state
 | 
			
		||||
      (+) Get error code
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */  
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Returns the DMA state.
 | 
			
		||||
  * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *               the configuration information for the specified DMA Channel.  
 | 
			
		||||
  * @retval HAL state
 | 
			
		||||
  */
 | 
			
		||||
HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
 | 
			
		||||
{
 | 
			
		||||
  return hdma->State;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Return the DMA error code
 | 
			
		||||
  * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *              the configuration information for the specified DMA Channel.
 | 
			
		||||
  * @retval DMA Error Code
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
 | 
			
		||||
{
 | 
			
		||||
  return hdma->ErrorCode;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup DMA_Private_Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Set the DMA Transfer parameters.
 | 
			
		||||
  * @param  hdma       pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *                     the configuration information for the specified DMA Channel.  
 | 
			
		||||
  * @param  SrcAddress The source memory Buffer address
 | 
			
		||||
  * @param  DstAddress The destination memory Buffer address
 | 
			
		||||
  * @param  DataLength The length of data to be transferred from source to destination
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
 | 
			
		||||
{
 | 
			
		||||
	/* Clear all flags */
 | 
			
		||||
  hdma->DmaBaseAddress->IFCR  = (DMA_FLAG_GL1 << hdma->ChannelIndex);
 | 
			
		||||
  
 | 
			
		||||
  /* Configure DMA Channel data length */
 | 
			
		||||
  hdma->Instance->CNDTR = DataLength;
 | 
			
		||||
  
 | 
			
		||||
  /* Peripheral to Memory */
 | 
			
		||||
  if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
 | 
			
		||||
  {   
 | 
			
		||||
    /* Configure DMA Channel destination address */
 | 
			
		||||
    hdma->Instance->CPAR = DstAddress;
 | 
			
		||||
    
 | 
			
		||||
    /* Configure DMA Channel source address */
 | 
			
		||||
    hdma->Instance->CMAR = SrcAddress;
 | 
			
		||||
  }
 | 
			
		||||
  /* Memory to Peripheral */
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    /* Configure DMA Channel source address */
 | 
			
		||||
    hdma->Instance->CPAR = SrcAddress;
 | 
			
		||||
    
 | 
			
		||||
    /* Configure DMA Channel destination address */
 | 
			
		||||
    hdma->Instance->CMAR = DstAddress;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Set the DMA base address and channel index depending on DMA instance
 | 
			
		||||
  * @param  hdma       pointer to a DMA_HandleTypeDef structure that contains
 | 
			
		||||
  *                     the configuration information for the specified DMA Stream. 
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
static void DMA_CalcBaseAndBitshift(DMA_HandleTypeDef *hdma)
 | 
			
		||||
{
 | 
			
		||||
#if defined (DMA2)
 | 
			
		||||
  /* calculation of the channel index */
 | 
			
		||||
  if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
 | 
			
		||||
  {
 | 
			
		||||
    /* DMA1 */
 | 
			
		||||
    hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2U;
 | 
			
		||||
    hdma->DmaBaseAddress = DMA1;
 | 
			
		||||
  }
 | 
			
		||||
  else 
 | 
			
		||||
  {
 | 
			
		||||
    /* DMA2 */
 | 
			
		||||
    hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2U;
 | 
			
		||||
    hdma->DmaBaseAddress = DMA2;
 | 
			
		||||
  }
 | 
			
		||||
#else
 | 
			
		||||
  /* calculation of the channel index */
 | 
			
		||||
  /* DMA1 */
 | 
			
		||||
  hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2U;
 | 
			
		||||
  hdma->DmaBaseAddress = DMA1;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
#endif /* HAL_DMA_MODULE_ENABLED */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
  /**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,619 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal_exti.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   EXTI HAL module driver.
 | 
			
		||||
  *          This file provides firmware functions to manage the following
 | 
			
		||||
  *          functionalities of the Extended Interrupts and events controller (EXTI) peripheral:
 | 
			
		||||
  *           + Initialization and de-initialization functions
 | 
			
		||||
  *           + IO operation functions
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2019 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file
 | 
			
		||||
  * in the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  @verbatim
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
                    ##### EXTI Peripheral features #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
  [..]
 | 
			
		||||
    (+) Each Exti line can be configured within this driver.
 | 
			
		||||
 | 
			
		||||
    (+) Exti line can be configured in 3 different modes
 | 
			
		||||
        (++) Interrupt
 | 
			
		||||
        (++) Event
 | 
			
		||||
        (++) Both of them
 | 
			
		||||
 | 
			
		||||
    (+) Configurable Exti lines can be configured with 3 different triggers
 | 
			
		||||
        (++) Rising
 | 
			
		||||
        (++) Falling
 | 
			
		||||
        (++) Both of them
 | 
			
		||||
 | 
			
		||||
    (+) When set in interrupt mode, configurable Exti lines have two different
 | 
			
		||||
        interrupts pending registers which allow to distinguish which transition
 | 
			
		||||
        occurs:
 | 
			
		||||
        (++) Rising edge pending interrupt
 | 
			
		||||
        (++) Falling
 | 
			
		||||
 | 
			
		||||
    (+) Exti lines 0 to 15 are linked to gpio pin number 0 to 15. Gpio port can
 | 
			
		||||
        be selected through multiplexer.
 | 
			
		||||
 | 
			
		||||
                     ##### How to use this driver #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
  [..]
 | 
			
		||||
 | 
			
		||||
    (#) Configure the EXTI line using HAL_EXTI_SetConfigLine().
 | 
			
		||||
        (++) Choose the interrupt line number by setting "Line" member from
 | 
			
		||||
             EXTI_ConfigTypeDef structure.
 | 
			
		||||
        (++) Configure the interrupt and/or event mode using "Mode" member from
 | 
			
		||||
             EXTI_ConfigTypeDef structure.
 | 
			
		||||
        (++) For configurable lines, configure rising and/or falling trigger
 | 
			
		||||
             "Trigger" member from EXTI_ConfigTypeDef structure.
 | 
			
		||||
        (++) For Exti lines linked to gpio, choose gpio port using "GPIOSel"
 | 
			
		||||
             member from GPIO_InitTypeDef structure.
 | 
			
		||||
 | 
			
		||||
    (#) Get current Exti configuration of a dedicated line using
 | 
			
		||||
        HAL_EXTI_GetConfigLine().
 | 
			
		||||
        (++) Provide exiting handle as parameter.
 | 
			
		||||
        (++) Provide pointer on EXTI_ConfigTypeDef structure as second parameter.
 | 
			
		||||
 | 
			
		||||
    (#) Clear Exti configuration of a dedicated line using HAL_EXTI_GetConfigLine().
 | 
			
		||||
        (++) Provide exiting handle as parameter.
 | 
			
		||||
 | 
			
		||||
    (#) Register callback to treat Exti interrupts using HAL_EXTI_RegisterCallback().
 | 
			
		||||
        (++) Provide exiting handle as first parameter.
 | 
			
		||||
        (++) Provide which callback will be registered using one value from
 | 
			
		||||
             EXTI_CallbackIDTypeDef.
 | 
			
		||||
        (++) Provide callback function pointer.
 | 
			
		||||
 | 
			
		||||
    (#) Get interrupt pending bit using HAL_EXTI_GetPending().
 | 
			
		||||
 | 
			
		||||
    (#) Clear interrupt pending bit using HAL_EXTI_GetPending().
 | 
			
		||||
 | 
			
		||||
    (#) Generate software interrupt using HAL_EXTI_GenerateSWI().
 | 
			
		||||
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup EXTI
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
/** MISRA C:2012 deviation rule has been granted for following rule:
 | 
			
		||||
  * Rule-18.1_b - Medium: Array `EXTICR' 1st subscript interval [0,7] may be out
 | 
			
		||||
  * of bounds [0,3] in following API :
 | 
			
		||||
  * HAL_EXTI_SetConfigLine
 | 
			
		||||
  * HAL_EXTI_GetConfigLine
 | 
			
		||||
  * HAL_EXTI_ClearConfigLine
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef HAL_EXTI_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private defines -----------------------------------------------------------*/
 | 
			
		||||
/** @defgroup EXTI_Private_Constants EXTI Private Constants
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define EXTI_MODE_OFFSET                    0x08u   /* 0x20: offset between CPU IMR/EMR registers */
 | 
			
		||||
#define EXTI_CONFIG_OFFSET                  0x08u   /* 0x20: offset between CPU Rising/Falling configuration registers */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Private macros ------------------------------------------------------------*/
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/* Exported functions --------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/** @addtogroup EXTI_Exported_Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup EXTI_Exported_Functions_Group1
 | 
			
		||||
  * @brief    Configuration functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
              ##### Configuration functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Set configuration of a dedicated Exti line.
 | 
			
		||||
  * @param  hexti Exti handle.
 | 
			
		||||
  * @param  pExtiConfig Pointer on EXTI configuration to be set.
 | 
			
		||||
  * @retval HAL Status.
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
 | 
			
		||||
{
 | 
			
		||||
  __IO uint32_t *regaddr;
 | 
			
		||||
  uint32_t regval;
 | 
			
		||||
  uint32_t linepos;
 | 
			
		||||
  uint32_t maskline;
 | 
			
		||||
  uint32_t offset;
 | 
			
		||||
 | 
			
		||||
  /* Check null pointer */
 | 
			
		||||
  if ((hexti == NULL) || (pExtiConfig == NULL))
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Check parameters */
 | 
			
		||||
  assert_param(IS_EXTI_LINE(pExtiConfig->Line));
 | 
			
		||||
  assert_param(IS_EXTI_MODE(pExtiConfig->Mode));
 | 
			
		||||
 | 
			
		||||
  /* Assign line number to handle */
 | 
			
		||||
  hexti->Line = pExtiConfig->Line;
 | 
			
		||||
 | 
			
		||||
  /* Compute line register offset and line mask */
 | 
			
		||||
  offset = ((pExtiConfig->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
 | 
			
		||||
  linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
 | 
			
		||||
  maskline = (1uL << linepos);
 | 
			
		||||
 | 
			
		||||
  /* Configure triggers for configurable lines */
 | 
			
		||||
  if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    assert_param(IS_EXTI_TRIGGER(pExtiConfig->Trigger));
 | 
			
		||||
 | 
			
		||||
    /* Configure rising trigger */
 | 
			
		||||
    regaddr = (&EXTI->RTSR + (EXTI_CONFIG_OFFSET * offset));
 | 
			
		||||
    regval = *regaddr;
 | 
			
		||||
 | 
			
		||||
    /* Mask or set line */
 | 
			
		||||
    if ((pExtiConfig->Trigger & EXTI_TRIGGER_RISING) != 0x00u)
 | 
			
		||||
    {
 | 
			
		||||
      regval |= maskline;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      regval &= ~maskline;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Store rising trigger mode */
 | 
			
		||||
    *regaddr = regval;
 | 
			
		||||
 | 
			
		||||
    /* Configure falling trigger */
 | 
			
		||||
    regaddr = (&EXTI->FTSR + (EXTI_CONFIG_OFFSET * offset));
 | 
			
		||||
    regval = *regaddr;
 | 
			
		||||
 | 
			
		||||
    /* Mask or set line */
 | 
			
		||||
    if ((pExtiConfig->Trigger & EXTI_TRIGGER_FALLING) != 0x00u)
 | 
			
		||||
    {
 | 
			
		||||
      regval |= maskline;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      regval &= ~maskline;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Store falling trigger mode */
 | 
			
		||||
    *regaddr = regval;
 | 
			
		||||
 | 
			
		||||
    /* Configure gpio port selection in case of gpio exti line */
 | 
			
		||||
    if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
 | 
			
		||||
    {
 | 
			
		||||
      assert_param(IS_EXTI_GPIO_PORT(pExtiConfig->GPIOSel));
 | 
			
		||||
      assert_param(IS_EXTI_GPIO_PIN(linepos));
 | 
			
		||||
 | 
			
		||||
      regval = SYSCFG->EXTICR[linepos >> 2u];
 | 
			
		||||
      regval &= ~(SYSCFG_EXTICR1_EXTI0 << (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
 | 
			
		||||
      regval |= (pExtiConfig->GPIOSel << (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
 | 
			
		||||
      SYSCFG->EXTICR[linepos >> 2u] = regval;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Configure interrupt mode : read current mode */
 | 
			
		||||
  regaddr = (&EXTI->IMR + (EXTI_MODE_OFFSET * offset));
 | 
			
		||||
  regval = *regaddr;
 | 
			
		||||
 | 
			
		||||
  /* Mask or set line */
 | 
			
		||||
  if ((pExtiConfig->Mode & EXTI_MODE_INTERRUPT) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    regval |= maskline;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    regval &= ~maskline;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Store interrupt mode */
 | 
			
		||||
  *regaddr = regval;
 | 
			
		||||
 | 
			
		||||
  /* Configure event mode : read current mode */
 | 
			
		||||
  regaddr = (&EXTI->EMR + (EXTI_MODE_OFFSET * offset));
 | 
			
		||||
  regval = *regaddr;
 | 
			
		||||
 | 
			
		||||
  /* Mask or set line */
 | 
			
		||||
  if ((pExtiConfig->Mode & EXTI_MODE_EVENT) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    regval |= maskline;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    regval &= ~maskline;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Store event mode */
 | 
			
		||||
  *regaddr = regval;
 | 
			
		||||
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Get configuration of a dedicated Exti line.
 | 
			
		||||
  * @param  hexti Exti handle.
 | 
			
		||||
  * @param  pExtiConfig Pointer on structure to store Exti configuration.
 | 
			
		||||
  * @retval HAL Status.
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
 | 
			
		||||
{
 | 
			
		||||
  __IO uint32_t *regaddr;
 | 
			
		||||
  uint32_t regval;
 | 
			
		||||
  uint32_t linepos;
 | 
			
		||||
  uint32_t maskline;
 | 
			
		||||
  uint32_t offset;
 | 
			
		||||
 | 
			
		||||
  /* Check null pointer */
 | 
			
		||||
  if ((hexti == NULL) || (pExtiConfig == NULL))
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Check the parameter */
 | 
			
		||||
  assert_param(IS_EXTI_LINE(hexti->Line));
 | 
			
		||||
 | 
			
		||||
  /* Store handle line number to configuration structure */
 | 
			
		||||
  pExtiConfig->Line = hexti->Line;
 | 
			
		||||
 | 
			
		||||
  /* compute line register offset and line mask */
 | 
			
		||||
  offset = ((pExtiConfig->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
 | 
			
		||||
  linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
 | 
			
		||||
  maskline = (1uL << linepos);
 | 
			
		||||
 | 
			
		||||
  /* 1] Get core mode : interrupt */
 | 
			
		||||
  regaddr = (&EXTI->IMR + (EXTI_MODE_OFFSET * offset));
 | 
			
		||||
  regval = *regaddr;
 | 
			
		||||
 | 
			
		||||
  /* Check if selected line is enable */
 | 
			
		||||
  if ((regval & maskline) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    pExtiConfig->Mode = EXTI_MODE_INTERRUPT;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    pExtiConfig->Mode = EXTI_MODE_NONE;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Get event mode */
 | 
			
		||||
  regaddr = (&EXTI->EMR + (EXTI_MODE_OFFSET * offset));
 | 
			
		||||
  regval = *regaddr;
 | 
			
		||||
 | 
			
		||||
  /* Check if selected line is enable */
 | 
			
		||||
  if ((regval & maskline) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    pExtiConfig->Mode |= EXTI_MODE_EVENT;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Get default Trigger and GPIOSel configuration */
 | 
			
		||||
  pExtiConfig->Trigger = EXTI_TRIGGER_NONE;
 | 
			
		||||
  pExtiConfig->GPIOSel = 0x00u;
 | 
			
		||||
 | 
			
		||||
  /* 2] Get trigger for configurable lines : rising */
 | 
			
		||||
  if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    regaddr = (&EXTI->RTSR + (EXTI_CONFIG_OFFSET * offset));
 | 
			
		||||
    regval = *regaddr;
 | 
			
		||||
 | 
			
		||||
    /* Check if configuration of selected line is enable */
 | 
			
		||||
    if ((regval & maskline) != 0x00u)
 | 
			
		||||
    {
 | 
			
		||||
      pExtiConfig->Trigger = EXTI_TRIGGER_RISING;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Get falling configuration */
 | 
			
		||||
    regaddr = (&EXTI->FTSR + (EXTI_CONFIG_OFFSET * offset));
 | 
			
		||||
    regval = *regaddr;
 | 
			
		||||
 | 
			
		||||
    /* Check if configuration of selected line is enable */
 | 
			
		||||
    if ((regval & maskline) != 0x00u)
 | 
			
		||||
    {
 | 
			
		||||
      pExtiConfig->Trigger |= EXTI_TRIGGER_FALLING;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Get Gpio port selection for gpio lines */
 | 
			
		||||
    if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
 | 
			
		||||
    {
 | 
			
		||||
      assert_param(IS_EXTI_GPIO_PIN(linepos));
 | 
			
		||||
 | 
			
		||||
      regval = SYSCFG->EXTICR[linepos >> 2u];
 | 
			
		||||
      pExtiConfig->GPIOSel = (regval >> (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03u))) & SYSCFG_EXTICR1_EXTI0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Clear whole configuration of a dedicated Exti line.
 | 
			
		||||
  * @param  hexti Exti handle.
 | 
			
		||||
  * @retval HAL Status.
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti)
 | 
			
		||||
{
 | 
			
		||||
  __IO uint32_t *regaddr;
 | 
			
		||||
  uint32_t regval;
 | 
			
		||||
  uint32_t linepos;
 | 
			
		||||
  uint32_t maskline;
 | 
			
		||||
  uint32_t offset;
 | 
			
		||||
 | 
			
		||||
  /* Check null pointer */
 | 
			
		||||
  if (hexti == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Check the parameter */
 | 
			
		||||
  assert_param(IS_EXTI_LINE(hexti->Line));
 | 
			
		||||
 | 
			
		||||
  /* compute line register offset and line mask */
 | 
			
		||||
  offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
 | 
			
		||||
  linepos = (hexti->Line & EXTI_PIN_MASK);
 | 
			
		||||
  maskline = (1uL << linepos);
 | 
			
		||||
 | 
			
		||||
  /* 1] Clear interrupt mode */
 | 
			
		||||
  regaddr = (&EXTI->IMR + (EXTI_MODE_OFFSET * offset));
 | 
			
		||||
  regval = (*regaddr & ~maskline);
 | 
			
		||||
  *regaddr = regval;
 | 
			
		||||
 | 
			
		||||
  /* 2] Clear event mode */
 | 
			
		||||
  regaddr = (&EXTI->EMR + (EXTI_MODE_OFFSET * offset));
 | 
			
		||||
  regval = (*regaddr & ~maskline);
 | 
			
		||||
  *regaddr = regval;
 | 
			
		||||
 | 
			
		||||
  /* 3] Clear triggers in case of configurable lines */
 | 
			
		||||
  if ((hexti->Line & EXTI_CONFIG) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    regaddr = (&EXTI->RTSR + (EXTI_CONFIG_OFFSET * offset));
 | 
			
		||||
    regval = (*regaddr & ~maskline);
 | 
			
		||||
    *regaddr = regval;
 | 
			
		||||
 | 
			
		||||
    regaddr = (&EXTI->FTSR + (EXTI_CONFIG_OFFSET * offset));
 | 
			
		||||
    regval = (*regaddr & ~maskline);
 | 
			
		||||
    *regaddr = regval;
 | 
			
		||||
 | 
			
		||||
    /* Get Gpio port selection for gpio lines */
 | 
			
		||||
    if ((hexti->Line & EXTI_GPIO) == EXTI_GPIO)
 | 
			
		||||
    {
 | 
			
		||||
      assert_param(IS_EXTI_GPIO_PIN(linepos));
 | 
			
		||||
 | 
			
		||||
      regval = SYSCFG->EXTICR[linepos >> 2u];
 | 
			
		||||
      regval &= ~(SYSCFG_EXTICR1_EXTI0 << (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
 | 
			
		||||
      SYSCFG->EXTICR[linepos >> 2u] = regval;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Register callback for a dedicated Exti line.
 | 
			
		||||
  * @param  hexti Exti handle.
 | 
			
		||||
  * @param  CallbackID User callback identifier.
 | 
			
		||||
  *         This parameter can be one of @arg @ref EXTI_CallbackIDTypeDef values.
 | 
			
		||||
  * @param  pPendingCbfn function pointer to be stored as callback.
 | 
			
		||||
  * @retval HAL Status.
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, void (*pPendingCbfn)(void))
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
 | 
			
		||||
  switch (CallbackID)
 | 
			
		||||
  {
 | 
			
		||||
    case  HAL_EXTI_COMMON_CB_ID:
 | 
			
		||||
      hexti->PendingCallback = pPendingCbfn;
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
      status = HAL_ERROR;
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Store line number as handle private field.
 | 
			
		||||
  * @param  hexti Exti handle.
 | 
			
		||||
  * @param  ExtiLine Exti line number.
 | 
			
		||||
  *         This parameter can be from 0 to @ref EXTI_LINE_NB.
 | 
			
		||||
  * @retval HAL Status.
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_EXTI_LINE(ExtiLine));
 | 
			
		||||
 | 
			
		||||
  /* Check null pointer */
 | 
			
		||||
  if (hexti == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    /* Store line number as handle private field */
 | 
			
		||||
    hexti->Line = ExtiLine;
 | 
			
		||||
 | 
			
		||||
    return HAL_OK;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup EXTI_Exported_Functions_Group2
 | 
			
		||||
  *  @brief EXTI IO functions.
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                       ##### IO operation functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Handle EXTI interrupt request.
 | 
			
		||||
  * @param  hexti Exti handle.
 | 
			
		||||
  * @retval none.
 | 
			
		||||
  */
 | 
			
		||||
void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti)
 | 
			
		||||
{
 | 
			
		||||
  __IO uint32_t *regaddr;
 | 
			
		||||
  uint32_t regval;
 | 
			
		||||
  uint32_t maskline;
 | 
			
		||||
  uint32_t offset;
 | 
			
		||||
 | 
			
		||||
  /* Compute line register offset and line mask */
 | 
			
		||||
  offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
 | 
			
		||||
  maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
 | 
			
		||||
 | 
			
		||||
  /* Get pending bit  */
 | 
			
		||||
  regaddr = (&EXTI->PR + (EXTI_CONFIG_OFFSET * offset));
 | 
			
		||||
  regval = (*regaddr & maskline);
 | 
			
		||||
 | 
			
		||||
  if (regval != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    /* Clear pending bit */
 | 
			
		||||
    EXTI->PR = maskline;
 | 
			
		||||
 | 
			
		||||
    /* Call callback */
 | 
			
		||||
    if (hexti->PendingCallback != NULL)
 | 
			
		||||
    {
 | 
			
		||||
      hexti->PendingCallback();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Get interrupt pending bit of a dedicated line.
 | 
			
		||||
  * @param  hexti Exti handle.
 | 
			
		||||
  * @param  Edge Specify which pending edge as to be checked.
 | 
			
		||||
  *         This parameter can be one of the following values:
 | 
			
		||||
  *           @arg @ref EXTI_TRIGGER_RISING_FALLING
 | 
			
		||||
  *         This parameter is kept for compatibility with other series.
 | 
			
		||||
  * @retval 1 if interrupt is pending else 0.
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
 | 
			
		||||
{
 | 
			
		||||
  __IO uint32_t *regaddr;
 | 
			
		||||
  uint32_t regval;
 | 
			
		||||
  uint32_t linepos;
 | 
			
		||||
  uint32_t maskline;
 | 
			
		||||
  uint32_t offset;
 | 
			
		||||
 | 
			
		||||
  /* Check parameters */
 | 
			
		||||
  assert_param(IS_EXTI_LINE(hexti->Line));
 | 
			
		||||
  assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
 | 
			
		||||
  assert_param(IS_EXTI_PENDING_EDGE(Edge));
 | 
			
		||||
 | 
			
		||||
  /* compute line register offset and line mask */
 | 
			
		||||
  offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
 | 
			
		||||
  linepos = (hexti->Line & EXTI_PIN_MASK);
 | 
			
		||||
  maskline = (1uL << linepos);
 | 
			
		||||
 | 
			
		||||
  /* Get pending bit  */
 | 
			
		||||
  regaddr = (&EXTI->PR + (EXTI_CONFIG_OFFSET * offset));
 | 
			
		||||
  /* return 1 if bit is set else 0 */
 | 
			
		||||
  regval = ((*regaddr & maskline) >> linepos);
 | 
			
		||||
  return regval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Clear interrupt pending bit of a dedicated line.
 | 
			
		||||
  * @param  hexti Exti handle.
 | 
			
		||||
  * @param  Edge Specify which pending edge as to be clear.
 | 
			
		||||
  *         This parameter can be one of the following values:
 | 
			
		||||
  *           @arg @ref EXTI_TRIGGER_RISING_FALLING
 | 
			
		||||
  *         This parameter is kept for compatibility with other series.
 | 
			
		||||
  * @retval None.
 | 
			
		||||
  */
 | 
			
		||||
void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
 | 
			
		||||
{
 | 
			
		||||
  __IO uint32_t *regaddr;
 | 
			
		||||
  uint32_t maskline;
 | 
			
		||||
  uint32_t offset;
 | 
			
		||||
 | 
			
		||||
  /* Check parameters */
 | 
			
		||||
  assert_param(IS_EXTI_LINE(hexti->Line));
 | 
			
		||||
  assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
 | 
			
		||||
  assert_param(IS_EXTI_PENDING_EDGE(Edge));
 | 
			
		||||
 | 
			
		||||
  /* compute line register offset and line mask */
 | 
			
		||||
  offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
 | 
			
		||||
  maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
 | 
			
		||||
 | 
			
		||||
  /* Get pending bit  */
 | 
			
		||||
  regaddr = (&EXTI->PR + (EXTI_CONFIG_OFFSET * offset));
 | 
			
		||||
 | 
			
		||||
  /* Clear Pending bit */
 | 
			
		||||
  *regaddr =  maskline;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Generate a software interrupt for a dedicated line.
 | 
			
		||||
  * @param  hexti Exti handle.
 | 
			
		||||
  * @retval None.
 | 
			
		||||
  */
 | 
			
		||||
void HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti)
 | 
			
		||||
{
 | 
			
		||||
  __IO uint32_t *regaddr;
 | 
			
		||||
  uint32_t maskline;
 | 
			
		||||
  uint32_t offset;
 | 
			
		||||
 | 
			
		||||
  /* Check parameters */
 | 
			
		||||
  assert_param(IS_EXTI_LINE(hexti->Line));
 | 
			
		||||
  assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));
 | 
			
		||||
 | 
			
		||||
  /* compute line register offset and line mask */
 | 
			
		||||
  offset = ((hexti->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT);
 | 
			
		||||
  maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
 | 
			
		||||
 | 
			
		||||
  regaddr = (&EXTI->SWIER + (EXTI_CONFIG_OFFSET * offset));
 | 
			
		||||
  *regaddr = maskline;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif /* HAL_EXTI_MODULE_ENABLED */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,692 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal_flash.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   FLASH HAL module driver.
 | 
			
		||||
  *          This file provides firmware functions to manage the following 
 | 
			
		||||
  *          functionalities of the internal FLASH memory:
 | 
			
		||||
  *           + Program operations functions
 | 
			
		||||
  *           + Memory Control functions 
 | 
			
		||||
  *           + Peripheral State functions
 | 
			
		||||
  *         
 | 
			
		||||
  @verbatim
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
                        ##### FLASH peripheral features #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
  [..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses 
 | 
			
		||||
       to the Flash memory. It implements the erase and program Flash memory operations 
 | 
			
		||||
       and the read and write protection mechanisms.
 | 
			
		||||
 | 
			
		||||
  [..] The Flash memory interface accelerates code execution with a system of instruction
 | 
			
		||||
      prefetch. 
 | 
			
		||||
 | 
			
		||||
  [..] The FLASH main features are:
 | 
			
		||||
      (+) Flash memory read operations
 | 
			
		||||
      (+) Flash memory program/erase operations
 | 
			
		||||
      (+) Read / write protections
 | 
			
		||||
      (+) Prefetch on I-Code
 | 
			
		||||
      (+) Option Bytes programming
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                     ##### How to use this driver #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
  [..]                             
 | 
			
		||||
      This driver provides functions and macros to configure and program the FLASH 
 | 
			
		||||
      memory of all STM32F3xx devices.
 | 
			
		||||
    
 | 
			
		||||
      (#) FLASH Memory I/O Programming functions: this group includes all needed
 | 
			
		||||
          functions to erase and program the main memory:
 | 
			
		||||
        (++) Lock and Unlock the FLASH interface
 | 
			
		||||
        (++) Erase function: Erase page, erase all pages
 | 
			
		||||
        (++) Program functions: half word, word and doubleword
 | 
			
		||||
      (#) FLASH Option Bytes Programming functions: this group includes all needed
 | 
			
		||||
          functions to manage the Option Bytes:
 | 
			
		||||
        (++) Lock and Unlock the Option Bytes
 | 
			
		||||
        (++) Set/Reset the write protection
 | 
			
		||||
        (++) Set the Read protection Level
 | 
			
		||||
        (++) Program the user Option Bytes
 | 
			
		||||
        (++) Launch the Option Bytes loader
 | 
			
		||||
        (++) Erase Option Bytes
 | 
			
		||||
        (++) Program the data Option Bytes
 | 
			
		||||
        (++) Get the Write protection.
 | 
			
		||||
        (++) Get the user option bytes.
 | 
			
		||||
    
 | 
			
		||||
      (#) Interrupts and flags management functions : this group 
 | 
			
		||||
          includes all needed functions to:
 | 
			
		||||
        (++) Handle FLASH interrupts
 | 
			
		||||
        (++) Wait for last FLASH operation according to its status
 | 
			
		||||
        (++) Get error flag status
 | 
			
		||||
 | 
			
		||||
  [..] In addition to these function, this driver includes a set of macros allowing
 | 
			
		||||
       to handle the following operations:
 | 
			
		||||
      
 | 
			
		||||
      (+) Set/Get the latency
 | 
			
		||||
      (+) Enable/Disable the prefetch buffer
 | 
			
		||||
      (+) Enable/Disable the half cycle access
 | 
			
		||||
      (+) Enable/Disable the FLASH interrupts
 | 
			
		||||
      (+) Monitor the FLASH flags status
 | 
			
		||||
          
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file in
 | 
			
		||||
  * the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef HAL_FLASH_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/** @defgroup FLASH FLASH
 | 
			
		||||
  * @brief FLASH HAL module driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private define ------------------------------------------------------------*/
 | 
			
		||||
/** @defgroup FLASH_Private_Constants FLASH Private Constants
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Private macro ---------------------------- ---------------------------------*/
 | 
			
		||||
/** @defgroup FLASH_Private_Macros FLASH Private Macros
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/** @defgroup FLASH_Private_Variables FLASH Private Variables
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
/* Variables used for Erase pages under interruption*/
 | 
			
		||||
FLASH_ProcessTypeDef pFlash;
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/** @defgroup FLASH_Private_Functions FLASH Private Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
static  void   FLASH_Program_HalfWord(uint32_t Address, uint16_t Data);
 | 
			
		||||
static  void   FLASH_SetErrorCode(void);
 | 
			
		||||
extern void    FLASH_PageErase(uint32_t PageAddress);
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Exported functions ---------------------------------------------------------*/
 | 
			
		||||
/** @defgroup FLASH_Exported_Functions FLASH Exported Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
/** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions 
 | 
			
		||||
  *  @brief   Programming operation functions 
 | 
			
		||||
  *
 | 
			
		||||
@verbatim   
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Program halfword, word or double word at a specified address
 | 
			
		||||
  * @note   The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
 | 
			
		||||
  *         The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
 | 
			
		||||
  *
 | 
			
		||||
  * @note   If an erase and a program operations are requested simultaneously,    
 | 
			
		||||
  *         the erase operation is performed before the program one.
 | 
			
		||||
  *  
 | 
			
		||||
  * @note   FLASH should be previously erased before new programming (only exception to this 
 | 
			
		||||
  *         is when 0x0000 is programmed)
 | 
			
		||||
  *
 | 
			
		||||
  * @param  TypeProgram   Indicate the way to program at a specified address.
 | 
			
		||||
  *                       This parameter can be a value of @ref FLASH_Type_Program
 | 
			
		||||
  * @param  Address       Specifie the address to be programmed.
 | 
			
		||||
  * @param  Data          Specifie the data to be programmed
 | 
			
		||||
  * 
 | 
			
		||||
  * @retval HAL_StatusTypeDef HAL Status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_ERROR;
 | 
			
		||||
  uint8_t index = 0U;
 | 
			
		||||
  uint8_t nbiterations = 0U;
 | 
			
		||||
  
 | 
			
		||||
  /* Process Locked */
 | 
			
		||||
  __HAL_LOCK(&pFlash);
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
 | 
			
		||||
  assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
 | 
			
		||||
 | 
			
		||||
    /* Wait for last operation to be completed */
 | 
			
		||||
    status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
 | 
			
		||||
  
 | 
			
		||||
  if(status == HAL_OK)
 | 
			
		||||
  {
 | 
			
		||||
    if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
 | 
			
		||||
    {
 | 
			
		||||
      /* Program halfword (16-bit) at a specified address. */
 | 
			
		||||
      nbiterations = 1U;
 | 
			
		||||
    }
 | 
			
		||||
    else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
 | 
			
		||||
    {
 | 
			
		||||
      /* Program word (32-bit = 2*16-bit) at a specified address. */
 | 
			
		||||
      nbiterations = 2U;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      /* Program double word (64-bit = 4*16-bit) at a specified address. */
 | 
			
		||||
      nbiterations = 4U;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (index = 0U; index < nbiterations; index++)
 | 
			
		||||
    {
 | 
			
		||||
      FLASH_Program_HalfWord((Address + (2U*index)), (uint16_t)(Data >> (16U*index)));
 | 
			
		||||
 | 
			
		||||
        /* Wait for last operation to be completed */
 | 
			
		||||
        status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
 | 
			
		||||
    
 | 
			
		||||
        /* If the program operation is completed, disable the PG Bit */
 | 
			
		||||
        CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
 | 
			
		||||
      /* In case of error, stop programming procedure */
 | 
			
		||||
      if (status != HAL_OK)
 | 
			
		||||
      {
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Process Unlocked */
 | 
			
		||||
  __HAL_UNLOCK(&pFlash);
 | 
			
		||||
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Program halfword, word or double word at a specified address  with interrupt enabled.
 | 
			
		||||
  * @note   The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
 | 
			
		||||
  *         The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
 | 
			
		||||
  *
 | 
			
		||||
  * @note   If an erase and a program operations are requested simultaneously,    
 | 
			
		||||
  *         the erase operation is performed before the program one.
 | 
			
		||||
  *
 | 
			
		||||
  * @param  TypeProgram  Indicate the way to program at a specified address.
 | 
			
		||||
  *                      This parameter can be a value of @ref FLASH_Type_Program
 | 
			
		||||
  * @param  Address      Specifie the address to be programmed.
 | 
			
		||||
  * @param  Data         Specifie the data to be programmed
 | 
			
		||||
  * 
 | 
			
		||||
  * @retval HAL_StatusTypeDef HAL Status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
  
 | 
			
		||||
  /* Process Locked */
 | 
			
		||||
  __HAL_LOCK(&pFlash);
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
 | 
			
		||||
  assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
 | 
			
		||||
 | 
			
		||||
  /* Enable End of FLASH Operation and Error source interrupts */
 | 
			
		||||
  __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR);
 | 
			
		||||
  
 | 
			
		||||
  pFlash.Address = Address;
 | 
			
		||||
  pFlash.Data = Data;
 | 
			
		||||
 | 
			
		||||
  if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
 | 
			
		||||
  {
 | 
			
		||||
    pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMHALFWORD;
 | 
			
		||||
    /* Program halfword (16-bit) at a specified address. */
 | 
			
		||||
    pFlash.DataRemaining = 1U;
 | 
			
		||||
  }
 | 
			
		||||
  else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
 | 
			
		||||
  {
 | 
			
		||||
    pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMWORD;
 | 
			
		||||
    /* Program word (32-bit : 2*16-bit) at a specified address. */
 | 
			
		||||
    pFlash.DataRemaining = 2U;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMDOUBLEWORD;
 | 
			
		||||
    /* Program double word (64-bit : 4*16-bit) at a specified address. */
 | 
			
		||||
    pFlash.DataRemaining = 4U;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Program halfword (16-bit) at a specified address. */
 | 
			
		||||
  FLASH_Program_HalfWord(Address, (uint16_t)Data);
 | 
			
		||||
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function handles FLASH interrupt request.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_FLASH_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t addresstmp = 0U;
 | 
			
		||||
  
 | 
			
		||||
  /* Check FLASH operation error flags */
 | 
			
		||||
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
 | 
			
		||||
  {
 | 
			
		||||
    /* Return the faulty address */
 | 
			
		||||
    addresstmp = pFlash.Address;
 | 
			
		||||
    /* Reset address */
 | 
			
		||||
    pFlash.Address = 0xFFFFFFFFU;
 | 
			
		||||
  
 | 
			
		||||
    /* Save the Error code */
 | 
			
		||||
    FLASH_SetErrorCode();
 | 
			
		||||
    
 | 
			
		||||
    /* FLASH error interrupt user callback */
 | 
			
		||||
    HAL_FLASH_OperationErrorCallback(addresstmp);
 | 
			
		||||
 | 
			
		||||
    /* Stop the procedure ongoing */
 | 
			
		||||
    pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Check FLASH End of Operation flag  */
 | 
			
		||||
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
 | 
			
		||||
  {
 | 
			
		||||
    /* Clear FLASH End of Operation pending bit */
 | 
			
		||||
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
 | 
			
		||||
    
 | 
			
		||||
    /* Process can continue only if no error detected */
 | 
			
		||||
    if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
 | 
			
		||||
    {
 | 
			
		||||
      if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
 | 
			
		||||
      {
 | 
			
		||||
        /* Nb of pages to erased can be decreased */
 | 
			
		||||
        pFlash.DataRemaining--;
 | 
			
		||||
 | 
			
		||||
        /* Check if there are still pages to erase */
 | 
			
		||||
        if(pFlash.DataRemaining != 0U)
 | 
			
		||||
        {
 | 
			
		||||
          addresstmp = pFlash.Address;
 | 
			
		||||
          /*Indicate user which sector has been erased */
 | 
			
		||||
          HAL_FLASH_EndOfOperationCallback(addresstmp);
 | 
			
		||||
 | 
			
		||||
          /*Increment sector number*/
 | 
			
		||||
          addresstmp = pFlash.Address + FLASH_PAGE_SIZE;
 | 
			
		||||
          pFlash.Address = addresstmp;
 | 
			
		||||
 | 
			
		||||
          /* If the erase operation is completed, disable the PER Bit */
 | 
			
		||||
          CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
 | 
			
		||||
 | 
			
		||||
          FLASH_PageErase(addresstmp);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          /* No more pages to Erase, user callback can be called. */
 | 
			
		||||
          /* Reset Sector and stop Erase pages procedure */
 | 
			
		||||
          pFlash.Address = addresstmp = 0xFFFFFFFFU;
 | 
			
		||||
          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
 | 
			
		||||
          /* FLASH EOP interrupt user callback */
 | 
			
		||||
          HAL_FLASH_EndOfOperationCallback(addresstmp);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
 | 
			
		||||
      {
 | 
			
		||||
        /* Operation is completed, disable the MER Bit */
 | 
			
		||||
        CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
 | 
			
		||||
 | 
			
		||||
          /* MassErase ended. Return the selected bank */
 | 
			
		||||
          /* FLASH EOP interrupt user callback */
 | 
			
		||||
          HAL_FLASH_EndOfOperationCallback(0U);
 | 
			
		||||
 | 
			
		||||
          /* Stop Mass Erase procedure*/
 | 
			
		||||
          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
 | 
			
		||||
        }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        /* Nb of 16-bit data to program can be decreased */
 | 
			
		||||
        pFlash.DataRemaining--;
 | 
			
		||||
        
 | 
			
		||||
        /* Check if there are still 16-bit data to program */
 | 
			
		||||
        if(pFlash.DataRemaining != 0U)
 | 
			
		||||
        {
 | 
			
		||||
          /* Increment address to 16-bit */
 | 
			
		||||
          pFlash.Address += 2U;
 | 
			
		||||
          addresstmp = pFlash.Address;
 | 
			
		||||
          
 | 
			
		||||
          /* Shift to have next 16-bit data */
 | 
			
		||||
          pFlash.Data = (pFlash.Data >> 16U);
 | 
			
		||||
          
 | 
			
		||||
          /* Operation is completed, disable the PG Bit */
 | 
			
		||||
          CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
 | 
			
		||||
 | 
			
		||||
          /*Program halfword (16-bit) at a specified address.*/
 | 
			
		||||
          FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          /* Program ended. Return the selected address */
 | 
			
		||||
          /* FLASH EOP interrupt user callback */
 | 
			
		||||
          if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
 | 
			
		||||
          {
 | 
			
		||||
            HAL_FLASH_EndOfOperationCallback(pFlash.Address);
 | 
			
		||||
          }
 | 
			
		||||
          else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
 | 
			
		||||
          {
 | 
			
		||||
            HAL_FLASH_EndOfOperationCallback(pFlash.Address - 2U);
 | 
			
		||||
          }
 | 
			
		||||
          else 
 | 
			
		||||
          {
 | 
			
		||||
            HAL_FLASH_EndOfOperationCallback(pFlash.Address - 6U);
 | 
			
		||||
          }
 | 
			
		||||
        
 | 
			
		||||
          /* Reset Address and stop Program procedure */
 | 
			
		||||
          pFlash.Address = 0xFFFFFFFFU;
 | 
			
		||||
          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE)
 | 
			
		||||
  {
 | 
			
		||||
    /* Operation is completed, disable the PG, PER and MER Bits */
 | 
			
		||||
    CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER));
 | 
			
		||||
 | 
			
		||||
    /* Disable End of FLASH Operation and Error source interrupts */
 | 
			
		||||
    __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR);
 | 
			
		||||
 | 
			
		||||
    /* Process Unlocked */
 | 
			
		||||
    __HAL_UNLOCK(&pFlash);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  FLASH end of operation interrupt callback
 | 
			
		||||
  * @param  ReturnValue The value saved in this parameter depends on the ongoing procedure
 | 
			
		||||
  *                 - Mass Erase: No return value expected
 | 
			
		||||
  *                 - Pages Erase: Address of the page which has been erased 
 | 
			
		||||
  *                    (if 0xFFFFFFFF, it means that all the selected pages have been erased)
 | 
			
		||||
  *                 - Program: Address which was selected for data program
 | 
			
		||||
  * @retval none
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
 | 
			
		||||
{
 | 
			
		||||
  /* Prevent unused argument(s) compilation warning */
 | 
			
		||||
  UNUSED(ReturnValue);
 | 
			
		||||
 | 
			
		||||
  /* NOTE : This function Should not be modified, when the callback is needed,
 | 
			
		||||
            the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
 | 
			
		||||
   */ 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  FLASH operation error interrupt callback
 | 
			
		||||
  * @param  ReturnValue The value saved in this parameter depends on the ongoing procedure
 | 
			
		||||
  *                 - Mass Erase: No return value expected
 | 
			
		||||
  *                 - Pages Erase: Address of the page which returned an error
 | 
			
		||||
  *                 - Program: Address which was selected for data program
 | 
			
		||||
  * @retval none
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
 | 
			
		||||
{
 | 
			
		||||
  /* Prevent unused argument(s) compilation warning */
 | 
			
		||||
  UNUSED(ReturnValue);
 | 
			
		||||
 | 
			
		||||
  /* NOTE : This function Should not be modified, when the callback is needed,
 | 
			
		||||
            the HAL_FLASH_OperationErrorCallback could be implemented in the user file
 | 
			
		||||
   */ 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions 
 | 
			
		||||
 *  @brief   management functions 
 | 
			
		||||
 *
 | 
			
		||||
@verbatim   
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                      ##### Peripheral Control functions #####
 | 
			
		||||
 ===============================================================================  
 | 
			
		||||
    [..]
 | 
			
		||||
    This subsection provides a set of functions allowing to control the FLASH 
 | 
			
		||||
    memory operations.
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Unlock the FLASH control register access
 | 
			
		||||
  * @retval HAL Status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASH_Unlock(void)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
 | 
			
		||||
  if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
 | 
			
		||||
  {
 | 
			
		||||
    /* Authorize the FLASH Registers access */
 | 
			
		||||
    WRITE_REG(FLASH->KEYR, FLASH_KEY1);
 | 
			
		||||
    WRITE_REG(FLASH->KEYR, FLASH_KEY2);
 | 
			
		||||
 | 
			
		||||
    /* Verify Flash is unlocked */
 | 
			
		||||
    if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
 | 
			
		||||
    {
 | 
			
		||||
      status = HAL_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Locks the FLASH control register access
 | 
			
		||||
  * @retval HAL Status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASH_Lock(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Set the LOCK Bit to lock the FLASH Registers access */
 | 
			
		||||
  SET_BIT(FLASH->CR, FLASH_CR_LOCK);
 | 
			
		||||
  
 | 
			
		||||
  return HAL_OK;  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Unlock the FLASH Option Control Registers access.
 | 
			
		||||
  * @retval HAL Status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
 | 
			
		||||
{
 | 
			
		||||
  if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_OPTWRE))
 | 
			
		||||
  {
 | 
			
		||||
    /* Authorizes the Option Byte register programming */
 | 
			
		||||
    WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
 | 
			
		||||
    WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }  
 | 
			
		||||
  
 | 
			
		||||
  return HAL_OK;  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Lock the FLASH Option Control Registers access.
 | 
			
		||||
  * @retval HAL Status 
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Clear the OPTWRE Bit to lock the FLASH Option Byte Registers access */
 | 
			
		||||
  CLEAR_BIT(FLASH->CR, FLASH_CR_OPTWRE);
 | 
			
		||||
  
 | 
			
		||||
  return HAL_OK;  
 | 
			
		||||
}
 | 
			
		||||
  
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Launch the option byte loading.
 | 
			
		||||
  * @note   This function will reset automatically the MCU.
 | 
			
		||||
  * @retval HAL Status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Set the OBL_Launch bit to launch the option byte loading */
 | 
			
		||||
  SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH);
 | 
			
		||||
  
 | 
			
		||||
  /* Wait for last operation to be completed */
 | 
			
		||||
  return(FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */  
 | 
			
		||||
 | 
			
		||||
/** @defgroup FLASH_Exported_Functions_Group3 Peripheral errors functions 
 | 
			
		||||
 *  @brief    Peripheral errors functions 
 | 
			
		||||
 *
 | 
			
		||||
@verbatim   
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                      ##### Peripheral Errors functions #####
 | 
			
		||||
 ===============================================================================  
 | 
			
		||||
    [..]
 | 
			
		||||
    This subsection permit to get in run-time errors of  the FLASH peripheral.
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Get the specific FLASH error flag.
 | 
			
		||||
  * @retval FLASH_ErrorCode The returned value can be:
 | 
			
		||||
  *            @ref FLASH_Error_Codes
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_FLASH_GetError(void)
 | 
			
		||||
{
 | 
			
		||||
   return pFlash.ErrorCode;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup FLASH_Private_Functions
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Program a half-word (16-bit) at a specified address.
 | 
			
		||||
  * @param  Address specify the address to be programmed.
 | 
			
		||||
  * @param  Data    specify the data to be programmed.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data)
 | 
			
		||||
{
 | 
			
		||||
  /* Clean the error context */
 | 
			
		||||
  pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
 | 
			
		||||
  
 | 
			
		||||
    /* Proceed to program the new data */
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_PG);
 | 
			
		||||
 | 
			
		||||
  /* Write data in the address */
 | 
			
		||||
  *(__IO uint16_t*)Address = Data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Wait for a FLASH operation to complete.
 | 
			
		||||
  * @param  Timeout  maximum flash operation timeout
 | 
			
		||||
  * @retval HAL Status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
 | 
			
		||||
{
 | 
			
		||||
  /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
 | 
			
		||||
     Even if the FLASH operation fails, the BUSY flag will be reset and an error
 | 
			
		||||
     flag will be set */
 | 
			
		||||
     
 | 
			
		||||
  uint32_t tickstart = HAL_GetTick();
 | 
			
		||||
     
 | 
			
		||||
  while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)) 
 | 
			
		||||
  { 
 | 
			
		||||
    if (Timeout != HAL_MAX_DELAY)
 | 
			
		||||
    {
 | 
			
		||||
      if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout))
 | 
			
		||||
      {
 | 
			
		||||
        return HAL_TIMEOUT;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Check FLASH End of Operation flag  */
 | 
			
		||||
  if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
 | 
			
		||||
  {
 | 
			
		||||
    /* Clear FLASH End of Operation pending bit */
 | 
			
		||||
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR)  || 
 | 
			
		||||
     __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
 | 
			
		||||
  {
 | 
			
		||||
    /*Save the error code*/
 | 
			
		||||
    FLASH_SetErrorCode();
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* There is no error flag set */
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Set the specific FLASH error flag.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
static void FLASH_SetErrorCode(void)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t flags = 0U;
 | 
			
		||||
  
 | 
			
		||||
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
 | 
			
		||||
  {
 | 
			
		||||
    pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
 | 
			
		||||
    flags |= FLASH_FLAG_WRPERR;
 | 
			
		||||
  }
 | 
			
		||||
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
 | 
			
		||||
  {
 | 
			
		||||
    pFlash.ErrorCode |= HAL_FLASH_ERROR_PROG;
 | 
			
		||||
    flags |= FLASH_FLAG_PGERR;
 | 
			
		||||
  }
 | 
			
		||||
  /* Clear FLASH error pending bits */
 | 
			
		||||
  __HAL_FLASH_CLEAR_FLAG(flags);
 | 
			
		||||
}  
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif /* HAL_FLASH_MODULE_ENABLED */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,980 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal_flash_ex.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   Extended FLASH HAL module driver.
 | 
			
		||||
  *    
 | 
			
		||||
  *          This file provides firmware functions to manage the following 
 | 
			
		||||
  *          functionalities of the FLASH peripheral:
 | 
			
		||||
  *           + Extended Initialization/de-initialization functions
 | 
			
		||||
  *           + Extended I/O operation functions
 | 
			
		||||
  *           + Extended Peripheral Control functions 
 | 
			
		||||
  *         
 | 
			
		||||
  @verbatim
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
               ##### Flash peripheral extended features  #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
           
 | 
			
		||||
                      ##### How to use this driver #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
  [..] This driver provides functions to configure and program the FLASH memory 
 | 
			
		||||
       of all STM32F3xxx devices. It includes
 | 
			
		||||
       
 | 
			
		||||
        (++) Set/Reset the write protection
 | 
			
		||||
        (++) Program the user Option Bytes
 | 
			
		||||
        (++) Get the Read protection Level
 | 
			
		||||
  
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file in
 | 
			
		||||
  * the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#ifdef HAL_FLASH_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/** @addtogroup FLASH
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
/** @addtogroup FLASH_Private_Variables
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
/* Variables used for Erase pages under interruption*/
 | 
			
		||||
extern FLASH_ProcessTypeDef pFlash;
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
/** @defgroup FLASHEx FLASHEx
 | 
			
		||||
  * @brief FLASH HAL Extension module driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private define ------------------------------------------------------------*/
 | 
			
		||||
/** @defgroup FLASHEx_Private_Constants FLASHEx Private Constants
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
#define FLASH_POSITION_IWDGSW_BIT        (uint32_t)POSITION_VAL(FLASH_OBR_IWDG_SW)
 | 
			
		||||
#define FLASH_POSITION_OB_USERDATA0_BIT  (uint32_t)POSITION_VAL(FLASH_OBR_DATA0)
 | 
			
		||||
#define FLASH_POSITION_OB_USERDATA1_BIT  (uint32_t)POSITION_VAL(FLASH_OBR_DATA1)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Private macro -------------------------------------------------------------*/
 | 
			
		||||
/** @defgroup FLASHEx_Private_Macros FLASHEx Private Macros
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */ 
 | 
			
		||||
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/** @defgroup FLASHEx_Private_Functions FLASHEx Private Functions
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
/* Erase operations */
 | 
			
		||||
static void              FLASH_MassErase(void);
 | 
			
		||||
void    FLASH_PageErase(uint32_t PageAddress);
 | 
			
		||||
 | 
			
		||||
/* Option bytes control */
 | 
			
		||||
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage);
 | 
			
		||||
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage);
 | 
			
		||||
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel);
 | 
			
		||||
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig);
 | 
			
		||||
static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data);
 | 
			
		||||
static uint32_t          FLASH_OB_GetWRP(void);
 | 
			
		||||
static uint32_t          FLASH_OB_GetRDP(void);
 | 
			
		||||
static uint8_t           FLASH_OB_GetUser(void);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Exported functions ---------------------------------------------------------*/
 | 
			
		||||
/** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
/** @defgroup FLASHEx_Exported_Functions_Group1 FLASHEx Memory Erasing functions
 | 
			
		||||
 *  @brief   FLASH Memory Erasing functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim   
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
                ##### FLASH Erasing Programming functions ##### 
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
    [..] The FLASH Memory Erasing functions, includes the following functions:
 | 
			
		||||
    (+) HAL_FLASHEx_Erase: return only when erase has been done
 | 
			
		||||
    (+) HAL_FLASHEx_Erase_IT: end of erase is done when HAL_FLASH_EndOfOperationCallback 
 | 
			
		||||
        is called with parameter 0xFFFFFFFF
 | 
			
		||||
 | 
			
		||||
    [..] Any operation of erase should follow these steps:
 | 
			
		||||
    (#) Call the HAL_FLASH_Unlock() function to enable the flash control register and 
 | 
			
		||||
        program memory access.
 | 
			
		||||
    (#) Call the desired function to erase page.
 | 
			
		||||
    (#) Call the HAL_FLASH_Lock() to disable the flash program memory access 
 | 
			
		||||
       (recommended to protect the FLASH memory against possible unwanted operation).
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Perform a mass erase or erase the specified FLASH memory pages
 | 
			
		||||
  * @note   To correctly run this function, the @ref HAL_FLASH_Unlock() function
 | 
			
		||||
  *         must be called before.
 | 
			
		||||
  *         Call the @ref HAL_FLASH_Lock() to disable the flash memory access 
 | 
			
		||||
  *         (recommended to protect the FLASH memory against possible unwanted operation)
 | 
			
		||||
  * @param[in]  pEraseInit pointer to an FLASH_EraseInitTypeDef structure that
 | 
			
		||||
  *         contains the configuration information for the erasing.
 | 
			
		||||
  *
 | 
			
		||||
  * @param[out]  PageError pointer to variable  that
 | 
			
		||||
  *         contains the configuration information on faulty page in case of error
 | 
			
		||||
  *         (0xFFFFFFFF means that all the pages have been correctly erased)
 | 
			
		||||
  *
 | 
			
		||||
  * @retval HAL_StatusTypeDef HAL Status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_ERROR;
 | 
			
		||||
  uint32_t address = 0U;
 | 
			
		||||
 | 
			
		||||
  /* Process Locked */
 | 
			
		||||
  __HAL_LOCK(&pFlash);
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
 | 
			
		||||
 | 
			
		||||
  if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
 | 
			
		||||
  {
 | 
			
		||||
      /* Mass Erase requested for Bank1 */
 | 
			
		||||
      /* Wait for last operation to be completed */
 | 
			
		||||
      if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
 | 
			
		||||
      {
 | 
			
		||||
        /*Mass erase to be done*/
 | 
			
		||||
        FLASH_MassErase();
 | 
			
		||||
        
 | 
			
		||||
        /* Wait for last operation to be completed */
 | 
			
		||||
        status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
        
 | 
			
		||||
        /* If the erase operation is completed, disable the MER Bit */
 | 
			
		||||
        CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
 | 
			
		||||
      }
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    /* Page Erase is requested */
 | 
			
		||||
    /* Check the parameters */
 | 
			
		||||
    assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress));
 | 
			
		||||
    assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages));
 | 
			
		||||
    
 | 
			
		||||
      /* Page Erase requested on address located on bank1 */
 | 
			
		||||
      /* Wait for last operation to be completed */
 | 
			
		||||
      if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
 | 
			
		||||
      {
 | 
			
		||||
        /*Initialization of PageError variable*/
 | 
			
		||||
        *PageError = 0xFFFFFFFFU;
 | 
			
		||||
        
 | 
			
		||||
        /* Erase page by page to be done*/
 | 
			
		||||
        for(address = pEraseInit->PageAddress;
 | 
			
		||||
            address < ((pEraseInit->NbPages * FLASH_PAGE_SIZE) + pEraseInit->PageAddress);
 | 
			
		||||
            address += FLASH_PAGE_SIZE)
 | 
			
		||||
        {
 | 
			
		||||
          FLASH_PageErase(address);
 | 
			
		||||
          
 | 
			
		||||
          /* Wait for last operation to be completed */
 | 
			
		||||
          status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
          
 | 
			
		||||
          /* If the erase operation is completed, disable the PER Bit */
 | 
			
		||||
          CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
 | 
			
		||||
          
 | 
			
		||||
          if (status != HAL_OK)
 | 
			
		||||
          {
 | 
			
		||||
            /* In case of error, stop erase procedure and return the faulty address */
 | 
			
		||||
            *PageError = address;
 | 
			
		||||
            break;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Process Unlocked */
 | 
			
		||||
  __HAL_UNLOCK(&pFlash);
 | 
			
		||||
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Perform a mass erase or erase the specified FLASH memory pages with interrupt enabled
 | 
			
		||||
  * @note   To correctly run this function, the @ref HAL_FLASH_Unlock() function
 | 
			
		||||
  *         must be called before.
 | 
			
		||||
  *         Call the @ref HAL_FLASH_Lock() to disable the flash memory access 
 | 
			
		||||
  *         (recommended to protect the FLASH memory against possible unwanted operation)
 | 
			
		||||
  * @param  pEraseInit pointer to an FLASH_EraseInitTypeDef structure that
 | 
			
		||||
  *         contains the configuration information for the erasing.
 | 
			
		||||
  *
 | 
			
		||||
  * @retval HAL_StatusTypeDef HAL Status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
 | 
			
		||||
  /* Process Locked */
 | 
			
		||||
  __HAL_LOCK(&pFlash);
 | 
			
		||||
 | 
			
		||||
  /* If procedure already ongoing, reject the next one */
 | 
			
		||||
  if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
 | 
			
		||||
 | 
			
		||||
  /* Enable End of FLASH Operation and Error source interrupts */
 | 
			
		||||
  __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR);
 | 
			
		||||
 | 
			
		||||
  if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
 | 
			
		||||
  {
 | 
			
		||||
    /*Mass erase to be done*/
 | 
			
		||||
    pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE;
 | 
			
		||||
        FLASH_MassErase();
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    /* Erase by page to be done*/
 | 
			
		||||
 | 
			
		||||
    /* Check the parameters */
 | 
			
		||||
    assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress));
 | 
			
		||||
    assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages));
 | 
			
		||||
 | 
			
		||||
    pFlash.ProcedureOnGoing = FLASH_PROC_PAGEERASE;
 | 
			
		||||
    pFlash.DataRemaining = pEraseInit->NbPages;
 | 
			
		||||
    pFlash.Address = pEraseInit->PageAddress;
 | 
			
		||||
 | 
			
		||||
    /*Erase 1st page and wait for IT*/
 | 
			
		||||
    FLASH_PageErase(pEraseInit->PageAddress);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup FLASHEx_Exported_Functions_Group2 Option Bytes Programming functions
 | 
			
		||||
 *  @brief   Option Bytes Programming functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim   
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
                ##### Option Bytes Programming functions ##### 
 | 
			
		||||
  ==============================================================================  
 | 
			
		||||
    [..]
 | 
			
		||||
    This subsection provides a set of functions allowing to control the FLASH 
 | 
			
		||||
    option bytes operations.
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Erases the FLASH option bytes.
 | 
			
		||||
  * @note   This functions erases all option bytes except the Read protection (RDP).
 | 
			
		||||
  *         The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
 | 
			
		||||
  *         The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
 | 
			
		||||
  *         The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes
 | 
			
		||||
  *         (system reset will occur)
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
 | 
			
		||||
{
 | 
			
		||||
  uint8_t rdptmp = OB_RDP_LEVEL_0;
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_ERROR;
 | 
			
		||||
 | 
			
		||||
  /* Get the actual read protection Option Byte value */
 | 
			
		||||
  rdptmp = FLASH_OB_GetRDP();
 | 
			
		||||
 | 
			
		||||
  /* Wait for last operation to be completed */
 | 
			
		||||
  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
 | 
			
		||||
  if(status == HAL_OK)
 | 
			
		||||
  {
 | 
			
		||||
    /* Clean the error context */
 | 
			
		||||
    pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
 | 
			
		||||
 | 
			
		||||
    /* If the previous operation is completed, proceed to erase the option bytes */
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_OPTER);
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_STRT);
 | 
			
		||||
 | 
			
		||||
    /* Wait for last operation to be completed */
 | 
			
		||||
    status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
 | 
			
		||||
    /* If the erase operation is completed, disable the OPTER Bit */
 | 
			
		||||
    CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
 | 
			
		||||
 | 
			
		||||
    if(status == HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
      /* Restore the last read protection Option Byte value */
 | 
			
		||||
      status = FLASH_OB_RDP_LevelConfig(rdptmp);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Return the erase status */
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Program option bytes
 | 
			
		||||
  * @note   The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
 | 
			
		||||
  *         The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
 | 
			
		||||
  *         The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes
 | 
			
		||||
  *         (system reset will occur)
 | 
			
		||||
  *
 | 
			
		||||
  * @param  pOBInit pointer to an FLASH_OBInitStruct structure that
 | 
			
		||||
  *         contains the configuration information for the programming.
 | 
			
		||||
  *
 | 
			
		||||
  * @retval HAL_StatusTypeDef HAL Status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_ERROR;
 | 
			
		||||
 | 
			
		||||
  /* Process Locked */
 | 
			
		||||
  __HAL_LOCK(&pFlash);
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_OPTIONBYTE(pOBInit->OptionType));
 | 
			
		||||
 | 
			
		||||
  /* Write protection configuration */
 | 
			
		||||
  if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP)
 | 
			
		||||
  {
 | 
			
		||||
    assert_param(IS_WRPSTATE(pOBInit->WRPState));
 | 
			
		||||
    if (pOBInit->WRPState == OB_WRPSTATE_ENABLE)
 | 
			
		||||
    {
 | 
			
		||||
      /* Enable of Write protection on the selected page */
 | 
			
		||||
      status = FLASH_OB_EnableWRP(pOBInit->WRPPage);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      /* Disable of Write protection on the selected page */
 | 
			
		||||
      status = FLASH_OB_DisableWRP(pOBInit->WRPPage);
 | 
			
		||||
    }
 | 
			
		||||
    if (status != HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
      /* Process Unlocked */
 | 
			
		||||
      __HAL_UNLOCK(&pFlash);
 | 
			
		||||
      return status;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Read protection configuration */
 | 
			
		||||
  if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP)
 | 
			
		||||
  {
 | 
			
		||||
    status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel);
 | 
			
		||||
    if (status != HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
      /* Process Unlocked */
 | 
			
		||||
      __HAL_UNLOCK(&pFlash);
 | 
			
		||||
      return status;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* USER configuration */
 | 
			
		||||
  if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER)
 | 
			
		||||
  {
 | 
			
		||||
    status = FLASH_OB_UserConfig(pOBInit->USERConfig);
 | 
			
		||||
    if (status != HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
      /* Process Unlocked */
 | 
			
		||||
      __HAL_UNLOCK(&pFlash);
 | 
			
		||||
      return status;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* DATA configuration*/
 | 
			
		||||
  if((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA)
 | 
			
		||||
  {
 | 
			
		||||
    status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData);
 | 
			
		||||
    if (status != HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
      /* Process Unlocked */
 | 
			
		||||
      __HAL_UNLOCK(&pFlash);
 | 
			
		||||
      return status;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Process Unlocked */
 | 
			
		||||
  __HAL_UNLOCK(&pFlash);
 | 
			
		||||
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Get the Option byte configuration
 | 
			
		||||
  * @param  pOBInit pointer to an FLASH_OBInitStruct structure that
 | 
			
		||||
  *         contains the configuration information for the programming.
 | 
			
		||||
  *
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
 | 
			
		||||
{
 | 
			
		||||
  pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER;
 | 
			
		||||
 | 
			
		||||
  /*Get WRP*/
 | 
			
		||||
  pOBInit->WRPPage = FLASH_OB_GetWRP();
 | 
			
		||||
 | 
			
		||||
  /*Get RDP Level*/
 | 
			
		||||
  pOBInit->RDPLevel = FLASH_OB_GetRDP();
 | 
			
		||||
 | 
			
		||||
  /*Get USER*/
 | 
			
		||||
  pOBInit->USERConfig = FLASH_OB_GetUser();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Get the Option byte user data
 | 
			
		||||
  * @param  DATAAdress Address of the option byte DATA
 | 
			
		||||
  *          This parameter can be one of the following values:
 | 
			
		||||
  *            @arg @ref OB_DATA_ADDRESS_DATA0
 | 
			
		||||
  *            @arg @ref OB_DATA_ADDRESS_DATA1
 | 
			
		||||
  * @retval Value programmed in USER data
 | 
			
		||||
  */
 | 
			
		||||
uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t value = 0U;
 | 
			
		||||
  
 | 
			
		||||
  if (DATAAdress == OB_DATA_ADDRESS_DATA0)
 | 
			
		||||
  {
 | 
			
		||||
    /* Get value programmed in OB USER Data0 */
 | 
			
		||||
    value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA0) >> FLASH_POSITION_OB_USERDATA0_BIT;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    /* Get value programmed in OB USER Data1 */
 | 
			
		||||
    value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA1) >> FLASH_POSITION_OB_USERDATA1_BIT;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  return value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup FLASHEx_Private_Functions
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Full erase of FLASH memory Bank 
 | 
			
		||||
  *
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
static void FLASH_MassErase(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Clean the error context */
 | 
			
		||||
  pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
 | 
			
		||||
 | 
			
		||||
    /* Only bank1 will be erased*/
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_MER);
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_STRT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Enable the write protection of the desired pages
 | 
			
		||||
  * @note   An option byte erase is done automatically in this function. 
 | 
			
		||||
  * @note   When the memory read protection level is selected (RDP level = 1), 
 | 
			
		||||
  *         it is not possible to program or erase the flash page i if
 | 
			
		||||
  *         debug features are connected or boot code is executed in RAM, even if nWRPi = 1 
 | 
			
		||||
  * 
 | 
			
		||||
  * @param  WriteProtectPage specifies the page(s) to be write protected.
 | 
			
		||||
  *         The value of this parameter depend on device used within the same series 
 | 
			
		||||
  * @retval HAL status 
 | 
			
		||||
  */
 | 
			
		||||
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
  uint16_t WRP0_Data = 0xFFFFU;
 | 
			
		||||
#if defined(OB_WRP1_WRP1)
 | 
			
		||||
  uint16_t WRP1_Data = 0xFFFFU;
 | 
			
		||||
#endif /* OB_WRP1_WRP1 */
 | 
			
		||||
#if defined(OB_WRP2_WRP2)
 | 
			
		||||
  uint16_t WRP2_Data = 0xFFFFU;
 | 
			
		||||
#endif /* OB_WRP2_WRP2 */
 | 
			
		||||
#if defined(OB_WRP3_WRP3)
 | 
			
		||||
  uint16_t WRP3_Data = 0xFFFFU;
 | 
			
		||||
#endif /* OB_WRP3_WRP3 */
 | 
			
		||||
  
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_OB_WRP(WriteProtectPage));
 | 
			
		||||
    
 | 
			
		||||
  /* Get current write protected pages and the new pages to be protected ******/
 | 
			
		||||
  WriteProtectPage = (uint32_t)(~((~FLASH_OB_GetWRP()) | WriteProtectPage));
 | 
			
		||||
  
 | 
			
		||||
#if defined(OB_WRP_PAGES0TO15MASK)
 | 
			
		||||
  WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK);
 | 
			
		||||
#endif /* OB_WRP_PAGES0TO31MASK */
 | 
			
		||||
  
 | 
			
		||||
#if defined(OB_WRP_PAGES16TO31MASK)
 | 
			
		||||
  WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8U);
 | 
			
		||||
#endif /* OB_WRP_PAGES32TO63MASK */
 | 
			
		||||
 
 | 
			
		||||
#if defined(OB_WRP_PAGES32TO47MASK)
 | 
			
		||||
  WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16U);
 | 
			
		||||
#endif /* OB_WRP_PAGES32TO47MASK */
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP_PAGES48TO127MASK)
 | 
			
		||||
  WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24U); 
 | 
			
		||||
#elif defined(OB_WRP_PAGES48TO255MASK)
 | 
			
		||||
  WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO255MASK) >> 24U); 
 | 
			
		||||
#endif /* OB_WRP_PAGES48TO63MASK */
 | 
			
		||||
  
 | 
			
		||||
  /* Wait for last operation to be completed */
 | 
			
		||||
  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
 | 
			
		||||
  if(status == HAL_OK)
 | 
			
		||||
  { 
 | 
			
		||||
    /* Clean the error context */
 | 
			
		||||
    pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
 | 
			
		||||
 | 
			
		||||
    /* To be able to write again option byte, need to perform a option byte erase */
 | 
			
		||||
    status = HAL_FLASHEx_OBErase();
 | 
			
		||||
    if (status == HAL_OK)  
 | 
			
		||||
    {
 | 
			
		||||
      /* Enable write protection */
 | 
			
		||||
      SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP0_WRP0)
 | 
			
		||||
      if(WRP0_Data != 0xFFU)
 | 
			
		||||
      {
 | 
			
		||||
        OB->WRP0 &= WRP0_Data;
 | 
			
		||||
        
 | 
			
		||||
        /* Wait for last operation to be completed */
 | 
			
		||||
        status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
      }
 | 
			
		||||
#endif /* OB_WRP0_WRP0 */
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP1_WRP1)
 | 
			
		||||
      if((status == HAL_OK) && (WRP1_Data != 0xFFU))
 | 
			
		||||
      {
 | 
			
		||||
        OB->WRP1 &= WRP1_Data;
 | 
			
		||||
        
 | 
			
		||||
        /* Wait for last operation to be completed */
 | 
			
		||||
        status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
      }
 | 
			
		||||
#endif /* OB_WRP1_WRP1 */
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP2_WRP2)
 | 
			
		||||
      if((status == HAL_OK) && (WRP2_Data != 0xFFU))
 | 
			
		||||
      {
 | 
			
		||||
        OB->WRP2 &= WRP2_Data;
 | 
			
		||||
        
 | 
			
		||||
        /* Wait for last operation to be completed */
 | 
			
		||||
        status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
      }
 | 
			
		||||
#endif /* OB_WRP2_WRP2 */
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP3_WRP3)
 | 
			
		||||
      if((status == HAL_OK) && (WRP3_Data != 0xFFU))
 | 
			
		||||
      {
 | 
			
		||||
        OB->WRP3 &= WRP3_Data;
 | 
			
		||||
        
 | 
			
		||||
        /* Wait for last operation to be completed */
 | 
			
		||||
        status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
      }
 | 
			
		||||
#endif /* OB_WRP3_WRP3 */
 | 
			
		||||
 | 
			
		||||
      /* if the program operation is completed, disable the OPTPG Bit */
 | 
			
		||||
      CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Disable the write protection of the desired pages
 | 
			
		||||
  * @note   An option byte erase is done automatically in this function. 
 | 
			
		||||
  * @note   When the memory read protection level is selected (RDP level = 1), 
 | 
			
		||||
  *         it is not possible to program or erase the flash page i if   
 | 
			
		||||
  *         debug features are connected or boot code is executed in RAM, even if nWRPi = 1 
 | 
			
		||||
  * 
 | 
			
		||||
  * @param  WriteProtectPage specifies the page(s) to be write unprotected.
 | 
			
		||||
  *         The value of this parameter depend on device used within the same series 
 | 
			
		||||
  * @retval HAL status 
 | 
			
		||||
  */
 | 
			
		||||
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
  uint16_t WRP0_Data = 0xFFFFU;
 | 
			
		||||
#if defined(OB_WRP1_WRP1)
 | 
			
		||||
  uint16_t WRP1_Data = 0xFFFFU;
 | 
			
		||||
#endif /* OB_WRP1_WRP1 */
 | 
			
		||||
#if defined(OB_WRP2_WRP2)
 | 
			
		||||
  uint16_t WRP2_Data = 0xFFFFU;
 | 
			
		||||
#endif /* OB_WRP2_WRP2 */
 | 
			
		||||
#if defined(OB_WRP3_WRP3)
 | 
			
		||||
  uint16_t WRP3_Data = 0xFFFFU;
 | 
			
		||||
#endif /* OB_WRP3_WRP3 */
 | 
			
		||||
  
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_OB_WRP(WriteProtectPage));
 | 
			
		||||
 | 
			
		||||
  /* Get current write protected pages and the new pages to be unprotected ******/
 | 
			
		||||
  WriteProtectPage = (FLASH_OB_GetWRP() | WriteProtectPage);
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP_PAGES0TO15MASK)
 | 
			
		||||
  WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK);
 | 
			
		||||
#endif /* OB_WRP_PAGES0TO31MASK */
 | 
			
		||||
  
 | 
			
		||||
#if defined(OB_WRP_PAGES16TO31MASK)
 | 
			
		||||
  WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8U);
 | 
			
		||||
#endif /* OB_WRP_PAGES32TO63MASK */
 | 
			
		||||
 
 | 
			
		||||
#if defined(OB_WRP_PAGES32TO47MASK)
 | 
			
		||||
  WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16U);
 | 
			
		||||
#endif /* OB_WRP_PAGES32TO47MASK */
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP_PAGES48TO127MASK)
 | 
			
		||||
  WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24U); 
 | 
			
		||||
#elif defined(OB_WRP_PAGES48TO255MASK)
 | 
			
		||||
  WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO255MASK) >> 24U); 
 | 
			
		||||
#endif /* OB_WRP_PAGES48TO63MASK */
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
  /* Wait for last operation to be completed */
 | 
			
		||||
  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
 | 
			
		||||
  if(status == HAL_OK)
 | 
			
		||||
  { 
 | 
			
		||||
    /* Clean the error context */
 | 
			
		||||
    pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
 | 
			
		||||
 | 
			
		||||
    /* To be able to write again option byte, need to perform a option byte erase */
 | 
			
		||||
    status = HAL_FLASHEx_OBErase();
 | 
			
		||||
    if (status == HAL_OK)  
 | 
			
		||||
    {
 | 
			
		||||
      SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP0_WRP0)
 | 
			
		||||
      if(WRP0_Data != 0xFFU)
 | 
			
		||||
      {
 | 
			
		||||
        OB->WRP0 |= WRP0_Data;
 | 
			
		||||
        
 | 
			
		||||
        /* Wait for last operation to be completed */
 | 
			
		||||
        status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
      }
 | 
			
		||||
#endif /* OB_WRP0_WRP0 */
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP1_WRP1)
 | 
			
		||||
      if((status == HAL_OK) && (WRP1_Data != 0xFFU))
 | 
			
		||||
      {
 | 
			
		||||
        OB->WRP1 |= WRP1_Data;
 | 
			
		||||
        
 | 
			
		||||
        /* Wait for last operation to be completed */
 | 
			
		||||
        status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
      }
 | 
			
		||||
#endif /* OB_WRP1_WRP1 */
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP2_WRP2)
 | 
			
		||||
      if((status == HAL_OK) && (WRP2_Data != 0xFFU))
 | 
			
		||||
      {
 | 
			
		||||
        OB->WRP2 |= WRP2_Data;
 | 
			
		||||
        
 | 
			
		||||
        /* Wait for last operation to be completed */
 | 
			
		||||
        status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
      }
 | 
			
		||||
#endif /* OB_WRP2_WRP2 */
 | 
			
		||||
 | 
			
		||||
#if defined(OB_WRP3_WRP3)
 | 
			
		||||
      if((status == HAL_OK) && (WRP3_Data != 0xFFU))
 | 
			
		||||
      {
 | 
			
		||||
        OB->WRP3 |= WRP3_Data;
 | 
			
		||||
        
 | 
			
		||||
        /* Wait for last operation to be completed */
 | 
			
		||||
        status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
      }
 | 
			
		||||
#endif /* OB_WRP3_WRP3 */
 | 
			
		||||
 | 
			
		||||
      /* if the program operation is completed, disable the OPTPG Bit */
 | 
			
		||||
      CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Set the read protection level.
 | 
			
		||||
  * @param  ReadProtectLevel specifies the read protection level.
 | 
			
		||||
  *         This parameter can be one of the following values:
 | 
			
		||||
  *            @arg @ref OB_RDP_LEVEL_0 No protection
 | 
			
		||||
  *            @arg @ref OB_RDP_LEVEL_1 Read protection of the memory
 | 
			
		||||
  *            @arg @ref OB_RDP_LEVEL_2 Full chip protection
 | 
			
		||||
  * @note   Warning: When enabling OB_RDP level 2 it's no more possible to go back to level 1 or 0
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
  
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_OB_RDP_LEVEL(ReadProtectLevel));
 | 
			
		||||
  
 | 
			
		||||
  /* Wait for last operation to be completed */
 | 
			
		||||
  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
  
 | 
			
		||||
  if(status == HAL_OK)
 | 
			
		||||
  { 
 | 
			
		||||
    /* Clean the error context */
 | 
			
		||||
    pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
 | 
			
		||||
    
 | 
			
		||||
    /* If the previous operation is completed, proceed to erase the option bytes */
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_OPTER);
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_STRT);
 | 
			
		||||
 | 
			
		||||
    /* Wait for last operation to be completed */
 | 
			
		||||
    status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
 | 
			
		||||
    /* If the erase operation is completed, disable the OPTER Bit */
 | 
			
		||||
    CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
 | 
			
		||||
 | 
			
		||||
    if(status == HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
      /* Enable the Option Bytes Programming operation */
 | 
			
		||||
      SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
 | 
			
		||||
      
 | 
			
		||||
      WRITE_REG(OB->RDP, ReadProtectLevel);
 | 
			
		||||
      
 | 
			
		||||
      /* Wait for last operation to be completed */
 | 
			
		||||
      status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); 
 | 
			
		||||
      
 | 
			
		||||
      /* if the program operation is completed, disable the OPTPG Bit */
 | 
			
		||||
      CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Program the FLASH User Option Byte.    
 | 
			
		||||
  * @note   Programming of the OB should be performed only after an erase (otherwise PGERR occurs)
 | 
			
		||||
  * @param  UserConfig The FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1), RST_STDBY(Bit2), nBOOT1(Bit4),
 | 
			
		||||
  *         VDDA_Analog_Monitoring(Bit5) and SRAM_Parity_Enable(Bit6). 
 | 
			
		||||
  *         And SDADC12_VDD_MONITOR(Bit7) for STM32F373 or STM32F378 . 
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_OB_IWDG_SOURCE((UserConfig&OB_IWDG_SW)));
 | 
			
		||||
  assert_param(IS_OB_STOP_SOURCE((UserConfig&OB_STOP_NO_RST)));
 | 
			
		||||
  assert_param(IS_OB_STDBY_SOURCE((UserConfig&OB_STDBY_NO_RST)));
 | 
			
		||||
  assert_param(IS_OB_BOOT1((UserConfig&OB_BOOT1_SET)));
 | 
			
		||||
  assert_param(IS_OB_VDDA_ANALOG((UserConfig&OB_VDDA_ANALOG_ON)));
 | 
			
		||||
  assert_param(IS_OB_SRAM_PARITY((UserConfig&OB_SRAM_PARITY_RESET)));
 | 
			
		||||
#if defined(FLASH_OBR_SDADC12_VDD_MONITOR)
 | 
			
		||||
  assert_param(IS_OB_SDACD_VDD_MONITOR((UserConfig&OB_SDACD_VDD_MONITOR_SET)));
 | 
			
		||||
#endif /* FLASH_OBR_SDADC12_VDD_MONITOR */
 | 
			
		||||
 | 
			
		||||
  /* Wait for last operation to be completed */
 | 
			
		||||
  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
  
 | 
			
		||||
  if(status == HAL_OK)
 | 
			
		||||
  {     
 | 
			
		||||
    /* Clean the error context */
 | 
			
		||||
    pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
 | 
			
		||||
 | 
			
		||||
    /* Enable the Option Bytes Programming operation */
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_OPTPG); 
 | 
			
		||||
 
 | 
			
		||||
#if   defined(FLASH_OBR_SDADC12_VDD_MONITOR)
 | 
			
		||||
    OB->USER = (UserConfig | 0x08U);
 | 
			
		||||
#else
 | 
			
		||||
    OB->USER = (UserConfig | 0x88U);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    /* Wait for last operation to be completed */
 | 
			
		||||
    status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
 | 
			
		||||
    /* if the program operation is completed, disable the OPTPG Bit */
 | 
			
		||||
    CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  return status; 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Programs a half word at a specified Option Byte Data address.
 | 
			
		||||
  * @note   The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
 | 
			
		||||
  *         The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
 | 
			
		||||
  *         The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes 
 | 
			
		||||
  *         (system reset will occur)
 | 
			
		||||
  *         Programming of the OB should be performed only after an erase (otherwise PGERR occurs)
 | 
			
		||||
  * @param  Address specifies the address to be programmed.
 | 
			
		||||
  *         This parameter can be 0x1FFFF804 or 0x1FFFF806. 
 | 
			
		||||
  * @param  Data specifies the data to be programmed.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_ERROR;
 | 
			
		||||
  
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_OB_DATA_ADDRESS(Address));
 | 
			
		||||
  
 | 
			
		||||
  /* Wait for last operation to be completed */
 | 
			
		||||
  status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
  
 | 
			
		||||
  if(status == HAL_OK)
 | 
			
		||||
  {
 | 
			
		||||
    /* Clean the error context */
 | 
			
		||||
    pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
 | 
			
		||||
 | 
			
		||||
    /* Enables the Option Bytes Programming operation */
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_OPTPG); 
 | 
			
		||||
    *(__IO uint16_t*)Address = Data;
 | 
			
		||||
    
 | 
			
		||||
    /* Wait for last operation to be completed */
 | 
			
		||||
    status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
 | 
			
		||||
    
 | 
			
		||||
    /* If the program operation is completed, disable the OPTPG Bit */
 | 
			
		||||
    CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG);
 | 
			
		||||
  }
 | 
			
		||||
  /* Return the Option Byte Data Program Status */
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Return the FLASH Write Protection Option Bytes value.
 | 
			
		||||
  * @retval The FLASH Write Protection Option Bytes value
 | 
			
		||||
  */
 | 
			
		||||
static uint32_t FLASH_OB_GetWRP(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Return the FLASH write protection Register value */
 | 
			
		||||
  return (uint32_t)(READ_REG(FLASH->WRPR));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Returns the FLASH Read Protection level.
 | 
			
		||||
  * @retval FLASH RDP level
 | 
			
		||||
  *         This parameter can be one of the following values:
 | 
			
		||||
  *            @arg @ref OB_RDP_LEVEL_0 No protection
 | 
			
		||||
  *            @arg @ref OB_RDP_LEVEL_1 Read protection of the memory
 | 
			
		||||
  *            @arg @ref OB_RDP_LEVEL_2 Full chip protection
 | 
			
		||||
  */
 | 
			
		||||
static uint32_t FLASH_OB_GetRDP(void)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t tmp_reg = 0U;
 | 
			
		||||
  
 | 
			
		||||
  /* Read RDP level bits */
 | 
			
		||||
#if defined(FLASH_OBR_RDPRT)
 | 
			
		||||
  tmp_reg = READ_BIT(FLASH->OBR, FLASH_OBR_RDPRT);
 | 
			
		||||
#elif defined(FLASH_OBR_LEVEL1_PROT)
 | 
			
		||||
  tmp_reg = READ_BIT(FLASH->OBR, (FLASH_OBR_LEVEL1_PROT | FLASH_OBR_LEVEL2_PROT));
 | 
			
		||||
#endif /* FLASH_OBR_RDPRT */
 | 
			
		||||
 | 
			
		||||
#if defined(FLASH_OBR_RDPRT)
 | 
			
		||||
  if (tmp_reg == FLASH_OBR_RDPRT_2)
 | 
			
		||||
#elif defined(FLASH_OBR_LEVEL1_PROT)
 | 
			
		||||
  if (tmp_reg == FLASH_OBR_LEVEL2_PROT)
 | 
			
		||||
#endif /* FLASH_OBR_RDPRT */
 | 
			
		||||
  {
 | 
			
		||||
    return OB_RDP_LEVEL_2;
 | 
			
		||||
  }
 | 
			
		||||
  else if (tmp_reg == 0U)
 | 
			
		||||
  {
 | 
			
		||||
    return OB_RDP_LEVEL_0;
 | 
			
		||||
  }
 | 
			
		||||
  else 
 | 
			
		||||
  {
 | 
			
		||||
    return OB_RDP_LEVEL_1;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Return the FLASH User Option Byte value.
 | 
			
		||||
  * @retval  The FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1), RST_STDBY(Bit2), nBOOT1(Bit4),
 | 
			
		||||
  *         VDDA_Analog_Monitoring(Bit5) and SRAM_Parity_Enable(Bit6). 
 | 
			
		||||
  *         And SDADC12_VDD_MONITOR(Bit7) for STM32F373 or STM32F378 . 
 | 
			
		||||
  */
 | 
			
		||||
static uint8_t FLASH_OB_GetUser(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Return the User Option Byte */
 | 
			
		||||
  return (uint8_t)((READ_REG(FLASH->OBR) & FLASH_OBR_USER) >> FLASH_POSITION_IWDGSW_BIT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup FLASH
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup FLASH_Private_Functions
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Erase the specified FLASH memory page
 | 
			
		||||
  * @param  PageAddress FLASH page to erase
 | 
			
		||||
  *         The value of this parameter depend on device used within the same series      
 | 
			
		||||
  * 
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void FLASH_PageErase(uint32_t PageAddress)
 | 
			
		||||
{
 | 
			
		||||
  /* Clean the error context */
 | 
			
		||||
  pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
 | 
			
		||||
 | 
			
		||||
    /* Proceed to erase the page */
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_PER);
 | 
			
		||||
    WRITE_REG(FLASH->AR, PageAddress);
 | 
			
		||||
    SET_BIT(FLASH->CR, FLASH_CR_STRT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif /* HAL_FLASH_MODULE_ENABLED */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,541 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal_gpio.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   GPIO HAL module driver.
 | 
			
		||||
  *          This file provides firmware functions to manage the following
 | 
			
		||||
  *          functionalities of the General Purpose Input/Output (GPIO) peripheral:
 | 
			
		||||
  *           + Initialization and de-initialization functions
 | 
			
		||||
  *           + IO operation functions
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file
 | 
			
		||||
  * in the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  @verbatim
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
                    ##### GPIO Peripheral features #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
  [..]
 | 
			
		||||
    (+) Each port bit of the general-purpose I/O (GPIO) ports can be individually
 | 
			
		||||
        configured by software in several modes:
 | 
			
		||||
        (++) Input mode
 | 
			
		||||
        (++) Analog mode
 | 
			
		||||
        (++) Output mode
 | 
			
		||||
        (++) Alternate function mode
 | 
			
		||||
        (++) External interrupt/event lines
 | 
			
		||||
 | 
			
		||||
    (+) During and just after reset, the alternate functions and external interrupt
 | 
			
		||||
        lines are not active and the I/O ports are configured in input floating mode.
 | 
			
		||||
 | 
			
		||||
    (+) All GPIO pins have weak internal pull-up and pull-down resistors, which can be
 | 
			
		||||
        activated or not.
 | 
			
		||||
 | 
			
		||||
    (+) In Output or Alternate mode, each IO can be configured on open-drain or push-pull
 | 
			
		||||
        type and the IO speed can be selected depending on the VDD value.
 | 
			
		||||
 | 
			
		||||
    (+) The microcontroller IO pins are connected to onboard peripherals/modules through a
 | 
			
		||||
        multiplexer that allows only one peripheral alternate function (AF) connected
 | 
			
		||||
       to an IO pin at a time. In this way, there can be no conflict between peripherals
 | 
			
		||||
       sharing the same IO pin.
 | 
			
		||||
 | 
			
		||||
    (+) All ports have external interrupt/event capability. To use external interrupt
 | 
			
		||||
        lines, the port must be configured in input mode. All available GPIO pins are
 | 
			
		||||
        connected to the 16 external interrupt/event lines from EXTI0 to EXTI15.
 | 
			
		||||
 | 
			
		||||
    (+) The external interrupt/event controller consists of up to 23 edge detectors
 | 
			
		||||
        (16 lines are connected to GPIO) for generating event/interrupt requests (each
 | 
			
		||||
        input line can be independently configured to select the type (interrupt or event)
 | 
			
		||||
        and the corresponding trigger event (rising or falling or both). Each line can
 | 
			
		||||
        also be masked independently.
 | 
			
		||||
 | 
			
		||||
                     ##### How to use this driver #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
  [..]
 | 
			
		||||
    (#) Enable the GPIO AHB clock using the following function: __HAL_RCC_GPIOx_CLK_ENABLE().
 | 
			
		||||
 | 
			
		||||
    (#) Configure the GPIO pin(s) using HAL_GPIO_Init().
 | 
			
		||||
        (++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure
 | 
			
		||||
        (++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef
 | 
			
		||||
             structure.
 | 
			
		||||
        (++) In case of Output or alternate function mode selection: the speed is
 | 
			
		||||
             configured through "Speed" member from GPIO_InitTypeDef structure.
 | 
			
		||||
        (++) In alternate mode is selection, the alternate function connected to the IO
 | 
			
		||||
             is configured through "Alternate" member from GPIO_InitTypeDef structure.
 | 
			
		||||
        (++) Analog mode is required when a pin is to be used as ADC channel
 | 
			
		||||
             or DAC output.
 | 
			
		||||
        (++) In case of external interrupt/event selection the "Mode" member from
 | 
			
		||||
             GPIO_InitTypeDef structure select the type (interrupt or event) and
 | 
			
		||||
             the corresponding trigger event (rising or falling or both).
 | 
			
		||||
 | 
			
		||||
    (#) In case of external interrupt/event mode selection, configure NVIC IRQ priority
 | 
			
		||||
        mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using
 | 
			
		||||
        HAL_NVIC_EnableIRQ().
 | 
			
		||||
 | 
			
		||||
    (#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin().
 | 
			
		||||
 | 
			
		||||
    (#) To set/reset the level of a pin configured in output mode use
 | 
			
		||||
        HAL_GPIO_WritePin()/HAL_GPIO_TogglePin().
 | 
			
		||||
 | 
			
		||||
   (#) To lock pin configuration until next reset use HAL_GPIO_LockPin().
 | 
			
		||||
  
 | 
			
		||||
    (#) During and just after reset, the alternate functions are not
 | 
			
		||||
        active and the GPIO pins are configured in input floating mode (except JTAG
 | 
			
		||||
        pins).
 | 
			
		||||
 | 
			
		||||
    (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose
 | 
			
		||||
        (PC14 and PC15U, respectively) when the LSE oscillator is off. The LSE has
 | 
			
		||||
        priority over the GPIO function.
 | 
			
		||||
 | 
			
		||||
    (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as
 | 
			
		||||
        general purpose PF0 and PF1, respectively, when the HSE oscillator is off.
 | 
			
		||||
        The HSE has priority over the GPIO function.
 | 
			
		||||
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup GPIO GPIO
 | 
			
		||||
  * @brief GPIO HAL module driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** MISRA C:2012 deviation rule has been granted for following rules:
 | 
			
		||||
  * Rule-18.1_d - Medium: Array pointer `GPIOx' is accessed with index [..,..]
 | 
			
		||||
  * which may be out of array bounds [..,UNKNOWN] in following APIs:
 | 
			
		||||
  * HAL_GPIO_Init
 | 
			
		||||
  * HAL_GPIO_DeInit
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef HAL_GPIO_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private defines -----------------------------------------------------------*/
 | 
			
		||||
/** @addtogroup GPIO_Private_Constants
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define GPIO_NUMBER           (16U)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
  
 | 
			
		||||
/* Private macros ------------------------------------------------------------*/
 | 
			
		||||
/* Private macros ------------------------------------------------------------*/
 | 
			
		||||
/** @defgroup GPIO_Private_Macros GPIO Private Macros
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/* Exported functions --------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/** @defgroup GPIO_Exported_Functions GPIO Exported Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup GPIO_Exported_Functions_Group1 Initialization/de-initialization functions 
 | 
			
		||||
 *  @brief    Initialization and Configuration functions
 | 
			
		||||
 *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
              ##### Initialization and de-initialization functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Initialize the GPIOx peripheral according to the specified parameters in the GPIO_Init.
 | 
			
		||||
  * @param  GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F3 family devices
 | 
			
		||||
  * @param  GPIO_Init pointer to a GPIO_InitTypeDef structure that contains
 | 
			
		||||
  *         the configuration information for the specified GPIO peripheral.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t position = 0x00u;
 | 
			
		||||
  uint32_t iocurrent;
 | 
			
		||||
  uint32_t temp;
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
 | 
			
		||||
  assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
 | 
			
		||||
  assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
 | 
			
		||||
 | 
			
		||||
  /* Configure the port pins */
 | 
			
		||||
  while (((GPIO_Init->Pin) >> position) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    /* Get current io position */
 | 
			
		||||
    iocurrent = (GPIO_Init->Pin) & (1uL << position);
 | 
			
		||||
 | 
			
		||||
    if (iocurrent != 0x00u)
 | 
			
		||||
    {
 | 
			
		||||
      /*--------------------- GPIO Mode Configuration ------------------------*/
 | 
			
		||||
      /* In case of Output or Alternate function mode selection */
 | 
			
		||||
      if(((GPIO_Init->Mode & GPIO_MODE) == MODE_OUTPUT) || ((GPIO_Init->Mode & GPIO_MODE) == MODE_AF))
 | 
			
		||||
      {
 | 
			
		||||
        /* Check the Speed parameter */
 | 
			
		||||
        assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
 | 
			
		||||
        /* Configure the IO Speed */
 | 
			
		||||
        temp = GPIOx->OSPEEDR;
 | 
			
		||||
        temp &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2u));
 | 
			
		||||
        temp |= (GPIO_Init->Speed << (position * 2u));
 | 
			
		||||
        GPIOx->OSPEEDR = temp;
 | 
			
		||||
 | 
			
		||||
        /* Configure the IO Output Type */
 | 
			
		||||
        temp = GPIOx->OTYPER;
 | 
			
		||||
        temp &= ~(GPIO_OTYPER_OT_0 << position) ;
 | 
			
		||||
        temp |= (((GPIO_Init->Mode & OUTPUT_TYPE) >> OUTPUT_TYPE_Pos) << position);
 | 
			
		||||
        GPIOx->OTYPER = temp;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if((GPIO_Init->Mode & GPIO_MODE) != MODE_ANALOG)
 | 
			
		||||
      {
 | 
			
		||||
        /* Check the Pull parameter */
 | 
			
		||||
        assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
 | 
			
		||||
 | 
			
		||||
        /* Activate the Pull-up or Pull down resistor for the current IO */
 | 
			
		||||
        temp = GPIOx->PUPDR;
 | 
			
		||||
        temp &= ~(GPIO_PUPDR_PUPDR0 << (position * 2u));
 | 
			
		||||
        temp |= ((GPIO_Init->Pull) << (position * 2u));
 | 
			
		||||
        GPIOx->PUPDR = temp;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      /*--------------------- GPIO Mode Configuration ------------------------*/
 | 
			
		||||
      /* In case of Alternate function mode selection */
 | 
			
		||||
      if((GPIO_Init->Mode & GPIO_MODE) == MODE_AF)
 | 
			
		||||
      {
 | 
			
		||||
        /* Check the Alternate function parameters */
 | 
			
		||||
        assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
 | 
			
		||||
        assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
 | 
			
		||||
 | 
			
		||||
        /* Configure Alternate function mapped with the current IO */
 | 
			
		||||
        temp = GPIOx->AFR[position >> 3u];
 | 
			
		||||
        temp &= ~(0xFu << ((position & 0x07u) * 4u));
 | 
			
		||||
        temp |= ((GPIO_Init->Alternate) << ((position & 0x07u) * 4u));
 | 
			
		||||
        GPIOx->AFR[position >> 3u] = temp;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      /* Configure IO Direction mode (Input, Output, Alternate or Analog) */
 | 
			
		||||
      temp = GPIOx->MODER;
 | 
			
		||||
      temp &= ~(GPIO_MODER_MODER0 << (position * 2u));
 | 
			
		||||
      temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2u));
 | 
			
		||||
      GPIOx->MODER = temp;
 | 
			
		||||
 | 
			
		||||
      /*--------------------- EXTI Mode Configuration ------------------------*/
 | 
			
		||||
      /* Configure the External Interrupt or event for the current IO */
 | 
			
		||||
      if((GPIO_Init->Mode & EXTI_MODE) != 0x00u)
 | 
			
		||||
      {
 | 
			
		||||
        /* Enable SYSCFG Clock */
 | 
			
		||||
        __HAL_RCC_SYSCFG_CLK_ENABLE();
 | 
			
		||||
 | 
			
		||||
        temp = SYSCFG->EXTICR[position >> 2u];
 | 
			
		||||
        temp &= ~(0x0FuL << (4u * (position & 0x03u)));
 | 
			
		||||
        temp |= (GPIO_GET_INDEX(GPIOx) << (4u * (position & 0x03u)));
 | 
			
		||||
        SYSCFG->EXTICR[position >> 2u] = temp;
 | 
			
		||||
 | 
			
		||||
        /* Clear Rising Falling edge configuration */
 | 
			
		||||
        temp = EXTI->RTSR;
 | 
			
		||||
        temp &= ~(iocurrent);
 | 
			
		||||
        if((GPIO_Init->Mode & TRIGGER_RISING) != 0x00u)
 | 
			
		||||
        {
 | 
			
		||||
          temp |= iocurrent;
 | 
			
		||||
        }
 | 
			
		||||
        EXTI->RTSR = temp;
 | 
			
		||||
 | 
			
		||||
        temp = EXTI->FTSR;
 | 
			
		||||
        temp &= ~(iocurrent);
 | 
			
		||||
        if((GPIO_Init->Mode & TRIGGER_FALLING) != 0x00u)
 | 
			
		||||
        {
 | 
			
		||||
          temp |= iocurrent;
 | 
			
		||||
        }
 | 
			
		||||
        EXTI->FTSR = temp;
 | 
			
		||||
 | 
			
		||||
        temp = EXTI->EMR;
 | 
			
		||||
        temp &= ~(iocurrent);
 | 
			
		||||
        if((GPIO_Init->Mode & EXTI_EVT) != 0x00u)
 | 
			
		||||
        {
 | 
			
		||||
          temp |= iocurrent;
 | 
			
		||||
        }
 | 
			
		||||
        EXTI->EMR = temp;
 | 
			
		||||
 | 
			
		||||
        /* Clear EXTI line configuration */
 | 
			
		||||
        temp = EXTI->IMR;
 | 
			
		||||
        temp &= ~(iocurrent);
 | 
			
		||||
        if((GPIO_Init->Mode & EXTI_IT) != 0x00u)
 | 
			
		||||
        {
 | 
			
		||||
          temp |= iocurrent;
 | 
			
		||||
        }
 | 
			
		||||
        EXTI->IMR = temp;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    position++;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  De-initialize the GPIOx peripheral registers to their default reset values.
 | 
			
		||||
  * @param  GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F30X device or STM32F37X device
 | 
			
		||||
  * @param  GPIO_Pin specifies the port bit to be written.
 | 
			
		||||
  *         This parameter can be one of GPIO_PIN_x where x can be (0..15).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_GPIO_DeInit(GPIO_TypeDef  *GPIOx, uint32_t GPIO_Pin)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t position = 0x00u;
 | 
			
		||||
  uint32_t iocurrent;
 | 
			
		||||
  uint32_t tmp;
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
 | 
			
		||||
  assert_param(IS_GPIO_PIN(GPIO_Pin));
 | 
			
		||||
 | 
			
		||||
  /* Configure the port pins */
 | 
			
		||||
  while ((GPIO_Pin >> position) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    /* Get current io position */
 | 
			
		||||
    iocurrent = (GPIO_Pin) & (1uL << position);
 | 
			
		||||
 | 
			
		||||
    if (iocurrent != 0x00u)
 | 
			
		||||
    {
 | 
			
		||||
      /*------------------------- EXTI Mode Configuration --------------------*/
 | 
			
		||||
      /* Clear the External Interrupt or Event for the current IO */
 | 
			
		||||
 | 
			
		||||
      tmp = SYSCFG->EXTICR[position >> 2u];
 | 
			
		||||
      tmp &= (0x0FuL << (4u * (position & 0x03u)));
 | 
			
		||||
      if (tmp == (GPIO_GET_INDEX(GPIOx) << (4u * (position & 0x03u))))
 | 
			
		||||
      {
 | 
			
		||||
        /* Clear EXTI line configuration */
 | 
			
		||||
        EXTI->IMR &= ~((uint32_t)iocurrent);
 | 
			
		||||
        EXTI->EMR &= ~((uint32_t)iocurrent);
 | 
			
		||||
        
 | 
			
		||||
        /* Clear Rising Falling edge configuration */
 | 
			
		||||
        EXTI->FTSR &= ~((uint32_t)iocurrent);
 | 
			
		||||
        EXTI->RTSR &= ~((uint32_t)iocurrent);
 | 
			
		||||
 | 
			
		||||
        /* Configure the External Interrupt or event for the current IO */
 | 
			
		||||
        tmp = 0x0FuL << (4u * (position & 0x03u));
 | 
			
		||||
        SYSCFG->EXTICR[position >> 2u] &= ~tmp;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      /*------------------------- GPIO Mode Configuration --------------------*/
 | 
			
		||||
      /* Configure IO Direction in Input Floating Mode */
 | 
			
		||||
      GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (position * 2u));
 | 
			
		||||
 | 
			
		||||
      /* Configure the default Alternate Function in current IO */
 | 
			
		||||
      GPIOx->AFR[position >> 3u] &= ~(0xFu << ((uint32_t)(position & 0x07u) * 4u)) ;
 | 
			
		||||
 | 
			
		||||
      /* Deactivate the Pull-up and Pull-down resistor for the current IO */
 | 
			
		||||
      GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << (position * 2u));
 | 
			
		||||
 | 
			
		||||
      /* Configure the default value IO Output Type */
 | 
			
		||||
      GPIOx->OTYPER  &= ~(GPIO_OTYPER_OT_0 << position) ;
 | 
			
		||||
 | 
			
		||||
      /* Configure the default value for IO Speed */
 | 
			
		||||
      GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2u));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    position++;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup GPIO_Exported_Functions_Group2 IO operation functions 
 | 
			
		||||
 *  @brief GPIO Read, Write, Toggle, Lock and EXTI management functions.
 | 
			
		||||
 *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                       ##### IO operation functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Read the specified input port pin.
 | 
			
		||||
  * @param  GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F3 family
 | 
			
		||||
  * @param  GPIO_Pin specifies the port bit to read.
 | 
			
		||||
  *         This parameter can be GPIO_PIN_x where x can be (0..15).
 | 
			
		||||
  * @retval The input port pin value.
 | 
			
		||||
  */
 | 
			
		||||
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
 | 
			
		||||
{
 | 
			
		||||
  GPIO_PinState bitstatus;
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_GPIO_PIN(GPIO_Pin));
 | 
			
		||||
 | 
			
		||||
  if((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)
 | 
			
		||||
  {
 | 
			
		||||
    bitstatus = GPIO_PIN_SET;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    bitstatus = GPIO_PIN_RESET;
 | 
			
		||||
  }
 | 
			
		||||
  return bitstatus;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Set or clear the selected data port bit.
 | 
			
		||||
  *
 | 
			
		||||
  * @note   This function uses GPIOx_BSRR and GPIOx_BRR registers to allow atomic read/modify
 | 
			
		||||
  *         accesses. In this way, there is no risk of an IRQ occurring between
 | 
			
		||||
  *         the read and the modify access.
 | 
			
		||||
  *
 | 
			
		||||
  * @param  GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F3 family
 | 
			
		||||
  * @param  GPIO_Pin specifies the port bit to be written.
 | 
			
		||||
  *         This parameter can be one of GPIO_PIN_x where x can be (0..15).
 | 
			
		||||
  * @param  PinState specifies the value to be written to the selected bit.
 | 
			
		||||
  *         This parameter can be one of the GPIO_PinState enum values:
 | 
			
		||||
  *            @arg GPIO_PIN_RESET: to clear the port pin
 | 
			
		||||
  *            @arg GPIO_PIN_SET: to set the port pin
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_GPIO_PIN(GPIO_Pin));
 | 
			
		||||
  assert_param(IS_GPIO_PIN_ACTION(PinState));
 | 
			
		||||
 | 
			
		||||
  if(PinState != GPIO_PIN_RESET)
 | 
			
		||||
  {
 | 
			
		||||
    GPIOx->BSRR = (uint32_t)GPIO_Pin;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    GPIOx->BRR = (uint32_t)GPIO_Pin;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Toggle the specified GPIO pin.
 | 
			
		||||
  * @param  GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F3 family
 | 
			
		||||
  * @param  GPIO_Pin specifies the pin to be toggled.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t odr;
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_GPIO_PIN(GPIO_Pin));
 | 
			
		||||
 | 
			
		||||
  /* get current Output Data Register value */
 | 
			
		||||
  odr = GPIOx->ODR;
 | 
			
		||||
 | 
			
		||||
  /* Set selected pins that were at low level, and reset ones that were high */
 | 
			
		||||
  GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* @brief  Lock GPIO Pins configuration registers.
 | 
			
		||||
  * @note   The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
 | 
			
		||||
  *         GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
 | 
			
		||||
  * @note   The configuration of the locked GPIO pins can no longer be modified
 | 
			
		||||
  *         until the next reset.
 | 
			
		||||
  * @param  GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F3 family
 | 
			
		||||
  * @param  GPIO_Pin specifies the port bits to be locked.
 | 
			
		||||
  *         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
 | 
			
		||||
{
 | 
			
		||||
  __IO uint32_t tmp = GPIO_LCKR_LCKK;
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_GPIO_LOCK_INSTANCE(GPIOx));
 | 
			
		||||
  assert_param(IS_GPIO_PIN(GPIO_Pin));
 | 
			
		||||
 | 
			
		||||
  /* Apply lock key write sequence */
 | 
			
		||||
  tmp |= GPIO_Pin;
 | 
			
		||||
  /* Set LCKx bit(s): LCKK='1' + LCK[15U-0] */
 | 
			
		||||
  GPIOx->LCKR = tmp;
 | 
			
		||||
  /* Reset LCKx bit(s): LCKK='0' + LCK[15U-0] */
 | 
			
		||||
  GPIOx->LCKR = GPIO_Pin;
 | 
			
		||||
  /* Set LCKx bit(s): LCKK='1' + LCK[15U-0] */
 | 
			
		||||
  GPIOx->LCKR = tmp;
 | 
			
		||||
  /* Read LCKK register. This read is mandatory to complete key lock sequence */
 | 
			
		||||
  tmp = GPIOx->LCKR;
 | 
			
		||||
 | 
			
		||||
  /* read again in order to confirm lock is active */
 | 
			
		||||
 if((GPIOx->LCKR & GPIO_LCKR_LCKK) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_OK;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Handle EXTI interrupt request.
 | 
			
		||||
  * @param  GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
 | 
			
		||||
{
 | 
			
		||||
  /* EXTI line interrupt detected */
 | 
			
		||||
  if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != 0x00u)
 | 
			
		||||
  {
 | 
			
		||||
    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
 | 
			
		||||
    HAL_GPIO_EXTI_Callback(GPIO_Pin);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  EXTI line detection callback.
 | 
			
		||||
  * @param  GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
 | 
			
		||||
{
 | 
			
		||||
  /* Prevent unused argument(s) compilation warning */
 | 
			
		||||
  UNUSED(GPIO_Pin);
 | 
			
		||||
 | 
			
		||||
  /* NOTE: This function should not be modified, when the callback is needed,
 | 
			
		||||
           the HAL_GPIO_EXTI_Callback could be implemented in the user file
 | 
			
		||||
   */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif /* HAL_GPIO_MODULE_ENABLED */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										7278
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_i2c.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7278
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_i2c.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -0,0 +1,364 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal_i2c_ex.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   I2C Extended HAL module driver.
 | 
			
		||||
  *          This file provides firmware functions to manage the following
 | 
			
		||||
  *          functionalities of I2C Extended peripheral:
 | 
			
		||||
  *           + Filter Mode Functions
 | 
			
		||||
  *           + WakeUp Mode Functions
 | 
			
		||||
  *           + FastModePlus Functions
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file
 | 
			
		||||
  * in the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  @verbatim
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
               ##### I2C peripheral Extended features  #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
  [..] Comparing to other previous devices, the I2C interface for STM32F3xx
 | 
			
		||||
       devices contains the following additional features
 | 
			
		||||
 | 
			
		||||
       (+) Possibility to disable or enable Analog Noise Filter
 | 
			
		||||
       (+) Use of a configured Digital Noise Filter
 | 
			
		||||
       (+) Disable or enable wakeup from Stop mode(s)
 | 
			
		||||
       (+) Disable or enable Fast Mode Plus
 | 
			
		||||
 | 
			
		||||
                     ##### How to use this driver #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
  [..] This driver provides functions to configure Noise Filter and Wake Up Feature
 | 
			
		||||
    (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter()
 | 
			
		||||
    (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter()
 | 
			
		||||
    (#) Configure the enable or disable of I2C Wake Up Mode using the functions :
 | 
			
		||||
          (++) HAL_I2CEx_EnableWakeUp()
 | 
			
		||||
          (++) HAL_I2CEx_DisableWakeUp()
 | 
			
		||||
    (#) Configure the enable or disable of fast mode plus driving capability using the functions :
 | 
			
		||||
          (++) HAL_I2CEx_EnableFastModePlus()
 | 
			
		||||
          (++) HAL_I2CEx_DisableFastModePlus()
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup I2CEx I2CEx
 | 
			
		||||
  * @brief I2C Extended HAL module driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef HAL_I2C_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private define ------------------------------------------------------------*/
 | 
			
		||||
/* Private macro -------------------------------------------------------------*/
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/* Private functions ---------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup I2CEx_Exported_Functions_Group1 Filter Mode Functions
 | 
			
		||||
  * @brief    Filter Mode Functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                      ##### Filter Mode Functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    [..] This section provides functions allowing to:
 | 
			
		||||
      (+) Configure Noise Filters
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Configure I2C Analog noise filter.
 | 
			
		||||
  * @param  hi2c Pointer to a I2C_HandleTypeDef structure that contains
 | 
			
		||||
  *                the configuration information for the specified I2Cx peripheral.
 | 
			
		||||
  * @param  AnalogFilter New state of the Analog filter.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
 | 
			
		||||
  assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
 | 
			
		||||
 | 
			
		||||
  if (hi2c->State == HAL_I2C_STATE_READY)
 | 
			
		||||
  {
 | 
			
		||||
    /* Process Locked */
 | 
			
		||||
    __HAL_LOCK(hi2c);
 | 
			
		||||
 | 
			
		||||
    hi2c->State = HAL_I2C_STATE_BUSY;
 | 
			
		||||
 | 
			
		||||
    /* Disable the selected I2C peripheral */
 | 
			
		||||
    __HAL_I2C_DISABLE(hi2c);
 | 
			
		||||
 | 
			
		||||
    /* Reset I2Cx ANOFF bit */
 | 
			
		||||
    hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
 | 
			
		||||
 | 
			
		||||
    /* Set analog filter bit*/
 | 
			
		||||
    hi2c->Instance->CR1 |= AnalogFilter;
 | 
			
		||||
 | 
			
		||||
    __HAL_I2C_ENABLE(hi2c);
 | 
			
		||||
 | 
			
		||||
    hi2c->State = HAL_I2C_STATE_READY;
 | 
			
		||||
 | 
			
		||||
    /* Process Unlocked */
 | 
			
		||||
    __HAL_UNLOCK(hi2c);
 | 
			
		||||
 | 
			
		||||
    return HAL_OK;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_BUSY;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Configure I2C Digital noise filter.
 | 
			
		||||
  * @param  hi2c Pointer to a I2C_HandleTypeDef structure that contains
 | 
			
		||||
  *                the configuration information for the specified I2Cx peripheral.
 | 
			
		||||
  * @param  DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t tmpreg;
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
 | 
			
		||||
  assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
 | 
			
		||||
 | 
			
		||||
  if (hi2c->State == HAL_I2C_STATE_READY)
 | 
			
		||||
  {
 | 
			
		||||
    /* Process Locked */
 | 
			
		||||
    __HAL_LOCK(hi2c);
 | 
			
		||||
 | 
			
		||||
    hi2c->State = HAL_I2C_STATE_BUSY;
 | 
			
		||||
 | 
			
		||||
    /* Disable the selected I2C peripheral */
 | 
			
		||||
    __HAL_I2C_DISABLE(hi2c);
 | 
			
		||||
 | 
			
		||||
    /* Get the old register value */
 | 
			
		||||
    tmpreg = hi2c->Instance->CR1;
 | 
			
		||||
 | 
			
		||||
    /* Reset I2Cx DNF bits [11:8] */
 | 
			
		||||
    tmpreg &= ~(I2C_CR1_DNF);
 | 
			
		||||
 | 
			
		||||
    /* Set I2Cx DNF coefficient */
 | 
			
		||||
    tmpreg |= DigitalFilter << 8U;
 | 
			
		||||
 | 
			
		||||
    /* Store the new register value */
 | 
			
		||||
    hi2c->Instance->CR1 = tmpreg;
 | 
			
		||||
 | 
			
		||||
    __HAL_I2C_ENABLE(hi2c);
 | 
			
		||||
 | 
			
		||||
    hi2c->State = HAL_I2C_STATE_READY;
 | 
			
		||||
 | 
			
		||||
    /* Process Unlocked */
 | 
			
		||||
    __HAL_UNLOCK(hi2c);
 | 
			
		||||
 | 
			
		||||
    return HAL_OK;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_BUSY;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup I2CEx_Exported_Functions_Group2 WakeUp Mode Functions
 | 
			
		||||
  * @brief    WakeUp Mode Functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                      ##### WakeUp Mode Functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    [..] This section provides functions allowing to:
 | 
			
		||||
      (+) Configure Wake Up Feature
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Enable I2C wakeup from Stop mode(s).
 | 
			
		||||
  * @param  hi2c Pointer to a I2C_HandleTypeDef structure that contains
 | 
			
		||||
  *                the configuration information for the specified I2Cx peripheral.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));
 | 
			
		||||
 | 
			
		||||
  if (hi2c->State == HAL_I2C_STATE_READY)
 | 
			
		||||
  {
 | 
			
		||||
    /* Process Locked */
 | 
			
		||||
    __HAL_LOCK(hi2c);
 | 
			
		||||
 | 
			
		||||
    hi2c->State = HAL_I2C_STATE_BUSY;
 | 
			
		||||
 | 
			
		||||
    /* Disable the selected I2C peripheral */
 | 
			
		||||
    __HAL_I2C_DISABLE(hi2c);
 | 
			
		||||
 | 
			
		||||
    /* Enable wakeup from stop mode */
 | 
			
		||||
    hi2c->Instance->CR1 |= I2C_CR1_WUPEN;
 | 
			
		||||
 | 
			
		||||
    __HAL_I2C_ENABLE(hi2c);
 | 
			
		||||
 | 
			
		||||
    hi2c->State = HAL_I2C_STATE_READY;
 | 
			
		||||
 | 
			
		||||
    /* Process Unlocked */
 | 
			
		||||
    __HAL_UNLOCK(hi2c);
 | 
			
		||||
 | 
			
		||||
    return HAL_OK;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_BUSY;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Disable I2C wakeup from Stop mode(s).
 | 
			
		||||
  * @param  hi2c Pointer to a I2C_HandleTypeDef structure that contains
 | 
			
		||||
  *                the configuration information for the specified I2Cx peripheral.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance));
 | 
			
		||||
 | 
			
		||||
  if (hi2c->State == HAL_I2C_STATE_READY)
 | 
			
		||||
  {
 | 
			
		||||
    /* Process Locked */
 | 
			
		||||
    __HAL_LOCK(hi2c);
 | 
			
		||||
 | 
			
		||||
    hi2c->State = HAL_I2C_STATE_BUSY;
 | 
			
		||||
 | 
			
		||||
    /* Disable the selected I2C peripheral */
 | 
			
		||||
    __HAL_I2C_DISABLE(hi2c);
 | 
			
		||||
 | 
			
		||||
    /* Enable wakeup from stop mode */
 | 
			
		||||
    hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN);
 | 
			
		||||
 | 
			
		||||
    __HAL_I2C_ENABLE(hi2c);
 | 
			
		||||
 | 
			
		||||
    hi2c->State = HAL_I2C_STATE_READY;
 | 
			
		||||
 | 
			
		||||
    /* Process Unlocked */
 | 
			
		||||
    __HAL_UNLOCK(hi2c);
 | 
			
		||||
 | 
			
		||||
    return HAL_OK;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_BUSY;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup I2CEx_Exported_Functions_Group3 Fast Mode Plus Functions
 | 
			
		||||
  * @brief    Fast Mode Plus Functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                      ##### Fast Mode Plus Functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    [..] This section provides functions allowing to:
 | 
			
		||||
      (+) Configure Fast Mode Plus
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Enable the I2C fast mode plus driving capability.
 | 
			
		||||
  * @param ConfigFastModePlus Selects the pin.
 | 
			
		||||
  *   This parameter can be one of the @ref I2CEx_FastModePlus values
 | 
			
		||||
  * @note  For I2C1, fast mode plus driving capability can be enabled on all selected
 | 
			
		||||
  *        I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently
 | 
			
		||||
  *        on each one of the following pins PB6, PB7, PB8 and PB9.
 | 
			
		||||
  * @note  For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
 | 
			
		||||
  *        can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter.
 | 
			
		||||
  * @note  For all I2C2 pins fast mode plus driving capability can be enabled
 | 
			
		||||
  *        only by using I2C_FASTMODEPLUS_I2C2 parameter.
 | 
			
		||||
  * @note  For all I2C3 pins fast mode plus driving capability can be enabled
 | 
			
		||||
  *        only by using I2C_FASTMODEPLUS_I2C3 parameter.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameter */
 | 
			
		||||
  assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));
 | 
			
		||||
 | 
			
		||||
  /* Enable SYSCFG clock */
 | 
			
		||||
  __HAL_RCC_SYSCFG_CLK_ENABLE();
 | 
			
		||||
 | 
			
		||||
  /* Enable fast mode plus driving capability for selected pin */
 | 
			
		||||
  SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Disable the I2C fast mode plus driving capability.
 | 
			
		||||
  * @param ConfigFastModePlus Selects the pin.
 | 
			
		||||
  *   This parameter can be one of the @ref I2CEx_FastModePlus values
 | 
			
		||||
  * @note  For I2C1, fast mode plus driving capability can be disabled on all selected
 | 
			
		||||
  *        I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently
 | 
			
		||||
  *        on each one of the following pins PB6, PB7, PB8 and PB9.
 | 
			
		||||
  * @note  For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
 | 
			
		||||
  *        can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter.
 | 
			
		||||
  * @note  For all I2C2 pins fast mode plus driving capability can be disabled
 | 
			
		||||
  *        only by using I2C_FASTMODEPLUS_I2C2 parameter.
 | 
			
		||||
  * @note  For all I2C3 pins fast mode plus driving capability can be disabled
 | 
			
		||||
  *        only by using I2C_FASTMODEPLUS_I2C3 parameter.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameter */
 | 
			
		||||
  assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus));
 | 
			
		||||
 | 
			
		||||
  /* Enable SYSCFG clock */
 | 
			
		||||
  __HAL_RCC_SYSCFG_CLK_ENABLE();
 | 
			
		||||
 | 
			
		||||
  /* Disable fast mode plus driving capability for selected pin */
 | 
			
		||||
  CLEAR_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif /* HAL_I2C_MODULE_ENABLED */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
@ -0,0 +1,457 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal_pwr.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   PWR HAL module driver.
 | 
			
		||||
  *          This file provides firmware functions to manage the following
 | 
			
		||||
  *          functionalities of the Power Controller (PWR) peripheral:
 | 
			
		||||
  *           + Initialization/de-initialization functions
 | 
			
		||||
  *           + Peripheral Control functions
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file
 | 
			
		||||
  * in the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup PWR PWR
 | 
			
		||||
  * @brief PWR HAL module driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef HAL_PWR_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private define ------------------------------------------------------------*/
 | 
			
		||||
/* Private macro -------------------------------------------------------------*/
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/* Private functions ---------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/** @defgroup PWR_Exported_Functions PWR Exported Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions 
 | 
			
		||||
  *  @brief    Initialization and de-initialization functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
              ##### Initialization and de-initialization functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    [..]
 | 
			
		||||
      After reset, the backup domain (RTC registers, RTC backup data
 | 
			
		||||
      registers and backup SRAM) is protected against possible unwanted
 | 
			
		||||
      write accesses.
 | 
			
		||||
      To enable access to the RTC Domain and RTC registers, proceed as follows:
 | 
			
		||||
        (+) Enable the Power Controller (PWR) APB1 interface clock using the
 | 
			
		||||
            __HAL_RCC_PWR_CLK_ENABLE() macro.
 | 
			
		||||
        (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Deinitializes the PWR peripheral registers to their default reset values.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_DeInit(void)
 | 
			
		||||
{
 | 
			
		||||
  __HAL_RCC_PWR_FORCE_RESET();
 | 
			
		||||
  __HAL_RCC_PWR_RELEASE_RESET();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Enables access to the backup domain (RTC registers, RTC
 | 
			
		||||
  *         backup data registers and backup SRAM).
 | 
			
		||||
  * @note  If the HSE divided by 32 is used as the RTC clock, the
 | 
			
		||||
  *         Backup Domain Access should be kept enabled.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_EnableBkUpAccess(void)
 | 
			
		||||
{
 | 
			
		||||
  SET_BIT(PWR->CR, PWR_CR_DBP);  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Disables access to the backup domain (RTC registers, RTC
 | 
			
		||||
  *         backup data registers and backup SRAM).
 | 
			
		||||
  * @note  If the HSE divided by 32 is used as the RTC clock, the
 | 
			
		||||
  *         Backup Domain Access should be kept enabled.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_DisableBkUpAccess(void)
 | 
			
		||||
{
 | 
			
		||||
  CLEAR_BIT(PWR->CR, PWR_CR_DBP);  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions 
 | 
			
		||||
  *  @brief Low Power modes configuration functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                 ##### Peripheral Control functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    
 | 
			
		||||
    *** WakeUp pin configuration ***
 | 
			
		||||
    ================================
 | 
			
		||||
    [..]
 | 
			
		||||
      (+) WakeUp pin is used to wakeup the system from Standby mode. This pin is
 | 
			
		||||
          forced in input pull down configuration and is active on rising edges.
 | 
			
		||||
      (+) There are up to three WakeUp pins:
 | 
			
		||||
          (++)WakeUp Pin 1 on PA.00.
 | 
			
		||||
          (++)WakeUp Pin 2 on PC.13 (STM32F303xC, STM32F303xE only).
 | 
			
		||||
          (++)WakeUp Pin 3 on PE.06.
 | 
			
		||||
 | 
			
		||||
    *** Main and Backup Regulators configuration ***
 | 
			
		||||
    ================================================
 | 
			
		||||
    [..]
 | 
			
		||||
      (+) When the backup domain is supplied by VDD (analog switch connected to VDD)
 | 
			
		||||
          the backup SRAM is powered from VDD which replaces the VBAT power supply to
 | 
			
		||||
          save battery life.
 | 
			
		||||
 | 
			
		||||
      (+) The backup SRAM is not mass erased by a tamper event. It is read
 | 
			
		||||
          protected to prevent confidential data, such as cryptographic private
 | 
			
		||||
          key, from being accessed. The backup SRAM can be erased only through
 | 
			
		||||
          the Flash interface when a protection level change from level 1 to
 | 
			
		||||
          level 0 is requested.
 | 
			
		||||
      -@- Refer to the description of Read protection (RDP) in the Flash
 | 
			
		||||
          programming manual.
 | 
			
		||||
 | 
			
		||||
        Refer to the datasheets for more details.
 | 
			
		||||
 | 
			
		||||
    *** Low Power modes configuration ***
 | 
			
		||||
    =====================================
 | 
			
		||||
    [..]
 | 
			
		||||
      The devices feature 3 low-power modes:
 | 
			
		||||
      (+) Sleep mode: Cortex-M4 core stopped, peripherals kept running.
 | 
			
		||||
      (+) Stop mode: all clocks are stopped, regulator running, regulator
 | 
			
		||||
          in low power mode
 | 
			
		||||
      (+) Standby mode: 1.2V domain powered off (mode not available on STM32F3x8 devices).
 | 
			
		||||
 | 
			
		||||
   *** Sleep mode ***
 | 
			
		||||
   ==================
 | 
			
		||||
    [..]
 | 
			
		||||
      (+) Entry:
 | 
			
		||||
          The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFx)
 | 
			
		||||
              functions with
 | 
			
		||||
          (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
 | 
			
		||||
          (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
 | 
			
		||||
     
 | 
			
		||||
      (+) Exit:
 | 
			
		||||
        (++) Any peripheral interrupt acknowledged by the nested vectored interrupt
 | 
			
		||||
              controller (NVIC) can wake up the device from Sleep mode.
 | 
			
		||||
 | 
			
		||||
   *** Stop mode ***
 | 
			
		||||
   =================
 | 
			
		||||
    [..]
 | 
			
		||||
      In Stop mode, all clocks in the 1.8V domain are stopped, the PLL, the HSI,
 | 
			
		||||
      and the HSE RC oscillators are disabled. Internal SRAM and register contents
 | 
			
		||||
      are preserved.
 | 
			
		||||
      The voltage regulator can be configured either in normal or low-power mode to minimize the consumption.
 | 
			
		||||
 | 
			
		||||
      (+) Entry:
 | 
			
		||||
          The Stop mode is entered using the HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI )
 | 
			
		||||
             function with:
 | 
			
		||||
          (++) Main regulator ON or
 | 
			
		||||
          (++) Low Power regulator ON.
 | 
			
		||||
          (++) PWR_STOPENTRY_WFI: enter STOP mode with WFI instruction or
 | 
			
		||||
          (++) PWR_STOPENTRY_WFE: enter STOP mode with WFE instruction
 | 
			
		||||
      (+) Exit:
 | 
			
		||||
          (++) Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
 | 
			
		||||
          (++) Some specific communication peripherals (CEC, USART, I2C) interrupts, 
 | 
			
		||||
               when programmed in wakeup mode (the peripheral must be 
 | 
			
		||||
               programmed in wakeup mode and the corresponding interrupt vector 
 | 
			
		||||
               must be enabled in the NVIC).
 | 
			
		||||
 | 
			
		||||
   *** Standby mode ***
 | 
			
		||||
   ====================
 | 
			
		||||
     [..]
 | 
			
		||||
      The Standby mode allows to achieve the lowest power consumption. It is based
 | 
			
		||||
      on the Cortex-M4 deep sleep mode, with the voltage regulator disabled.
 | 
			
		||||
      The 1.8V domain is consequently powered off. The PLL, the HSI oscillator and
 | 
			
		||||
      the HSE oscillator are also switched off. SRAM and register contents are lost
 | 
			
		||||
      except for the RTC registers, RTC backup registers, backup SRAM and Standby
 | 
			
		||||
      circuitry.
 | 
			
		||||
      The voltage regulator is OFF.
 | 
			
		||||
 | 
			
		||||
      (+) Entry:
 | 
			
		||||
          (++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function.
 | 
			
		||||
      (+) Exit:
 | 
			
		||||
          (++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup,
 | 
			
		||||
               tamper event, time-stamp event, external reset in NRST pin, IWDG reset.
 | 
			
		||||
 | 
			
		||||
   *** Auto-wakeup (AWU) from low-power mode ***
 | 
			
		||||
   =============================================
 | 
			
		||||
    [..]
 | 
			
		||||
      The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC
 | 
			
		||||
      Wakeup event, a tamper event, a time-stamp event, or a comparator event, 
 | 
			
		||||
      without depending on an external interrupt (Auto-wakeup mode).
 | 
			
		||||
 | 
			
		||||
    (+) RTC auto-wakeup (AWU) from the Stop and Standby modes
 | 
			
		||||
 | 
			
		||||
      (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to
 | 
			
		||||
            configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function.
 | 
			
		||||
 | 
			
		||||
      (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it
 | 
			
		||||
           is necessary to configure the RTC to detect the tamper or time stamp event using the
 | 
			
		||||
           HAL_RTC_SetTimeStamp_IT() or HAL_RTC_SetTamper_IT() functions.
 | 
			
		||||
 | 
			
		||||
      (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to
 | 
			
		||||
           configure the RTC to generate the RTC WakeUp event using the HAL_RTC_SetWakeUpTimer_IT() function.
 | 
			
		||||
 | 
			
		||||
    (+) Comparator auto-wakeup (AWU) from the Stop mode
 | 
			
		||||
 | 
			
		||||
      (++) To wake up from the Stop mode with a comparator wakeup event, it is necessary to:
 | 
			
		||||
           (+++) Configure the EXTI Line associated with the comparator (example EXTI Line 22 for comparator 2U) 
 | 
			
		||||
                 to be sensitive to to the selected edges (falling, rising or falling 
 | 
			
		||||
                 and rising) (Interrupt or Event modes) using the EXTI_Init() function.
 | 
			
		||||
           (+++) Configure the comparator to generate the event.      
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Enables the WakeUp PINx functionality.
 | 
			
		||||
  * @param WakeUpPinx Specifies the Power Wake-Up pin to enable.
 | 
			
		||||
  *         This parameter can be value of :
 | 
			
		||||
  *           @ref PWR_WakeUp_Pins
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
 | 
			
		||||
  /* Enable the EWUPx pin */
 | 
			
		||||
  SET_BIT(PWR->CSR, WakeUpPinx);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Disables the WakeUp PINx functionality.
 | 
			
		||||
  * @param WakeUpPinx Specifies the Power Wake-Up pin to disable.
 | 
			
		||||
  *         This parameter can be values of :
 | 
			
		||||
  *           @ref PWR_WakeUp_Pins
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
 | 
			
		||||
  /* Disable the EWUPx pin */
 | 
			
		||||
  CLEAR_BIT(PWR->CSR, WakeUpPinx);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Enters Sleep mode.
 | 
			
		||||
  * @note  In Sleep mode, all I/O pins keep the same state as in Run mode.
 | 
			
		||||
  * @param Regulator Specifies the regulator state in SLEEP mode.
 | 
			
		||||
  *          This parameter can be one of the following values:
 | 
			
		||||
  *            @arg PWR_MAINREGULATOR_ON: SLEEP mode with regulator ON
 | 
			
		||||
  *            @arg PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON
 | 
			
		||||
  * @note This parameter has no effect in F3 family and is just maintained to 
 | 
			
		||||
  *       offer full portability of other STM32 families software.
 | 
			
		||||
  * @param SLEEPEntry Specifies if SLEEP mode is entered with WFI or WFE instruction.
 | 
			
		||||
  *           When WFI entry is used, tick interrupt have to be disabled if not desired as 
 | 
			
		||||
  *           the interrupt wake up source.
 | 
			
		||||
  *           This parameter can be one of the following values:
 | 
			
		||||
  *            @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
 | 
			
		||||
  *            @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));
 | 
			
		||||
 | 
			
		||||
  /* Clear SLEEPDEEP bit of Cortex System Control Register */
 | 
			
		||||
  SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
 | 
			
		||||
 | 
			
		||||
  /* Select SLEEP mode entry -------------------------------------------------*/
 | 
			
		||||
  if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
 | 
			
		||||
  {
 | 
			
		||||
    /* Request Wait For Interrupt */
 | 
			
		||||
    __WFI();
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    /* Request Wait For Event */
 | 
			
		||||
    __SEV();
 | 
			
		||||
    __WFE();
 | 
			
		||||
    __WFE();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Enters STOP mode.
 | 
			
		||||
  * @note  In Stop mode, all I/O pins keep the same state as in Run mode.
 | 
			
		||||
  * @note  When exiting Stop mode by issuing an interrupt or a wakeup event,
 | 
			
		||||
  *         the HSI RC oscillator is selected as system clock.
 | 
			
		||||
  * @note  When the voltage regulator operates in low power mode, an additional
 | 
			
		||||
  *         startup delay is incurred when waking up from Stop mode.
 | 
			
		||||
  *         By keeping the internal regulator ON during Stop mode, the consumption
 | 
			
		||||
  *         is higher although the startup time is reduced.
 | 
			
		||||
  * @param Regulator Specifies the regulator state in STOP mode.
 | 
			
		||||
  *          This parameter can be one of the following values:
 | 
			
		||||
  *            @arg PWR_MAINREGULATOR_ON: STOP mode with regulator ON
 | 
			
		||||
  *            @arg PWR_LOWPOWERREGULATOR_ON: STOP mode with low power regulator ON
 | 
			
		||||
  * @param STOPEntry specifies if STOP mode in entered with WFI or WFE instruction.
 | 
			
		||||
  *          This parameter can be one of the following values:
 | 
			
		||||
  *            @arg PWR_STOPENTRY_WFI:Enter STOP mode with WFI instruction
 | 
			
		||||
  *            @arg PWR_STOPENTRY_WFE: Enter STOP mode with WFE instruction
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t tmpreg = 0U;
 | 
			
		||||
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_PWR_REGULATOR(Regulator));
 | 
			
		||||
  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
 | 
			
		||||
 | 
			
		||||
  /* Select the regulator state in STOP mode ---------------------------------*/
 | 
			
		||||
  tmpreg = PWR->CR;
 | 
			
		||||
  
 | 
			
		||||
  /* Clear PDDS and LPDS bits */
 | 
			
		||||
  tmpreg &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPDS);
 | 
			
		||||
 | 
			
		||||
  /* Set LPDS bit according to Regulator value */
 | 
			
		||||
  tmpreg |= Regulator;
 | 
			
		||||
 | 
			
		||||
  /* Store the new value */
 | 
			
		||||
  PWR->CR = tmpreg;
 | 
			
		||||
 | 
			
		||||
  /* Set SLEEPDEEP bit of Cortex System Control Register */
 | 
			
		||||
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
 | 
			
		||||
 | 
			
		||||
  /* Select STOP mode entry --------------------------------------------------*/
 | 
			
		||||
  if(STOPEntry == PWR_STOPENTRY_WFI)
 | 
			
		||||
  {
 | 
			
		||||
    /* Request Wait For Interrupt */
 | 
			
		||||
    __WFI();
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    /* Request Wait For Event */
 | 
			
		||||
    __SEV();
 | 
			
		||||
    __WFE();
 | 
			
		||||
    __WFE();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Reset SLEEPDEEP bit of Cortex System Control Register */
 | 
			
		||||
  SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Enters STANDBY mode.
 | 
			
		||||
  * @note  In Standby mode, all I/O pins are high impedance except for:
 | 
			
		||||
  *          - Reset pad (still available), 
 | 
			
		||||
  *          - RTC alternate function pins if configured for tamper, time-stamp, RTC
 | 
			
		||||
  *            Alarm out, or RTC clock calibration out, 
 | 
			
		||||
  *          - WKUP pins if enabled.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_EnterSTANDBYMode(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Select STANDBY mode */
 | 
			
		||||
  PWR->CR |= PWR_CR_PDDS;
 | 
			
		||||
 | 
			
		||||
  /* Set SLEEPDEEP bit of Cortex System Control Register */
 | 
			
		||||
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
 | 
			
		||||
 | 
			
		||||
  /* This option is used to ensure that store operations are completed */
 | 
			
		||||
#if defined ( __CC_ARM)
 | 
			
		||||
  __force_stores();
 | 
			
		||||
#endif
 | 
			
		||||
  /* Request Wait For Interrupt */
 | 
			
		||||
  __WFI();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Indicates Sleep-On-Exit when returning from Handler mode to Thread mode. 
 | 
			
		||||
  * @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor 
 | 
			
		||||
  *       re-enters SLEEP mode when an interruption handling is over.
 | 
			
		||||
  *       Setting this bit is useful when the processor is expected to run only on
 | 
			
		||||
  *       interruptions handling.         
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_EnableSleepOnExit(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Set SLEEPONEXIT bit of Cortex System Control Register */
 | 
			
		||||
  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Disables Sleep-On-Exit feature when returning from Handler mode to Thread mode. 
 | 
			
		||||
  * @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the processor 
 | 
			
		||||
  *       re-enters SLEEP mode when an interruption handling is over.          
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_DisableSleepOnExit(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Clear SLEEPONEXIT bit of Cortex System Control Register */
 | 
			
		||||
  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Enables CORTEX M4 SEVONPEND bit. 
 | 
			
		||||
  * @note Sets SEVONPEND bit of SCR register. When this bit is set, this causes 
 | 
			
		||||
  *       WFE to wake up when an interrupt moves from inactive to pended.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_EnableSEVOnPend(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Set SEVONPEND bit of Cortex System Control Register */
 | 
			
		||||
  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Disables CORTEX M4 SEVONPEND bit. 
 | 
			
		||||
  * @note Clears SEVONPEND bit of SCR register. When this bit is set, this causes 
 | 
			
		||||
  *       WFE to wake up when an interrupt moves from inactive to pended.         
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_DisableSEVOnPend(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Clear SEVONPEND bit of Cortex System Control Register */
 | 
			
		||||
  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif /* HAL_PWR_MODULE_ENABLED */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
@ -0,0 +1,269 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal_pwr_ex.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   Extended PWR HAL module driver.
 | 
			
		||||
  *          This file provides firmware functions to manage the following
 | 
			
		||||
  *          functionalities of the Power Controller (PWR) peripheral:
 | 
			
		||||
  *           + Extended Initialization and de-initialization functions
 | 
			
		||||
  *           + Extended Peripheral Control functions
 | 
			
		||||
  *         
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file
 | 
			
		||||
  * in the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup PWREx PWREx
 | 
			
		||||
  * @brief    PWREx HAL module driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef HAL_PWR_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private define ------------------------------------------------------------*/
 | 
			
		||||
/** @defgroup PWREx_Private_Constants PWR Extended Private Constants
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
#define PVD_MODE_IT               (0x00010000U)
 | 
			
		||||
#define PVD_MODE_EVT              (0x00020000U)
 | 
			
		||||
#define PVD_RISING_EDGE           (0x00000001U)
 | 
			
		||||
#define PVD_FALLING_EDGE          (0x00000002U)
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 
 | 
			
		||||
/* Private macro -------------------------------------------------------------*/
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/* Exported functions ---------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/** @defgroup PWREx_Exported_Functions PWR Extended Exported Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended Control Functions
 | 
			
		||||
  *  @brief   Extended Peripheral Control functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                 ##### Peripheral Extended control functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    *** PVD configuration (present on all other devices than STM32F3x8 devices) ***
 | 
			
		||||
    =========================
 | 
			
		||||
    [..]
 | 
			
		||||
      (+) The PVD is used to monitor the VDD power supply by comparing it to a
 | 
			
		||||
          threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
 | 
			
		||||
      (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
 | 
			
		||||
          than the PVD threshold. This event is internally connected to the EXTI
 | 
			
		||||
          line16 and can generate an interrupt if enabled. This is done through
 | 
			
		||||
          __HAL_PWR_PVD_EXTI_ENABLE_IT() macro
 | 
			
		||||
      (+) The PVD is stopped in Standby mode.
 | 
			
		||||
      -@- PVD is not available on STM32F3x8 Product Line
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    *** Voltage regulator ***
 | 
			
		||||
    =========================
 | 
			
		||||
    [..]
 | 
			
		||||
      (+) The voltage regulator is always enabled after Reset. It works in three different
 | 
			
		||||
          modes.
 | 
			
		||||
          In Run mode, the regulator supplies full power to the 1.8V domain (core, memories
 | 
			
		||||
          and digital peripherals).
 | 
			
		||||
          In Stop mode, the regulator supplies low power to the 1.8V domain, preserving
 | 
			
		||||
          contents of registers and SRAM.
 | 
			
		||||
          In Stop mode, the regulator is powered off. The contents of the registers and SRAM
 | 
			
		||||
          are lost except for the Standby circuitry and the Backup Domain.
 | 
			
		||||
          Note: in the STM32F3x8xx devices, the voltage regulator is bypassed and the
 | 
			
		||||
          microcontroller must be powered from a nominal VDD = 1.8V +/-8U% voltage.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
 | 
			
		||||
          than the PVD threshold. This event is internally connected to the EXTI
 | 
			
		||||
          line16 and can generate an interrupt if enabled. This is done through
 | 
			
		||||
          __HAL_PWR_PVD_EXTI_ENABLE_IT() macro
 | 
			
		||||
      (+) The PVD is stopped in Standby mode.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    *** SDADC power configuration ***
 | 
			
		||||
    ================================
 | 
			
		||||
    [..]
 | 
			
		||||
      (+) On STM32F373xC/STM32F378xx devices, there are up to 
 | 
			
		||||
          3 SDADC instances that can be enabled/disabled.
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#if defined(STM32F302xE) || defined(STM32F303xE) || \
 | 
			
		||||
    defined(STM32F302xC) || defined(STM32F303xC) || \
 | 
			
		||||
    defined(STM32F303x8) || defined(STM32F334x8) || \
 | 
			
		||||
    defined(STM32F301x8) || defined(STM32F302x8) || \
 | 
			
		||||
    defined(STM32F373xC)
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
 | 
			
		||||
  * @param sConfigPVD pointer to an PWR_PVDTypeDef structure that contains the configuration
 | 
			
		||||
  *        information for the PVD.
 | 
			
		||||
  * @note Refer to the electrical characteristics of your device datasheet for
 | 
			
		||||
  *         more details about the voltage threshold corresponding to each
 | 
			
		||||
  *         detection level.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
 | 
			
		||||
  assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
 | 
			
		||||
 | 
			
		||||
  /* Set PLS[7:5] bits according to PVDLevel value */
 | 
			
		||||
  MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel);
 | 
			
		||||
  
 | 
			
		||||
  /* Clear any previous config. Keep it clear if no event or IT mode is selected */
 | 
			
		||||
  __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
 | 
			
		||||
  __HAL_PWR_PVD_EXTI_DISABLE_IT();
 | 
			
		||||
  __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
 | 
			
		||||
 | 
			
		||||
  /* Configure interrupt mode */
 | 
			
		||||
  if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
 | 
			
		||||
  {
 | 
			
		||||
    __HAL_PWR_PVD_EXTI_ENABLE_IT();
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Configure event mode */
 | 
			
		||||
  if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
 | 
			
		||||
  {
 | 
			
		||||
    __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /* Configure the edge */
 | 
			
		||||
  if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
 | 
			
		||||
  {
 | 
			
		||||
    __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
 | 
			
		||||
  {
 | 
			
		||||
    __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Enables the Power Voltage Detector(PVD).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_EnablePVD(void)
 | 
			
		||||
{
 | 
			
		||||
  SET_BIT(PWR->CR, PWR_CR_PVDE);  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Disables the Power Voltage Detector(PVD).
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_DisablePVD(void)
 | 
			
		||||
{
 | 
			
		||||
  CLEAR_BIT(PWR->CR, PWR_CR_PVDE);  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function handles the PWR PVD interrupt request.
 | 
			
		||||
  * @note This API should be called under the PVD_IRQHandler().
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWR_PVD_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  /* Check PWR exti flag */
 | 
			
		||||
  if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
 | 
			
		||||
  {
 | 
			
		||||
    /* PWR PVD interrupt user callback */
 | 
			
		||||
    HAL_PWR_PVDCallback();
 | 
			
		||||
 | 
			
		||||
    /* Clear PWR Exti pending bit */
 | 
			
		||||
    __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief PWR PVD interrupt callback
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_PWR_PVDCallback(void)
 | 
			
		||||
{
 | 
			
		||||
  /* NOTE : This function Should not be modified, when the callback is needed,
 | 
			
		||||
            the HAL_PWR_PVDCallback could be implemented in the user file
 | 
			
		||||
   */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* STM32F302xE || STM32F303xE || */
 | 
			
		||||
       /* STM32F302xC || STM32F303xC || */
 | 
			
		||||
       /* STM32F303x8 || STM32F334x8 || */
 | 
			
		||||
       /* STM32F301x8 || STM32F302x8 || */
 | 
			
		||||
       /* STM32F373xC                   */
 | 
			
		||||
 | 
			
		||||
#if defined(STM32F373xC) || defined(STM32F378xx)
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Enables the SDADC peripheral functionaliy
 | 
			
		||||
  * @param  Analogx specifies the SDADC peripheral instance.
 | 
			
		||||
  *   This parameter can be: PWR_SDADC_ANALOG1, PWR_SDADC_ANALOG2 or PWR_SDADC_ANALOG3.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWREx_EnableSDADC(uint32_t Analogx)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_PWR_SDADC_ANALOG(Analogx));
 | 
			
		||||
 | 
			
		||||
  /* Enable PWR clock interface for SDADC use */
 | 
			
		||||
  __HAL_RCC_PWR_CLK_ENABLE();
 | 
			
		||||
    
 | 
			
		||||
  PWR->CR |= Analogx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Disables the SDADC peripheral functionaliy
 | 
			
		||||
  * @param  Analogx specifies the SDADC peripheral instance.
 | 
			
		||||
  *   This parameter can be: PWR_SDADC_ANALOG1, PWR_SDADC_ANALOG2 or PWR_SDADC_ANALOG3.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
void HAL_PWREx_DisableSDADC(uint32_t Analogx)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the parameters */
 | 
			
		||||
  assert_param(IS_PWR_SDADC_ANALOG(Analogx));
 | 
			
		||||
  
 | 
			
		||||
  PWR->CR &= ~Analogx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* STM32F373xC || STM32F378xx */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif /* HAL_PWR_MODULE_ENABLED */
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
							
								
								
									
										1221
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_rcc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1221
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_rcc.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										7934
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_tim.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7934
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_tim.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										4015
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_uart.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4015
									
								
								Software/Code/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_uart.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -0,0 +1,775 @@
 | 
			
		||||
/**
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @file    stm32f3xx_hal_uart_ex.c
 | 
			
		||||
  * @author  MCD Application Team
 | 
			
		||||
  * @brief   Extended UART HAL module driver.
 | 
			
		||||
  *          This file provides firmware functions to manage the following extended
 | 
			
		||||
  *          functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART).
 | 
			
		||||
  *           + Initialization and de-initialization functions
 | 
			
		||||
  *           + Peripheral Control functions
 | 
			
		||||
  *
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  * @attention
 | 
			
		||||
  *
 | 
			
		||||
  * Copyright (c) 2016 STMicroelectronics.
 | 
			
		||||
  * All rights reserved.
 | 
			
		||||
  *
 | 
			
		||||
  * This software is licensed under terms that can be found in the LICENSE file
 | 
			
		||||
  * in the root directory of this software component.
 | 
			
		||||
  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
			
		||||
  *
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  @verbatim
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
               ##### UART peripheral extended features  #####
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
    (#) Declare a UART_HandleTypeDef handle structure.
 | 
			
		||||
 | 
			
		||||
    (#) For the UART RS485 Driver Enable mode, initialize the UART registers
 | 
			
		||||
        by calling the HAL_RS485Ex_Init() API.
 | 
			
		||||
 | 
			
		||||
  @endverbatim
 | 
			
		||||
  ******************************************************************************
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Includes ------------------------------------------------------------------*/
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
/** @addtogroup STM32F3xx_HAL_Driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UARTEx UARTEx
 | 
			
		||||
  * @brief UART Extended HAL module driver
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#ifdef HAL_UART_MODULE_ENABLED
 | 
			
		||||
 | 
			
		||||
/* Private typedef -----------------------------------------------------------*/
 | 
			
		||||
/* Private define ------------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/* Private macros ------------------------------------------------------------*/
 | 
			
		||||
/* Private variables ---------------------------------------------------------*/
 | 
			
		||||
/* Private function prototypes -----------------------------------------------*/
 | 
			
		||||
/** @defgroup UARTEx_Private_Functions UARTEx Private Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
static void UARTEx_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/* Exported functions --------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
/** @defgroup UARTEx_Exported_Functions  UARTEx Exported Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UARTEx_Exported_Functions_Group1 Initialization and de-initialization functions
 | 
			
		||||
  * @brief    Extended Initialization and Configuration Functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
===============================================================================
 | 
			
		||||
            ##### Initialization and Configuration functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    [..]
 | 
			
		||||
    This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
 | 
			
		||||
    in asynchronous mode.
 | 
			
		||||
      (+) For the asynchronous mode the parameters below can be configured:
 | 
			
		||||
        (++) Baud Rate
 | 
			
		||||
        (++) Word Length
 | 
			
		||||
        (++) Stop Bit
 | 
			
		||||
        (++) Parity: If the parity is enabled, then the MSB bit of the data written
 | 
			
		||||
             in the data register is transmitted but is changed by the parity bit.
 | 
			
		||||
        (++) Hardware flow control
 | 
			
		||||
        (++) Receiver/transmitter modes
 | 
			
		||||
        (++) Over Sampling Method
 | 
			
		||||
        (++) One-Bit Sampling Method
 | 
			
		||||
      (+) For the asynchronous mode, the following advanced features can be configured as well:
 | 
			
		||||
        (++) TX and/or RX pin level inversion
 | 
			
		||||
        (++) data logical level inversion
 | 
			
		||||
        (++) RX and TX pins swap
 | 
			
		||||
        (++) RX overrun detection disabling
 | 
			
		||||
        (++) DMA disabling on RX error
 | 
			
		||||
        (++) MSB first on communication line
 | 
			
		||||
        (++) auto Baud rate detection
 | 
			
		||||
    [..]
 | 
			
		||||
    The HAL_RS485Ex_Init() API follows the UART RS485 mode configuration
 | 
			
		||||
     procedures (details for the procedures are available in reference manual).
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
 | 
			
		||||
  Depending on the frame length defined by the M1 and M0 bits (7-bit,
 | 
			
		||||
  8-bit or 9-bit), the possible UART formats are listed in the
 | 
			
		||||
  following table.
 | 
			
		||||
 | 
			
		||||
    Table 1. UART frame format.
 | 
			
		||||
    +-----------------------------------------------------------------------+
 | 
			
		||||
    |  M1 bit |  M0 bit |  PCE bit  |             UART frame                |
 | 
			
		||||
    |---------|---------|-----------|---------------------------------------|
 | 
			
		||||
    |    0    |    0    |    0      |    | SB |    8 bit data   | STB |     |
 | 
			
		||||
    |---------|---------|-----------|---------------------------------------|
 | 
			
		||||
    |    0    |    0    |    1      |    | SB | 7 bit data | PB | STB |     |
 | 
			
		||||
    |---------|---------|-----------|---------------------------------------|
 | 
			
		||||
    |    0    |    1    |    0      |    | SB |    9 bit data   | STB |     |
 | 
			
		||||
    |---------|---------|-----------|---------------------------------------|
 | 
			
		||||
    |    0    |    1    |    1      |    | SB | 8 bit data | PB | STB |     |
 | 
			
		||||
    |---------|---------|-----------|---------------------------------------|
 | 
			
		||||
    |    1    |    0    |    0      |    | SB |    7 bit data   | STB |     |
 | 
			
		||||
    |---------|---------|-----------|---------------------------------------|
 | 
			
		||||
    |    1    |    0    |    1      |    | SB | 6 bit data | PB | STB |     |
 | 
			
		||||
    +-----------------------------------------------------------------------+
 | 
			
		||||
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Initialize the RS485 Driver enable feature according to the specified
 | 
			
		||||
  *         parameters in the UART_InitTypeDef and creates the associated handle.
 | 
			
		||||
  * @param huart            UART handle.
 | 
			
		||||
  * @param Polarity         Select the driver enable polarity.
 | 
			
		||||
  *          This parameter can be one of the following values:
 | 
			
		||||
  *          @arg @ref UART_DE_POLARITY_HIGH DE signal is active high
 | 
			
		||||
  *          @arg @ref UART_DE_POLARITY_LOW  DE signal is active low
 | 
			
		||||
  * @param AssertionTime    Driver Enable assertion time:
 | 
			
		||||
  *       5-bit value defining the time between the activation of the DE (Driver Enable)
 | 
			
		||||
  *       signal and the beginning of the start bit. It is expressed in sample time
 | 
			
		||||
  *       units (1/8 or 1/16 bit time, depending on the oversampling rate)
 | 
			
		||||
  * @param DeassertionTime  Driver Enable deassertion time:
 | 
			
		||||
  *       5-bit value defining the time between the end of the last stop bit, in a
 | 
			
		||||
  *       transmitted message, and the de-activation of the DE (Driver Enable) signal.
 | 
			
		||||
  *       It is expressed in sample time units (1/8 or 1/16 bit time, depending on the
 | 
			
		||||
  *       oversampling rate).
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime,
 | 
			
		||||
                                   uint32_t DeassertionTime)
 | 
			
		||||
{
 | 
			
		||||
  uint32_t temp;
 | 
			
		||||
 | 
			
		||||
  /* Check the UART handle allocation */
 | 
			
		||||
  if (huart == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
  /* Check the Driver Enable UART instance */
 | 
			
		||||
  assert_param(IS_UART_DRIVER_ENABLE_INSTANCE(huart->Instance));
 | 
			
		||||
 | 
			
		||||
  /* Check the Driver Enable polarity */
 | 
			
		||||
  assert_param(IS_UART_DE_POLARITY(Polarity));
 | 
			
		||||
 | 
			
		||||
  /* Check the Driver Enable assertion time */
 | 
			
		||||
  assert_param(IS_UART_ASSERTIONTIME(AssertionTime));
 | 
			
		||||
 | 
			
		||||
  /* Check the Driver Enable deassertion time */
 | 
			
		||||
  assert_param(IS_UART_DEASSERTIONTIME(DeassertionTime));
 | 
			
		||||
 | 
			
		||||
  if (huart->gState == HAL_UART_STATE_RESET)
 | 
			
		||||
  {
 | 
			
		||||
    /* Allocate lock resource and initialize it */
 | 
			
		||||
    huart->Lock = HAL_UNLOCKED;
 | 
			
		||||
 | 
			
		||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
 | 
			
		||||
    UART_InitCallbacksToDefault(huart);
 | 
			
		||||
 | 
			
		||||
    if (huart->MspInitCallback == NULL)
 | 
			
		||||
    {
 | 
			
		||||
      huart->MspInitCallback = HAL_UART_MspInit;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Init the low level hardware */
 | 
			
		||||
    huart->MspInitCallback(huart);
 | 
			
		||||
#else
 | 
			
		||||
    /* Init the low level hardware : GPIO, CLOCK, CORTEX */
 | 
			
		||||
    HAL_UART_MspInit(huart);
 | 
			
		||||
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  huart->gState = HAL_UART_STATE_BUSY;
 | 
			
		||||
 | 
			
		||||
  /* Disable the Peripheral */
 | 
			
		||||
  __HAL_UART_DISABLE(huart);
 | 
			
		||||
 | 
			
		||||
  /* Set the UART Communication parameters */
 | 
			
		||||
  if (UART_SetConfig(huart) == HAL_ERROR)
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
 | 
			
		||||
  {
 | 
			
		||||
    UART_AdvFeatureConfig(huart);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Enable the Driver Enable mode by setting the DEM bit in the CR3 register */
 | 
			
		||||
  SET_BIT(huart->Instance->CR3, USART_CR3_DEM);
 | 
			
		||||
 | 
			
		||||
  /* Set the Driver Enable polarity */
 | 
			
		||||
  MODIFY_REG(huart->Instance->CR3, USART_CR3_DEP, Polarity);
 | 
			
		||||
 | 
			
		||||
  /* Set the Driver Enable assertion and deassertion times */
 | 
			
		||||
  temp = (AssertionTime << UART_CR1_DEAT_ADDRESS_LSB_POS);
 | 
			
		||||
  temp |= (DeassertionTime << UART_CR1_DEDT_ADDRESS_LSB_POS);
 | 
			
		||||
  MODIFY_REG(huart->Instance->CR1, (USART_CR1_DEDT | USART_CR1_DEAT), temp);
 | 
			
		||||
 | 
			
		||||
  /* Enable the Peripheral */
 | 
			
		||||
  __HAL_UART_ENABLE(huart);
 | 
			
		||||
 | 
			
		||||
  /* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */
 | 
			
		||||
  return (UART_CheckIdleState(huart));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UARTEx_Exported_Functions_Group2 IO operation functions
 | 
			
		||||
  *  @brief Extended functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                      ##### IO operation functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    This subsection provides a set of Wakeup and FIFO mode related callback functions.
 | 
			
		||||
 | 
			
		||||
    (#) Wakeup from Stop mode Callback:
 | 
			
		||||
        (+) HAL_UARTEx_WakeupCallback()
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief UART wakeup from Stop mode callback.
 | 
			
		||||
  * @param huart UART handle.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
__weak void HAL_UARTEx_WakeupCallback(UART_HandleTypeDef *huart)
 | 
			
		||||
{
 | 
			
		||||
  /* Prevent unused argument(s) compilation warning */
 | 
			
		||||
  UNUSED(huart);
 | 
			
		||||
 | 
			
		||||
  /* NOTE : This function should not be modified, when the callback is needed,
 | 
			
		||||
            the HAL_UARTEx_WakeupCallback can be implemented in the user file.
 | 
			
		||||
   */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @defgroup UARTEx_Exported_Functions_Group3 Peripheral Control functions
 | 
			
		||||
  * @brief    Extended Peripheral Control functions
 | 
			
		||||
  *
 | 
			
		||||
@verbatim
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
                      ##### Peripheral Control functions #####
 | 
			
		||||
 ===============================================================================
 | 
			
		||||
    [..] This section provides the following functions:
 | 
			
		||||
     (+) HAL_MultiProcessorEx_AddressLength_Set() API optionally sets the UART node address
 | 
			
		||||
         detection length to more than 4 bits for multiprocessor address mark wake up.
 | 
			
		||||
     (+) HAL_UARTEx_StopModeWakeUpSourceConfig() API defines the wake-up from stop mode
 | 
			
		||||
         trigger: address match, Start Bit detection or RXNE bit status.
 | 
			
		||||
     (+) HAL_UARTEx_EnableStopMode() API enables the UART to wake up the MCU from stop mode
 | 
			
		||||
     (+) HAL_UARTEx_DisableStopMode() API disables the above functionality
 | 
			
		||||
 | 
			
		||||
    [..] This subsection also provides a set of additional functions providing enhanced reception
 | 
			
		||||
    services to user. (For example, these functions allow application to handle use cases
 | 
			
		||||
    where number of data to be received is unknown).
 | 
			
		||||
 | 
			
		||||
    (#) Compared to standard reception services which only consider number of received
 | 
			
		||||
        data elements as reception completion criteria, these functions also consider additional events
 | 
			
		||||
        as triggers for updating reception status to caller :
 | 
			
		||||
       (+) Detection of inactivity period (RX line has not been active for a given period).
 | 
			
		||||
          (++) RX inactivity detected by IDLE event, i.e. RX line has been in idle state (normally high state)
 | 
			
		||||
               for 1 frame time, after last received byte.
 | 
			
		||||
          (++) RX inactivity detected by RTO, i.e. line has been in idle state
 | 
			
		||||
               for a programmable time, after last received byte.
 | 
			
		||||
       (+) Detection that a specific character has been received.
 | 
			
		||||
 | 
			
		||||
    (#) There are two mode of transfer:
 | 
			
		||||
       (+) Blocking mode: The reception is performed in polling mode, until either expected number of data is received,
 | 
			
		||||
           or till IDLE event occurs. Reception is handled only during function execution.
 | 
			
		||||
           When function exits, no data reception could occur. HAL status and number of actually received data elements,
 | 
			
		||||
           are returned by function after finishing transfer.
 | 
			
		||||
       (+) Non-Blocking mode: The reception is performed using Interrupts or DMA.
 | 
			
		||||
           These API's return the HAL status.
 | 
			
		||||
           The end of the data processing will be indicated through the
 | 
			
		||||
           dedicated UART IRQ when using Interrupt mode or the DMA IRQ when using DMA mode.
 | 
			
		||||
           The HAL_UARTEx_RxEventCallback() user callback will be executed during Receive process
 | 
			
		||||
           The HAL_UART_ErrorCallback()user callback will be executed when a reception error is detected.
 | 
			
		||||
 | 
			
		||||
    (#) Blocking mode API:
 | 
			
		||||
        (+) HAL_UARTEx_ReceiveToIdle()
 | 
			
		||||
 | 
			
		||||
    (#) Non-Blocking mode API with Interrupt:
 | 
			
		||||
        (+) HAL_UARTEx_ReceiveToIdle_IT()
 | 
			
		||||
 | 
			
		||||
    (#) Non-Blocking mode API with DMA:
 | 
			
		||||
        (+) HAL_UARTEx_ReceiveToIdle_DMA()
 | 
			
		||||
 | 
			
		||||
@endverbatim
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief By default in multiprocessor mode, when the wake up method is set
 | 
			
		||||
  *        to address mark, the UART handles only 4-bit long addresses detection;
 | 
			
		||||
  *        this API allows to enable longer addresses detection (6-, 7- or 8-bit
 | 
			
		||||
  *        long).
 | 
			
		||||
  * @note  Addresses detection lengths are: 6-bit address detection in 7-bit data mode,
 | 
			
		||||
  *        7-bit address detection in 8-bit data mode, 8-bit address detection in 9-bit data mode.
 | 
			
		||||
  * @param huart         UART handle.
 | 
			
		||||
  * @param AddressLength This parameter can be one of the following values:
 | 
			
		||||
  *          @arg @ref UART_ADDRESS_DETECT_4B 4-bit long address
 | 
			
		||||
  *          @arg @ref UART_ADDRESS_DETECT_7B 6-, 7- or 8-bit long address
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength)
 | 
			
		||||
{
 | 
			
		||||
  /* Check the UART handle allocation */
 | 
			
		||||
  if (huart == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Check the address length parameter */
 | 
			
		||||
  assert_param(IS_UART_ADDRESSLENGTH_DETECT(AddressLength));
 | 
			
		||||
 | 
			
		||||
  huart->gState = HAL_UART_STATE_BUSY;
 | 
			
		||||
 | 
			
		||||
  /* Disable the Peripheral */
 | 
			
		||||
  __HAL_UART_DISABLE(huart);
 | 
			
		||||
 | 
			
		||||
  /* Set the address length */
 | 
			
		||||
  MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, AddressLength);
 | 
			
		||||
 | 
			
		||||
  /* Enable the Peripheral */
 | 
			
		||||
  __HAL_UART_ENABLE(huart);
 | 
			
		||||
 | 
			
		||||
  /* TEACK and/or REACK to check before moving huart->gState to Ready */
 | 
			
		||||
  return (UART_CheckIdleState(huart));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Set Wakeup from Stop mode interrupt flag selection.
 | 
			
		||||
  * @note It is the application responsibility to enable the interrupt used as
 | 
			
		||||
  *       usart_wkup interrupt source before entering low-power mode.
 | 
			
		||||
  * @param huart           UART handle.
 | 
			
		||||
  * @param WakeUpSelection Address match, Start Bit detection or RXNE/RXFNE bit status.
 | 
			
		||||
  *          This parameter can be one of the following values:
 | 
			
		||||
  *          @arg @ref UART_WAKEUP_ON_ADDRESS
 | 
			
		||||
  *          @arg @ref UART_WAKEUP_ON_STARTBIT
 | 
			
		||||
  *          @arg @ref UART_WAKEUP_ON_READDATA_NONEMPTY
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status = HAL_OK;
 | 
			
		||||
  uint32_t tickstart;
 | 
			
		||||
 | 
			
		||||
  /* check the wake-up from stop mode UART instance */
 | 
			
		||||
  assert_param(IS_UART_WAKEUP_FROMSTOP_INSTANCE(huart->Instance));
 | 
			
		||||
  /* check the wake-up selection parameter */
 | 
			
		||||
  assert_param(IS_UART_WAKEUP_SELECTION(WakeUpSelection.WakeUpEvent));
 | 
			
		||||
 | 
			
		||||
  /* Process Locked */
 | 
			
		||||
  __HAL_LOCK(huart);
 | 
			
		||||
 | 
			
		||||
  huart->gState = HAL_UART_STATE_BUSY;
 | 
			
		||||
 | 
			
		||||
  /* Disable the Peripheral */
 | 
			
		||||
  __HAL_UART_DISABLE(huart);
 | 
			
		||||
 | 
			
		||||
  /* Set the wake-up selection scheme */
 | 
			
		||||
  MODIFY_REG(huart->Instance->CR3, USART_CR3_WUS, WakeUpSelection.WakeUpEvent);
 | 
			
		||||
 | 
			
		||||
  if (WakeUpSelection.WakeUpEvent == UART_WAKEUP_ON_ADDRESS)
 | 
			
		||||
  {
 | 
			
		||||
    UARTEx_Wakeup_AddressConfig(huart, WakeUpSelection);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Enable the Peripheral */
 | 
			
		||||
  __HAL_UART_ENABLE(huart);
 | 
			
		||||
 | 
			
		||||
  /* Init tickstart for timeout management */
 | 
			
		||||
  tickstart = HAL_GetTick();
 | 
			
		||||
 | 
			
		||||
  /* Wait until REACK flag is set */
 | 
			
		||||
  if (UART_WaitOnFlagUntilTimeout(huart, USART_ISR_REACK, RESET, tickstart, HAL_UART_TIMEOUT_VALUE) != HAL_OK)
 | 
			
		||||
  {
 | 
			
		||||
    status = HAL_TIMEOUT;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    /* Initialize the UART State */
 | 
			
		||||
    huart->gState = HAL_UART_STATE_READY;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Process Unlocked */
 | 
			
		||||
  __HAL_UNLOCK(huart);
 | 
			
		||||
 | 
			
		||||
  return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Enable UART Stop Mode.
 | 
			
		||||
  * @note The UART is able to wake up the MCU from Stop 1 mode as long as UART clock is HSI or LSE.
 | 
			
		||||
  * @param huart UART handle.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart)
 | 
			
		||||
{
 | 
			
		||||
  /* Process Locked */
 | 
			
		||||
  __HAL_LOCK(huart);
 | 
			
		||||
 | 
			
		||||
  /* Set UESM bit */
 | 
			
		||||
  ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_UESM);
 | 
			
		||||
 | 
			
		||||
  /* Process Unlocked */
 | 
			
		||||
  __HAL_UNLOCK(huart);
 | 
			
		||||
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Disable UART Stop Mode.
 | 
			
		||||
  * @param huart UART handle.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart)
 | 
			
		||||
{
 | 
			
		||||
  /* Process Locked */
 | 
			
		||||
  __HAL_LOCK(huart);
 | 
			
		||||
 | 
			
		||||
  /* Clear UESM bit */
 | 
			
		||||
  ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_UESM);
 | 
			
		||||
 | 
			
		||||
  /* Process Unlocked */
 | 
			
		||||
  __HAL_UNLOCK(huart);
 | 
			
		||||
 | 
			
		||||
  return HAL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Receive an amount of data in blocking mode till either the expected number of data
 | 
			
		||||
  *        is received or an IDLE event occurs.
 | 
			
		||||
  * @note  HAL_OK is returned if reception is completed (expected number of data has been received)
 | 
			
		||||
  *        or if reception is stopped after IDLE event (less than the expected number of data has been received)
 | 
			
		||||
  *        In this case, RxLen output parameter indicates number of data available in reception buffer.
 | 
			
		||||
  * @note  When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
 | 
			
		||||
  *        the received data is handled as a set of uint16_t. In this case, Size must indicate the number
 | 
			
		||||
  *        of uint16_t available through pData.
 | 
			
		||||
  * @param huart   UART handle.
 | 
			
		||||
  * @param pData   Pointer to data buffer (uint8_t or uint16_t data elements).
 | 
			
		||||
  * @param Size    Amount of data elements (uint8_t or uint16_t) to be received.
 | 
			
		||||
  * @param RxLen   Number of data elements finally received
 | 
			
		||||
  *                (could be lower than Size, in case reception ends on IDLE event)
 | 
			
		||||
  * @param Timeout Timeout duration expressed in ms (covers the whole reception sequence).
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint16_t *RxLen,
 | 
			
		||||
                                           uint32_t Timeout)
 | 
			
		||||
{
 | 
			
		||||
  uint8_t  *pdata8bits;
 | 
			
		||||
  uint16_t *pdata16bits;
 | 
			
		||||
  uint16_t uhMask;
 | 
			
		||||
  uint32_t tickstart;
 | 
			
		||||
 | 
			
		||||
  /* Check that a Rx process is not already ongoing */
 | 
			
		||||
  if (huart->RxState == HAL_UART_STATE_READY)
 | 
			
		||||
  {
 | 
			
		||||
    if ((pData == NULL) || (Size == 0U))
 | 
			
		||||
    {
 | 
			
		||||
      return  HAL_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    huart->ErrorCode = HAL_UART_ERROR_NONE;
 | 
			
		||||
    huart->RxState = HAL_UART_STATE_BUSY_RX;
 | 
			
		||||
    huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
 | 
			
		||||
    huart->RxEventType = HAL_UART_RXEVENT_TC;
 | 
			
		||||
 | 
			
		||||
    /* Init tickstart for timeout management */
 | 
			
		||||
    tickstart = HAL_GetTick();
 | 
			
		||||
 | 
			
		||||
    huart->RxXferSize  = Size;
 | 
			
		||||
    huart->RxXferCount = Size;
 | 
			
		||||
 | 
			
		||||
    /* Computation of UART mask to apply to RDR register */
 | 
			
		||||
    UART_MASK_COMPUTATION(huart);
 | 
			
		||||
    uhMask = huart->Mask;
 | 
			
		||||
 | 
			
		||||
    /* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */
 | 
			
		||||
    if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
 | 
			
		||||
    {
 | 
			
		||||
      pdata8bits  = NULL;
 | 
			
		||||
      pdata16bits = (uint16_t *) pData;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      pdata8bits  = pData;
 | 
			
		||||
      pdata16bits = NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Initialize output number of received elements */
 | 
			
		||||
    *RxLen = 0U;
 | 
			
		||||
 | 
			
		||||
    /* as long as data have to be received */
 | 
			
		||||
    while (huart->RxXferCount > 0U)
 | 
			
		||||
    {
 | 
			
		||||
      /* Check if IDLE flag is set */
 | 
			
		||||
      if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE))
 | 
			
		||||
      {
 | 
			
		||||
        /* Clear IDLE flag in ISR */
 | 
			
		||||
        __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_IDLEF);
 | 
			
		||||
 | 
			
		||||
        /* If Set, but no data ever received, clear flag without exiting loop */
 | 
			
		||||
        /* If Set, and data has already been received, this means Idle Event is valid : End reception */
 | 
			
		||||
        if (*RxLen > 0U)
 | 
			
		||||
        {
 | 
			
		||||
          huart->RxEventType = HAL_UART_RXEVENT_IDLE;
 | 
			
		||||
          huart->RxState = HAL_UART_STATE_READY;
 | 
			
		||||
 | 
			
		||||
          return HAL_OK;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      /* Check if RXNE flag is set */
 | 
			
		||||
      if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE))
 | 
			
		||||
      {
 | 
			
		||||
        if (pdata8bits == NULL)
 | 
			
		||||
        {
 | 
			
		||||
          *pdata16bits = (uint16_t)(huart->Instance->RDR & uhMask);
 | 
			
		||||
          pdata16bits++;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          *pdata8bits = (uint8_t)(huart->Instance->RDR & (uint8_t)uhMask);
 | 
			
		||||
          pdata8bits++;
 | 
			
		||||
        }
 | 
			
		||||
        /* Increment number of received elements */
 | 
			
		||||
        *RxLen += 1U;
 | 
			
		||||
        huart->RxXferCount--;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      /* Check for the Timeout */
 | 
			
		||||
      if (Timeout != HAL_MAX_DELAY)
 | 
			
		||||
      {
 | 
			
		||||
        if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
 | 
			
		||||
        {
 | 
			
		||||
          huart->RxState = HAL_UART_STATE_READY;
 | 
			
		||||
 | 
			
		||||
          return HAL_TIMEOUT;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Set number of received elements in output parameter : RxLen */
 | 
			
		||||
    *RxLen = huart->RxXferSize - huart->RxXferCount;
 | 
			
		||||
    /* At end of Rx process, restore huart->RxState to Ready */
 | 
			
		||||
    huart->RxState = HAL_UART_STATE_READY;
 | 
			
		||||
 | 
			
		||||
    return HAL_OK;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_BUSY;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Receive an amount of data in interrupt mode till either the expected number of data
 | 
			
		||||
  *        is received or an IDLE event occurs.
 | 
			
		||||
  * @note  Reception is initiated by this function call. Further progress of reception is achieved thanks
 | 
			
		||||
  *        to UART interrupts raised by RXNE and IDLE events. Callback is called at end of reception indicating
 | 
			
		||||
  *        number of received data elements.
 | 
			
		||||
  * @note  When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
 | 
			
		||||
  *        the received data is handled as a set of uint16_t. In this case, Size must indicate the number
 | 
			
		||||
  *        of uint16_t available through pData.
 | 
			
		||||
  * @param huart UART handle.
 | 
			
		||||
  * @param pData Pointer to data buffer (uint8_t or uint16_t data elements).
 | 
			
		||||
  * @param Size  Amount of data elements (uint8_t or uint16_t) to be received.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status;
 | 
			
		||||
 | 
			
		||||
  /* Check that a Rx process is not already ongoing */
 | 
			
		||||
  if (huart->RxState == HAL_UART_STATE_READY)
 | 
			
		||||
  {
 | 
			
		||||
    if ((pData == NULL) || (Size == 0U))
 | 
			
		||||
    {
 | 
			
		||||
      return HAL_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Set Reception type to reception till IDLE Event*/
 | 
			
		||||
    huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
 | 
			
		||||
    huart->RxEventType = HAL_UART_RXEVENT_TC;
 | 
			
		||||
 | 
			
		||||
    status =  UART_Start_Receive_IT(huart, pData, Size);
 | 
			
		||||
 | 
			
		||||
    /* Check Rx process has been successfully started */
 | 
			
		||||
    if (status == HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
      if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
 | 
			
		||||
      {
 | 
			
		||||
        __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_IDLEF);
 | 
			
		||||
        ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        /* In case of errors already pending when reception is started,
 | 
			
		||||
           Interrupts may have already been raised and lead to reception abortion.
 | 
			
		||||
           (Overrun error for instance).
 | 
			
		||||
           In such case Reception Type has been reset to HAL_UART_RECEPTION_STANDARD. */
 | 
			
		||||
        status = HAL_ERROR;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return status;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_BUSY;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Receive an amount of data in DMA mode till either the expected number
 | 
			
		||||
  *        of data is received or an IDLE event occurs.
 | 
			
		||||
  * @note  Reception is initiated by this function call. Further progress of reception is achieved thanks
 | 
			
		||||
  *        to DMA services, transferring automatically received data elements in user reception buffer and
 | 
			
		||||
  *        calling registered callbacks at half/end of reception. UART IDLE events are also used to consider
 | 
			
		||||
  *        reception phase as ended. In all cases, callback execution will indicate number of received data elements.
 | 
			
		||||
  * @note  When the UART parity is enabled (PCE = 1), the received data contain
 | 
			
		||||
  *        the parity bit (MSB position).
 | 
			
		||||
  * @note  When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
 | 
			
		||||
  *        the received data is handled as a set of uint16_t. In this case, Size must indicate the number
 | 
			
		||||
  *        of uint16_t available through pData.
 | 
			
		||||
  * @param huart UART handle.
 | 
			
		||||
  * @param pData Pointer to data buffer (uint8_t or uint16_t data elements).
 | 
			
		||||
  * @param Size  Amount of data elements (uint8_t or uint16_t) to be received.
 | 
			
		||||
  * @retval HAL status
 | 
			
		||||
  */
 | 
			
		||||
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
 | 
			
		||||
{
 | 
			
		||||
  HAL_StatusTypeDef status;
 | 
			
		||||
 | 
			
		||||
  /* Check that a Rx process is not already ongoing */
 | 
			
		||||
  if (huart->RxState == HAL_UART_STATE_READY)
 | 
			
		||||
  {
 | 
			
		||||
    if ((pData == NULL) || (Size == 0U))
 | 
			
		||||
    {
 | 
			
		||||
      return HAL_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Set Reception type to reception till IDLE Event*/
 | 
			
		||||
    huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
 | 
			
		||||
    huart->RxEventType = HAL_UART_RXEVENT_TC;
 | 
			
		||||
 | 
			
		||||
    status =  UART_Start_Receive_DMA(huart, pData, Size);
 | 
			
		||||
 | 
			
		||||
    /* Check Rx process has been successfully started */
 | 
			
		||||
    if (status == HAL_OK)
 | 
			
		||||
    {
 | 
			
		||||
      if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
 | 
			
		||||
      {
 | 
			
		||||
        __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_IDLEF);
 | 
			
		||||
        ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        /* In case of errors already pending when reception is started,
 | 
			
		||||
           Interrupts may have already been raised and lead to reception abortion.
 | 
			
		||||
           (Overrun error for instance).
 | 
			
		||||
           In such case Reception Type has been reset to HAL_UART_RECEPTION_STANDARD. */
 | 
			
		||||
        status = HAL_ERROR;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return status;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    return HAL_BUSY;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Provide Rx Event type that has lead to RxEvent callback execution.
 | 
			
		||||
  * @note  When HAL_UARTEx_ReceiveToIdle_IT() or HAL_UARTEx_ReceiveToIdle_DMA() API are called, progress
 | 
			
		||||
  *        of reception process is provided to application through calls of Rx Event callback (either default one
 | 
			
		||||
  *        HAL_UARTEx_RxEventCallback() or user registered one). As several types of events could occur (IDLE event,
 | 
			
		||||
  *        Half Transfer, or Transfer Complete), this function allows to retrieve the Rx Event type that has lead
 | 
			
		||||
  *        to Rx Event callback execution.
 | 
			
		||||
  * @note  This function is expected to be called within the user implementation of Rx Event Callback,
 | 
			
		||||
  *        in order to provide the accurate value :
 | 
			
		||||
  *        In Interrupt Mode :
 | 
			
		||||
  *           - HAL_UART_RXEVENT_TC : when Reception has been completed (expected nb of data has been received)
 | 
			
		||||
  *           - HAL_UART_RXEVENT_IDLE : when Idle event occurred prior reception has been completed (nb of
 | 
			
		||||
  *             received data is lower than expected one)
 | 
			
		||||
  *        In DMA Mode :
 | 
			
		||||
  *           - HAL_UART_RXEVENT_TC : when Reception has been completed (expected nb of data has been received)
 | 
			
		||||
  *           - HAL_UART_RXEVENT_HT : when half of expected nb of data has been received
 | 
			
		||||
  *           - HAL_UART_RXEVENT_IDLE : when Idle event occurred prior reception has been completed (nb of
 | 
			
		||||
  *             received data is lower than expected one).
 | 
			
		||||
  *        In DMA mode, RxEvent callback could be called several times;
 | 
			
		||||
  *        When DMA is configured in Normal Mode, HT event does not stop Reception process;
 | 
			
		||||
  *        When DMA is configured in Circular Mode, HT, TC or IDLE events don't stop Reception process;
 | 
			
		||||
  * @param  huart UART handle.
 | 
			
		||||
  * @retval Rx Event Type (return vale will be a value of @ref UART_RxEvent_Type_Values)
 | 
			
		||||
  */
 | 
			
		||||
HAL_UART_RxEventTypeTypeDef HAL_UARTEx_GetRxEventType(UART_HandleTypeDef *huart)
 | 
			
		||||
{
 | 
			
		||||
  /* Return Rx Event type value, as stored in UART handle */
 | 
			
		||||
  return (huart->RxEventType);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/** @addtogroup UARTEx_Private_Functions
 | 
			
		||||
  * @{
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Initialize the UART wake-up from stop mode parameters when triggered by address detection.
 | 
			
		||||
  * @param huart           UART handle.
 | 
			
		||||
  * @param WakeUpSelection UART wake up from stop mode parameters.
 | 
			
		||||
  * @retval None
 | 
			
		||||
  */
 | 
			
		||||
static void UARTEx_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
 | 
			
		||||
{
 | 
			
		||||
  assert_param(IS_UART_ADDRESSLENGTH_DETECT(WakeUpSelection.AddressLength));
 | 
			
		||||
 | 
			
		||||
  /* Set the USART address length */
 | 
			
		||||
  MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, WakeUpSelection.AddressLength);
 | 
			
		||||
 | 
			
		||||
  /* Set the USART address node */
 | 
			
		||||
  MODIFY_REG(huart->Instance->CR2, USART_CR2_ADD, ((uint32_t)WakeUpSelection.Address << UART_CR2_ADDRESS_LSB_POS));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
#endif /* HAL_UART_MODULE_ENABLED */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @}
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user