@@ -0,0 +1,197 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief CMSIS STM32F7xx Device Peripheral Access Layer Header File. | |||
* | |||
* The file is the unique include file that the application programmer | |||
* is using in the C source code, usually in main.c. This file contains: | |||
* - Configuration section that allows to select: | |||
* - The STM32F7xx device used in the target application | |||
* - To use or not the peripheral's drivers in application code(i.e. | |||
* code will be based on direct access to peripheral's registers | |||
* rather than drivers API), this option is controlled by | |||
* "#define USE_HAL_DRIVER" | |||
* | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/** @addtogroup CMSIS | |||
* @{ | |||
*/ | |||
/** @addtogroup stm32f7xx | |||
* @{ | |||
*/ | |||
#ifndef __STM32F7xx_H | |||
#define __STM32F7xx_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif /* __cplusplus */ | |||
/** @addtogroup Library_configuration_section | |||
* @{ | |||
*/ | |||
/** | |||
* @brief STM32 Family | |||
*/ | |||
#if !defined (STM32F7) | |||
#define STM32F7 | |||
#endif /* STM32F7 */ | |||
/* Uncomment the line below according to the target STM32 device used in your | |||
application | |||
*/ | |||
#if !defined (STM32F756xx) && !defined (STM32F746xx) && !defined (STM32F745xx) | |||
/* #define STM32F756xx */ /*!< STM32F756VG, STM32F756ZG, STM32F756ZG, STM32F756IG, STM32F756BG, | |||
STM32F756NG Devices */ | |||
/* #define STM32F746xx */ /*!< STM32F746VE, STM32F746VG, STM32F746ZE, STM32F746ZG, STM32F746IE, STM32F746IG, | |||
STM32F746BE, STM32F746BG, STM32F746NE, STM32F746NG Devices */ | |||
/* #define STM32F745xx */ /*!< STM32F745VE, STM32F745VG, STM32F745ZG, STM32F745ZE, STM32F745IE, STM32F745IG Devices */ | |||
#endif | |||
/* Tip: To avoid modifying this file each time you need to switch between these | |||
devices, you can define the device in your toolchain compiler preprocessor. | |||
*/ | |||
#if !defined (USE_HAL_DRIVER) | |||
/** | |||
* @brief Comment the line below if you will not use the peripherals drivers. | |||
In this case, these drivers will not be included and the application code will | |||
be based on direct access to peripherals registers | |||
*/ | |||
/*#define USE_HAL_DRIVER */ | |||
#endif /* USE_HAL_DRIVER */ | |||
/** | |||
* @brief CMSIS Device version number V1.0.1 | |||
*/ | |||
#define __STM32F7xx_CMSIS_DEVICE_VERSION_MAIN (0x01) /*!< [31:24] main version */ | |||
#define __STM32F7xx_CMSIS_DEVICE_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */ | |||
#define __STM32F7xx_CMSIS_DEVICE_VERSION_SUB2 (0x01) /*!< [15:8] sub2 version */ | |||
#define __STM32F7xx_CMSIS_DEVICE_VERSION_RC (0x00) /*!< [7:0] release candidate */ | |||
#define __STM32F7xx_CMSIS_DEVICE_VERSION ((__STM32F7xx_CMSIS_DEVICE_VERSION_MAIN << 24)\ | |||
|(__STM32F7xx_CMSIS_DEVICE_VERSION_SUB1 << 16)\ | |||
|(__STM32F7xx_CMSIS_DEVICE_VERSION_SUB2 << 8 )\ | |||
|(__STM32F7xx_CMSIS_DEVICE_VERSION)) | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup Device_Included | |||
* @{ | |||
*/ | |||
#if defined(STM32F756xx) | |||
#include "stm32f756xx.h" | |||
#elif defined(STM32F746xx) | |||
#include "stm32f746xx.h" | |||
#elif defined(STM32F745xx) | |||
#include "stm32f745xx.h" | |||
#else | |||
#error "Please select first the target STM32F7xx device used in your application (in stm32f7xx.h file)" | |||
#endif | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup Exported_types | |||
* @{ | |||
*/ | |||
typedef enum | |||
{ | |||
RESET = 0, | |||
SET = !RESET | |||
} FlagStatus, ITStatus; | |||
typedef enum | |||
{ | |||
DISABLE = 0, | |||
ENABLE = !DISABLE | |||
} FunctionalState; | |||
#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) | |||
typedef enum | |||
{ | |||
ERROR = 0, | |||
SUCCESS = !ERROR | |||
} ErrorStatus; | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup Exported_macro | |||
* @{ | |||
*/ | |||
#define SET_BIT(REG, BIT) ((REG) |= (BIT)) | |||
#define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) | |||
#define READ_BIT(REG, BIT) ((REG) & (BIT)) | |||
#define CLEAR_REG(REG) ((REG) = (0x0)) | |||
#define WRITE_REG(REG, VAL) ((REG) = (VAL)) | |||
#define READ_REG(REG) ((REG)) | |||
#define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) | |||
#define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL))) | |||
/** | |||
* @} | |||
*/ | |||
#ifdef USE_HAL_DRIVER | |||
#include "stm32f7xx_hal_conf.h" | |||
#endif /* USE_HAL_DRIVER */ | |||
#ifdef __cplusplus | |||
} | |||
#endif /* __cplusplus */ | |||
#endif /* __STM32F7xx_H */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,122 @@ | |||
/** | |||
****************************************************************************** | |||
* @file system_stm32f7xx.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief CMSIS Cortex-M7 Device System Source File for STM32F7xx devices. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/** @addtogroup CMSIS | |||
* @{ | |||
*/ | |||
/** @addtogroup stm32f7xx_system | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Define to prevent recursive inclusion | |||
*/ | |||
#ifndef __SYSTEM_STM32F7XX_H | |||
#define __SYSTEM_STM32F7XX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/** @addtogroup STM32F7xx_System_Includes | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup STM32F7xx_System_Exported_types | |||
* @{ | |||
*/ | |||
/* This variable is updated in three ways: | |||
1) by calling CMSIS function SystemCoreClockUpdate() | |||
2) by calling HAL API function HAL_RCC_GetSysClockFreq() | |||
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency | |||
Note: If you use this function to configure the system clock; then there | |||
is no need to call the 2 first functions listed above, since SystemCoreClock | |||
variable is updated automatically. | |||
*/ | |||
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup STM32F7xx_System_Exported_Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup STM32F7xx_System_Exported_Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup STM32F7xx_System_Exported_Functions | |||
* @{ | |||
*/ | |||
extern void SystemInit(void); | |||
extern void SystemCoreClockUpdate(void); | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /*__SYSTEM_STM32F7XX_H */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,209 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief This file contains all the functions prototypes for the HAL | |||
* module driver. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_H | |||
#define __STM32F7xx_HAL_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_conf.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup HAL | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup HAL_Exported_Macros HAL Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Freeze/Unfreeze Peripherals in Debug mode | |||
*/ | |||
#define __HAL_DBGMCU_FREEZE_TIM2() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM2_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM3() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM3_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM4() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM4_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM5() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM5_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM6() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM6_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM7() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM7_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM12() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM12_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM13() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM13_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM14() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM14_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_LPTIM1() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_LPTIM1_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_RTC() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_RTC_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_WWDG() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_WWDG_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_IWDG() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_IWDG_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_I2C1_TIMEOUT() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_I2C1_SMBUS_TIMEOUT)) | |||
#define __HAL_DBGMCU_FREEZE_I2C2_TIMEOUT() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_I2C2_SMBUS_TIMEOUT)) | |||
#define __HAL_DBGMCU_FREEZE_I2C3_TIMEOUT() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_I2C3_SMBUS_TIMEOUT)) | |||
#define __HAL_DBGMCU_FREEZE_I2C4_TIMEOUT() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_I2C4_SMBUS_TIMEOUT)) | |||
#define __HAL_DBGMCU_FREEZE_CAN1() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_CAN1_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_CAN2() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_CAN2_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM1() (DBGMCU->APB2FZ |= (DBGMCU_APB2_FZ_DBG_TIM1_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM8() (DBGMCU->APB2FZ |= (DBGMCU_APB2_FZ_DBG_TIM8_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM9() (DBGMCU->APB2FZ |= (DBGMCU_APB2_FZ_DBG_TIM9_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM10() (DBGMCU->APB2FZ |= (DBGMCU_APB2_FZ_DBG_TIM10_STOP)) | |||
#define __HAL_DBGMCU_FREEZE_TIM11() (DBGMCU->APB2FZ |= (DBGMCU_APB2_FZ_DBG_TIM11_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM2() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM2_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM3() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM3_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM4() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM4_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM5() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM5_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM6() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM6_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM7() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM7_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM12() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM12_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM13() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM13_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM14() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM14_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_LPTIM1() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_LPTIM1_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_RTC() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_RTC_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_WWDG() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_WWDG_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_IWDG() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_IWDG_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_I2C1_TIMEOUT() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_I2C1_SMBUS_TIMEOUT)) | |||
#define __HAL_DBGMCU_UNFREEZE_I2C2_TIMEOUT() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_I2C2_SMBUS_TIMEOUT)) | |||
#define __HAL_DBGMCU_UNFREEZE_I2C3_TIMEOUT() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_I2C3_SMBUS_TIMEOUT)) | |||
#define __HAL_DBGMCU_UNFREEZE_I2C4_TIMEOUT() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_I2C4_SMBUS_TIMEOUT)) | |||
#define __HAL_DBGMCU_UNFREEZE_CAN1() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_CAN1_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_CAN2() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_CAN2_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM1() (DBGMCU->APB2FZ &= ~(DBGMCU_APB2_FZ_DBG_TIM1_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM8() (DBGMCU->APB2FZ &= ~(DBGMCU_APB2_FZ_DBG_TIM8_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM9() (DBGMCU->APB2FZ &= ~(DBGMCU_APB2_FZ_DBG_TIM9_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM10() (DBGMCU->APB2FZ &= ~(DBGMCU_APB2_FZ_DBG_TIM10_STOP)) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM11() (DBGMCU->APB2FZ &= ~(DBGMCU_APB2_FZ_DBG_TIM11_STOP)) | |||
/** @brief FMC (NOR/RAM) mapped at 0x60000000 and SDRAM mapped at 0xC0000000 | |||
*/ | |||
#define __HAL_SYSCFG_REMAPMEMORY_FMC() (SYSCFG->MEMRMP &= ~(SYSCFG_MEMRMP_SWP_FMC)) | |||
/** @brief FMC/SDRAM mapped at 0x60000000 (NOR/RAM) mapped at 0xC0000000 | |||
*/ | |||
#define __HAL_SYSCFG_REMAPMEMORY_FMC_SDRAM() do {SYSCFG->MEMRMP &= ~(SYSCFG_MEMRMP_SWP_FMC);\ | |||
SYSCFG->MEMRMP |= (SYSCFG_MEMRMP_SWP_FMC_0);\ | |||
}while(0); | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup HAL_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup HAL_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions ******************************/ | |||
HAL_StatusTypeDef HAL_Init(void); | |||
HAL_StatusTypeDef HAL_DeInit(void); | |||
void HAL_MspInit(void); | |||
void HAL_MspDeInit(void); | |||
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup HAL_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions ************************************************/ | |||
void HAL_IncTick(void); | |||
void HAL_Delay(__IO uint32_t Delay); | |||
uint32_t HAL_GetTick(void); | |||
void HAL_SuspendTick(void); | |||
void HAL_ResumeTick(void); | |||
uint32_t HAL_GetHalVersion(void); | |||
uint32_t HAL_GetREVID(void); | |||
uint32_t HAL_GetDEVID(void); | |||
void HAL_DBGMCU_EnableDBGSleepMode(void); | |||
void HAL_DBGMCU_DisableDBGSleepMode(void); | |||
void HAL_DBGMCU_EnableDBGStopMode(void); | |||
void HAL_DBGMCU_DisableDBGStopMode(void); | |||
void HAL_DBGMCU_EnableDBGStandbyMode(void); | |||
void HAL_DBGMCU_DisableDBGStandbyMode(void); | |||
void HAL_EnableCompensationCell(void); | |||
void HAL_DisableCompensationCell(void); | |||
void HAL_EnableFMCMemorySwapping(void); | |||
void HAL_DisableFMCMemorySwapping(void); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/** @defgroup HAL_Private_Variables HAL Private Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup HAL_Private_Constants HAL Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,765 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_adc.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of ADC HAL extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_ADC_H | |||
#define __STM32F7xx_ADC_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup ADC | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup ADC_Exported_Types ADC Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief HAL State structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_ADC_STATE_RESET = 0x00, /*!< ADC not yet initialized or disabled */ | |||
HAL_ADC_STATE_READY = 0x01, /*!< ADC peripheral ready for use */ | |||
HAL_ADC_STATE_BUSY = 0x02, /*!< An internal process is ongoing */ | |||
HAL_ADC_STATE_BUSY_REG = 0x12, /*!< Regular conversion is ongoing */ | |||
HAL_ADC_STATE_BUSY_INJ = 0x22, /*!< Injected conversion is ongoing */ | |||
HAL_ADC_STATE_BUSY_INJ_REG = 0x32, /*!< Injected and regular conversion are ongoing */ | |||
HAL_ADC_STATE_TIMEOUT = 0x03, /*!< Timeout state */ | |||
HAL_ADC_STATE_ERROR = 0x04, /*!< ADC state error */ | |||
HAL_ADC_STATE_EOC = 0x05, /*!< Conversion is completed */ | |||
HAL_ADC_STATE_EOC_REG = 0x15, /*!< Regular conversion is completed */ | |||
HAL_ADC_STATE_EOC_INJ = 0x25, /*!< Injected conversion is completed */ | |||
HAL_ADC_STATE_EOC_INJ_REG = 0x35, /*!< Injected and regular conversion are completed */ | |||
HAL_ADC_STATE_AWD = 0x06 /*!< ADC state analog watchdog */ | |||
}HAL_ADC_StateTypeDef; | |||
/** | |||
* @brief ADC Init structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t ClockPrescaler; /*!< Select the frequency of the clock to the ADC. The clock is common for | |||
all the ADCs. | |||
This parameter can be a value of @ref ADC_ClockPrescaler */ | |||
uint32_t Resolution; /*!< Configures the ADC resolution dual mode. | |||
This parameter can be a value of @ref ADC_Resolution */ | |||
uint32_t DataAlign; /*!< Specifies whether the ADC data alignment is left or right. | |||
This parameter can be a value of @ref ADC_data_align */ | |||
uint32_t ScanConvMode; /*!< Specifies whether the conversion is performed in Scan (multi channels) or | |||
Single (one channel) mode. | |||
This parameter can be set to ENABLE or DISABLE */ | |||
uint32_t EOCSelection; /*!< Specifies whether the EOC flag is set | |||
at the end of single channel conversion or at the end of all conversions. | |||
This parameter can be a value of @ref ADC_EOCSelection */ | |||
uint32_t ContinuousConvMode; /*!< Specifies whether the conversion is performed in Continuous or Single mode. | |||
This parameter can be set to ENABLE or DISABLE. */ | |||
uint32_t DMAContinuousRequests; /*!< Specifies whether the DMA requests is performed in Continuous or in Single mode. | |||
This parameter can be set to ENABLE or DISABLE. */ | |||
uint32_t NbrOfConversion; /*!< Specifies the number of ADC conversions that will be done using the sequencer for | |||
regular channel group. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 16. */ | |||
uint32_t DiscontinuousConvMode; /*!< Specifies whether the conversion is performed in Discontinuous or not | |||
for regular channels. | |||
This parameter can be set to ENABLE or DISABLE. */ | |||
uint32_t NbrOfDiscConversion; /*!< Specifies the number of ADC discontinuous conversions that will be done | |||
using the sequencer for regular channel group. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 8. */ | |||
uint32_t ExternalTrigConv; /*!< Selects the external event used to trigger the conversion start of regular group. | |||
If set to ADC_SOFTWARE_START, external triggers are disabled. | |||
This parameter can be a value of @ref ADC_External_trigger_Source_Regular | |||
Note: This parameter can be modified only if there is no conversion is ongoing. */ | |||
uint32_t ExternalTrigConvEdge; /*!< Selects the external trigger edge of regular group. | |||
If trigger is set to ADC_SOFTWARE_START, this parameter is discarded. | |||
This parameter can be a value of @ref ADC_External_trigger_edge_Regular | |||
Note: This parameter can be modified only if there is no conversion is ongoing. */ | |||
}ADC_InitTypeDef; | |||
/** | |||
* @brief ADC handle Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
ADC_TypeDef *Instance; /*!< Register base address */ | |||
ADC_InitTypeDef Init; /*!< ADC required parameters */ | |||
__IO uint32_t NbrOfCurrentConversionRank; /*!< ADC number of current conversion rank */ | |||
DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */ | |||
HAL_LockTypeDef Lock; /*!< ADC locking object */ | |||
__IO HAL_ADC_StateTypeDef State; /*!< ADC communication state */ | |||
__IO uint32_t ErrorCode; /*!< ADC Error code */ | |||
}ADC_HandleTypeDef; | |||
/** | |||
* @brief ADC Configuration regular Channel structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Channel; /*!< The ADC channel to configure. | |||
This parameter can be a value of @ref ADC_channels */ | |||
uint32_t Rank; /*!< The rank in the regular group sequencer. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 16 */ | |||
uint32_t SamplingTime; /*!< The sample time value to be set for the selected channel. | |||
This parameter can be a value of @ref ADC_sampling_times */ | |||
uint32_t Offset; /*!< Reserved for future use, can be set to 0 */ | |||
}ADC_ChannelConfTypeDef; | |||
/** | |||
* @brief ADC Configuration multi-mode structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t WatchdogMode; /*!< Configures the ADC analog watchdog mode. | |||
This parameter can be a value of @ref ADC_analog_watchdog_selection */ | |||
uint32_t HighThreshold; /*!< Configures the ADC analog watchdog High threshold value. | |||
This parameter must be a 12-bit value. */ | |||
uint32_t LowThreshold; /*!< Configures the ADC analog watchdog High threshold value. | |||
This parameter must be a 12-bit value. */ | |||
uint32_t Channel; /*!< Configures ADC channel for the analog watchdog. | |||
This parameter has an effect only if watchdog mode is configured on single channel | |||
This parameter can be a value of @ref ADC_channels */ | |||
uint32_t ITMode; /*!< Specifies whether the analog watchdog is configured | |||
is interrupt mode or in polling mode. | |||
This parameter can be set to ENABLE or DISABLE */ | |||
uint32_t WatchdogNumber; /*!< Reserved for future use, can be set to 0 */ | |||
}ADC_AnalogWDGConfTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup ADC_Exported_Constants ADC Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup ADC_Error_Code ADC Error Code | |||
* @{ | |||
*/ | |||
#define HAL_ADC_ERROR_NONE ((uint32_t)0x00) /*!< No error */ | |||
#define HAL_ADC_ERROR_OVR ((uint32_t)0x01) /*!< OVR error */ | |||
#define HAL_ADC_ERROR_DMA ((uint32_t)0x02) /*!< DMA transfer error */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_ClockPrescaler ADC Clock Prescaler | |||
* @{ | |||
*/ | |||
#define ADC_CLOCK_SYNC_PCLK_DIV2 ((uint32_t)0x00000000) | |||
#define ADC_CLOCK_SYNC_PCLK_DIV4 ((uint32_t)ADC_CCR_ADCPRE_0) | |||
#define ADC_CLOCK_SYNC_PCLK_DIV6 ((uint32_t)ADC_CCR_ADCPRE_1) | |||
#define ADC_CLOCK_SYNC_PCLK_DIV8 ((uint32_t)ADC_CCR_ADCPRE) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_delay_between_2_sampling_phases ADC Delay Between 2 Sampling Phases | |||
* @{ | |||
*/ | |||
#define ADC_TWOSAMPLINGDELAY_5CYCLES ((uint32_t)0x00000000) | |||
#define ADC_TWOSAMPLINGDELAY_6CYCLES ((uint32_t)ADC_CCR_DELAY_0) | |||
#define ADC_TWOSAMPLINGDELAY_7CYCLES ((uint32_t)ADC_CCR_DELAY_1) | |||
#define ADC_TWOSAMPLINGDELAY_8CYCLES ((uint32_t)(ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0)) | |||
#define ADC_TWOSAMPLINGDELAY_9CYCLES ((uint32_t)ADC_CCR_DELAY_2) | |||
#define ADC_TWOSAMPLINGDELAY_10CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_0)) | |||
#define ADC_TWOSAMPLINGDELAY_11CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1)) | |||
#define ADC_TWOSAMPLINGDELAY_12CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0)) | |||
#define ADC_TWOSAMPLINGDELAY_13CYCLES ((uint32_t)ADC_CCR_DELAY_3) | |||
#define ADC_TWOSAMPLINGDELAY_14CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_0)) | |||
#define ADC_TWOSAMPLINGDELAY_15CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_1)) | |||
#define ADC_TWOSAMPLINGDELAY_16CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0)) | |||
#define ADC_TWOSAMPLINGDELAY_17CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2)) | |||
#define ADC_TWOSAMPLINGDELAY_18CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2 | ADC_CCR_DELAY_0)) | |||
#define ADC_TWOSAMPLINGDELAY_19CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1)) | |||
#define ADC_TWOSAMPLINGDELAY_20CYCLES ((uint32_t)ADC_CCR_DELAY) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_Resolution ADC Resolution | |||
* @{ | |||
*/ | |||
#define ADC_RESOLUTION_12B ((uint32_t)0x00000000) | |||
#define ADC_RESOLUTION_10B ((uint32_t)ADC_CR1_RES_0) | |||
#define ADC_RESOLUTION_8B ((uint32_t)ADC_CR1_RES_1) | |||
#define ADC_RESOLUTION_6B ((uint32_t)ADC_CR1_RES) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_External_trigger_edge_Regular ADC External Trigger Edge Regular | |||
* @{ | |||
*/ | |||
#define ADC_EXTERNALTRIGCONVEDGE_NONE ((uint32_t)0x00000000) | |||
#define ADC_EXTERNALTRIGCONVEDGE_RISING ((uint32_t)ADC_CR2_EXTEN_0) | |||
#define ADC_EXTERNALTRIGCONVEDGE_FALLING ((uint32_t)ADC_CR2_EXTEN_1) | |||
#define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING ((uint32_t)ADC_CR2_EXTEN) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_External_trigger_Source_Regular ADC External Trigger Source Regular | |||
* @{ | |||
*/ | |||
/* Note: Parameter ADC_SOFTWARE_START is a software parameter used for */ | |||
/* compatibility with other STM32 devices. */ | |||
#define ADC_EXTERNALTRIGCONV_T1_CC1 ((uint32_t)0x00000000) | |||
#define ADC_EXTERNALTRIGCONV_T1_CC2 ((uint32_t)ADC_CR2_EXTSEL_0) | |||
#define ADC_EXTERNALTRIGCONV_T1_CC3 ((uint32_t)ADC_CR2_EXTSEL_1) | |||
#define ADC_EXTERNALTRIGCONV_T2_CC2 ((uint32_t)(ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0)) | |||
#define ADC_EXTERNALTRIGCONV_T5_TRGO ((uint32_t)ADC_CR2_EXTSEL_2) | |||
#define ADC_EXTERNALTRIGCONV_T4_CC4 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0)) | |||
#define ADC_EXTERNALTRIGCONV_T3_CC4 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1)) | |||
#define ADC_EXTERNALTRIGCONV_T8_TRGO ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0)) | |||
#define ADC_EXTERNALTRIGCONV_T8_TRGO2 ((uint32_t)ADC_CR2_EXTSEL_3) | |||
#define ADC_EXTERNALTRIGCONV_T1_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_0)) | |||
#define ADC_EXTERNALTRIGCONV_T1_TRGO2 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1)) | |||
#define ADC_EXTERNALTRIGCONV_T2_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0)) | |||
#define ADC_EXTERNALTRIGCONV_T4_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2)) | |||
#define ADC_EXTERNALTRIGCONV_T6_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0)) | |||
#define ADC_EXTERNALTRIGCONV_EXT_IT11 ((uint32_t)ADC_CR2_EXTSEL) | |||
#define ADC_SOFTWARE_START ((uint32_t)ADC_CR2_EXTSEL + 1) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_data_align ADC Data Align | |||
* @{ | |||
*/ | |||
#define ADC_DATAALIGN_RIGHT ((uint32_t)0x00000000) | |||
#define ADC_DATAALIGN_LEFT ((uint32_t)ADC_CR2_ALIGN) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_channels ADC Common Channels | |||
* @{ | |||
*/ | |||
#define ADC_CHANNEL_0 ((uint32_t)0x00000000) | |||
#define ADC_CHANNEL_1 ((uint32_t)ADC_CR1_AWDCH_0) | |||
#define ADC_CHANNEL_2 ((uint32_t)ADC_CR1_AWDCH_1) | |||
#define ADC_CHANNEL_3 ((uint32_t)(ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0)) | |||
#define ADC_CHANNEL_4 ((uint32_t)ADC_CR1_AWDCH_2) | |||
#define ADC_CHANNEL_5 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0)) | |||
#define ADC_CHANNEL_6 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1)) | |||
#define ADC_CHANNEL_7 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0)) | |||
#define ADC_CHANNEL_8 ((uint32_t)ADC_CR1_AWDCH_3) | |||
#define ADC_CHANNEL_9 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_0)) | |||
#define ADC_CHANNEL_10 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1)) | |||
#define ADC_CHANNEL_11 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0)) | |||
#define ADC_CHANNEL_12 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2)) | |||
#define ADC_CHANNEL_13 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0)) | |||
#define ADC_CHANNEL_14 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1)) | |||
#define ADC_CHANNEL_15 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0)) | |||
#define ADC_CHANNEL_16 ((uint32_t)ADC_CR1_AWDCH_4) | |||
#define ADC_CHANNEL_17 ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_0)) | |||
#define ADC_CHANNEL_18 ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_1)) | |||
#define ADC_CHANNEL_VREFINT ((uint32_t)ADC_CHANNEL_17) | |||
#define ADC_CHANNEL_VBAT ((uint32_t)ADC_CHANNEL_18) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_sampling_times ADC Sampling Times | |||
* @{ | |||
*/ | |||
#define ADC_SAMPLETIME_3CYCLES ((uint32_t)0x00000000) | |||
#define ADC_SAMPLETIME_15CYCLES ((uint32_t)ADC_SMPR1_SMP10_0) | |||
#define ADC_SAMPLETIME_28CYCLES ((uint32_t)ADC_SMPR1_SMP10_1) | |||
#define ADC_SAMPLETIME_56CYCLES ((uint32_t)(ADC_SMPR1_SMP10_1 | ADC_SMPR1_SMP10_0)) | |||
#define ADC_SAMPLETIME_84CYCLES ((uint32_t)ADC_SMPR1_SMP10_2) | |||
#define ADC_SAMPLETIME_112CYCLES ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_0)) | |||
#define ADC_SAMPLETIME_144CYCLES ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_1)) | |||
#define ADC_SAMPLETIME_480CYCLES ((uint32_t)ADC_SMPR1_SMP10) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_EOCSelection ADC EOC Selection | |||
* @{ | |||
*/ | |||
#define ADC_EOC_SEQ_CONV ((uint32_t)0x00000000) | |||
#define ADC_EOC_SINGLE_CONV ((uint32_t)0x00000001) | |||
#define ADC_EOC_SINGLE_SEQ_CONV ((uint32_t)0x00000002) /*!< reserved for future use */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_Event_type ADC Event Type | |||
* @{ | |||
*/ | |||
#define ADC_AWD_EVENT ((uint32_t)ADC_FLAG_AWD) | |||
#define ADC_OVR_EVENT ((uint32_t)ADC_FLAG_OVR) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_analog_watchdog_selection ADC Analog Watchdog Selection | |||
* @{ | |||
*/ | |||
#define ADC_ANALOGWATCHDOG_SINGLE_REG ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN)) | |||
#define ADC_ANALOGWATCHDOG_SINGLE_INJEC ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_JAWDEN)) | |||
#define ADC_ANALOGWATCHDOG_SINGLE_REGINJEC ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN | ADC_CR1_JAWDEN)) | |||
#define ADC_ANALOGWATCHDOG_ALL_REG ((uint32_t)ADC_CR1_AWDEN) | |||
#define ADC_ANALOGWATCHDOG_ALL_INJEC ((uint32_t)ADC_CR1_JAWDEN) | |||
#define ADC_ANALOGWATCHDOG_ALL_REGINJEC ((uint32_t)(ADC_CR1_AWDEN | ADC_CR1_JAWDEN)) | |||
#define ADC_ANALOGWATCHDOG_NONE ((uint32_t)0x00000000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_interrupts_definition ADC Interrupts Definition | |||
* @{ | |||
*/ | |||
#define ADC_IT_EOC ((uint32_t)ADC_CR1_EOCIE) | |||
#define ADC_IT_AWD ((uint32_t)ADC_CR1_AWDIE) | |||
#define ADC_IT_JEOC ((uint32_t)ADC_CR1_JEOCIE) | |||
#define ADC_IT_OVR ((uint32_t)ADC_CR1_OVRIE) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_flags_definition ADC Flags Definition | |||
* @{ | |||
*/ | |||
#define ADC_FLAG_AWD ((uint32_t)ADC_SR_AWD) | |||
#define ADC_FLAG_EOC ((uint32_t)ADC_SR_EOC) | |||
#define ADC_FLAG_JEOC ((uint32_t)ADC_SR_JEOC) | |||
#define ADC_FLAG_JSTRT ((uint32_t)ADC_SR_JSTRT) | |||
#define ADC_FLAG_STRT ((uint32_t)ADC_SR_STRT) | |||
#define ADC_FLAG_OVR ((uint32_t)ADC_SR_OVR) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADC_channels_type ADC Channels Type | |||
* @{ | |||
*/ | |||
#define ADC_ALL_CHANNELS ((uint32_t)0x00000001) | |||
#define ADC_REGULAR_CHANNELS ((uint32_t)0x00000002) /*!< reserved for future use */ | |||
#define ADC_INJECTED_CHANNELS ((uint32_t)0x00000003) /*!< reserved for future use */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup ADC_Exported_Macros ADC Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset ADC handle state | |||
* @param __HANDLE__: ADC handle | |||
* @retval None | |||
*/ | |||
#define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_ADC_STATE_RESET) | |||
/** | |||
* @brief Enable the ADC peripheral. | |||
* @param __HANDLE__: ADC handle | |||
* @retval None | |||
*/ | |||
#define __HAL_ADC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 |= ADC_CR2_ADON) | |||
/** | |||
* @brief Disable the ADC peripheral. | |||
* @param __HANDLE__: ADC handle | |||
* @retval None | |||
*/ | |||
#define __HAL_ADC_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 &= ~ADC_CR2_ADON) | |||
/** | |||
* @brief Enable the ADC end of conversion interrupt. | |||
* @param __HANDLE__: specifies the ADC Handle. | |||
* @param __INTERRUPT__: ADC Interrupt. | |||
* @retval None | |||
*/ | |||
#define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) |= (__INTERRUPT__)) | |||
/** | |||
* @brief Disable the ADC end of conversion interrupt. | |||
* @param __HANDLE__: specifies the ADC Handle. | |||
* @param __INTERRUPT__: ADC interrupt. | |||
* @retval None | |||
*/ | |||
#define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) &= ~(__INTERRUPT__)) | |||
/** @brief Check if the specified ADC interrupt source is enabled or disabled. | |||
* @param __HANDLE__: specifies the ADC Handle. | |||
* @param __INTERRUPT__: specifies the ADC interrupt source to check. | |||
* @retval The new state of __IT__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__)) | |||
/** | |||
* @brief Clear the ADC's pending flags. | |||
* @param __HANDLE__: specifies the ADC Handle. | |||
* @param __FLAG__: ADC flag. | |||
* @retval None | |||
*/ | |||
#define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = ~(__FLAG__)) | |||
/** | |||
* @brief Get the selected ADC's flag status. | |||
* @param __HANDLE__: specifies the ADC Handle. | |||
* @param __FLAG__: ADC flag. | |||
* @retval None | |||
*/ | |||
#define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__)) | |||
/** | |||
* @} | |||
*/ | |||
/* Include ADC HAL Extension module */ | |||
#include "stm32f7xx_hal_adc_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup ADC_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup ADC_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization/de-initialization functions ***********************************/ | |||
HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc); | |||
HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc); | |||
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc); | |||
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup ADC_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* I/O operation functions ******************************************************/ | |||
HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc); | |||
HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc); | |||
HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc); | |||
HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc); | |||
void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc); | |||
HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length); | |||
HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc); | |||
uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc); | |||
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc); | |||
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc); | |||
void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc); | |||
void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup ADC_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions *************************************************/ | |||
HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig); | |||
HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup ADC_Exported_Functions_Group4 | |||
* @{ | |||
*/ | |||
/* Peripheral State functions ***************************************************/ | |||
HAL_ADC_StateTypeDef HAL_ADC_GetState(ADC_HandleTypeDef* hadc); | |||
uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup ADC_Private_Constants ADC Private Constants | |||
* @{ | |||
*/ | |||
/* Delay for ADC stabilization time. */ | |||
/* Maximum delay is 1us (refer to device datasheet, parameter tSTAB). */ | |||
/* Unit: us */ | |||
#define ADC_STAB_DELAY_US ((uint32_t) 3) | |||
/* Delay for temperature sensor stabilization time. */ | |||
/* Maximum delay is 10us (refer to device datasheet, parameter tSTART). */ | |||
/* Unit: us */ | |||
#define ADC_TEMPSENSOR_DELAY_US ((uint32_t) 10) | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup ADC_Private_Macros ADC Private Macros | |||
* @{ | |||
*/ | |||
#define IS_ADC_CLOCKPRESCALER(__ADC_CLOCK__) (((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV2) || \ | |||
((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV4) || \ | |||
((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV6) || \ | |||
((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV8)) | |||
#define IS_ADC_SAMPLING_DELAY(__DELAY__) (((__DELAY__) == ADC_TWOSAMPLINGDELAY_5CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_6CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_7CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_8CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_9CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_10CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_11CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_12CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_13CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_14CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_15CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_16CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_17CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_18CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_19CYCLES) || \ | |||
((__DELAY__) == ADC_TWOSAMPLINGDELAY_20CYCLES)) | |||
#define IS_ADC_RESOLUTION(__RESOLUTION__) (((__RESOLUTION__) == ADC_RESOLUTION_12B) || \ | |||
((__RESOLUTION__) == ADC_RESOLUTION_10B) || \ | |||
((__RESOLUTION__) == ADC_RESOLUTION_8B) || \ | |||
((__RESOLUTION__) == ADC_RESOLUTION_6B)) | |||
#define IS_ADC_EXT_TRIG_EDGE(__EDGE__) (((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \ | |||
((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \ | |||
((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \ | |||
((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING)) | |||
#define IS_ADC_EXT_TRIG(__REGTRIG__) (((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T1_CC1) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T1_CC2) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T1_CC3) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T2_CC2) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T5_TRGO) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T4_CC4) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T3_CC4) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T8_TRGO) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T8_TRGO2) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T1_TRGO2) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T4_TRGO) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T6_TRGO) || \ | |||
((__REGTRIG__) == ADC_EXTERNALTRIGCONV_EXT_IT11) || \ | |||
((__REGTRIG__) == ADC_SOFTWARE_START)) | |||
#define IS_ADC_DATA_ALIGN(__ALIGN__) (((__ALIGN__) == ADC_DATAALIGN_RIGHT) || \ | |||
((__ALIGN__) == ADC_DATAALIGN_LEFT)) | |||
#define IS_ADC_SAMPLE_TIME(__TIME__) (((__TIME__) == ADC_SAMPLETIME_3CYCLES) || \ | |||
((__TIME__) == ADC_SAMPLETIME_15CYCLES) || \ | |||
((__TIME__) == ADC_SAMPLETIME_28CYCLES) || \ | |||
((__TIME__) == ADC_SAMPLETIME_56CYCLES) || \ | |||
((__TIME__) == ADC_SAMPLETIME_84CYCLES) || \ | |||
((__TIME__) == ADC_SAMPLETIME_112CYCLES) || \ | |||
((__TIME__) == ADC_SAMPLETIME_144CYCLES) || \ | |||
((__TIME__) == ADC_SAMPLETIME_480CYCLES)) | |||
#define IS_ADC_EOCSelection(__EOCSelection__) (((__EOCSelection__) == ADC_EOC_SINGLE_CONV) || \ | |||
((__EOCSelection__) == ADC_EOC_SEQ_CONV) || \ | |||
((__EOCSelection__) == ADC_EOC_SINGLE_SEQ_CONV)) | |||
#define IS_ADC_EVENT_TYPE(__EVENT__) (((__EVENT__) == ADC_AWD_EVENT) || \ | |||
((__EVENT__) == ADC_OVR_EVENT)) | |||
#define IS_ADC_ANALOG_WATCHDOG(__WATCHDOG__) (((__WATCHDOG__) == ADC_ANALOGWATCHDOG_SINGLE_REG) || \ | |||
((__WATCHDOG__) == ADC_ANALOGWATCHDOG_SINGLE_INJEC) || \ | |||
((__WATCHDOG__) == ADC_ANALOGWATCHDOG_SINGLE_REGINJEC) || \ | |||
((__WATCHDOG__) == ADC_ANALOGWATCHDOG_ALL_REG) || \ | |||
((__WATCHDOG__) == ADC_ANALOGWATCHDOG_ALL_INJEC) || \ | |||
((__WATCHDOG__) == ADC_ANALOGWATCHDOG_ALL_REGINJEC) || \ | |||
((__WATCHDOG__) == ADC_ANALOGWATCHDOG_NONE)) | |||
#define IS_ADC_CHANNELS_TYPE(CHANNEL_TYPE) (((CHANNEL_TYPE) == ADC_ALL_CHANNELS) || \ | |||
((CHANNEL_TYPE) == ADC_REGULAR_CHANNELS) || \ | |||
((CHANNEL_TYPE) == ADC_INJECTED_CHANNELS)) | |||
#define IS_ADC_THRESHOLD(__THRESHOLD__) ((__THRESHOLD__) <= ((uint32_t)0xFFF)) | |||
#define IS_ADC_REGULAR_LENGTH(__LENGTH__) (((__LENGTH__) >= ((uint32_t)1)) && ((__LENGTH__) <= ((uint32_t)16))) | |||
#define IS_ADC_REGULAR_RANK(__RANK__) (((__RANK__) >= ((uint32_t)1)) && ((__RANK__) <= ((uint32_t)16))) | |||
#define IS_ADC_REGULAR_DISC_NUMBER(__NUMBER__) (((__NUMBER__) >= ((uint32_t)1)) && ((__NUMBER__) <= ((uint32_t)8))) | |||
#define IS_ADC_RANGE(__RESOLUTION__, __ADC_VALUE__) \ | |||
((((__RESOLUTION__) == ADC_RESOLUTION_12B) && ((__ADC_VALUE__) <= ((uint32_t)0x0FFF))) || \ | |||
(((__RESOLUTION__) == ADC_RESOLUTION_10B) && ((__ADC_VALUE__) <= ((uint32_t)0x03FF))) || \ | |||
(((__RESOLUTION__) == ADC_RESOLUTION_8B) && ((__ADC_VALUE__) <= ((uint32_t)0x00FF))) || \ | |||
(((__RESOLUTION__) == ADC_RESOLUTION_6B) && ((__ADC_VALUE__) <= ((uint32_t)0x003F)))) | |||
/** | |||
* @brief Set ADC Regular channel sequence length. | |||
* @param _NbrOfConversion_: Regular channel sequence length. | |||
* @retval None | |||
*/ | |||
#define ADC_SQR1(_NbrOfConversion_) (((_NbrOfConversion_) - (uint8_t)1) << 20) | |||
/** | |||
* @brief Set the ADC's sample time for channel numbers between 10 and 18. | |||
* @param _SAMPLETIME_: Sample time parameter. | |||
* @param _CHANNELNB_: Channel number. | |||
* @retval None | |||
*/ | |||
#define ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * (((uint32_t)((uint16_t)(_CHANNELNB_))) - 10))) | |||
/** | |||
* @brief Set the ADC's sample time for channel numbers between 0 and 9. | |||
* @param _SAMPLETIME_: Sample time parameter. | |||
* @param _CHANNELNB_: Channel number. | |||
* @retval None | |||
*/ | |||
#define ADC_SMPR2(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * ((uint32_t)((uint16_t)(_CHANNELNB_))))) | |||
/** | |||
* @brief Set the selected regular channel rank for rank between 1 and 6. | |||
* @param _CHANNELNB_: Channel number. | |||
* @param _RANKNB_: Rank number. | |||
* @retval None | |||
*/ | |||
#define ADC_SQR3_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5 * ((_RANKNB_) - 1))) | |||
/** | |||
* @brief Set the selected regular channel rank for rank between 7 and 12. | |||
* @param _CHANNELNB_: Channel number. | |||
* @param _RANKNB_: Rank number. | |||
* @retval None | |||
*/ | |||
#define ADC_SQR2_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5 * ((_RANKNB_) - 7))) | |||
/** | |||
* @brief Set the selected regular channel rank for rank between 13 and 16. | |||
* @param _CHANNELNB_: Channel number. | |||
* @param _RANKNB_: Rank number. | |||
* @retval None | |||
*/ | |||
#define ADC_SQR1_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5 * ((_RANKNB_) - 13))) | |||
/** | |||
* @brief Enable ADC continuous conversion mode. | |||
* @param _CONTINUOUS_MODE_: Continuous mode. | |||
* @retval None | |||
*/ | |||
#define ADC_CR2_CONTINUOUS(_CONTINUOUS_MODE_) ((_CONTINUOUS_MODE_) << 1) | |||
/** | |||
* @brief Configures the number of discontinuous conversions for the regular group channels. | |||
* @param _NBR_DISCONTINUOUSCONV_: Number of discontinuous conversions. | |||
* @retval None | |||
*/ | |||
#define ADC_CR1_DISCONTINUOUS(_NBR_DISCONTINUOUSCONV_) (((_NBR_DISCONTINUOUSCONV_) - 1) << POSITION_VAL(ADC_CR1_DISCNUM)) | |||
/** | |||
* @brief Enable ADC scan mode. | |||
* @param _SCANCONV_MODE_: Scan conversion mode. | |||
* @retval None | |||
*/ | |||
#define ADC_CR1_SCANCONV(_SCANCONV_MODE_) ((_SCANCONV_MODE_) << 8) | |||
/** | |||
* @brief Enable the ADC end of conversion selection. | |||
* @param _EOCSelection_MODE_: End of conversion selection mode. | |||
* @retval None | |||
*/ | |||
#define ADC_CR2_EOCSelection(_EOCSelection_MODE_) ((_EOCSelection_MODE_) << 10) | |||
/** | |||
* @brief Enable the ADC DMA continuous request. | |||
* @param _DMAContReq_MODE_: DMA continuous request mode. | |||
* @retval None | |||
*/ | |||
#define ADC_CR2_DMAContReq(_DMAContReq_MODE_) ((_DMAContReq_MODE_) << 9) | |||
/** | |||
* @brief Return resolution bits in CR1 register. | |||
* @param __HANDLE__: ADC handle | |||
* @retval None | |||
*/ | |||
#define ADC_GET_RESOLUTION(__HANDLE__) (((__HANDLE__)->Instance->CR1) & ADC_CR1_RES) | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup ADC_Private_Functions ADC Private Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /*__STM32F7xx_ADC_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,329 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_adc.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of ADC HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_ADC_EX_H | |||
#define __STM32F7xx_ADC_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup ADCEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup ADCEx_Exported_Types ADC Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief ADC Configuration injected Channel structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t InjectedChannel; /*!< Configure the ADC injected channel. | |||
This parameter can be a value of @ref ADC_channels */ | |||
uint32_t InjectedRank; /*!< The rank in the injected group sequencer | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 4. */ | |||
uint32_t InjectedSamplingTime; /*!< The sample time value to be set for the selected channel. | |||
This parameter can be a value of @ref ADC_sampling_times */ | |||
uint32_t InjectedOffset; /*!< Defines the offset to be subtracted from the raw converted data when convert injected channels. | |||
This parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF. */ | |||
uint32_t InjectedNbrOfConversion; /*!< Specifies the number of ADC conversions that will be done using the sequencer for | |||
injected channel group. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 4. */ | |||
uint32_t AutoInjectedConv; /*!< Enables or disables the selected ADC automatic injected group | |||
conversion after regular one */ | |||
uint32_t InjectedDiscontinuousConvMode; /*!< Specifies whether the conversion is performed in Discontinuous mode or not for injected channels. | |||
This parameter can be set to ENABLE or DISABLE. */ | |||
uint32_t ExternalTrigInjecConvEdge; /*!< Select the external trigger edge and enable the trigger of an injected channels. | |||
This parameter can be a value of @ref ADCEx_External_trigger_edge_Injected */ | |||
uint32_t ExternalTrigInjecConv; /*!< Select the external event used to trigger the start of conversion of a injected channels. | |||
This parameter can be a value of @ref ADCEx_External_trigger_Source_Injected */ | |||
}ADC_InjectionConfTypeDef; | |||
/** | |||
* @brief ADC Configuration multi-mode structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Mode; /*!< Configures the ADC to operate in independent or multi mode. | |||
This parameter can be a value of @ref ADCEx_Common_mode */ | |||
uint32_t DMAAccessMode; /*!< Configures the Direct memory access mode for multi ADC mode. | |||
This parameter can be a value of @ref ADCEx_Direct_memory_access_mode_for_multi_mode */ | |||
uint32_t TwoSamplingDelay; /*!< Configures the Delay between 2 sampling phases. | |||
This parameter can be a value of @ref ADC_delay_between_2_sampling_phases */ | |||
}ADC_MultiModeTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup ADCEx_Exported_Constants ADC Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup ADCEx_Common_mode ADC Common Mode | |||
* @{ | |||
*/ | |||
#define ADC_MODE_INDEPENDENT ((uint32_t)0x00000000) | |||
#define ADC_DUALMODE_REGSIMULT_INJECSIMULT ((uint32_t)ADC_CCR_MULTI_0) | |||
#define ADC_DUALMODE_REGSIMULT_ALTERTRIG ((uint32_t)ADC_CCR_MULTI_1) | |||
#define ADC_DUALMODE_INJECSIMULT ((uint32_t)(ADC_CCR_MULTI_2 | ADC_CCR_MULTI_0)) | |||
#define ADC_DUALMODE_REGSIMULT ((uint32_t)(ADC_CCR_MULTI_2 | ADC_CCR_MULTI_1)) | |||
#define ADC_DUALMODE_INTERL ((uint32_t)(ADC_CCR_MULTI_2 | ADC_CCR_MULTI_1 | ADC_CCR_MULTI_0)) | |||
#define ADC_DUALMODE_ALTERTRIG ((uint32_t)(ADC_CCR_MULTI_3 | ADC_CCR_MULTI_0)) | |||
#define ADC_TRIPLEMODE_REGSIMULT_INJECSIMULT ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_0)) | |||
#define ADC_TRIPLEMODE_REGSIMULT_AlterTrig ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_1)) | |||
#define ADC_TRIPLEMODE_INJECSIMULT ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_2 | ADC_CCR_MULTI_0)) | |||
#define ADC_TRIPLEMODE_REGSIMULT ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_2 | ADC_CCR_MULTI_1)) | |||
#define ADC_TRIPLEMODE_INTERL ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_2 | ADC_CCR_MULTI_1 | ADC_CCR_MULTI_0)) | |||
#define ADC_TRIPLEMODE_ALTERTRIG ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_3 | ADC_CCR_MULTI_0)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADCEx_Direct_memory_access_mode_for_multi_mode ADC Direct Memory Access Mode For Multi Mode | |||
* @{ | |||
*/ | |||
#define ADC_DMAACCESSMODE_DISABLED ((uint32_t)0x00000000) /*!< DMA mode disabled */ | |||
#define ADC_DMAACCESSMODE_1 ((uint32_t)ADC_CCR_DMA_0) /*!< DMA mode 1 enabled (2 / 3 half-words one by one - 1 then 2 then 3)*/ | |||
#define ADC_DMAACCESSMODE_2 ((uint32_t)ADC_CCR_DMA_1) /*!< DMA mode 2 enabled (2 / 3 half-words by pairs - 2&1 then 1&3 then 3&2)*/ | |||
#define ADC_DMAACCESSMODE_3 ((uint32_t)ADC_CCR_DMA) /*!< DMA mode 3 enabled (2 / 3 bytes by pairs - 2&1 then 1&3 then 3&2) */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADCEx_External_trigger_edge_Injected ADC External Trigger Edge Injected | |||
* @{ | |||
*/ | |||
#define ADC_EXTERNALTRIGINJECCONVEDGE_NONE ((uint32_t)0x00000000) | |||
#define ADC_EXTERNALTRIGINJECCONVEDGE_RISING ((uint32_t)ADC_CR2_JEXTEN_0) | |||
#define ADC_EXTERNALTRIGINJECCONVEDGE_FALLING ((uint32_t)ADC_CR2_JEXTEN_1) | |||
#define ADC_EXTERNALTRIGINJECCONVEDGE_RISINGFALLING ((uint32_t)ADC_CR2_JEXTEN) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADCEx_External_trigger_Source_Injected ADC External Trigger Source Injected | |||
* @{ | |||
*/ | |||
#define ADC_EXTERNALTRIGINJECCONV_T1_TRGO ((uint32_t)0x00000000) | |||
#define ADC_EXTERNALTRIGINJECCONV_T1_CC4 ((uint32_t)ADC_CR2_JEXTSEL_0) | |||
#define ADC_EXTERNALTRIGINJECCONV_T2_TRGO ((uint32_t)ADC_CR2_JEXTSEL_1) | |||
#define ADC_EXTERNALTRIGINJECCONV_T2_CC1 ((uint32_t)(ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0)) | |||
#define ADC_EXTERNALTRIGINJECCONV_T3_CC4 ((uint32_t)ADC_CR2_JEXTSEL_2) | |||
#define ADC_EXTERNALTRIGINJECCONV_T4_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_0)) | |||
#define ADC_EXTERNALTRIGINJECCONV_T8_CC4 ((uint32_t)(ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0)) | |||
#define ADC_EXTERNALTRIGINJECCONV_T1_TRGO2 ((uint32_t)ADC_CR2_JEXTSEL_3) | |||
#define ADC_EXTERNALTRIGINJECCONV_T8_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_0)) | |||
#define ADC_EXTERNALTRIGINJECCONV_T8_TRGO2 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_1)) | |||
#define ADC_EXTERNALTRIGINJECCONV_T3_CC3 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0)) | |||
#define ADC_EXTERNALTRIGINJECCONV_T5_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_2)) | |||
#define ADC_EXTERNALTRIGINJECCONV_T3_CC1 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_0)) | |||
#define ADC_EXTERNALTRIGINJECCONV_T6_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADCEx_injected_channel_selection ADC Injected Channel Selection | |||
* @{ | |||
*/ | |||
#define ADC_INJECTED_RANK_1 ((uint32_t)0x00000001) | |||
#define ADC_INJECTED_RANK_2 ((uint32_t)0x00000002) | |||
#define ADC_INJECTED_RANK_3 ((uint32_t)0x00000003) | |||
#define ADC_INJECTED_RANK_4 ((uint32_t)0x00000004) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup ADCEx_channels ADC Specific Channels | |||
* @{ | |||
*/ | |||
#define ADC_CHANNEL_TEMPSENSOR ((uint32_t)ADC_CHANNEL_16) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup ADC_Exported_Macros ADC Exported Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup ADCEx_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup ADCEx_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* I/O operation functions ******************************************************/ | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc); | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc); | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc); | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc); | |||
uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank); | |||
HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length); | |||
HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc); | |||
uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc); | |||
void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc); | |||
/* Peripheral Control functions *************************************************/ | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc,ADC_InjectionConfTypeDef* sConfigInjected); | |||
HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup ADCEx_Private_Constants ADC Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup ADCEx_Private_Macros ADC Private Macros | |||
* @{ | |||
*/ | |||
#define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) <= ADC_CHANNEL_18) || \ | |||
((CHANNEL) == ADC_CHANNEL_TEMPSENSOR)) | |||
#define IS_ADC_MODE(__MODE__) (((__MODE__) == ADC_MODE_INDEPENDENT) || \ | |||
((__MODE__) == ADC_DUALMODE_REGSIMULT_INJECSIMULT) || \ | |||
((__MODE__) == ADC_DUALMODE_REGSIMULT_ALTERTRIG) || \ | |||
((__MODE__) == ADC_DUALMODE_INJECSIMULT) || \ | |||
((__MODE__) == ADC_DUALMODE_REGSIMULT) || \ | |||
((__MODE__) == ADC_DUALMODE_INTERL) || \ | |||
((__MODE__) == ADC_DUALMODE_ALTERTRIG) || \ | |||
((__MODE__) == ADC_TRIPLEMODE_REGSIMULT_INJECSIMULT) || \ | |||
((__MODE__) == ADC_TRIPLEMODE_REGSIMULT_AlterTrig) || \ | |||
((__MODE__) == ADC_TRIPLEMODE_INJECSIMULT) || \ | |||
((__MODE__) == ADC_TRIPLEMODE_REGSIMULT) || \ | |||
((__MODE__) == ADC_TRIPLEMODE_INTERL) || \ | |||
((__MODE__) == ADC_TRIPLEMODE_ALTERTRIG)) | |||
#define IS_ADC_DMA_ACCESS_MODE(__MODE__) (((__MODE__) == ADC_DMAACCESSMODE_DISABLED) || \ | |||
((__MODE__) == ADC_DMAACCESSMODE_1) || \ | |||
((__MODE__) == ADC_DMAACCESSMODE_2) || \ | |||
((__MODE__) == ADC_DMAACCESSMODE_3)) | |||
#define IS_ADC_EXT_INJEC_TRIG_EDGE(__EDGE__) (((__EDGE__) == ADC_EXTERNALTRIGINJECCONVEDGE_NONE) || \ | |||
((__EDGE__) == ADC_EXTERNALTRIGINJECCONVEDGE_RISING) || \ | |||
((__EDGE__) == ADC_EXTERNALTRIGINJECCONVEDGE_FALLING) || \ | |||
((__EDGE__) == ADC_EXTERNALTRIGINJECCONVEDGE_RISINGFALLING)) | |||
#define IS_ADC_EXT_INJEC_TRIG(__INJTRIG__) (((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T1_CC4) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T2_CC1) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T3_CC4) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T8_CC4) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO2) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T8_TRGO) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T8_TRGO2) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T3_CC3) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T5_TRGO) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T3_CC1) || \ | |||
((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T6_TRGO)) | |||
#define IS_ADC_INJECTED_LENGTH(__LENGTH__) (((__LENGTH__) >= ((uint32_t)1)) && ((__LENGTH__) <= ((uint32_t)4))) | |||
#define IS_ADC_INJECTED_RANK(__RANK__) (((__RANK__) >= ((uint32_t)1)) && ((__RANK__) <= ((uint32_t)4))) | |||
/** | |||
* @brief Set the selected injected Channel rank. | |||
* @param _CHANNELNB_: Channel number. | |||
* @param _RANKNB_: Rank number. | |||
* @param _JSQR_JL_: Sequence length. | |||
* @retval None | |||
*/ | |||
#define ADC_JSQR(_CHANNELNB_, _RANKNB_,_JSQR_JL_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5 * (uint8_t)(((_RANKNB_) + 3) - (_JSQR_JL_)))) | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup ADCEx_Private_Functions ADC Private Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /*__STM32F7xx_ADC_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,769 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_can.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of CAN HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_CAN_H | |||
#define __STM32F7xx_HAL_CAN_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup CAN | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup CAN_Exported_Types CAN Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief HAL State structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_CAN_STATE_RESET = 0x00, /*!< CAN not yet initialized or disabled */ | |||
HAL_CAN_STATE_READY = 0x01, /*!< CAN initialized and ready for use */ | |||
HAL_CAN_STATE_BUSY = 0x02, /*!< CAN process is ongoing */ | |||
HAL_CAN_STATE_BUSY_TX = 0x12, /*!< CAN process is ongoing */ | |||
HAL_CAN_STATE_BUSY_RX = 0x22, /*!< CAN process is ongoing */ | |||
HAL_CAN_STATE_BUSY_TX_RX = 0x32, /*!< CAN process is ongoing */ | |||
HAL_CAN_STATE_TIMEOUT = 0x03, /*!< Timeout state */ | |||
HAL_CAN_STATE_ERROR = 0x04 /*!< CAN error state */ | |||
}HAL_CAN_StateTypeDef; | |||
/** | |||
* @brief CAN init structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Prescaler; /*!< Specifies the length of a time quantum. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 1024 */ | |||
uint32_t Mode; /*!< Specifies the CAN operating mode. | |||
This parameter can be a value of @ref CAN_operating_mode */ | |||
uint32_t SJW; /*!< Specifies the maximum number of time quanta | |||
the CAN hardware is allowed to lengthen or | |||
shorten a bit to perform resynchronization. | |||
This parameter can be a value of @ref CAN_synchronisation_jump_width */ | |||
uint32_t BS1; /*!< Specifies the number of time quanta in Bit Segment 1. | |||
This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_1 */ | |||
uint32_t BS2; /*!< Specifies the number of time quanta in Bit Segment 2. | |||
This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */ | |||
uint32_t TTCM; /*!< Enable or disable the time triggered communication mode. | |||
This parameter can be set to ENABLE or DISABLE. */ | |||
uint32_t ABOM; /*!< Enable or disable the automatic bus-off management. | |||
This parameter can be set to ENABLE or DISABLE */ | |||
uint32_t AWUM; /*!< Enable or disable the automatic wake-up mode. | |||
This parameter can be set to ENABLE or DISABLE */ | |||
uint32_t NART; /*!< Enable or disable the non-automatic retransmission mode. | |||
This parameter can be set to ENABLE or DISABLE */ | |||
uint32_t RFLM; /*!< Enable or disable the receive FIFO Locked mode. | |||
This parameter can be set to ENABLE or DISABLE */ | |||
uint32_t TXFP; /*!< Enable or disable the transmit FIFO priority. | |||
This parameter can be set to ENABLE or DISABLE */ | |||
}CAN_InitTypeDef; | |||
/** | |||
* @brief CAN filter configuration structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bit | |||
configuration, first one for a 16-bit configuration). | |||
This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */ | |||
uint32_t FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bit | |||
configuration, second one for a 16-bit configuration). | |||
This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */ | |||
uint32_t FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number, | |||
according to the mode (MSBs for a 32-bit configuration, | |||
first one for a 16-bit configuration). | |||
This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */ | |||
uint32_t FilterMaskIdLow; /*!< Specifies the filter mask number or identification number, | |||
according to the mode (LSBs for a 32-bit configuration, | |||
second one for a 16-bit configuration). | |||
This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */ | |||
uint32_t FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter. | |||
This parameter can be a value of @ref CAN_filter_FIFO */ | |||
uint32_t FilterNumber; /*!< Specifies the filter which will be initialized. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 27 */ | |||
uint32_t FilterMode; /*!< Specifies the filter mode to be initialized. | |||
This parameter can be a value of @ref CAN_filter_mode */ | |||
uint32_t FilterScale; /*!< Specifies the filter scale. | |||
This parameter can be a value of @ref CAN_filter_scale */ | |||
uint32_t FilterActivation; /*!< Enable or disable the filter. | |||
This parameter can be set to ENABLE or DISABLE. */ | |||
uint32_t BankNumber; /*!< Select the start slave bank filter. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 28 */ | |||
}CAN_FilterConfTypeDef; | |||
/** | |||
* @brief CAN Tx message structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t StdId; /*!< Specifies the standard identifier. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF */ | |||
uint32_t ExtId; /*!< Specifies the extended identifier. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF */ | |||
uint32_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted. | |||
This parameter can be a value of @ref CAN_Identifier_Type */ | |||
uint32_t RTR; /*!< Specifies the type of frame for the message that will be transmitted. | |||
This parameter can be a value of @ref CAN_remote_transmission_request */ | |||
uint32_t DLC; /*!< Specifies the length of the frame that will be transmitted. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 8 */ | |||
uint8_t Data[8]; /*!< Contains the data to be transmitted. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */ | |||
}CanTxMsgTypeDef; | |||
/** | |||
* @brief CAN Rx message structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t StdId; /*!< Specifies the standard identifier. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF */ | |||
uint32_t ExtId; /*!< Specifies the extended identifier. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF */ | |||
uint32_t IDE; /*!< Specifies the type of identifier for the message that will be received. | |||
This parameter can be a value of @ref CAN_Identifier_Type */ | |||
uint32_t RTR; /*!< Specifies the type of frame for the received message. | |||
This parameter can be a value of @ref CAN_remote_transmission_request */ | |||
uint32_t DLC; /*!< Specifies the length of the frame that will be received. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 8 */ | |||
uint8_t Data[8]; /*!< Contains the data to be received. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */ | |||
uint32_t FMI; /*!< Specifies the index of the filter the message stored in the mailbox passes through. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */ | |||
uint32_t FIFONumber; /*!< Specifies the receive FIFO number. | |||
This parameter can be CAN_FIFO0 or CAN_FIFO1 */ | |||
}CanRxMsgTypeDef; | |||
/** | |||
* @brief CAN handle Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
CAN_TypeDef *Instance; /*!< Register base address */ | |||
CAN_InitTypeDef Init; /*!< CAN required parameters */ | |||
CanTxMsgTypeDef* pTxMsg; /*!< Pointer to transmit structure */ | |||
CanRxMsgTypeDef* pRxMsg; /*!< Pointer to reception structure */ | |||
__IO HAL_CAN_StateTypeDef State; /*!< CAN communication state */ | |||
HAL_LockTypeDef Lock; /*!< CAN locking object */ | |||
__IO uint32_t ErrorCode; /*!< CAN Error code */ | |||
}CAN_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup CAN_Exported_Constants CAN Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup HAL_CAN_Error_Code HAL CAN Error Code | |||
* @{ | |||
*/ | |||
#define HAL_CAN_ERROR_NONE 0x00 /*!< No error */ | |||
#define HAL_CAN_ERROR_EWG 0x01 /*!< EWG error */ | |||
#define HAL_CAN_ERROR_EPV 0x02 /*!< EPV error */ | |||
#define HAL_CAN_ERROR_BOF 0x04 /*!< BOF error */ | |||
#define HAL_CAN_ERROR_STF 0x08 /*!< Stuff error */ | |||
#define HAL_CAN_ERROR_FOR 0x10 /*!< Form error */ | |||
#define HAL_CAN_ERROR_ACK 0x20 /*!< Acknowledgment error */ | |||
#define HAL_CAN_ERROR_BR 0x40 /*!< Bit recessive */ | |||
#define HAL_CAN_ERROR_BD 0x80 /*!< LEC dominant */ | |||
#define HAL_CAN_ERROR_CRC 0x100 /*!< LEC transfer error */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_InitStatus CAN InitStatus | |||
* @{ | |||
*/ | |||
#define CAN_INITSTATUS_FAILED ((uint8_t)0x00) /*!< CAN initialization failed */ | |||
#define CAN_INITSTATUS_SUCCESS ((uint8_t)0x01) /*!< CAN initialization OK */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_operating_mode CAN Operating Mode | |||
* @{ | |||
*/ | |||
#define CAN_MODE_NORMAL ((uint32_t)0x00000000) /*!< Normal mode */ | |||
#define CAN_MODE_LOOPBACK ((uint32_t)CAN_BTR_LBKM) /*!< Loopback mode */ | |||
#define CAN_MODE_SILENT ((uint32_t)CAN_BTR_SILM) /*!< Silent mode */ | |||
#define CAN_MODE_SILENT_LOOPBACK ((uint32_t)(CAN_BTR_LBKM | CAN_BTR_SILM)) /*!< Loopback combined with silent mode */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_synchronisation_jump_width CAN Synchronisation Jump Width | |||
* @{ | |||
*/ | |||
#define CAN_SJW_1TQ ((uint32_t)0x00000000) /*!< 1 time quantum */ | |||
#define CAN_SJW_2TQ ((uint32_t)CAN_BTR_SJW_0) /*!< 2 time quantum */ | |||
#define CAN_SJW_3TQ ((uint32_t)CAN_BTR_SJW_1) /*!< 3 time quantum */ | |||
#define CAN_SJW_4TQ ((uint32_t)CAN_BTR_SJW) /*!< 4 time quantum */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_time_quantum_in_bit_segment_1 CAN Time Quantum in bit segment 1 | |||
* @{ | |||
*/ | |||
#define CAN_BS1_1TQ ((uint32_t)0x00000000) /*!< 1 time quantum */ | |||
#define CAN_BS1_2TQ ((uint32_t)CAN_BTR_TS1_0) /*!< 2 time quantum */ | |||
#define CAN_BS1_3TQ ((uint32_t)CAN_BTR_TS1_1) /*!< 3 time quantum */ | |||
#define CAN_BS1_4TQ ((uint32_t)(CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 4 time quantum */ | |||
#define CAN_BS1_5TQ ((uint32_t)CAN_BTR_TS1_2) /*!< 5 time quantum */ | |||
#define CAN_BS1_6TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_0)) /*!< 6 time quantum */ | |||
#define CAN_BS1_7TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1)) /*!< 7 time quantum */ | |||
#define CAN_BS1_8TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 8 time quantum */ | |||
#define CAN_BS1_9TQ ((uint32_t)CAN_BTR_TS1_3) /*!< 9 time quantum */ | |||
#define CAN_BS1_10TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_0)) /*!< 10 time quantum */ | |||
#define CAN_BS1_11TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1)) /*!< 11 time quantum */ | |||
#define CAN_BS1_12TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 12 time quantum */ | |||
#define CAN_BS1_13TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2)) /*!< 13 time quantum */ | |||
#define CAN_BS1_14TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_0)) /*!< 14 time quantum */ | |||
#define CAN_BS1_15TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_1)) /*!< 15 time quantum */ | |||
#define CAN_BS1_16TQ ((uint32_t)CAN_BTR_TS1) /*!< 16 time quantum */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_time_quantum_in_bit_segment_2 CAN Time Quantum in bit segment 2 | |||
* @{ | |||
*/ | |||
#define CAN_BS2_1TQ ((uint32_t)0x00000000) /*!< 1 time quantum */ | |||
#define CAN_BS2_2TQ ((uint32_t)CAN_BTR_TS2_0) /*!< 2 time quantum */ | |||
#define CAN_BS2_3TQ ((uint32_t)CAN_BTR_TS2_1) /*!< 3 time quantum */ | |||
#define CAN_BS2_4TQ ((uint32_t)(CAN_BTR_TS2_1 | CAN_BTR_TS2_0)) /*!< 4 time quantum */ | |||
#define CAN_BS2_5TQ ((uint32_t)CAN_BTR_TS2_2) /*!< 5 time quantum */ | |||
#define CAN_BS2_6TQ ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_0)) /*!< 6 time quantum */ | |||
#define CAN_BS2_7TQ ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_1)) /*!< 7 time quantum */ | |||
#define CAN_BS2_8TQ ((uint32_t)CAN_BTR_TS2) /*!< 8 time quantum */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_filter_mode CAN Filter Mode | |||
* @{ | |||
*/ | |||
#define CAN_FILTERMODE_IDMASK ((uint8_t)0x00) /*!< Identifier mask mode */ | |||
#define CAN_FILTERMODE_IDLIST ((uint8_t)0x01) /*!< Identifier list mode */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_filter_scale CAN Filter Scale | |||
* @{ | |||
*/ | |||
#define CAN_FILTERSCALE_16BIT ((uint8_t)0x00) /*!< Two 16-bit filters */ | |||
#define CAN_FILTERSCALE_32BIT ((uint8_t)0x01) /*!< One 32-bit filter */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_filter_FIFO CAN Filter FIFO | |||
* @{ | |||
*/ | |||
#define CAN_FILTER_FIFO0 ((uint8_t)0x00) /*!< Filter FIFO 0 assignment for filter x */ | |||
#define CAN_FILTER_FIFO1 ((uint8_t)0x01) /*!< Filter FIFO 1 assignment for filter x */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_Identifier_Type CAN Identifier Type | |||
* @{ | |||
*/ | |||
#define CAN_ID_STD ((uint32_t)0x00000000) /*!< Standard Id */ | |||
#define CAN_ID_EXT ((uint32_t)0x00000004) /*!< Extended Id */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_remote_transmission_request CAN Remote Transmission Request | |||
* @{ | |||
*/ | |||
#define CAN_RTR_DATA ((uint32_t)0x00000000) /*!< Data frame */ | |||
#define CAN_RTR_REMOTE ((uint32_t)0x00000002) /*!< Remote frame */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_receive_FIFO_number_constants CAN Receive FIFO Number Constants | |||
* @{ | |||
*/ | |||
#define CAN_FIFO0 ((uint8_t)0x00) /*!< CAN FIFO 0 used to receive */ | |||
#define CAN_FIFO1 ((uint8_t)0x01) /*!< CAN FIFO 1 used to receive */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_flags CAN Flags | |||
* @{ | |||
*/ | |||
/* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus() | |||
and CAN_ClearFlag() functions. */ | |||
/* If the flag is 0x1XXXXXXX, it means that it can only be used with | |||
CAN_GetFlagStatus() function. */ | |||
/* Transmit Flags */ | |||
#define CAN_FLAG_RQCP0 ((uint32_t)0x00000500) /*!< Request MailBox0 flag */ | |||
#define CAN_FLAG_RQCP1 ((uint32_t)0x00000508) /*!< Request MailBox1 flag */ | |||
#define CAN_FLAG_RQCP2 ((uint32_t)0x00000510) /*!< Request MailBox2 flag */ | |||
#define CAN_FLAG_TXOK0 ((uint32_t)0x00000501) /*!< Transmission OK MailBox0 flag */ | |||
#define CAN_FLAG_TXOK1 ((uint32_t)0x00000509) /*!< Transmission OK MailBox1 flag */ | |||
#define CAN_FLAG_TXOK2 ((uint32_t)0x00000511) /*!< Transmission OK MailBox2 flag */ | |||
#define CAN_FLAG_TME0 ((uint32_t)0x0000051A) /*!< Transmit mailbox 0 empty flag */ | |||
#define CAN_FLAG_TME1 ((uint32_t)0x0000051B) /*!< Transmit mailbox 0 empty flag */ | |||
#define CAN_FLAG_TME2 ((uint32_t)0x0000051C) /*!< Transmit mailbox 0 empty flag */ | |||
/* Receive Flags */ | |||
#define CAN_FLAG_FF0 ((uint32_t)0x00000203) /*!< FIFO 0 Full flag */ | |||
#define CAN_FLAG_FOV0 ((uint32_t)0x00000204) /*!< FIFO 0 Overrun flag */ | |||
#define CAN_FLAG_FF1 ((uint32_t)0x00000403) /*!< FIFO 1 Full flag */ | |||
#define CAN_FLAG_FOV1 ((uint32_t)0x00000404) /*!< FIFO 1 Overrun flag */ | |||
/* Operating Mode Flags */ | |||
#define CAN_FLAG_WKU ((uint32_t)0x00000103) /*!< Wake up flag */ | |||
#define CAN_FLAG_SLAK ((uint32_t)0x00000101) /*!< Sleep acknowledge flag */ | |||
#define CAN_FLAG_SLAKI ((uint32_t)0x00000104) /*!< Sleep acknowledge flag */ | |||
/* @note When SLAK interrupt is disabled (SLKIE=0), no polling on SLAKI is possible. | |||
In this case the SLAK bit can be polled.*/ | |||
/* Error Flags */ | |||
#define CAN_FLAG_EWG ((uint32_t)0x00000300) /*!< Error warning flag */ | |||
#define CAN_FLAG_EPV ((uint32_t)0x00000301) /*!< Error passive flag */ | |||
#define CAN_FLAG_BOF ((uint32_t)0x00000302) /*!< Bus-Off flag */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_Interrupts CAN Interrupts | |||
* @{ | |||
*/ | |||
#define CAN_IT_TME ((uint32_t)CAN_IER_TMEIE) /*!< Transmit mailbox empty interrupt */ | |||
/* Receive Interrupts */ | |||
#define CAN_IT_FMP0 ((uint32_t)CAN_IER_FMPIE0) /*!< FIFO 0 message pending interrupt */ | |||
#define CAN_IT_FF0 ((uint32_t)CAN_IER_FFIE0) /*!< FIFO 0 full interrupt */ | |||
#define CAN_IT_FOV0 ((uint32_t)CAN_IER_FOVIE0) /*!< FIFO 0 overrun interrupt */ | |||
#define CAN_IT_FMP1 ((uint32_t)CAN_IER_FMPIE1) /*!< FIFO 1 message pending interrupt */ | |||
#define CAN_IT_FF1 ((uint32_t)CAN_IER_FFIE1) /*!< FIFO 1 full interrupt */ | |||
#define CAN_IT_FOV1 ((uint32_t)CAN_IER_FOVIE1) /*!< FIFO 1 overrun interrupt */ | |||
/* Operating Mode Interrupts */ | |||
#define CAN_IT_WKU ((uint32_t)CAN_IER_WKUIE) /*!< Wake-up interrupt */ | |||
#define CAN_IT_SLK ((uint32_t)CAN_IER_SLKIE) /*!< Sleep acknowledge interrupt */ | |||
/* Error Interrupts */ | |||
#define CAN_IT_EWG ((uint32_t)CAN_IER_EWGIE) /*!< Error warning interrupt */ | |||
#define CAN_IT_EPV ((uint32_t)CAN_IER_EPVIE) /*!< Error passive interrupt */ | |||
#define CAN_IT_BOF ((uint32_t)CAN_IER_BOFIE) /*!< Bus-off interrupt */ | |||
#define CAN_IT_LEC ((uint32_t)CAN_IER_LECIE) /*!< Last error code interrupt */ | |||
#define CAN_IT_ERR ((uint32_t)CAN_IER_ERRIE) /*!< Error Interrupt */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CAN_Mailboxes_Definition CAN Mailboxes Definition | |||
* @{ | |||
*/ | |||
#define CAN_TXMAILBOX_0 ((uint8_t)0x00) | |||
#define CAN_TXMAILBOX_1 ((uint8_t)0x01) | |||
#define CAN_TXMAILBOX_2 ((uint8_t)0x02) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup CAN_Exported_Macros CAN Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset CAN handle state | |||
* @param __HANDLE__: specifies the CAN Handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_CAN_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CAN_STATE_RESET) | |||
/** | |||
* @brief Enable the specified CAN interrupts. | |||
* @param __HANDLE__: CAN handle | |||
* @param __INTERRUPT__: CAN Interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_CAN_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__)) | |||
/** | |||
* @brief Disable the specified CAN interrupts. | |||
* @param __HANDLE__: CAN handle | |||
* @param __INTERRUPT__: CAN Interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_CAN_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__)) | |||
/** | |||
* @brief Return the number of pending received messages. | |||
* @param __HANDLE__: CAN handle | |||
* @param __FIFONUMBER__: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1. | |||
* @retval The number of pending message. | |||
*/ | |||
#define __HAL_CAN_MSG_PENDING(__HANDLE__, __FIFONUMBER__) (((__FIFONUMBER__) == CAN_FIFO0)? \ | |||
((uint8_t)((__HANDLE__)->Instance->RF0R&(uint32_t)0x03)) : ((uint8_t)((__HANDLE__)->Instance->RF1R&(uint32_t)0x03))) | |||
/** @brief Check whether the specified CAN flag is set or not. | |||
* @param __HANDLE__: CAN Handle | |||
* @param __FLAG__: specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg CAN_TSR_RQCP0: Request MailBox0 Flag | |||
* @arg CAN_TSR_RQCP1: Request MailBox1 Flag | |||
* @arg CAN_TSR_RQCP2: Request MailBox2 Flag | |||
* @arg CAN_FLAG_TXOK0: Transmission OK MailBox0 Flag | |||
* @arg CAN_FLAG_TXOK1: Transmission OK MailBox1 Flag | |||
* @arg CAN_FLAG_TXOK2: Transmission OK MailBox2 Flag | |||
* @arg CAN_FLAG_TME0: Transmit mailbox 0 empty Flag | |||
* @arg CAN_FLAG_TME1: Transmit mailbox 1 empty Flag | |||
* @arg CAN_FLAG_TME2: Transmit mailbox 2 empty Flag | |||
* @arg CAN_FLAG_FMP0: FIFO 0 Message Pending Flag | |||
* @arg CAN_FLAG_FF0: FIFO 0 Full Flag | |||
* @arg CAN_FLAG_FOV0: FIFO 0 Overrun Flag | |||
* @arg CAN_FLAG_FMP1: FIFO 1 Message Pending Flag | |||
* @arg CAN_FLAG_FF1: FIFO 1 Full Flag | |||
* @arg CAN_FLAG_FOV1: FIFO 1 Overrun Flag | |||
* @arg CAN_FLAG_WKU: Wake up Flag | |||
* @arg CAN_FLAG_SLAK: Sleep acknowledge Flag | |||
* @arg CAN_FLAG_SLAKI: Sleep acknowledge Flag | |||
* @arg CAN_FLAG_EWG: Error Warning Flag | |||
* @arg CAN_FLAG_EPV: Error Passive Flag | |||
* @arg CAN_FLAG_BOF: Bus-Off Flag | |||
* @retval The new state of __FLAG__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_CAN_GET_FLAG(__HANDLE__, __FLAG__) \ | |||
((((__FLAG__) >> 8) == 5)? ((((__HANDLE__)->Instance->TSR) & (1 << ((__FLAG__) & CAN_FLAG_MASK))) == (1 << ((__FLAG__) & CAN_FLAG_MASK))): \ | |||
(((__FLAG__) >> 8) == 2)? ((((__HANDLE__)->Instance->RF0R) & (1 << ((__FLAG__) & CAN_FLAG_MASK))) == (1 << ((__FLAG__) & CAN_FLAG_MASK))): \ | |||
(((__FLAG__) >> 8) == 4)? ((((__HANDLE__)->Instance->RF1R) & (1 << ((__FLAG__) & CAN_FLAG_MASK))) == (1 << ((__FLAG__) & CAN_FLAG_MASK))): \ | |||
(((__FLAG__) >> 8) == 1)? ((((__HANDLE__)->Instance->MSR) & (1 << ((__FLAG__) & CAN_FLAG_MASK))) == (1 << ((__FLAG__) & CAN_FLAG_MASK))): \ | |||
((((__HANDLE__)->Instance->ESR) & (1 << ((__FLAG__) & CAN_FLAG_MASK))) == (1 << ((__FLAG__) & CAN_FLAG_MASK)))) | |||
/** @brief Clear the specified CAN pending flag. | |||
* @param __HANDLE__: CAN Handle. | |||
* @param __FLAG__: specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg CAN_TSR_RQCP0: Request MailBox0 Flag | |||
* @arg CAN_TSR_RQCP1: Request MailBox1 Flag | |||
* @arg CAN_TSR_RQCP2: Request MailBox2 Flag | |||
* @arg CAN_FLAG_TXOK0: Transmission OK MailBox0 Flag | |||
* @arg CAN_FLAG_TXOK1: Transmission OK MailBox1 Flag | |||
* @arg CAN_FLAG_TXOK2: Transmission OK MailBox2 Flag | |||
* @arg CAN_FLAG_TME0: Transmit mailbox 0 empty Flag | |||
* @arg CAN_FLAG_TME1: Transmit mailbox 1 empty Flag | |||
* @arg CAN_FLAG_TME2: Transmit mailbox 2 empty Flag | |||
* @arg CAN_FLAG_FMP0: FIFO 0 Message Pending Flag | |||
* @arg CAN_FLAG_FF0: FIFO 0 Full Flag | |||
* @arg CAN_FLAG_FOV0: FIFO 0 Overrun Flag | |||
* @arg CAN_FLAG_FMP1: FIFO 1 Message Pending Flag | |||
* @arg CAN_FLAG_FF1: FIFO 1 Full Flag | |||
* @arg CAN_FLAG_FOV1: FIFO 1 Overrun Flag | |||
* @arg CAN_FLAG_WKU: Wake up Flag | |||
* @arg CAN_FLAG_SLAK: Sleep acknowledge Flag | |||
* @arg CAN_FLAG_SLAKI: Sleep acknowledge Flag | |||
* @arg CAN_FLAG_EWG: Error Warning Flag | |||
* @arg CAN_FLAG_EPV: Error Passive Flag | |||
* @arg CAN_FLAG_BOF: Bus-Off Flag | |||
* @retval The new state of __FLAG__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_CAN_CLEAR_FLAG(__HANDLE__, __FLAG__) \ | |||
((((__FLAG__) >> 8) == 5)? (((__HANDLE__)->Instance->TSR) = ~((uint32_t)1 << ((__FLAG__) & CAN_FLAG_MASK))): \ | |||
(((__FLAG__) >> 8) == 2)? (((__HANDLE__)->Instance->RF0R) = ~((uint32_t)1 << ((__FLAG__) & CAN_FLAG_MASK))): \ | |||
(((__FLAG__) >> 8) == 4)? (((__HANDLE__)->Instance->RF1R) = ~((uint32_t)1 << ((__FLAG__) & CAN_FLAG_MASK))): \ | |||
(((__FLAG__) >> 8) == 1)? (((__HANDLE__)->Instance->MSR) = ~((uint32_t)1 << ((__FLAG__) & CAN_FLAG_MASK))): \ | |||
(((__HANDLE__)->Instance->ESR) = ~((uint32_t)1 << ((__FLAG__) & CAN_FLAG_MASK)))) | |||
/** @brief Check if the specified CAN interrupt source is enabled or disabled. | |||
* @param __HANDLE__: CAN Handle | |||
* @param __INTERRUPT__: specifies the CAN interrupt source to check. | |||
* This parameter can be one of the following values: | |||
* @arg CAN_IT_TME: Transmit mailbox empty interrupt enable | |||
* @arg CAN_IT_FMP0: FIFO0 message pending interrupt enable | |||
* @arg CAN_IT_FMP1: FIFO1 message pending interrupt enable | |||
* @retval The new state of __IT__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_CAN_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) | |||
/** | |||
* @brief Check the transmission status of a CAN Frame. | |||
* @param __HANDLE__: CAN Handle | |||
* @param __TRANSMITMAILBOX__: the number of the mailbox that is used for transmission. | |||
* @retval The new status of transmission (TRUE or FALSE). | |||
*/ | |||
#define __HAL_CAN_TRANSMIT_STATUS(__HANDLE__, __TRANSMITMAILBOX__)\ | |||
(((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_0)? ((((__HANDLE__)->Instance->TSR) & (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0)) == (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0)) :\ | |||
((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_1)? ((((__HANDLE__)->Instance->TSR) & (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1)) == (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1)) :\ | |||
((((__HANDLE__)->Instance->TSR) & (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2)) == (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2))) | |||
/** | |||
* @brief Release the specified receive FIFO. | |||
* @param __HANDLE__: CAN handle | |||
* @param __FIFONUMBER__: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1. | |||
* @retval None | |||
*/ | |||
#define __HAL_CAN_FIFO_RELEASE(__HANDLE__, __FIFONUMBER__) (((__FIFONUMBER__) == CAN_FIFO0)? \ | |||
((__HANDLE__)->Instance->RF0R |= CAN_RF0R_RFOM0) : ((__HANDLE__)->Instance->RF1R |= CAN_RF1R_RFOM1)) | |||
/** | |||
* @brief Cancel a transmit request. | |||
* @param __HANDLE__: CAN Handle | |||
* @param __TRANSMITMAILBOX__: the number of the mailbox that is used for transmission. | |||
* @retval None | |||
*/ | |||
#define __HAL_CAN_CANCEL_TRANSMIT(__HANDLE__, __TRANSMITMAILBOX__)\ | |||
(((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_0)? ((__HANDLE__)->Instance->TSR |= CAN_TSR_ABRQ0) :\ | |||
((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_1)? ((__HANDLE__)->Instance->TSR |= CAN_TSR_ABRQ1) :\ | |||
((__HANDLE__)->Instance->TSR |= CAN_TSR_ABRQ2)) | |||
/** | |||
* @brief Enable or disable the DBG Freeze for CAN. | |||
* @param __HANDLE__: CAN Handle | |||
* @param __NEWSTATE__: new state of the CAN peripheral. | |||
* This parameter can be: ENABLE (CAN reception/transmission is frozen | |||
* during debug. Reception FIFOs can still be accessed/controlled normally) | |||
* or DISABLE (CAN is working during debug). | |||
* @retval None | |||
*/ | |||
#define __HAL_CAN_DBG_FREEZE(__HANDLE__, __NEWSTATE__) (((__NEWSTATE__) == ENABLE)? \ | |||
((__HANDLE__)->Instance->MCR |= CAN_MCR_DBF) : ((__HANDLE__)->Instance->MCR &= ~CAN_MCR_DBF)) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup CAN_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup CAN_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization/de-initialization functions ***********************************/ | |||
HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef* hcan); | |||
HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef* hcan, CAN_FilterConfTypeDef* sFilterConfig); | |||
HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef* hcan); | |||
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan); | |||
void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup CAN_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* I/O operation functions ******************************************************/ | |||
HAL_StatusTypeDef HAL_CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_CAN_Transmit_IT(CAN_HandleTypeDef *hcan); | |||
HAL_StatusTypeDef HAL_CAN_Receive(CAN_HandleTypeDef *hcan, uint8_t FIFONumber, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_CAN_Receive_IT(CAN_HandleTypeDef *hcan, uint8_t FIFONumber); | |||
HAL_StatusTypeDef HAL_CAN_Sleep(CAN_HandleTypeDef *hcan); | |||
HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef *hcan); | |||
void HAL_CAN_IRQHandler(CAN_HandleTypeDef* hcan); | |||
void HAL_CAN_TxCpltCallback(CAN_HandleTypeDef* hcan); | |||
void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan); | |||
void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup CAN_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
/* Peripheral State functions ***************************************************/ | |||
uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan); | |||
HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef* hcan); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/** @defgroup CAN_Private_Types CAN Private Types | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/** @defgroup CAN_Private_Variables CAN Private Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup CAN_Private_Constants CAN Private Constants | |||
* @{ | |||
*/ | |||
#define CAN_TXSTATUS_NOMAILBOX ((uint8_t)0x04) /*!< CAN cell did not provide CAN_TxStatus_NoMailBox */ | |||
#define CAN_FLAG_MASK ((uint32_t)0x000000FF) | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup CAN_Private_Macros CAN Private Macros | |||
* @{ | |||
*/ | |||
#define IS_CAN_MODE(MODE) (((MODE) == CAN_MODE_NORMAL) || \ | |||
((MODE) == CAN_MODE_LOOPBACK)|| \ | |||
((MODE) == CAN_MODE_SILENT) || \ | |||
((MODE) == CAN_MODE_SILENT_LOOPBACK)) | |||
#define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1TQ) || ((SJW) == CAN_SJW_2TQ)|| \ | |||
((SJW) == CAN_SJW_3TQ) || ((SJW) == CAN_SJW_4TQ)) | |||
#define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16TQ) | |||
#define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8TQ) | |||
#define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024)) | |||
#define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27) | |||
#define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FILTERMODE_IDMASK) || \ | |||
((MODE) == CAN_FILTERMODE_IDLIST)) | |||
#define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FILTERSCALE_16BIT) || \ | |||
((SCALE) == CAN_FILTERSCALE_32BIT)) | |||
#define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FILTER_FIFO0) || \ | |||
((FIFO) == CAN_FILTER_FIFO1)) | |||
#define IS_CAN_BANKNUMBER(BANKNUMBER) ((BANKNUMBER) <= 28) | |||
#define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02)) | |||
#define IS_CAN_STDID(STDID) ((STDID) <= ((uint32_t)0x7FF)) | |||
#define IS_CAN_EXTID(EXTID) ((EXTID) <= ((uint32_t)0x1FFFFFFF)) | |||
#define IS_CAN_DLC(DLC) ((DLC) <= ((uint8_t)0x08)) | |||
#define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_ID_STD) || \ | |||
((IDTYPE) == CAN_ID_EXT)) | |||
#define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_DATA) || ((RTR) == CAN_RTR_REMOTE)) | |||
#define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1)) | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup CAN_Private_Functions CAN Private Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_CAN_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,490 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_cortex.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of CORTEX HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_CORTEX_H | |||
#define __STM32F7xx_HAL_CORTEX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup CORTEX | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Exported_Types Cortex Exported Types | |||
* @{ | |||
*/ | |||
#if (__MPU_PRESENT == 1) | |||
/** @defgroup CORTEX_MPU_Region_Initialization_Structure_definition MPU Region Initialization Structure Definition | |||
* @brief MPU Region initialization structure | |||
* @{ | |||
*/ | |||
typedef struct | |||
{ | |||
uint8_t Enable; /*!< Specifies the status of the region. | |||
This parameter can be a value of @ref CORTEX_MPU_Region_Enable */ | |||
uint8_t Number; /*!< Specifies the number of the region to protect. | |||
This parameter can be a value of @ref CORTEX_MPU_Region_Number */ | |||
uint32_t BaseAddress; /*!< Specifies the base address of the region to protect. */ | |||
uint8_t Size; /*!< Specifies the size of the region to protect. | |||
This parameter can be a value of @ref CORTEX_MPU_Region_Size */ | |||
uint8_t SubRegionDisable; /*!< Specifies the number of the subregion protection to disable. | |||
This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */ | |||
uint8_t TypeExtField; /*!< Specifies the TEX field level. | |||
This parameter can be a value of @ref CORTEX_MPU_TEX_Levels */ | |||
uint8_t AccessPermission; /*!< Specifies the region access permission type. | |||
This parameter can be a value of @ref CORTEX_MPU_Region_Permission_Attributes */ | |||
uint8_t DisableExec; /*!< Specifies the instruction access status. | |||
This parameter can be a value of @ref CORTEX_MPU_Instruction_Access */ | |||
uint8_t IsShareable; /*!< Specifies the shareability status of the protected region. | |||
This parameter can be a value of @ref CORTEX_MPU_Access_Shareable */ | |||
uint8_t IsCacheable; /*!< Specifies the cacheable status of the region protected. | |||
This parameter can be a value of @ref CORTEX_MPU_Access_Cacheable */ | |||
uint8_t IsBufferable; /*!< Specifies the bufferable status of the protected region. | |||
This parameter can be a value of @ref CORTEX_MPU_Access_Bufferable */ | |||
}MPU_Region_InitTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
#endif /* __MPU_PRESENT */ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup CORTEX_Preemption_Priority_Group CORTEX Preemption Priority Group | |||
* @{ | |||
*/ | |||
#define NVIC_PRIORITYGROUP_0 ((uint32_t)0x00000007) /*!< 0 bits for pre-emption priority | |||
4 bits for subpriority */ | |||
#define NVIC_PRIORITYGROUP_1 ((uint32_t)0x00000006) /*!< 1 bits for pre-emption priority | |||
3 bits for subpriority */ | |||
#define NVIC_PRIORITYGROUP_2 ((uint32_t)0x00000005) /*!< 2 bits for pre-emption priority | |||
2 bits for subpriority */ | |||
#define NVIC_PRIORITYGROUP_3 ((uint32_t)0x00000004) /*!< 3 bits for pre-emption priority | |||
1 bits for subpriority */ | |||
#define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003) /*!< 4 bits for pre-emption priority | |||
0 bits for subpriority */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_SysTick_clock_source CORTEX _SysTick clock source | |||
* @{ | |||
*/ | |||
#define SYSTICK_CLKSOURCE_HCLK_DIV8 ((uint32_t)0x00000000) | |||
#define SYSTICK_CLKSOURCE_HCLK ((uint32_t)0x00000004) | |||
/** | |||
* @} | |||
*/ | |||
#if (__MPU_PRESENT == 1) | |||
/** @defgroup CORTEX_MPU_HFNMI_PRIVDEF_Control MPU HFNMI and PRIVILEGED Access control | |||
* @{ | |||
*/ | |||
#define MPU_HFNMI_PRIVDEF_NONE ((uint32_t)0x00000000) | |||
#define MPU_HARDFAULT_NMI ((uint32_t)0x00000002) | |||
#define MPU_PRIVILEGED_DEFAULT ((uint32_t)0x00000004) | |||
#define MPU_HFNMI_PRIVDEF ((uint32_t)0x00000006) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Region_Enable CORTEX MPU Region Enable | |||
* @{ | |||
*/ | |||
#define MPU_REGION_ENABLE ((uint8_t)0x01) | |||
#define MPU_REGION_DISABLE ((uint8_t)0x00) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Instruction_Access CORTEX MPU Instruction Access | |||
* @{ | |||
*/ | |||
#define MPU_INSTRUCTION_ACCESS_ENABLE ((uint8_t)0x00) | |||
#define MPU_INSTRUCTION_ACCESS_DISABLE ((uint8_t)0x01) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Access_Shareable CORTEX MPU Instruction Access Shareable | |||
* @{ | |||
*/ | |||
#define MPU_ACCESS_SHAREABLE ((uint8_t)0x01) | |||
#define MPU_ACCESS_NOT_SHAREABLE ((uint8_t)0x00) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Access_Cacheable CORTEX MPU Instruction Access Cacheable | |||
* @{ | |||
*/ | |||
#define MPU_ACCESS_CACHEABLE ((uint8_t)0x01) | |||
#define MPU_ACCESS_NOT_CACHEABLE ((uint8_t)0x00) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Access_Bufferable CORTEX MPU Instruction Access Bufferable | |||
* @{ | |||
*/ | |||
#define MPU_ACCESS_BUFFERABLE ((uint8_t)0x01) | |||
#define MPU_ACCESS_NOT_BUFFERABLE ((uint8_t)0x00) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_TEX_Levels MPU TEX Levels | |||
* @{ | |||
*/ | |||
#define MPU_TEX_LEVEL0 ((uint8_t)0x00) | |||
#define MPU_TEX_LEVEL1 ((uint8_t)0x01) | |||
#define MPU_TEX_LEVEL2 ((uint8_t)0x02) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Region_Size CORTEX MPU Region Size | |||
* @{ | |||
*/ | |||
#define MPU_REGION_SIZE_32B ((uint8_t)0x04) | |||
#define MPU_REGION_SIZE_64B ((uint8_t)0x05) | |||
#define MPU_REGION_SIZE_128B ((uint8_t)0x06) | |||
#define MPU_REGION_SIZE_256B ((uint8_t)0x07) | |||
#define MPU_REGION_SIZE_512B ((uint8_t)0x08) | |||
#define MPU_REGION_SIZE_1KB ((uint8_t)0x09) | |||
#define MPU_REGION_SIZE_2KB ((uint8_t)0x0A) | |||
#define MPU_REGION_SIZE_4KB ((uint8_t)0x0B) | |||
#define MPU_REGION_SIZE_8KB ((uint8_t)0x0C) | |||
#define MPU_REGION_SIZE_16KB ((uint8_t)0x0D) | |||
#define MPU_REGION_SIZE_32KB ((uint8_t)0x0E) | |||
#define MPU_REGION_SIZE_64KB ((uint8_t)0x0F) | |||
#define MPU_REGION_SIZE_128KB ((uint8_t)0x10) | |||
#define MPU_REGION_SIZE_256KB ((uint8_t)0x11) | |||
#define MPU_REGION_SIZE_512KB ((uint8_t)0x12) | |||
#define MPU_REGION_SIZE_1MB ((uint8_t)0x13) | |||
#define MPU_REGION_SIZE_2MB ((uint8_t)0x14) | |||
#define MPU_REGION_SIZE_4MB ((uint8_t)0x15) | |||
#define MPU_REGION_SIZE_8MB ((uint8_t)0x16) | |||
#define MPU_REGION_SIZE_16MB ((uint8_t)0x17) | |||
#define MPU_REGION_SIZE_32MB ((uint8_t)0x18) | |||
#define MPU_REGION_SIZE_64MB ((uint8_t)0x19) | |||
#define MPU_REGION_SIZE_128MB ((uint8_t)0x1A) | |||
#define MPU_REGION_SIZE_256MB ((uint8_t)0x1B) | |||
#define MPU_REGION_SIZE_512MB ((uint8_t)0x1C) | |||
#define MPU_REGION_SIZE_1GB ((uint8_t)0x1D) | |||
#define MPU_REGION_SIZE_2GB ((uint8_t)0x1E) | |||
#define MPU_REGION_SIZE_4GB ((uint8_t)0x1F) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Region_Permission_Attributes CORTEX MPU Region Permission Attributes | |||
* @{ | |||
*/ | |||
#define MPU_REGION_NO_ACCESS ((uint8_t)0x00) | |||
#define MPU_REGION_PRIV_RW ((uint8_t)0x01) | |||
#define MPU_REGION_PRIV_RW_URO ((uint8_t)0x02) | |||
#define MPU_REGION_FULL_ACCESS ((uint8_t)0x03) | |||
#define MPU_REGION_PRIV_RO ((uint8_t)0x05) | |||
#define MPU_REGION_PRIV_RO_URO ((uint8_t)0x06) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Region_Number CORTEX MPU Region Number | |||
* @{ | |||
*/ | |||
#define MPU_REGION_NUMBER0 ((uint8_t)0x00) | |||
#define MPU_REGION_NUMBER1 ((uint8_t)0x01) | |||
#define MPU_REGION_NUMBER2 ((uint8_t)0x02) | |||
#define MPU_REGION_NUMBER3 ((uint8_t)0x03) | |||
#define MPU_REGION_NUMBER4 ((uint8_t)0x04) | |||
#define MPU_REGION_NUMBER5 ((uint8_t)0x05) | |||
#define MPU_REGION_NUMBER6 ((uint8_t)0x06) | |||
#define MPU_REGION_NUMBER7 ((uint8_t)0x07) | |||
/** | |||
* @} | |||
*/ | |||
#endif /* __MPU_PRESENT */ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported Macros -----------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Exported_Macros CORTEX Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Configures the SysTick clock source. | |||
* @param __CLKSRC__: 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 | |||
*/ | |||
#define __HAL_CORTEX_SYSTICKCLK_CONFIG(__CLKSRC__) \ | |||
do { \ | |||
if ((__CLKSRC__) == SYSTICK_CLKSOURCE_HCLK) \ | |||
{ \ | |||
SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK; \ | |||
} \ | |||
else \ | |||
SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK; \ | |||
} while(0) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup CORTEX_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup CORTEX_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions *****************************/ | |||
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup); | |||
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); | |||
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn); | |||
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn); | |||
void HAL_NVIC_SystemReset(void); | |||
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup CORTEX_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions ***********************************************/ | |||
#if (__MPU_PRESENT == 1) | |||
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init); | |||
#endif /* __MPU_PRESENT */ | |||
uint32_t HAL_NVIC_GetPriorityGrouping(void); | |||
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority); | |||
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn); | |||
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn); | |||
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn); | |||
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn); | |||
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource); | |||
void HAL_SYSTICK_IRQHandler(void); | |||
void HAL_SYSTICK_Callback(void); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Private_Macros CORTEX Private Macros | |||
* @{ | |||
*/ | |||
#define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PRIORITYGROUP_0) || \ | |||
((GROUP) == NVIC_PRIORITYGROUP_1) || \ | |||
((GROUP) == NVIC_PRIORITYGROUP_2) || \ | |||
((GROUP) == NVIC_PRIORITYGROUP_3) || \ | |||
((GROUP) == NVIC_PRIORITYGROUP_4)) | |||
#define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) | |||
#define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) | |||
#define IS_NVIC_DEVICE_IRQ(IRQ) ((IRQ) >= 0x00) | |||
#define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SYSTICK_CLKSOURCE_HCLK) || \ | |||
((SOURCE) == SYSTICK_CLKSOURCE_HCLK_DIV8)) | |||
#if (__MPU_PRESENT == 1) | |||
#define IS_MPU_REGION_ENABLE(STATE) (((STATE) == MPU_REGION_ENABLE) || \ | |||
((STATE) == MPU_REGION_DISABLE)) | |||
#define IS_MPU_INSTRUCTION_ACCESS(STATE) (((STATE) == MPU_INSTRUCTION_ACCESS_ENABLE) || \ | |||
((STATE) == MPU_INSTRUCTION_ACCESS_DISABLE)) | |||
#define IS_MPU_ACCESS_SHAREABLE(STATE) (((STATE) == MPU_ACCESS_SHAREABLE) || \ | |||
((STATE) == MPU_ACCESS_NOT_SHAREABLE)) | |||
#define IS_MPU_ACCESS_CACHEABLE(STATE) (((STATE) == MPU_ACCESS_CACHEABLE) || \ | |||
((STATE) == MPU_ACCESS_NOT_CACHEABLE)) | |||
#define IS_MPU_ACCESS_BUFFERABLE(STATE) (((STATE) == MPU_ACCESS_BUFFERABLE) || \ | |||
((STATE) == MPU_ACCESS_NOT_BUFFERABLE)) | |||
#define IS_MPU_TEX_LEVEL(TYPE) (((TYPE) == MPU_TEX_LEVEL0) || \ | |||
((TYPE) == MPU_TEX_LEVEL1) || \ | |||
((TYPE) == MPU_TEX_LEVEL2)) | |||
#define IS_MPU_REGION_PERMISSION_ATTRIBUTE(TYPE) (((TYPE) == MPU_REGION_NO_ACCESS) || \ | |||
((TYPE) == MPU_REGION_PRIV_RW) || \ | |||
((TYPE) == MPU_REGION_PRIV_RW_URO) || \ | |||
((TYPE) == MPU_REGION_FULL_ACCESS) || \ | |||
((TYPE) == MPU_REGION_PRIV_RO) || \ | |||
((TYPE) == MPU_REGION_PRIV_RO_URO)) | |||
#define IS_MPU_REGION_NUMBER(NUMBER) (((NUMBER) == MPU_REGION_NUMBER0) || \ | |||
((NUMBER) == MPU_REGION_NUMBER1) || \ | |||
((NUMBER) == MPU_REGION_NUMBER2) || \ | |||
((NUMBER) == MPU_REGION_NUMBER3) || \ | |||
((NUMBER) == MPU_REGION_NUMBER4) || \ | |||
((NUMBER) == MPU_REGION_NUMBER5) || \ | |||
((NUMBER) == MPU_REGION_NUMBER6) || \ | |||
((NUMBER) == MPU_REGION_NUMBER7)) | |||
#define IS_MPU_REGION_SIZE(SIZE) (((SIZE) == MPU_REGION_SIZE_32B) || \ | |||
((SIZE) == MPU_REGION_SIZE_64B) || \ | |||
((SIZE) == MPU_REGION_SIZE_128B) || \ | |||
((SIZE) == MPU_REGION_SIZE_256B) || \ | |||
((SIZE) == MPU_REGION_SIZE_512B) || \ | |||
((SIZE) == MPU_REGION_SIZE_1KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_2KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_4KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_8KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_16KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_32KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_64KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_128KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_256KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_512KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_1MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_2MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_4MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_8MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_16MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_32MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_64MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_128MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_256MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_512MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_1GB) || \ | |||
((SIZE) == MPU_REGION_SIZE_2GB) || \ | |||
((SIZE) == MPU_REGION_SIZE_4GB)) | |||
#define IS_MPU_SUB_REGION_DISABLE(SUBREGION) ((SUBREGION) < (uint16_t)0x00FF) | |||
#endif /* __MPU_PRESENT */ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Private_Functions CORTEX Private Functions | |||
* @brief CORTEX private functions | |||
* @{ | |||
*/ | |||
#if (__MPU_PRESENT == 1) | |||
/** | |||
* @brief Disables the MPU | |||
* @retval None | |||
*/ | |||
__STATIC_INLINE void HAL_MPU_Disable(void) | |||
{ | |||
/* Disable fault exceptions */ | |||
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; | |||
/* Disable the MPU */ | |||
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; | |||
} | |||
/** | |||
* @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 | |||
*/ | |||
__STATIC_INLINE 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; | |||
} | |||
#endif /* __MPU_PRESENT */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_CORTEX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,408 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_dac.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of DAC HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_DAC_H | |||
#define __STM32F7xx_HAL_DAC_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup DAC | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup DAC_Exported_Types DAC Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief HAL State structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_DAC_STATE_RESET = 0x00, /*!< DAC not yet initialized or disabled */ | |||
HAL_DAC_STATE_READY = 0x01, /*!< DAC initialized and ready for use */ | |||
HAL_DAC_STATE_BUSY = 0x02, /*!< DAC internal processing is ongoing */ | |||
HAL_DAC_STATE_TIMEOUT = 0x03, /*!< DAC timeout state */ | |||
HAL_DAC_STATE_ERROR = 0x04 /*!< DAC error state */ | |||
}HAL_DAC_StateTypeDef; | |||
/** | |||
* @brief DAC handle Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
DAC_TypeDef *Instance; /*!< Register base address */ | |||
__IO HAL_DAC_StateTypeDef State; /*!< DAC communication state */ | |||
HAL_LockTypeDef Lock; /*!< DAC locking object */ | |||
DMA_HandleTypeDef *DMA_Handle1; /*!< Pointer DMA handler for channel 1 */ | |||
DMA_HandleTypeDef *DMA_Handle2; /*!< Pointer DMA handler for channel 2 */ | |||
__IO uint32_t ErrorCode; /*!< DAC Error code */ | |||
}DAC_HandleTypeDef; | |||
/** | |||
* @brief DAC Configuration regular Channel structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel. | |||
This parameter can be a value of @ref DAC_trigger_selection */ | |||
uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled. | |||
This parameter can be a value of @ref DAC_output_buffer */ | |||
}DAC_ChannelConfTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup DAC_Exported_Constants DAC Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup DAC_Error_Code DAC Error Code | |||
* @{ | |||
*/ | |||
#define HAL_DAC_ERROR_NONE 0x00 /*!< No error */ | |||
#define HAL_DAC_ERROR_DMAUNDERRUNCH1 0x01 /*!< DAC channel1 DAM underrun error */ | |||
#define HAL_DAC_ERROR_DMAUNDERRUNCH2 0x02 /*!< DAC channel2 DAM underrun error */ | |||
#define HAL_DAC_ERROR_DMA 0x04 /*!< DMA error */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DAC_trigger_selection DAC Trigger Selection | |||
* @{ | |||
*/ | |||
#define DAC_TRIGGER_NONE ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register | |||
has been loaded, and not by external trigger */ | |||
#define DAC_TRIGGER_T2_TRGO ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TEN1)) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */ | |||
#define DAC_TRIGGER_T4_TRGO ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */ | |||
#define DAC_TRIGGER_T5_TRGO ((uint32_t)(DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM5 TRGO selected as external conversion trigger for DAC channel */ | |||
#define DAC_TRIGGER_T6_TRGO ((uint32_t)DAC_CR_TEN1) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */ | |||
#define DAC_TRIGGER_T7_TRGO ((uint32_t)(DAC_CR_TSEL1_1 | DAC_CR_TEN1)) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */ | |||
#define DAC_TRIGGER_T8_TRGO ((uint32_t)(DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel */ | |||
#define DAC_TRIGGER_EXT_IT9 ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1 | DAC_CR_TEN1)) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */ | |||
#define DAC_TRIGGER_SOFTWARE ((uint32_t)(DAC_CR_TSEL1 | DAC_CR_TEN1)) /*!< Conversion started by software trigger for DAC channel */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DAC_output_buffer DAC Output Buffer | |||
* @{ | |||
*/ | |||
#define DAC_OUTPUTBUFFER_ENABLE ((uint32_t)0x00000000) | |||
#define DAC_OUTPUTBUFFER_DISABLE ((uint32_t)DAC_CR_BOFF1) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DAC_Channel_selection DAC Channel Selection | |||
* @{ | |||
*/ | |||
#define DAC_CHANNEL_1 ((uint32_t)0x00000000) | |||
#define DAC_CHANNEL_2 ((uint32_t)0x00000010) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DAC_data_alignment DAC Data Alignment | |||
* @{ | |||
*/ | |||
#define DAC_ALIGN_12B_R ((uint32_t)0x00000000) | |||
#define DAC_ALIGN_12B_L ((uint32_t)0x00000004) | |||
#define DAC_ALIGN_8B_R ((uint32_t)0x00000008) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DAC_flags_definition DAC Flags Definition | |||
* @{ | |||
*/ | |||
#define DAC_FLAG_DMAUDR1 ((uint32_t)DAC_SR_DMAUDR1) | |||
#define DAC_FLAG_DMAUDR2 ((uint32_t)DAC_SR_DMAUDR2) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DAC_IT_definition DAC IT Definition | |||
* @{ | |||
*/ | |||
#define DAC_IT_DMAUDR1 ((uint32_t)DAC_SR_DMAUDR1) | |||
#define DAC_IT_DMAUDR2 ((uint32_t)DAC_SR_DMAUDR2) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup DAC_Exported_Macros DAC Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset DAC handle state | |||
* @param __HANDLE__: specifies the DAC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DAC_STATE_RESET) | |||
/** @brief Enable the DAC channel | |||
* @param __HANDLE__: specifies the DAC handle. | |||
* @param __DAC_CHANNEL__: specifies the DAC channel | |||
* @retval None | |||
*/ | |||
#define __HAL_DAC_ENABLE(__HANDLE__, __DAC_CHANNEL__) \ | |||
((__HANDLE__)->Instance->CR |= (DAC_CR_EN1 << (__DAC_CHANNEL__))) | |||
/** @brief Disable the DAC channel | |||
* @param __HANDLE__: specifies the DAC handle | |||
* @param __DAC_CHANNEL__: specifies the DAC channel. | |||
* @retval None | |||
*/ | |||
#define __HAL_DAC_DISABLE(__HANDLE__, __DAC_CHANNEL__) \ | |||
((__HANDLE__)->Instance->CR &= ~(DAC_CR_EN1 << (__DAC_CHANNEL__))) | |||
/** @brief Enable the DAC interrupt | |||
* @param __HANDLE__: specifies the DAC handle | |||
* @param __INTERRUPT__: specifies the DAC interrupt. | |||
* @retval None | |||
*/ | |||
#define __HAL_DAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__)) | |||
/** @brief Disable the DAC interrupt | |||
* @param __HANDLE__: specifies the DAC handle | |||
* @param __INTERRUPT__: specifies the DAC interrupt. | |||
* @retval None | |||
*/ | |||
#define __HAL_DAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__)) | |||
/** @brief Checks if the specified DAC interrupt source is enabled or disabled. | |||
* @param __HANDLE__: DAC handle | |||
* @param __INTERRUPT__: DAC interrupt source to check | |||
* This parameter can be any combination of the following values: | |||
* @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt | |||
* @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt | |||
* @retval State of interruption (SET or RESET) | |||
*/ | |||
#define __HAL_DAC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__)) | |||
/** @brief Get the selected DAC's flag status. | |||
* @param __HANDLE__: specifies the DAC handle. | |||
* @param __FLAG__: specifies the flag to clear. | |||
* This parameter can be any combination of the following values: | |||
* @arg DAC_FLAG_DMAUDR1: DMA underrun 1 flag | |||
* @arg DAC_FLAG_DMAUDR2: DMA underrun 2 flag | |||
* @retval None | |||
*/ | |||
#define __HAL_DAC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__)) | |||
/** @brief Clear the DAC's flag. | |||
* @param __HANDLE__: specifies the DAC handle. | |||
* @param __FLAG__: specifies the flag to clear. | |||
* This parameter can be any combination of the following values: | |||
* @arg DAC_FLAG_DMAUDR1: DMA underrun 1 flag | |||
* @arg DAC_FLAG_DMAUDR2: DMA underrun 2 flag | |||
* @retval None | |||
*/ | |||
#define __HAL_DAC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = (__FLAG__)) | |||
/** | |||
* @} | |||
*/ | |||
/* Include DAC HAL Extension module */ | |||
#include "stm32f7xx_hal_dac_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup DAC_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup DAC_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization/de-initialization functions *********************************/ | |||
HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac); | |||
HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac); | |||
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac); | |||
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup DAC_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* I/O operation functions ****************************************************/ | |||
HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel); | |||
HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel); | |||
HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment); | |||
HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel); | |||
uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup DAC_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions ***********************************************/ | |||
HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel); | |||
HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup DAC_Exported_Functions_Group4 | |||
* @{ | |||
*/ | |||
/* Peripheral State functions *************************************************/ | |||
HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac); | |||
void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac); | |||
uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac); | |||
void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac); | |||
void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac); | |||
void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac); | |||
void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup DAC_Private_Constants DAC Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup DAC_Private_Macros DAC Private Macros | |||
* @{ | |||
*/ | |||
#define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0) | |||
#define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_ALIGN_12B_R) || \ | |||
((ALIGN) == DAC_ALIGN_12B_L) || \ | |||
((ALIGN) == DAC_ALIGN_8B_R)) | |||
#define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || \ | |||
((CHANNEL) == DAC_CHANNEL_2)) | |||
#define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OUTPUTBUFFER_ENABLE) || \ | |||
((STATE) == DAC_OUTPUTBUFFER_DISABLE)) | |||
#define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \ | |||
((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \ | |||
((TRIGGER) == DAC_TRIGGER_T8_TRGO) || \ | |||
((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \ | |||
((TRIGGER) == DAC_TRIGGER_T5_TRGO) || \ | |||
((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \ | |||
((TRIGGER) == DAC_TRIGGER_T4_TRGO) || \ | |||
((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \ | |||
((TRIGGER) == DAC_TRIGGER_SOFTWARE)) | |||
/** @brief Set DHR12R1 alignment | |||
* @param __ALIGNMENT__: specifies the DAC alignment | |||
* @retval None | |||
*/ | |||
#define DAC_DHR12R1_ALIGNMENT(__ALIGNMENT__) (((uint32_t)0x00000008) + (__ALIGNMENT__)) | |||
/** @brief Set DHR12R2 alignment | |||
* @param __ALIGNMENT__: specifies the DAC alignment | |||
* @retval None | |||
*/ | |||
#define DAC_DHR12R2_ALIGNMENT(__ALIGNMENT__) (((uint32_t)0x00000014) + (__ALIGNMENT__)) | |||
/** @brief Set DHR12RD alignment | |||
* @param __ALIGNMENT__: specifies the DAC alignment | |||
* @retval None | |||
*/ | |||
#define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__) (((uint32_t)0x00000020) + (__ALIGNMENT__)) | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup DAC_Private_Functions DAC Private Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /*__STM32F7xx_HAL_DAC_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,191 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_dac.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of DAC HAL Extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_DAC_EX_H | |||
#define __STM32F7xx_HAL_DAC_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup DACEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup DACEx_Exported_Constants DAC Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup DACEx_lfsrunmask_triangleamplitude DAC LFS Run Mask Triangle Amplitude | |||
* @{ | |||
*/ | |||
#define DAC_LFSRUNMASK_BIT0 ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS1_0 ((uint32_t)DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS2_0 ((uint32_t)DAC_CR_MAMP1_1) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS3_0 ((uint32_t)DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0)/*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS4_0 ((uint32_t)DAC_CR_MAMP1_2) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS5_0 ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS6_0 ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS7_0 ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS8_0 ((uint32_t)DAC_CR_MAMP1_3) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS9_0 ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS10_0 ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */ | |||
#define DAC_LFSRUNMASK_BITS11_0 ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */ | |||
#define DAC_TRIANGLEAMPLITUDE_1 ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */ | |||
#define DAC_TRIANGLEAMPLITUDE_3 ((uint32_t)DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 3 */ | |||
#define DAC_TRIANGLEAMPLITUDE_7 ((uint32_t)DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 7 */ | |||
#define DAC_TRIANGLEAMPLITUDE_15 ((uint32_t)DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 15 */ | |||
#define DAC_TRIANGLEAMPLITUDE_31 ((uint32_t)DAC_CR_MAMP1_2) /*!< Select max triangle amplitude of 31 */ | |||
#define DAC_TRIANGLEAMPLITUDE_63 ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 63 */ | |||
#define DAC_TRIANGLEAMPLITUDE_127 ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 127 */ | |||
#define DAC_TRIANGLEAMPLITUDE_255 ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 255 */ | |||
#define DAC_TRIANGLEAMPLITUDE_511 ((uint32_t)DAC_CR_MAMP1_3) /*!< Select max triangle amplitude of 511 */ | |||
#define DAC_TRIANGLEAMPLITUDE_1023 ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 1023 */ | |||
#define DAC_TRIANGLEAMPLITUDE_2047 ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 2047 */ | |||
#define DAC_TRIANGLEAMPLITUDE_4095 ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 4095 */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup DACEx_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup DACEx_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Extension features functions ***********************************************/ | |||
uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac); | |||
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude); | |||
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude); | |||
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2); | |||
void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac); | |||
void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac); | |||
void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef* hdac); | |||
void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef* hdac); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup DACEx_Private_Constants DAC Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup DACEx_Private_Macros DAC Private Macros | |||
* @{ | |||
*/ | |||
#define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUNMASK_BIT0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS1_0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS2_0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS3_0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS4_0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS5_0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS6_0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS7_0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS8_0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS9_0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS10_0) || \ | |||
((VALUE) == DAC_LFSRUNMASK_BITS11_0) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_1) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_3) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_7) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_15) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_31) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_63) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_127) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_255) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_511) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_1023) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_2047) || \ | |||
((VALUE) == DAC_TRIANGLEAMPLITUDE_4095)) | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup DACEx_Private_Functions DAC Private Functions | |||
* @{ | |||
*/ | |||
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma); | |||
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma); | |||
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /*__STM32F7xx_HAL_DAC_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,213 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_def.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief This file contains HAL common defines, enumeration, macros and | |||
* structures definitions. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_DEF | |||
#define __STM32F7xx_HAL_DEF | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx.h" | |||
#include "Legacy/stm32_hal_legacy.h" | |||
#include <stdio.h> | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** | |||
* @brief HAL Status structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_OK = 0x00, | |||
HAL_ERROR = 0x01, | |||
HAL_BUSY = 0x02, | |||
HAL_TIMEOUT = 0x03 | |||
} HAL_StatusTypeDef; | |||
/** | |||
* @brief HAL Lock structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_UNLOCKED = 0x00, | |||
HAL_LOCKED = 0x01 | |||
} HAL_LockTypeDef; | |||
/* Exported macro ------------------------------------------------------------*/ | |||
#define HAL_MAX_DELAY 0xFFFFFFFF | |||
#define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != RESET) | |||
#define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == RESET) | |||
#define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ | |||
do{ \ | |||
(__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ | |||
(__DMA_HANDLE__).Parent = (__HANDLE__); \ | |||
} while(0) | |||
#define UNUSED(x) ((void)(x)) | |||
/** @brief Reset the Handle's State field. | |||
* @param __HANDLE__: specifies the Peripheral Handle. | |||
* @note This macro can be used for the following purpose: | |||
* - When the Handle is declared as local variable; before passing it as parameter | |||
* to HAL_PPP_Init() for the first time, it is mandatory to use this macro | |||
* to set to 0 the Handle's "State" field. | |||
* Otherwise, "State" field may have any random value and the first time the function | |||
* HAL_PPP_Init() is called, the low level hardware initialization will be missed | |||
* (i.e. HAL_PPP_MspInit() will not be executed). | |||
* - When there is a need to reconfigure the low level hardware: instead of calling | |||
* HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). | |||
* In this later function, when the Handle's "State" field is set to 0, it will execute the function | |||
* HAL_PPP_MspInit() which will reconfigure the low level hardware. | |||
* @retval None | |||
*/ | |||
#define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0) | |||
#if (USE_RTOS == 1) | |||
/* Reserved for future use */ | |||
#error USE_RTOS should be 0 in the current HAL release | |||
#else | |||
#define __HAL_LOCK(__HANDLE__) \ | |||
do{ \ | |||
if((__HANDLE__)->Lock == HAL_LOCKED) \ | |||
{ \ | |||
return HAL_BUSY; \ | |||
} \ | |||
else \ | |||
{ \ | |||
(__HANDLE__)->Lock = HAL_LOCKED; \ | |||
} \ | |||
}while (0) | |||
#define __HAL_UNLOCK(__HANDLE__) \ | |||
do{ \ | |||
(__HANDLE__)->Lock = HAL_UNLOCKED; \ | |||
}while (0) | |||
#endif /* USE_RTOS */ | |||
#if defined ( __GNUC__ ) | |||
#ifndef __weak | |||
#define __weak __attribute__((weak)) | |||
#endif /* __weak */ | |||
#ifndef __packed | |||
#define __packed __attribute__((__packed__)) | |||
#endif /* __packed */ | |||
#endif /* __GNUC__ */ | |||
/* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ | |||
#if defined (__GNUC__) /* GNU Compiler */ | |||
#ifndef __ALIGN_END | |||
#define __ALIGN_END __attribute__ ((aligned (4))) | |||
#endif /* __ALIGN_END */ | |||
#ifndef __ALIGN_BEGIN | |||
#define __ALIGN_BEGIN | |||
#endif /* __ALIGN_BEGIN */ | |||
#else | |||
#ifndef __ALIGN_END | |||
#define __ALIGN_END | |||
#endif /* __ALIGN_END */ | |||
#ifndef __ALIGN_BEGIN | |||
#if defined (__CC_ARM) /* ARM Compiler */ | |||
#define __ALIGN_BEGIN __align(4) | |||
#elif defined (__ICCARM__) /* IAR Compiler */ | |||
#define __ALIGN_BEGIN | |||
#endif /* __CC_ARM */ | |||
#endif /* __ALIGN_BEGIN */ | |||
#endif /* __GNUC__ */ | |||
/** | |||
* @brief __RAM_FUNC definition | |||
*/ | |||
#if defined ( __CC_ARM ) | |||
/* ARM Compiler | |||
------------ | |||
RAM functions are defined using the toolchain options. | |||
Functions that are executed in RAM should reside in a separate source module. | |||
Using the 'Options for File' dialog you can simply change the 'Code / Const' | |||
area of a module to a memory space in physical RAM. | |||
Available memory areas are declared in the 'Target' tab of the 'Options for Target' | |||
dialog. | |||
*/ | |||
#define __RAM_FUNC HAL_StatusTypeDef | |||
#elif defined ( __ICCARM__ ) | |||
/* ICCARM Compiler | |||
--------------- | |||
RAM functions are defined using a specific toolchain keyword "__ramfunc". | |||
*/ | |||
#define __RAM_FUNC __ramfunc HAL_StatusTypeDef | |||
#elif defined ( __GNUC__ ) | |||
/* GNU Compiler | |||
------------ | |||
RAM functions are defined using a specific toolchain attribute | |||
"__attribute__((section(".RamFunc")))". | |||
*/ | |||
#define __RAM_FUNC HAL_StatusTypeDef __attribute__((section(".RamFunc"))) | |||
#endif | |||
/** | |||
* @brief __NOINLINE definition | |||
*/ | |||
#if defined ( __CC_ARM ) || defined ( __GNUC__ ) | |||
/* ARM & GNUCompiler | |||
---------------- | |||
*/ | |||
#define __NOINLINE __attribute__ ( (noinline) ) | |||
#elif defined ( __ICCARM__ ) | |||
/* ICCARM Compiler | |||
--------------- | |||
*/ | |||
#define __NOINLINE _Pragma("optimize = no_inline") | |||
#endif | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* ___STM32F7xx_HAL_DEF */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,772 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_dma.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of DMA HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_DMA_H | |||
#define __STM32F7xx_HAL_DMA_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup DMA | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup DMA_Exported_Types DMA Exported Types | |||
* @brief DMA Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief DMA Configuration Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Channel; /*!< Specifies the channel used for the specified stream. | |||
This parameter can be a value of @ref DMA_Channel_selection */ | |||
uint32_t Direction; /*!< Specifies if the data will be transferred from memory to peripheral, | |||
from memory to memory or from peripheral to memory. | |||
This parameter can be a value of @ref DMA_Data_transfer_direction */ | |||
uint32_t PeriphInc; /*!< Specifies whether the Peripheral address register should be incremented or not. | |||
This parameter can be a value of @ref DMA_Peripheral_incremented_mode */ | |||
uint32_t MemInc; /*!< Specifies whether the memory address register should be incremented or not. | |||
This parameter can be a value of @ref DMA_Memory_incremented_mode */ | |||
uint32_t PeriphDataAlignment; /*!< Specifies the Peripheral data width. | |||
This parameter can be a value of @ref DMA_Peripheral_data_size */ | |||
uint32_t MemDataAlignment; /*!< Specifies the Memory data width. | |||
This parameter can be a value of @ref DMA_Memory_data_size */ | |||
uint32_t Mode; /*!< Specifies the operation mode of the DMAy Streamx. | |||
This parameter can be a value of @ref DMA_mode | |||
@note The circular buffer mode cannot be used if the memory-to-memory | |||
data transfer is configured on the selected Stream */ | |||
uint32_t Priority; /*!< Specifies the software priority for the DMAy Streamx. | |||
This parameter can be a value of @ref DMA_Priority_level */ | |||
uint32_t FIFOMode; /*!< Specifies if the FIFO mode or Direct mode will be used for the specified stream. | |||
This parameter can be a value of @ref DMA_FIFO_direct_mode | |||
@note The Direct mode (FIFO mode disabled) cannot be used if the | |||
memory-to-memory data transfer is configured on the selected stream */ | |||
uint32_t FIFOThreshold; /*!< Specifies the FIFO threshold level. | |||
This parameter can be a value of @ref DMA_FIFO_threshold_level */ | |||
uint32_t MemBurst; /*!< Specifies the Burst transfer configuration for the memory transfers. | |||
It specifies the amount of data to be transferred in a single non interruptible | |||
transaction. | |||
This parameter can be a value of @ref DMA_Memory_burst | |||
@note The burst mode is possible only if the address Increment mode is enabled. */ | |||
uint32_t PeriphBurst; /*!< Specifies the Burst transfer configuration for the peripheral transfers. | |||
It specifies the amount of data to be transferred in a single non interruptible | |||
transaction. | |||
This parameter can be a value of @ref DMA_Peripheral_burst | |||
@note The burst mode is possible only if the address Increment mode is enabled. */ | |||
}DMA_InitTypeDef; | |||
/** | |||
* @brief HAL DMA State structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_DMA_STATE_RESET = 0x00, /*!< DMA not yet initialized or disabled */ | |||
HAL_DMA_STATE_READY = 0x01, /*!< DMA initialized and ready for use */ | |||
HAL_DMA_STATE_READY_MEM0 = 0x11, /*!< DMA Mem0 process success */ | |||
HAL_DMA_STATE_READY_MEM1 = 0x21, /*!< DMA Mem1 process success */ | |||
HAL_DMA_STATE_READY_HALF_MEM0 = 0x31, /*!< DMA Mem0 Half process success */ | |||
HAL_DMA_STATE_READY_HALF_MEM1 = 0x41, /*!< DMA Mem1 Half process success */ | |||
HAL_DMA_STATE_BUSY = 0x02, /*!< DMA process is ongoing */ | |||
HAL_DMA_STATE_BUSY_MEM0 = 0x12, /*!< DMA Mem0 process is ongoing */ | |||
HAL_DMA_STATE_BUSY_MEM1 = 0x22, /*!< DMA Mem1 process is ongoing */ | |||
HAL_DMA_STATE_TIMEOUT = 0x03, /*!< DMA timeout state */ | |||
HAL_DMA_STATE_ERROR = 0x04, /*!< DMA error state */ | |||
}HAL_DMA_StateTypeDef; | |||
/** | |||
* @brief HAL DMA Error Code structure definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_DMA_FULL_TRANSFER = 0x00, /*!< Full transfer */ | |||
HAL_DMA_HALF_TRANSFER = 0x01, /*!< Half Transfer */ | |||
}HAL_DMA_LevelCompleteTypeDef; | |||
/** | |||
* @brief DMA handle Structure definition | |||
*/ | |||
typedef struct __DMA_HandleTypeDef | |||
{ | |||
DMA_Stream_TypeDef *Instance; /*!< Register base address */ | |||
DMA_InitTypeDef Init; /*!< DMA communication parameters */ | |||
HAL_LockTypeDef Lock; /*!< DMA locking object */ | |||
__IO HAL_DMA_StateTypeDef State; /*!< DMA transfer state */ | |||
void *Parent; /*!< Parent object state */ | |||
void (* XferCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete callback */ | |||
void (* XferHalfCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA Half transfer complete callback */ | |||
void (* XferM1CpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete Memory1 callback */ | |||
void (* XferErrorCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer error callback */ | |||
__IO uint32_t ErrorCode; /*!< DMA Error code */ | |||
}DMA_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup DMA_Exported_Constants DMA Exported Constants | |||
* @brief DMA Exported constants | |||
* @{ | |||
*/ | |||
/** @defgroup DMA_Error_Code DMA Error Code | |||
* @brief DMA Error Code | |||
* @{ | |||
*/ | |||
#define HAL_DMA_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */ | |||
#define HAL_DMA_ERROR_TE ((uint32_t)0x00000001) /*!< Transfer error */ | |||
#define HAL_DMA_ERROR_FE ((uint32_t)0x00000002) /*!< FIFO error */ | |||
#define HAL_DMA_ERROR_DME ((uint32_t)0x00000004) /*!< Direct Mode error */ | |||
#define HAL_DMA_ERROR_TIMEOUT ((uint32_t)0x00000020) /*!< Timeout error */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Channel_selection DMA Channel selection | |||
* @brief DMA channel selection | |||
* @{ | |||
*/ | |||
#define DMA_CHANNEL_0 ((uint32_t)0x00000000) /*!< DMA Channel 0 */ | |||
#define DMA_CHANNEL_1 ((uint32_t)0x02000000) /*!< DMA Channel 1 */ | |||
#define DMA_CHANNEL_2 ((uint32_t)0x04000000) /*!< DMA Channel 2 */ | |||
#define DMA_CHANNEL_3 ((uint32_t)0x06000000) /*!< DMA Channel 3 */ | |||
#define DMA_CHANNEL_4 ((uint32_t)0x08000000) /*!< DMA Channel 4 */ | |||
#define DMA_CHANNEL_5 ((uint32_t)0x0A000000) /*!< DMA Channel 5 */ | |||
#define DMA_CHANNEL_6 ((uint32_t)0x0C000000) /*!< DMA Channel 6 */ | |||
#define DMA_CHANNEL_7 ((uint32_t)0x0E000000) /*!< DMA Channel 7 */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Data_transfer_direction DMA Data transfer direction | |||
* @brief DMA data transfer direction | |||
* @{ | |||
*/ | |||
#define DMA_PERIPH_TO_MEMORY ((uint32_t)0x00000000) /*!< Peripheral to memory direction */ | |||
#define DMA_MEMORY_TO_PERIPH ((uint32_t)DMA_SxCR_DIR_0) /*!< Memory to peripheral direction */ | |||
#define DMA_MEMORY_TO_MEMORY ((uint32_t)DMA_SxCR_DIR_1) /*!< Memory to memory direction */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Peripheral_incremented_mode DMA Peripheral incremented mode | |||
* @brief DMA peripheral incremented mode | |||
* @{ | |||
*/ | |||
#define DMA_PINC_ENABLE ((uint32_t)DMA_SxCR_PINC) /*!< Peripheral increment mode enable */ | |||
#define DMA_PINC_DISABLE ((uint32_t)0x00000000) /*!< Peripheral increment mode disable */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Memory_incremented_mode DMA Memory incremented mode | |||
* @brief DMA memory incremented mode | |||
* @{ | |||
*/ | |||
#define DMA_MINC_ENABLE ((uint32_t)DMA_SxCR_MINC) /*!< Memory increment mode enable */ | |||
#define DMA_MINC_DISABLE ((uint32_t)0x00000000) /*!< Memory increment mode disable */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Peripheral_data_size DMA Peripheral data size | |||
* @brief DMA peripheral data size | |||
* @{ | |||
*/ | |||
#define DMA_PDATAALIGN_BYTE ((uint32_t)0x00000000) /*!< Peripheral data alignment: Byte */ | |||
#define DMA_PDATAALIGN_HALFWORD ((uint32_t)DMA_SxCR_PSIZE_0) /*!< Peripheral data alignment: HalfWord */ | |||
#define DMA_PDATAALIGN_WORD ((uint32_t)DMA_SxCR_PSIZE_1) /*!< Peripheral data alignment: Word */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Memory_data_size DMA Memory data size | |||
* @brief DMA memory data size | |||
* @{ | |||
*/ | |||
#define DMA_MDATAALIGN_BYTE ((uint32_t)0x00000000) /*!< Memory data alignment: Byte */ | |||
#define DMA_MDATAALIGN_HALFWORD ((uint32_t)DMA_SxCR_MSIZE_0) /*!< Memory data alignment: HalfWord */ | |||
#define DMA_MDATAALIGN_WORD ((uint32_t)DMA_SxCR_MSIZE_1) /*!< Memory data alignment: Word */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_mode DMA mode | |||
* @brief DMA mode | |||
* @{ | |||
*/ | |||
#define DMA_NORMAL ((uint32_t)0x00000000) /*!< Normal mode */ | |||
#define DMA_CIRCULAR ((uint32_t)DMA_SxCR_CIRC) /*!< Circular mode */ | |||
#define DMA_PFCTRL ((uint32_t)DMA_SxCR_PFCTRL) /*!< Peripheral flow control mode */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Priority_level DMA Priority level | |||
* @brief DMA priority levels | |||
* @{ | |||
*/ | |||
#define DMA_PRIORITY_LOW ((uint32_t)0x00000000) /*!< Priority level: Low */ | |||
#define DMA_PRIORITY_MEDIUM ((uint32_t)DMA_SxCR_PL_0) /*!< Priority level: Medium */ | |||
#define DMA_PRIORITY_HIGH ((uint32_t)DMA_SxCR_PL_1) /*!< Priority level: High */ | |||
#define DMA_PRIORITY_VERY_HIGH ((uint32_t)DMA_SxCR_PL) /*!< Priority level: Very High */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_FIFO_direct_mode DMA FIFO direct mode | |||
* @brief DMA FIFO direct mode | |||
* @{ | |||
*/ | |||
#define DMA_FIFOMODE_DISABLE ((uint32_t)0x00000000) /*!< FIFO mode disable */ | |||
#define DMA_FIFOMODE_ENABLE ((uint32_t)DMA_SxFCR_DMDIS) /*!< FIFO mode enable */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_FIFO_threshold_level DMA FIFO threshold level | |||
* @brief DMA FIFO level | |||
* @{ | |||
*/ | |||
#define DMA_FIFO_THRESHOLD_1QUARTERFULL ((uint32_t)0x00000000) /*!< FIFO threshold 1 quart full configuration */ | |||
#define DMA_FIFO_THRESHOLD_HALFFULL ((uint32_t)DMA_SxFCR_FTH_0) /*!< FIFO threshold half full configuration */ | |||
#define DMA_FIFO_THRESHOLD_3QUARTERSFULL ((uint32_t)DMA_SxFCR_FTH_1) /*!< FIFO threshold 3 quarts full configuration */ | |||
#define DMA_FIFO_THRESHOLD_FULL ((uint32_t)DMA_SxFCR_FTH) /*!< FIFO threshold full configuration */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Memory_burst DMA Memory burst | |||
* @brief DMA memory burst | |||
* @{ | |||
*/ | |||
#define DMA_MBURST_SINGLE ((uint32_t)0x00000000) | |||
#define DMA_MBURST_INC4 ((uint32_t)DMA_SxCR_MBURST_0) | |||
#define DMA_MBURST_INC8 ((uint32_t)DMA_SxCR_MBURST_1) | |||
#define DMA_MBURST_INC16 ((uint32_t)DMA_SxCR_MBURST) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Peripheral_burst DMA Peripheral burst | |||
* @brief DMA peripheral burst | |||
* @{ | |||
*/ | |||
#define DMA_PBURST_SINGLE ((uint32_t)0x00000000) | |||
#define DMA_PBURST_INC4 ((uint32_t)DMA_SxCR_PBURST_0) | |||
#define DMA_PBURST_INC8 ((uint32_t)DMA_SxCR_PBURST_1) | |||
#define DMA_PBURST_INC16 ((uint32_t)DMA_SxCR_PBURST) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_interrupt_enable_definitions DMA interrupt enable definitions | |||
* @brief DMA interrupts definition | |||
* @{ | |||
*/ | |||
#define DMA_IT_TC ((uint32_t)DMA_SxCR_TCIE) | |||
#define DMA_IT_HT ((uint32_t)DMA_SxCR_HTIE) | |||
#define DMA_IT_TE ((uint32_t)DMA_SxCR_TEIE) | |||
#define DMA_IT_DME ((uint32_t)DMA_SxCR_DMEIE) | |||
#define DMA_IT_FE ((uint32_t)0x00000080) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_flag_definitions DMA flag definitions | |||
* @brief DMA flag definitions | |||
* @{ | |||
*/ | |||
#define DMA_FLAG_FEIF0_4 ((uint32_t)0x00800001) | |||
#define DMA_FLAG_DMEIF0_4 ((uint32_t)0x00800004) | |||
#define DMA_FLAG_TEIF0_4 ((uint32_t)0x00000008) | |||
#define DMA_FLAG_HTIF0_4 ((uint32_t)0x00000010) | |||
#define DMA_FLAG_TCIF0_4 ((uint32_t)0x00000020) | |||
#define DMA_FLAG_FEIF1_5 ((uint32_t)0x00000040) | |||
#define DMA_FLAG_DMEIF1_5 ((uint32_t)0x00000100) | |||
#define DMA_FLAG_TEIF1_5 ((uint32_t)0x00000200) | |||
#define DMA_FLAG_HTIF1_5 ((uint32_t)0x00000400) | |||
#define DMA_FLAG_TCIF1_5 ((uint32_t)0x00000800) | |||
#define DMA_FLAG_FEIF2_6 ((uint32_t)0x00010000) | |||
#define DMA_FLAG_DMEIF2_6 ((uint32_t)0x00040000) | |||
#define DMA_FLAG_TEIF2_6 ((uint32_t)0x00080000) | |||
#define DMA_FLAG_HTIF2_6 ((uint32_t)0x00100000) | |||
#define DMA_FLAG_TCIF2_6 ((uint32_t)0x00200000) | |||
#define DMA_FLAG_FEIF3_7 ((uint32_t)0x00400000) | |||
#define DMA_FLAG_DMEIF3_7 ((uint32_t)0x01000000) | |||
#define DMA_FLAG_TEIF3_7 ((uint32_t)0x02000000) | |||
#define DMA_FLAG_HTIF3_7 ((uint32_t)0x04000000) | |||
#define DMA_FLAG_TCIF3_7 ((uint32_t)0x08000000) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @brief Reset DMA handle state | |||
* @param __HANDLE__: specifies the DMA handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DMA_STATE_RESET) | |||
/** | |||
* @brief Return the current DMA Stream FIFO filled level. | |||
* @param __HANDLE__: DMA handle | |||
* @retval The FIFO filling state. | |||
* - DMA_FIFOStatus_Less1QuarterFull: when FIFO is less than 1 quarter-full | |||
* and not empty. | |||
* - DMA_FIFOStatus_1QuarterFull: if more than 1 quarter-full. | |||
* - DMA_FIFOStatus_HalfFull: if more than 1 half-full. | |||
* - DMA_FIFOStatus_3QuartersFull: if more than 3 quarters-full. | |||
* - DMA_FIFOStatus_Empty: when FIFO is empty | |||
* - DMA_FIFOStatus_Full: when FIFO is full | |||
*/ | |||
#define __HAL_DMA_GET_FS(__HANDLE__) (((__HANDLE__)->Instance->FCR & (DMA_SxFCR_FS))) | |||
/** | |||
* @brief Enable the specified DMA Stream. | |||
* @param __HANDLE__: DMA handle | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= DMA_SxCR_EN) | |||
/** | |||
* @brief Disable the specified DMA Stream. | |||
* @param __HANDLE__: DMA handle | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~DMA_SxCR_EN) | |||
/* Interrupt & Flag management */ | |||
/** | |||
* @brief Return the current DMA Stream transfer complete flag. | |||
* @param __HANDLE__: DMA handle | |||
* @retval The specified transfer complete flag index. | |||
*/ | |||
#define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__) \ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream0))? DMA_FLAG_TCIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream0))? DMA_FLAG_TCIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream4))? DMA_FLAG_TCIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream4))? DMA_FLAG_TCIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream1))? DMA_FLAG_TCIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream1))? DMA_FLAG_TCIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream5))? DMA_FLAG_TCIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream5))? DMA_FLAG_TCIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream2))? DMA_FLAG_TCIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream2))? DMA_FLAG_TCIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream6))? DMA_FLAG_TCIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream6))? DMA_FLAG_TCIF2_6 :\ | |||
DMA_FLAG_TCIF3_7) | |||
/** | |||
* @brief Return the current DMA Stream half transfer complete flag. | |||
* @param __HANDLE__: DMA handle | |||
* @retval The specified half transfer complete flag index. | |||
*/ | |||
#define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream0))? DMA_FLAG_HTIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream0))? DMA_FLAG_HTIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream4))? DMA_FLAG_HTIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream4))? DMA_FLAG_HTIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream1))? DMA_FLAG_HTIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream1))? DMA_FLAG_HTIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream5))? DMA_FLAG_HTIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream5))? DMA_FLAG_HTIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream2))? DMA_FLAG_HTIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream2))? DMA_FLAG_HTIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream6))? DMA_FLAG_HTIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream6))? DMA_FLAG_HTIF2_6 :\ | |||
DMA_FLAG_HTIF3_7) | |||
/** | |||
* @brief Return the current DMA Stream transfer error flag. | |||
* @param __HANDLE__: DMA handle | |||
* @retval The specified transfer error flag index. | |||
*/ | |||
#define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream0))? DMA_FLAG_TEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream0))? DMA_FLAG_TEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream4))? DMA_FLAG_TEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream4))? DMA_FLAG_TEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream1))? DMA_FLAG_TEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream1))? DMA_FLAG_TEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream5))? DMA_FLAG_TEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream5))? DMA_FLAG_TEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream2))? DMA_FLAG_TEIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream2))? DMA_FLAG_TEIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream6))? DMA_FLAG_TEIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream6))? DMA_FLAG_TEIF2_6 :\ | |||
DMA_FLAG_TEIF3_7) | |||
/** | |||
* @brief Return the current DMA Stream FIFO error flag. | |||
* @param __HANDLE__: DMA handle | |||
* @retval The specified FIFO error flag index. | |||
*/ | |||
#define __HAL_DMA_GET_FE_FLAG_INDEX(__HANDLE__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream0))? DMA_FLAG_FEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream0))? DMA_FLAG_FEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream4))? DMA_FLAG_FEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream4))? DMA_FLAG_FEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream1))? DMA_FLAG_FEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream1))? DMA_FLAG_FEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream5))? DMA_FLAG_FEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream5))? DMA_FLAG_FEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream2))? DMA_FLAG_FEIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream2))? DMA_FLAG_FEIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream6))? DMA_FLAG_FEIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream6))? DMA_FLAG_FEIF2_6 :\ | |||
DMA_FLAG_FEIF3_7) | |||
/** | |||
* @brief Return the current DMA Stream direct mode error flag. | |||
* @param __HANDLE__: DMA handle | |||
* @retval The specified direct mode error flag index. | |||
*/ | |||
#define __HAL_DMA_GET_DME_FLAG_INDEX(__HANDLE__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream0))? DMA_FLAG_DMEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream0))? DMA_FLAG_DMEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream4))? DMA_FLAG_DMEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream4))? DMA_FLAG_DMEIF0_4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream1))? DMA_FLAG_DMEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream1))? DMA_FLAG_DMEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream5))? DMA_FLAG_DMEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream5))? DMA_FLAG_DMEIF1_5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream2))? DMA_FLAG_DMEIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream2))? DMA_FLAG_DMEIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Stream6))? DMA_FLAG_DMEIF2_6 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Stream6))? DMA_FLAG_DMEIF2_6 :\ | |||
DMA_FLAG_DMEIF3_7) | |||
/** | |||
* @brief Get the DMA Stream pending flags. | |||
* @param __HANDLE__: DMA handle | |||
* @param __FLAG__: Get the specified flag. | |||
* This parameter can be any combination of the following values: | |||
* @arg DMA_FLAG_TCIFx: Transfer complete flag. | |||
* @arg DMA_FLAG_HTIFx: Half transfer complete flag. | |||
* @arg DMA_FLAG_TEIFx: Transfer error flag. | |||
* @arg DMA_FLAG_DMEIFx: Direct mode error flag. | |||
* @arg DMA_FLAG_FEIFx: FIFO error flag. | |||
* Where x can be 0_4, 1_5, 2_6 or 3_7 to select the DMA Stream flag. | |||
* @retval The state of FLAG (SET or RESET). | |||
*/ | |||
#define __HAL_DMA_GET_FLAG(__HANDLE__, __FLAG__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA2_Stream3)? (DMA2->HISR & (__FLAG__)) :\ | |||
((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA1_Stream7)? (DMA2->LISR & (__FLAG__)) :\ | |||
((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA1_Stream3)? (DMA1->HISR & (__FLAG__)) : (DMA1->LISR & (__FLAG__))) | |||
/** | |||
* @brief Clear the DMA Stream pending flags. | |||
* @param __HANDLE__: DMA handle | |||
* @param __FLAG__: specifies the flag to clear. | |||
* This parameter can be any combination of the following values: | |||
* @arg DMA_FLAG_TCIFx: Transfer complete flag. | |||
* @arg DMA_FLAG_HTIFx: Half transfer complete flag. | |||
* @arg DMA_FLAG_TEIFx: Transfer error flag. | |||
* @arg DMA_FLAG_DMEIFx: Direct mode error flag. | |||
* @arg DMA_FLAG_FEIFx: FIFO error flag. | |||
* Where x can be 0_4, 1_5, 2_6 or 3_7 to select the DMA Stream flag. | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) \ | |||
(((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA2_Stream3)? (DMA2->HIFCR = (__FLAG__)) :\ | |||
((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA1_Stream7)? (DMA2->LIFCR = (__FLAG__)) :\ | |||
((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA1_Stream3)? (DMA1->HIFCR = (__FLAG__)) : (DMA1->LIFCR = (__FLAG__))) | |||
/** | |||
* @brief Enable the specified DMA Stream interrupts. | |||
* @param __HANDLE__: DMA handle | |||
* @param __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled. | |||
* This parameter can be any combination of the following values: | |||
* @arg DMA_IT_TC: Transfer complete interrupt mask. | |||
* @arg DMA_IT_HT: Half transfer complete interrupt mask. | |||
* @arg DMA_IT_TE: Transfer error interrupt mask. | |||
* @arg DMA_IT_FE: FIFO error interrupt mask. | |||
* @arg DMA_IT_DME: Direct mode error interrupt. | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__INTERRUPT__) != DMA_IT_FE)? \ | |||
((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) : ((__HANDLE__)->Instance->FCR |= (__INTERRUPT__))) | |||
/** | |||
* @brief Disable the specified DMA Stream interrupts. | |||
* @param __HANDLE__: DMA handle | |||
* @param __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled. | |||
* This parameter can be any combination of the following values: | |||
* @arg DMA_IT_TC: Transfer complete interrupt mask. | |||
* @arg DMA_IT_HT: Half transfer complete interrupt mask. | |||
* @arg DMA_IT_TE: Transfer error interrupt mask. | |||
* @arg DMA_IT_FE: FIFO error interrupt mask. | |||
* @arg DMA_IT_DME: Direct mode error interrupt. | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__INTERRUPT__) != DMA_IT_FE)? \ | |||
((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) : ((__HANDLE__)->Instance->FCR &= ~(__INTERRUPT__))) | |||
/** | |||
* @brief Check whether the specified DMA Stream interrupt is enabled or not. | |||
* @param __HANDLE__: DMA handle | |||
* @param __INTERRUPT__: specifies the DMA interrupt source to check. | |||
* This parameter can be one of the following values: | |||
* @arg DMA_IT_TC: Transfer complete interrupt mask. | |||
* @arg DMA_IT_HT: Half transfer complete interrupt mask. | |||
* @arg DMA_IT_TE: Transfer error interrupt mask. | |||
* @arg DMA_IT_FE: FIFO error interrupt mask. | |||
* @arg DMA_IT_DME: Direct mode error interrupt. | |||
* @retval The state of DMA_IT. | |||
*/ | |||
#define __HAL_DMA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__INTERRUPT__) != DMA_IT_FE)? \ | |||
((__HANDLE__)->Instance->CR & (__INTERRUPT__)) : \ | |||
((__HANDLE__)->Instance->FCR & (__INTERRUPT__))) | |||
/** | |||
* @brief Writes the number of data units to be transferred on the DMA Stream. | |||
* @param __HANDLE__: DMA handle | |||
* @param __COUNTER__: Number of data units to be transferred (from 0 to 65535) | |||
* Number of data items depends only on the Peripheral data format. | |||
* | |||
* @note If Peripheral data format is Bytes: number of data units is equal | |||
* to total number of bytes to be transferred. | |||
* | |||
* @note If Peripheral data format is Half-Word: number of data units is | |||
* equal to total number of bytes to be transferred / 2. | |||
* | |||
* @note If Peripheral data format is Word: number of data units is equal | |||
* to total number of bytes to be transferred / 4. | |||
* | |||
* @retval The number of remaining data units in the current DMAy Streamx transfer. | |||
*/ | |||
#define __HAL_DMA_SET_COUNTER(__HANDLE__, __COUNTER__) ((__HANDLE__)->Instance->NDTR = (uint16_t)(__COUNTER__)) | |||
/** | |||
* @brief Returns the number of remaining data units in the current DMAy Streamx transfer. | |||
* @param __HANDLE__: DMA handle | |||
* | |||
* @retval The number of remaining data units in the current DMA Stream transfer. | |||
*/ | |||
#define __HAL_DMA_GET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->NDTR) | |||
/* Include DMA HAL Extension module */ | |||
#include "stm32f7xx_hal_dma_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup DMA_Exported_Functions DMA Exported Functions | |||
* @brief DMA Exported functions | |||
* @{ | |||
*/ | |||
/** @defgroup DMA_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @brief Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma); | |||
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Exported_Functions_Group2 I/O operation functions | |||
* @brief I/O operation functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_DMA_Start (DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); | |||
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); | |||
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma); | |||
HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout); | |||
void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Exported_Functions_Group3 Peripheral State functions | |||
* @brief Peripheral State functions | |||
* @{ | |||
*/ | |||
HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma); | |||
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private Constants -------------------------------------------------------------*/ | |||
/** @defgroup DMA_Private_Constants DMA Private Constants | |||
* @brief DMA private defines and constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup DMA_Private_Macros DMA Private Macros | |||
* @brief DMA private macros | |||
* @{ | |||
*/ | |||
#define IS_DMA_CHANNEL(CHANNEL) (((CHANNEL) == DMA_CHANNEL_0) || \ | |||
((CHANNEL) == DMA_CHANNEL_1) || \ | |||
((CHANNEL) == DMA_CHANNEL_2) || \ | |||
((CHANNEL) == DMA_CHANNEL_3) || \ | |||
((CHANNEL) == DMA_CHANNEL_4) || \ | |||
((CHANNEL) == DMA_CHANNEL_5) || \ | |||
((CHANNEL) == DMA_CHANNEL_6) || \ | |||
((CHANNEL) == DMA_CHANNEL_7)) | |||
#define IS_DMA_DIRECTION(DIRECTION) (((DIRECTION) == DMA_PERIPH_TO_MEMORY ) || \ | |||
((DIRECTION) == DMA_MEMORY_TO_PERIPH) || \ | |||
((DIRECTION) == DMA_MEMORY_TO_MEMORY)) | |||
#define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1) && ((SIZE) < 0x10000)) | |||
#define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PINC_ENABLE) || \ | |||
((STATE) == DMA_PINC_DISABLE)) | |||
#define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MINC_ENABLE) || \ | |||
((STATE) == DMA_MINC_DISABLE)) | |||
#define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PDATAALIGN_BYTE) || \ | |||
((SIZE) == DMA_PDATAALIGN_HALFWORD) || \ | |||
((SIZE) == DMA_PDATAALIGN_WORD)) | |||
#define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MDATAALIGN_BYTE) || \ | |||
((SIZE) == DMA_MDATAALIGN_HALFWORD) || \ | |||
((SIZE) == DMA_MDATAALIGN_WORD )) | |||
#define IS_DMA_MODE(MODE) (((MODE) == DMA_NORMAL ) || \ | |||
((MODE) == DMA_CIRCULAR) || \ | |||
((MODE) == DMA_PFCTRL)) | |||
#define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_PRIORITY_LOW ) || \ | |||
((PRIORITY) == DMA_PRIORITY_MEDIUM) || \ | |||
((PRIORITY) == DMA_PRIORITY_HIGH) || \ | |||
((PRIORITY) == DMA_PRIORITY_VERY_HIGH)) | |||
#define IS_DMA_FIFO_MODE_STATE(STATE) (((STATE) == DMA_FIFOMODE_DISABLE ) || \ | |||
((STATE) == DMA_FIFOMODE_ENABLE)) | |||
#define IS_DMA_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == DMA_FIFO_THRESHOLD_1QUARTERFULL ) || \ | |||
((THRESHOLD) == DMA_FIFO_THRESHOLD_HALFFULL) || \ | |||
((THRESHOLD) == DMA_FIFO_THRESHOLD_3QUARTERSFULL) || \ | |||
((THRESHOLD) == DMA_FIFO_THRESHOLD_FULL)) | |||
#define IS_DMA_MEMORY_BURST(BURST) (((BURST) == DMA_MBURST_SINGLE) || \ | |||
((BURST) == DMA_MBURST_INC4) || \ | |||
((BURST) == DMA_MBURST_INC8) || \ | |||
((BURST) == DMA_MBURST_INC16)) | |||
#define IS_DMA_PERIPHERAL_BURST(BURST) (((BURST) == DMA_PBURST_SINGLE) || \ | |||
((BURST) == DMA_PBURST_INC4) || \ | |||
((BURST) == DMA_PBURST_INC8) || \ | |||
((BURST) == DMA_PBURST_INC16)) | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup DMA_Private_Functions DMA Private Functions | |||
* @brief DMA private functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_DMA_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,123 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_dma_ex.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of DMA HAL extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_DMA_EX_H | |||
#define __STM32F7xx_HAL_DMA_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup DMAEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup DMAEx_Exported_Types DMAEx Exported Types | |||
* @brief DMAEx Exported types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief HAL DMA Memory definition | |||
*/ | |||
typedef enum | |||
{ | |||
MEMORY0 = 0x00, /*!< Memory 0 */ | |||
MEMORY1 = 0x01, /*!< Memory 1 */ | |||
}HAL_DMA_MemoryTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions | |||
* @brief DMAEx Exported functions | |||
* @{ | |||
*/ | |||
/** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions | |||
* @brief Extended features functions | |||
* @{ | |||
*/ | |||
/* IO operation functions *******************************************************/ | |||
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); | |||
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); | |||
HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup DMAEx_Private_Functions DMAEx Private Functions | |||
* @brief DMAEx Private functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_DMA_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,396 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_flash.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of FLASH HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_FLASH_H | |||
#define __STM32F7xx_HAL_FLASH_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASH | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup FLASH_Exported_Types FLASH Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief FLASH Procedure structure definition | |||
*/ | |||
typedef enum | |||
{ | |||
FLASH_PROC_NONE = 0, | |||
FLASH_PROC_SECTERASE, | |||
FLASH_PROC_MASSERASE, | |||
FLASH_PROC_PROGRAM | |||
} FLASH_ProcedureTypeDef; | |||
/** | |||
* @brief FLASH handle Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
__IO FLASH_ProcedureTypeDef ProcedureOnGoing; /* Internal variable to indicate which procedure is ongoing or not in IT context */ | |||
__IO uint32_t NbSectorsToErase; /* Internal variable to save the remaining sectors to erase in IT context */ | |||
__IO uint8_t VoltageForErase; /* Internal variable to provide voltage range selected by user in IT context */ | |||
__IO uint32_t Sector; /* Internal variable to define the current sector which is erasing */ | |||
__IO uint32_t Address; /* Internal variable to save address selected for program */ | |||
HAL_LockTypeDef Lock; /* FLASH locking object */ | |||
__IO uint32_t ErrorCode; /* FLASH error code */ | |||
}FLASH_ProcessTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup FLASH_Exported_Constants FLASH Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup FLASH_Error_Code FLASH Error Code | |||
* @brief FLASH Error Code | |||
* @{ | |||
*/ | |||
#define HAL_FLASH_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */ | |||
#define HAL_FLASH_ERROR_ERS ((uint32_t)0x00000002) /*!< Programming Sequence error */ | |||
#define HAL_FLASH_ERROR_PGP ((uint32_t)0x00000004) /*!< Programming Parallelism error */ | |||
#define HAL_FLASH_ERROR_PGA ((uint32_t)0x00000008) /*!< Programming Alignment error */ | |||
#define HAL_FLASH_ERROR_WRP ((uint32_t)0x00000010) /*!< Write protection error */ | |||
#define HAL_FLASH_ERROR_OPERATION ((uint32_t)0x00000020) /*!< Operation Error */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Type_Program FLASH Type Program | |||
* @{ | |||
*/ | |||
#define FLASH_TYPEPROGRAM_BYTE ((uint32_t)0x00) /*!< Program byte (8-bit) at a specified address */ | |||
#define FLASH_TYPEPROGRAM_HALFWORD ((uint32_t)0x01) /*!< Program a half-word (16-bit) at a specified address */ | |||
#define FLASH_TYPEPROGRAM_WORD ((uint32_t)0x02) /*!< Program a word (32-bit) at a specified address */ | |||
#define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03) /*!< Program a double word (64-bit) at a specified address */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Flag_definition FLASH Flag definition | |||
* @brief Flag definition | |||
* @{ | |||
*/ | |||
#define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */ | |||
#define FLASH_FLAG_OPERR FLASH_SR_OPERR /*!< FLASH operation Error flag */ | |||
#define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */ | |||
#define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */ | |||
#define FLASH_FLAG_PGPERR FLASH_SR_PGPERR /*!< FLASH Programming Parallelism error flag */ | |||
#define FLASH_FLAG_ERSERR FLASH_SR_ERSERR /*!< FLASH Erasing Sequence error flag */ | |||
#define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition | |||
* @brief FLASH Interrupt definition | |||
* @{ | |||
*/ | |||
#define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */ | |||
#define FLASH_IT_ERR ((uint32_t)0x02000000) /*!< Error Interrupt source */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism | |||
* @{ | |||
*/ | |||
#define FLASH_PSIZE_BYTE ((uint32_t)0x00000000) | |||
#define FLASH_PSIZE_HALF_WORD ((uint32_t)FLASH_CR_PSIZE_0) | |||
#define FLASH_PSIZE_WORD ((uint32_t)FLASH_CR_PSIZE_1) | |||
#define FLASH_PSIZE_DOUBLE_WORD ((uint32_t)FLASH_CR_PSIZE) | |||
#define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Keys FLASH Keys | |||
* @{ | |||
*/ | |||
#define FLASH_KEY1 ((uint32_t)0x45670123) | |||
#define FLASH_KEY2 ((uint32_t)0xCDEF89AB) | |||
#define FLASH_OPT_KEY1 ((uint32_t)0x08192A3B) | |||
#define FLASH_OPT_KEY2 ((uint32_t)0x4C5D6E7F) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup FLASH_Exported_Macros FLASH Exported Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Set the FLASH Latency. | |||
* @param __LATENCY__: FLASH Latency | |||
* The value of this parameter depend on device used within the same series | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_SET_LATENCY(__LATENCY__) \ | |||
MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(__LATENCY__)) | |||
/** | |||
* @brief Get the FLASH Latency. | |||
* @retval FLASH Latency | |||
* The value of this parameter depend on device used within the same series | |||
*/ | |||
#define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)) | |||
/** | |||
* @brief Enable the FLASH prefetch buffer. | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTEN) | |||
/** | |||
* @brief Disable the FLASH prefetch buffer. | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTEN)) | |||
/** | |||
* @brief Enable the FLASH Adaptive Real-Time memory accelerator. | |||
* @note The ART accelerator is available only for flash access on ITCM interface. | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_ART_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_ARTEN) | |||
/** | |||
* @brief Disable the FLASH Adaptive Real-Time memory accelerator. | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_ART_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_ARTEN) | |||
/** | |||
* @brief Resets the FLASH Adaptive Real-Time memory accelerator. | |||
* @note This function must be used only when the Adaptive Real-Time memory accelerator | |||
* is disabled. | |||
* @retval None | |||
*/ | |||
#define __HAL_FLASH_ART_RESET() (FLASH->ACR |= FLASH_ACR_ARTRST) | |||
/** | |||
* @brief Enable the specified FLASH interrupt. | |||
* @param __INTERRUPT__ : FLASH interrupt | |||
* This parameter can be any combination of the following values: | |||
* @arg FLASH_IT_EOP: End of FLASH Operation Interrupt | |||
* @arg FLASH_IT_ERR: Error Interrupt | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__)) | |||
/** | |||
* @brief Disable the specified FLASH interrupt. | |||
* @param __INTERRUPT__ : FLASH interrupt | |||
* This parameter can be any combination of the following values: | |||
* @arg FLASH_IT_EOP: End of FLASH Operation Interrupt | |||
* @arg FLASH_IT_ERR: Error Interrupt | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(uint32_t)(__INTERRUPT__)) | |||
/** | |||
* @brief Get the specified FLASH flag status. | |||
* @param __FLAG__: specifies the FLASH flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg FLASH_FLAG_EOP : FLASH End of Operation flag | |||
* @arg FLASH_FLAG_OPERR : FLASH operation Error flag | |||
* @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag | |||
* @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag | |||
* @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag | |||
* @arg FLASH_FLAG_ERSERR : FLASH Erasing Sequence error flag | |||
* @arg FLASH_FLAG_BSY : FLASH Busy flag | |||
* @retval The new state of __FLAG__ (SET or RESET). | |||
*/ | |||
#define __HAL_FLASH_GET_FLAG(__FLAG__) ((FLASH->SR & (__FLAG__))) | |||
/** | |||
* @brief Clear the specified FLASH flag. | |||
* @param __FLAG__: specifies the FLASH flags to clear. | |||
* This parameter can be any combination of the following values: | |||
* @arg FLASH_FLAG_EOP : FLASH End of Operation flag | |||
* @arg FLASH_FLAG_OPERR : FLASH operation Error flag | |||
* @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag | |||
* @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag | |||
* @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag | |||
* @arg FLASH_FLAG_ERSERR : FLASH Erasing Sequence error flag | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (FLASH->SR = (__FLAG__)) | |||
/** | |||
* @} | |||
*/ | |||
/* Include FLASH HAL Extension module */ | |||
#include "stm32f7xx_hal_flash_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup FLASH_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASH_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Program operation functions ***********************************************/ | |||
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data); | |||
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data); | |||
/* FLASH IRQ handler method */ | |||
void HAL_FLASH_IRQHandler(void); | |||
/* Callbacks in non blocking modes */ | |||
void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue); | |||
void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASH_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions **********************************************/ | |||
HAL_StatusTypeDef HAL_FLASH_Unlock(void); | |||
HAL_StatusTypeDef HAL_FLASH_Lock(void); | |||
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void); | |||
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void); | |||
/* Option bytes control */ | |||
HAL_StatusTypeDef HAL_FLASH_OB_Launch(void); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASH_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
/* Peripheral State functions ************************************************/ | |||
uint32_t HAL_FLASH_GetError(void); | |||
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/** @defgroup FLASH_Private_Variables FLASH Private Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup FLASH_Private_Constants FLASH Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup FLASH_Private_Macros FLASH Private Macros | |||
* @{ | |||
*/ | |||
/** @defgroup FLASH_IS_FLASH_Definitions FLASH Private macros to check input parameters | |||
* @{ | |||
*/ | |||
#define IS_FLASH_TYPEPROGRAM(VALUE)(((VALUE) == FLASH_TYPEPROGRAM_BYTE) || \ | |||
((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \ | |||
((VALUE) == FLASH_TYPEPROGRAM_WORD) || \ | |||
((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup FLASH_Private_Functions FLASH Private Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_FLASH_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,468 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_flash_ex.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of FLASH HAL Extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_FLASH_EX_H | |||
#define __STM32F7xx_HAL_FLASH_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASHEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup FLASHEx_Exported_Types FLASH Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief FLASH Erase structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t TypeErase; /*!< Mass erase or sector Erase. | |||
This parameter can be a value of @ref FLASHEx_Type_Erase */ | |||
uint32_t Sector; /*!< Initial FLASH sector to erase when Mass erase is disabled | |||
This parameter must be a value of @ref FLASHEx_Sectors */ | |||
uint32_t NbSectors; /*!< Number of sectors to be erased. | |||
This parameter must be a value between 1 and (max number of sectors - value of Initial sector)*/ | |||
uint32_t VoltageRange;/*!< The device voltage range which defines the erase parallelism | |||
This parameter must be a value of @ref FLASHEx_Voltage_Range */ | |||
} FLASH_EraseInitTypeDef; | |||
/** | |||
* @brief FLASH Option Bytes Program structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t OptionType; /*!< Option byte to be configured. | |||
This parameter can be a value of @ref FLASHEx_Option_Type */ | |||
uint32_t WRPState; /*!< Write protection activation or deactivation. | |||
This parameter can be a value of @ref FLASHEx_WRP_State */ | |||
uint32_t WRPSector; /*!< Specifies the sector(s) to be write protected. | |||
The value of this parameter depend on device used within the same series */ | |||
uint32_t RDPLevel; /*!< Set the read protection level. | |||
This parameter can be a value of @ref FLASHEx_Option_Bytes_Read_Protection */ | |||
uint32_t BORLevel; /*!< Set the BOR Level. | |||
This parameter can be a value of @ref FLASHEx_BOR_Reset_Level */ | |||
uint32_t USERConfig; /*!< Program the FLASH User Option Byte: WWDG_SW / IWDG_SW / RST_STOP / RST_STDBY / | |||
IWDG_FREEZE_STOP / IWDG_FREEZE_SANDBY. */ | |||
uint32_t BootAddr0; /*!< Boot base address when Boot pin = 0. | |||
This parameter can be a value of @ref FLASHEx_Boot_Address */ | |||
uint32_t BootAddr1; /*!< Boot base address when Boot pin = 1. | |||
This parameter can be a value of @ref FLASHEx_Boot_Address */ | |||
} FLASH_OBProgramInitTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup FLASHEx_Exported_Constants FLASH Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup FLASHEx_Type_Erase FLASH Type Erase | |||
* @{ | |||
*/ | |||
#define FLASH_TYPEERASE_SECTORS ((uint32_t)0x00) /*!< Sectors erase only */ | |||
#define FLASH_TYPEERASE_MASSERASE ((uint32_t)0x01) /*!< Flash Mass erase activation */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Voltage_Range FLASH Voltage Range | |||
* @{ | |||
*/ | |||
#define FLASH_VOLTAGE_RANGE_1 ((uint32_t)0x00) /*!< Device operating range: 1.8V to 2.1V */ | |||
#define FLASH_VOLTAGE_RANGE_2 ((uint32_t)0x01) /*!< Device operating range: 2.1V to 2.7V */ | |||
#define FLASH_VOLTAGE_RANGE_3 ((uint32_t)0x02) /*!< Device operating range: 2.7V to 3.6V */ | |||
#define FLASH_VOLTAGE_RANGE_4 ((uint32_t)0x03) /*!< Device operating range: 2.7V to 3.6V + External Vpp */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_WRP_State FLASH WRP State | |||
* @{ | |||
*/ | |||
#define OB_WRPSTATE_DISABLE ((uint32_t)0x00) /*!< Disable the write protection of the desired bank 1 sectors */ | |||
#define OB_WRPSTATE_ENABLE ((uint32_t)0x01) /*!< Enable the write protection of the desired bank 1 sectors */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Type FLASH Option Type | |||
* @{ | |||
*/ | |||
#define OPTIONBYTE_WRP ((uint32_t)0x01) /*!< WRP option byte configuration */ | |||
#define OPTIONBYTE_RDP ((uint32_t)0x02) /*!< RDP option byte configuration */ | |||
#define OPTIONBYTE_USER ((uint32_t)0x04) /*!< USER option byte configuration */ | |||
#define OPTIONBYTE_BOR ((uint32_t)0x08) /*!< BOR option byte configuration */ | |||
#define OPTIONBYTE_BOOTADDR_0 ((uint32_t)0x10) /*!< Boot 0 Address configuration */ | |||
#define OPTIONBYTE_BOOTADDR_1 ((uint32_t)0x20) /*!< Boot 1 Address configuration */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_Read_Protection FLASH Option Bytes Read Protection | |||
* @{ | |||
*/ | |||
#define OB_RDP_LEVEL_0 ((uint8_t)0xAA) | |||
#define OB_RDP_LEVEL_1 ((uint8_t)0x55) | |||
#define OB_RDP_LEVEL_2 ((uint8_t)0xCC) /*!< Warning: When enabling read protection level 2 | |||
it s no more possible to go back to level 1 or 0 */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_WWatchdog FLASH Option Bytes WWatchdog | |||
* @{ | |||
*/ | |||
#define OB_WWDG_SW ((uint32_t)0x10) /*!< Software WWDG selected */ | |||
#define OB_WWDG_HW ((uint32_t)0x00) /*!< Hardware WWDG selected */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_IWatchdog FLASH Option Bytes IWatchdog | |||
* @{ | |||
*/ | |||
#define OB_IWDG_SW ((uint32_t)0x20) /*!< Software IWDG selected */ | |||
#define OB_IWDG_HW ((uint32_t)0x00) /*!< Hardware IWDG selected */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_nRST_STOP FLASH Option Bytes nRST_STOP | |||
* @{ | |||
*/ | |||
#define OB_STOP_NO_RST ((uint32_t)0x40) /*!< No reset generated when entering in STOP */ | |||
#define OB_STOP_RST ((uint32_t)0x00) /*!< Reset generated when entering in STOP */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_nRST_STDBY FLASH Option Bytes nRST_STDBY | |||
* @{ | |||
*/ | |||
#define OB_STDBY_NO_RST ((uint32_t)0x80) /*!< No reset generated when entering in STANDBY */ | |||
#define OB_STDBY_RST ((uint32_t)0x00) /*!< Reset generated when entering in STANDBY */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_IWDG_FREEZE_STOP FLASH IWDG Counter Freeze in STOP | |||
* @{ | |||
*/ | |||
#define OB_IWDG_STOP_FREEZE ((uint32_t)0x00000000) /*!< Freeze IWDG counter in STOP mode */ | |||
#define OB_IWDG_STOP_ACTIVE ((uint32_t)0x40000000) /*!< IWDG counter active in STOP mode */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_IWDG_FREEZE_SANDBY FLASH IWDG Counter Freeze in STANDBY | |||
* @{ | |||
*/ | |||
#define OB_IWDG_STDBY_FREEZE ((uint32_t)0x00000000) /*!< Freeze IWDG counter in STANDBY mode */ | |||
#define OB_IWDG_STDBY_ACTIVE ((uint32_t)0x40000000) /*!< IWDG counter active in STANDBY mode */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_BOR_Reset_Level FLASH BOR Reset Level | |||
* @{ | |||
*/ | |||
#define OB_BOR_LEVEL3 ((uint32_t)0x00) /*!< Supply voltage ranges from 2.70 to 3.60 V */ | |||
#define OB_BOR_LEVEL2 ((uint32_t)0x04) /*!< Supply voltage ranges from 2.40 to 2.70 V */ | |||
#define OB_BOR_LEVEL1 ((uint32_t)0x08) /*!< Supply voltage ranges from 2.10 to 2.40 V */ | |||
#define OB_BOR_OFF ((uint32_t)0x0C) /*!< Supply voltage ranges from 1.62 to 2.10 V */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Boot_Address FLASH Boot Address | |||
* @{ | |||
*/ | |||
#define OB_BOOTADDR_ITCM_RAM ((uint32_t)0x0000) /*!< Boot from ITCM RAM (0x00000000) */ | |||
#define OB_BOOTADDR_SYSTEM ((uint32_t)0x0040) /*!< Boot from System memory bootloader (0x00100000) */ | |||
#define OB_BOOTADDR_ITCM_FLASH ((uint32_t)0x0080) /*!< Boot from Flash on ITCM interface (0x00200000) */ | |||
#define OB_BOOTADDR_AXIM_FLASH ((uint32_t)0x2000) /*!< Boot from Flash on AXIM interface (0x08000000) */ | |||
#define OB_BOOTADDR_DTCM_RAM ((uint32_t)0x8000) /*!< Boot from DTCM RAM (0x20000000) */ | |||
#define OB_BOOTADDR_SRAM1 ((uint32_t)0x8004) /*!< Boot from SRAM1 (0x20010000) */ | |||
#define OB_BOOTADDR_SRAM2 ((uint32_t)0x8013) /*!< Boot from SRAM2 (0x2004C000) */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Latency FLASH Latency | |||
* @{ | |||
*/ | |||
#define FLASH_LATENCY_0 FLASH_ACR_LATENCY_0WS /*!< FLASH Zero Latency cycle */ | |||
#define FLASH_LATENCY_1 FLASH_ACR_LATENCY_1WS /*!< FLASH One Latency cycle */ | |||
#define FLASH_LATENCY_2 FLASH_ACR_LATENCY_2WS /*!< FLASH Two Latency cycles */ | |||
#define FLASH_LATENCY_3 FLASH_ACR_LATENCY_3WS /*!< FLASH Three Latency cycles */ | |||
#define FLASH_LATENCY_4 FLASH_ACR_LATENCY_4WS /*!< FLASH Four Latency cycles */ | |||
#define FLASH_LATENCY_5 FLASH_ACR_LATENCY_5WS /*!< FLASH Five Latency cycles */ | |||
#define FLASH_LATENCY_6 FLASH_ACR_LATENCY_6WS /*!< FLASH Six Latency cycles */ | |||
#define FLASH_LATENCY_7 FLASH_ACR_LATENCY_7WS /*!< FLASH Seven Latency cycles */ | |||
#define FLASH_LATENCY_8 FLASH_ACR_LATENCY_8WS /*!< FLASH Eight Latency cycles */ | |||
#define FLASH_LATENCY_9 FLASH_ACR_LATENCY_9WS /*!< FLASH Nine Latency cycles */ | |||
#define FLASH_LATENCY_10 FLASH_ACR_LATENCY_10WS /*!< FLASH Ten Latency cycles */ | |||
#define FLASH_LATENCY_11 FLASH_ACR_LATENCY_11WS /*!< FLASH Eleven Latency cycles */ | |||
#define FLASH_LATENCY_12 FLASH_ACR_LATENCY_12WS /*!< FLASH Twelve Latency cycles */ | |||
#define FLASH_LATENCY_13 FLASH_ACR_LATENCY_13WS /*!< FLASH Thirteen Latency cycles */ | |||
#define FLASH_LATENCY_14 FLASH_ACR_LATENCY_14WS /*!< FLASH Fourteen Latency cycles */ | |||
#define FLASH_LATENCY_15 FLASH_ACR_LATENCY_15WS /*!< FLASH Fifteen Latency cycles */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_MassErase_bit FLASH Mass Erase bit | |||
* @{ | |||
*/ | |||
#define FLASH_MER_BIT (FLASH_CR_MER) /*!< MER bit to clear */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Sectors FLASH Sectors | |||
* @{ | |||
*/ | |||
#define FLASH_SECTOR_0 ((uint32_t)0) /*!< Sector Number 0 */ | |||
#define FLASH_SECTOR_1 ((uint32_t)1) /*!< Sector Number 1 */ | |||
#define FLASH_SECTOR_2 ((uint32_t)2) /*!< Sector Number 2 */ | |||
#define FLASH_SECTOR_3 ((uint32_t)3) /*!< Sector Number 3 */ | |||
#define FLASH_SECTOR_4 ((uint32_t)4) /*!< Sector Number 4 */ | |||
#define FLASH_SECTOR_5 ((uint32_t)5) /*!< Sector Number 5 */ | |||
#define FLASH_SECTOR_6 ((uint32_t)6) /*!< Sector Number 6 */ | |||
#define FLASH_SECTOR_7 ((uint32_t)7) /*!< Sector Number 7 */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASH Option Bytes Write Protection | |||
* @{ | |||
*/ | |||
#define OB_WRP_SECTOR_0 ((uint32_t)0x00010000) /*!< Write protection of Sector0 */ | |||
#define OB_WRP_SECTOR_1 ((uint32_t)0x00020000) /*!< Write protection of Sector1 */ | |||
#define OB_WRP_SECTOR_2 ((uint32_t)0x00040000) /*!< Write protection of Sector2 */ | |||
#define OB_WRP_SECTOR_3 ((uint32_t)0x00080000) /*!< Write protection of Sector3 */ | |||
#define OB_WRP_SECTOR_4 ((uint32_t)0x00100000) /*!< Write protection of Sector4 */ | |||
#define OB_WRP_SECTOR_5 ((uint32_t)0x00200000) /*!< Write protection of Sector5 */ | |||
#define OB_WRP_SECTOR_6 ((uint32_t)0x00400000) /*!< Write protection of Sector6 */ | |||
#define OB_WRP_SECTOR_7 ((uint32_t)0x00800000) /*!< Write protection of Sector7 */ | |||
#define OB_WRP_SECTOR_All ((uint32_t)0x00FF0000) /*!< Write protection of all Sectors */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup FLASHEx_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASHEx_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Extension Program operation functions *************************************/ | |||
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError); | |||
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit); | |||
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit); | |||
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup FLASHEx_Private_Constants FLASH Private Constants | |||
* @{ | |||
*/ | |||
#define FLASH_SECTOR_TOTAL 8 | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup FLASHEx_Private_Macros FLASH Private Macros | |||
* @{ | |||
*/ | |||
/** @defgroup FLASHEx_IS_FLASH_Definitions FLASH Private macros to check input parameters | |||
* @{ | |||
*/ | |||
#define IS_FLASH_TYPEERASE(VALUE)(((VALUE) == FLASH_TYPEERASE_SECTORS) || \ | |||
((VALUE) == FLASH_TYPEERASE_MASSERASE)) | |||
#define IS_VOLTAGERANGE(RANGE)(((RANGE) == FLASH_VOLTAGE_RANGE_1) || \ | |||
((RANGE) == FLASH_VOLTAGE_RANGE_2) || \ | |||
((RANGE) == FLASH_VOLTAGE_RANGE_3) || \ | |||
((RANGE) == FLASH_VOLTAGE_RANGE_4)) | |||
#define IS_WRPSTATE(VALUE)(((VALUE) == OB_WRPSTATE_DISABLE) || \ | |||
((VALUE) == OB_WRPSTATE_ENABLE)) | |||
#define IS_OPTIONBYTE(VALUE)(((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER |\ | |||
OPTIONBYTE_BOR | OPTIONBYTE_BOOTADDR_0 | OPTIONBYTE_BOOTADDR_1))) | |||
#define IS_OB_BOOT_ADDRESS(ADDRESS) (((ADDRESS) == OB_BOOTADDR_ITCM_RAM) || \ | |||
((ADDRESS) == OB_BOOTADDR_SYSTEM) || \ | |||
((ADDRESS) == OB_BOOTADDR_ITCM_FLASH) || \ | |||
((ADDRESS) == OB_BOOTADDR_AXIM_FLASH) || \ | |||
((ADDRESS) == OB_BOOTADDR_DTCM_RAM) || \ | |||
((ADDRESS) == OB_BOOTADDR_SRAM1) || \ | |||
((ADDRESS) == OB_BOOTADDR_SRAM2)) | |||
#define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) ||\ | |||
((LEVEL) == OB_RDP_LEVEL_1) ||\ | |||
((LEVEL) == OB_RDP_LEVEL_2)) | |||
#define IS_OB_WWDG_SOURCE(SOURCE) (((SOURCE) == OB_WWDG_SW) || ((SOURCE) == OB_WWDG_HW)) | |||
#define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW)) | |||
#define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST)) | |||
#define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST)) | |||
#define IS_OB_IWDG_STOP_FREEZE(FREEZE) (((FREEZE) == OB_IWDG_STOP_FREEZE) || ((FREEZE) == OB_IWDG_STOP_ACTIVE)) | |||
#define IS_OB_IWDG_STDBY_FREEZE(FREEZE) (((FREEZE) == OB_IWDG_STDBY_FREEZE) || ((FREEZE) == OB_IWDG_STDBY_ACTIVE)) | |||
#define IS_OB_BOR_LEVEL(LEVEL) (((LEVEL) == OB_BOR_LEVEL1) || ((LEVEL) == OB_BOR_LEVEL2) ||\ | |||
((LEVEL) == OB_BOR_LEVEL3) || ((LEVEL) == OB_BOR_OFF)) | |||
#define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_LATENCY_0) || \ | |||
((LATENCY) == FLASH_LATENCY_1) || \ | |||
((LATENCY) == FLASH_LATENCY_2) || \ | |||
((LATENCY) == FLASH_LATENCY_3) || \ | |||
((LATENCY) == FLASH_LATENCY_4) || \ | |||
((LATENCY) == FLASH_LATENCY_5) || \ | |||
((LATENCY) == FLASH_LATENCY_6) || \ | |||
((LATENCY) == FLASH_LATENCY_7) || \ | |||
((LATENCY) == FLASH_LATENCY_8) || \ | |||
((LATENCY) == FLASH_LATENCY_9) || \ | |||
((LATENCY) == FLASH_LATENCY_10) || \ | |||
((LATENCY) == FLASH_LATENCY_11) || \ | |||
((LATENCY) == FLASH_LATENCY_12) || \ | |||
((LATENCY) == FLASH_LATENCY_13) || \ | |||
((LATENCY) == FLASH_LATENCY_14) || \ | |||
((LATENCY) == FLASH_LATENCY_15)) | |||
#define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_SECTOR_0) || ((SECTOR) == FLASH_SECTOR_1) ||\ | |||
((SECTOR) == FLASH_SECTOR_2) || ((SECTOR) == FLASH_SECTOR_3) ||\ | |||
((SECTOR) == FLASH_SECTOR_4) || ((SECTOR) == FLASH_SECTOR_5) ||\ | |||
((SECTOR) == FLASH_SECTOR_6) || ((SECTOR) == FLASH_SECTOR_7)) | |||
#define IS_FLASH_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((ADDRESS) <= FLASH_END)) | |||
#define IS_FLASH_NBSECTORS(NBSECTORS) (((NBSECTORS) != 0) && ((NBSECTORS) <= FLASH_SECTOR_TOTAL)) | |||
#define IS_OB_WRP_SECTOR(SECTOR) ((((SECTOR) & (uint32_t)0xFF00FFFF) == 0x00000000) && ((SECTOR) != 0x00000000)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup FLASHEx_Private_Functions FLASH Private Functions | |||
* @{ | |||
*/ | |||
void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_FLASH_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,327 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_gpio.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of GPIO HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_GPIO_H | |||
#define __STM32F7xx_HAL_GPIO_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup GPIO | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup GPIO_Exported_Types GPIO Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief GPIO Init structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Pin; /*!< Specifies the GPIO pins to be configured. | |||
This parameter can be any value of @ref GPIO_pins_define */ | |||
uint32_t Mode; /*!< Specifies the operating mode for the selected pins. | |||
This parameter can be a value of @ref GPIO_mode_define */ | |||
uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins. | |||
This parameter can be a value of @ref GPIO_pull_define */ | |||
uint32_t Speed; /*!< Specifies the speed for the selected pins. | |||
This parameter can be a value of @ref GPIO_speed_define */ | |||
uint32_t Alternate; /*!< Peripheral to be connected to the selected pins. | |||
This parameter can be a value of @ref GPIO_Alternate_function_selection */ | |||
}GPIO_InitTypeDef; | |||
/** | |||
* @brief GPIO Bit SET and Bit RESET enumeration | |||
*/ | |||
typedef enum | |||
{ | |||
GPIO_PIN_RESET = 0, | |||
GPIO_PIN_SET | |||
}GPIO_PinState; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup GPIO_Exported_Constants GPIO Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup GPIO_pins_define GPIO pins define | |||
* @{ | |||
*/ | |||
#define GPIO_PIN_0 ((uint16_t)0x0001) /* Pin 0 selected */ | |||
#define GPIO_PIN_1 ((uint16_t)0x0002) /* Pin 1 selected */ | |||
#define GPIO_PIN_2 ((uint16_t)0x0004) /* Pin 2 selected */ | |||
#define GPIO_PIN_3 ((uint16_t)0x0008) /* Pin 3 selected */ | |||
#define GPIO_PIN_4 ((uint16_t)0x0010) /* Pin 4 selected */ | |||
#define GPIO_PIN_5 ((uint16_t)0x0020) /* Pin 5 selected */ | |||
#define GPIO_PIN_6 ((uint16_t)0x0040) /* Pin 6 selected */ | |||
#define GPIO_PIN_7 ((uint16_t)0x0080) /* Pin 7 selected */ | |||
#define GPIO_PIN_8 ((uint16_t)0x0100) /* Pin 8 selected */ | |||
#define GPIO_PIN_9 ((uint16_t)0x0200) /* Pin 9 selected */ | |||
#define GPIO_PIN_10 ((uint16_t)0x0400) /* Pin 10 selected */ | |||
#define GPIO_PIN_11 ((uint16_t)0x0800) /* Pin 11 selected */ | |||
#define GPIO_PIN_12 ((uint16_t)0x1000) /* Pin 12 selected */ | |||
#define GPIO_PIN_13 ((uint16_t)0x2000) /* Pin 13 selected */ | |||
#define GPIO_PIN_14 ((uint16_t)0x4000) /* Pin 14 selected */ | |||
#define GPIO_PIN_15 ((uint16_t)0x8000) /* Pin 15 selected */ | |||
#define GPIO_PIN_All ((uint16_t)0xFFFF) /* All pins selected */ | |||
#define GPIO_PIN_MASK ((uint32_t)0x0000FFFF) /* PIN mask for assert test */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup GPIO_mode_define GPIO mode define | |||
* @brief GPIO Configuration Mode | |||
* Elements values convention: 0xX0yz00YZ | |||
* - X : GPIO mode or EXTI Mode | |||
* - y : External IT or Event trigger detection | |||
* - z : IO configuration on External IT or Event | |||
* - Y : Output type (Push Pull or Open Drain) | |||
* - Z : IO Direction mode (Input, Output, Alternate or Analog) | |||
* @{ | |||
*/ | |||
#define GPIO_MODE_INPUT ((uint32_t)0x00000000) /*!< Input Floating Mode */ | |||
#define GPIO_MODE_OUTPUT_PP ((uint32_t)0x00000001) /*!< Output Push Pull Mode */ | |||
#define GPIO_MODE_OUTPUT_OD ((uint32_t)0x00000011) /*!< Output Open Drain Mode */ | |||
#define GPIO_MODE_AF_PP ((uint32_t)0x00000002) /*!< Alternate Function Push Pull Mode */ | |||
#define GPIO_MODE_AF_OD ((uint32_t)0x00000012) /*!< Alternate Function Open Drain Mode */ | |||
#define GPIO_MODE_ANALOG ((uint32_t)0x00000003) /*!< Analog Mode */ | |||
#define GPIO_MODE_IT_RISING ((uint32_t)0x10110000) /*!< External Interrupt Mode with Rising edge trigger detection */ | |||
#define GPIO_MODE_IT_FALLING ((uint32_t)0x10210000) /*!< External Interrupt Mode with Falling edge trigger detection */ | |||
#define GPIO_MODE_IT_RISING_FALLING ((uint32_t)0x10310000) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ | |||
#define GPIO_MODE_EVT_RISING ((uint32_t)0x10120000) /*!< External Event Mode with Rising edge trigger detection */ | |||
#define GPIO_MODE_EVT_FALLING ((uint32_t)0x10220000) /*!< External Event Mode with Falling edge trigger detection */ | |||
#define GPIO_MODE_EVT_RISING_FALLING ((uint32_t)0x10320000) /*!< External Event Mode with Rising/Falling edge trigger detection */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup GPIO_speed_define GPIO speed define | |||
* @brief GPIO Output Maximum frequency | |||
* @{ | |||
*/ | |||
#define GPIO_SPEED_LOW ((uint32_t)0x00000000) /*!< Low speed */ | |||
#define GPIO_SPEED_MEDIUM ((uint32_t)0x00000001) /*!< Medium speed */ | |||
#define GPIO_SPEED_FAST ((uint32_t)0x00000002) /*!< Fast speed */ | |||
#define GPIO_SPEED_HIGH ((uint32_t)0x00000003) /*!< High speed */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup GPIO_pull_define GPIO pull define | |||
* @brief GPIO Pull-Up or Pull-Down Activation | |||
* @{ | |||
*/ | |||
#define GPIO_NOPULL ((uint32_t)0x00000000) /*!< No Pull-up or Pull-down activation */ | |||
#define GPIO_PULLUP ((uint32_t)0x00000001) /*!< Pull-up activation */ | |||
#define GPIO_PULLDOWN ((uint32_t)0x00000002) /*!< Pull-down activation */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup GPIO_Exported_Macros GPIO Exported Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Checks whether the specified EXTI line flag is set or not. | |||
* @param __EXTI_LINE__: specifies the EXTI line flag to check. | |||
* This parameter can be GPIO_PIN_x where x can be(0..15) | |||
* @retval The new state of __EXTI_LINE__ (SET or RESET). | |||
*/ | |||
#define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__)) | |||
/** | |||
* @brief Clears the EXTI's line pending flags. | |||
* @param __EXTI_LINE__: specifies the EXTI lines flags to clear. | |||
* This parameter can be any combination of GPIO_PIN_x where x can be (0..15) | |||
* @retval None | |||
*/ | |||
#define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__)) | |||
/** | |||
* @brief Checks whether the specified EXTI line is asserted or not. | |||
* @param __EXTI_LINE__: specifies the EXTI line to check. | |||
* This parameter can be GPIO_PIN_x where x can be(0..15) | |||
* @retval The new state of __EXTI_LINE__ (SET or RESET). | |||
*/ | |||
#define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__)) | |||
/** | |||
* @brief Clears the EXTI's line pending bits. | |||
* @param __EXTI_LINE__: specifies the EXTI lines to clear. | |||
* This parameter can be any combination of GPIO_PIN_x where x can be (0..15) | |||
* @retval None | |||
*/ | |||
#define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__)) | |||
/** | |||
* @brief Generates a Software interrupt on selected EXTI line. | |||
* @param __EXTI_LINE__: specifies the EXTI line to check. | |||
* This parameter can be GPIO_PIN_x where x can be(0..15) | |||
* @retval None | |||
*/ | |||
#define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER |= (__EXTI_LINE__)) | |||
/** | |||
* @} | |||
*/ | |||
/* Include GPIO HAL Extension module */ | |||
#include "stm32f7xx_hal_gpio_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup GPIO_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup GPIO_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions *****************************/ | |||
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init); | |||
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup GPIO_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* IO operation functions *****************************************************/ | |||
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); | |||
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState); | |||
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); | |||
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); | |||
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin); | |||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup GPIO_Private_Constants GPIO Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup GPIO_Private_Macros GPIO Private Macros | |||
* @{ | |||
*/ | |||
#define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET)) | |||
#define IS_GPIO_PIN(PIN) (((PIN) & GPIO_PIN_MASK ) != (uint32_t)0x00) | |||
#define IS_GPIO_MODE(MODE) (((MODE) == GPIO_MODE_INPUT) ||\ | |||
((MODE) == GPIO_MODE_OUTPUT_PP) ||\ | |||
((MODE) == GPIO_MODE_OUTPUT_OD) ||\ | |||
((MODE) == GPIO_MODE_AF_PP) ||\ | |||
((MODE) == GPIO_MODE_AF_OD) ||\ | |||
((MODE) == GPIO_MODE_IT_RISING) ||\ | |||
((MODE) == GPIO_MODE_IT_FALLING) ||\ | |||
((MODE) == GPIO_MODE_IT_RISING_FALLING) ||\ | |||
((MODE) == GPIO_MODE_EVT_RISING) ||\ | |||
((MODE) == GPIO_MODE_EVT_FALLING) ||\ | |||
((MODE) == GPIO_MODE_EVT_RISING_FALLING) ||\ | |||
((MODE) == GPIO_MODE_ANALOG)) | |||
#define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_SPEED_LOW) || ((SPEED) == GPIO_SPEED_MEDIUM) || \ | |||
((SPEED) == GPIO_SPEED_FAST) || ((SPEED) == GPIO_SPEED_HIGH)) | |||
#define IS_GPIO_PULL(PULL) (((PULL) == GPIO_NOPULL) || ((PULL) == GPIO_PULLUP) || \ | |||
((PULL) == GPIO_PULLDOWN)) | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup GPIO_Private_Functions GPIO Private Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_GPIO_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,377 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_gpio_ex.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of GPIO HAL Extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_GPIO_EX_H | |||
#define __STM32F7xx_HAL_GPIO_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup GPIOEx GPIOEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup GPIOEx_Exported_Constants GPIO Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup GPIO_Alternate_function_selection GPIO Alternate Function Selection | |||
* @{ | |||
*/ | |||
/** | |||
* @brief AF 0 selection | |||
*/ | |||
#define GPIO_AF0_RTC_50Hz ((uint8_t)0x00) /* RTC_50Hz Alternate Function mapping */ | |||
#define GPIO_AF0_MCO ((uint8_t)0x00) /* MCO (MCO1 and MCO2) Alternate Function mapping */ | |||
#define GPIO_AF0_SWJ ((uint8_t)0x00) /* SWJ (SWD and JTAG) Alternate Function mapping */ | |||
#define GPIO_AF0_TRACE ((uint8_t)0x00) /* TRACE Alternate Function mapping */ | |||
/** | |||
* @brief AF 1 selection | |||
*/ | |||
#define GPIO_AF1_TIM1 ((uint8_t)0x01) /* TIM1 Alternate Function mapping */ | |||
#define GPIO_AF1_TIM2 ((uint8_t)0x01) /* TIM2 Alternate Function mapping */ | |||
/** | |||
* @brief AF 2 selection | |||
*/ | |||
#define GPIO_AF2_TIM3 ((uint8_t)0x02) /* TIM3 Alternate Function mapping */ | |||
#define GPIO_AF2_TIM4 ((uint8_t)0x02) /* TIM4 Alternate Function mapping */ | |||
#define GPIO_AF2_TIM5 ((uint8_t)0x02) /* TIM5 Alternate Function mapping */ | |||
/** | |||
* @brief AF 3 selection | |||
*/ | |||
#define GPIO_AF3_TIM8 ((uint8_t)0x03) /* TIM8 Alternate Function mapping */ | |||
#define GPIO_AF3_TIM9 ((uint8_t)0x03) /* TIM9 Alternate Function mapping */ | |||
#define GPIO_AF3_TIM10 ((uint8_t)0x03) /* TIM10 Alternate Function mapping */ | |||
#define GPIO_AF3_TIM11 ((uint8_t)0x03) /* TIM11 Alternate Function mapping */ | |||
#define GPIO_AF3_LPTIM1 ((uint8_t)0x03) /* LPTIM1 Alternate Function mapping */ | |||
#define GPIO_AF3_CEC ((uint8_t)0x03) /* CEC Alternate Function mapping */ | |||
/** | |||
* @brief AF 4 selection | |||
*/ | |||
#define GPIO_AF4_I2C1 ((uint8_t)0x04) /* I2C1 Alternate Function mapping */ | |||
#define GPIO_AF4_I2C2 ((uint8_t)0x04) /* I2C2 Alternate Function mapping */ | |||
#define GPIO_AF4_I2C3 ((uint8_t)0x04) /* I2C3 Alternate Function mapping */ | |||
#define GPIO_AF4_I2C4 ((uint8_t)0x04) /* I2C4 Alternate Function mapping */ | |||
#define GPIO_AF4_CEC ((uint8_t)0x04) /* CEC Alternate Function mapping */ | |||
/** | |||
* @brief AF 5 selection | |||
*/ | |||
#define GPIO_AF5_SPI1 ((uint8_t)0x05) /* SPI1 Alternate Function mapping */ | |||
#define GPIO_AF5_SPI2 ((uint8_t)0x05) /* SPI2/I2S2 Alternate Function mapping */ | |||
#define GPIO_AF5_SPI3 ((uint8_t)0x05) /* SPI3/I2S3 Alternate Function mapping */ | |||
#define GPIO_AF5_SPI4 ((uint8_t)0x05) /* SPI4 Alternate Function mapping */ | |||
#define GPIO_AF5_SPI5 ((uint8_t)0x05) /* SPI5 Alternate Function mapping */ | |||
#define GPIO_AF5_SPI6 ((uint8_t)0x05) /* SPI6 Alternate Function mapping */ | |||
/** | |||
* @brief AF 6 selection | |||
*/ | |||
#define GPIO_AF6_SPI3 ((uint8_t)0x06) /* SPI3/I2S3 Alternate Function mapping */ | |||
#define GPIO_AF6_SAI1 ((uint8_t)0x06) /* SAI1 Alternate Function mapping */ | |||
/** | |||
* @brief AF 7 selection | |||
*/ | |||
#define GPIO_AF7_USART1 ((uint8_t)0x07) /* USART1 Alternate Function mapping */ | |||
#define GPIO_AF7_USART2 ((uint8_t)0x07) /* USART2 Alternate Function mapping */ | |||
#define GPIO_AF7_USART3 ((uint8_t)0x07) /* USART3 Alternate Function mapping */ | |||
#define GPIO_AF7_UART5 ((uint8_t)0x07) /* UART5 Alternate Function mapping */ | |||
#define GPIO_AF7_SPDIFRX ((uint8_t)0x07) /* SPDIF-RX Alternate Function mapping */ | |||
#define GPIO_AF7_SPI2 ((uint8_t)0x07) /* SPI2 Alternate Function mapping */ | |||
#define GPIO_AF7_SPI3 ((uint8_t)0x07) /* SPI3 Alternate Function mapping */ | |||
/** | |||
* @brief AF 8 selection | |||
*/ | |||
#define GPIO_AF8_UART4 ((uint8_t)0x08) /* UART4 Alternate Function mapping */ | |||
#define GPIO_AF8_UART5 ((uint8_t)0x08) /* UART5 Alternate Function mapping */ | |||
#define GPIO_AF8_USART6 ((uint8_t)0x08) /* USART6 Alternate Function mapping */ | |||
#define GPIO_AF8_UART7 ((uint8_t)0x08) /* UART7 Alternate Function mapping */ | |||
#define GPIO_AF8_UART8 ((uint8_t)0x08) /* UART8 Alternate Function mapping */ | |||
#define GPIO_AF8_SPDIFRX ((uint8_t)0x08) /* SPIDIF-RX Alternate Function mapping */ | |||
#define GPIO_AF8_SAI2 ((uint8_t)0x08) /* SAI2 Alternate Function mapping */ | |||
/** | |||
* @brief AF 9 selection | |||
*/ | |||
#define GPIO_AF9_CAN1 ((uint8_t)0x09) /* CAN1 Alternate Function mapping */ | |||
#define GPIO_AF9_CAN2 ((uint8_t)0x09) /* CAN2 Alternate Function mapping */ | |||
#define GPIO_AF9_TIM12 ((uint8_t)0x09) /* TIM12 Alternate Function mapping */ | |||
#define GPIO_AF9_TIM13 ((uint8_t)0x09) /* TIM13 Alternate Function mapping */ | |||
#define GPIO_AF9_TIM14 ((uint8_t)0x09) /* TIM14 Alternate Function mapping */ | |||
#define GPIO_AF9_QUADSPI ((uint8_t)0x09) /* QUADSPI Alternate Function mapping */ | |||
#if defined(STM32F756xx) || defined(STM32F746xx) | |||
#define GPIO_AF9_LTDC ((uint8_t)0x09) /* LCD-TFT Alternate Function mapping */ | |||
#endif /* STM32F756xx || STM32F746xx */ | |||
/** | |||
* @brief AF 10 selection | |||
*/ | |||
#define GPIO_AF10_OTG_FS ((uint8_t)0xA) /* OTG_FS Alternate Function mapping */ | |||
#define GPIO_AF10_OTG_HS ((uint8_t)0xA) /* OTG_HS Alternate Function mapping */ | |||
#define GPIO_AF10_QUADSPI ((uint8_t)0xA) /* QUADSPI Alternate Function mapping */ | |||
#define GPIO_AF10_SAI2 ((uint8_t)0xA) /* SAI2 Alternate Function mapping */ | |||
/** | |||
* @brief AF 11 selection | |||
*/ | |||
#define GPIO_AF11_ETH ((uint8_t)0x0B) /* ETHERNET Alternate Function mapping */ | |||
/** | |||
* @brief AF 12 selection | |||
*/ | |||
#define GPIO_AF12_FMC ((uint8_t)0xC) /* FMC Alternate Function mapping */ | |||
#define GPIO_AF12_OTG_HS_FS ((uint8_t)0xC) /* OTG HS configured in FS, Alternate Function mapping */ | |||
#define GPIO_AF12_SDMMC1 ((uint8_t)0xC) /* SDMMC1 Alternate Function mapping */ | |||
/** | |||
* @brief AF 13 selection | |||
*/ | |||
#define GPIO_AF13_DCMI ((uint8_t)0x0D) /* DCMI Alternate Function mapping */ | |||
#if defined(STM32F756xx) || defined(STM32F746xx) | |||
/** | |||
* @brief AF 14 selection | |||
*/ | |||
#define GPIO_AF14_LTDC ((uint8_t)0x0E) /* LCD-TFT Alternate Function mapping */ | |||
#endif /* STM32F756xx || STM32F746xx */ | |||
/** | |||
* @brief AF 15 selection | |||
*/ | |||
#define GPIO_AF15_EVENTOUT ((uint8_t)0x0F) /* EVENTOUT Alternate Function mapping */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup GPIOEx_Exported_Macros GPIO Exported Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup GPIOEx_Exported_Functions GPIO Exported Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup GPIOEx_Private_Constants GPIO Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @brief GPIO pin available on the platform | |||
*/ | |||
/* Defines the available pins per GPIOs */ | |||
#define GPIOA_PIN_AVAILABLE GPIO_PIN_All | |||
#define GPIOB_PIN_AVAILABLE GPIO_PIN_All | |||
#define GPIOC_PIN_AVAILABLE GPIO_PIN_All | |||
#define GPIOD_PIN_AVAILABLE GPIO_PIN_All | |||
#define GPIOE_PIN_AVAILABLE GPIO_PIN_All | |||
#define GPIOF_PIN_AVAILABLE GPIO_PIN_All | |||
#define GPIOG_PIN_AVAILABLE GPIO_PIN_All | |||
#define GPIOI_PIN_AVAILABLE GPIO_PIN_All | |||
#define GPIOJ_PIN_AVAILABLE GPIO_PIN_All | |||
#define GPIOH_PIN_AVAILABLE GPIO_PIN_All | |||
#define GPIOK_PIN_AVAILABLE (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_4 | \ | |||
GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7) | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup GPIOEx_Private_Macros GPIO Private Macros | |||
* @{ | |||
*/ | |||
/** @defgroup GPIOEx_Get_Port_Index GPIO Get Port Index | |||
* @{ | |||
*/ | |||
#define GPIO_GET_INDEX(__GPIOx__) (uint8_t)(((__GPIOx__) == (GPIOA))? 0U :\ | |||
((__GPIOx__) == (GPIOB))? 1U :\ | |||
((__GPIOx__) == (GPIOC))? 2U :\ | |||
((__GPIOx__) == (GPIOD))? 3U :\ | |||
((__GPIOx__) == (GPIOE))? 4U :\ | |||
((__GPIOx__) == (GPIOF))? 5U :\ | |||
((__GPIOx__) == (GPIOG))? 6U :\ | |||
((__GPIOx__) == (GPIOH))? 7U :\ | |||
((__GPIOx__) == (GPIOI))? 8U :\ | |||
((__GPIOx__) == (GPIOJ))? 9U : 10U) | |||
/** | |||
* @} | |||
*/ | |||
#define IS_GPIO_PIN_AVAILABLE(__INSTANCE__,__PIN__) \ | |||
((((__INSTANCE__) == GPIOA) && (((__PIN__) & (GPIOA_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOA_PIN_AVAILABLE)) == (GPIOA_PIN_AVAILABLE))) || \ | |||
(((__INSTANCE__) == GPIOB) && (((__PIN__) & (GPIOB_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOB_PIN_AVAILABLE)) == (GPIOB_PIN_AVAILABLE))) || \ | |||
(((__INSTANCE__) == GPIOC) && (((__PIN__) & (GPIOC_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOC_PIN_AVAILABLE)) == (GPIOC_PIN_AVAILABLE))) || \ | |||
(((__INSTANCE__) == GPIOD) && (((__PIN__) & (GPIOD_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOD_PIN_AVAILABLE)) == (GPIOD_PIN_AVAILABLE))) || \ | |||
(((__INSTANCE__) == GPIOE) && (((__PIN__) & (GPIOE_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOE_PIN_AVAILABLE)) == (GPIOE_PIN_AVAILABLE))) || \ | |||
(((__INSTANCE__) == GPIOF) && (((__PIN__) & (GPIOF_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOF_PIN_AVAILABLE)) == (GPIOF_PIN_AVAILABLE))) || \ | |||
(((__INSTANCE__) == GPIOG) && (((__PIN__) & (GPIOG_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOG_PIN_AVAILABLE)) == (GPIOG_PIN_AVAILABLE))) || \ | |||
(((__INSTANCE__) == GPIOI) && (((__PIN__) & (GPIOI_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOI_PIN_AVAILABLE)) == (GPIOI_PIN_AVAILABLE))) || \ | |||
(((__INSTANCE__) == GPIOJ) && (((__PIN__) & (GPIOJ_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOJ_PIN_AVAILABLE)) == (GPIOJ_PIN_AVAILABLE))) || \ | |||
(((__INSTANCE__) == GPIOK) && (((__PIN__) & (GPIOK_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOK_PIN_AVAILABLE)) == (GPIOK_PIN_AVAILABLE))) || \ | |||
(((__INSTANCE__) == GPIOH) && (((__PIN__) & (GPIOH_PIN_AVAILABLE)) != 0) && (((__PIN__) | (GPIOH_PIN_AVAILABLE)) == (GPIOH_PIN_AVAILABLE)))) | |||
/** @defgroup GPIOEx_IS_Alternat_function_selection GPIO Check Alternate Function | |||
* @{ | |||
*/ | |||
#if defined(STM32F756xx) || defined(STM32F746xx) | |||
#define IS_GPIO_AF(AF) (((AF) == GPIO_AF0_RTC_50Hz) || ((AF) == GPIO_AF1_TIM1) || \ | |||
((AF) == GPIO_AF0_SWJ) || ((AF) == GPIO_AF0_TRACE) || \ | |||
((AF) == GPIO_AF0_MCO) || ((AF) == GPIO_AF1_TIM2) || \ | |||
((AF) == GPIO_AF2_TIM3) || ((AF) == GPIO_AF2_TIM4) || \ | |||
((AF) == GPIO_AF2_TIM5) || ((AF) == GPIO_AF3_TIM8) || \ | |||
((AF) == GPIO_AF3_TIM9) || ((AF) == GPIO_AF3_TIM10) || \ | |||
((AF) == GPIO_AF3_TIM11) || ((AF) == GPIO_AF3_LPTIM1) || \ | |||
((AF) == GPIO_AF3_CEC) || ((AF) == GPIO_AF4_CEC) || \ | |||
((AF) == GPIO_AF4_I2C1) || ((AF) == GPIO_AF4_I2C2) || \ | |||
((AF) == GPIO_AF4_I2C3) || ((AF) == GPIO_AF4_I2C4) || \ | |||
((AF) == GPIO_AF5_SPI1) || ((AF) == GPIO_AF5_SPI2) || \ | |||
((AF) == GPIO_AF5_SPI3) || ((AF) == GPIO_AF5_SPI4) || \ | |||
((AF) == GPIO_AF5_SPI5) || ((AF) == GPIO_AF5_SPI6) || \ | |||
((AF) == GPIO_AF6_SPI3) || ((AF) == GPIO_AF6_SAI1) || \ | |||
((AF) == GPIO_AF7_SPI3) || ((AF) == GPIO_AF7_SPI2) || \ | |||
((AF) == GPIO_AF7_USART1) || ((AF) == GPIO_AF7_USART2) || \ | |||
((AF) == GPIO_AF7_USART3) || ((AF) == GPIO_AF7_UART5) || \ | |||
((AF) == GPIO_AF7_SPDIFRX) || ((AF) == GPIO_AF8_SPDIFRX) || \ | |||
((AF) == GPIO_AF8_SAI2) || ((AF) == GPIO_AF8_USART6) || \ | |||
((AF) == GPIO_AF8_UART4) || ((AF) == GPIO_AF8_UART5) || \ | |||
((AF) == GPIO_AF8_UART7) || ((AF) == GPIO_AF8_UART8) || \ | |||
((AF) == GPIO_AF9_CAN1) || ((AF) == GPIO_AF9_CAN2) || \ | |||
((AF) == GPIO_AF9_TIM12) || ((AF) == GPIO_AF9_TIM12) || \ | |||
((AF) == GPIO_AF9_TIM14) || ((AF) == GPIO_AF9_QUADSPI) || \ | |||
((AF) == GPIO_AF9_LTDC) || ((AF) == GPIO_AF10_OTG_FS) || \ | |||
((AF) == GPIO_AF10_OTG_HS) || ((AF) == GPIO_AF10_SAI2) || \ | |||
((AF) == GPIO_AF10_QUADSPI) || ((AF) == GPIO_AF11_ETH) || \ | |||
((AF) == GPIO_AF12_OTG_HS_FS) || ((AF) == GPIO_AF12_SDMMC1) || \ | |||
((AF) == GPIO_AF12_FMC) || ((AF) == GPIO_AF15_EVENTOUT) || \ | |||
((AF) == GPIO_AF13_DCMI) || ((AF) == GPIO_AF14_LTDC)) | |||
#elif defined(STM32F745xx) | |||
#define IS_GPIO_AF(AF) (((AF) == GPIO_AF0_RTC_50Hz) || ((AF) == GPIO_AF1_TIM1) || \ | |||
((AF) == GPIO_AF0_SWJ) || ((AF) == GPIO_AF0_TRACE) || \ | |||
((AF) == GPIO_AF0_MCO) || ((AF) == GPIO_AF1_TIM2) || \ | |||
((AF) == GPIO_AF2_TIM3) || ((AF) == GPIO_AF2_TIM4) || \ | |||
((AF) == GPIO_AF2_TIM5) || ((AF) == GPIO_AF3_TIM8) || \ | |||
((AF) == GPIO_AF3_TIM9) || ((AF) == GPIO_AF3_TIM10) || \ | |||
((AF) == GPIO_AF3_TIM11) || ((AF) == GPIO_AF3_LPTIM1) || \ | |||
((AF) == GPIO_AF3_CEC) || ((AF) == GPIO_AF4_CEC) || \ | |||
((AF) == GPIO_AF4_I2C1) || ((AF) == GPIO_AF4_I2C2) || \ | |||
((AF) == GPIO_AF4_I2C3) || ((AF) == GPIO_AF4_I2C4) || \ | |||
((AF) == GPIO_AF5_SPI1) || ((AF) == GPIO_AF5_SPI2) || \ | |||
((AF) == GPIO_AF5_SPI3) || ((AF) == GPIO_AF5_SPI4) || \ | |||
((AF) == GPIO_AF5_SPI5) || ((AF) == GPIO_AF5_SPI6) || \ | |||
((AF) == GPIO_AF6_SPI3) || ((AF) == GPIO_AF6_SAI1) || \ | |||
((AF) == GPIO_AF7_SPI3) || ((AF) == GPIO_AF7_SPI2) || \ | |||
((AF) == GPIO_AF7_USART1) || ((AF) == GPIO_AF7_USART2) || \ | |||
((AF) == GPIO_AF7_USART3) || ((AF) == GPIO_AF7_UART5) || \ | |||
((AF) == GPIO_AF7_SPDIFRX) || ((AF) == GPIO_AF8_SPDIFRX) || \ | |||
((AF) == GPIO_AF8_SAI2) || ((AF) == GPIO_AF8_USART6) || \ | |||
((AF) == GPIO_AF8_UART4) || ((AF) == GPIO_AF8_UART5) || \ | |||
((AF) == GPIO_AF8_UART7) || ((AF) == GPIO_AF8_UART8) || \ | |||
((AF) == GPIO_AF9_CAN1) || ((AF) == GPIO_AF9_CAN2) || \ | |||
((AF) == GPIO_AF9_TIM12) || ((AF) == GPIO_AF9_TIM12) || \ | |||
((AF) == GPIO_AF9_TIM14) || ((AF) == GPIO_AF9_QUADSPI) || \ | |||
((AF) == GPIO_AF13_DCMI) || ((AF) == GPIO_AF10_OTG_FS) || \ | |||
((AF) == GPIO_AF10_OTG_HS) || ((AF) == GPIO_AF10_SAI2) || \ | |||
((AF) == GPIO_AF10_QUADSPI) || ((AF) == GPIO_AF11_ETH) || \ | |||
((AF) == GPIO_AF12_OTG_HS_FS) || ((AF) == GPIO_AF12_SDMMC1) || \ | |||
((AF) == GPIO_AF12_FMC) || ((AF) == GPIO_AF15_EVENTOUT)) | |||
#endif /* STM32F756xx || STM32F746xx */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup GPIOEx_Private_Functions GPIO Private Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_GPIO_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,598 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_i2c.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of I2C HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_I2C_H | |||
#define __STM32F7xx_HAL_I2C_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup I2C | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup I2C_Exported_Types I2C Exported Types | |||
* @{ | |||
*/ | |||
/** @defgroup I2C_Configuration_Structure_definition I2C Configuration Structure definition | |||
* @brief I2C Configuration Structure definition | |||
* @{ | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Timing; /*!< Specifies the I2C_TIMINGR_register value. | |||
This parameter calculated by referring to I2C initialization | |||
section in Reference manual */ | |||
uint32_t OwnAddress1; /*!< Specifies the first device own address. | |||
This parameter can be a 7-bit or 10-bit address. */ | |||
uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode is selected. | |||
This parameter can be a value of @ref I2C_addressing_mode */ | |||
uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected. | |||
This parameter can be a value of @ref I2C_dual_addressing_mode */ | |||
uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is selected | |||
This parameter can be a 7-bit address. */ | |||
uint32_t OwnAddress2Masks; /*!< Specifies the acknoledge mask address second device own address if dual addressing mode is selected | |||
This parameter can be a value of @ref I2C_own_address2_masks */ | |||
uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected. | |||
This parameter can be a value of @ref I2C_general_call_addressing_mode */ | |||
uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected. | |||
This parameter can be a value of @ref I2C_nostretch_mode */ | |||
}I2C_InitTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup HAL_state_structure_definition HAL state structure definition | |||
* @brief HAL State structure definition | |||
* @{ | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_I2C_STATE_RESET = 0x00, /*!< I2C not yet initialized or disabled */ | |||
HAL_I2C_STATE_READY = 0x01, /*!< I2C initialized and ready for use */ | |||
HAL_I2C_STATE_BUSY = 0x02, /*!< I2C internal process is ongoing */ | |||
HAL_I2C_STATE_MASTER_BUSY_TX = 0x12, /*!< Master Data Transmission process is ongoing */ | |||
HAL_I2C_STATE_MASTER_BUSY_RX = 0x22, /*!< Master Data Reception process is ongoing */ | |||
HAL_I2C_STATE_SLAVE_BUSY_TX = 0x32, /*!< Slave Data Transmission process is ongoing */ | |||
HAL_I2C_STATE_SLAVE_BUSY_RX = 0x42, /*!< Slave Data Reception process is ongoing */ | |||
HAL_I2C_STATE_MEM_BUSY_TX = 0x52, /*!< Memory Data Transmission process is ongoing */ | |||
HAL_I2C_STATE_MEM_BUSY_RX = 0x62, /*!< Memory Data Reception process is ongoing */ | |||
HAL_I2C_STATE_TIMEOUT = 0x03, /*!< Timeout state */ | |||
HAL_I2C_STATE_ERROR = 0x04 /*!< Reception process is ongoing */ | |||
}HAL_I2C_StateTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_Error_Code_definition I2C Error Code definition | |||
* @brief I2C Error Code definition | |||
* @{ | |||
*/ | |||
#define HAL_I2C_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */ | |||
#define HAL_I2C_ERROR_BERR ((uint32_t)0x00000001) /*!< BERR error */ | |||
#define HAL_I2C_ERROR_ARLO ((uint32_t)0x00000002) /*!< ARLO error */ | |||
#define HAL_I2C_ERROR_AF ((uint32_t)0x00000004) /*!< ACKF error */ | |||
#define HAL_I2C_ERROR_OVR ((uint32_t)0x00000008) /*!< OVR error */ | |||
#define HAL_I2C_ERROR_DMA ((uint32_t)0x00000010) /*!< DMA transfer error */ | |||
#define HAL_I2C_ERROR_TIMEOUT ((uint32_t)0x00000020) /*!< Timeout error */ | |||
#define HAL_I2C_ERROR_SIZE ((uint32_t)0x00000040) /*!< Size Management error */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_handle_Structure_definition I2C handle Structure definition | |||
* @brief I2C handle Structure definition | |||
* @{ | |||
*/ | |||
typedef struct | |||
{ | |||
I2C_TypeDef *Instance; /*!< I2C registers base address */ | |||
I2C_InitTypeDef Init; /*!< I2C communication parameters */ | |||
uint8_t *pBuffPtr; /*!< Pointer to I2C transfer buffer */ | |||
uint16_t XferSize; /*!< I2C transfer size */ | |||
__IO uint16_t XferCount; /*!< I2C transfer counter */ | |||
DMA_HandleTypeDef *hdmatx; /*!< I2C Tx DMA handle parameters */ | |||
DMA_HandleTypeDef *hdmarx; /*!< I2C Rx DMA handle parameters */ | |||
HAL_LockTypeDef Lock; /*!< I2C locking object */ | |||
__IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */ | |||
__IO uint32_t ErrorCode; /*!< I2C Error code */ | |||
}I2C_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup I2C_Exported_Constants I2C Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup I2C_addressing_mode I2C addressing mode | |||
* @{ | |||
*/ | |||
#define I2C_ADDRESSINGMODE_7BIT ((uint32_t)0x00000001) | |||
#define I2C_ADDRESSINGMODE_10BIT ((uint32_t)0x00000002) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_dual_addressing_mode I2C dual addressing mode | |||
* @{ | |||
*/ | |||
#define I2C_DUALADDRESS_DISABLE ((uint32_t)0x00000000) | |||
#define I2C_DUALADDRESS_ENABLE I2C_OAR2_OA2EN | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_own_address2_masks I2C own address2 masks | |||
* @{ | |||
*/ | |||
#define I2C_OA2_NOMASK ((uint8_t)0x00) | |||
#define I2C_OA2_MASK01 ((uint8_t)0x01) | |||
#define I2C_OA2_MASK02 ((uint8_t)0x02) | |||
#define I2C_OA2_MASK03 ((uint8_t)0x03) | |||
#define I2C_OA2_MASK04 ((uint8_t)0x04) | |||
#define I2C_OA2_MASK05 ((uint8_t)0x05) | |||
#define I2C_OA2_MASK06 ((uint8_t)0x06) | |||
#define I2C_OA2_MASK07 ((uint8_t)0x07) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_general_call_addressing_mode I2C general call addressing mode | |||
* @{ | |||
*/ | |||
#define I2C_GENERALCALL_DISABLE ((uint32_t)0x00000000) | |||
#define I2C_GENERALCALL_ENABLE I2C_CR1_GCEN | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_nostretch_mode I2C nostretch mode | |||
* @{ | |||
*/ | |||
#define I2C_NOSTRETCH_DISABLE ((uint32_t)0x00000000) | |||
#define I2C_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_Memory_Address_Size I2C Memory Address Size | |||
* @{ | |||
*/ | |||
#define I2C_MEMADD_SIZE_8BIT ((uint32_t)0x00000001) | |||
#define I2C_MEMADD_SIZE_16BIT ((uint32_t)0x00000002) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_ReloadEndMode_definition I2C ReloadEndMode definition | |||
* @{ | |||
*/ | |||
#define I2C_RELOAD_MODE I2C_CR2_RELOAD | |||
#define I2C_AUTOEND_MODE I2C_CR2_AUTOEND | |||
#define I2C_SOFTEND_MODE ((uint32_t)0x00000000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_StartStopMode_definition I2C StartStopMode definition | |||
* @{ | |||
*/ | |||
#define I2C_NO_STARTSTOP ((uint32_t)0x00000000) | |||
#define I2C_GENERATE_STOP I2C_CR2_STOP | |||
#define I2C_GENERATE_START_READ (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN) | |||
#define I2C_GENERATE_START_WRITE I2C_CR2_START | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition | |||
* @brief I2C Interrupt definition | |||
* Elements values convention: 0xXXXXXXXX | |||
* - XXXXXXXX : Interrupt control mask | |||
* @{ | |||
*/ | |||
#define I2C_IT_ERRI I2C_CR1_ERRIE | |||
#define I2C_IT_TCI I2C_CR1_TCIE | |||
#define I2C_IT_STOPI I2C_CR1_STOPIE | |||
#define I2C_IT_NACKI I2C_CR1_NACKIE | |||
#define I2C_IT_ADDRI I2C_CR1_ADDRIE | |||
#define I2C_IT_RXI I2C_CR1_RXIE | |||
#define I2C_IT_TXI I2C_CR1_TXIE | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2C_Flag_definition I2C Flag definition | |||
* @{ | |||
*/ | |||
#define I2C_FLAG_TXE I2C_ISR_TXE | |||
#define I2C_FLAG_TXIS I2C_ISR_TXIS | |||
#define I2C_FLAG_RXNE I2C_ISR_RXNE | |||
#define I2C_FLAG_ADDR I2C_ISR_ADDR | |||
#define I2C_FLAG_AF I2C_ISR_NACKF | |||
#define I2C_FLAG_STOPF I2C_ISR_STOPF | |||
#define I2C_FLAG_TC I2C_ISR_TC | |||
#define I2C_FLAG_TCR I2C_ISR_TCR | |||
#define I2C_FLAG_BERR I2C_ISR_BERR | |||
#define I2C_FLAG_ARLO I2C_ISR_ARLO | |||
#define I2C_FLAG_OVR I2C_ISR_OVR | |||
#define I2C_FLAG_PECERR I2C_ISR_PECERR | |||
#define I2C_FLAG_TIMEOUT I2C_ISR_TIMEOUT | |||
#define I2C_FLAG_ALERT I2C_ISR_ALERT | |||
#define I2C_FLAG_BUSY I2C_ISR_BUSY | |||
#define I2C_FLAG_DIR I2C_ISR_DIR | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/** @defgroup I2C_Exported_Macros I2C Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset I2C handle state | |||
* @param __HANDLE__: specifies the I2C Handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET) | |||
/** @brief Enable the specified I2C interrupts. | |||
* @param __HANDLE__: specifies the I2C Handle. | |||
* @param __INTERRUPT__: specifies the interrupt source to enable. | |||
* This parameter can be one of the following values: | |||
* @arg I2C_IT_ERRI: Errors interrupt enable | |||
* @arg I2C_IT_TCI: Transfer complete interrupt enable | |||
* @arg I2C_IT_STOPI: STOP detection interrupt enable | |||
* @arg I2C_IT_NACKI: NACK received interrupt enable | |||
* @arg I2C_IT_ADDRI: Address match interrupt enable | |||
* @arg I2C_IT_RXI: RX interrupt enable | |||
* @arg I2C_IT_TXI: TX interrupt enable | |||
* | |||
* @retval None | |||
*/ | |||
#define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 |= (__INTERRUPT__)) | |||
/** @brief Disable the specified I2C interrupts. | |||
* @param __HANDLE__: specifies the I2C Handle. | |||
* @param __INTERRUPT__: specifies the interrupt source to disable. | |||
* This parameter can be one of the following values: | |||
* @arg I2C_IT_ERRI: Errors interrupt enable | |||
* @arg I2C_IT_TCI: Transfer complete interrupt enable | |||
* @arg I2C_IT_STOPI: STOP detection interrupt enable | |||
* @arg I2C_IT_NACKI: NACK received interrupt enable | |||
* @arg I2C_IT_ADDRI: Address match interrupt enable | |||
* @arg I2C_IT_RXI: RX interrupt enable | |||
* @arg I2C_IT_TXI: TX interrupt enable | |||
* | |||
* @retval None | |||
*/ | |||
#define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 &= (~(__INTERRUPT__))) | |||
/** @brief Checks if the specified I2C interrupt source is enabled or disabled. | |||
* @param __HANDLE__: specifies the I2C Handle. | |||
* @param __INTERRUPT__: specifies the I2C interrupt source to check. | |||
* This parameter can be one of the following values: | |||
* @arg I2C_IT_ERRI: Errors interrupt enable | |||
* @arg I2C_IT_TCI: Transfer complete interrupt enable | |||
* @arg I2C_IT_STOPI: STOP detection interrupt enable | |||
* @arg I2C_IT_NACKI: NACK received interrupt enable | |||
* @arg I2C_IT_ADDRI: Address match interrupt enable | |||
* @arg I2C_IT_RXI: RX interrupt enable | |||
* @arg I2C_IT_TXI: TX interrupt enable | |||
* | |||
* @retval The new state of __INTERRUPT__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) | |||
/** @brief Checks whether the specified I2C flag is set or not. | |||
* @param __HANDLE__: specifies the I2C Handle. | |||
* @param __FLAG__: specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg I2C_FLAG_TXE: Transmit data register empty | |||
* @arg I2C_FLAG_TXIS: Transmit interrupt status | |||
* @arg I2C_FLAG_RXNE: Receive data register not empty | |||
* @arg I2C_FLAG_ADDR: Address matched (slave mode) | |||
* @arg I2C_FLAG_AF: Acknowledge failure received flag | |||
* @arg I2C_FLAG_STOPF: STOP detection flag | |||
* @arg I2C_FLAG_TC: Transfer complete (master mode) | |||
* @arg I2C_FLAG_TCR: Transfer complete reload | |||
* @arg I2C_FLAG_BERR: Bus error | |||
* @arg I2C_FLAG_ARLO: Arbitration lost | |||
* @arg I2C_FLAG_OVR: Overrun/Underrun | |||
* @arg I2C_FLAG_PECERR: PEC error in reception | |||
* @arg I2C_FLAG_TIMEOUT: Timeout or Tlow detection flag | |||
* @arg I2C_FLAG_ALERT: SMBus alert | |||
* @arg I2C_FLAG_BUSY: Bus busy | |||
* @arg I2C_FLAG_DIR: Transfer direction (slave mode) | |||
* | |||
* @retval The new state of __FLAG__ (TRUE or FALSE). | |||
*/ | |||
#define I2C_FLAG_MASK ((uint32_t)0x0001FFFF) | |||
#define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK))) | |||
/** @brief Clears the I2C pending flags which are cleared by writing 1 in a specific bit. | |||
* @param __HANDLE__: specifies the I2C Handle. | |||
* @param __FLAG__: specifies the flag to clear. | |||
* This parameter can be any combination of the following values: | |||
* @arg I2C_FLAG_ADDR: Address matched (slave mode) | |||
* @arg I2C_FLAG_AF: Acknowledge failure received flag | |||
* @arg I2C_FLAG_STOPF: STOP detection flag | |||
* @arg I2C_FLAG_BERR: Bus error | |||
* @arg I2C_FLAG_ARLO: Arbitration lost | |||
* @arg I2C_FLAG_OVR: Overrun/Underrun | |||
* @arg I2C_FLAG_PECERR: PEC error in reception | |||
* @arg I2C_FLAG_TIMEOUT: Timeout or Tlow detection flag | |||
* @arg I2C_FLAG_ALERT: SMBus alert | |||
* | |||
* @retval None | |||
*/ | |||
#define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = ((__FLAG__) & I2C_FLAG_MASK)) | |||
/** @brief Enable the specified I2C peripheral. | |||
* @param __HANDLE__: specifies the I2C Handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_I2C_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)) | |||
/** @brief Disable the specified I2C peripheral. | |||
* @param __HANDLE__: specifies the I2C Handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_I2C_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)) | |||
/** | |||
* @} | |||
*/ | |||
/* Include I2C HAL Extension module */ | |||
#include "stm32f7xx_hal_i2c_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup I2C_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup I2C_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions******************************/ | |||
HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c); | |||
HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c); | |||
void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c); | |||
void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup I2C_Exported_Functions_Group2 Input and Output operation functions | |||
* @{ | |||
*/ | |||
/* IO operation functions ****************************************************/ | |||
/******* Blocking mode: Polling */ | |||
HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout); | |||
/******* Non-Blocking mode: Interrupt */ | |||
HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2C_Mem_Write_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2C_Mem_Read_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); | |||
/******* Non-Blocking mode: DMA */ | |||
HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2C_Mem_Write_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2C_Mem_Read_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup IRQ_Handler_and_Callbacks IRQ Handler and Callbacks | |||
* @{ | |||
*/ | |||
/******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */ | |||
void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c); | |||
void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c); | |||
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c); | |||
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c); | |||
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c); | |||
void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c); | |||
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c); | |||
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c); | |||
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup I2C_Exported_Functions_Group3 Peripheral State and Errors functions | |||
* @{ | |||
*/ | |||
/* Peripheral State and Errors functions *************************************/ | |||
HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c); | |||
uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup I2C_Private_Constants I2C Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup I2C_Private_Macro I2C Private Macros | |||
* @{ | |||
*/ | |||
#define IS_I2C_ADDRESSING_MODE(MODE) (((MODE) == I2C_ADDRESSINGMODE_7BIT) || \ | |||
((MODE) == I2C_ADDRESSINGMODE_10BIT)) | |||
#define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLE) || \ | |||
((ADDRESS) == I2C_DUALADDRESS_ENABLE)) | |||
#define IS_I2C_OWN_ADDRESS2_MASK(MASK) (((MASK) == I2C_OA2_NOMASK) || \ | |||
((MASK) == I2C_OA2_MASK01) || \ | |||
((MASK) == I2C_OA2_MASK02) || \ | |||
((MASK) == I2C_OA2_MASK03) || \ | |||
((MASK) == I2C_OA2_MASK04) || \ | |||
((MASK) == I2C_OA2_MASK05) || \ | |||
((MASK) == I2C_OA2_MASK06) || \ | |||
((MASK) == I2C_OA2_MASK07)) | |||
#define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLE) || \ | |||
((CALL) == I2C_GENERALCALL_ENABLE)) | |||
#define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \ | |||
((STRETCH) == I2C_NOSTRETCH_ENABLE)) | |||
#define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \ | |||
((SIZE) == I2C_MEMADD_SIZE_16BIT)) | |||
#define IS_TRANSFER_MODE(MODE) (((MODE) == I2C_RELOAD_MODE) || \ | |||
((MODE) == I2C_AUTOEND_MODE) || \ | |||
((MODE) == I2C_SOFTEND_MODE)) | |||
#define IS_TRANSFER_REQUEST(REQUEST) (((REQUEST) == I2C_GENERATE_STOP) || \ | |||
((REQUEST) == I2C_GENERATE_START_READ) || \ | |||
((REQUEST) == I2C_GENERATE_START_WRITE) || \ | |||
((REQUEST) == I2C_NO_STARTSTOP)) | |||
#define I2C_RESET_CR2(__HANDLE__) ((__HANDLE__)->Instance->CR2 &= (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_HEAD10R | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_RD_WRN))) | |||
#define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= (uint32_t)0x000003FF) | |||
#define IS_I2C_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= (uint16_t)0x00FF) | |||
#define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00))) >> 8))) | |||
#define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FF)))) | |||
#define I2C_GENERATE_START(__ADDMODE__,__ADDRESS__) (((__ADDMODE__) == I2C_ADDRESSINGMODE_7BIT) ? (uint32_t)((((uint32_t)(__ADDRESS__) & (I2C_CR2_SADD)) | (I2C_CR2_START) | (I2C_CR2_AUTOEND)) & (~I2C_CR2_RD_WRN)) : \ | |||
(uint32_t)((((uint32_t)(__ADDRESS__) & (I2C_CR2_SADD)) | (I2C_CR2_ADD10) | (I2C_CR2_START)) & (~I2C_CR2_RD_WRN))) | |||
/** | |||
* @} | |||
*/ | |||
/* Private Functions ---------------------------------------------------------*/ | |||
/** @defgroup I2C_Private_Functions I2C Private Functions | |||
* @{ | |||
*/ | |||
/* Private functions are defined in stm32f7xx_hal_i2c.c file */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_I2C_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||
@@ -0,0 +1,129 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_i2c_ex.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of I2C HAL Extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_I2C_EX_H | |||
#define __STM32F7xx_HAL_I2C_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup I2CEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup I2CEx_Exported_Constants I2CEx Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup I2CEx_Analog_Filter I2CEx Analog Filter | |||
* @{ | |||
*/ | |||
#define I2C_ANALOGFILTER_ENABLE ((uint32_t)0x00000000) | |||
#define I2C_ANALOGFILTER_DISABLE I2C_CR1_ANFOFF | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/* Peripheral Control methods ************************************************/ | |||
HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter); | |||
HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter); | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup I2C_Private_Constants I2C Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup I2C_Private_Macro I2C Private Macros | |||
* @{ | |||
*/ | |||
#define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_ANALOGFILTER_ENABLE) || \ | |||
((FILTER) == I2C_ANALOGFILTER_DISABLE)) | |||
#define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000F) | |||
/** | |||
* @} | |||
*/ | |||
/* Private Functions ---------------------------------------------------------*/ | |||
/** @defgroup I2C_Private_Functions I2C Private Functions | |||
* @{ | |||
*/ | |||
/* Private functions are defined in stm32f7xx_hal_i2c_ex.c file */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_I2C_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,483 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_i2s.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of I2S HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_I2S_H | |||
#define __STM32F7xx_HAL_I2S_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup I2S | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup I2S_Exported_Types I2S Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief I2S Init structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Mode; /*!< Specifies the I2S operating mode. | |||
This parameter can be a value of @ref I2S_Mode */ | |||
uint32_t Standard; /*!< Specifies the standard used for the I2S communication. | |||
This parameter can be a value of @ref I2S_Standard */ | |||
uint32_t DataFormat; /*!< Specifies the data format for the I2S communication. | |||
This parameter can be a value of @ref I2S_Data_Format */ | |||
uint32_t MCLKOutput; /*!< Specifies whether the I2S MCLK output is enabled or not. | |||
This parameter can be a value of @ref I2S_MCLK_Output */ | |||
uint32_t AudioFreq; /*!< Specifies the frequency selected for the I2S communication. | |||
This parameter can be a value of @ref I2S_Audio_Frequency */ | |||
uint32_t CPOL; /*!< Specifies the idle state of the I2S clock. | |||
This parameter can be a value of @ref I2S_Clock_Polarity */ | |||
uint32_t ClockSource; /*!< Specifies the I2S Clock Source. | |||
This parameter can be a value of @ref I2S_Clock_Source */ | |||
}I2S_InitTypeDef; | |||
/** | |||
* @brief HAL State structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_I2S_STATE_RESET = 0x00, /*!< I2S not yet initialized or disabled */ | |||
HAL_I2S_STATE_READY = 0x01, /*!< I2S initialized and ready for use */ | |||
HAL_I2S_STATE_BUSY = 0x02, /*!< I2S internal process is ongoing */ | |||
HAL_I2S_STATE_BUSY_TX = 0x03, /*!< Data Transmission process is ongoing */ | |||
HAL_I2S_STATE_BUSY_RX = 0x04, /*!< Data Reception process is ongoing */ | |||
HAL_I2S_STATE_BUSY_TX_RX = 0x05, /*!< Data Transmission and Reception process is ongoing */ | |||
HAL_I2S_STATE_TIMEOUT = 0x06, /*!< I2S timeout state */ | |||
HAL_I2S_STATE_ERROR = 0x07 /*!< I2S error state */ | |||
}HAL_I2S_StateTypeDef; | |||
/** | |||
* @brief I2S handle Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
SPI_TypeDef *Instance; /* I2S registers base address */ | |||
I2S_InitTypeDef Init; /* I2S communication parameters */ | |||
uint16_t *pTxBuffPtr; /* Pointer to I2S Tx transfer buffer */ | |||
__IO uint16_t TxXferSize; /* I2S Tx transfer size */ | |||
__IO uint16_t TxXferCount; /* I2S Tx transfer Counter */ | |||
uint16_t *pRxBuffPtr; /* Pointer to I2S Rx transfer buffer */ | |||
__IO uint16_t RxXferSize; /* I2S Rx transfer size */ | |||
__IO uint16_t RxXferCount; /* I2S Rx transfer counter | |||
(This field is initialized at the | |||
same value as transfer size at the | |||
beginning of the transfer and | |||
decremented when a sample is received. | |||
NbSamplesReceived = RxBufferSize-RxBufferCount) */ | |||
DMA_HandleTypeDef *hdmatx; /* I2S Tx DMA handle parameters */ | |||
DMA_HandleTypeDef *hdmarx; /* I2S Rx DMA handle parameters */ | |||
__IO HAL_LockTypeDef Lock; /* I2S locking object */ | |||
__IO HAL_I2S_StateTypeDef State; /* I2S communication state */ | |||
__IO uint32_t ErrorCode; /* I2S Error code */ | |||
}I2S_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup I2S_Exported_Constants I2S Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup I2S_Error_Defintion I2S_Error_Defintion | |||
*@brief I2S Error Code | |||
* @{ | |||
*/ | |||
#define HAL_I2S_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */ | |||
#define HAL_I2S_ERROR_TIMEOUT ((uint32_t)0x00000001) /*!< Timeout error */ | |||
#define HAL_I2S_ERROR_OVR ((uint32_t)0x00000002) /*!< OVR error */ | |||
#define HAL_I2S_ERROR_UDR ((uint32_t)0x00000004) /*!< UDR error */ | |||
#define HAL_I2S_ERROR_DMA ((uint32_t)0x00000008) /*!< DMA transfer error */ | |||
#define HAL_I2S_ERROR_UNKNOW ((uint32_t)0x00000010) /*!< Unknow Error error */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2S_Clock_Source I2S Clock Source | |||
* @{ | |||
*/ | |||
#define I2S_CLOCK_EXTERNAL ((uint32_t)0x00000001) | |||
#define I2S_CLOCK_SYSCLK ((uint32_t)0x00000002) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2S_Mode I2S Mode | |||
* @{ | |||
*/ | |||
#define I2S_MODE_SLAVE_TX ((uint32_t)0x00000000) | |||
#define I2S_MODE_SLAVE_RX ((uint32_t)0x00000100) | |||
#define I2S_MODE_MASTER_TX ((uint32_t)0x00000200) | |||
#define I2S_MODE_MASTER_RX ((uint32_t)0x00000300) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2S_Standard I2S Standard | |||
* @{ | |||
*/ | |||
#define I2S_STANDARD_PHILIPS ((uint32_t)0x00000000) | |||
#define I2S_STANDARD_MSB ((uint32_t)0x00000010) | |||
#define I2S_STANDARD_LSB ((uint32_t)0x00000020) | |||
#define I2S_STANDARD_PCM_SHORT ((uint32_t)0x00000030) | |||
#define I2S_STANDARD_PCM_LONG ((uint32_t)0x000000B0) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2S_Data_Format I2S Data Format | |||
* @{ | |||
*/ | |||
#define I2S_DATAFORMAT_16B ((uint32_t)0x00000000) | |||
#define I2S_DATAFORMAT_16B_EXTENDED ((uint32_t)0x00000001) | |||
#define I2S_DATAFORMAT_24B ((uint32_t)0x00000003) | |||
#define I2S_DATAFORMAT_32B ((uint32_t)0x00000005) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2S_MCLK_Output I2S Mclk Output | |||
* @{ | |||
*/ | |||
#define I2S_MCLKOUTPUT_ENABLE ((uint32_t)SPI_I2SPR_MCKOE) | |||
#define I2S_MCLKOUTPUT_DISABLE ((uint32_t)0x00000000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2S_Audio_Frequency I2S Audio Frequency | |||
* @{ | |||
*/ | |||
#define I2S_AUDIOFREQ_192K ((uint32_t)192000) | |||
#define I2S_AUDIOFREQ_96K ((uint32_t)96000) | |||
#define I2S_AUDIOFREQ_48K ((uint32_t)48000) | |||
#define I2S_AUDIOFREQ_44K ((uint32_t)44100) | |||
#define I2S_AUDIOFREQ_32K ((uint32_t)32000) | |||
#define I2S_AUDIOFREQ_22K ((uint32_t)22050) | |||
#define I2S_AUDIOFREQ_16K ((uint32_t)16000) | |||
#define I2S_AUDIOFREQ_11K ((uint32_t)11025) | |||
#define I2S_AUDIOFREQ_8K ((uint32_t)8000) | |||
#define I2S_AUDIOFREQ_DEFAULT ((uint32_t)2) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2S_Clock_Polarity I2S Clock Polarity | |||
* @{ | |||
*/ | |||
#define I2S_CPOL_LOW ((uint32_t)0x00000000) | |||
#define I2S_CPOL_HIGH ((uint32_t)SPI_I2SCFGR_CKPOL) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2S_Interrupts_Definition I2S Interrupts Definition | |||
* @{ | |||
*/ | |||
#define I2S_IT_TXE SPI_CR2_TXEIE | |||
#define I2S_IT_RXNE SPI_CR2_RXNEIE | |||
#define I2S_IT_ERR SPI_CR2_ERRIE | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup I2S_Flags_Definition I2S Flags Definition | |||
* @{ | |||
*/ | |||
#define I2S_FLAG_TXE SPI_SR_TXE | |||
#define I2S_FLAG_RXNE SPI_SR_RXNE | |||
#define I2S_FLAG_UDR SPI_SR_UDR | |||
#define I2S_FLAG_OVR SPI_SR_OVR | |||
#define I2S_FLAG_FRE SPI_SR_FRE | |||
#define I2S_FLAG_CHSIDE SPI_SR_CHSIDE | |||
#define I2S_FLAG_BSY SPI_SR_BSY | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/** @defgroup I2S_Exported_Macros I2S Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset I2S handle state | |||
* @param __HANDLE__: specifies the I2S handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2S_STATE_RESET) | |||
/** @brief Enable or disable the specified SPI peripheral (in I2S mode). | |||
* @param __HANDLE__: specifies the I2S Handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_I2S_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->I2SCFGR |= SPI_I2SCFGR_I2SE) | |||
#define __HAL_I2S_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->I2SCFGR &= ~SPI_I2SCFGR_I2SE) | |||
/** @brief Enable or disable the specified I2S interrupts. | |||
* @param __HANDLE__: specifies the I2S Handle. | |||
* @param __INTERRUPT__: specifies the interrupt source to enable or disable. | |||
* This parameter can be one of the following values: | |||
* @arg I2S_IT_TXE: Tx buffer empty interrupt enable | |||
* @arg I2S_IT_RXNE: RX buffer not empty interrupt enable | |||
* @arg I2S_IT_ERR: Error interrupt enable | |||
* @retval None | |||
*/ | |||
#define __HAL_I2S_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__)) | |||
#define __HAL_I2S_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= ~(__INTERRUPT__)) | |||
/** @brief Checks if the specified I2S interrupt source is enabled or disabled. | |||
* @param __HANDLE__: specifies the I2S Handle. | |||
* This parameter can be I2S where x: 1, 2, or 3 to select the I2S peripheral. | |||
* @param __INTERRUPT__: specifies the I2S interrupt source to check. | |||
* This parameter can be one of the following values: | |||
* @arg I2S_IT_TXE: Tx buffer empty interrupt enable | |||
* @arg I2S_IT_RXNE: RX buffer not empty interrupt enable | |||
* @arg I2S_IT_ERR: Error interrupt enable | |||
* @retval The new state of __IT__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_I2S_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) | |||
/** @brief Checks whether the specified I2S flag is set or not. | |||
* @param __HANDLE__: specifies the I2S Handle. | |||
* @param __FLAG__: specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg I2S_FLAG_RXNE: Receive buffer not empty flag | |||
* @arg I2S_FLAG_TXE: Transmit buffer empty flag | |||
* @arg I2S_FLAG_UDR: Underrun flag | |||
* @arg I2S_FLAG_OVR: Overrun flag | |||
* @arg I2S_FLAG_FRE: Frame error flag | |||
* @arg I2S_FLAG_CHSIDE: Channel Side flag | |||
* @arg I2S_FLAG_BSY: Busy flag | |||
* @retval The new state of __FLAG__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_I2S_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__)) | |||
/** @brief Clears the I2S OVR pending flag. | |||
* @param __HANDLE__: specifies the I2S Handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_I2S_CLEAR_OVRFLAG(__HANDLE__) \ | |||
do{ \ | |||
__IO uint32_t tmpreg; \ | |||
tmpreg = (__HANDLE__)->Instance->DR; \ | |||
tmpreg = (__HANDLE__)->Instance->SR; \ | |||
UNUSED(tmpreg); \ | |||
} while(0) | |||
/** @brief Clears the I2S UDR pending flag. | |||
* @param __HANDLE__: specifies the I2S Handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_I2S_CLEAR_UDRFLAG(__HANDLE__) \ | |||
do{ \ | |||
__IO uint32_t tmpreg; \ | |||
tmpreg = (__HANDLE__)->Instance->SR; \ | |||
UNUSED(tmpreg); \ | |||
} while(0) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup I2S_Exported_Functions I2S Exported Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup I2S_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions *****************************/ | |||
HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s); | |||
HAL_StatusTypeDef HAL_I2S_DeInit (I2S_HandleTypeDef *hi2s); | |||
void HAL_I2S_MspInit(I2S_HandleTypeDef *hi2s); | |||
void HAL_I2S_MspDeInit(I2S_HandleTypeDef *hi2s); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup I2S_Exported_Functions_Group2 Input and Output operation functions | |||
* @{ | |||
*/ | |||
/* I/O operation functions ***************************************************/ | |||
/* Blocking mode: Polling */ | |||
HAL_StatusTypeDef HAL_I2S_Transmit(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_I2S_Receive(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout); | |||
/* Non-Blocking mode: Interrupt */ | |||
HAL_StatusTypeDef HAL_I2S_Transmit_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2S_Receive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size); | |||
void HAL_I2S_IRQHandler(I2S_HandleTypeDef *hi2s); | |||
/* Non-Blocking mode: DMA */ | |||
HAL_StatusTypeDef HAL_I2S_Transmit_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2S_Receive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_I2S_DMAPause(I2S_HandleTypeDef *hi2s); | |||
HAL_StatusTypeDef HAL_I2S_DMAResume(I2S_HandleTypeDef *hi2s); | |||
HAL_StatusTypeDef HAL_I2S_DMAStop(I2S_HandleTypeDef *hi2s); | |||
/* Callbacks used in non blocking modes (Interrupt and DMA) *******************/ | |||
void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s); | |||
void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s); | |||
void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s); | |||
void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s); | |||
void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup I2S_Exported_Functions_Group3 Peripheral State and Errors functions | |||
* @{ | |||
*/ | |||
/* Peripheral Control and State functions ************************************/ | |||
HAL_I2S_StateTypeDef HAL_I2S_GetState(I2S_HandleTypeDef *hi2s); | |||
uint32_t HAL_I2S_GetError(I2S_HandleTypeDef *hi2s); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup I2S_Private_Constants I2S Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup I2S_Private_Macros I2S Private Macros | |||
* @{ | |||
*/ | |||
#define IS_I2S_CLOCKSOURCE(CLOCK) (((CLOCK) == I2S_CLOCK_EXTERNAL) || \ | |||
((CLOCK) == I2S_CLOCK_SYSCLK)) | |||
#define IS_I2S_MODE(MODE) (((MODE) == I2S_MODE_SLAVE_TX) || \ | |||
((MODE) == I2S_MODE_SLAVE_RX) || \ | |||
((MODE) == I2S_MODE_MASTER_TX)|| \ | |||
((MODE) == I2S_MODE_MASTER_RX)) | |||
#define IS_I2S_STANDARD(STANDARD) (((STANDARD) == I2S_STANDARD_PHILIPS) || \ | |||
((STANDARD) == I2S_STANDARD_MSB) || \ | |||
((STANDARD) == I2S_STANDARD_LSB) || \ | |||
((STANDARD) == I2S_STANDARD_PCM_SHORT) || \ | |||
((STANDARD) == I2S_STANDARD_PCM_LONG)) | |||
#define IS_I2S_DATA_FORMAT(FORMAT) (((FORMAT) == I2S_DATAFORMAT_16B) || \ | |||
((FORMAT) == I2S_DATAFORMAT_16B_EXTENDED) || \ | |||
((FORMAT) == I2S_DATAFORMAT_24B) || \ | |||
((FORMAT) == I2S_DATAFORMAT_32B)) | |||
#define IS_I2S_MCLK_OUTPUT(OUTPUT) (((OUTPUT) == I2S_MCLKOUTPUT_ENABLE) || \ | |||
((OUTPUT) == I2S_MCLKOUTPUT_DISABLE)) | |||
#define IS_I2S_AUDIO_FREQ(FREQ) ((((FREQ) >= I2S_AUDIOFREQ_8K) && \ | |||
((FREQ) <= I2S_AUDIOFREQ_192K)) || \ | |||
((FREQ) == I2S_AUDIOFREQ_DEFAULT)) | |||
#define IS_I2S_CPOL(CPOL) (((CPOL) == I2S_CPOL_LOW) || \ | |||
((CPOL) == I2S_CPOL_HIGH)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_I2S_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,326 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_pcd.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of PCD HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_PCD_H | |||
#define __STM32F7xx_HAL_PCD_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_ll_usb.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup PCD | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup PCD_Exported_Types PCD Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief PCD State structure definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_PCD_STATE_RESET = 0x00, | |||
HAL_PCD_STATE_READY = 0x01, | |||
HAL_PCD_STATE_ERROR = 0x02, | |||
HAL_PCD_STATE_BUSY = 0x03, | |||
HAL_PCD_STATE_TIMEOUT = 0x04 | |||
} PCD_StateTypeDef; | |||
/* Device LPM suspend state */ | |||
typedef enum | |||
{ | |||
LPM_L0 = 0x00, /* on */ | |||
LPM_L1 = 0x01, /* LPM L1 sleep */ | |||
LPM_L2 = 0x02, /* suspend */ | |||
LPM_L3 = 0x03, /* off */ | |||
}PCD_LPM_StateTypeDef; | |||
typedef USB_OTG_GlobalTypeDef PCD_TypeDef; | |||
typedef USB_OTG_CfgTypeDef PCD_InitTypeDef; | |||
typedef USB_OTG_EPTypeDef PCD_EPTypeDef ; | |||
/** | |||
* @brief PCD Handle Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
PCD_TypeDef *Instance; /*!< Register base address */ | |||
PCD_InitTypeDef Init; /*!< PCD required parameters */ | |||
PCD_EPTypeDef IN_ep[15]; /*!< IN endpoint parameters */ | |||
PCD_EPTypeDef OUT_ep[15]; /*!< OUT endpoint parameters */ | |||
HAL_LockTypeDef Lock; /*!< PCD peripheral status */ | |||
__IO PCD_StateTypeDef State; /*!< PCD communication state */ | |||
uint32_t Setup[12]; /*!< Setup packet buffer */ | |||
PCD_LPM_StateTypeDef LPM_State; /*!< LPM State */ | |||
uint32_t BESL; | |||
uint32_t lpm_active; /*!< Enable or disable the Link Power Management . | |||
This parameter can be set to ENABLE or DISABLE */ | |||
void *pData; /*!< Pointer to upper stack Handler */ | |||
} PCD_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Include PCD HAL Extension module */ | |||
#include "stm32f7xx_hal_pcd_ex.h" | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup PCD_Exported_Constants PCD Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup PCD_Speed PCD Speed | |||
* @{ | |||
*/ | |||
#define PCD_SPEED_HIGH 0 | |||
#define PCD_SPEED_HIGH_IN_FULL 1 | |||
#define PCD_SPEED_FULL 2 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PCD_PHY_Module PCD PHY Module | |||
* @{ | |||
*/ | |||
#define PCD_PHY_ULPI 1 | |||
#define PCD_PHY_EMBEDDED 2 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PCD_Turnaround_Timeout Turnaround Timeout Value | |||
* @{ | |||
*/ | |||
#ifndef USBD_HS_TRDT_VALUE | |||
#define USBD_HS_TRDT_VALUE 9 | |||
#endif /* USBD_HS_TRDT_VALUE */ | |||
#ifndef USBD_FS_TRDT_VALUE | |||
#define USBD_FS_TRDT_VALUE 5 | |||
#endif /* USBD_HS_TRDT_VALUE */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/** @defgroup PCD_Exported_Macros PCD Exported Macros | |||
* @brief macros to handle interrupts and specific clock configurations | |||
* @{ | |||
*/ | |||
#define __HAL_PCD_ENABLE(__HANDLE__) USB_EnableGlobalInt ((__HANDLE__)->Instance) | |||
#define __HAL_PCD_DISABLE(__HANDLE__) USB_DisableGlobalInt ((__HANDLE__)->Instance) | |||
#define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__)) | |||
#define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->GINTSTS) = (__INTERRUPT__)) | |||
#define __HAL_PCD_IS_INVALID_INTERRUPT(__HANDLE__) (USB_ReadInterrupts((__HANDLE__)->Instance) == 0) | |||
#define __HAL_PCD_UNGATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) &= \ | |||
~(USB_OTG_PCGCCTL_STOPCLK) | |||
#define __HAL_PCD_GATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) |= USB_OTG_PCGCCTL_STOPCLK | |||
#define __HAL_PCD_IS_PHY_SUSPENDED(__HANDLE__) ((*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE))&0x10) | |||
#define USB_OTG_FS_WAKEUP_EXTI_RISING_EDGE ((uint32_t)0x08) | |||
#define USB_OTG_FS_WAKEUP_EXTI_FALLING_EDGE ((uint32_t)0x0C) | |||
#define USB_OTG_FS_WAKEUP_EXTI_RISING_FALLING_EDGE ((uint32_t)0x10) | |||
#define USB_OTG_HS_WAKEUP_EXTI_RISING_EDGE ((uint32_t)0x08) | |||
#define USB_OTG_HS_WAKEUP_EXTI_FALLING_EDGE ((uint32_t)0x0C) | |||
#define USB_OTG_HS_WAKEUP_EXTI_RISING_FALLING_EDGE ((uint32_t)0x10) | |||
#define USB_OTG_HS_WAKEUP_EXTI_LINE ((uint32_t)0x00100000) /*!< External interrupt line 20 Connected to the USB HS EXTI Line */ | |||
#define USB_OTG_FS_WAKEUP_EXTI_LINE ((uint32_t)0x00040000) /*!< External interrupt line 18 Connected to the USB FS EXTI Line */ | |||
#define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= (USB_OTG_HS_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_OTG_HS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_OTG_HS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_HS_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = (USB_OTG_HS_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_EDGE() EXTI->FTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE);\ | |||
EXTI->RTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE | |||
#define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_FALLING_EDGE() EXTI->FTSR |= (USB_OTG_HS_WAKEUP_EXTI_LINE);\ | |||
EXTI->RTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_FALLING_EDGE() EXTI->RTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE);\ | |||
EXTI->FTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE;)\ | |||
EXTI->RTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE;\ | |||
EXTI->FTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE | |||
#define __HAL_USB_OTG_HS_WAKEUP_EXTI_GENERATE_SWIT() (EXTI->SWIER |= USB_OTG_FS_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= USB_OTG_FS_WAKEUP_EXTI_LINE | |||
#define __HAL_USB_OTG_FS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_OTG_FS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_FS_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = USB_OTG_FS_WAKEUP_EXTI_LINE | |||
#define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE() EXTI->FTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE);\ | |||
EXTI->RTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE | |||
#define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_FALLING_EDGE() EXTI->FTSR |= (USB_OTG_FS_WAKEUP_EXTI_LINE);\ | |||
EXTI->RTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_FALLING_EDGE() EXTI->RTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE);\ | |||
EXTI->FTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE);\ | |||
EXTI->RTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE;\ | |||
EXTI->FTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE | |||
#define __HAL_USB_OTG_FS_WAKEUP_EXTI_GENERATE_SWIT() (EXTI->SWIER |= USB_OTG_FS_WAKEUP_EXTI_LINE) | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup PCD_Exported_Functions PCD Exported Functions | |||
* @{ | |||
*/ | |||
/* Initialization/de-initialization functions ********************************/ | |||
/** @addtogroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_DeInit (PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd); | |||
/** | |||
* @} | |||
*/ | |||
/* I/O operation functions ***************************************************/ | |||
/* Non-Blocking mode: Interrupt */ | |||
/** @addtogroup PCD_Exported_Functions_Group2 IO operation functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | |||
void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | |||
void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | |||
void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | |||
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd); | |||
/** | |||
* @} | |||
*/ | |||
/* Peripheral Control functions **********************************************/ | |||
/** @addtogroup PCD_Exported_Functions_Group3 Peripheral Control functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address); | |||
HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type); | |||
HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | |||
HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len); | |||
HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len); | |||
uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | |||
HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | |||
HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | |||
HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | |||
HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd); | |||
/** | |||
* @} | |||
*/ | |||
/* Peripheral State functions ************************************************/ | |||
/** @addtogroup PCD_Exported_Functions_Group4 Peripheral State functions | |||
* @{ | |||
*/ | |||
PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PCD_Instance_definition PCD Instance definition | |||
* @{ | |||
*/ | |||
#define IS_PCD_ALL_INSTANCE(INSTANCE) (((INSTANCE) == USB_OTG_FS) || \ | |||
((INSTANCE) == USB_OTG_HS)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_PCD_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,101 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_pcd_ex.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of PCD HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_PCD_EX_H | |||
#define __STM32F7xx_HAL_PCD_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup PCDEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
typedef enum | |||
{ | |||
PCD_LPM_L0_ACTIVE = 0x00, /* on */ | |||
PCD_LPM_L1_ACTIVE = 0x01, /* LPM L1 sleep */ | |||
}PCD_LPM_MsgTypeDef; | |||
/* Exported constants --------------------------------------------------------*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); | |||
HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); | |||
HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_PCD_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,424 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_pwr.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of PWR HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_PWR_H | |||
#define __STM32F7xx_HAL_PWR_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup PWR | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup PWR_Exported_Types PWR Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief PWR PVD configuration structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level. | |||
This parameter can be a value of @ref PWR_PVD_detection_level */ | |||
uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins. | |||
This parameter can be a value of @ref PWR_PVD_Mode */ | |||
}PWR_PVDTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup PWR_Exported_Constants PWR Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup PWR_PVD_detection_level PWR PVD detection level | |||
* @{ | |||
*/ | |||
#define PWR_PVDLEVEL_0 PWR_CR1_PLS_LEV0 | |||
#define PWR_PVDLEVEL_1 PWR_CR1_PLS_LEV1 | |||
#define PWR_PVDLEVEL_2 PWR_CR1_PLS_LEV2 | |||
#define PWR_PVDLEVEL_3 PWR_CR1_PLS_LEV3 | |||
#define PWR_PVDLEVEL_4 PWR_CR1_PLS_LEV4 | |||
#define PWR_PVDLEVEL_5 PWR_CR1_PLS_LEV5 | |||
#define PWR_PVDLEVEL_6 PWR_CR1_PLS_LEV6 | |||
#define PWR_PVDLEVEL_7 PWR_CR1_PLS_LEV7/* External input analog voltage | |||
(Compare internally to VREFINT) */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_PVD_Mode PWR PVD Mode | |||
* @{ | |||
*/ | |||
#define PWR_PVD_MODE_NORMAL ((uint32_t)0x00000000) /*!< basic mode is used */ | |||
#define PWR_PVD_MODE_IT_RISING ((uint32_t)0x00010001) /*!< External Interrupt Mode with Rising edge trigger detection */ | |||
#define PWR_PVD_MODE_IT_FALLING ((uint32_t)0x00010002) /*!< External Interrupt Mode with Falling edge trigger detection */ | |||
#define PWR_PVD_MODE_IT_RISING_FALLING ((uint32_t)0x00010003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ | |||
#define PWR_PVD_MODE_EVENT_RISING ((uint32_t)0x00020001) /*!< Event Mode with Rising edge trigger detection */ | |||
#define PWR_PVD_MODE_EVENT_FALLING ((uint32_t)0x00020002) /*!< Event Mode with Falling edge trigger detection */ | |||
#define PWR_PVD_MODE_EVENT_RISING_FALLING ((uint32_t)0x00020003) /*!< Event Mode with Rising/Falling edge trigger detection */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_Regulator_state_in_STOP_mode PWR Regulator state in SLEEP/STOP mode | |||
* @{ | |||
*/ | |||
#define PWR_MAINREGULATOR_ON ((uint32_t)0x00000000) | |||
#define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPDS | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry | |||
* @{ | |||
*/ | |||
#define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) | |||
#define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_STOP_mode_entry PWR STOP mode entry | |||
* @{ | |||
*/ | |||
#define PWR_STOPENTRY_WFI ((uint8_t)0x01) | |||
#define PWR_STOPENTRY_WFE ((uint8_t)0x02) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_Regulator_Voltage_Scale PWR Regulator Voltage Scale | |||
* @{ | |||
*/ | |||
#define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR1_VOS | |||
#define PWR_REGULATOR_VOLTAGE_SCALE2 PWR_CR1_VOS_1 | |||
#define PWR_REGULATOR_VOLTAGE_SCALE3 PWR_CR1_VOS_0 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_Flag PWR Flag | |||
* @{ | |||
*/ | |||
#define PWR_FLAG_WU PWR_CSR1_WUIF | |||
#define PWR_FLAG_SB PWR_CSR1_SBF | |||
#define PWR_FLAG_PVDO PWR_CSR1_PVDO | |||
#define PWR_FLAG_BRR PWR_CSR1_BRR | |||
#define PWR_FLAG_VOSRDY PWR_CSR1_VOSRDY | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup PWR_Exported_Macro PWR Exported Macro | |||
* @{ | |||
*/ | |||
/** @brief macros configure the main internal regulator output voltage. | |||
* @param __REGULATOR__: specifies the regulator output voltage to achieve | |||
* a tradeoff between performance and power consumption when the device does | |||
* not operate at the maximum frequency (refer to the datasheets for more details). | |||
* This parameter can be one of the following values: | |||
* @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode | |||
* @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode | |||
* @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode | |||
* @retval None | |||
*/ | |||
#define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do { \ | |||
__IO uint32_t tmpreg; \ | |||
MODIFY_REG(PWR->CR1, PWR_CR1_VOS, (__REGULATOR__)); \ | |||
/* Delay after an RCC peripheral clock enabling */ \ | |||
tmpreg = READ_BIT(PWR->CR1, PWR_CR1_VOS); \ | |||
UNUSED(tmpreg); \ | |||
} while(0) | |||
/** @brief Check PWR flag is set or not. | |||
* @param __FLAG__: specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event | |||
* was received on the internal wakeup line in standby mode (RTC alarm (Alarm A or Alarm B), | |||
* RTC Tamper event, RTC TimeStamp event or RTC Wakeup)). | |||
* @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was | |||
* resumed from StandBy mode. | |||
* @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled | |||
* by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode | |||
* For this reason, this bit is equal to 0 after Standby or reset | |||
* until the PVDE bit is set. | |||
* @arg PWR_FLAG_BRR: Backup regulator ready flag. This bit is not reset | |||
* when the device wakes up from Standby mode or by a system reset | |||
* or power reset. | |||
* @arg PWR_FLAG_VOSRDY: This flag indicates that the Regulator voltage | |||
* scaling output selection is ready. | |||
* @retval The new state of __FLAG__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR1 & (__FLAG__)) == (__FLAG__)) | |||
/** @brief Clear the PWR's pending flags. | |||
* @param __FLAG__: specifies the flag to clear. | |||
* This parameter can be one of the following values: | |||
* @arg PWR_FLAG_SB: StandBy flag | |||
*/ | |||
#define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->CR1 |= (__FLAG__) << 2) | |||
/** | |||
* @brief Enable the PVD Exti Line 16. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_ENABLE_IT() (EXTI->IMR |= (PWR_EXTI_LINE_PVD)) | |||
/** | |||
* @brief Disable the PVD EXTI Line 16. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_DISABLE_IT() (EXTI->IMR &= ~(PWR_EXTI_LINE_PVD)) | |||
/** | |||
* @brief Enable event on PVD Exti Line 16. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() (EXTI->EMR |= (PWR_EXTI_LINE_PVD)) | |||
/** | |||
* @brief Disable event on PVD Exti Line 16. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(PWR_EXTI_LINE_PVD)) | |||
/** | |||
* @brief Enable the PVD Extended Interrupt Rising Trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief Disable the PVD Extended Interrupt Rising Trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief Enable the PVD Extended Interrupt Falling Trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief Disable the PVD Extended Interrupt Falling Trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief PVD EXTI line configuration: set rising & falling edge trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); | |||
/** | |||
* @brief Disable the PVD Extended Interrupt Rising & Falling Trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); | |||
/** | |||
* @brief checks whether the specified PVD Exti interrupt flag is set or not. | |||
* @retval EXTI PVD Line Status. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR & (PWR_EXTI_LINE_PVD)) | |||
/** | |||
* @brief Clear the PVD Exti flag. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() (EXTI->PR = (PWR_EXTI_LINE_PVD)) | |||
/** | |||
* @brief Generates a Software interrupt on PVD EXTI line. | |||
* @retval None | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() (EXTI->SWIER |= (PWR_EXTI_LINE_PVD)) | |||
/** | |||
* @} | |||
*/ | |||
/* Include PWR HAL Extension module */ | |||
#include "stm32f7xx_hal_pwr_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup PWR_Exported_Functions PWR Exported Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions *****************************/ | |||
void HAL_PWR_DeInit(void); | |||
void HAL_PWR_EnableBkUpAccess(void); | |||
void HAL_PWR_DisableBkUpAccess(void); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions **********************************************/ | |||
/* PVD configuration */ | |||
void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD); | |||
void HAL_PWR_EnablePVD(void); | |||
void HAL_PWR_DisablePVD(void); | |||
/* WakeUp pins configuration */ | |||
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity); | |||
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx); | |||
/* Low Power modes entry */ | |||
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry); | |||
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry); | |||
void HAL_PWR_EnterSTANDBYMode(void); | |||
/* Power PVD IRQ Handler */ | |||
void HAL_PWR_PVD_IRQHandler(void); | |||
void HAL_PWR_PVDCallback(void); | |||
/* Cortex System Control functions *******************************************/ | |||
void HAL_PWR_EnableSleepOnExit(void); | |||
void HAL_PWR_DisableSleepOnExit(void); | |||
void HAL_PWR_EnableSEVOnPend(void); | |||
void HAL_PWR_DisableSEVOnPend(void); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup PWR_Private_Constants PWR Private Constants | |||
* @{ | |||
*/ | |||
/** @defgroup PWR_PVD_EXTI_Line PWR PVD EXTI Line | |||
* @{ | |||
*/ | |||
#define PWR_EXTI_LINE_PVD ((uint32_t)EXTI_IMR_MR16) /*!< External interrupt line 16 Connected to the PVD EXTI Line */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup PWR_Private_Macros PWR Private Macros | |||
* @{ | |||
*/ | |||
/** @defgroup PWR_IS_PWR_Definitions PWR Private macros to check input parameters | |||
* @{ | |||
*/ | |||
#define IS_PWR_WAKEUP_POLARITY(POLARITY) (((POLARITY) == PWR_POLARITY_RISINGEDGE) || \ | |||
((POLARITY) == PWR_POLARITY_FALLINGEDGE)) | |||
#define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \ | |||
((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \ | |||
((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \ | |||
((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7)) | |||
#define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING)|| ((MODE) == PWR_PVD_MODE_IT_FALLING) || \ | |||
((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \ | |||
((MODE) == PWR_PVD_MODE_EVENT_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) || \ | |||
((MODE) == PWR_PVD_MODE_NORMAL)) | |||
#define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \ | |||
((REGULATOR) == PWR_LOWPOWERREGULATOR_ON)) | |||
#define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE)) | |||
#define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE)) | |||
#define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \ | |||
((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \ | |||
((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE3)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_PWR_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,280 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_pwr_ex.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of PWR HAL Extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_PWR_EX_H | |||
#define __STM32F7xx_HAL_PWR_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup PWREx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup PWREx_Exported_Constants PWREx Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup PWREx_WakeUp_Pins PWREx Wake Up Pins | |||
* @{ | |||
*/ | |||
#define PWR_WAKEUP_PIN1 PWR_CSR2_EWUP1 | |||
#define PWR_WAKEUP_PIN2 PWR_CSR2_EWUP2 | |||
#define PWR_WAKEUP_PIN3 PWR_CSR2_EWUP3 | |||
#define PWR_WAKEUP_PIN4 PWR_CSR2_EWUP4 | |||
#define PWR_WAKEUP_PIN5 PWR_CSR2_EWUP5 | |||
#define PWR_WAKEUP_PIN6 PWR_CSR2_EWUP6 | |||
#define PWR_WAKEUP_PIN1_HIGH PWR_CSR2_EWUP1 | |||
#define PWR_WAKEUP_PIN2_HIGH PWR_CSR2_EWUP2 | |||
#define PWR_WAKEUP_PIN3_HIGH PWR_CSR2_EWUP3 | |||
#define PWR_WAKEUP_PIN4_HIGH PWR_CSR2_EWUP4 | |||
#define PWR_WAKEUP_PIN5_HIGH PWR_CSR2_EWUP5 | |||
#define PWR_WAKEUP_PIN6_HIGH PWR_CSR2_EWUP6 | |||
#define PWR_WAKEUP_PIN1_LOW (uint32_t)((PWR_CR2_WUPP1<<6) | PWR_CSR2_EWUP1) | |||
#define PWR_WAKEUP_PIN2_LOW (uint32_t)((PWR_CR2_WUPP2<<6) | PWR_CSR2_EWUP2) | |||
#define PWR_WAKEUP_PIN3_LOW (uint32_t)((PWR_CR2_WUPP3<<6) | PWR_CSR2_EWUP3) | |||
#define PWR_WAKEUP_PIN4_LOW (uint32_t)((PWR_CR2_WUPP4<<6) | PWR_CSR2_EWUP4) | |||
#define PWR_WAKEUP_PIN5_LOW (uint32_t)((PWR_CR2_WUPP5<<6) | PWR_CSR2_EWUP5) | |||
#define PWR_WAKEUP_PIN6_LOW (uint32_t)((PWR_CR2_WUPP6<<6) | PWR_CSR2_EWUP6) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWREx_Regulator_state_in_UnderDrive_mode PWREx Regulator state in UnderDrive mode | |||
* @{ | |||
*/ | |||
#define PWR_MAINREGULATOR_UNDERDRIVE_ON PWR_CR1_MRUDS | |||
#define PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON ((uint32_t)(PWR_CR1_LPDS | PWR_CR1_LPUDS)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWREx_Over_Under_Drive_Flag PWREx Over Under Drive Flag | |||
* @{ | |||
*/ | |||
#define PWR_FLAG_ODRDY PWR_CSR1_ODRDY | |||
#define PWR_FLAG_ODSWRDY PWR_CSR1_ODSWRDY | |||
#define PWR_FLAG_UDRDY PWR_CSR1_UDSWRDY | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWREx_Wakeup_Pins_Flag PWREx Wake Up Pin Flags | |||
* @{ | |||
*/ | |||
#define PWR_WAKEUP_PIN_FLAG1 PWR_CSR2_WUPF1 | |||
#define PWR_WAKEUP_PIN_FLAG2 PWR_CSR2_WUPF2 | |||
#define PWR_WAKEUP_PIN_FLAG3 PWR_CSR2_WUPF3 | |||
#define PWR_WAKEUP_PIN_FLAG4 PWR_CSR2_WUPF4 | |||
#define PWR_WAKEUP_PIN_FLAG5 PWR_CSR2_WUPF5 | |||
#define PWR_WAKEUP_PIN_FLAG6 PWR_CSR2_WUPF6 | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup PWREx_Exported_Macro PWREx Exported Macro | |||
* @{ | |||
*/ | |||
/** @brief Macros to enable or disable the Over drive mode. | |||
*/ | |||
#define __HAL_PWR_OVERDRIVE_ENABLE() (PWR->CR1 |= (uint32_t)PWR_CR1_ODEN) | |||
#define __HAL_PWR_OVERDRIVE_DISABLE() (PWR->CR1 &= (uint32_t)(~PWR_CR1_ODEN)) | |||
/** @brief Macros to enable or disable the Over drive switching. | |||
*/ | |||
#define __HAL_PWR_OVERDRIVESWITCHING_ENABLE() (PWR->CR1 |= (uint32_t)PWR_CR1_ODSWEN) | |||
#define __HAL_PWR_OVERDRIVESWITCHING_DISABLE() (PWR->CR1 &= (uint32_t)(~PWR_CR1_ODSWEN)) | |||
/** @brief Macros to enable or disable the Under drive mode. | |||
* @note This mode is enabled only with STOP low power mode. | |||
* In this mode, the 1.2V domain is preserved in reduced leakage mode. This | |||
* mode is only available when the main regulator or the low power regulator | |||
* is in low voltage mode. | |||
* @note If the Under-drive mode was enabled, it is automatically disabled after | |||
* exiting Stop mode. | |||
* When the voltage regulator operates in Under-drive mode, an additional | |||
* startup delay is induced when waking up from Stop mode. | |||
*/ | |||
#define __HAL_PWR_UNDERDRIVE_ENABLE() (PWR->CR1 |= (uint32_t)PWR_CR1_UDEN) | |||
#define __HAL_PWR_UNDERDRIVE_DISABLE() (PWR->CR1 &= (uint32_t)(~PWR_CR1_UDEN)) | |||
/** @brief Check PWR flag is set or not. | |||
* @param __FLAG__: specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg PWR_FLAG_ODRDY: This flag indicates that the Over-drive mode | |||
* is ready | |||
* @arg PWR_FLAG_ODSWRDY: This flag indicates that the Over-drive mode | |||
* switching is ready | |||
* @arg PWR_FLAG_UDRDY: This flag indicates that the Under-drive mode | |||
* is enabled in Stop mode | |||
* @retval The new state of __FLAG__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_PWR_GET_ODRUDR_FLAG(__FLAG__) ((PWR->CSR1 & (__FLAG__)) == (__FLAG__)) | |||
/** @brief Clear the Under-Drive Ready flag. | |||
*/ | |||
#define __HAL_PWR_CLEAR_ODRUDR_FLAG() (PWR->CSR1 |= PWR_FLAG_UDRDY) | |||
/** @brief Check Wake Up flag is set or not. | |||
* @param __WUFLAG__: specifies the Wake Up flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg PWR_WAKEUP_PIN_FLAG1: Wakeup Pin Flag for PA0 | |||
* @arg PWR_WAKEUP_PIN_FLAG2: Wakeup Pin Flag for PA2 | |||
* @arg PWR_WAKEUP_PIN_FLAG3: Wakeup Pin Flag for PC1 | |||
* @arg PWR_WAKEUP_PIN_FLAG4: Wakeup Pin Flag for PC13 | |||
* @arg PWR_WAKEUP_PIN_FLAG5: Wakeup Pin Flag for PI8 | |||
* @arg PWR_WAKEUP_PIN_FLAG6: Wakeup Pin Flag for PI11 | |||
*/ | |||
#define __HAL_PWR_GET_WAKEUP_FLAG(__WUFLAG__) (PWR->CSR2 & (__WUFLAG__)) | |||
/** @brief Clear the WakeUp pins flags. | |||
* @param __WUFLAG__: specifies the Wake Up pin flag to clear. | |||
* This parameter can be one of the following values: | |||
* @arg PWR_WAKEUP_PIN_FLAG1: Wakeup Pin Flag for PA0 | |||
* @arg PWR_WAKEUP_PIN_FLAG2: Wakeup Pin Flag for PA2 | |||
* @arg PWR_WAKEUP_PIN_FLAG3: Wakeup Pin Flag for PC1 | |||
* @arg PWR_WAKEUP_PIN_FLAG4: Wakeup Pin Flag for PC13 | |||
* @arg PWR_WAKEUP_PIN_FLAG5: Wakeup Pin Flag for PI8 | |||
* @arg PWR_WAKEUP_PIN_FLAG6: Wakeup Pin Flag for PI11 | |||
*/ | |||
#define __HAL_PWR_CLEAR_WAKEUP_FLAG(__WUFLAG__) (PWR->CR2 |= (__WUFLAG__)) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup PWREx_Exported_Functions PWREx Exported Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup PWREx_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
uint32_t HAL_PWREx_GetVoltageRange(void); | |||
HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling); | |||
void HAL_PWREx_EnableFlashPowerDown(void); | |||
void HAL_PWREx_DisableFlashPowerDown(void); | |||
HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void); | |||
HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void); | |||
void HAL_PWREx_EnableMainRegulatorLowVoltage(void); | |||
void HAL_PWREx_DisableMainRegulatorLowVoltage(void); | |||
void HAL_PWREx_EnableLowRegulatorLowVoltage(void); | |||
void HAL_PWREx_DisableLowRegulatorLowVoltage(void); | |||
HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void); | |||
HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void); | |||
HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup PWREx_Private_Macros PWREx Private Macros | |||
* @{ | |||
*/ | |||
/** @defgroup PWREx_IS_PWR_Definitions PWREx Private macros to check input parameters | |||
* @{ | |||
*/ | |||
#define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_UNDERDRIVE_ON) || \ | |||
((REGULATOR) == PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON)) | |||
#define IS_PWR_WAKEUP_PIN(__PIN__) (((__PIN__) == PWR_WAKEUP_PIN1) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN2) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN3) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN4) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN5) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN6) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN1_HIGH) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN2_HIGH) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN3_HIGH) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN4_HIGH) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN5_HIGH) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN6_HIGH) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN1_LOW) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN2_LOW) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN3_LOW) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN4_LOW) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN5_LOW) || \ | |||
((__PIN__) == PWR_WAKEUP_PIN6_LOW)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_PWR_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,358 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_rng.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of RNG HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_RNG_H | |||
#define __STM32F7xx_HAL_RNG_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup RNG RNG | |||
* @brief RNG HAL module driver | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup RNG_Exported_Types RNG Exported Types | |||
* @{ | |||
*/ | |||
/** @defgroup RNG_Exported_Types_Group1 RNG State Structure definition | |||
* @{ | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_RNG_STATE_RESET = 0x00, /*!< RNG not yet initialized or disabled */ | |||
HAL_RNG_STATE_READY = 0x01, /*!< RNG initialized and ready for use */ | |||
HAL_RNG_STATE_BUSY = 0x02, /*!< RNG internal process is ongoing */ | |||
HAL_RNG_STATE_TIMEOUT = 0x03, /*!< RNG timeout state */ | |||
HAL_RNG_STATE_ERROR = 0x04 /*!< RNG error state */ | |||
}HAL_RNG_StateTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RNG_Exported_Types_Group2 RNG Handle Structure definition | |||
* @{ | |||
*/ | |||
typedef struct | |||
{ | |||
RNG_TypeDef *Instance; /*!< Register base address */ | |||
uint32_t RandomNumber; /*!< Last Generated random number */ | |||
HAL_LockTypeDef Lock; /*!< RNG locking object */ | |||
__IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */ | |||
}RNG_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup RNG_Exported_Constants RNG Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition | |||
* @{ | |||
*/ | |||
#define RNG_IT_DRDY RNG_SR_DRDY /*!< Data Ready interrupt */ | |||
#define RNG_IT_CEI RNG_SR_CEIS /*!< Clock error interrupt */ | |||
#define RNG_IT_SEI RNG_SR_SEIS /*!< Seed error interrupt */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition | |||
* @{ | |||
*/ | |||
#define RNG_FLAG_DRDY RNG_SR_DRDY /*!< Data ready */ | |||
#define RNG_FLAG_CECS RNG_SR_CECS /*!< Clock error current status */ | |||
#define RNG_FLAG_SECS RNG_SR_SECS /*!< Seed error current status */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/** @defgroup RNG_Exported_Macros RNG Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset RNG handle state | |||
* @param __HANDLE__: RNG Handle | |||
* @retval None | |||
*/ | |||
#define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET) | |||
/** | |||
* @brief Enables the RNG peripheral. | |||
* @param __HANDLE__: RNG Handle | |||
* @retval None | |||
*/ | |||
#define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN) | |||
/** | |||
* @brief Disables the RNG peripheral. | |||
* @param __HANDLE__: RNG Handle | |||
* @retval None | |||
*/ | |||
#define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN) | |||
/** | |||
* @brief Check the selected RNG flag status. | |||
* @param __HANDLE__: RNG Handle | |||
* @param __FLAG__: RNG flag | |||
* This parameter can be one of the following values: | |||
* @arg RNG_FLAG_DRDY: Data ready | |||
* @arg RNG_FLAG_CECS: Clock error current status | |||
* @arg RNG_FLAG_SECS: Seed error current status | |||
* @retval The new state of __FLAG__ (SET or RESET). | |||
*/ | |||
#define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) | |||
/** | |||
* @brief Clears the selected RNG flag status. | |||
* @param __HANDLE__: RNG handle | |||
* @param __FLAG__: RNG flag to clear | |||
* @note WARNING: This is a dummy macro for HAL code alignment, | |||
* flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only. | |||
* @retval None | |||
*/ | |||
#define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */ | |||
/** | |||
* @brief Enables the RNG interrupts. | |||
* @param __HANDLE__: RNG Handle | |||
* @retval None | |||
*/ | |||
#define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE) | |||
/** | |||
* @brief Disables the RNG interrupts. | |||
* @param __HANDLE__: RNG Handle | |||
* @retval None | |||
*/ | |||
#define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE) | |||
/** | |||
* @brief Checks whether the specified RNG interrupt has occurred or not. | |||
* @param __HANDLE__: RNG Handle | |||
* @param __INTERRUPT__: specifies the RNG interrupt status flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg RNG_IT_DRDY: Data ready interrupt | |||
* @arg RNG_IT_CEI: Clock error interrupt | |||
* @arg RNG_IT_SEI: Seed error interrupt | |||
* @retval The new state of __INTERRUPT__ (SET or RESET). | |||
*/ | |||
#define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__)) | |||
/** | |||
* @brief Clear the RNG interrupt status flags. | |||
* @param __HANDLE__: RNG Handle | |||
* @param __INTERRUPT__: specifies the RNG interrupt status flag to clear. | |||
* This parameter can be one of the following values: | |||
* @arg RNG_IT_CEI: Clock error interrupt | |||
* @arg RNG_IT_SEI: Seed error interrupt | |||
* @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY. | |||
* @retval None | |||
*/ | |||
#define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__)) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup RNG_Exported_Functions RNG Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup RNG_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng); | |||
HAL_StatusTypeDef HAL_RNG_DeInit (RNG_HandleTypeDef *hrng); | |||
void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng); | |||
void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions | |||
* @{ | |||
*/ | |||
uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber() instead */ | |||
uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber_IT() instead */ | |||
HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit); | |||
HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng); | |||
uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng); | |||
void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng); | |||
void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng); | |||
void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef* hrng, uint32_t random32bit); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions | |||
* @{ | |||
*/ | |||
HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/** @defgroup RNG_Private_Types RNG Private Types | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private defines -----------------------------------------------------------*/ | |||
/** @defgroup RNG_Private_Defines RNG Private Defines | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/** @defgroup RNG_Private_Variables RNG Private Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup RNG_Private_Constants RNG Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup RNG_Private_Macros RNG Private Macros | |||
* @{ | |||
*/ | |||
#define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \ | |||
((IT) == RNG_IT_SEI)) | |||
#define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \ | |||
((FLAG) == RNG_FLAG_CECS) || \ | |||
((FLAG) == RNG_FLAG_SECS)) | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions prototypes ----------------------------------------------*/ | |||
/** @defgroup RNG_Private_Functions_Prototypes RNG Private Functions Prototypes | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup RNG_Private_Functions RNG Private Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_RNG_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,806 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_rtc.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of RTC HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_RTC_H | |||
#define __STM32F7xx_HAL_RTC_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup RTC | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup RTC_Exported_Types RTC Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief HAL State structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_RTC_STATE_RESET = 0x00, /*!< RTC not yet initialized or disabled */ | |||
HAL_RTC_STATE_READY = 0x01, /*!< RTC initialized and ready for use */ | |||
HAL_RTC_STATE_BUSY = 0x02, /*!< RTC process is ongoing */ | |||
HAL_RTC_STATE_TIMEOUT = 0x03, /*!< RTC timeout state */ | |||
HAL_RTC_STATE_ERROR = 0x04 /*!< RTC error state */ | |||
}HAL_RTCStateTypeDef; | |||
/** | |||
* @brief RTC Configuration Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t HourFormat; /*!< Specifies the RTC Hour Format. | |||
This parameter can be a value of @ref RTC_Hour_Formats */ | |||
uint32_t AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value. | |||
This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */ | |||
uint32_t SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value. | |||
This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */ | |||
uint32_t OutPut; /*!< Specifies which signal will be routed to the RTC output. | |||
This parameter can be a value of @ref RTCEx_Output_selection_Definitions */ | |||
uint32_t OutPutPolarity; /*!< Specifies the polarity of the output signal. | |||
This parameter can be a value of @ref RTC_Output_Polarity_Definitions */ | |||
uint32_t OutPutType; /*!< Specifies the RTC Output Pin mode. | |||
This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */ | |||
}RTC_InitTypeDef; | |||
/** | |||
* @brief RTC Time structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint8_t Hours; /*!< Specifies the RTC Time Hour. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */ | |||
uint8_t Minutes; /*!< Specifies the RTC Time Minutes. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ | |||
uint8_t Seconds; /*!< Specifies the RTC Time Seconds. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ | |||
uint32_t SubSeconds; /*!< Specifies the RTC Time SubSeconds. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ | |||
uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time. | |||
This parameter can be a value of @ref RTC_AM_PM_Definitions */ | |||
uint32_t DayLightSaving; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment. | |||
This parameter can be a value of @ref RTC_DayLightSaving_Definitions */ | |||
uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BCK bit | |||
in CR register to store the operation. | |||
This parameter can be a value of @ref RTC_StoreOperation_Definitions */ | |||
}RTC_TimeTypeDef; | |||
/** | |||
* @brief RTC Date structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. | |||
This parameter can be a value of @ref RTC_WeekDay_Definitions */ | |||
uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). | |||
This parameter can be a value of @ref RTC_Month_Date_Definitions */ | |||
uint8_t Date; /*!< Specifies the RTC Date. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 31 */ | |||
uint8_t Year; /*!< Specifies the RTC Date Year. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 99 */ | |||
}RTC_DateTypeDef; | |||
/** | |||
* @brief RTC Alarm structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */ | |||
uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. | |||
This parameter can be a value of @ref RTC_AlarmMask_Definitions */ | |||
uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks. | |||
This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */ | |||
uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. | |||
This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ | |||
uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. | |||
If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range. | |||
If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */ | |||
uint32_t Alarm; /*!< Specifies the alarm . | |||
This parameter can be a value of @ref RTC_Alarms_Definitions */ | |||
}RTC_AlarmTypeDef; | |||
/** | |||
* @brief RTC Handle Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
RTC_TypeDef *Instance; /*!< Register base address */ | |||
RTC_InitTypeDef Init; /*!< RTC required parameters */ | |||
HAL_LockTypeDef Lock; /*!< RTC locking object */ | |||
__IO HAL_RTCStateTypeDef State; /*!< Time communication state */ | |||
}RTC_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup RTC_Exported_Constants RTC Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup RTC_Hour_Formats RTC Hour Formats | |||
* @{ | |||
*/ | |||
#define RTC_HOURFORMAT_24 ((uint32_t)0x00000000) | |||
#define RTC_HOURFORMAT_12 ((uint32_t)0x00000040) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions | |||
* @{ | |||
*/ | |||
#define RTC_OUTPUT_POLARITY_HIGH ((uint32_t)0x00000000) | |||
#define RTC_OUTPUT_POLARITY_LOW ((uint32_t)0x00100000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT | |||
* @{ | |||
*/ | |||
#define RTC_OUTPUT_TYPE_OPENDRAIN ((uint32_t)0x00000000) | |||
#define RTC_OUTPUT_TYPE_PUSHPULL ((uint32_t)RTC_OR_ALARMTYPE) /* 0x00000008 */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions | |||
* @{ | |||
*/ | |||
#define RTC_HOURFORMAT12_AM ((uint8_t)0x00) | |||
#define RTC_HOURFORMAT12_PM ((uint8_t)0x40) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions | |||
* @{ | |||
*/ | |||
#define RTC_DAYLIGHTSAVING_SUB1H ((uint32_t)0x00020000) | |||
#define RTC_DAYLIGHTSAVING_ADD1H ((uint32_t)0x00010000) | |||
#define RTC_DAYLIGHTSAVING_NONE ((uint32_t)0x00000000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions | |||
* @{ | |||
*/ | |||
#define RTC_STOREOPERATION_RESET ((uint32_t)0x00000000) | |||
#define RTC_STOREOPERATION_SET ((uint32_t)0x00040000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions | |||
* @{ | |||
*/ | |||
#define RTC_FORMAT_BIN ((uint32_t)0x000000000) | |||
#define RTC_FORMAT_BCD ((uint32_t)0x000000001) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions | |||
* @{ | |||
*/ | |||
/* Coded in BCD format */ | |||
#define RTC_MONTH_JANUARY ((uint8_t)0x01) | |||
#define RTC_MONTH_FEBRUARY ((uint8_t)0x02) | |||
#define RTC_MONTH_MARCH ((uint8_t)0x03) | |||
#define RTC_MONTH_APRIL ((uint8_t)0x04) | |||
#define RTC_MONTH_MAY ((uint8_t)0x05) | |||
#define RTC_MONTH_JUNE ((uint8_t)0x06) | |||
#define RTC_MONTH_JULY ((uint8_t)0x07) | |||
#define RTC_MONTH_AUGUST ((uint8_t)0x08) | |||
#define RTC_MONTH_SEPTEMBER ((uint8_t)0x09) | |||
#define RTC_MONTH_OCTOBER ((uint8_t)0x10) | |||
#define RTC_MONTH_NOVEMBER ((uint8_t)0x11) | |||
#define RTC_MONTH_DECEMBER ((uint8_t)0x12) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions | |||
* @{ | |||
*/ | |||
#define RTC_WEEKDAY_MONDAY ((uint8_t)0x01) | |||
#define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02) | |||
#define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03) | |||
#define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04) | |||
#define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05) | |||
#define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06) | |||
#define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions | |||
* @{ | |||
*/ | |||
#define RTC_ALARMDATEWEEKDAYSEL_DATE ((uint32_t)0x00000000) | |||
#define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY ((uint32_t)0x40000000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions | |||
* @{ | |||
*/ | |||
#define RTC_ALARMMASK_NONE ((uint32_t)0x00000000) | |||
#define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4 | |||
#define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3 | |||
#define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2 | |||
#define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1 | |||
#define RTC_ALARMMASK_ALL ((uint32_t)0x80808080) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions | |||
* @{ | |||
*/ | |||
#define RTC_ALARM_A RTC_CR_ALRAE | |||
#define RTC_ALARM_B RTC_CR_ALRBE | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions | |||
* @{ | |||
*/ | |||
#define RTC_ALARMSUBSECONDMASK_ALL ((uint32_t)0x00000000) /*!< All Alarm SS fields are masked. | |||
There is no comparison on sub seconds | |||
for Alarm */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_1 ((uint32_t)0x01000000) /*!< SS[14:1] are don't care in Alarm | |||
comparison. Only SS[0] is compared. */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_2 ((uint32_t)0x02000000) /*!< SS[14:2] are don't care in Alarm | |||
comparison. Only SS[1:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_3 ((uint32_t)0x03000000) /*!< SS[14:3] are don't care in Alarm | |||
comparison. Only SS[2:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_4 ((uint32_t)0x04000000) /*!< SS[14:4] are don't care in Alarm | |||
comparison. Only SS[3:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_5 ((uint32_t)0x05000000) /*!< SS[14:5] are don't care in Alarm | |||
comparison. Only SS[4:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_6 ((uint32_t)0x06000000) /*!< SS[14:6] are don't care in Alarm | |||
comparison. Only SS[5:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_7 ((uint32_t)0x07000000) /*!< SS[14:7] are don't care in Alarm | |||
comparison. Only SS[6:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_8 ((uint32_t)0x08000000) /*!< SS[14:8] are don't care in Alarm | |||
comparison. Only SS[7:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_9 ((uint32_t)0x09000000) /*!< SS[14:9] are don't care in Alarm | |||
comparison. Only SS[8:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_10 ((uint32_t)0x0A000000) /*!< SS[14:10] are don't care in Alarm | |||
comparison. Only SS[9:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_11 ((uint32_t)0x0B000000) /*!< SS[14:11] are don't care in Alarm | |||
comparison. Only SS[10:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_12 ((uint32_t)0x0C000000) /*!< SS[14:12] are don't care in Alarm | |||
comparison.Only SS[11:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14_13 ((uint32_t)0x0D000000) /*!< SS[14:13] are don't care in Alarm | |||
comparison. Only SS[12:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_SS14 ((uint32_t)0x0E000000) /*!< SS[14] is don't care in Alarm | |||
comparison.Only SS[13:0] are compared */ | |||
#define RTC_ALARMSUBSECONDMASK_NONE ((uint32_t)0x0F000000) /*!< SS[14:0] are compared and must match | |||
to activate alarm. */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions | |||
* @{ | |||
*/ | |||
#define RTC_IT_TS ((uint32_t)RTC_CR_TSIE) | |||
#define RTC_IT_WUT ((uint32_t)RTC_CR_WUTIE) | |||
#define RTC_IT_ALRA ((uint32_t)RTC_CR_ALRAIE) | |||
#define RTC_IT_ALRB ((uint32_t)RTC_CR_ALRBIE) | |||
#define RTC_IT_TAMP ((uint32_t)RTC_TAMPCR_TAMPIE) /* Used only to Enable the Tamper Interrupt */ | |||
#define RTC_IT_TAMP1 ((uint32_t)RTC_TAMPCR_TAMP1IE) | |||
#define RTC_IT_TAMP2 ((uint32_t)RTC_TAMPCR_TAMP2IE) | |||
#define RTC_IT_TAMP3 ((uint32_t)RTC_TAMPCR_TAMP3IE) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Flags_Definitions RTC Flags Definitions | |||
* @{ | |||
*/ | |||
#define RTC_FLAG_RECALPF ((uint32_t)RTC_ISR_RECALPF) | |||
#define RTC_FLAG_TAMP3F ((uint32_t)RTC_ISR_TAMP3F) | |||
#define RTC_FLAG_TAMP2F ((uint32_t)RTC_ISR_TAMP2F) | |||
#define RTC_FLAG_TAMP1F ((uint32_t)RTC_ISR_TAMP1F) | |||
#define RTC_FLAG_TSOVF ((uint32_t)RTC_ISR_TSOVF) | |||
#define RTC_FLAG_TSF ((uint32_t)RTC_ISR_TSF) | |||
#define RTC_FLAG_ITSF ((uint32_t)RTC_ISR_ITSF) | |||
#define RTC_FLAG_WUTF ((uint32_t)RTC_ISR_WUTF) | |||
#define RTC_FLAG_ALRBF ((uint32_t)RTC_ISR_ALRBF) | |||
#define RTC_FLAG_ALRAF ((uint32_t)RTC_ISR_ALRAF) | |||
#define RTC_FLAG_INITF ((uint32_t)RTC_ISR_INITF) | |||
#define RTC_FLAG_RSF ((uint32_t)RTC_ISR_RSF) | |||
#define RTC_FLAG_INITS ((uint32_t)RTC_ISR_INITS) | |||
#define RTC_FLAG_SHPF ((uint32_t)RTC_ISR_SHPF) | |||
#define RTC_FLAG_WUTWF ((uint32_t)RTC_ISR_WUTWF) | |||
#define RTC_FLAG_ALRBWF ((uint32_t)RTC_ISR_ALRBWF) | |||
#define RTC_FLAG_ALRAWF ((uint32_t)RTC_ISR_ALRAWF) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup RTC_Exported_Macros RTC Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset RTC handle state | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET) | |||
/** | |||
* @brief Disable the write protection for RTC registers. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \ | |||
do{ \ | |||
(__HANDLE__)->Instance->WPR = 0xCA; \ | |||
(__HANDLE__)->Instance->WPR = 0x53; \ | |||
} while(0) | |||
/** | |||
* @brief Enable the write protection for RTC registers. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \ | |||
do{ \ | |||
(__HANDLE__)->Instance->WPR = 0xFF; \ | |||
} while(0) | |||
/** | |||
* @brief Enable the RTC ALARMA peripheral. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE)) | |||
/** | |||
* @brief Disable the RTC ALARMA peripheral. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE)) | |||
/** | |||
* @brief Enable the RTC ALARMB peripheral. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE)) | |||
/** | |||
* @brief Disable the RTC ALARMB peripheral. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE)) | |||
/** | |||
* @brief Enable the RTC Alarm interrupt. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @param __INTERRUPT__: specifies the RTC Alarm interrupt sources to be enabled or disabled. | |||
* This parameter can be any combination of the following values: | |||
* @arg RTC_IT_ALRA: Alarm A interrupt | |||
* @arg RTC_IT_ALRB: Alarm B interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) | |||
/** | |||
* @brief Disable the RTC Alarm interrupt. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @param __INTERRUPT__: specifies the RTC Alarm interrupt sources to be enabled or disabled. | |||
* This parameter can be any combination of the following values: | |||
* @arg RTC_IT_ALRA: Alarm A interrupt | |||
* @arg RTC_IT_ALRB: Alarm B interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) | |||
/** | |||
* @brief Check whether the specified RTC Alarm interrupt has occurred or not. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @param __INTERRUPT__: specifies the RTC Alarm interrupt to check. | |||
* This parameter can be: | |||
* @arg RTC_IT_ALRA: Alarm A interrupt | |||
* @arg RTC_IT_ALRB: Alarm B interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) ((((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4)) & 0x0000FFFF) != RESET)? SET : RESET) | |||
/** | |||
* @brief Get the selected RTC Alarm's flag status. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @param __FLAG__: specifies the RTC Alarm Flag to check. | |||
* This parameter can be: | |||
* @arg RTC_FLAG_ALRAF | |||
* @arg RTC_FLAG_ALRBF | |||
* @arg RTC_FLAG_ALRAWF | |||
* @arg RTC_FLAG_ALRBWF | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET) | |||
/** | |||
* @brief Clear the RTC Alarm's pending flags. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @param __FLAG__: specifies the RTC Alarm Flag sources to be enabled or disabled. | |||
* This parameter can be: | |||
* @arg RTC_FLAG_ALRAF | |||
* @arg RTC_FLAG_ALRBF | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~(((__FLAG__) | RTC_ISR_INIT)& 0x0000FFFF)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)) | |||
/** | |||
* @brief Check whether the specified RTC Alarm interrupt has been enabled or not. | |||
* @param __HANDLE__: specifies the RTC handle. | |||
* @param __INTERRUPT__: specifies the RTC Alarm interrupt sources to check. | |||
* This parameter can be: | |||
* @arg RTC_IT_ALRA: Alarm A interrupt | |||
* @arg RTC_IT_ALRB: Alarm B interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET) | |||
/** | |||
* @brief Enable interrupt on the RTC Alarm associated Exti line. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Disable interrupt on the RTC Alarm associated Exti line. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) | |||
/** | |||
* @brief Enable event on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Disable event on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) | |||
/** | |||
* @brief Enable falling edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Disable falling edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) | |||
/** | |||
* @brief Enable rising edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Disable rising edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) | |||
/** | |||
* @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();__HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); | |||
/** | |||
* @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();__HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); | |||
/** | |||
* @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not. | |||
* @retval Line Status. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Clear the RTC Alarm associated Exti line flag. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Generate a Software interrupt on RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @} | |||
*/ | |||
/* Include RTC HAL Extension module */ | |||
#include "stm32f7xx_hal_rtc_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup RTC_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup RTC_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions ****************************/ | |||
HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc); | |||
HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc); | |||
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc); | |||
void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup RTC_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* RTC Time and Date functions ************************************************/ | |||
HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); | |||
HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); | |||
HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); | |||
HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup RTC_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
/* RTC Alarm functions ********************************************************/ | |||
HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); | |||
HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); | |||
HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm); | |||
HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format); | |||
void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc); | |||
HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); | |||
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup RTC_Exported_Functions_Group4 | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions ***********************************************/ | |||
HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup RTC_Exported_Functions_Group5 | |||
* @{ | |||
*/ | |||
/* Peripheral State functions *************************************************/ | |||
HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup RTC_Private_Constants RTC Private Constants | |||
* @{ | |||
*/ | |||
/* Masks Definition */ | |||
#define RTC_TR_RESERVED_MASK ((uint32_t)0x007F7F7F) | |||
#define RTC_DR_RESERVED_MASK ((uint32_t)0x00FFFF3F) | |||
#define RTC_INIT_MASK ((uint32_t)0xFFFFFFFF) | |||
#define RTC_RSF_MASK ((uint32_t)0xFFFFFF5F) | |||
#define RTC_TIMEOUT_VALUE 1000 | |||
#define RTC_EXTI_LINE_ALARM_EVENT ((uint32_t)EXTI_IMR_MR17) /*!< External interrupt line 17 Connected to the RTC Alarm event */ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup RTC_Private_Macros RTC Private Macros | |||
* @{ | |||
*/ | |||
/** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters | |||
* @{ | |||
*/ | |||
#define IS_RTC_HOUR_FORMAT(__FORMAT__) (((__FORMAT__) == RTC_HOURFORMAT_12) || \ | |||
((__FORMAT__) == RTC_HOURFORMAT_24)) | |||
#define IS_RTC_OUTPUT_POL(__POL__) (((__POL__) == RTC_OUTPUT_POLARITY_HIGH) || \ | |||
((__POL__) == RTC_OUTPUT_POLARITY_LOW)) | |||
#define IS_RTC_OUTPUT_TYPE(__TYPE__) (((__TYPE__) == RTC_OUTPUT_TYPE_OPENDRAIN) || \ | |||
((__TYPE__) == RTC_OUTPUT_TYPE_PUSHPULL)) | |||
#define IS_RTC_ASYNCH_PREDIV(__PREDIV__) ((__PREDIV__) <= (uint32_t)0x7F) | |||
#define IS_RTC_SYNCH_PREDIV(__PREDIV__) ((__PREDIV__) <= (uint32_t)0x7FFF) | |||
#define IS_RTC_HOUR12(__HOUR__) (((__HOUR__) > (uint32_t)0) && ((__HOUR__) <= (uint32_t)12)) | |||
#define IS_RTC_HOUR24(__HOUR__) ((__HOUR__) <= (uint32_t)23) | |||
#define IS_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= (uint32_t)59) | |||
#define IS_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= (uint32_t)59) | |||
#define IS_RTC_HOURFORMAT12(__PM__) (((__PM__) == RTC_HOURFORMAT12_AM) || ((__PM__) == RTC_HOURFORMAT12_PM)) | |||
#define IS_RTC_DAYLIGHT_SAVING(__SAVE__) (((__SAVE__) == RTC_DAYLIGHTSAVING_SUB1H) || \ | |||
((__SAVE__) == RTC_DAYLIGHTSAVING_ADD1H) || \ | |||
((__SAVE__) == RTC_DAYLIGHTSAVING_NONE)) | |||
#define IS_RTC_STORE_OPERATION(__OPERATION__) (((__OPERATION__) == RTC_STOREOPERATION_RESET) || \ | |||
((__OPERATION__) == RTC_STOREOPERATION_SET)) | |||
#define IS_RTC_FORMAT(__FORMAT__) (((__FORMAT__) == RTC_FORMAT_BIN) || ((__FORMAT__) == RTC_FORMAT_BCD)) | |||
#define IS_RTC_YEAR(__YEAR__) ((__YEAR__) <= (uint32_t)99) | |||
#define IS_RTC_MONTH(__MONTH__) (((__MONTH__) >= (uint32_t)1) && ((__MONTH__) <= (uint32_t)12)) | |||
#define IS_RTC_DATE(__DATE__) (((__DATE__) >= (uint32_t)1) && ((__DATE__) <= (uint32_t)31)) | |||
#define IS_RTC_WEEKDAY(__WEEKDAY__) (((__WEEKDAY__) == RTC_WEEKDAY_MONDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_TUESDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_WEDNESDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_THURSDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_FRIDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_SATURDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_SUNDAY)) | |||
#define IS_RTC_ALARM_DATE_WEEKDAY_DATE(__DATE__) (((__DATE__) >(uint32_t) 0) && ((__DATE__) <= (uint32_t)31)) | |||
#define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(__WEEKDAY__) (((__WEEKDAY__) == RTC_WEEKDAY_MONDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_TUESDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_WEDNESDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_THURSDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_FRIDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_SATURDAY) || \ | |||
((__WEEKDAY__) == RTC_WEEKDAY_SUNDAY)) | |||
#define IS_RTC_ALARM_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \ | |||
((__SEL__) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY)) | |||
#define IS_RTC_ALARM_MASK(__MASK__) (((__MASK__) & 0x7F7F7F7F) == (uint32_t)RESET) | |||
#define IS_RTC_ALARM(__ALARM__) (((__ALARM__) == RTC_ALARM_A) || ((__ALARM__) == RTC_ALARM_B)) | |||
#define IS_RTC_ALARM_SUB_SECOND_VALUE(__VALUE__) ((__VALUE__) <= (uint32_t)0x00007FFF) | |||
#define IS_RTC_ALARM_SUB_SECOND_MASK(__MASK__) (((__MASK__) == RTC_ALARMSUBSECONDMASK_ALL) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_1) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_2) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_3) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_4) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_5) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_6) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_7) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_8) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_9) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_10) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_11) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_12) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_13) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14) || \ | |||
((__MASK__) == RTC_ALARMSUBSECONDMASK_NONE)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup RTC_Private_Functions RTC Private Functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc); | |||
uint8_t RTC_ByteToBcd2(uint8_t Value); | |||
uint8_t RTC_Bcd2ToByte(uint8_t Value); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_RTC_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,774 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_sd.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of SD HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_SD_H | |||
#define __STM32F7xx_HAL_SD_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_ll_sdmmc.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup SD SD | |||
* @brief SD HAL module driver | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup SD_Exported_Types SD Exported Types | |||
* @{ | |||
*/ | |||
/** @defgroup SD_Exported_Types_Group1 SD Handle Structure definition | |||
* @{ | |||
*/ | |||
#define SD_InitTypeDef SDMMC_InitTypeDef | |||
#define SD_TypeDef SDMMC_TypeDef | |||
typedef struct | |||
{ | |||
SD_TypeDef *Instance; /*!< SDMMC register base address */ | |||
SD_InitTypeDef Init; /*!< SD required parameters */ | |||
HAL_LockTypeDef Lock; /*!< SD locking object */ | |||
uint32_t CardType; /*!< SD card type */ | |||
uint32_t RCA; /*!< SD relative card address */ | |||
uint32_t CSD[4]; /*!< SD card specific data table */ | |||
uint32_t CID[4]; /*!< SD card identification number table */ | |||
__IO uint32_t SdTransferCplt; /*!< SD transfer complete flag in non blocking mode */ | |||
__IO uint32_t SdTransferErr; /*!< SD transfer error flag in non blocking mode */ | |||
__IO uint32_t DmaTransferCplt; /*!< SD DMA transfer complete flag */ | |||
__IO uint32_t SdOperation; /*!< SD transfer operation (read/write) */ | |||
DMA_HandleTypeDef *hdmarx; /*!< SD Rx DMA handle parameters */ | |||
DMA_HandleTypeDef *hdmatx; /*!< SD Tx DMA handle parameters */ | |||
}SD_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SD_Exported_Types_Group2 Card Specific Data: CSD Register | |||
* @{ | |||
*/ | |||
typedef struct | |||
{ | |||
__IO uint8_t CSDStruct; /*!< CSD structure */ | |||
__IO uint8_t SysSpecVersion; /*!< System specification version */ | |||
__IO uint8_t Reserved1; /*!< Reserved */ | |||
__IO uint8_t TAAC; /*!< Data read access time 1 */ | |||
__IO uint8_t NSAC; /*!< Data read access time 2 in CLK cycles */ | |||
__IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */ | |||
__IO uint16_t CardComdClasses; /*!< Card command classes */ | |||
__IO uint8_t RdBlockLen; /*!< Max. read data block length */ | |||
__IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */ | |||
__IO uint8_t WrBlockMisalign; /*!< Write block misalignment */ | |||
__IO uint8_t RdBlockMisalign; /*!< Read block misalignment */ | |||
__IO uint8_t DSRImpl; /*!< DSR implemented */ | |||
__IO uint8_t Reserved2; /*!< Reserved */ | |||
__IO uint32_t DeviceSize; /*!< Device Size */ | |||
__IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */ | |||
__IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */ | |||
__IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */ | |||
__IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */ | |||
__IO uint8_t DeviceSizeMul; /*!< Device size multiplier */ | |||
__IO uint8_t EraseGrSize; /*!< Erase group size */ | |||
__IO uint8_t EraseGrMul; /*!< Erase group size multiplier */ | |||
__IO uint8_t WrProtectGrSize; /*!< Write protect group size */ | |||
__IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */ | |||
__IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */ | |||
__IO uint8_t WrSpeedFact; /*!< Write speed factor */ | |||
__IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */ | |||
__IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */ | |||
__IO uint8_t Reserved3; /*!< Reserved */ | |||
__IO uint8_t ContentProtectAppli; /*!< Content protection application */ | |||
__IO uint8_t FileFormatGrouop; /*!< File format group */ | |||
__IO uint8_t CopyFlag; /*!< Copy flag (OTP) */ | |||
__IO uint8_t PermWrProtect; /*!< Permanent write protection */ | |||
__IO uint8_t TempWrProtect; /*!< Temporary write protection */ | |||
__IO uint8_t FileFormat; /*!< File format */ | |||
__IO uint8_t ECC; /*!< ECC code */ | |||
__IO uint8_t CSD_CRC; /*!< CSD CRC */ | |||
__IO uint8_t Reserved4; /*!< Always 1 */ | |||
}HAL_SD_CSDTypedef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SD_Exported_Types_Group3 Card Identification Data: CID Register | |||
* @{ | |||
*/ | |||
typedef struct | |||
{ | |||
__IO uint8_t ManufacturerID; /*!< Manufacturer ID */ | |||
__IO uint16_t OEM_AppliID; /*!< OEM/Application ID */ | |||
__IO uint32_t ProdName1; /*!< Product Name part1 */ | |||
__IO uint8_t ProdName2; /*!< Product Name part2 */ | |||
__IO uint8_t ProdRev; /*!< Product Revision */ | |||
__IO uint32_t ProdSN; /*!< Product Serial Number */ | |||
__IO uint8_t Reserved1; /*!< Reserved1 */ | |||
__IO uint16_t ManufactDate; /*!< Manufacturing Date */ | |||
__IO uint8_t CID_CRC; /*!< CID CRC */ | |||
__IO uint8_t Reserved2; /*!< Always 1 */ | |||
}HAL_SD_CIDTypedef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SD_Exported_Types_Group4 SD Card Status returned by ACMD13 | |||
* @{ | |||
*/ | |||
typedef struct | |||
{ | |||
__IO uint8_t DAT_BUS_WIDTH; /*!< Shows the currently defined data bus width */ | |||
__IO uint8_t SECURED_MODE; /*!< Card is in secured mode of operation */ | |||
__IO uint16_t SD_CARD_TYPE; /*!< Carries information about card type */ | |||
__IO uint32_t SIZE_OF_PROTECTED_AREA; /*!< Carries information about the capacity of protected area */ | |||
__IO uint8_t SPEED_CLASS; /*!< Carries information about the speed class of the card */ | |||
__IO uint8_t PERFORMANCE_MOVE; /*!< Carries information about the card's performance move */ | |||
__IO uint8_t AU_SIZE; /*!< Carries information about the card's allocation unit size */ | |||
__IO uint16_t ERASE_SIZE; /*!< Determines the number of AUs to be erased in one operation */ | |||
__IO uint8_t ERASE_TIMEOUT; /*!< Determines the timeout for any number of AU erase */ | |||
__IO uint8_t ERASE_OFFSET; /*!< Carries information about the erase offset */ | |||
}HAL_SD_CardStatusTypedef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SD_Exported_Types_Group5 SD Card information structure | |||
* @{ | |||
*/ | |||
typedef struct | |||
{ | |||
HAL_SD_CSDTypedef SD_csd; /*!< SD card specific data register */ | |||
HAL_SD_CIDTypedef SD_cid; /*!< SD card identification number register */ | |||
uint64_t CardCapacity; /*!< Card capacity */ | |||
uint32_t CardBlockSize; /*!< Card block size */ | |||
uint16_t RCA; /*!< SD relative card address */ | |||
uint8_t CardType; /*!< SD card type */ | |||
}HAL_SD_CardInfoTypedef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SD_Exported_Types_Group6 SD Error status enumeration Structure definition | |||
* @{ | |||
*/ | |||
typedef enum | |||
{ | |||
/** | |||
* @brief SD specific error defines | |||
*/ | |||
SD_CMD_CRC_FAIL = (1), /*!< Command response received (but CRC check failed) */ | |||
SD_DATA_CRC_FAIL = (2), /*!< Data block sent/received (CRC check failed) */ | |||
SD_CMD_RSP_TIMEOUT = (3), /*!< Command response timeout */ | |||
SD_DATA_TIMEOUT = (4), /*!< Data timeout */ | |||
SD_TX_UNDERRUN = (5), /*!< Transmit FIFO underrun */ | |||
SD_RX_OVERRUN = (6), /*!< Receive FIFO overrun */ | |||
SD_START_BIT_ERR = (7), /*!< Start bit not detected on all data signals in wide bus mode */ | |||
SD_CMD_OUT_OF_RANGE = (8), /*!< Command's argument was out of range. */ | |||
SD_ADDR_MISALIGNED = (9), /*!< Misaligned address */ | |||
SD_BLOCK_LEN_ERR = (10), /*!< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length */ | |||
SD_ERASE_SEQ_ERR = (11), /*!< An error in the sequence of erase command occurs. */ | |||
SD_BAD_ERASE_PARAM = (12), /*!< An invalid selection for erase groups */ | |||
SD_WRITE_PROT_VIOLATION = (13), /*!< Attempt to program a write protect block */ | |||
SD_LOCK_UNLOCK_FAILED = (14), /*!< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */ | |||
SD_COM_CRC_FAILED = (15), /*!< CRC check of the previous command failed */ | |||
SD_ILLEGAL_CMD = (16), /*!< Command is not legal for the card state */ | |||
SD_CARD_ECC_FAILED = (17), /*!< Card internal ECC was applied but failed to correct the data */ | |||
SD_CC_ERROR = (18), /*!< Internal card controller error */ | |||
SD_GENERAL_UNKNOWN_ERROR = (19), /*!< General or unknown error */ | |||
SD_STREAM_READ_UNDERRUN = (20), /*!< The card could not sustain data transfer in stream read operation. */ | |||
SD_STREAM_WRITE_OVERRUN = (21), /*!< The card could not sustain data programming in stream mode */ | |||
SD_CID_CSD_OVERWRITE = (22), /*!< CID/CSD overwrite error */ | |||
SD_WP_ERASE_SKIP = (23), /*!< Only partial address space was erased */ | |||
SD_CARD_ECC_DISABLED = (24), /*!< Command has been executed without using internal ECC */ | |||
SD_ERASE_RESET = (25), /*!< Erase sequence was cleared before executing because an out of erase sequence command was received */ | |||
SD_AKE_SEQ_ERROR = (26), /*!< Error in sequence of authentication. */ | |||
SD_INVALID_VOLTRANGE = (27), | |||
SD_ADDR_OUT_OF_RANGE = (28), | |||
SD_SWITCH_ERROR = (29), | |||
SD_SDMMC_DISABLED = (30), | |||
SD_SDMMC_FUNCTION_BUSY = (31), | |||
SD_SDMMC_FUNCTION_FAILED = (32), | |||
SD_SDMMC_UNKNOWN_FUNCTION = (33), | |||
/** | |||
* @brief Standard error defines | |||
*/ | |||
SD_INTERNAL_ERROR = (34), | |||
SD_NOT_CONFIGURED = (35), | |||
SD_REQUEST_PENDING = (36), | |||
SD_REQUEST_NOT_APPLICABLE = (37), | |||
SD_INVALID_PARAMETER = (38), | |||
SD_UNSUPPORTED_FEATURE = (39), | |||
SD_UNSUPPORTED_HW = (40), | |||
SD_ERROR = (41), | |||
SD_OK = (0) | |||
}HAL_SD_ErrorTypedef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SD_Exported_Types_Group7 SD Transfer state enumeration structure | |||
* @{ | |||
*/ | |||
typedef enum | |||
{ | |||
SD_TRANSFER_OK = 0, /*!< Transfer success */ | |||
SD_TRANSFER_BUSY = 1, /*!< Transfer is occurring */ | |||
SD_TRANSFER_ERROR = 2 /*!< Transfer failed */ | |||
}HAL_SD_TransferStateTypedef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SD_Exported_Types_Group8 SD Card State enumeration structure | |||
* @{ | |||
*/ | |||
typedef enum | |||
{ | |||
SD_CARD_READY = ((uint32_t)0x00000001), /*!< Card state is ready */ | |||
SD_CARD_IDENTIFICATION = ((uint32_t)0x00000002), /*!< Card is in identification state */ | |||
SD_CARD_STANDBY = ((uint32_t)0x00000003), /*!< Card is in standby state */ | |||
SD_CARD_TRANSFER = ((uint32_t)0x00000004), /*!< Card is in transfer state */ | |||
SD_CARD_SENDING = ((uint32_t)0x00000005), /*!< Card is sending an operation */ | |||
SD_CARD_RECEIVING = ((uint32_t)0x00000006), /*!< Card is receiving operation information */ | |||
SD_CARD_PROGRAMMING = ((uint32_t)0x00000007), /*!< Card is in programming state */ | |||
SD_CARD_DISCONNECTED = ((uint32_t)0x00000008), /*!< Card is disconnected */ | |||
SD_CARD_ERROR = ((uint32_t)0x000000FF) /*!< Card is in error state */ | |||
}HAL_SD_CardStateTypedef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SD_Exported_Types_Group9 SD Operation enumeration structure | |||
* @{ | |||
*/ | |||
typedef enum | |||
{ | |||
SD_READ_SINGLE_BLOCK = 0, /*!< Read single block operation */ | |||
SD_READ_MULTIPLE_BLOCK = 1, /*!< Read multiple blocks operation */ | |||
SD_WRITE_SINGLE_BLOCK = 2, /*!< Write single block operation */ | |||
SD_WRITE_MULTIPLE_BLOCK = 3 /*!< Write multiple blocks operation */ | |||
}HAL_SD_OperationTypedef; | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup SD_Exported_Constants SD Exported Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @brief SD Commands Index | |||
*/ | |||
#define SD_CMD_GO_IDLE_STATE ((uint8_t)0) /*!< Resets the SD memory card. */ | |||
#define SD_CMD_SEND_OP_COND ((uint8_t)1) /*!< Sends host capacity support information and activates the card's initialization process. */ | |||
#define SD_CMD_ALL_SEND_CID ((uint8_t)2) /*!< Asks any card connected to the host to send the CID numbers on the CMD line. */ | |||
#define SD_CMD_SET_REL_ADDR ((uint8_t)3) /*!< Asks the card to publish a new relative address (RCA). */ | |||
#define SD_CMD_SET_DSR ((uint8_t)4) /*!< Programs the DSR of all cards. */ | |||
#define SD_CMD_SDMMC_SEN_OP_COND ((uint8_t)5) /*!< Sends host capacity support information (HCS) and asks the accessed card to send its | |||
operating condition register (OCR) content in the response on the CMD line. */ | |||
#define SD_CMD_HS_SWITCH ((uint8_t)6) /*!< Checks switchable function (mode 0) and switch card function (mode 1). */ | |||
#define SD_CMD_SEL_DESEL_CARD ((uint8_t)7) /*!< Selects the card by its own relative address and gets deselected by any other address */ | |||
#define SD_CMD_HS_SEND_EXT_CSD ((uint8_t)8) /*!< Sends SD Memory Card interface condition, which includes host supply voltage information | |||
and asks the card whether card supports voltage. */ | |||
#define SD_CMD_SEND_CSD ((uint8_t)9) /*!< Addressed card sends its card specific data (CSD) on the CMD line. */ | |||
#define SD_CMD_SEND_CID ((uint8_t)10) /*!< Addressed card sends its card identification (CID) on the CMD line. */ | |||
#define SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11) /*!< SD card doesn't support it. */ | |||
#define SD_CMD_STOP_TRANSMISSION ((uint8_t)12) /*!< Forces the card to stop transmission. */ | |||
#define SD_CMD_SEND_STATUS ((uint8_t)13) /*!< Addressed card sends its status register. */ | |||
#define SD_CMD_HS_BUSTEST_READ ((uint8_t)14) | |||
#define SD_CMD_GO_INACTIVE_STATE ((uint8_t)15) /*!< Sends an addressed card into the inactive state. */ | |||
#define SD_CMD_SET_BLOCKLEN ((uint8_t)16) /*!< Sets the block length (in bytes for SDSC) for all following block commands | |||
(read, write, lock). Default block length is fixed to 512 Bytes. Not effective | |||
for SDHS and SDXC. */ | |||
#define SD_CMD_READ_SINGLE_BLOCK ((uint8_t)17) /*!< Reads single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of | |||
fixed 512 bytes in case of SDHC and SDXC. */ | |||
#define SD_CMD_READ_MULT_BLOCK ((uint8_t)18) /*!< Continuously transfers data blocks from card to host until interrupted by | |||
STOP_TRANSMISSION command. */ | |||
#define SD_CMD_HS_BUSTEST_WRITE ((uint8_t)19) /*!< 64 bytes tuning pattern is sent for SDR50 and SDR104. */ | |||
#define SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20) /*!< Speed class control command. */ | |||
#define SD_CMD_SET_BLOCK_COUNT ((uint8_t)23) /*!< Specify block count for CMD18 and CMD25. */ | |||
#define SD_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24) /*!< Writes single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of | |||
fixed 512 bytes in case of SDHC and SDXC. */ | |||
#define SD_CMD_WRITE_MULT_BLOCK ((uint8_t)25) /*!< Continuously writes blocks of data until a STOP_TRANSMISSION follows. */ | |||
#define SD_CMD_PROG_CID ((uint8_t)26) /*!< Reserved for manufacturers. */ | |||
#define SD_CMD_PROG_CSD ((uint8_t)27) /*!< Programming of the programmable bits of the CSD. */ | |||
#define SD_CMD_SET_WRITE_PROT ((uint8_t)28) /*!< Sets the write protection bit of the addressed group. */ | |||
#define SD_CMD_CLR_WRITE_PROT ((uint8_t)29) /*!< Clears the write protection bit of the addressed group. */ | |||
#define SD_CMD_SEND_WRITE_PROT ((uint8_t)30) /*!< Asks the card to send the status of the write protection bits. */ | |||
#define SD_CMD_SD_ERASE_GRP_START ((uint8_t)32) /*!< Sets the address of the first write block to be erased. (For SD card only). */ | |||
#define SD_CMD_SD_ERASE_GRP_END ((uint8_t)33) /*!< Sets the address of the last write block of the continuous range to be erased. */ | |||
#define SD_CMD_ERASE_GRP_START ((uint8_t)35) /*!< Sets the address of the first write block to be erased. Reserved for each command | |||
system set by switch function command (CMD6). */ | |||
#define SD_CMD_ERASE_GRP_END ((uint8_t)36) /*!< Sets the address of the last write block of the continuous range to be erased. | |||
Reserved for each command system set by switch function command (CMD6). */ | |||
#define SD_CMD_ERASE ((uint8_t)38) /*!< Reserved for SD security applications. */ | |||
#define SD_CMD_FAST_IO ((uint8_t)39) /*!< SD card doesn't support it (Reserved). */ | |||
#define SD_CMD_GO_IRQ_STATE ((uint8_t)40) /*!< SD card doesn't support it (Reserved). */ | |||
#define SD_CMD_LOCK_UNLOCK ((uint8_t)42) /*!< Sets/resets the password or lock/unlock the card. The size of the data block is set by | |||
the SET_BLOCK_LEN command. */ | |||
#define SD_CMD_APP_CMD ((uint8_t)55) /*!< Indicates to the card that the next command is an application specific command rather | |||
than a standard command. */ | |||
#define SD_CMD_GEN_CMD ((uint8_t)56) /*!< Used either to transfer a data block to the card or to get a data block from the card | |||
for general purpose/application specific commands. */ | |||
#define SD_CMD_NO_CMD ((uint8_t)64) | |||
/** | |||
* @brief Following commands are SD Card Specific commands. | |||
* SDMMC_APP_CMD should be sent before sending these commands. | |||
*/ | |||
#define SD_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6) /*!< (ACMD6) Defines the data bus width to be used for data transfer. The allowed data bus | |||
widths are given in SCR register. */ | |||
#define SD_CMD_SD_APP_STATUS ((uint8_t)13) /*!< (ACMD13) Sends the SD status. */ | |||
#define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22) /*!< (ACMD22) Sends the number of the written (without errors) write blocks. Responds with | |||
32bit+CRC data block. */ | |||
#define SD_CMD_SD_APP_OP_COND ((uint8_t)41) /*!< (ACMD41) Sends host capacity support information (HCS) and asks the accessed card to | |||
send its operating condition register (OCR) content in the response on the CMD line. */ | |||
#define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) /*!< (ACMD42) Connects/Disconnects the 50 KOhm pull-up resistor on CD/DAT3 (pin 1) of the card. */ | |||
#define SD_CMD_SD_APP_SEND_SCR ((uint8_t)51) /*!< Reads the SD Configuration Register (SCR). */ | |||
#define SD_CMD_SDMMC_RW_DIRECT ((uint8_t)52) /*!< For SD I/O card only, reserved for security specification. */ | |||
#define SD_CMD_SDMMC_RW_EXTENDED ((uint8_t)53) /*!< For SD I/O card only, reserved for security specification. */ | |||
/** | |||
* @brief Following commands are SD Card Specific security commands. | |||
* SD_CMD_APP_CMD should be sent before sending these commands. | |||
*/ | |||
#define SD_CMD_SD_APP_GET_MKB ((uint8_t)43) /*!< For SD card only */ | |||
#define SD_CMD_SD_APP_GET_MID ((uint8_t)44) /*!< For SD card only */ | |||
#define SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45) /*!< For SD card only */ | |||
#define SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46) /*!< For SD card only */ | |||
#define SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47) /*!< For SD card only */ | |||
#define SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48) /*!< For SD card only */ | |||
#define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18) /*!< For SD card only */ | |||
#define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25) /*!< For SD card only */ | |||
#define SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38) /*!< For SD card only */ | |||
#define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49) /*!< For SD card only */ | |||
#define SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48) /*!< For SD card only */ | |||
/** | |||
* @brief Supported SD Memory Cards | |||
*/ | |||
#define STD_CAPACITY_SD_CARD_V1_1 ((uint32_t)0x00000000) | |||
#define STD_CAPACITY_SD_CARD_V2_0 ((uint32_t)0x00000001) | |||
#define HIGH_CAPACITY_SD_CARD ((uint32_t)0x00000002) | |||
#define MULTIMEDIA_CARD ((uint32_t)0x00000003) | |||
#define SECURE_DIGITAL_IO_CARD ((uint32_t)0x00000004) | |||
#define HIGH_SPEED_MULTIMEDIA_CARD ((uint32_t)0x00000005) | |||
#define SECURE_DIGITAL_IO_COMBO_CARD ((uint32_t)0x00000006) | |||
#define HIGH_CAPACITY_MMC_CARD ((uint32_t)0x00000007) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup SD_Exported_macros SD Exported Macros | |||
* @brief macros to handle interrupts and specific clock configurations | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Enable the SD device. | |||
* @retval None | |||
*/ | |||
#define __HAL_SD_SDMMC_ENABLE(__HANDLE__) __SDMMC_ENABLE((__HANDLE__)->Instance) | |||
/** | |||
* @brief Disable the SD device. | |||
* @retval None | |||
*/ | |||
#define __HAL_SD_SDMMC_DISABLE(__HANDLE__) __SDMMC_DISABLE((__HANDLE__)->Instance) | |||
/** | |||
* @brief Enable the SDMMC DMA transfer. | |||
* @retval None | |||
*/ | |||
#define __HAL_SD_SDMMC_DMA_ENABLE(__HANDLE__) __SDMMC_DMA_ENABLE((__HANDLE__)->Instance) | |||
/** | |||
* @brief Disable the SDMMC DMA transfer. | |||
* @retval None | |||
*/ | |||
#define __HAL_SD_SDMMC_DMA_DISABLE(__HANDLE__) __SDMMC_DMA_DISABLE((__HANDLE__)->Instance) | |||
/** | |||
* @brief Enable the SD device interrupt. | |||
* @param __HANDLE__: SD Handle | |||
* @param __INTERRUPT__: specifies the SDMMC interrupt sources to be enabled. | |||
* This parameter can be one or a combination of the following values: | |||
* @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt | |||
* @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt | |||
* @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt | |||
* @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt | |||
* @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt | |||
* @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt | |||
* @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt | |||
* @arg SDMMC_IT_TXACT: Data transmit in progress interrupt | |||
* @arg SDMMC_IT_RXACT: Data receive in progress interrupt | |||
* @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt | |||
* @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt | |||
* @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt | |||
* @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt | |||
* @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt | |||
* @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt | |||
* @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt | |||
* @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt | |||
* @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_SD_SDMMC_ENABLE_IT(__HANDLE__, __INTERRUPT__) __SDMMC_ENABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__)) | |||
/** | |||
* @brief Disable the SD device interrupt. | |||
* @param __HANDLE__: SD Handle | |||
* @param __INTERRUPT__: specifies the SDMMC interrupt sources to be disabled. | |||
* This parameter can be one or a combination of the following values: | |||
* @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt | |||
* @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt | |||
* @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt | |||
* @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt | |||
* @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt | |||
* @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt | |||
* @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt | |||
* @arg SDMMC_IT_TXACT: Data transmit in progress interrupt | |||
* @arg SDMMC_IT_RXACT: Data receive in progress interrupt | |||
* @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt | |||
* @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt | |||
* @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt | |||
* @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt | |||
* @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt | |||
* @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt | |||
* @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt | |||
* @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt | |||
* @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_SD_SDMMC_DISABLE_IT(__HANDLE__, __INTERRUPT__) __SDMMC_DISABLE_IT((__HANDLE__)->Instance, (__INTERRUPT__)) | |||
/** | |||
* @brief Check whether the specified SD flag is set or not. | |||
* @param __HANDLE__: SD Handle | |||
* @param __FLAG__: specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed) | |||
* @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed) | |||
* @arg SDMMC_FLAG_CTIMEOUT: Command response timeout | |||
* @arg SDMMC_FLAG_DTIMEOUT: Data timeout | |||
* @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error | |||
* @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error | |||
* @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed) | |||
* @arg SDMMC_FLAG_CMDSENT: Command sent (no response required) | |||
* @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero) | |||
* @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed) | |||
* @arg SDMMC_FLAG_CMDACT: Command transfer in progress | |||
* @arg SDMMC_FLAG_TXACT: Data transmit in progress | |||
* @arg SDMMC_FLAG_RXACT: Data receive in progress | |||
* @arg SDMMC_FLAG_TXFIFOHE: Transmit FIFO Half Empty | |||
* @arg SDMMC_FLAG_RXFIFOHF: Receive FIFO Half Full | |||
* @arg SDMMC_FLAG_TXFIFOF: Transmit FIFO full | |||
* @arg SDMMC_FLAG_RXFIFOF: Receive FIFO full | |||
* @arg SDMMC_FLAG_TXFIFOE: Transmit FIFO empty | |||
* @arg SDMMC_FLAG_RXFIFOE: Receive FIFO empty | |||
* @arg SDMMC_FLAG_TXDAVL: Data available in transmit FIFO | |||
* @arg SDMMC_FLAG_RXDAVL: Data available in receive FIFO | |||
* @arg SDMMC_FLAG_SDIOIT: SD I/O interrupt received | |||
* @retval The new state of SD FLAG (SET or RESET). | |||
*/ | |||
#define __HAL_SD_SDMMC_GET_FLAG(__HANDLE__, __FLAG__) __SDMMC_GET_FLAG((__HANDLE__)->Instance, (__FLAG__)) | |||
/** | |||
* @brief Clear the SD's pending flags. | |||
* @param __HANDLE__: SD Handle | |||
* @param __FLAG__: specifies the flag to clear. | |||
* This parameter can be one or a combination of the following values: | |||
* @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed) | |||
* @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed) | |||
* @arg SDMMC_FLAG_CTIMEOUT: Command response timeout | |||
* @arg SDMMC_FLAG_DTIMEOUT: Data timeout | |||
* @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error | |||
* @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error | |||
* @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed) | |||
* @arg SDMMC_FLAG_CMDSENT: Command sent (no response required) | |||
* @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero) | |||
* @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed) | |||
* @arg SDMMC_FLAG_SDIOIT: SD I/O interrupt received | |||
* @retval None | |||
*/ | |||
#define __HAL_SD_SDMMC_CLEAR_FLAG(__HANDLE__, __FLAG__) __SDMMC_CLEAR_FLAG((__HANDLE__)->Instance, (__FLAG__)) | |||
/** | |||
* @brief Check whether the specified SD interrupt has occurred or not. | |||
* @param __HANDLE__: SD Handle | |||
* @param __INTERRUPT__: specifies the SDMMC interrupt source to check. | |||
* This parameter can be one of the following values: | |||
* @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt | |||
* @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt | |||
* @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt | |||
* @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt | |||
* @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt | |||
* @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt | |||
* @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt | |||
* @arg SDMMC_IT_TXACT: Data transmit in progress interrupt | |||
* @arg SDMMC_IT_RXACT: Data receive in progress interrupt | |||
* @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt | |||
* @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt | |||
* @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt | |||
* @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt | |||
* @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt | |||
* @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt | |||
* @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt | |||
* @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt | |||
* @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt | |||
* @retval The new state of SD IT (SET or RESET). | |||
*/ | |||
#define __HAL_SD_SDMMC_GET_IT(__HANDLE__, __INTERRUPT__) __SDMMC_GET_IT((__HANDLE__)->Instance, (__INTERRUPT__)) | |||
/** | |||
* @brief Clear the SD's interrupt pending bits. | |||
* @param __HANDLE__: SD Handle | |||
* @param __INTERRUPT__: specifies the interrupt pending bit to clear. | |||
* This parameter can be one or a combination of the following values: | |||
* @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt | |||
* @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt | |||
* @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt | |||
* @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt | |||
* @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt | |||
* @arg SDMMC_IT_DATAEND: Data end (data counter, SDMMC_DCOUNT, is zero) interrupt | |||
* @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_SD_SDMMC_CLEAR_IT(__HANDLE__, __INTERRUPT__) __SDMMC_CLEAR_IT((__HANDLE__)->Instance, (__INTERRUPT__)) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup SD_Exported_Functions SD Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup SD_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
HAL_SD_ErrorTypedef HAL_SD_Init(SD_HandleTypeDef *hsd, HAL_SD_CardInfoTypedef *SDCardInfo); | |||
HAL_StatusTypeDef HAL_SD_DeInit (SD_HandleTypeDef *hsd); | |||
void HAL_SD_MspInit(SD_HandleTypeDef *hsd); | |||
void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SD_Exported_Functions_Group2 Input and Output operation functions | |||
* @{ | |||
*/ | |||
/* Blocking mode: Polling */ | |||
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks); | |||
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks); | |||
HAL_SD_ErrorTypedef HAL_SD_Erase(SD_HandleTypeDef *hsd, uint64_t startaddr, uint64_t endaddr); | |||
/* Non-Blocking mode: Interrupt */ | |||
void HAL_SD_IRQHandler(SD_HandleTypeDef *hsd); | |||
/* Callback in non blocking modes (DMA) */ | |||
void HAL_SD_DMA_RxCpltCallback(DMA_HandleTypeDef *hdma); | |||
void HAL_SD_DMA_RxErrorCallback(DMA_HandleTypeDef *hdma); | |||
void HAL_SD_DMA_TxCpltCallback(DMA_HandleTypeDef *hdma); | |||
void HAL_SD_DMA_TxErrorCallback(DMA_HandleTypeDef *hdma); | |||
void HAL_SD_XferCpltCallback(SD_HandleTypeDef *hsd); | |||
void HAL_SD_XferErrorCallback(SD_HandleTypeDef *hsd); | |||
/* Non-Blocking mode: DMA */ | |||
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks); | |||
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks); | |||
HAL_SD_ErrorTypedef HAL_SD_CheckWriteOperation(SD_HandleTypeDef *hsd, uint32_t Timeout); | |||
HAL_SD_ErrorTypedef HAL_SD_CheckReadOperation(SD_HandleTypeDef *hsd, uint32_t Timeout); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SD_Exported_Functions_Group3 Peripheral Control functions | |||
* @{ | |||
*/ | |||
HAL_SD_ErrorTypedef HAL_SD_Get_CardInfo(SD_HandleTypeDef *hsd, HAL_SD_CardInfoTypedef *pCardInfo); | |||
HAL_SD_ErrorTypedef HAL_SD_WideBusOperation_Config(SD_HandleTypeDef *hsd, uint32_t WideMode); | |||
HAL_SD_ErrorTypedef HAL_SD_StopTransfer(SD_HandleTypeDef *hsd); | |||
HAL_SD_ErrorTypedef HAL_SD_HighSpeed (SD_HandleTypeDef *hsd); | |||
/** | |||
* @} | |||
*/ | |||
/* Peripheral State functions ************************************************/ | |||
/** @defgroup SD_Exported_Functions_Group4 Peripheral State functions | |||
* @{ | |||
*/ | |||
HAL_SD_ErrorTypedef HAL_SD_SendSDStatus(SD_HandleTypeDef *hsd, uint32_t *pSDstatus); | |||
HAL_SD_ErrorTypedef HAL_SD_GetCardStatus(SD_HandleTypeDef *hsd, HAL_SD_CardStatusTypedef *pCardStatus); | |||
HAL_SD_TransferStateTypedef HAL_SD_GetStatus(SD_HandleTypeDef *hsd); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/** @defgroup SD_Private_Types SD Private Types | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private defines -----------------------------------------------------------*/ | |||
/** @defgroup SD_Private_Defines SD Private Defines | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/** @defgroup SD_Private_Variables SD Private Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup SD_Private_Constants SD Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup SD_Private_Macros SD Private Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions prototypes ----------------------------------------------*/ | |||
/** @defgroup SD_Private_Functions_Prototypes SD Private Functions Prototypes | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup SD_Private_Functions SD Private Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_SD_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,696 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_spi.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of SPI HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_SPI_H | |||
#define __STM32F7xx_HAL_SPI_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup SPI | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup SPI_Exported_Types SPI Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief SPI Configuration Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Mode; /*!< Specifies the SPI operating mode. | |||
This parameter can be a value of @ref SPI_Mode */ | |||
uint32_t Direction; /*!< Specifies the SPI bidirectional mode state. | |||
This parameter can be a value of @ref SPI_Direction */ | |||
uint32_t DataSize; /*!< Specifies the SPI data size. | |||
This parameter can be a value of @ref SPI_Data_Size */ | |||
uint32_t CLKPolarity; /*!< Specifies the serial clock steady state. | |||
This parameter can be a value of @ref SPI_Clock_Polarity */ | |||
uint32_t CLKPhase; /*!< Specifies the clock active edge for the bit capture. | |||
This parameter can be a value of @ref SPI_Clock_Phase */ | |||
uint32_t NSS; /*!< Specifies whether the NSS signal is managed by | |||
hardware (NSS pin) or by software using the SSI bit. | |||
This parameter can be a value of @ref SPI_Slave_Select_management */ | |||
uint32_t BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be | |||
used to configure the transmit and receive SCK clock. | |||
This parameter can be a value of @ref SPI_BaudRate_Prescaler | |||
@note The communication clock is derived from the master | |||
clock. The slave clock does not need to be set. */ | |||
uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit. | |||
This parameter can be a value of @ref SPI_MSB_LSB_transmission */ | |||
uint32_t TIMode; /*!< Specifies if the TI mode is enabled or not . | |||
This parameter can be a value of @ref SPI_TI_mode */ | |||
uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not. | |||
This parameter can be a value of @ref SPI_CRC_Calculation */ | |||
uint32_t CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 65535 */ | |||
uint32_t CRCLength; /*!< Specifies the CRC Length used for the CRC calculation. | |||
CRC Length is only used with Data8 and Data16, not other data size | |||
This parameter can be a value of @ref SPI_CRC_length */ | |||
uint32_t NSSPMode; /*!< Specifies whether the NSSP signal is enabled or not . | |||
This parameter can be a value of @ref SPI_NSSP_Mode | |||
This mode is activated by the NSSP bit in the SPIx_CR2 register and | |||
it takes effect only if the SPI interface is configured as Motorola SPI | |||
master (FRF=0) with capture on the first edge (SPIx_CR1 CPHA = 0, | |||
CPOL setting is ignored).. */ | |||
} SPI_InitTypeDef; | |||
/** | |||
* @brief HAL State structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_SPI_STATE_RESET = 0x00, /*!< Peripheral not Initialized */ | |||
HAL_SPI_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */ | |||
HAL_SPI_STATE_BUSY = 0x02, /*!< an internal process is ongoing */ | |||
HAL_SPI_STATE_BUSY_TX = 0x03, /*!< Data Transmission process is ongoing */ | |||
HAL_SPI_STATE_BUSY_RX = 0x04, /*!< Data Reception process is ongoing */ | |||
HAL_SPI_STATE_BUSY_TX_RX = 0x05, /*!< Data Transmission and Reception process is ongoing*/ | |||
HAL_SPI_STATE_ERROR = 0x06 /*!< SPI error state */ | |||
}HAL_SPI_StateTypeDef; | |||
/** | |||
* @brief SPI handle Structure definition | |||
*/ | |||
typedef struct __SPI_HandleTypeDef | |||
{ | |||
SPI_TypeDef *Instance; /* SPI registers base address */ | |||
SPI_InitTypeDef Init; /* SPI communication parameters */ | |||
uint8_t *pTxBuffPtr; /* Pointer to SPI Tx transfer Buffer */ | |||
uint16_t TxXferSize; /* SPI Tx Transfer size */ | |||
uint16_t TxXferCount; /* SPI Tx Transfer Counter */ | |||
uint8_t *pRxBuffPtr; /* Pointer to SPI Rx transfer Buffer */ | |||
uint16_t RxXferSize; /* SPI Rx Transfer size */ | |||
uint16_t RxXferCount; /* SPI Rx Transfer Counter */ | |||
uint32_t CRCSize; /* SPI CRC size used for the transfer */ | |||
void (*RxISR)(struct __SPI_HandleTypeDef *hspi); /* function pointer on Rx IRQ handler */ | |||
void (*TxISR)(struct __SPI_HandleTypeDef *hspi); /* function pointer on Tx IRQ handler */ | |||
DMA_HandleTypeDef *hdmatx; /* SPI Tx DMA Handle parameters */ | |||
DMA_HandleTypeDef *hdmarx; /* SPI Rx DMA Handle parameters */ | |||
HAL_LockTypeDef Lock; /* Locking object */ | |||
HAL_SPI_StateTypeDef State; /* SPI communication state */ | |||
uint32_t ErrorCode; /* SPI Error code */ | |||
}SPI_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup SPI_Exported_Constants SPI Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup SPI_Error_Code SPI Error Code | |||
* @{ | |||
*/ | |||
#define HAL_SPI_ERROR_NONE (uint32_t)0x00000000 /*!< No error */ | |||
#define HAL_SPI_ERROR_MODF (uint32_t)0x00000001 /*!< MODF error */ | |||
#define HAL_SPI_ERROR_CRC (uint32_t)0x00000002 /*!< CRC error */ | |||
#define HAL_SPI_ERROR_OVR (uint32_t)0x00000004 /*!< OVR error */ | |||
#define HAL_SPI_ERROR_FRE (uint32_t)0x00000008 /*!< FRE error */ | |||
#define HAL_SPI_ERROR_DMA (uint32_t)0x00000010 /*!< DMA transfer error */ | |||
#define HAL_SPI_ERROR_FLAG (uint32_t)0x00000020 /*!< Error on BSY/TXE/FTLVL/FRLVL Flag */ | |||
#define HAL_SPI_ERROR_UNKNOW (uint32_t)0x00000040 /*!< Unknow Error error */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Mode SPI Mode | |||
* @{ | |||
*/ | |||
#define SPI_MODE_SLAVE ((uint32_t)0x00000000) | |||
#define SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Direction SPI Direction Mode | |||
* @{ | |||
*/ | |||
#define SPI_DIRECTION_2LINES ((uint32_t)0x00000000) | |||
#define SPI_DIRECTION_2LINES_RXONLY SPI_CR1_RXONLY | |||
#define SPI_DIRECTION_1LINE SPI_CR1_BIDIMODE | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Data_Size SPI Data Size | |||
* @{ | |||
*/ | |||
#define SPI_DATASIZE_4BIT ((uint32_t)0x0300) | |||
#define SPI_DATASIZE_5BIT ((uint32_t)0x0400) | |||
#define SPI_DATASIZE_6BIT ((uint32_t)0x0500) | |||
#define SPI_DATASIZE_7BIT ((uint32_t)0x0600) | |||
#define SPI_DATASIZE_8BIT ((uint32_t)0x0700) | |||
#define SPI_DATASIZE_9BIT ((uint32_t)0x0800) | |||
#define SPI_DATASIZE_10BIT ((uint32_t)0x0900) | |||
#define SPI_DATASIZE_11BIT ((uint32_t)0x0A00) | |||
#define SPI_DATASIZE_12BIT ((uint32_t)0x0B00) | |||
#define SPI_DATASIZE_13BIT ((uint32_t)0x0C00) | |||
#define SPI_DATASIZE_14BIT ((uint32_t)0x0D00) | |||
#define SPI_DATASIZE_15BIT ((uint32_t)0x0E00) | |||
#define SPI_DATASIZE_16BIT ((uint32_t)0x0F00) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Clock_Polarity SPI Clock Polarity | |||
* @{ | |||
*/ | |||
#define SPI_POLARITY_LOW ((uint32_t)0x00000000) | |||
#define SPI_POLARITY_HIGH SPI_CR1_CPOL | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Clock_Phase SPI Clock Phase | |||
* @{ | |||
*/ | |||
#define SPI_PHASE_1EDGE ((uint32_t)0x00000000) | |||
#define SPI_PHASE_2EDGE SPI_CR1_CPHA | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Slave_Select_management SPI Slave Select management | |||
* @{ | |||
*/ | |||
#define SPI_NSS_SOFT SPI_CR1_SSM | |||
#define SPI_NSS_HARD_INPUT ((uint32_t)0x00000000) | |||
#define SPI_NSS_HARD_OUTPUT ((uint32_t)0x00040000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_NSSP_Mode SPI NSS Pulse Mode | |||
* @{ | |||
*/ | |||
#define SPI_NSS_PULSE_ENABLE SPI_CR2_NSSP | |||
#define SPI_NSS_PULSE_DISABLE ((uint32_t)0x00000000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_BaudRate_Prescaler SPI BaudRate Prescaler | |||
* @{ | |||
*/ | |||
#define SPI_BAUDRATEPRESCALER_2 ((uint32_t)0x00000000) | |||
#define SPI_BAUDRATEPRESCALER_4 ((uint32_t)0x00000008) | |||
#define SPI_BAUDRATEPRESCALER_8 ((uint32_t)0x00000010) | |||
#define SPI_BAUDRATEPRESCALER_16 ((uint32_t)0x00000018) | |||
#define SPI_BAUDRATEPRESCALER_32 ((uint32_t)0x00000020) | |||
#define SPI_BAUDRATEPRESCALER_64 ((uint32_t)0x00000028) | |||
#define SPI_BAUDRATEPRESCALER_128 ((uint32_t)0x00000030) | |||
#define SPI_BAUDRATEPRESCALER_256 ((uint32_t)0x00000038) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_MSB_LSB_transmission SPI MSB LSB transmission | |||
* @{ | |||
*/ | |||
#define SPI_FIRSTBIT_MSB ((uint32_t)0x00000000) | |||
#define SPI_FIRSTBIT_LSB SPI_CR1_LSBFIRST | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_TI_mode SPI TI mode | |||
* @{ | |||
*/ | |||
#define SPI_TIMODE_DISABLE ((uint32_t)0x00000000) | |||
#define SPI_TIMODE_ENABLE SPI_CR2_FRF | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_CRC_Calculation SPI CRC Calculation | |||
* @{ | |||
*/ | |||
#define SPI_CRCCALCULATION_DISABLE ((uint32_t)0x00000000) | |||
#define SPI_CRCCALCULATION_ENABLE SPI_CR1_CRCEN | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_CRC_length SPI CRC Length | |||
* @{ | |||
* This parameter can be one of the following values: | |||
* SPI_CRC_LENGTH_DATASIZE: aligned with the data size | |||
* SPI_CRC_LENGTH_8BIT : CRC 8bit | |||
* SPI_CRC_LENGTH_16BIT : CRC 16bit | |||
*/ | |||
#define SPI_CRC_LENGTH_DATASIZE ((uint32_t)0x00000000) | |||
#define SPI_CRC_LENGTH_8BIT ((uint32_t)0x00000001) | |||
#define SPI_CRC_LENGTH_16BIT ((uint32_t)0x00000002) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_FIFO_reception_threshold SPI FIFO Reception Threshold | |||
* @{ | |||
* This parameter can be one of the following values: | |||
* SPI_RXFIFO_THRESHOLD or SPI_RXFIFO_THRESHOLD_QF : | |||
* RXNE event is generated if the FIFO | |||
* level is greater or equal to 1/2(16-bits). | |||
* SPI_RXFIFO_THRESHOLD_HF: RXNE event is generated if the FIFO | |||
* level is greater or equal to 1/4(8 bits). */ | |||
#define SPI_RXFIFO_THRESHOLD SPI_CR2_FRXTH | |||
#define SPI_RXFIFO_THRESHOLD_QF SPI_CR2_FRXTH | |||
#define SPI_RXFIFO_THRESHOLD_HF ((uint32_t)0x00000000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Interrupt_configuration_definition SPI Interrupt configuration definition | |||
* @brief SPI Interrupt definition | |||
* Elements values convention: 0xXXXXXXXX | |||
* - XXXXXXXX : Interrupt control mask | |||
* @{ | |||
*/ | |||
#define SPI_IT_TXE SPI_CR2_TXEIE | |||
#define SPI_IT_RXNE SPI_CR2_RXNEIE | |||
#define SPI_IT_ERR SPI_CR2_ERRIE | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Flag_definition SPI Flag definition | |||
* @brief Flag definition | |||
* Elements values convention: 0xXXXXYYYY | |||
* - XXXX : Flag register Index | |||
* - YYYY : Flag mask | |||
* @{ | |||
*/ | |||
#define SPI_FLAG_RXNE SPI_SR_RXNE /* SPI status flag: Rx buffer not empty flag */ | |||
#define SPI_FLAG_TXE SPI_SR_TXE /* SPI status flag: Tx buffer empty flag */ | |||
#define SPI_FLAG_BSY SPI_SR_BSY /* SPI status flag: Busy flag */ | |||
#define SPI_FLAG_CRCERR SPI_SR_CRCERR /* SPI Error flag: CRC error flag */ | |||
#define SPI_FLAG_MODF SPI_SR_MODF /* SPI Error flag: Mode fault flag */ | |||
#define SPI_FLAG_OVR SPI_SR_OVR /* SPI Error flag: Overrun flag */ | |||
#define SPI_FLAG_FRE SPI_SR_FRE /* SPI Error flag: TI mode frame format error flag */ | |||
#define SPI_FLAG_FTLVL SPI_SR_FTLVL /* SPI fifo transmission level */ | |||
#define SPI_FLAG_FRLVL SPI_SR_FRLVL /* SPI fifo reception level */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_transmission_fifo_status_level SPI Transmission FIFO Status Level | |||
* @{ | |||
*/ | |||
#define SPI_FTLVL_EMPTY ((uint32_t)0x0000) | |||
#define SPI_FTLVL_QUARTER_FULL ((uint32_t)0x0800) | |||
#define SPI_FTLVL_HALF_FULL ((uint32_t)0x1000) | |||
#define SPI_FTLVL_FULL ((uint32_t)0x1800) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_reception_fifo_status_level SPI Reception FIFO Status Level | |||
* @{ | |||
*/ | |||
#define SPI_FRLVL_EMPTY ((uint32_t)0x0000) | |||
#define SPI_FRLVL_QUARTER_FULL ((uint32_t)0x0200) | |||
#define SPI_FRLVL_HALF_FULL ((uint32_t)0x0400) | |||
#define SPI_FRLVL_FULL ((uint32_t)0x0600) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macros ------------------------------------------------------------*/ | |||
/** @defgroup SPI_Exported_Macros SPI Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset SPI handle state | |||
* @param __HANDLE__: SPI handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SPI_STATE_RESET) | |||
/** @brief Enables or disables the specified SPI interrupts. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @param __INTERRUPT__ : specifies the interrupt source to enable or disable. | |||
* This parameter can be one of the following values: | |||
* @arg SPI_IT_TXE: Tx buffer empty interrupt enable | |||
* @arg SPI_IT_RXNE: RX buffer not empty interrupt enable | |||
* @arg SPI_IT_ERR: Error interrupt enable | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__)) | |||
#define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__))) | |||
/** @brief Checks if the specified SPI interrupt source is enabled or disabled. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @param __INTERRUPT__ : specifies the SPI interrupt source to check. | |||
* This parameter can be one of the following values: | |||
* @arg SPI_IT_TXE: Tx buffer empty interrupt enable | |||
* @arg SPI_IT_RXNE: RX buffer not empty interrupt enable | |||
* @arg SPI_IT_ERR: Error interrupt enable | |||
* @retval The new state of __IT__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) | |||
/** @brief Checks whether the specified SPI flag is set or not. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @param __FLAG__ : specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg SPI_FLAG_RXNE: Receive buffer not empty flag | |||
* @arg SPI_FLAG_TXE: Transmit buffer empty flag | |||
* @arg SPI_FLAG_CRCERR: CRC error flag | |||
* @arg SPI_FLAG_MODF: Mode fault flag | |||
* @arg SPI_FLAG_OVR: Overrun flag | |||
* @arg SPI_FLAG_BSY: Busy flag | |||
* @arg SPI_FLAG_FRE: Frame format error flag | |||
* @arg SPI_FLAG_FTLVL: SPI fifo transmission level | |||
* @arg SPI_FLAG_FRLVL: SPI fifo reception level | |||
* @retval The new state of __FLAG__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__)) | |||
/** @brief Clears the SPI CRCERR pending flag. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_CLEAR_CRCERRFLAG(__HANDLE__) ((__HANDLE__)->Instance->SR = (uint16_t)(~SPI_FLAG_CRCERR)) | |||
/** @brief Clears the SPI MODF pending flag. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_CLEAR_MODFFLAG(__HANDLE__) \ | |||
do{ \ | |||
__IO uint32_t tmpreg; \ | |||
tmpreg = (__HANDLE__)->Instance->SR; \ | |||
(__HANDLE__)->Instance->CR1 &= (~SPI_CR1_SPE); \ | |||
UNUSED(tmpreg); \ | |||
} while(0) | |||
/** @brief Clears the SPI OVR pending flag. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_CLEAR_OVRFLAG(__HANDLE__) \ | |||
do{ \ | |||
__IO uint32_t tmpreg; \ | |||
tmpreg = (__HANDLE__)->Instance->DR; \ | |||
tmpreg = (__HANDLE__)->Instance->SR; \ | |||
UNUSED(tmpreg); \ | |||
} while(0) | |||
/** @brief Clears the SPI FRE pending flag. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_CLEAR_FREFLAG(__HANDLE__) \ | |||
do{ \ | |||
__IO uint32_t tmpreg; \ | |||
tmpreg = (__HANDLE__)->Instance->SR; \ | |||
UNUSED(tmpreg); \ | |||
} while(0) | |||
/** @brief Enables the SPI. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SPI_CR1_SPE) | |||
/** @brief Disables the SPI. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= (~SPI_CR1_SPE)) | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros --------------------------------------------------------*/ | |||
/** @defgroup SPI_Private_Macros SPI Private Macros | |||
* @{ | |||
*/ | |||
/** @brief Sets the SPI transmit-only mode. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define SPI_1LINE_TX(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SPI_CR1_BIDIOE) | |||
/** @brief Sets the SPI receive-only mode. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define SPI_1LINE_RX(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= (~SPI_CR1_BIDIOE)) | |||
/** @brief Resets the CRC calculation of the SPI. | |||
* @param __HANDLE__ : specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define SPI_RESET_CRC(__HANDLE__) do{(__HANDLE__)->Instance->CR1 &= (uint16_t)(~SPI_CR1_CRCEN);\ | |||
(__HANDLE__)->Instance->CR1 |= SPI_CR1_CRCEN;}while(0) | |||
#define IS_SPI_MODE(MODE) (((MODE) == SPI_MODE_SLAVE) || \ | |||
((MODE) == SPI_MODE_MASTER)) | |||
#define IS_SPI_DIRECTION(MODE) (((MODE) == SPI_DIRECTION_2LINES) || \ | |||
((MODE) == SPI_DIRECTION_2LINES_RXONLY) ||\ | |||
((MODE) == SPI_DIRECTION_1LINE)) | |||
#define IS_SPI_DIRECTION_2LINES(MODE) ((MODE) == SPI_DIRECTION_2LINES) | |||
#define IS_SPI_DIRECTION_2LINES_OR_1LINE(MODE) (((MODE) == SPI_DIRECTION_2LINES)|| \ | |||
((MODE) == SPI_DIRECTION_1LINE)) | |||
#define IS_SPI_DATASIZE(DATASIZE) (((DATASIZE) == SPI_DATASIZE_16BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_15BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_14BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_13BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_12BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_11BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_10BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_9BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_8BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_7BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_6BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_5BIT) || \ | |||
((DATASIZE) == SPI_DATASIZE_4BIT)) | |||
#define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_POLARITY_LOW) || \ | |||
((CPOL) == SPI_POLARITY_HIGH)) | |||
#define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_PHASE_1EDGE) || \ | |||
((CPHA) == SPI_PHASE_2EDGE)) | |||
#define IS_SPI_NSS(NSS) (((NSS) == SPI_NSS_SOFT) || \ | |||
((NSS) == SPI_NSS_HARD_INPUT) || \ | |||
((NSS) == SPI_NSS_HARD_OUTPUT)) | |||
#define IS_SPI_NSSP(NSSP) (((NSSP) == SPI_NSS_PULSE_ENABLE) || \ | |||
((NSSP) == SPI_NSS_PULSE_DISABLE)) | |||
#define IS_SPI_BAUDRATE_PRESCALER(PRESCALER) (((PRESCALER) == SPI_BAUDRATEPRESCALER_2) || \ | |||
((PRESCALER) == SPI_BAUDRATEPRESCALER_4) || \ | |||
((PRESCALER) == SPI_BAUDRATEPRESCALER_8) || \ | |||
((PRESCALER) == SPI_BAUDRATEPRESCALER_16) || \ | |||
((PRESCALER) == SPI_BAUDRATEPRESCALER_32) || \ | |||
((PRESCALER) == SPI_BAUDRATEPRESCALER_64) || \ | |||
((PRESCALER) == SPI_BAUDRATEPRESCALER_128) || \ | |||
((PRESCALER) == SPI_BAUDRATEPRESCALER_256)) | |||
#define IS_SPI_FIRST_BIT(BIT) (((BIT) == SPI_FIRSTBIT_MSB) || \ | |||
((BIT) == SPI_FIRSTBIT_LSB)) | |||
#define IS_SPI_TIMODE(MODE) (((MODE) == SPI_TIMODE_DISABLE) || \ | |||
((MODE) == SPI_TIMODE_ENABLE)) | |||
#define IS_SPI_CRC_CALCULATION(CALCULATION) (((CALCULATION) == SPI_CRCCALCULATION_DISABLE) || \ | |||
((CALCULATION) == SPI_CRCCALCULATION_ENABLE)) | |||
#define IS_SPI_CRC_LENGTH(LENGTH) (((LENGTH) == SPI_CRC_LENGTH_DATASIZE) ||\ | |||
((LENGTH) == SPI_CRC_LENGTH_8BIT) || \ | |||
((LENGTH) == SPI_CRC_LENGTH_16BIT)) | |||
#define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL) (((POLYNOMIAL) >= 0x1) && ((POLYNOMIAL) <= 0xFFFF)) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup SPI_Exported_Functions SPI Exported Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup SPI_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions ****************************/ | |||
HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi); | |||
HAL_StatusTypeDef HAL_SPI_DeInit (SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup SPI_Exported_Functions_Group2 IO operation functions | |||
* @{ | |||
*/ | |||
/* IO operation functions *****************************************************/ | |||
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_DMAPause(SPI_HandleTypeDef *hspi); | |||
HAL_StatusTypeDef HAL_SPI_DMAResume(SPI_HandleTypeDef *hspi); | |||
HAL_StatusTypeDef HAL_SPI_DMAStop(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_IRQHandler(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup SPI_Exported_Functions_Group3 Peripheral State and Errors functions | |||
* @{ | |||
*/ | |||
/* Peripheral State and Error functions ***************************************/ | |||
HAL_SPI_StateTypeDef HAL_SPI_GetState(SPI_HandleTypeDef *hspi); | |||
uint32_t HAL_SPI_GetError(SPI_HandleTypeDef *hspi); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_SPI_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,552 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_tim_ex.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of TIM HAL Extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_TIM_EX_H | |||
#define __STM32F7xx_HAL_TIM_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup TIMEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup TIMEx_Exported_Types TIM Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief TIM Hall sensor Configuration Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal. | |||
This parameter can be a value of @ref TIM_Input_Capture_Polarity */ | |||
uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler. | |||
This parameter can be a value of @ref TIM_Input_Capture_Prescaler */ | |||
uint32_t IC1Filter; /*!< Specifies the input capture filter. | |||
This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */ | |||
uint32_t Commutation_Delay; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. | |||
This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */ | |||
} TIM_HallSensor_InitTypeDef; | |||
/** | |||
* @brief TIM Master configuration Structure definition | |||
*/ | |||
typedef struct { | |||
uint32_t MasterOutputTrigger; /*!< Trigger output (TRGO) selection. | |||
This parameter can be a value of @ref TIM_Master_Mode_Selection */ | |||
uint32_t MasterOutputTrigger2; /*!< Trigger output2 (TRGO2) selection | |||
This parameter can be a value of @ref TIMEx_Master_Mode_Selection_2 */ | |||
uint32_t MasterSlaveMode; /*!< Master/slave mode selection. | |||
This parameter can be a value of @ref TIM_Master_Slave_Mode */ | |||
}TIM_MasterConfigTypeDef; | |||
/** | |||
* @brief TIM Break input(s) and Dead time configuration Structure definition | |||
* @note 2 break inputs can be configured (BKIN and BKIN2) with configurable | |||
* filter and polarity. | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t OffStateRunMode; /*!< TIM off state in run mode. | |||
This parameter can be a value of @ref TIM_OSSR_Off_State_Selection_for_Run_mode_state */ | |||
uint32_t OffStateIDLEMode; /*!< TIM off state in IDLE mode. | |||
This parameter can be a value of @ref TIM_OSSI_Off_State_Selection_for_Idle_mode_state */ | |||
uint32_t LockLevel; /*!< TIM Lock level. | |||
This parameter can be a value of @ref TIM_Lock_level */ | |||
uint32_t DeadTime; /*!< TIM dead Time. | |||
This parameter can be a number between Min_Data = 0x00 and Max_Data = 0xFF */ | |||
uint32_t BreakState; /*!< TIM Break State. | |||
This parameter can be a value of @ref TIM_Break_Input_enable_disable */ | |||
uint32_t BreakPolarity; /*!< TIM Break input polarity. | |||
This parameter can be a value of @ref TIM_Break_Polarity */ | |||
uint32_t BreakFilter; /*!< Specifies the break input filter. | |||
This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */ | |||
uint32_t Break2State; /*!< TIM Break2 State | |||
This parameter can be a value of @ref TIMEx_Break2_Input_enable_disable */ | |||
uint32_t Break2Polarity; /*!< TIM Break2 input polarity | |||
This parameter can be a value of @ref TIMEx_Break2_Polarity */ | |||
uint32_t Break2Filter; /*!< TIM break2 input filter. | |||
This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */ | |||
uint32_t AutomaticOutput; /*!< TIM Automatic Output Enable state | |||
This parameter can be a value of @ref TIM_AOE_Bit_Set_Reset */ | |||
} TIM_BreakDeadTimeConfigTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup TIMEx_Exported_Constants TIMEx Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup TIMEx_Channel TIMEx Channel | |||
* @{ | |||
*/ | |||
#define TIM_CHANNEL_1 ((uint32_t)0x0000) | |||
#define TIM_CHANNEL_2 ((uint32_t)0x0004) | |||
#define TIM_CHANNEL_3 ((uint32_t)0x0008) | |||
#define TIM_CHANNEL_4 ((uint32_t)0x000C) | |||
#define TIM_CHANNEL_5 ((uint32_t)0x0010) | |||
#define TIM_CHANNEL_6 ((uint32_t)0x0014) | |||
#define TIM_CHANNEL_ALL ((uint32_t)0x003C) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup TIMEx_Output_Compare_and_PWM_modes TIMEx Output Compare and PWM Modes | |||
* @{ | |||
*/ | |||
#define TIM_OCMODE_TIMING ((uint32_t)0x0000) | |||
#define TIM_OCMODE_ACTIVE ((uint32_t)TIM_CCMR1_OC1M_0) | |||
#define TIM_OCMODE_INACTIVE ((uint32_t)TIM_CCMR1_OC1M_1) | |||
#define TIM_OCMODE_TOGGLE ((uint32_t)TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) | |||
#define TIM_OCMODE_PWM1 ((uint32_t)TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1) | |||
#define TIM_OCMODE_PWM2 ((uint32_t)TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) | |||
#define TIM_OCMODE_FORCED_ACTIVE ((uint32_t)TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0) | |||
#define TIM_OCMODE_FORCED_INACTIVE ((uint32_t)TIM_CCMR1_OC1M_2) | |||
#define TIM_OCMODE_RETRIGERRABLE_OPM1 ((uint32_t)TIM_CCMR1_OC1M_3) | |||
#define TIM_OCMODE_RETRIGERRABLE_OPM2 ((uint32_t)TIM_CCMR1_OC1M_3 | TIM_CCMR1_OC1M_0) | |||
#define TIM_OCMODE_COMBINED_PWM1 ((uint32_t)TIM_CCMR1_OC1M_3 | TIM_CCMR1_OC1M_2) | |||
#define TIM_OCMODE_COMBINED_PWM2 ((uint32_t)TIM_CCMR1_OC1M_3 | TIM_CCMR1_OC1M_0 | TIM_CCMR1_OC1M_2) | |||
#define TIM_OCMODE_ASSYMETRIC_PWM1 ((uint32_t)TIM_CCMR1_OC1M_3 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2) | |||
#define TIM_OCMODE_ASSYMETRIC_PWM2 ((uint32_t)TIM_CCMR1_OC1M_3 | TIM_CCMR1_OC1M) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup TIMEx_Remap TIMEx Remap | |||
* @{ | |||
*/ | |||
#define TIM_TIM2_TIM8_TRGO (0x00000000) | |||
#define TIM_TIM2_ETH_PTP (0x00000400) | |||
#define TIM_TIM2_USBFS_SOF (0x00000800) | |||
#define TIM_TIM2_USBHS_SOF (0x00000C00) | |||
#define TIM_TIM5_GPIO (0x00000000) | |||
#define TIM_TIM5_LSI (0x00000040) | |||
#define TIM_TIM5_LSE (0x00000080) | |||
#define TIM_TIM5_RTC (0x000000C0) | |||
#define TIM_TIM11_GPIO (0x00000000) | |||
#define TIM_TIM11_SPDIFRX (0x00000001) | |||
#define TIM_TIM11_HSE (0x00000002) | |||
#define TIM_TIM11_MCO1 (0x00000003) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup TIMEx_ClearInput_Source TIMEx Clear Input Source | |||
* @{ | |||
*/ | |||
#define TIM_CLEARINPUTSOURCE_ETR ((uint32_t)0x0001) | |||
#define TIM_CLEARINPUTSOURCE_OCREFCLR ((uint32_t)0x0002) | |||
#define TIM_CLEARINPUTSOURCE_NONE ((uint32_t)0x0000) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup TIMEx_Break2_Input_enable_disable TIMEx Break input 2 Enable | |||
* @{ | |||
*/ | |||
#define TIM_BREAK2_DISABLE ((uint32_t)0x00000000) | |||
#define TIM_BREAK2_ENABLE ((uint32_t)TIM_BDTR_BK2E) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup TIMEx_Break2_Polarity TIMEx Break2 Polarity | |||
* @{ | |||
*/ | |||
#define TIM_BREAK2POLARITY_LOW ((uint32_t)0x00000000) | |||
#define TIM_BREAK2POLARITY_HIGH (TIM_BDTR_BK2P) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup TIMEx_Group_Channel5 TIMEx Group Channel 5 and Channel 1, 2 or 3 | |||
* @{ | |||
*/ | |||
#define TIM_GROUPCH5_NONE (uint32_t)0x00000000 /* !< No effect of OC5REF on OC1REFC, OC2REFC and OC3REFC */ | |||
#define TIM_GROUPCH5_OC1REFC (TIM_CCR5_GC5C1) /* !< OC1REFC is the logical AND of OC1REFC and OC5REF */ | |||
#define TIM_GROUPCH5_OC2REFC (TIM_CCR5_GC5C2) /* !< OC2REFC is the logical AND of OC2REFC and OC5REF */ | |||
#define TIM_GROUPCH5_OC3REFC (TIM_CCR5_GC5C3) /* !< OC3REFC is the logical AND of OC3REFC and OC5REF */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup TIMEx_Master_Mode_Selection_2 TIMEx Master Mode Selection 2 (TRGO2) | |||
* @{ | |||
*/ | |||
#define TIM_TRGO2_RESET ((uint32_t)0x00000000) | |||
#define TIM_TRGO2_ENABLE ((uint32_t)(TIM_CR2_MMS2_0)) | |||
#define TIM_TRGO2_UPDATE ((uint32_t)(TIM_CR2_MMS2_1)) | |||
#define TIM_TRGO2_OC1 ((uint32_t)(TIM_CR2_MMS2_1 | TIM_CR2_MMS2_0)) | |||
#define TIM_TRGO2_OC1REF ((uint32_t)(TIM_CR2_MMS2_2)) | |||
#define TIM_TRGO2_OC2REF ((uint32_t)(TIM_CR2_MMS2_2 | TIM_CR2_MMS2_0)) | |||
#define TIM_TRGO2_OC3REF ((uint32_t)(TIM_CR2_MMS2_2 | TIM_CR2_MMS2_1)) | |||
#define TIM_TRGO2_OC4REF ((uint32_t)(TIM_CR2_MMS2_2 | TIM_CR2_MMS2_1 | TIM_CR2_MMS2_0)) | |||
#define TIM_TRGO2_OC5REF ((uint32_t)(TIM_CR2_MMS2_3)) | |||
#define TIM_TRGO2_OC6REF ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_0)) | |||
#define TIM_TRGO2_OC4REF_RISINGFALLING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_1)) | |||
#define TIM_TRGO2_OC6REF_RISINGFALLING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_1 | TIM_CR2_MMS2_0)) | |||
#define TIM_TRGO2_OC4REF_RISING_OC6REF_RISING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_2)) | |||
#define TIM_TRGO2_OC4REF_RISING_OC6REF_FALLING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_2 | TIM_CR2_MMS2_0)) | |||
#define TIM_TRGO2_OC5REF_RISING_OC6REF_RISING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_2 |TIM_CR2_MMS2_1)) | |||
#define TIM_TRGO2_OC5REF_RISING_OC6REF_FALLING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_2 | TIM_CR2_MMS2_1 | TIM_CR2_MMS2_0)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup TIMEx_Slave_Mode TIMEx Slave mode | |||
* @{ | |||
*/ | |||
#define TIM_SLAVEMODE_DISABLE ((uint32_t)0x0000) | |||
#define TIM_SLAVEMODE_RESET ((uint32_t)(TIM_SMCR_SMS_2)) | |||
#define TIM_SLAVEMODE_GATED ((uint32_t)(TIM_SMCR_SMS_2 | TIM_SMCR_SMS_0)) | |||
#define TIM_SLAVEMODE_TRIGGER ((uint32_t)(TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1)) | |||
#define TIM_SLAVEMODE_EXTERNAL1 ((uint32_t)(TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0)) | |||
#define TIM_SLAVEMODE_COMBINED_RESETTRIGGER ((uint32_t)(TIM_SMCR_SMS_3)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup TIMEx_Exported_Macros TIMEx Exported Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Sets the TIM Capture Compare Register value on runtime without | |||
* calling another time ConfigChannel function. | |||
* @param __HANDLE__: TIM handle. | |||
* @param __CHANNEL__ : TIM Channels to be configured. | |||
* This parameter can be one of the following values: | |||
* @arg TIM_CHANNEL_1: TIM Channel 1 selected | |||
* @arg TIM_CHANNEL_2: TIM Channel 2 selected | |||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected | |||
* @arg TIM_CHANNEL_4: TIM Channel 4 selected | |||
* @arg TIM_CHANNEL_5: TIM Channel 5 selected | |||
* @arg TIM_CHANNEL_6: TIM Channel 6 selected | |||
* @param __COMPARE__: specifies the Capture Compare register new value. | |||
* @retval None | |||
*/ | |||
#define __HAL_TIM_SET_COMPARE(__HANDLE__, __CHANNEL__, __COMPARE__) \ | |||
(((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCR1 = (__COMPARE__)) :\ | |||
((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCR2 = (__COMPARE__)) :\ | |||
((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCR3 = (__COMPARE__)) :\ | |||
((__CHANNEL__) == TIM_CHANNEL_4) ? ((__HANDLE__)->Instance->CCR4 = (__COMPARE__)) :\ | |||
((__CHANNEL__) == TIM_CHANNEL_5) ? ((__HANDLE__)->Instance->CCR5 = (__COMPARE__)) :\ | |||
((__HANDLE__)->Instance->CCR6 |= (__COMPARE__))) | |||
/** | |||
* @brief Gets the TIM Capture Compare Register value on runtime | |||
* @param __HANDLE__: TIM handle. | |||
* @param __CHANNEL__ : TIM Channel associated with the capture compare register | |||
* This parameter can be one of the following values: | |||
* @arg TIM_CHANNEL_1: get capture/compare 1 register value | |||
* @arg TIM_CHANNEL_2: get capture/compare 2 register value | |||
* @arg TIM_CHANNEL_3: get capture/compare 3 register value | |||
* @arg TIM_CHANNEL_4: get capture/compare 4 register value | |||
* @arg TIM_CHANNEL_5: get capture/compare 5 register value | |||
* @arg TIM_CHANNEL_6: get capture/compare 6 register value | |||
* @retval None | |||
*/ | |||
#define __HAL_TIM_GET_COMPARE(__HANDLE__, __CHANNEL__) \ | |||
(((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCR1) :\ | |||
((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCR2) :\ | |||
((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCR3) :\ | |||
((__CHANNEL__) == TIM_CHANNEL_4) ? ((__HANDLE__)->Instance->CCR4) :\ | |||
((__CHANNEL__) == TIM_CHANNEL_5) ? ((__HANDLE__)->Instance->CCR5) :\ | |||
((__HANDLE__)->Instance->CCR6)) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup TIMEx_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup TIMEx_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Timer Hall Sensor functions **********************************************/ | |||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef* htim, TIM_HallSensor_InitTypeDef* sConfig); | |||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef* htim); | |||
void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef* htim); | |||
void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef* htim); | |||
/* Blocking mode: Polling */ | |||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef* htim); | |||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef* htim); | |||
/* Non-Blocking mode: Interrupt */ | |||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef* htim); | |||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef* htim); | |||
/* Non-Blocking mode: DMA */ | |||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef* htim, uint32_t *pData, uint16_t Length); | |||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef* htim); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup TIMEx_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* Timer Complementary Output Compare functions *****************************/ | |||
/* Blocking mode: Polling */ | |||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef* htim, uint32_t Channel); | |||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef* htim, uint32_t Channel); | |||
/* Non-Blocking mode: Interrupt */ | |||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef* htim, uint32_t Channel); | |||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef* htim, uint32_t Channel); | |||
/* Non-Blocking mode: DMA */ | |||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef* htim, uint32_t Channel, uint32_t *pData, uint16_t Length); | |||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef* htim, uint32_t Channel); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup TIMEx_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
/* Timer Complementary PWM functions ****************************************/ | |||
/* Blocking mode: Polling */ | |||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef* htim, uint32_t Channel); | |||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef* htim, uint32_t Channel); | |||
/* Non-Blocking mode: Interrupt */ | |||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef* htim, uint32_t Channel); | |||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef* htim, uint32_t Channel); | |||
/* Non-Blocking mode: DMA */ | |||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef* htim, uint32_t Channel, uint32_t *pData, uint16_t Length); | |||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef* htim, uint32_t Channel); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup TIMEx_Exported_Functions_Group4 | |||
* @{ | |||
*/ | |||
/* Timer Complementary One Pulse functions **********************************/ | |||
/* Blocking mode: Polling */ | |||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef* htim, uint32_t OutputChannel); | |||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef* htim, uint32_t OutputChannel); | |||
/* Non-Blocking mode: Interrupt */ | |||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef* htim, uint32_t OutputChannel); | |||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef* htim, uint32_t OutputChannel); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup TIMEx_Exported_Functions_Group5 | |||
* @{ | |||
*/ | |||
/* Extension Control functions ************************************************/ | |||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef* htim, uint32_t InputTrigger, uint32_t CommutationSource); | |||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef* htim, uint32_t InputTrigger, uint32_t CommutationSource); | |||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef* htim, uint32_t InputTrigger, uint32_t CommutationSource); | |||
HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef* htim, TIM_MasterConfigTypeDef * sMasterConfig); | |||
HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef* htim, TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig); | |||
HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef* htim, uint32_t Remap); | |||
HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t OCRef); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup TIMEx_Exported_Functions_Group6 | |||
* @{ | |||
*/ | |||
/* Extension Callback *********************************************************/ | |||
void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef* htim); | |||
void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef* htim); | |||
void HAL_TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup TIMEx_Exported_Functions_Group7 | |||
* @{ | |||
*/ | |||
/* Extension Peripheral State functions **************************************/ | |||
HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef* htim); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup TIMEx_Private_Macros TIMEx Private Macros | |||
* @{ | |||
*/ | |||
#define IS_TIM_CHANNELS(CHANNEL) (((CHANNEL) == TIM_CHANNEL_1) || \ | |||
((CHANNEL) == TIM_CHANNEL_2) || \ | |||
((CHANNEL) == TIM_CHANNEL_3) || \ | |||
((CHANNEL) == TIM_CHANNEL_4) || \ | |||
((CHANNEL) == TIM_CHANNEL_5) || \ | |||
((CHANNEL) == TIM_CHANNEL_6) || \ | |||
((CHANNEL) == TIM_CHANNEL_ALL)) | |||
#define IS_TIM_PWMI_CHANNELS(CHANNEL) (((CHANNEL) == TIM_CHANNEL_1) || \ | |||
((CHANNEL) == TIM_CHANNEL_2)) | |||
#define IS_TIM_OPM_CHANNELS(CHANNEL) (((CHANNEL) == TIM_CHANNEL_1) || \ | |||
((CHANNEL) == TIM_CHANNEL_2)) | |||
#define IS_TIM_COMPLEMENTARY_CHANNELS(CHANNEL) (((CHANNEL) == TIM_CHANNEL_1) || \ | |||
((CHANNEL) == TIM_CHANNEL_2) || \ | |||
((CHANNEL) == TIM_CHANNEL_3)) | |||
#define IS_TIM_PWM_MODE(MODE) (((MODE) == TIM_OCMODE_PWM1) || \ | |||
((MODE) == TIM_OCMODE_PWM2) || \ | |||
((MODE) == TIM_OCMODE_COMBINED_PWM1) || \ | |||
((MODE) == TIM_OCMODE_COMBINED_PWM2) || \ | |||
((MODE) == TIM_OCMODE_ASSYMETRIC_PWM1) || \ | |||
((MODE) == TIM_OCMODE_ASSYMETRIC_PWM2)) | |||
#define IS_TIM_OC_MODE(MODE) (((MODE) == TIM_OCMODE_TIMING) || \ | |||
((MODE) == TIM_OCMODE_ACTIVE) || \ | |||
((MODE) == TIM_OCMODE_INACTIVE) || \ | |||
((MODE) == TIM_OCMODE_TOGGLE) || \ | |||
((MODE) == TIM_OCMODE_FORCED_ACTIVE) || \ | |||
((MODE) == TIM_OCMODE_FORCED_INACTIVE) || \ | |||
((MODE) == TIM_OCMODE_RETRIGERRABLE_OPM1) || \ | |||
((MODE) == TIM_OCMODE_RETRIGERRABLE_OPM2)) | |||
#define IS_TIM_REMAP(__TIM_REMAP__) (((__TIM_REMAP__) == TIM_TIM2_TIM8_TRGO)||\ | |||
((__TIM_REMAP__) == TIM_TIM2_ETH_PTP)||\ | |||
((__TIM_REMAP__) == TIM_TIM2_USBFS_SOF)||\ | |||
((__TIM_REMAP__) == TIM_TIM2_USBHS_SOF)||\ | |||
((__TIM_REMAP__) == TIM_TIM5_GPIO)||\ | |||
((__TIM_REMAP__) == TIM_TIM5_LSI)||\ | |||
((__TIM_REMAP__) == TIM_TIM5_LSE)||\ | |||
((__TIM_REMAP__) == TIM_TIM5_RTC)||\ | |||
((__TIM_REMAP__) == TIM_TIM11_GPIO)||\ | |||
((__TIM_REMAP__) == TIM_TIM11_SPDIFRX)||\ | |||
((__TIM_REMAP__) == TIM_TIM11_HSE)||\ | |||
((__TIM_REMAP__) == TIM_TIM11_MCO1)) | |||
#define IS_TIM_DEADTIME(__DEADTIME__) ((__DEADTIME__) <= 0xFF) | |||
#define IS_TIM_BREAK_FILTER(__FILTER__) ((__FILTER__) <= 0xF) | |||
#define IS_TIM_CLEARINPUT_SOURCE(MODE) (((MODE) == TIM_CLEARINPUTSOURCE_ETR) || \ | |||
((MODE) == TIM_CLEARINPUTSOURCE_OCREFCLR) || \ | |||
((MODE) == TIM_CLEARINPUTSOURCE_NONE)) | |||
#define IS_TIM_BREAK2_STATE(STATE) (((STATE) == TIM_BREAK2_ENABLE) || \ | |||
((STATE) == TIM_BREAK2_DISABLE)) | |||
#define IS_TIM_BREAK2_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_BREAK2POLARITY_LOW) || \ | |||
((__POLARITY__) == TIM_BREAK2POLARITY_HIGH)) | |||
#define IS_TIM_GROUPCH5(OCREF) ((((OCREF) & 0x1FFFFFFF) == 0x00000000)) | |||
#define IS_TIM_TRGO2_SOURCE(SOURCE) (((SOURCE) == TIM_TRGO2_RESET) || \ | |||
((SOURCE) == TIM_TRGO2_ENABLE) || \ | |||
((SOURCE) == TIM_TRGO2_UPDATE) || \ | |||
((SOURCE) == TIM_TRGO2_OC1) || \ | |||
((SOURCE) == TIM_TRGO2_OC1REF) || \ | |||
((SOURCE) == TIM_TRGO2_OC2REF) || \ | |||
((SOURCE) == TIM_TRGO2_OC3REF) || \ | |||
((SOURCE) == TIM_TRGO2_OC3REF) || \ | |||
((SOURCE) == TIM_TRGO2_OC4REF) || \ | |||
((SOURCE) == TIM_TRGO2_OC5REF) || \ | |||
((SOURCE) == TIM_TRGO2_OC6REF) || \ | |||
((SOURCE) == TIM_TRGO2_OC4REF_RISINGFALLING) || \ | |||
((SOURCE) == TIM_TRGO2_OC6REF_RISINGFALLING) || \ | |||
((SOURCE) == TIM_TRGO2_OC4REF_RISING_OC6REF_RISING) || \ | |||
((SOURCE) == TIM_TRGO2_OC4REF_RISING_OC6REF_FALLING) || \ | |||
((SOURCE) == TIM_TRGO2_OC5REF_RISING_OC6REF_RISING) || \ | |||
((SOURCE) == TIM_TRGO2_OC5REF_RISING_OC6REF_FALLING)) | |||
#define IS_TIM_SLAVE_MODE(MODE) (((MODE) == TIM_SLAVEMODE_DISABLE) || \ | |||
((MODE) == TIM_SLAVEMODE_RESET) || \ | |||
((MODE) == TIM_SLAVEMODE_GATED) || \ | |||
((MODE) == TIM_SLAVEMODE_TRIGGER) || \ | |||
((MODE) == TIM_SLAVEMODE_EXTERNAL1) || \ | |||
((MODE) == TIM_SLAVEMODE_COMBINED_RESETTRIGGER)) | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup TIMEx_Private_Functions TIMEx Private Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_TIM_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,335 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_uart_ex.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of UART HAL Extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_HAL_UART_EX_H | |||
#define __STM32F7xx_HAL_UART_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup UARTEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup UARTEx_Exported_Constants UARTEx Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup UARTEx_Word_Length UARTEx Word Length | |||
* @{ | |||
*/ | |||
#define UART_WORDLENGTH_7B ((uint32_t)USART_CR1_M_1) | |||
#define UART_WORDLENGTH_8B ((uint32_t)0x0000) | |||
#define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M_0) | |||
#define IS_UART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == UART_WORDLENGTH_7B) || \ | |||
((__LENGTH__) == UART_WORDLENGTH_8B) || \ | |||
((__LENGTH__) == UART_WORDLENGTH_9B)) | |||
#define IS_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup UARTEx_WakeUp_Address_Length UARTEx WakeUp Address Length | |||
* @{ | |||
*/ | |||
#define UART_ADDRESS_DETECT_4B ((uint32_t)0x00000000) | |||
#define UART_ADDRESS_DETECT_7B ((uint32_t)USART_CR2_ADDM7) | |||
#define IS_UART_ADDRESSLENGTH_DETECT(__ADDRESS__) (((__ADDRESS__) == UART_ADDRESS_DETECT_4B) || \ | |||
((__ADDRESS__) == UART_ADDRESS_DETECT_7B)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup UARTEx_Exported_Macros UARTEx Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reports the UART clock source. | |||
* @param __HANDLE__: specifies the UART Handle | |||
* @param __CLOCKSOURCE__: output variable | |||
* @retval UART clocking source, written in __CLOCKSOURCE__. | |||
*/ | |||
#define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ | |||
do { \ | |||
if((__HANDLE__)->Instance == USART1) \ | |||
{ \ | |||
switch(__HAL_RCC_GET_USART1_SOURCE()) \ | |||
{ \ | |||
case RCC_USART1CLKSOURCE_PCLK2: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \ | |||
break; \ | |||
case RCC_USART1CLKSOURCE_HSI: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ | |||
break; \ | |||
case RCC_USART1CLKSOURCE_SYSCLK: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ | |||
break; \ | |||
case RCC_USART1CLKSOURCE_LSE: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ | |||
break; \ | |||
default: \ | |||
break; \ | |||
} \ | |||
} \ | |||
else if((__HANDLE__)->Instance == USART2) \ | |||
{ \ | |||
switch(__HAL_RCC_GET_USART2_SOURCE()) \ | |||
{ \ | |||
case RCC_USART2CLKSOURCE_PCLK1: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \ | |||
break; \ | |||
case RCC_USART2CLKSOURCE_HSI: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ | |||
break; \ | |||
case RCC_USART2CLKSOURCE_SYSCLK: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ | |||
break; \ | |||
case RCC_USART2CLKSOURCE_LSE: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ | |||
break; \ | |||
default: \ | |||
break; \ | |||
} \ | |||
} \ | |||
else if((__HANDLE__)->Instance == USART3) \ | |||
{ \ | |||
switch(__HAL_RCC_GET_USART3_SOURCE()) \ | |||
{ \ | |||
case RCC_USART3CLKSOURCE_PCLK1: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \ | |||
break; \ | |||
case RCC_USART3CLKSOURCE_HSI: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ | |||
break; \ | |||
case RCC_USART3CLKSOURCE_SYSCLK: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ | |||
break; \ | |||
case RCC_USART3CLKSOURCE_LSE: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ | |||
break; \ | |||
default: \ | |||
break; \ | |||
} \ | |||
} \ | |||
else if((__HANDLE__)->Instance == UART4) \ | |||
{ \ | |||
switch(__HAL_RCC_GET_UART4_SOURCE()) \ | |||
{ \ | |||
case RCC_UART4CLKSOURCE_PCLK1: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \ | |||
break; \ | |||
case RCC_UART4CLKSOURCE_HSI: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ | |||
break; \ | |||
case RCC_UART4CLKSOURCE_SYSCLK: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ | |||
break; \ | |||
case RCC_UART4CLKSOURCE_LSE: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ | |||
break; \ | |||
default: \ | |||
break; \ | |||
} \ | |||
} \ | |||
else if ((__HANDLE__)->Instance == UART5) \ | |||
{ \ | |||
switch(__HAL_RCC_GET_UART5_SOURCE()) \ | |||
{ \ | |||
case RCC_UART5CLKSOURCE_PCLK1: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \ | |||
break; \ | |||
case RCC_UART5CLKSOURCE_HSI: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ | |||
break; \ | |||
case RCC_UART5CLKSOURCE_SYSCLK: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ | |||
break; \ | |||
case RCC_UART5CLKSOURCE_LSE: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ | |||
break; \ | |||
default: \ | |||
break; \ | |||
} \ | |||
} \ | |||
else if((__HANDLE__)->Instance == USART6) \ | |||
{ \ | |||
switch(__HAL_RCC_GET_USART6_SOURCE()) \ | |||
{ \ | |||
case RCC_USART6CLKSOURCE_PCLK2: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \ | |||
break; \ | |||
case RCC_USART6CLKSOURCE_HSI: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ | |||
break; \ | |||
case RCC_USART6CLKSOURCE_SYSCLK: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ | |||
break; \ | |||
case RCC_USART6CLKSOURCE_LSE: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ | |||
break; \ | |||
default: \ | |||
break; \ | |||
} \ | |||
} \ | |||
else if ((__HANDLE__)->Instance == UART7) \ | |||
{ \ | |||
switch(__HAL_RCC_GET_UART7_SOURCE()) \ | |||
{ \ | |||
case RCC_UART7CLKSOURCE_PCLK1: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \ | |||
break; \ | |||
case RCC_UART7CLKSOURCE_HSI: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ | |||
break; \ | |||
case RCC_UART7CLKSOURCE_SYSCLK: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ | |||
break; \ | |||
case RCC_UART7CLKSOURCE_LSE: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ | |||
break; \ | |||
default: \ | |||
break; \ | |||
} \ | |||
} \ | |||
else if ((__HANDLE__)->Instance == UART8) \ | |||
{ \ | |||
switch(__HAL_RCC_GET_UART8_SOURCE()) \ | |||
{ \ | |||
case RCC_UART8CLKSOURCE_PCLK1: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \ | |||
break; \ | |||
case RCC_UART8CLKSOURCE_HSI: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ | |||
break; \ | |||
case RCC_UART8CLKSOURCE_SYSCLK: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ | |||
break; \ | |||
case RCC_UART8CLKSOURCE_LSE: \ | |||
(__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ | |||
break; \ | |||
default: \ | |||
break; \ | |||
} \ | |||
} \ | |||
} while(0) | |||
/** @brief Reports the UART mask to apply to retrieve the received data | |||
* according to the word length and to the parity bits activation. | |||
* If PCE = 1, the parity bit is not included in the data extracted | |||
* by the reception API(). | |||
* This masking operation is not carried out in the case of | |||
* DMA transfers. | |||
* @param __HANDLE__: specifies the UART Handle | |||
* @retval mask to apply to UART RDR register value. | |||
*/ | |||
#define UART_MASK_COMPUTATION(__HANDLE__) \ | |||
do { \ | |||
if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B) \ | |||
{ \ | |||
if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \ | |||
{ \ | |||
(__HANDLE__)->Mask = 0x01FF ; \ | |||
} \ | |||
else \ | |||
{ \ | |||
(__HANDLE__)->Mask = 0x00FF ; \ | |||
} \ | |||
} \ | |||
else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B) \ | |||
{ \ | |||
if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \ | |||
{ \ | |||
(__HANDLE__)->Mask = 0x00FF ; \ | |||
} \ | |||
else \ | |||
{ \ | |||
(__HANDLE__)->Mask = 0x007F ; \ | |||
} \ | |||
} \ | |||
else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_7B) \ | |||
{ \ | |||
if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \ | |||
{ \ | |||
(__HANDLE__)->Mask = 0x007F ; \ | |||
} \ | |||
else \ | |||
{ \ | |||
(__HANDLE__)->Mask = 0x003F ; \ | |||
} \ | |||
} \ | |||
} while(0) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_HAL_UART_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,804 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_ll_sdmmc.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of SDMMC HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_LL_SDMMC_H | |||
#define __STM32F7xx_LL_SDMMC_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup SDMMC_LL | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup SDMMC_LL_Exported_Types SDMMC_LL Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief SDMMC Configuration Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t ClockEdge; /*!< Specifies the clock transition on which the bit capture is made. | |||
This parameter can be a value of @ref SDMMC_LL_Clock_Edge */ | |||
uint32_t ClockBypass; /*!< Specifies whether the SDMMC Clock divider bypass is | |||
enabled or disabled. | |||
This parameter can be a value of @ref SDMMC_LL_Clock_Bypass */ | |||
uint32_t ClockPowerSave; /*!< Specifies whether SDMMC Clock output is enabled or | |||
disabled when the bus is idle. | |||
This parameter can be a value of @ref SDMMC_LL_Clock_Power_Save */ | |||
uint32_t BusWide; /*!< Specifies the SDMMC bus width. | |||
This parameter can be a value of @ref SDMMC_LL_Bus_Wide */ | |||
uint32_t HardwareFlowControl; /*!< Specifies whether the SDMMC hardware flow control is enabled or disabled. | |||
This parameter can be a value of @ref SDMMC_LL_Hardware_Flow_Control */ | |||
uint32_t ClockDiv; /*!< Specifies the clock frequency of the SDMMC controller. | |||
This parameter can be a value between Min_Data = 0 and Max_Data = 255 */ | |||
}SDMMC_InitTypeDef; | |||
/** | |||
* @brief SDMMC Command Control structure | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Argument; /*!< Specifies the SDMMC command argument which is sent | |||
to a card as part of a command message. If a command | |||
contains an argument, it must be loaded into this register | |||
before writing the command to the command register. */ | |||
uint32_t CmdIndex; /*!< Specifies the SDMMC command index. It must be Min_Data = 0 and | |||
Max_Data = 64 */ | |||
uint32_t Response; /*!< Specifies the SDMMC response type. | |||
This parameter can be a value of @ref SDMMC_LL_Response_Type */ | |||
uint32_t WaitForInterrupt; /*!< Specifies whether SDMMC wait for interrupt request is | |||
enabled or disabled. | |||
This parameter can be a value of @ref SDMMC_LL_Wait_Interrupt_State */ | |||
uint32_t CPSM; /*!< Specifies whether SDMMC Command path state machine (CPSM) | |||
is enabled or disabled. | |||
This parameter can be a value of @ref SDMMC_LL_CPSM_State */ | |||
}SDMMC_CmdInitTypeDef; | |||
/** | |||
* @brief SDMMC Data Control structure | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t DataTimeOut; /*!< Specifies the data timeout period in card bus clock periods. */ | |||
uint32_t DataLength; /*!< Specifies the number of data bytes to be transferred. */ | |||
uint32_t DataBlockSize; /*!< Specifies the data block size for block transfer. | |||
This parameter can be a value of @ref SDMMC_LL_Data_Block_Size */ | |||
uint32_t TransferDir; /*!< Specifies the data transfer direction, whether the transfer | |||
is a read or write. | |||
This parameter can be a value of @ref SDMMC_LL_Transfer_Direction */ | |||
uint32_t TransferMode; /*!< Specifies whether data transfer is in stream or block mode. | |||
This parameter can be a value of @ref SDMMC_LL_Transfer_Type */ | |||
uint32_t DPSM; /*!< Specifies whether SDMMC Data path state machine (DPSM) | |||
is enabled or disabled. | |||
This parameter can be a value of @ref SDMMC_LL_DPSM_State */ | |||
}SDMMC_DataInitTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup SDMMC_LL_Exported_Constants SDMMC_LL Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup SDMMC_LL_Clock_Edge Clock Edge | |||
* @{ | |||
*/ | |||
#define SDMMC_CLOCK_EDGE_RISING ((uint32_t)0x00000000) | |||
#define SDMMC_CLOCK_EDGE_FALLING SDMMC_CLKCR_NEGEDGE | |||
#define IS_SDMMC_CLOCK_EDGE(EDGE) (((EDGE) == SDMMC_CLOCK_EDGE_RISING) || \ | |||
((EDGE) == SDMMC_CLOCK_EDGE_FALLING)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Clock_Bypass Clock Bypass | |||
* @{ | |||
*/ | |||
#define SDMMC_CLOCK_BYPASS_DISABLE ((uint32_t)0x00000000) | |||
#define SDMMC_CLOCK_BYPASS_ENABLE SDMMC_CLKCR_BYPASS | |||
#define IS_SDMMC_CLOCK_BYPASS(BYPASS) (((BYPASS) == SDMMC_CLOCK_BYPASS_DISABLE) || \ | |||
((BYPASS) == SDMMC_CLOCK_BYPASS_ENABLE)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Clock_Power_Save Clock Power Saving | |||
* @{ | |||
*/ | |||
#define SDMMC_CLOCK_POWER_SAVE_DISABLE ((uint32_t)0x00000000) | |||
#define SDMMC_CLOCK_POWER_SAVE_ENABLE SDMMC_CLKCR_PWRSAV | |||
#define IS_SDMMC_CLOCK_POWER_SAVE(SAVE) (((SAVE) == SDMMC_CLOCK_POWER_SAVE_DISABLE) || \ | |||
((SAVE) == SDMMC_CLOCK_POWER_SAVE_ENABLE)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Bus_Wide Bus Width | |||
* @{ | |||
*/ | |||
#define SDMMC_BUS_WIDE_1B ((uint32_t)0x00000000) | |||
#define SDMMC_BUS_WIDE_4B SDMMC_CLKCR_WIDBUS_0 | |||
#define SDMMC_BUS_WIDE_8B SDMMC_CLKCR_WIDBUS_1 | |||
#define IS_SDMMC_BUS_WIDE(WIDE) (((WIDE) == SDMMC_BUS_WIDE_1B) || \ | |||
((WIDE) == SDMMC_BUS_WIDE_4B) || \ | |||
((WIDE) == SDMMC_BUS_WIDE_8B)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Hardware_Flow_Control Hardware Flow Control | |||
* @{ | |||
*/ | |||
#define SDMMC_HARDWARE_FLOW_CONTROL_DISABLE ((uint32_t)0x00000000) | |||
#define SDMMC_HARDWARE_FLOW_CONTROL_ENABLE SDMMC_CLKCR_HWFC_EN | |||
#define IS_SDMMC_HARDWARE_FLOW_CONTROL(CONTROL) (((CONTROL) == SDMMC_HARDWARE_FLOW_CONTROL_DISABLE) || \ | |||
((CONTROL) == SDMMC_HARDWARE_FLOW_CONTROL_ENABLE)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Clock_Division Clock Division | |||
* @{ | |||
*/ | |||
#define IS_SDMMC_CLKDIV(DIV) ((DIV) <= 0xFF) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Command_Index Command Index | |||
* @{ | |||
*/ | |||
#define IS_SDMMC_CMD_INDEX(INDEX) ((INDEX) < 0x40) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Response_Type Response Type | |||
* @{ | |||
*/ | |||
#define SDMMC_RESPONSE_NO ((uint32_t)0x00000000) | |||
#define SDMMC_RESPONSE_SHORT SDMMC_CMD_WAITRESP_0 | |||
#define SDMMC_RESPONSE_LONG SDMMC_CMD_WAITRESP | |||
#define IS_SDMMC_RESPONSE(RESPONSE) (((RESPONSE) == SDMMC_RESPONSE_NO) || \ | |||
((RESPONSE) == SDMMC_RESPONSE_SHORT) || \ | |||
((RESPONSE) == SDMMC_RESPONSE_LONG)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Wait_Interrupt_State Wait Interrupt | |||
* @{ | |||
*/ | |||
#define SDMMC_WAIT_NO ((uint32_t)0x00000000) | |||
#define SDMMC_WAIT_IT SDMMC_CMD_WAITINT | |||
#define SDMMC_WAIT_PEND SDMMC_CMD_WAITPEND | |||
#define IS_SDMMC_WAIT(WAIT) (((WAIT) == SDMMC_WAIT_NO) || \ | |||
((WAIT) == SDMMC_WAIT_IT) || \ | |||
((WAIT) == SDMMC_WAIT_PEND)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_CPSM_State CPSM State | |||
* @{ | |||
*/ | |||
#define SDMMC_CPSM_DISABLE ((uint32_t)0x00000000) | |||
#define SDMMC_CPSM_ENABLE SDMMC_CMD_CPSMEN | |||
#define IS_SDMMC_CPSM(CPSM) (((CPSM) == SDMMC_CPSM_DISABLE) || \ | |||
((CPSM) == SDMMC_CPSM_ENABLE)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Response_Registers Response Register | |||
* @{ | |||
*/ | |||
#define SDMMC_RESP1 ((uint32_t)0x00000000) | |||
#define SDMMC_RESP2 ((uint32_t)0x00000004) | |||
#define SDMMC_RESP3 ((uint32_t)0x00000008) | |||
#define SDMMC_RESP4 ((uint32_t)0x0000000C) | |||
#define IS_SDMMC_RESP(RESP) (((RESP) == SDMMC_RESP1) || \ | |||
((RESP) == SDMMC_RESP2) || \ | |||
((RESP) == SDMMC_RESP3) || \ | |||
((RESP) == SDMMC_RESP4)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Data_Length Data Lenght | |||
* @{ | |||
*/ | |||
#define IS_SDMMC_DATA_LENGTH(LENGTH) ((LENGTH) <= 0x01FFFFFF) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Data_Block_Size Data Block Size | |||
* @{ | |||
*/ | |||
#define SDMMC_DATABLOCK_SIZE_1B ((uint32_t)0x00000000) | |||
#define SDMMC_DATABLOCK_SIZE_2B SDMMC_DCTRL_DBLOCKSIZE_0 | |||
#define SDMMC_DATABLOCK_SIZE_4B SDMMC_DCTRL_DBLOCKSIZE_1 | |||
#define SDMMC_DATABLOCK_SIZE_8B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1) | |||
#define SDMMC_DATABLOCK_SIZE_16B SDMMC_DCTRL_DBLOCKSIZE_2 | |||
#define SDMMC_DATABLOCK_SIZE_32B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_2) | |||
#define SDMMC_DATABLOCK_SIZE_64B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2) | |||
#define SDMMC_DATABLOCK_SIZE_128B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2) | |||
#define SDMMC_DATABLOCK_SIZE_256B SDMMC_DCTRL_DBLOCKSIZE_3 | |||
#define SDMMC_DATABLOCK_SIZE_512B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_3) | |||
#define SDMMC_DATABLOCK_SIZE_1024B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_3) | |||
#define SDMMC_DATABLOCK_SIZE_2048B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_3) | |||
#define SDMMC_DATABLOCK_SIZE_4096B (SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3) | |||
#define SDMMC_DATABLOCK_SIZE_8192B (SDMMC_DCTRL_DBLOCKSIZE_0|SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3) | |||
#define SDMMC_DATABLOCK_SIZE_16384B (SDMMC_DCTRL_DBLOCKSIZE_1|SDMMC_DCTRL_DBLOCKSIZE_2|SDMMC_DCTRL_DBLOCKSIZE_3) | |||
#define IS_SDMMC_BLOCK_SIZE(SIZE) (((SIZE) == SDMMC_DATABLOCK_SIZE_1B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_2B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_4B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_8B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_16B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_32B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_64B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_128B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_256B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_512B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_1024B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_2048B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_4096B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_8192B) || \ | |||
((SIZE) == SDMMC_DATABLOCK_SIZE_16384B)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Transfer_Direction Transfer Direction | |||
* @{ | |||
*/ | |||
#define SDMMC_TRANSFER_DIR_TO_CARD ((uint32_t)0x00000000) | |||
#define SDMMC_TRANSFER_DIR_TO_SDMMC SDMMC_DCTRL_DTDIR | |||
#define IS_SDMMC_TRANSFER_DIR(DIR) (((DIR) == SDMMC_TRANSFER_DIR_TO_CARD) || \ | |||
((DIR) == SDMMC_TRANSFER_DIR_TO_SDMMC)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Transfer_Type Transfer Type | |||
* @{ | |||
*/ | |||
#define SDMMC_TRANSFER_MODE_BLOCK ((uint32_t)0x00000000) | |||
#define SDMMC_TRANSFER_MODE_STREAM SDMMC_DCTRL_DTMODE | |||
#define IS_SDMMC_TRANSFER_MODE(MODE) (((MODE) == SDMMC_TRANSFER_MODE_BLOCK) || \ | |||
((MODE) == SDMMC_TRANSFER_MODE_STREAM)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_DPSM_State DPSM State | |||
* @{ | |||
*/ | |||
#define SDMMC_DPSM_DISABLE ((uint32_t)0x00000000) | |||
#define SDMMC_DPSM_ENABLE SDMMC_DCTRL_DTEN | |||
#define IS_SDMMC_DPSM(DPSM) (((DPSM) == SDMMC_DPSM_DISABLE) ||\ | |||
((DPSM) == SDMMC_DPSM_ENABLE)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Read_Wait_Mode Read Wait Mode | |||
* @{ | |||
*/ | |||
#define SDMMC_READ_WAIT_MODE_DATA2 ((uint32_t)0x00000000) | |||
#define SDMMC_READ_WAIT_MODE_CLK (SDMMC_DCTRL_RWMOD) | |||
#define IS_SDMMC_READWAIT_MODE(MODE) (((MODE) == SDMMC_READ_WAIT_MODE_CLK) || \ | |||
((MODE) == SDMMC_READ_WAIT_MODE_DATA2)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Interrupt_sources Interrupt Sources | |||
* @{ | |||
*/ | |||
#define SDMMC_IT_CCRCFAIL SDMMC_STA_CCRCFAIL | |||
#define SDMMC_IT_DCRCFAIL SDMMC_STA_DCRCFAIL | |||
#define SDMMC_IT_CTIMEOUT SDMMC_STA_CTIMEOUT | |||
#define SDMMC_IT_DTIMEOUT SDMMC_STA_DTIMEOUT | |||
#define SDMMC_IT_TXUNDERR SDMMC_STA_TXUNDERR | |||
#define SDMMC_IT_RXOVERR SDMMC_STA_RXOVERR | |||
#define SDMMC_IT_CMDREND SDMMC_STA_CMDREND | |||
#define SDMMC_IT_CMDSENT SDMMC_STA_CMDSENT | |||
#define SDMMC_IT_DATAEND SDMMC_STA_DATAEND | |||
#define SDMMC_IT_DBCKEND SDMMC_STA_DBCKEND | |||
#define SDMMC_IT_CMDACT SDMMC_STA_CMDACT | |||
#define SDMMC_IT_TXACT SDMMC_STA_TXACT | |||
#define SDMMC_IT_RXACT SDMMC_STA_RXACT | |||
#define SDMMC_IT_TXFIFOHE SDMMC_STA_TXFIFOHE | |||
#define SDMMC_IT_RXFIFOHF SDMMC_STA_RXFIFOHF | |||
#define SDMMC_IT_TXFIFOF SDMMC_STA_TXFIFOF | |||
#define SDMMC_IT_RXFIFOF SDMMC_STA_RXFIFOF | |||
#define SDMMC_IT_TXFIFOE SDMMC_STA_TXFIFOE | |||
#define SDMMC_IT_RXFIFOE SDMMC_STA_RXFIFOE | |||
#define SDMMC_IT_TXDAVL SDMMC_STA_TXDAVL | |||
#define SDMMC_IT_RXDAVL SDMMC_STA_RXDAVL | |||
#define SDMMC_IT_SDIOIT SDMMC_STA_SDIOIT | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Flags Flags | |||
* @{ | |||
*/ | |||
#define SDMMC_FLAG_CCRCFAIL SDMMC_STA_CCRCFAIL | |||
#define SDMMC_FLAG_DCRCFAIL SDMMC_STA_DCRCFAIL | |||
#define SDMMC_FLAG_CTIMEOUT SDMMC_STA_CTIMEOUT | |||
#define SDMMC_FLAG_DTIMEOUT SDMMC_STA_DTIMEOUT | |||
#define SDMMC_FLAG_TXUNDERR SDMMC_STA_TXUNDERR | |||
#define SDMMC_FLAG_RXOVERR SDMMC_STA_RXOVERR | |||
#define SDMMC_FLAG_CMDREND SDMMC_STA_CMDREND | |||
#define SDMMC_FLAG_CMDSENT SDMMC_STA_CMDSENT | |||
#define SDMMC_FLAG_DATAEND SDMMC_STA_DATAEND | |||
#define SDMMC_FLAG_DBCKEND SDMMC_STA_DBCKEND | |||
#define SDMMC_FLAG_CMDACT SDMMC_STA_CMDACT | |||
#define SDMMC_FLAG_TXACT SDMMC_STA_TXACT | |||
#define SDMMC_FLAG_RXACT SDMMC_STA_RXACT | |||
#define SDMMC_FLAG_TXFIFOHE SDMMC_STA_TXFIFOHE | |||
#define SDMMC_FLAG_RXFIFOHF SDMMC_STA_RXFIFOHF | |||
#define SDMMC_FLAG_TXFIFOF SDMMC_STA_TXFIFOF | |||
#define SDMMC_FLAG_RXFIFOF SDMMC_STA_RXFIFOF | |||
#define SDMMC_FLAG_TXFIFOE SDMMC_STA_TXFIFOE | |||
#define SDMMC_FLAG_RXFIFOE SDMMC_STA_RXFIFOE | |||
#define SDMMC_FLAG_TXDAVL SDMMC_STA_TXDAVL | |||
#define SDMMC_FLAG_RXDAVL SDMMC_STA_RXDAVL | |||
#define SDMMC_FLAG_SDIOIT SDMMC_STA_SDIOIT | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup SDMMC_LL_Exported_macros SDMMC_LL Exported Macros | |||
* @{ | |||
*/ | |||
/** @defgroup SDMMC_LL_Register Bits And Addresses Definitions | |||
* @brief SDMMC_LL registers bit address in the alias region | |||
* @{ | |||
*/ | |||
/* ---------------------- SDMMC registers bit mask --------------------------- */ | |||
/* --- CLKCR Register ---*/ | |||
/* CLKCR register clear mask */ | |||
#define CLKCR_CLEAR_MASK ((uint32_t)(SDMMC_CLKCR_CLKDIV | SDMMC_CLKCR_PWRSAV |\ | |||
SDMMC_CLKCR_BYPASS | SDMMC_CLKCR_WIDBUS |\ | |||
SDMMC_CLKCR_NEGEDGE | SDMMC_CLKCR_HWFC_EN)) | |||
/* --- DCTRL Register ---*/ | |||
/* SDMMC DCTRL Clear Mask */ | |||
#define DCTRL_CLEAR_MASK ((uint32_t)(SDMMC_DCTRL_DTEN | SDMMC_DCTRL_DTDIR |\ | |||
SDMMC_DCTRL_DTMODE | SDMMC_DCTRL_DBLOCKSIZE)) | |||
/* --- CMD Register ---*/ | |||
/* CMD Register clear mask */ | |||
#define CMD_CLEAR_MASK ((uint32_t)(SDMMC_CMD_CMDINDEX | SDMMC_CMD_WAITRESP |\ | |||
SDMMC_CMD_WAITINT | SDMMC_CMD_WAITPEND |\ | |||
SDMMC_CMD_CPSMEN | SDMMC_CMD_SDIOSUSPEND)) | |||
/* SDMMC Initialization Frequency (400KHz max) */ | |||
#define SDMMC_INIT_CLK_DIV ((uint8_t)0x76) | |||
/* SDMMC Data Transfer Frequency (25MHz max) */ | |||
#define SDMMC_TRANSFER_CLK_DIV ((uint8_t)0x0) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SDMMC_LL_Interrupt_Clock Interrupt And Clock Configuration | |||
* @brief macros to handle interrupts and specific clock configurations | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Enable the SDMMC device. | |||
* @param __INSTANCE__: SDMMC Instance | |||
* @retval None | |||
*/ | |||
#define __SDMMC_ENABLE(__INSTANCE__) ((__INSTANCE__)->CLKCR |= SDMMC_CLKCR_CLKEN) | |||
/** | |||
* @brief Disable the SDMMC device. | |||
* @param __INSTANCE__: SDMMC Instance | |||
* @retval None | |||
*/ | |||
#define __SDMMC_DISABLE(__INSTANCE__) ((__INSTANCE__)->CLKCR &= ~SDMMC_CLKCR_CLKEN) | |||
/** | |||
* @brief Enable the SDMMC DMA transfer. | |||
* @param __INSTANCE__: SDMMC Instance | |||
* @retval None | |||
*/ | |||
#define __SDMMC_DMA_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_DMAEN) | |||
/** | |||
* @brief Disable the SDMMC DMA transfer. | |||
* @param __INSTANCE__: SDMMC Instance | |||
* @retval None | |||
*/ | |||
#define __SDMMC_DMA_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_DMAEN) | |||
/** | |||
* @brief Enable the SDMMC device interrupt. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @param __INTERRUPT__ : specifies the SDMMC interrupt sources to be enabled. | |||
* This parameter can be one or a combination of the following values: | |||
* @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt | |||
* @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt | |||
* @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt | |||
* @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt | |||
* @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt | |||
* @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt | |||
* @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt | |||
* @arg SDMMC_IT_TXACT: Data transmit in progress interrupt | |||
* @arg SDMMC_IT_RXACT: Data receive in progress interrupt | |||
* @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt | |||
* @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt | |||
* @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt | |||
* @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt | |||
* @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt | |||
* @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt | |||
* @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt | |||
* @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt | |||
* @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt | |||
* @retval None | |||
*/ | |||
#define __SDMMC_ENABLE_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->MASK |= (__INTERRUPT__)) | |||
/** | |||
* @brief Disable the SDMMC device interrupt. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @param __INTERRUPT__ : specifies the SDMMC interrupt sources to be disabled. | |||
* This parameter can be one or a combination of the following values: | |||
* @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt | |||
* @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt | |||
* @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt | |||
* @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt | |||
* @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt | |||
* @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt | |||
* @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt | |||
* @arg SDMMC_IT_TXACT: Data transmit in progress interrupt | |||
* @arg SDMMC_IT_RXACT: Data receive in progress interrupt | |||
* @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt | |||
* @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt | |||
* @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt | |||
* @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt | |||
* @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt | |||
* @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt | |||
* @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt | |||
* @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt | |||
* @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt | |||
* @retval None | |||
*/ | |||
#define __SDMMC_DISABLE_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->MASK &= ~(__INTERRUPT__)) | |||
/** | |||
* @brief Checks whether the specified SDMMC flag is set or not. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @param __FLAG__: specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed) | |||
* @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed) | |||
* @arg SDMMC_FLAG_CTIMEOUT: Command response timeout | |||
* @arg SDMMC_FLAG_DTIMEOUT: Data timeout | |||
* @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error | |||
* @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error | |||
* @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed) | |||
* @arg SDMMC_FLAG_CMDSENT: Command sent (no response required) | |||
* @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero) | |||
* @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed) | |||
* @arg SDMMC_FLAG_CMDACT: Command transfer in progress | |||
* @arg SDMMC_FLAG_TXACT: Data transmit in progress | |||
* @arg SDMMC_FLAG_RXACT: Data receive in progress | |||
* @arg SDMMC_FLAG_TXFIFOHE: Transmit FIFO Half Empty | |||
* @arg SDMMC_FLAG_RXFIFOHF: Receive FIFO Half Full | |||
* @arg SDMMC_FLAG_TXFIFOF: Transmit FIFO full | |||
* @arg SDMMC_FLAG_RXFIFOF: Receive FIFO full | |||
* @arg SDMMC_FLAG_TXFIFOE: Transmit FIFO empty | |||
* @arg SDMMC_FLAG_RXFIFOE: Receive FIFO empty | |||
* @arg SDMMC_FLAG_TXDAVL: Data available in transmit FIFO | |||
* @arg SDMMC_FLAG_RXDAVL: Data available in receive FIFO | |||
* @arg SDMMC_FLAG_SDMMCIT: SD I/O interrupt received | |||
* @retval The new state of SDMMC_FLAG (SET or RESET). | |||
*/ | |||
#define __SDMMC_GET_FLAG(__INSTANCE__, __FLAG__) (((__INSTANCE__)->STA &(__FLAG__)) != RESET) | |||
/** | |||
* @brief Clears the SDMMC pending flags. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @param __FLAG__: specifies the flag to clear. | |||
* This parameter can be one or a combination of the following values: | |||
* @arg SDMMC_FLAG_CCRCFAIL: Command response received (CRC check failed) | |||
* @arg SDMMC_FLAG_DCRCFAIL: Data block sent/received (CRC check failed) | |||
* @arg SDMMC_FLAG_CTIMEOUT: Command response timeout | |||
* @arg SDMMC_FLAG_DTIMEOUT: Data timeout | |||
* @arg SDMMC_FLAG_TXUNDERR: Transmit FIFO underrun error | |||
* @arg SDMMC_FLAG_RXOVERR: Received FIFO overrun error | |||
* @arg SDMMC_FLAG_CMDREND: Command response received (CRC check passed) | |||
* @arg SDMMC_FLAG_CMDSENT: Command sent (no response required) | |||
* @arg SDMMC_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero) | |||
* @arg SDMMC_FLAG_DBCKEND: Data block sent/received (CRC check passed) | |||
* @arg SDMMC_FLAG_SDMMCIT: SD I/O interrupt received | |||
* @retval None | |||
*/ | |||
#define __SDMMC_CLEAR_FLAG(__INSTANCE__, __FLAG__) ((__INSTANCE__)->ICR = (__FLAG__)) | |||
/** | |||
* @brief Checks whether the specified SDMMC interrupt has occurred or not. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @param __INTERRUPT__: specifies the SDMMC interrupt source to check. | |||
* This parameter can be one of the following values: | |||
* @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt | |||
* @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt | |||
* @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt | |||
* @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt | |||
* @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt | |||
* @arg SDMMC_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt | |||
* @arg SDMMC_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDACT: Command transfer in progress interrupt | |||
* @arg SDMMC_IT_TXACT: Data transmit in progress interrupt | |||
* @arg SDMMC_IT_RXACT: Data receive in progress interrupt | |||
* @arg SDMMC_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt | |||
* @arg SDMMC_IT_RXFIFOHF: Receive FIFO Half Full interrupt | |||
* @arg SDMMC_IT_TXFIFOF: Transmit FIFO full interrupt | |||
* @arg SDMMC_IT_RXFIFOF: Receive FIFO full interrupt | |||
* @arg SDMMC_IT_TXFIFOE: Transmit FIFO empty interrupt | |||
* @arg SDMMC_IT_RXFIFOE: Receive FIFO empty interrupt | |||
* @arg SDMMC_IT_TXDAVL: Data available in transmit FIFO interrupt | |||
* @arg SDMMC_IT_RXDAVL: Data available in receive FIFO interrupt | |||
* @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt | |||
* @retval The new state of SDMMC_IT (SET or RESET). | |||
*/ | |||
#define __SDMMC_GET_IT (__INSTANCE__, __INTERRUPT__) (((__INSTANCE__)->STA &(__INTERRUPT__)) == (__INTERRUPT__)) | |||
/** | |||
* @brief Clears the SDMMC's interrupt pending bits. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @param __INTERRUPT__: specifies the interrupt pending bit to clear. | |||
* This parameter can be one or a combination of the following values: | |||
* @arg SDMMC_IT_CCRCFAIL: Command response received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt | |||
* @arg SDMMC_IT_CTIMEOUT: Command response timeout interrupt | |||
* @arg SDMMC_IT_DTIMEOUT: Data timeout interrupt | |||
* @arg SDMMC_IT_TXUNDERR: Transmit FIFO underrun error interrupt | |||
* @arg SDMMC_IT_RXOVERR: Received FIFO overrun error interrupt | |||
* @arg SDMMC_IT_CMDREND: Command response received (CRC check passed) interrupt | |||
* @arg SDMMC_IT_CMDSENT: Command sent (no response required) interrupt | |||
* @arg SDMMC_IT_DATAEND: Data end (data counter, SDMMC_DCOUNT, is zero) interrupt | |||
* @arg SDMMC_IT_SDIOIT: SD I/O interrupt received interrupt | |||
* @retval None | |||
*/ | |||
#define __SDMMC_CLEAR_IT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->ICR = (__INTERRUPT__)) | |||
/** | |||
* @brief Enable Start the SD I/O Read Wait operation. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @retval None | |||
*/ | |||
#define __SDMMC_START_READWAIT_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_RWSTART) | |||
/** | |||
* @brief Disable Start the SD I/O Read Wait operations. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @retval None | |||
*/ | |||
#define __SDMMC_START_READWAIT_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_RWSTART) | |||
/** | |||
* @brief Enable Start the SD I/O Read Wait operation. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @retval None | |||
*/ | |||
#define __SDMMC_STOP_READWAIT_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_RWSTOP) | |||
/** | |||
* @brief Disable Stop the SD I/O Read Wait operations. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @retval None | |||
*/ | |||
#define __SDMMC_STOP_READWAIT_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_RWSTOP) | |||
/** | |||
* @brief Enable the SD I/O Mode Operation. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @retval None | |||
*/ | |||
#define __SDMMC_OPERATION_ENABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL |= SDMMC_DCTRL_SDIOEN) | |||
/** | |||
* @brief Disable the SD I/O Mode Operation. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @retval None | |||
*/ | |||
#define __SDMMC_OPERATION_DISABLE(__INSTANCE__) ((__INSTANCE__)->DCTRL &= ~SDMMC_DCTRL_SDIOEN) | |||
/** | |||
* @brief Enable the SD I/O Suspend command sending. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @retval None | |||
*/ | |||
#define __SDMMC_SUSPEND_CMD_ENABLE(__INSTANCE__) ((__INSTANCE__)->CMD |= SDMMC_CMD_SDIOSUSPEND) | |||
/** | |||
* @brief Disable the SD I/O Suspend command sending. | |||
* @param __INSTANCE__ : Pointer to SDMMC register base | |||
* @retval None | |||
*/ | |||
#define __SDMMC_SUSPEND_CMD_DISABLE(__INSTANCE__) ((__INSTANCE__)->CMD &= ~SDMMC_CMD_SDIOSUSPEND) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup SDMMC_LL_Exported_Functions | |||
* @{ | |||
*/ | |||
/* Initialization/de-initialization functions **********************************/ | |||
/** @addtogroup HAL_SDMMC_LL_Group1 | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef SDMMC_Init(SDMMC_TypeDef *SDMMCx, SDMMC_InitTypeDef Init); | |||
/** | |||
* @} | |||
*/ | |||
/* I/O operation functions *****************************************************/ | |||
/** @addtogroup HAL_SDMMC_LL_Group2 | |||
* @{ | |||
*/ | |||
/* Blocking mode: Polling */ | |||
uint32_t SDMMC_ReadFIFO(SDMMC_TypeDef *SDMMCx); | |||
HAL_StatusTypeDef SDMMC_WriteFIFO(SDMMC_TypeDef *SDMMCx, uint32_t *pWriteData); | |||
/** | |||
* @} | |||
*/ | |||
/* Peripheral Control functions ************************************************/ | |||
/** @addtogroup HAL_SDMMC_LL_Group3 | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef SDMMC_PowerState_ON(SDMMC_TypeDef *SDMMCx); | |||
HAL_StatusTypeDef SDMMC_PowerState_OFF(SDMMC_TypeDef *SDMMCx); | |||
uint32_t SDMMC_GetPowerState(SDMMC_TypeDef *SDMMCx); | |||
/* Command path state machine (CPSM) management functions */ | |||
HAL_StatusTypeDef SDMMC_SendCommand(SDMMC_TypeDef *SDMMCx, SDMMC_CmdInitTypeDef *Command); | |||
uint8_t SDMMC_GetCommandResponse(SDMMC_TypeDef *SDMMCx); | |||
uint32_t SDMMC_GetResponse(SDMMC_TypeDef *SDMMCx, uint32_t Response); | |||
/* Data path state machine (DPSM) management functions */ | |||
HAL_StatusTypeDef SDMMC_DataConfig(SDMMC_TypeDef *SDMMCx, SDMMC_DataInitTypeDef* Data); | |||
uint32_t SDMMC_GetDataCounter(SDMMC_TypeDef *SDMMCx); | |||
uint32_t SDMMC_GetFIFOCount(SDMMC_TypeDef *SDMMCx); | |||
/* SDMMC Cards mode management functions */ | |||
HAL_StatusTypeDef SDMMC_SetSDMMCReadWaitMode(SDMMC_TypeDef *SDMMCx, uint32_t SDMMC_ReadWaitMode); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_LL_SDMMC_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,463 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_ll_usb.h | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Header file of USB Core HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32F7xx_LL_USB_H | |||
#define __STM32F7xx_LL_USB_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal_def.h" | |||
/** @addtogroup STM32F7xx_HAL | |||
* @{ | |||
*/ | |||
/** @addtogroup USB_Core | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** | |||
* @brief USB Mode definition | |||
*/ | |||
typedef enum | |||
{ | |||
USB_OTG_DEVICE_MODE = 0, | |||
USB_OTG_HOST_MODE = 1, | |||
USB_OTG_DRD_MODE = 2 | |||
}USB_OTG_ModeTypeDef; | |||
/** | |||
* @brief URB States definition | |||
*/ | |||
typedef enum { | |||
URB_IDLE = 0, | |||
URB_DONE, | |||
URB_NOTREADY, | |||
URB_NYET, | |||
URB_ERROR, | |||
URB_STALL | |||
}USB_OTG_URBStateTypeDef; | |||
/** | |||
* @brief Host channel States definition | |||
*/ | |||
typedef enum { | |||
HC_IDLE = 0, | |||
HC_XFRC, | |||
HC_HALTED, | |||
HC_NAK, | |||
HC_NYET, | |||
HC_STALL, | |||
HC_XACTERR, | |||
HC_BBLERR, | |||
HC_DATATGLERR | |||
}USB_OTG_HCStateTypeDef; | |||
/** | |||
* @brief PCD Initialization Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t dev_endpoints; /*!< Device Endpoints number. | |||
This parameter depends on the used USB core. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ | |||
uint32_t Host_channels; /*!< Host Channels number. | |||
This parameter Depends on the used USB core. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ | |||
uint32_t speed; /*!< USB Core speed. | |||
This parameter can be any value of @ref USB_Core_Speed_ */ | |||
uint32_t dma_enable; /*!< Enable or disable of the USB embedded DMA. */ | |||
uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. | |||
This parameter can be any value of @ref USB_EP0_MPS_ */ | |||
uint32_t phy_itface; /*!< Select the used PHY interface. | |||
This parameter can be any value of @ref USB_Core_PHY_ */ | |||
uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */ | |||
uint32_t low_power_enable; /*!< Enable or disable the low power mode. */ | |||
uint32_t lpm_enable; /*!< Enable or disable Link Power Management. */ | |||
uint32_t vbus_sensing_enable; /*!< Enable or disable the VBUS Sensing feature. */ | |||
uint32_t use_dedicated_ep1; /*!< Enable or disable the use of the dedicated EP1 interrupt. */ | |||
uint32_t use_external_vbus; /*!< Enable or disable the use of the external VBUS. */ | |||
}USB_OTG_CfgTypeDef; | |||
typedef struct | |||
{ | |||
uint8_t num; /*!< Endpoint number | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ | |||
uint8_t is_in; /*!< Endpoint direction | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint8_t is_stall; /*!< Endpoint stall condition | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint8_t type; /*!< Endpoint type | |||
This parameter can be any value of @ref USB_EP_Type_ */ | |||
uint8_t data_pid_start; /*!< Initial data PID | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint8_t even_odd_frame; /*!< IFrame parity | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint16_t tx_fifo_num; /*!< Transmission FIFO number | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ | |||
uint32_t maxpacket; /*!< Endpoint Max packet size | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */ | |||
uint8_t *xfer_buff; /*!< Pointer to transfer buffer */ | |||
uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address */ | |||
uint32_t xfer_len; /*!< Current transfer length */ | |||
uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */ | |||
}USB_OTG_EPTypeDef; | |||
typedef struct | |||
{ | |||
uint8_t dev_addr ; /*!< USB device address. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 255 */ | |||
uint8_t ch_num; /*!< Host channel number. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ | |||
uint8_t ep_num; /*!< Endpoint number. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ | |||
uint8_t ep_is_in; /*!< Endpoint direction | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint8_t speed; /*!< USB Host speed. | |||
This parameter can be any value of @ref USB_Core_Speed_ */ | |||
uint8_t do_ping; /*!< Enable or disable the use of the PING protocol for HS mode. */ | |||
uint8_t process_ping; /*!< Execute the PING protocol for HS mode. */ | |||
uint8_t ep_type; /*!< Endpoint Type. | |||
This parameter can be any value of @ref USB_EP_Type_ */ | |||
uint16_t max_packet; /*!< Endpoint Max packet size. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */ | |||
uint8_t data_pid; /*!< Initial data PID. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint8_t *xfer_buff; /*!< Pointer to transfer buffer. */ | |||
uint32_t xfer_len; /*!< Current transfer length. */ | |||
uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer. */ | |||
uint8_t toggle_in; /*!< IN transfer current toggle flag. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint8_t toggle_out; /*!< OUT transfer current toggle flag | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address. */ | |||
uint32_t ErrCnt; /*!< Host channel error count.*/ | |||
USB_OTG_URBStateTypeDef urb_state; /*!< URB state. | |||
This parameter can be any value of @ref USB_OTG_URBStateTypeDef */ | |||
USB_OTG_HCStateTypeDef state; /*!< Host Channel state. | |||
This parameter can be any value of @ref USB_OTG_HCStateTypeDef */ | |||
}USB_OTG_HCTypeDef; | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup PCD_Exported_Constants PCD Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup USB_Core_Mode_ USB Core Mode | |||
* @{ | |||
*/ | |||
#define USB_OTG_MODE_DEVICE 0 | |||
#define USB_OTG_MODE_HOST 1 | |||
#define USB_OTG_MODE_DRD 2 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_Core_Speed_ USB Core Speed | |||
* @{ | |||
*/ | |||
#define USB_OTG_SPEED_HIGH 0 | |||
#define USB_OTG_SPEED_HIGH_IN_FULL 1 | |||
#define USB_OTG_SPEED_LOW 2 | |||
#define USB_OTG_SPEED_FULL 3 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_Core_PHY_ USB Core PHY | |||
* @{ | |||
*/ | |||
#define USB_OTG_ULPI_PHY 1 | |||
#define USB_OTG_EMBEDDED_PHY 2 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_Core_MPS_ USB Core MPS | |||
* @{ | |||
*/ | |||
#define USB_OTG_HS_MAX_PACKET_SIZE 512 | |||
#define USB_OTG_FS_MAX_PACKET_SIZE 64 | |||
#define USB_OTG_MAX_EP0_SIZE 64 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_Core_Phy_Frequency_ USB Core Phy Frequency | |||
* @{ | |||
*/ | |||
#define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ (0 << 1) | |||
#define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ (1 << 1) | |||
#define DSTS_ENUMSPD_LS_PHY_6MHZ (2 << 1) | |||
#define DSTS_ENUMSPD_FS_PHY_48MHZ (3 << 1) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_CORE_Frame_Interval_ USB CORE Frame Interval | |||
* @{ | |||
*/ | |||
#define DCFG_FRAME_INTERVAL_80 0 | |||
#define DCFG_FRAME_INTERVAL_85 1 | |||
#define DCFG_FRAME_INTERVAL_90 2 | |||
#define DCFG_FRAME_INTERVAL_95 3 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_EP0_MPS_ USB EP0 MPS | |||
* @{ | |||
*/ | |||
#define DEP0CTL_MPS_64 0 | |||
#define DEP0CTL_MPS_32 1 | |||
#define DEP0CTL_MPS_16 2 | |||
#define DEP0CTL_MPS_8 3 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_EP_Speed_ USB EP Speed | |||
* @{ | |||
*/ | |||
#define EP_SPEED_LOW 0 | |||
#define EP_SPEED_FULL 1 | |||
#define EP_SPEED_HIGH 2 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_EP_Type_ USB EP Type | |||
* @{ | |||
*/ | |||
#define EP_TYPE_CTRL 0 | |||
#define EP_TYPE_ISOC 1 | |||
#define EP_TYPE_BULK 2 | |||
#define EP_TYPE_INTR 3 | |||
#define EP_TYPE_MSK 3 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_STS_Defines_ USB STS Defines | |||
* @{ | |||
*/ | |||
#define STS_GOUT_NAK 1 | |||
#define STS_DATA_UPDT 2 | |||
#define STS_XFER_COMP 3 | |||
#define STS_SETUP_COMP 4 | |||
#define STS_SETUP_UPDT 6 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup HCFG_SPEED_Defines_ HCFG SPEED Defines | |||
* @{ | |||
*/ | |||
#define HCFG_30_60_MHZ 0 | |||
#define HCFG_48_MHZ 1 | |||
#define HCFG_6_MHZ 2 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup HPRT0_PRTSPD_SPEED_Defines_ HPRT0 PRTSPD SPEED Defines | |||
* @{ | |||
*/ | |||
#define HPRT0_PRTSPD_HIGH_SPEED 0 | |||
#define HPRT0_PRTSPD_FULL_SPEED 1 | |||
#define HPRT0_PRTSPD_LOW_SPEED 2 | |||
/** | |||
* @} | |||
*/ | |||
#define HCCHAR_CTRL 0 | |||
#define HCCHAR_ISOC 1 | |||
#define HCCHAR_BULK 2 | |||
#define HCCHAR_INTR 3 | |||
#define HC_PID_DATA0 0 | |||
#define HC_PID_DATA2 1 | |||
#define HC_PID_DATA1 2 | |||
#define HC_PID_SETUP 3 | |||
#define GRXSTS_PKTSTS_IN 2 | |||
#define GRXSTS_PKTSTS_IN_XFER_COMP 3 | |||
#define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5 | |||
#define GRXSTS_PKTSTS_CH_HALTED 7 | |||
#define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_PCGCCTL_BASE) | |||
#define USBx_HPRT0 *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_HOST_PORT_BASE) | |||
#define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)((uint32_t )USBx + USB_OTG_DEVICE_BASE)) | |||
#define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)((uint32_t)USBx + USB_OTG_IN_ENDPOINT_BASE + (i)*USB_OTG_EP_REG_SIZE)) | |||
#define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)((uint32_t)USBx + USB_OTG_OUT_ENDPOINT_BASE + (i)*USB_OTG_EP_REG_SIZE)) | |||
#define USBx_DFIFO(i) *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_FIFO_BASE + (i) * USB_OTG_FIFO_SIZE) | |||
#define USBx_HOST ((USB_OTG_HostTypeDef *)((uint32_t )USBx + USB_OTG_HOST_BASE)) | |||
#define USBx_HC(i) ((USB_OTG_HostChannelTypeDef *)((uint32_t)USBx + USB_OTG_HOST_CHANNEL_BASE + (i)*USB_OTG_HOST_CHANNEL_SIZE)) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
#define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK &= ~(__INTERRUPT__)) | |||
#define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK |= (__INTERRUPT__)) | |||
#define CLEAR_IN_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_INEP(__EPNUM__)->DIEPINT = (__INTERRUPT__)) | |||
#define CLEAR_OUT_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_OUTEP(__EPNUM__)->DOEPINT = (__INTERRUPT__)) | |||
/* Exported functions --------------------------------------------------------*/ | |||
HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef Init); | |||
HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef Init); | |||
HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx); | |||
HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx); | |||
HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx , USB_OTG_ModeTypeDef mode); | |||
HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx , uint8_t speed); | |||
HAL_StatusTypeDef USB_FlushRxFifo (USB_OTG_GlobalTypeDef *USBx); | |||
HAL_StatusTypeDef USB_FlushTxFifo (USB_OTG_GlobalTypeDef *USBx, uint32_t num ); | |||
HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep, uint8_t dma); | |||
HAL_StatusTypeDef USB_EP0StartXfer(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep, uint8_t dma); | |||
HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len, uint8_t dma); | |||
void * USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len); | |||
HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_EPClearStall(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_SetDevAddress (USB_OTG_GlobalTypeDef *USBx, uint8_t address); | |||
HAL_StatusTypeDef USB_DevConnect (USB_OTG_GlobalTypeDef *USBx); | |||
HAL_StatusTypeDef USB_DevDisconnect (USB_OTG_GlobalTypeDef *USBx); | |||
HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx); | |||
HAL_StatusTypeDef USB_ActivateSetup (USB_OTG_GlobalTypeDef *USBx); | |||
HAL_StatusTypeDef USB_EP0_OutStart(USB_OTG_GlobalTypeDef *USBx, uint8_t dma, uint8_t *psetup); | |||
uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx); | |||
uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx); | |||
uint32_t USB_ReadInterrupts (USB_OTG_GlobalTypeDef *USBx); | |||
uint32_t USB_ReadDevAllOutEpInterrupt (USB_OTG_GlobalTypeDef *USBx); | |||
uint32_t USB_ReadDevOutEPInterrupt (USB_OTG_GlobalTypeDef *USBx , uint8_t epnum); | |||
uint32_t USB_ReadDevAllInEpInterrupt (USB_OTG_GlobalTypeDef *USBx); | |||
uint32_t USB_ReadDevInEPInterrupt (USB_OTG_GlobalTypeDef *USBx , uint8_t epnum); | |||
void USB_ClearInterrupts (USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt); | |||
HAL_StatusTypeDef USB_HostInit (USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg); | |||
HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx , uint8_t freq); | |||
HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx); | |||
HAL_StatusTypeDef USB_DriveVbus (USB_OTG_GlobalTypeDef *USBx, uint8_t state); | |||
uint32_t USB_GetHostSpeed (USB_OTG_GlobalTypeDef *USBx); | |||
uint32_t USB_GetCurrentFrame (USB_OTG_GlobalTypeDef *USBx); | |||
HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, | |||
uint8_t ch_num, | |||
uint8_t epnum, | |||
uint8_t dev_address, | |||
uint8_t speed, | |||
uint8_t ep_type, | |||
uint16_t mps); | |||
HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDef *hc, uint8_t dma); | |||
uint32_t USB_HC_ReadInterrupt (USB_OTG_GlobalTypeDef *USBx); | |||
HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx , uint8_t hc_num); | |||
HAL_StatusTypeDef USB_DoPing(USB_OTG_GlobalTypeDef *USBx , uint8_t ch_num); | |||
HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32F7xx_LL_USB_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,504 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief HAL module driver. | |||
* This is the common part of the HAL initialization | |||
* | |||
@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: | |||
(+) Common HAL APIs | |||
(+) Services HAL APIs | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup HAL HAL | |||
* @brief HAL module driver. | |||
* @{ | |||
*/ | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/** @addtogroup HAL_Private_Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @brief STM32F7xx HAL Driver version number V1.0.1 | |||
*/ | |||
#define __STM32F7xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */ | |||
#define __STM32F7xx_HAL_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */ | |||
#define __STM32F7xx_HAL_VERSION_SUB2 (0x01) /*!< [15:8] sub2 version */ | |||
#define __STM32F7xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */ | |||
#define __STM32F7xx_HAL_VERSION ((__STM32F7xx_HAL_VERSION_MAIN << 24)\ | |||
|(__STM32F7xx_HAL_VERSION_SUB1 << 16)\ | |||
|(__STM32F7xx_HAL_VERSION_SUB2 << 8 )\ | |||
|(__STM32F7xx_HAL_VERSION_RC)) | |||
#define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/** @addtogroup HAL_Private_Variables | |||
* @{ | |||
*/ | |||
static __IO uint32_t uwTick; | |||
/** | |||
* @} | |||
*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Private 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 is used to initialize the HAL Library; it must be the first | |||
* instruction to be executed in the main program (before to call any other | |||
* HAL function), it performs the following: | |||
* Configure the Flash prefetch, and instruction cache through ART accelerator. | |||
* Configures the SysTick to generate an interrupt each 1 millisecond, | |||
* which is clocked by the HSI (at this stage, the clock is not yet | |||
* configured and thus the system is running from the internal HSI at 16 MHz). | |||
* Set NVIC Group Priority to 4. | |||
* Calls the HAL_MspInit() callback function defined in user file | |||
* "stm32f7xx_hal_msp.c" to do the global low level hardware initialization | |||
* | |||
* @note SysTick is used as time base for the HAL_Delay() function, the application | |||
* need to ensure that the SysTick time base is always set to 1 millisecond | |||
* to have correct HAL operation. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_Init(void) | |||
{ | |||
/* Configure Flash prefetch and Instruction cache through ART accelerator */ | |||
#if (ART_ACCLERATOR_ENABLE != 0) | |||
__HAL_FLASH_ART_ENABLE(); | |||
#endif /* ART_ACCLERATOR_ENABLE */ | |||
/* Set Interrupt Group Priority */ | |||
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); | |||
/* Use systick as time base source 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. | |||
* 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_AHB1_FORCE_RESET(); | |||
__HAL_RCC_AHB1_RELEASE_RESET(); | |||
__HAL_RCC_AHB2_FORCE_RESET(); | |||
__HAL_RCC_AHB2_RELEASE_RESET(); | |||
__HAL_RCC_AHB3_FORCE_RESET(); | |||
__HAL_RCC_AHB3_RELEASE_RESET(); | |||
/* De-Init the low level hardware */ | |||
HAL_MspDeInit(); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Initializes 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 DeInitializes 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 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*/ | |||
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); | |||
/*Configure the SysTick IRQ priority */ | |||
HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0); | |||
/* 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++; | |||
} | |||
/** | |||
* @brief Provides a tick value in millisecond. | |||
* @note This 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 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. | |||
* @note ThiS 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(__IO uint32_t Delay) | |||
{ | |||
uint32_t tickstart = 0; | |||
tickstart = HAL_GetTick(); | |||
while((HAL_GetTick() - tickstart) < Delay) | |||
{ | |||
} | |||
} | |||
/** | |||
* @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. | |||
* @note This 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 Returns the HAL revision | |||
* @retval version : 0xXYZR (8bits for each decimal, R for RC) | |||
*/ | |||
uint32_t HAL_GetHalVersion(void) | |||
{ | |||
return __STM32F7xx_HAL_VERSION; | |||
} | |||
/** | |||
* @brief Returns the device revision identifier. | |||
* @retval Device revision identifier | |||
*/ | |||
uint32_t HAL_GetREVID(void) | |||
{ | |||
return((DBGMCU->IDCODE) >> 16); | |||
} | |||
/** | |||
* @brief Returns the device identifier. | |||
* @retval Device identifier | |||
*/ | |||
uint32_t HAL_GetDEVID(void) | |||
{ | |||
return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK); | |||
} | |||
/** | |||
* @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); | |||
} | |||
/** | |||
* @brief Enables the I/O Compensation Cell. | |||
* @note The I/O compensation cell can be used only when the device supply | |||
* voltage ranges from 2.4 to 3.6 V. | |||
* @retval None | |||
*/ | |||
void HAL_EnableCompensationCell(void) | |||
{ | |||
SYSCFG->CMPCR |= SYSCFG_CMPCR_CMP_PD; | |||
} | |||
/** | |||
* @brief Power-down the I/O Compensation Cell. | |||
* @note The I/O compensation cell can be used only when the device supply | |||
* voltage ranges from 2.4 to 3.6 V. | |||
* @retval None | |||
*/ | |||
void HAL_DisableCompensationCell(void) | |||
{ | |||
SYSCFG->CMPCR &= (uint32_t)~((uint32_t)SYSCFG_CMPCR_CMP_PD); | |||
} | |||
/** | |||
* @brief Enables the FMC Memory Mapping Swapping. | |||
* | |||
* @note SDRAM is accessible at 0x60000000 | |||
* and NOR/RAM is accessible at 0xC0000000 | |||
* | |||
* @retval None | |||
*/ | |||
void HAL_EnableFMCMemorySwapping(void) | |||
{ | |||
SYSCFG->MEMRMP |= SYSCFG_MEMRMP_SWP_FMC_0; | |||
} | |||
/** | |||
* @brief Disables the FMC Memory Mapping Swapping | |||
* | |||
* @note SDRAM is accessible at 0xC0000000 (default mapping) | |||
* and NOR/RAM is accessible at 0x60000000 (default mapping) | |||
* | |||
* @retval None | |||
*/ | |||
void HAL_DisableFMCMemorySwapping(void) | |||
{ | |||
SYSCFG->MEMRMP &= (uint32_t)~((uint32_t)SYSCFG_MEMRMP_SWP_FMC); | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,854 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_adc_ex.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief This file provides firmware functions to manage the following | |||
* functionalities of the ADC extension peripheral: | |||
* + Extended features functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] | |||
(#)Initialize the ADC low level resources by implementing the HAL_ADC_MspInit(): | |||
(##) Enable the ADC interface clock using __HAL_RCC_ADC_CLK_ENABLE() | |||
(##) ADC pins configuration | |||
(+++) Enable the clock for the ADC GPIOs using the following function: | |||
__HAL_RCC_GPIOx_CLK_ENABLE() | |||
(+++) Configure these ADC pins in analog mode using HAL_GPIO_Init() | |||
(##) In case of using interrupts (e.g. HAL_ADC_Start_IT()) | |||
(+++) Configure the ADC interrupt priority using HAL_NVIC_SetPriority() | |||
(+++) Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ() | |||
(+++) In ADC IRQ handler, call HAL_ADC_IRQHandler() | |||
(##) In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA()) | |||
(+++) Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE() | |||
(+++) Configure and enable two DMA streams stream for managing data | |||
transfer from peripheral to memory (output stream) | |||
(+++) Associate the initialized DMA handle to the ADC DMA handle | |||
using __HAL_LINKDMA() | |||
(+++) Configure the priority and enable the NVIC for the transfer complete | |||
interrupt on the two DMA Streams. The output stream should have higher | |||
priority than the input stream. | |||
(#) Configure the ADC Prescaler, conversion resolution and data alignment | |||
using the HAL_ADC_Init() function. | |||
(#) Configure the ADC Injected channels group features, use HAL_ADC_Init() | |||
and HAL_ADC_ConfigChannel() functions. | |||
(#) Three operation modes are available within this driver : | |||
*** Polling mode IO operation *** | |||
================================= | |||
[..] | |||
(+) Start the ADC peripheral using HAL_ADCEx_InjectedStart() | |||
(+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage | |||
user can specify the value of timeout according to his end application | |||
(+) To read the ADC converted values, use the HAL_ADCEx_InjectedGetValue() function. | |||
(+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop() | |||
*** Interrupt mode IO operation *** | |||
=================================== | |||
[..] | |||
(+) Start the ADC peripheral using HAL_ADCEx_InjectedStart_IT() | |||
(+) Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine | |||
(+) At ADC end of conversion HAL_ADCEx_InjectedConvCpltCallback() function is executed and user can | |||
add his own code by customization of function pointer HAL_ADCEx_InjectedConvCpltCallback | |||
(+) In case of ADC Error, HAL_ADCEx_InjectedErrorCallback() function is executed and user can | |||
add his own code by customization of function pointer HAL_ADCEx_InjectedErrorCallback | |||
(+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop_IT() | |||
*** DMA mode IO operation *** | |||
============================== | |||
[..] | |||
(+) Start the ADC peripheral using HAL_ADCEx_InjectedStart_DMA(), at this stage the user specify the length | |||
of data to be transferred at each end of conversion | |||
(+) At The end of data transfer ba HAL_ADCEx_InjectedConvCpltCallback() function is executed and user can | |||
add his own code by customization of function pointer HAL_ADCEx_InjectedConvCpltCallback | |||
(+) In case of transfer Error, HAL_ADCEx_InjectedErrorCallback() function is executed and user can | |||
add his own code by customization of function pointer HAL_ADCEx_InjectedErrorCallback | |||
(+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop_DMA() | |||
*** Multi mode ADCs Regular channels configuration *** | |||
====================================================== | |||
[..] | |||
(+) Select the Multi mode ADC regular channels features (dual or triple mode) | |||
and configure the DMA mode using HAL_ADCEx_MultiModeConfigChannel() functions. | |||
(+) Start the ADC peripheral using HAL_ADCEx_MultiModeStart_DMA(), at this stage the user specify the length | |||
of data to be transferred at each end of conversion | |||
(+) Read the ADCs converted values using the HAL_ADCEx_MultiModeGetValue() function. | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup ADCEx ADCEx | |||
* @brief ADC Extended driver modules | |||
* @{ | |||
*/ | |||
#ifdef HAL_ADC_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/** @addtogroup ADCEx_Private_Functions | |||
* @{ | |||
*/ | |||
static void ADC_MultiModeDMAConvCplt(DMA_HandleTypeDef *hdma); | |||
static void ADC_MultiModeDMAError(DMA_HandleTypeDef *hdma); | |||
static void ADC_MultiModeDMAHalfConvCplt(DMA_HandleTypeDef *hdma); | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions ---------------------------------------------------------*/ | |||
/** @defgroup ADCEx_Exported_Functions ADC Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup ADCEx_Exported_Functions_Group1 Extended features functions | |||
* @brief Extended features functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Extended features functions ##### | |||
=============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Start conversion of injected channel. | |||
(+) Stop conversion of injected channel. | |||
(+) Start multimode and enable DMA transfer. | |||
(+) Stop multimode and disable DMA transfer. | |||
(+) Get result of injected channel conversion. | |||
(+) Get result of multimode conversion. | |||
(+) Configure injected channels. | |||
(+) Configure multimode. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Enables the selected ADC software start conversion of the injected channels. | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc) | |||
{ | |||
__IO uint32_t counter = 0; | |||
uint32_t tmp1 = 0, tmp2 = 0; | |||
/* Process locked */ | |||
__HAL_LOCK(hadc); | |||
/* Check if a regular conversion is ongoing */ | |||
if(hadc->State == HAL_ADC_STATE_BUSY_REG) | |||
{ | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_BUSY_INJ_REG; | |||
} | |||
else | |||
{ | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_BUSY_INJ; | |||
} | |||
/* Check if ADC peripheral is disabled in order to enable it and wait during | |||
Tstab time the ADC's stabilization */ | |||
if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON) | |||
{ | |||
/* Enable the Peripheral */ | |||
__HAL_ADC_ENABLE(hadc); | |||
/* Delay for temperature sensor stabilization time */ | |||
/* Compute number of CPU cycles to wait for */ | |||
counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000)); | |||
while(counter != 0) | |||
{ | |||
counter--; | |||
} | |||
} | |||
/* Check if Multimode enabled */ | |||
if(HAL_IS_BIT_CLR(ADC->CCR, ADC_CCR_MULTI)) | |||
{ | |||
tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN); | |||
tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO); | |||
if(tmp1 && tmp2) | |||
{ | |||
/* Enable the selected ADC software conversion for injected group */ | |||
hadc->Instance->CR2 |= ADC_CR2_JSWSTART; | |||
} | |||
} | |||
else | |||
{ | |||
tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN); | |||
tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO); | |||
if((hadc->Instance == ADC1) && tmp1 && tmp2) | |||
{ | |||
/* Enable the selected ADC software conversion for injected group */ | |||
hadc->Instance->CR2 |= ADC_CR2_JSWSTART; | |||
} | |||
} | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hadc); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Enables the interrupt and starts ADC conversion of injected channels. | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* | |||
* @retval HAL status. | |||
*/ | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc) | |||
{ | |||
__IO uint32_t counter = 0; | |||
uint32_t tmp1 = 0, tmp2 =0; | |||
/* Process locked */ | |||
__HAL_LOCK(hadc); | |||
/* Check if a regular conversion is ongoing */ | |||
if(hadc->State == HAL_ADC_STATE_BUSY_REG) | |||
{ | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_BUSY_INJ_REG; | |||
} | |||
else | |||
{ | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_BUSY_INJ; | |||
} | |||
/* Set ADC error code to none */ | |||
hadc->ErrorCode = HAL_ADC_ERROR_NONE; | |||
/* Check if ADC peripheral is disabled in order to enable it and wait during | |||
Tstab time the ADC's stabilization */ | |||
if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON) | |||
{ | |||
/* Enable the Peripheral */ | |||
__HAL_ADC_ENABLE(hadc); | |||
/* Delay for temperature sensor stabilization time */ | |||
/* Compute number of CPU cycles to wait for */ | |||
counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000)); | |||
while(counter != 0) | |||
{ | |||
counter--; | |||
} | |||
} | |||
/* Enable the ADC end of conversion interrupt for injected group */ | |||
__HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC); | |||
/* Enable the ADC overrun interrupt */ | |||
__HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR); | |||
/* Check if Multimode enabled */ | |||
if(HAL_IS_BIT_CLR(ADC->CCR, ADC_CCR_MULTI)) | |||
{ | |||
tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN); | |||
tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO); | |||
if(tmp1 && tmp2) | |||
{ | |||
/* Enable the selected ADC software conversion for injected group */ | |||
hadc->Instance->CR2 |= ADC_CR2_JSWSTART; | |||
} | |||
} | |||
else | |||
{ | |||
tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN); | |||
tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO); | |||
if((hadc->Instance == ADC1) && tmp1 && tmp2) | |||
{ | |||
/* Enable the selected ADC software conversion for injected group */ | |||
hadc->Instance->CR2 |= ADC_CR2_JSWSTART; | |||
} | |||
} | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hadc); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Disables ADC and stop conversion of injected channels. | |||
* | |||
* @note Caution: This function will stop also regular channels. | |||
* | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @retval HAL status. | |||
*/ | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc) | |||
{ | |||
/* Disable the Peripheral */ | |||
__HAL_ADC_DISABLE(hadc); | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_READY; | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Poll for injected conversion complete | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @param Timeout: Timeout value in millisecond. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout) | |||
{ | |||
uint32_t tickstart = 0; | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
/* Check End of conversion flag */ | |||
while(!(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOC))) | |||
{ | |||
/* Check for the Timeout */ | |||
if(Timeout != HAL_MAX_DELAY) | |||
{ | |||
if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) | |||
{ | |||
hadc->State= HAL_ADC_STATE_TIMEOUT; | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hadc); | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
} | |||
/* Check if a regular conversion is ready */ | |||
if(hadc->State == HAL_ADC_STATE_EOC_REG) | |||
{ | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_EOC_INJ_REG; | |||
} | |||
else | |||
{ | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_EOC_INJ; | |||
} | |||
/* Return ADC state */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Disables the interrupt and stop ADC conversion of injected channels. | |||
* | |||
* @note Caution: This function will stop also regular channels. | |||
* | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @retval HAL status. | |||
*/ | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc) | |||
{ | |||
/* Disable the ADC end of conversion interrupt for regular group */ | |||
__HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC); | |||
/* Disable the ADC end of conversion interrupt for injected group */ | |||
__HAL_ADC_DISABLE_IT(hadc, ADC_CR1_JEOCIE); | |||
/* Enable the Peripheral */ | |||
__HAL_ADC_DISABLE(hadc); | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_READY; | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Gets the converted value from data register of injected channel. | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @param InjectedRank: the ADC injected rank. | |||
* This parameter can be one of the following values: | |||
* @arg ADC_INJECTED_RANK_1: Injected Channel1 selected | |||
* @arg ADC_INJECTED_RANK_2: Injected Channel2 selected | |||
* @arg ADC_INJECTED_RANK_3: Injected Channel3 selected | |||
* @arg ADC_INJECTED_RANK_4: Injected Channel4 selected | |||
* @retval None | |||
*/ | |||
uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank) | |||
{ | |||
__IO uint32_t tmp = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_ADC_INJECTED_RANK(InjectedRank)); | |||
/* Clear the ADCx's flag for injected end of conversion */ | |||
__HAL_ADC_CLEAR_FLAG(hadc,ADC_FLAG_JEOC); | |||
/* Return the selected ADC converted value */ | |||
switch(InjectedRank) | |||
{ | |||
case ADC_INJECTED_RANK_4: | |||
{ | |||
tmp = hadc->Instance->JDR4; | |||
} | |||
break; | |||
case ADC_INJECTED_RANK_3: | |||
{ | |||
tmp = hadc->Instance->JDR3; | |||
} | |||
break; | |||
case ADC_INJECTED_RANK_2: | |||
{ | |||
tmp = hadc->Instance->JDR2; | |||
} | |||
break; | |||
case ADC_INJECTED_RANK_1: | |||
{ | |||
tmp = hadc->Instance->JDR1; | |||
} | |||
break; | |||
default: | |||
break; | |||
} | |||
return tmp; | |||
} | |||
/** | |||
* @brief Enables ADC DMA request after last transfer (Multi-ADC mode) and enables ADC peripheral | |||
* | |||
* @note Caution: This function must be used only with the ADC master. | |||
* | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @param pData: Pointer to buffer in which transferred from ADC peripheral to memory will be stored. | |||
* @param Length: The length of data to be transferred from ADC peripheral to memory. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length) | |||
{ | |||
__IO uint32_t counter = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode)); | |||
assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge)); | |||
assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DMAContinuousRequests)); | |||
/* Process locked */ | |||
__HAL_LOCK(hadc); | |||
/* Enable ADC overrun interrupt */ | |||
__HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR); | |||
if (hadc->Init.DMAContinuousRequests != DISABLE) | |||
{ | |||
/* Enable the selected ADC DMA request after last transfer */ | |||
ADC->CCR |= ADC_CCR_DDS; | |||
} | |||
else | |||
{ | |||
/* Disable the selected ADC EOC rising on each regular channel conversion */ | |||
ADC->CCR &= ~ADC_CCR_DDS; | |||
} | |||
/* Set the DMA transfer complete callback */ | |||
hadc->DMA_Handle->XferCpltCallback = ADC_MultiModeDMAConvCplt; | |||
/* Set the DMA half transfer complete callback */ | |||
hadc->DMA_Handle->XferHalfCpltCallback = ADC_MultiModeDMAHalfConvCplt; | |||
/* Set the DMA error callback */ | |||
hadc->DMA_Handle->XferErrorCallback = ADC_MultiModeDMAError ; | |||
/* Enable the DMA Stream */ | |||
HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&ADC->CDR, (uint32_t)pData, Length); | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_BUSY_REG; | |||
/* Check if ADC peripheral is disabled in order to enable it and wait during | |||
Tstab time the ADC's stabilization */ | |||
if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON) | |||
{ | |||
/* Enable the Peripheral */ | |||
__HAL_ADC_ENABLE(hadc); | |||
/* Delay for temperature sensor stabilization time */ | |||
/* Compute number of CPU cycles to wait for */ | |||
counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000)); | |||
while(counter != 0) | |||
{ | |||
counter--; | |||
} | |||
} | |||
/* if no external trigger present enable software conversion of regular channels */ | |||
if((hadc->Instance->CR2 & ADC_CR2_EXTEN) == RESET) | |||
{ | |||
/* Enable the selected ADC software conversion for regular group */ | |||
hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART; | |||
} | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hadc); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Disables ADC DMA (multi-ADC mode) and disables ADC peripheral | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc) | |||
{ | |||
/* Process locked */ | |||
__HAL_LOCK(hadc); | |||
/* Enable the Peripheral */ | |||
__HAL_ADC_DISABLE(hadc); | |||
/* Disable ADC overrun interrupt */ | |||
__HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR); | |||
/* Disable the selected ADC DMA request after last transfer */ | |||
ADC->CCR &= ~ADC_CCR_DDS; | |||
/* Disable the ADC DMA Stream */ | |||
HAL_DMA_Abort(hadc->DMA_Handle); | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_READY; | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hadc); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Returns the last ADC1, ADC2 and ADC3 regular conversions results | |||
* data in the selected multi mode. | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @retval The converted data value. | |||
*/ | |||
uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc) | |||
{ | |||
/* Return the multi mode conversion value */ | |||
return ADC->CDR; | |||
} | |||
/** | |||
* @brief Injected conversion complete callback in non blocking mode | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_ADC_InjectedConvCpltCallback could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief Configures for the selected ADC injected channel its corresponding | |||
* rank in the sequencer and its sample time. | |||
* @param hadc: pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @param sConfigInjected: ADC configuration structure for injected channel. | |||
* @retval None | |||
*/ | |||
HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_InjectionConfTypeDef* sConfigInjected) | |||
{ | |||
#ifdef USE_FULL_ASSERT | |||
uint32_t tmp = 0; | |||
#endif /* USE_FULL_ASSERT */ | |||
/* Check the parameters */ | |||
assert_param(IS_ADC_CHANNEL(sConfigInjected->InjectedChannel)); | |||
assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank)); | |||
assert_param(IS_ADC_SAMPLE_TIME(sConfigInjected->InjectedSamplingTime)); | |||
assert_param(IS_ADC_EXT_INJEC_TRIG(sConfigInjected->ExternalTrigInjecConv)); | |||
assert_param(IS_ADC_EXT_INJEC_TRIG_EDGE(sConfigInjected->ExternalTrigInjecConvEdge)); | |||
assert_param(IS_ADC_INJECTED_LENGTH(sConfigInjected->InjectedNbrOfConversion)); | |||
assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->AutoInjectedConv)); | |||
assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode)); | |||
#ifdef USE_FULL_ASSERT | |||
tmp = ADC_GET_RESOLUTION(hadc); | |||
assert_param(IS_ADC_RANGE(tmp, sConfigInjected->InjectedOffset)); | |||
#endif /* USE_FULL_ASSERT */ | |||
/* Process locked */ | |||
__HAL_LOCK(hadc); | |||
/* if ADC_Channel_10 ... ADC_Channel_18 is selected */ | |||
if (sConfigInjected->InjectedChannel > ADC_CHANNEL_9) | |||
{ | |||
/* Clear the old sample time */ | |||
hadc->Instance->SMPR1 &= ~ADC_SMPR1(ADC_SMPR1_SMP10, sConfigInjected->InjectedChannel); | |||
/* Set the new sample time */ | |||
hadc->Instance->SMPR1 |= ADC_SMPR1(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel); | |||
} | |||
else /* ADC_Channel include in ADC_Channel_[0..9] */ | |||
{ | |||
/* Clear the old sample time */ | |||
hadc->Instance->SMPR2 &= ~ADC_SMPR2(ADC_SMPR2_SMP0, sConfigInjected->InjectedChannel); | |||
/* Set the new sample time */ | |||
hadc->Instance->SMPR2 |= ADC_SMPR2(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel); | |||
} | |||
/*---------------------------- ADCx JSQR Configuration -----------------*/ | |||
hadc->Instance->JSQR &= ~(ADC_JSQR_JL); | |||
hadc->Instance->JSQR |= ADC_SQR1(sConfigInjected->InjectedNbrOfConversion); | |||
/* Rank configuration */ | |||
/* Clear the old SQx bits for the selected rank */ | |||
hadc->Instance->JSQR &= ~ADC_JSQR(ADC_JSQR_JSQ1, sConfigInjected->InjectedRank,sConfigInjected->InjectedNbrOfConversion); | |||
/* Set the SQx bits for the selected rank */ | |||
hadc->Instance->JSQR |= ADC_JSQR(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank,sConfigInjected->InjectedNbrOfConversion); | |||
/* Select external trigger to start conversion */ | |||
hadc->Instance->CR2 &= ~(ADC_CR2_JEXTSEL); | |||
hadc->Instance->CR2 |= sConfigInjected->ExternalTrigInjecConv; | |||
/* Select external trigger polarity */ | |||
hadc->Instance->CR2 &= ~(ADC_CR2_JEXTEN); | |||
hadc->Instance->CR2 |= sConfigInjected->ExternalTrigInjecConvEdge; | |||
if (sConfigInjected->AutoInjectedConv != DISABLE) | |||
{ | |||
/* Enable the selected ADC automatic injected group conversion */ | |||
hadc->Instance->CR1 |= ADC_CR1_JAUTO; | |||
} | |||
else | |||
{ | |||
/* Disable the selected ADC automatic injected group conversion */ | |||
hadc->Instance->CR1 &= ~(ADC_CR1_JAUTO); | |||
} | |||
if (sConfigInjected->InjectedDiscontinuousConvMode != DISABLE) | |||
{ | |||
/* Enable the selected ADC injected discontinuous mode */ | |||
hadc->Instance->CR1 |= ADC_CR1_JDISCEN; | |||
} | |||
else | |||
{ | |||
/* Disable the selected ADC injected discontinuous mode */ | |||
hadc->Instance->CR1 &= ~(ADC_CR1_JDISCEN); | |||
} | |||
switch(sConfigInjected->InjectedRank) | |||
{ | |||
case 1: | |||
/* Set injected channel 1 offset */ | |||
hadc->Instance->JOFR1 &= ~(ADC_JOFR1_JOFFSET1); | |||
hadc->Instance->JOFR1 |= sConfigInjected->InjectedOffset; | |||
break; | |||
case 2: | |||
/* Set injected channel 2 offset */ | |||
hadc->Instance->JOFR2 &= ~(ADC_JOFR2_JOFFSET2); | |||
hadc->Instance->JOFR2 |= sConfigInjected->InjectedOffset; | |||
break; | |||
case 3: | |||
/* Set injected channel 3 offset */ | |||
hadc->Instance->JOFR3 &= ~(ADC_JOFR3_JOFFSET3); | |||
hadc->Instance->JOFR3 |= sConfigInjected->InjectedOffset; | |||
break; | |||
default: | |||
/* Set injected channel 4 offset */ | |||
hadc->Instance->JOFR4 &= ~(ADC_JOFR4_JOFFSET4); | |||
hadc->Instance->JOFR4 |= sConfigInjected->InjectedOffset; | |||
break; | |||
} | |||
/* if ADC1 Channel_18 is selected enable VBAT Channel */ | |||
if ((hadc->Instance == ADC1) && (sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT)) | |||
{ | |||
/* Enable the VBAT channel*/ | |||
ADC->CCR |= ADC_CCR_VBATE; | |||
} | |||
/* if ADC1 Channel_16 or Channel_17 is selected enable TSVREFE Channel(Temperature sensor and VREFINT) */ | |||
if ((hadc->Instance == ADC1) && ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) || (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT))) | |||
{ | |||
/* Enable the TSVREFE channel*/ | |||
ADC->CCR |= ADC_CCR_TSVREFE; | |||
} | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hadc); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Configures the ADC multi-mode | |||
* @param hadc : pointer to a ADC_HandleTypeDef structure that contains | |||
* the configuration information for the specified ADC. | |||
* @param multimode : pointer to an ADC_MultiModeTypeDef structure that contains | |||
* the configuration information for multimode. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_ADC_MODE(multimode->Mode)); | |||
assert_param(IS_ADC_DMA_ACCESS_MODE(multimode->DMAAccessMode)); | |||
assert_param(IS_ADC_SAMPLING_DELAY(multimode->TwoSamplingDelay)); | |||
/* Process locked */ | |||
__HAL_LOCK(hadc); | |||
/* Set ADC mode */ | |||
ADC->CCR &= ~(ADC_CCR_MULTI); | |||
ADC->CCR |= multimode->Mode; | |||
/* Set the ADC DMA access mode */ | |||
ADC->CCR &= ~(ADC_CCR_DMA); | |||
ADC->CCR |= multimode->DMAAccessMode; | |||
/* Set delay between two sampling phases */ | |||
ADC->CCR &= ~(ADC_CCR_DELAY); | |||
ADC->CCR |= multimode->TwoSamplingDelay; | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hadc); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @brief DMA transfer complete callback. | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA module. | |||
* @retval None | |||
*/ | |||
static void ADC_MultiModeDMAConvCplt(DMA_HandleTypeDef *hdma) | |||
{ | |||
ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |||
/* Check if an injected conversion is ready */ | |||
if(hadc->State == HAL_ADC_STATE_EOC_INJ) | |||
{ | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_EOC_INJ_REG; | |||
} | |||
else | |||
{ | |||
/* Change ADC state */ | |||
hadc->State = HAL_ADC_STATE_EOC_REG; | |||
} | |||
HAL_ADC_ConvCpltCallback(hadc); | |||
} | |||
/** | |||
* @brief DMA half transfer complete callback. | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA module. | |||
* @retval None | |||
*/ | |||
static void ADC_MultiModeDMAHalfConvCplt(DMA_HandleTypeDef *hdma) | |||
{ | |||
ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |||
/* Conversion complete callback */ | |||
HAL_ADC_ConvHalfCpltCallback(hadc); | |||
} | |||
/** | |||
* @brief DMA error callback | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA module. | |||
* @retval None | |||
*/ | |||
static void ADC_MultiModeDMAError(DMA_HandleTypeDef *hdma) | |||
{ | |||
ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |||
hadc->State= HAL_ADC_STATE_ERROR; | |||
/* Set ADC error code to DMA error */ | |||
hadc->ErrorCode |= HAL_ADC_ERROR_DMA; | |||
HAL_ADC_ErrorCallback(hadc); | |||
} | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_ADC_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,483 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_cortex.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @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 according to the following table. | |||
(#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority(). | |||
(#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ(). | |||
(#) please refer to programming manual for details in how to configure priority. | |||
-@- When the NVIC_PRIORITYGROUP_0 is selected, IRQ preemption 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 preemption 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 (0x0F). | |||
(++) 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 stm32f7xx_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 | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup CORTEX CORTEX | |||
* @brief CORTEX HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_CORTEX_MODULE_ENABLED | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/* 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 (preemption 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 preemption priority | |||
* 4 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority | |||
* 3 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority | |||
* 2 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority | |||
* 1 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption priority | |||
* 0 bits for subpriority | |||
* @note When the NVIC_PriorityGroup_0 is selected, IRQ preemption 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 (stm32f7xxxx.h)) | |||
* @param PreemptPriority: The preemption priority for the IRQn channel. | |||
* This parameter can be a value between 0 and 15 | |||
* 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 | |||
* 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 = 0x00; | |||
/* 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 (stm32f7xxxx.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 (stm32f7xxxx.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 == 1) | |||
/** | |||
* @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 = 0x00; | |||
MPU->RASR = 0x00; | |||
} | |||
} | |||
#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 (stm32f7xxxx.h)) | |||
* @param PriorityGroup: the priority grouping bits length. | |||
* This parameter can be one of the following values: | |||
* @arg NVIC_PRIORITYGROUP_0: 0 bits for preemption priority | |||
* 4 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority | |||
* 3 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority | |||
* 2 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority | |||
* 1 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption 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 (stm32f7xxxx.h)) | |||
* @retval None | |||
*/ | |||
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_NVIC_DEVICE_IRQ(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 (stm32f7xxxx.h)) | |||
* @retval status: - 0 Interrupt status is not pending. | |||
* - 1 Interrupt status is pending. | |||
*/ | |||
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn)); | |||
/* Return 1 if pending else 0 */ | |||
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 (stm32f7xxxx.h)) | |||
* @retval None | |||
*/ | |||
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_NVIC_DEVICE_IRQ(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 (stm32f7xxxx.h)) | |||
* @retval status: - 0 Interrupt status is not pending. | |||
* - 1 Interrupt status is pending. | |||
*/ | |||
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn)); | |||
/* Return 1 if active else 0 */ | |||
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 */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,949 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_dac.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief DAC HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities of the Digital to Analog Converter (DAC) peripheral: | |||
* + Initialization and de-initialization functions | |||
* + IO operation functions | |||
* + Peripheral Control functions | |||
* + Peripheral State and Errors functions | |||
* | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### DAC Peripheral features ##### | |||
============================================================================== | |||
[..] | |||
*** DAC Channels *** | |||
==================== | |||
[..] | |||
The device integrates two 12-bit Digital Analog Converters that can | |||
be used independently or simultaneously (dual mode): | |||
(#) DAC channel1 with DAC_OUT1 (PA4) as output | |||
(#) DAC channel2 with DAC_OUT2 (PA5) as output | |||
*** DAC Triggers *** | |||
==================== | |||
[..] | |||
Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE | |||
and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register. | |||
[..] | |||
Digital to Analog conversion can be triggered by: | |||
(#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_TRIGGER_EXT_IT9. | |||
The used pin (GPIOx_Pin9) must be configured in input mode. | |||
(#) Timers TRGO: TIM2, TIM4, TIM5, TIM6, TIM7 and TIM8 | |||
(DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T4_TRGO...) | |||
(#) Software using DAC_TRIGGER_SOFTWARE | |||
*** DAC Buffer mode feature *** | |||
=============================== | |||
[..] | |||
Each DAC channel integrates an output buffer that can be used to | |||
reduce the output impedance, and to drive external loads directly | |||
without having to add an external operational amplifier. | |||
To enable, the output buffer use | |||
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; | |||
[..] | |||
(@) Refer to the device datasheet for more details about output | |||
impedance value with and without output buffer. | |||
*** DAC wave generation feature *** | |||
=================================== | |||
[..] | |||
Both DAC channels can be used to generate | |||
(#) Noise wave using HAL_DACEx_NoiseWaveGenerate() | |||
(#) Triangle wave using HAL_DACEx_TriangleWaveGenerate() | |||
*** DAC data format *** | |||
======================= | |||
[..] | |||
The DAC data format can be: | |||
(#) 8-bit right alignment using DAC_ALIGN_8B_R | |||
(#) 12-bit left alignment using DAC_ALIGN_12B_L | |||
(#) 12-bit right alignment using DAC_ALIGN_12B_R | |||
*** DAC data value to voltage correspondence *** | |||
================================================ | |||
[..] | |||
The analog output voltage on each DAC channel pin is determined | |||
by the following equation: | |||
DAC_OUTx = VREF+ * DOR / 4095 | |||
with DOR is the Data Output Register | |||
VEF+ is the input voltage reference (refer to the device datasheet) | |||
e.g. To set DAC_OUT1 to 0.7V, use | |||
Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V | |||
*** DMA requests *** | |||
===================== | |||
[..] | |||
A DMA1 request can be generated when an external trigger (but not | |||
a software trigger) occurs if DMA1 requests are enabled using | |||
HAL_DAC_Start_DMA() | |||
[..] | |||
DMA1 requests are mapped as following: | |||
(#) DAC channel1 : mapped on DMA1 Stream5 channel7 which must be | |||
already configured | |||
(#) DAC channel2 : mapped on DMA1 Stream6 channel7 which must be | |||
already configured | |||
-@- For Dual mode and specific signal (Triangle and noise) generation please | |||
refer to Extension Features Driver description | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] | |||
(+) DAC APB clock must be enabled to get write access to DAC | |||
registers using HAL_DAC_Init() | |||
(+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode. | |||
(+) Configure the DAC channel using HAL_DAC_ConfigChannel() function. | |||
(+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA functions | |||
*** Polling mode IO operation *** | |||
================================= | |||
[..] | |||
(+) Start the DAC peripheral using HAL_DAC_Start() | |||
(+) To read the DAC last data output value, use the HAL_DAC_GetValue() function. | |||
(+) Stop the DAC peripheral using HAL_DAC_Stop() | |||
*** DMA mode IO operation *** | |||
============================== | |||
[..] | |||
(+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length | |||
of data to be transferred at each end of conversion | |||
(+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1()or HAL_DAC_ConvCpltCallbackCh2() | |||
function is executed and user can add his own code by customization of function pointer | |||
HAL_DAC_ConvCpltCallbackCh1 or HAL_DAC_ConvCpltCallbackCh2 | |||
(+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can | |||
add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1 | |||
(+) Stop the DAC peripheral using HAL_DAC_Stop_DMA() | |||
*** DAC HAL driver macros list *** | |||
============================================= | |||
[..] | |||
Below the list of most used macros in DAC HAL driver. | |||
(+) __HAL_DAC_ENABLE : Enable the DAC peripheral | |||
(+) __HAL_DAC_DISABLE : Disable the DAC peripheral | |||
(+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags | |||
(+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status | |||
[..] | |||
(@) You can refer to the DAC HAL driver header file for more useful macros | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup DAC DAC | |||
* @brief DAC driver modules | |||
* @{ | |||
*/ | |||
#ifdef HAL_DAC_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/** @addtogroup DAC_Private_Functions | |||
* @{ | |||
*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma); | |||
static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma); | |||
static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma); | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup DAC_Exported_Functions DAC Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @brief Initialization and Configuration functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### Initialization and de-initialization functions ##### | |||
============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Initialize and configure the DAC. | |||
(+) De-initialize the DAC. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Initializes the DAC peripheral according to the specified parameters | |||
* in the DAC_InitStruct. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac) | |||
{ | |||
/* Check DAC handle */ | |||
if(hdac == NULL) | |||
{ | |||
return HAL_ERROR; | |||
} | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); | |||
if(hdac->State == HAL_DAC_STATE_RESET) | |||
{ | |||
/* Allocate lock resource and initialize it */ | |||
hdac->Lock = HAL_UNLOCKED; | |||
/* Init the low level hardware */ | |||
HAL_DAC_MspInit(hdac); | |||
} | |||
/* Initialize the DAC state*/ | |||
hdac->State = HAL_DAC_STATE_BUSY; | |||
/* Set DAC error code to none */ | |||
hdac->ErrorCode = HAL_DAC_ERROR_NONE; | |||
/* Initialize the DAC state*/ | |||
hdac->State = HAL_DAC_STATE_READY; | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Deinitializes the DAC peripheral registers to their default reset values. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac) | |||
{ | |||
/* Check DAC handle */ | |||
if(hdac == NULL) | |||
{ | |||
return HAL_ERROR; | |||
} | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_BUSY; | |||
/* DeInit the low level hardware */ | |||
HAL_DAC_MspDeInit(hdac); | |||
/* Set DAC error code to none */ | |||
hdac->ErrorCode = HAL_DAC_ERROR_NONE; | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_RESET; | |||
/* Release Lock */ | |||
__HAL_UNLOCK(hdac); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Initializes the DAC MSP. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_DAC_MspInit could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief DeInitializes the DAC MSP. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_DAC_MspDeInit could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DAC_Exported_Functions_Group2 IO operation functions | |||
* @brief IO operation functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### IO operation functions ##### | |||
============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Start conversion. | |||
(+) Stop conversion. | |||
(+) Start conversion and enable DMA transfer. | |||
(+) Stop conversion and disable DMA transfer. | |||
(+) Get result of conversion. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Enables DAC and starts conversion of channel. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @param Channel: The selected DAC channel. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_CHANNEL_1: DAC Channel1 selected | |||
* @arg DAC_CHANNEL_2: DAC Channel2 selected | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel) | |||
{ | |||
uint32_t tmp1 = 0, tmp2 = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_CHANNEL(Channel)); | |||
/* Process locked */ | |||
__HAL_LOCK(hdac); | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_BUSY; | |||
/* Enable the Peripheral */ | |||
__HAL_DAC_ENABLE(hdac, Channel); | |||
if(Channel == DAC_CHANNEL_1) | |||
{ | |||
tmp1 = hdac->Instance->CR & DAC_CR_TEN1; | |||
tmp2 = hdac->Instance->CR & DAC_CR_TSEL1; | |||
/* Check if software trigger enabled */ | |||
if((tmp1 == DAC_CR_TEN1) && (tmp2 == DAC_CR_TSEL1)) | |||
{ | |||
/* Enable the selected DAC software conversion */ | |||
hdac->Instance->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1; | |||
} | |||
} | |||
else | |||
{ | |||
tmp1 = hdac->Instance->CR & DAC_CR_TEN2; | |||
tmp2 = hdac->Instance->CR & DAC_CR_TSEL2; | |||
/* Check if software trigger enabled */ | |||
if((tmp1 == DAC_CR_TEN2) && (tmp2 == DAC_CR_TSEL2)) | |||
{ | |||
/* Enable the selected DAC software conversion*/ | |||
hdac->Instance->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG2; | |||
} | |||
} | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_READY; | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hdac); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Disables DAC and stop conversion of channel. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @param Channel: The selected DAC channel. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_CHANNEL_1: DAC Channel1 selected | |||
* @arg DAC_CHANNEL_2: DAC Channel2 selected | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_CHANNEL(Channel)); | |||
/* Disable the Peripheral */ | |||
__HAL_DAC_DISABLE(hdac, Channel); | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_READY; | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Enables DAC and starts conversion of channel. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @param Channel: The selected DAC channel. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_CHANNEL_1: DAC Channel1 selected | |||
* @arg DAC_CHANNEL_2: DAC Channel2 selected | |||
* @param pData: The destination peripheral Buffer address. | |||
* @param Length: The length of data to be transferred from memory to DAC peripheral | |||
* @param Alignment: Specifies the data alignment for DAC channel. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_ALIGN_8B_R: 8bit right data alignment selected | |||
* @arg DAC_ALIGN_12B_L: 12bit left data alignment selected | |||
* @arg DAC_ALIGN_12B_R: 12bit right data alignment selected | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment) | |||
{ | |||
uint32_t tmpreg = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_CHANNEL(Channel)); | |||
assert_param(IS_DAC_ALIGN(Alignment)); | |||
/* Process locked */ | |||
__HAL_LOCK(hdac); | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_BUSY; | |||
if(Channel == DAC_CHANNEL_1) | |||
{ | |||
/* Set the DMA transfer complete callback for channel1 */ | |||
hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1; | |||
/* Set the DMA half transfer complete callback for channel1 */ | |||
hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1; | |||
/* Set the DMA error callback for channel1 */ | |||
hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1; | |||
/* Enable the selected DAC channel1 DMA request */ | |||
hdac->Instance->CR |= DAC_CR_DMAEN1; | |||
/* Case of use of channel 1 */ | |||
switch(Alignment) | |||
{ | |||
case DAC_ALIGN_12B_R: | |||
/* Get DHR12R1 address */ | |||
tmpreg = (uint32_t)&hdac->Instance->DHR12R1; | |||
break; | |||
case DAC_ALIGN_12B_L: | |||
/* Get DHR12L1 address */ | |||
tmpreg = (uint32_t)&hdac->Instance->DHR12L1; | |||
break; | |||
case DAC_ALIGN_8B_R: | |||
/* Get DHR8R1 address */ | |||
tmpreg = (uint32_t)&hdac->Instance->DHR8R1; | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
else | |||
{ | |||
/* Set the DMA transfer complete callback for channel2 */ | |||
hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2; | |||
/* Set the DMA half transfer complete callback for channel2 */ | |||
hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2; | |||
/* Set the DMA error callback for channel2 */ | |||
hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2; | |||
/* Enable the selected DAC channel2 DMA request */ | |||
hdac->Instance->CR |= DAC_CR_DMAEN2; | |||
/* Case of use of channel 2 */ | |||
switch(Alignment) | |||
{ | |||
case DAC_ALIGN_12B_R: | |||
/* Get DHR12R2 address */ | |||
tmpreg = (uint32_t)&hdac->Instance->DHR12R2; | |||
break; | |||
case DAC_ALIGN_12B_L: | |||
/* Get DHR12L2 address */ | |||
tmpreg = (uint32_t)&hdac->Instance->DHR12L2; | |||
break; | |||
case DAC_ALIGN_8B_R: | |||
/* Get DHR8R2 address */ | |||
tmpreg = (uint32_t)&hdac->Instance->DHR8R2; | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
/* Enable the DMA Stream */ | |||
if(Channel == DAC_CHANNEL_1) | |||
{ | |||
/* Enable the DAC DMA underrun interrupt */ | |||
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1); | |||
/* Enable the DMA Stream */ | |||
HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length); | |||
} | |||
else | |||
{ | |||
/* Enable the DAC DMA underrun interrupt */ | |||
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2); | |||
/* Enable the DMA Stream */ | |||
HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length); | |||
} | |||
/* Enable the Peripheral */ | |||
__HAL_DAC_ENABLE(hdac, Channel); | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hdac); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Disables DAC and stop conversion of channel. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @param Channel: The selected DAC channel. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_CHANNEL_1: DAC Channel1 selected | |||
* @arg DAC_CHANNEL_2: DAC Channel2 selected | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel) | |||
{ | |||
HAL_StatusTypeDef status = HAL_OK; | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_CHANNEL(Channel)); | |||
/* Disable the selected DAC channel DMA request */ | |||
hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << Channel); | |||
/* Disable the Peripheral */ | |||
__HAL_DAC_DISABLE(hdac, Channel); | |||
/* Disable the DMA Channel */ | |||
/* Channel1 is used */ | |||
if(Channel == DAC_CHANNEL_1) | |||
{ | |||
status = HAL_DMA_Abort(hdac->DMA_Handle1); | |||
} | |||
else /* Channel2 is used for */ | |||
{ | |||
status = HAL_DMA_Abort(hdac->DMA_Handle2); | |||
} | |||
/* Check if DMA Channel effectively disabled */ | |||
if(status != HAL_OK) | |||
{ | |||
/* Update DAC state machine to error */ | |||
hdac->State = HAL_DAC_STATE_ERROR; | |||
} | |||
else | |||
{ | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_READY; | |||
} | |||
/* Return function status */ | |||
return status; | |||
} | |||
/** | |||
* @brief Returns the last data output value of the selected DAC channel. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @param Channel: The selected DAC channel. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_CHANNEL_1: DAC Channel1 selected | |||
* @arg DAC_CHANNEL_2: DAC Channel2 selected | |||
* @retval The selected DAC channel data output value. | |||
*/ | |||
uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_CHANNEL(Channel)); | |||
/* Returns the DAC channel data output register value */ | |||
if(Channel == DAC_CHANNEL_1) | |||
{ | |||
return hdac->Instance->DOR1; | |||
} | |||
else | |||
{ | |||
return hdac->Instance->DOR2; | |||
} | |||
} | |||
/** | |||
* @brief Handles DAC interrupt request | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac) | |||
{ | |||
/* Check underrun channel 1 flag */ | |||
if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1)) | |||
{ | |||
/* Change DAC state to error state */ | |||
hdac->State = HAL_DAC_STATE_ERROR; | |||
/* Set DAC error code to channel1 DMA underrun error */ | |||
hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH1; | |||
/* Clear the underrun flag */ | |||
__HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1); | |||
/* Disable the selected DAC channel1 DMA request */ | |||
hdac->Instance->CR &= ~DAC_CR_DMAEN1; | |||
/* Error callback */ | |||
HAL_DAC_DMAUnderrunCallbackCh1(hdac); | |||
} | |||
/* Check underrun channel 2 flag */ | |||
if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR2)) | |||
{ | |||
/* Change DAC state to error state */ | |||
hdac->State = HAL_DAC_STATE_ERROR; | |||
/* Set DAC error code to channel2 DMA underrun error */ | |||
hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH2; | |||
/* Clear the underrun flag */ | |||
__HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR2); | |||
/* Disable the selected DAC channel1 DMA request */ | |||
hdac->Instance->CR &= ~DAC_CR_DMAEN2; | |||
/* Error callback */ | |||
HAL_DACEx_DMAUnderrunCallbackCh2(hdac); | |||
} | |||
} | |||
/** | |||
* @brief Conversion complete callback in non blocking mode for Channel1 | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_DAC_ConvCpltCallback could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief Conversion half DMA transfer callback in non blocking mode for Channel1 | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief Error DAC callback for Channel1. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief DMA underrun DAC callback for channel1. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions | |||
* @brief Peripheral Control functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### Peripheral Control functions ##### | |||
============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Configure channels. | |||
(+) Set the specified data holding register value for DAC channel. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Configures the selected DAC channel. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @param sConfig: DAC configuration structure. | |||
* @param Channel: The selected DAC channel. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_CHANNEL_1: DAC Channel1 selected | |||
* @arg DAC_CHANNEL_2: DAC Channel2 selected | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel) | |||
{ | |||
uint32_t tmpreg1 = 0, tmpreg2 = 0; | |||
/* Check the DAC parameters */ | |||
assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger)); | |||
assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer)); | |||
assert_param(IS_DAC_CHANNEL(Channel)); | |||
/* Process locked */ | |||
__HAL_LOCK(hdac); | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_BUSY; | |||
/* Get the DAC CR value */ | |||
tmpreg1 = hdac->Instance->CR; | |||
/* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */ | |||
tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << Channel); | |||
/* Configure for the selected DAC channel: buffer output, trigger */ | |||
/* Set TSELx and TENx bits according to DAC_Trigger value */ | |||
/* Set BOFFx bit according to DAC_OutputBuffer value */ | |||
tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer); | |||
/* Calculate CR register value depending on DAC_Channel */ | |||
tmpreg1 |= tmpreg2 << Channel; | |||
/* Write to DAC CR */ | |||
hdac->Instance->CR = tmpreg1; | |||
/* Disable wave generation */ | |||
hdac->Instance->CR &= ~(DAC_CR_WAVE1 << Channel); | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_READY; | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hdac); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Set the specified data holding register value for DAC channel. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @param Channel: The selected DAC channel. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_CHANNEL_1: DAC Channel1 selected | |||
* @arg DAC_CHANNEL_2: DAC Channel2 selected | |||
* @param Alignment: Specifies the data alignment. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_ALIGN_8B_R: 8bit right data alignment selected | |||
* @arg DAC_ALIGN_12B_L: 12bit left data alignment selected | |||
* @arg DAC_ALIGN_12B_R: 12bit right data alignment selected | |||
* @param Data: Data to be loaded in the selected data holding register. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data) | |||
{ | |||
__IO uint32_t tmp = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_CHANNEL(Channel)); | |||
assert_param(IS_DAC_ALIGN(Alignment)); | |||
assert_param(IS_DAC_DATA(Data)); | |||
tmp = (uint32_t)hdac->Instance; | |||
if(Channel == DAC_CHANNEL_1) | |||
{ | |||
tmp += DAC_DHR12R1_ALIGNMENT(Alignment); | |||
} | |||
else | |||
{ | |||
tmp += DAC_DHR12R2_ALIGNMENT(Alignment); | |||
} | |||
/* Set the DAC channel1 selected data holding register */ | |||
*(__IO uint32_t *) tmp = Data; | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions | |||
* @brief Peripheral State and Errors functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### Peripheral State and Errors functions ##### | |||
============================================================================== | |||
[..] | |||
This subsection provides functions allowing to | |||
(+) Check the DAC state. | |||
(+) Check the DAC Errors. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief return the DAC state | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval HAL state | |||
*/ | |||
HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac) | |||
{ | |||
/* Return DAC state */ | |||
return hdac->State; | |||
} | |||
/** | |||
* @brief Return the DAC error code | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval DAC Error Code | |||
*/ | |||
uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac) | |||
{ | |||
return hdac->ErrorCode; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @brief DMA conversion complete callback. | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA module. | |||
* @retval None | |||
*/ | |||
static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma) | |||
{ | |||
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |||
HAL_DAC_ConvCpltCallbackCh1(hdac); | |||
hdac->State= HAL_DAC_STATE_READY; | |||
} | |||
/** | |||
* @brief DMA half transfer complete callback. | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA module. | |||
* @retval None | |||
*/ | |||
static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma) | |||
{ | |||
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |||
/* Conversion complete callback */ | |||
HAL_DAC_ConvHalfCpltCallbackCh1(hdac); | |||
} | |||
/** | |||
* @brief DMA error callback | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA module. | |||
* @retval None | |||
*/ | |||
static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma) | |||
{ | |||
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |||
/* Set DAC error code to DMA error */ | |||
hdac->ErrorCode |= HAL_DAC_ERROR_DMA; | |||
HAL_DAC_ErrorCallbackCh1(hdac); | |||
hdac->State= HAL_DAC_STATE_READY; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_DAC_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,376 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_dac_ex.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Extended DAC HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities of DAC extension peripheral: | |||
* + Extended features functions | |||
* | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] | |||
(+) When Dual mode is enabled (i.e DAC Channel1 and Channel2 are used simultaneously) : | |||
Use HAL_DACEx_DualGetValue() to get digital data to be converted and use | |||
HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in Channel 1 and Channel 2. | |||
(+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal. | |||
(+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal. | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup DACEx DACEx | |||
* @brief DAC driver modules | |||
* @{ | |||
*/ | |||
#ifdef HAL_DAC_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup DACEx_Exported_Functions DAC Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup DACEx_Exported_Functions_Group1 Extended features functions | |||
* @brief Extended features functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### Extended features functions ##### | |||
============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Start conversion. | |||
(+) Stop conversion. | |||
(+) Start conversion and enable DMA transfer. | |||
(+) Stop conversion and disable DMA transfer. | |||
(+) Get result of conversion. | |||
(+) Get result of dual mode conversion. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Returns the last data output value of the selected DAC channel. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval The selected DAC channel data output value. | |||
*/ | |||
uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac) | |||
{ | |||
uint32_t tmp = 0; | |||
tmp |= hdac->Instance->DOR1; | |||
tmp |= hdac->Instance->DOR2 << 16; | |||
/* Returns the DAC channel data output register value */ | |||
return tmp; | |||
} | |||
/** | |||
* @brief Enables or disables the selected DAC channel wave generation. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @param Channel: The selected DAC channel. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_CHANNEL_1: DAC Channel1 selected | |||
* @arg DAC_CHANNEL_2: DAC Channel2 selected | |||
* @param Amplitude: Select max triangle amplitude. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1 | |||
* @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3 | |||
* @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7 | |||
* @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15 | |||
* @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31 | |||
* @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63 | |||
* @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127 | |||
* @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255 | |||
* @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511 | |||
* @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023 | |||
* @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047 | |||
* @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095 | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_CHANNEL(Channel)); | |||
assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude)); | |||
/* Process locked */ | |||
__HAL_LOCK(hdac); | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_BUSY; | |||
/* Enable the selected wave generation for the selected DAC channel */ | |||
MODIFY_REG(hdac->Instance->CR, (DAC_CR_WAVE1 | DAC_CR_MAMP1) << Channel, (DAC_CR_WAVE1_1 | Amplitude) << Channel); | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_READY; | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hdac); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Enables or disables the selected DAC channel wave generation. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @param Channel: The selected DAC channel. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_CHANNEL_1: DAC Channel1 selected | |||
* @arg DAC_CHANNEL_2: DAC Channel2 selected | |||
* @param Amplitude: Unmask DAC channel LFSR for noise wave generation. | |||
* This parameter can be one of the following values: | |||
* @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation | |||
* @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_CHANNEL(Channel)); | |||
assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude)); | |||
/* Process locked */ | |||
__HAL_LOCK(hdac); | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_BUSY; | |||
/* Enable the selected wave generation for the selected DAC channel */ | |||
MODIFY_REG(hdac->Instance->CR, (DAC_CR_WAVE1 | DAC_CR_MAMP1) << Channel, (DAC_CR_WAVE1_0 | Amplitude) << Channel); | |||
/* Change DAC state */ | |||
hdac->State = HAL_DAC_STATE_READY; | |||
/* Process unlocked */ | |||
__HAL_UNLOCK(hdac); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Set the specified data holding register value for dual DAC channel. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @param Alignment: Specifies the data alignment for dual channel DAC. | |||
* This parameter can be one of the following values: | |||
* DAC_ALIGN_8B_R: 8bit right data alignment selected | |||
* DAC_ALIGN_12B_L: 12bit left data alignment selected | |||
* DAC_ALIGN_12B_R: 12bit right data alignment selected | |||
* @param Data1: Data for DAC Channel2 to be loaded in the selected data holding register. | |||
* @param Data2: Data for DAC Channel1 to be loaded in the selected data holding register. | |||
* @note In dual mode, a unique register access is required to write in both | |||
* DAC channels at the same time. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2) | |||
{ | |||
uint32_t data = 0, tmp = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_DAC_ALIGN(Alignment)); | |||
assert_param(IS_DAC_DATA(Data1)); | |||
assert_param(IS_DAC_DATA(Data2)); | |||
/* Calculate and set dual DAC data holding register value */ | |||
if (Alignment == DAC_ALIGN_8B_R) | |||
{ | |||
data = ((uint32_t)Data2 << 8) | Data1; | |||
} | |||
else | |||
{ | |||
data = ((uint32_t)Data2 << 16) | Data1; | |||
} | |||
tmp = (uint32_t)hdac->Instance; | |||
tmp += DAC_DHR12RD_ALIGNMENT(Alignment); | |||
/* Set the dual DAC selected data holding register */ | |||
*(__IO uint32_t *)tmp = data; | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @brief Conversion complete callback in non blocking mode for Channel2 | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_DAC_ConvCpltCallbackCh2 could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief Conversion half DMA transfer callback in non blocking mode for Channel2 | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief Error DAC callback for Channel2. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief DMA underrun DAC callback for channel2. | |||
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains | |||
* the configuration information for the specified DAC. | |||
* @retval None | |||
*/ | |||
__weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief DMA conversion complete callback. | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA module. | |||
* @retval None | |||
*/ | |||
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma) | |||
{ | |||
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |||
HAL_DACEx_ConvCpltCallbackCh2(hdac); | |||
hdac->State= HAL_DAC_STATE_READY; | |||
} | |||
/** | |||
* @brief DMA half transfer complete callback. | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA module. | |||
* @retval None | |||
*/ | |||
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma) | |||
{ | |||
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |||
/* Conversion complete callback */ | |||
HAL_DACEx_ConvHalfCpltCallbackCh2(hdac); | |||
} | |||
/** | |||
* @brief DMA error callback | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA module. | |||
* @retval None | |||
*/ | |||
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma) | |||
{ | |||
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |||
/* Set DAC error code to DMA error */ | |||
hdac->ErrorCode |= HAL_DAC_ERROR_DMA; | |||
HAL_DACEx_ErrorCallbackCh2(hdac); | |||
hdac->State= HAL_DAC_STATE_READY; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_DAC_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,921 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_dma.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @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 Stream | |||
(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 Stream, program the required configuration through the following parameters: | |||
Transfer Direction, Source and Destination data formats, | |||
Circular, Normal or peripheral flow control mode, Stream Priority level, | |||
Source and Destination Increment mode, FIFO mode and its Threshold (if needed), | |||
Burst mode for Source and/or Destination (if needed) using HAL_DMA_Init() function. | |||
*** 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_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). | |||
[..] | |||
(#) 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. | |||
-@- The FIFO is used mainly to reduce bus usage and to allow data packing/unpacking: it is | |||
possible to set different Data Sizes for the Peripheral and the Memory (ie. you can set | |||
Half-Word data size for the peripheral to access its data register and set Word data size | |||
for the Memory to gain in access time. Each two half words will be packed and written in | |||
a single access to a Word in the Memory). | |||
-@- When FIFO is disabled, it is not allowed to configure different Data Sizes for Source | |||
and Destination. In this case the Peripheral Data Size will be applied to both Source | |||
and Destination. | |||
*** DMA HAL driver macros list *** | |||
============================================= | |||
[..] | |||
Below the list of most used macros in DMA HAL driver. | |||
(+) __HAL_DMA_ENABLE: Enable the specified DMA Stream. | |||
(+) __HAL_DMA_DISABLE: Disable the specified DMA Stream. | |||
(+) __HAL_DMA_GET_FS: Return the current DMA Stream FIFO filled level. | |||
(+) __HAL_DMA_GET_FLAG: Get the DMA Stream pending flags. | |||
(+) __HAL_DMA_CLEAR_FLAG: Clear the DMA Stream pending flags. | |||
(+) __HAL_DMA_ENABLE_IT: Enable the specified DMA Stream interrupts. | |||
(+) __HAL_DMA_DISABLE_IT: Disable the specified DMA Stream interrupts. | |||
(+) __HAL_DMA_GET_IT_SOURCE: Check whether the specified DMA Stream interrupt has occurred or not. | |||
[..] | |||
(@) You can refer to the DMA HAL driver header file for more useful macros | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup DMA DMA | |||
* @brief DMA HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_DMA_MODULE_ENABLED | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @addtogroup DMA_Private_Constants | |||
* @{ | |||
*/ | |||
#define HAL_TIMEOUT_DMA_ABORT ((uint32_t)1000) /* 1s */ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @addtogroup DMA_Private_Functions | |||
* @{ | |||
*/ | |||
static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); | |||
/** | |||
* @brief Sets the DMA Transfer parameter. | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA Stream. | |||
* @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 DBM bit */ | |||
hdma->Instance->CR &= (uint32_t)(~DMA_SxCR_DBM); | |||
/* Configure DMA Stream data length */ | |||
hdma->Instance->NDTR = DataLength; | |||
/* Peripheral to Memory */ | |||
if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH) | |||
{ | |||
/* Configure DMA Stream destination address */ | |||
hdma->Instance->PAR = DstAddress; | |||
/* Configure DMA Stream source address */ | |||
hdma->Instance->M0AR = SrcAddress; | |||
} | |||
/* Memory to Peripheral */ | |||
else | |||
{ | |||
/* Configure DMA Stream source address */ | |||
hdma->Instance->PAR = SrcAddress; | |||
/* Configure DMA Stream destination address */ | |||
hdma->Instance->M0AR = DstAddress; | |||
} | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions ---------------------------------------------------------*/ | |||
/** @addtogroup DMA_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup DMA_Exported_Functions_Group1 | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Initialization and de-initialization functions ##### | |||
=============================================================================== | |||
[..] | |||
This section provides functions allowing to initialize the DMA Stream source | |||
and destination addresses, incrementation and data sizes, transfer direction, | |||
circular/normal mode selection, memory-to-memory mode selection and Stream priority value. | |||
[..] | |||
The HAL_DMA_Init() function follows the DMA configuration procedures as described in | |||
reference manual. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Initializes the DMA according to the specified | |||
* parameters in the DMA_InitTypeDef and create the associated handle. | |||
* @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_Init(DMA_HandleTypeDef *hdma) | |||
{ | |||
uint32_t tmp = 0; | |||
/* Check the DMA peripheral state */ | |||
if(hdma == NULL) | |||
{ | |||
return HAL_ERROR; | |||
} | |||
/* Check the parameters */ | |||
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance)); | |||
assert_param(IS_DMA_CHANNEL(hdma->Init.Channel)); | |||
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)); | |||
assert_param(IS_DMA_FIFO_MODE_STATE(hdma->Init.FIFOMode)); | |||
/* Check the memory burst, peripheral burst and FIFO threshold parameters only | |||
when FIFO mode is enabled */ | |||
if(hdma->Init.FIFOMode != DMA_FIFOMODE_DISABLE) | |||
{ | |||
assert_param(IS_DMA_FIFO_THRESHOLD(hdma->Init.FIFOThreshold)); | |||
assert_param(IS_DMA_MEMORY_BURST(hdma->Init.MemBurst)); | |||
assert_param(IS_DMA_PERIPHERAL_BURST(hdma->Init.PeriphBurst)); | |||
} | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_BUSY; | |||
/* Get the CR register value */ | |||
tmp = hdma->Instance->CR; | |||
/* Clear CHSEL, MBURST, PBURST, PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR, CT and DBM bits */ | |||
tmp &= ((uint32_t)~(DMA_SxCR_CHSEL | DMA_SxCR_MBURST | DMA_SxCR_PBURST | \ | |||
DMA_SxCR_PL | DMA_SxCR_MSIZE | DMA_SxCR_PSIZE | \ | |||
DMA_SxCR_MINC | DMA_SxCR_PINC | DMA_SxCR_CIRC | \ | |||
DMA_SxCR_DIR | DMA_SxCR_CT | DMA_SxCR_DBM)); | |||
/* Prepare the DMA Stream configuration */ | |||
tmp |= hdma->Init.Channel | hdma->Init.Direction | | |||
hdma->Init.PeriphInc | hdma->Init.MemInc | | |||
hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment | | |||
hdma->Init.Mode | hdma->Init.Priority; | |||
/* the Memory burst and peripheral burst are not used when the FIFO is disabled */ | |||
if(hdma->Init.FIFOMode == DMA_FIFOMODE_ENABLE) | |||
{ | |||
/* Get memory burst and peripheral burst */ | |||
tmp |= hdma->Init.MemBurst | hdma->Init.PeriphBurst; | |||
} | |||
/* Write to DMA Stream CR register */ | |||
hdma->Instance->CR = tmp; | |||
/* Get the FCR register value */ | |||
tmp = hdma->Instance->FCR; | |||
/* Clear Direct mode and FIFO threshold bits */ | |||
tmp &= (uint32_t)~(DMA_SxFCR_DMDIS | DMA_SxFCR_FTH); | |||
/* Prepare the DMA Stream FIFO configuration */ | |||
tmp |= hdma->Init.FIFOMode; | |||
/* the FIFO threshold is not used when the FIFO mode is disabled */ | |||
if(hdma->Init.FIFOMode == DMA_FIFOMODE_ENABLE) | |||
{ | |||
/* Get the FIFO threshold */ | |||
tmp |= hdma->Init.FIFOThreshold; | |||
} | |||
/* Write to DMA Stream FCR */ | |||
hdma->Instance->FCR = tmp; | |||
/* Initialize the error code */ | |||
hdma->ErrorCode = HAL_DMA_ERROR_NONE; | |||
/* Initialize the DMA state */ | |||
hdma->State = HAL_DMA_STATE_READY; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief DeInitializes the DMA peripheral | |||
* @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_DeInit(DMA_HandleTypeDef *hdma) | |||
{ | |||
/* Check the DMA peripheral state */ | |||
if(hdma == NULL) | |||
{ | |||
return HAL_ERROR; | |||
} | |||
/* Check the DMA peripheral state */ | |||
if(hdma->State == HAL_DMA_STATE_BUSY) | |||
{ | |||
return HAL_ERROR; | |||
} | |||
/* Disable the selected DMA Streamx */ | |||
__HAL_DMA_DISABLE(hdma); | |||
/* Reset DMA Streamx control register */ | |||
hdma->Instance->CR = 0; | |||
/* Reset DMA Streamx number of data to transfer register */ | |||
hdma->Instance->NDTR = 0; | |||
/* Reset DMA Streamx peripheral address register */ | |||
hdma->Instance->PAR = 0; | |||
/* Reset DMA Streamx memory 0 address register */ | |||
hdma->Instance->M0AR = 0; | |||
/* Reset DMA Streamx memory 1 address register */ | |||
hdma->Instance->M1AR = 0; | |||
/* Reset DMA Streamx FIFO control register */ | |||
hdma->Instance->FCR = (uint32_t)0x00000021; | |||
/* Clear all flags */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_DME_FLAG_INDEX(hdma)); | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)); | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_FE_FLAG_INDEX(hdma)); | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); | |||
/* Initialize the error code */ | |||
hdma->ErrorCode = HAL_DMA_ERROR_NONE; | |||
/* Initialize the DMA state */ | |||
hdma->State = HAL_DMA_STATE_RESET; | |||
/* Release Lock */ | |||
__HAL_UNLOCK(hdma); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup DMA_Exported_Functions_Group2 | |||
* | |||
@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 Starts the DMA Transfer. | |||
* @param hdma : pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA Stream. | |||
* @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) | |||
{ | |||
/* Process locked */ | |||
__HAL_LOCK(hdma); | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_BUSY; | |||
/* Check the parameters */ | |||
assert_param(IS_DMA_BUFFER_SIZE(DataLength)); | |||
/* Disable the peripheral */ | |||
__HAL_DMA_DISABLE(hdma); | |||
/* Configure the source, destination address and the data length */ | |||
DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength); | |||
/* Enable the Peripheral */ | |||
__HAL_DMA_ENABLE(hdma); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @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 Stream. | |||
* @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) | |||
{ | |||
/* Process locked */ | |||
__HAL_LOCK(hdma); | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_BUSY; | |||
/* Check the parameters */ | |||
assert_param(IS_DMA_BUFFER_SIZE(DataLength)); | |||
/* Disable the peripheral */ | |||
__HAL_DMA_DISABLE(hdma); | |||
/* Configure the source, destination address and the data length */ | |||
DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength); | |||
/* Enable the transfer complete interrupt */ | |||
__HAL_DMA_ENABLE_IT(hdma, DMA_IT_TC); | |||
/* Enable the Half transfer complete interrupt */ | |||
__HAL_DMA_ENABLE_IT(hdma, DMA_IT_HT); | |||
/* Enable the transfer Error interrupt */ | |||
__HAL_DMA_ENABLE_IT(hdma, DMA_IT_TE); | |||
/* Enable the FIFO Error interrupt */ | |||
__HAL_DMA_ENABLE_IT(hdma, DMA_IT_FE); | |||
/* Enable the direct mode Error interrupt */ | |||
__HAL_DMA_ENABLE_IT(hdma, DMA_IT_DME); | |||
/* Enable the Peripheral */ | |||
__HAL_DMA_ENABLE(hdma); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Aborts the DMA Transfer. | |||
* @param hdma : pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA Stream. | |||
* | |||
* @note After disabling a DMA Stream, a check for wait until the DMA Stream is | |||
* effectively disabled is added. If a Stream is disabled | |||
* while a data transfer is ongoing, the current data will be transferred | |||
* and the Stream will be effectively disabled only after the transfer of | |||
* this single data is finished. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma) | |||
{ | |||
uint32_t tickstart = 0; | |||
/* Disable the stream */ | |||
__HAL_DMA_DISABLE(hdma); | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
/* Check if the DMA Stream is effectively disabled */ | |||
while((hdma->Instance->CR & DMA_SxCR_EN) != 0) | |||
{ | |||
/* Check for the Timeout */ | |||
if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA_ABORT) | |||
{ | |||
/* Update error code */ | |||
hdma->ErrorCode |= HAL_DMA_ERROR_TIMEOUT; | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hdma); | |||
/* Change the DMA state */ | |||
hdma->State = HAL_DMA_STATE_TIMEOUT; | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hdma); | |||
/* Change the DMA state*/ | |||
hdma->State = HAL_DMA_STATE_READY; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Polling for transfer complete. | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA Stream. | |||
* @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, tmp, tmp1, tmp2; | |||
uint32_t tickstart = 0; | |||
/* Get the level transfer complete flag */ | |||
if(CompleteLevel == HAL_DMA_FULL_TRANSFER) | |||
{ | |||
/* Transfer Complete flag */ | |||
temp = __HAL_DMA_GET_TC_FLAG_INDEX(hdma); | |||
} | |||
else | |||
{ | |||
/* Half Transfer Complete flag */ | |||
temp = __HAL_DMA_GET_HT_FLAG_INDEX(hdma); | |||
} | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
while(__HAL_DMA_GET_FLAG(hdma, temp) == RESET) | |||
{ | |||
tmp = __HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)); | |||
tmp1 = __HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_FE_FLAG_INDEX(hdma)); | |||
tmp2 = __HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_DME_FLAG_INDEX(hdma)); | |||
if((tmp != RESET) || (tmp1 != RESET) || (tmp2 != RESET)) | |||
{ | |||
if(tmp != RESET) | |||
{ | |||
/* Update error code */ | |||
hdma->ErrorCode |= HAL_DMA_ERROR_TE; | |||
/* Clear the transfer error flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)); | |||
} | |||
if(tmp1 != RESET) | |||
{ | |||
/* Update error code */ | |||
hdma->ErrorCode |= HAL_DMA_ERROR_FE; | |||
/* Clear the FIFO error flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_FE_FLAG_INDEX(hdma)); | |||
} | |||
if(tmp2 != RESET) | |||
{ | |||
/* Update error code */ | |||
hdma->ErrorCode |= HAL_DMA_ERROR_DME; | |||
/* Clear the Direct Mode error flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_DME_FLAG_INDEX(hdma)); | |||
} | |||
/* Change the DMA state */ | |||
hdma->State= HAL_DMA_STATE_ERROR; | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hdma); | |||
return HAL_ERROR; | |||
} | |||
/* Check for the Timeout */ | |||
if(Timeout != HAL_MAX_DELAY) | |||
{ | |||
if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) | |||
{ | |||
/* Update error code */ | |||
hdma->ErrorCode |= HAL_DMA_ERROR_TIMEOUT; | |||
/* Change the DMA state */ | |||
hdma->State = HAL_DMA_STATE_TIMEOUT; | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hdma); | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
} | |||
if(CompleteLevel == HAL_DMA_FULL_TRANSFER) | |||
{ | |||
/* Multi_Buffering mode enabled */ | |||
if(((hdma->Instance->CR) & (uint32_t)(DMA_SxCR_DBM)) != 0) | |||
{ | |||
/* Clear the half transfer complete flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); | |||
/* Clear the transfer complete flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); | |||
/* Current memory buffer used is Memory 0 */ | |||
if((hdma->Instance->CR & DMA_SxCR_CT) == 0) | |||
{ | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_READY_MEM0; | |||
} | |||
/* Current memory buffer used is Memory 1 */ | |||
else if((hdma->Instance->CR & DMA_SxCR_CT) != 0) | |||
{ | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_READY_MEM1; | |||
} | |||
} | |||
else | |||
{ | |||
/* Clear the half transfer complete flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); | |||
/* Clear the transfer complete flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); | |||
/* The selected Streamx EN bit is cleared (DMA is disabled and all transfers | |||
are complete) */ | |||
hdma->State = HAL_DMA_STATE_READY_MEM0; | |||
} | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hdma); | |||
} | |||
else | |||
{ | |||
/* Multi_Buffering mode enabled */ | |||
if(((hdma->Instance->CR) & (uint32_t)(DMA_SxCR_DBM)) != 0) | |||
{ | |||
/* Clear the half transfer complete flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); | |||
/* Current memory buffer used is Memory 0 */ | |||
if((hdma->Instance->CR & DMA_SxCR_CT) == 0) | |||
{ | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_READY_HALF_MEM0; | |||
} | |||
/* Current memory buffer used is Memory 1 */ | |||
else if((hdma->Instance->CR & DMA_SxCR_CT) != 0) | |||
{ | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_READY_HALF_MEM1; | |||
} | |||
} | |||
else | |||
{ | |||
/* Clear the half transfer complete flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_READY_HALF_MEM0; | |||
} | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Handles DMA interrupt request. | |||
* @param hdma: pointer to a DMA_HandleTypeDef structure that contains | |||
* the configuration information for the specified DMA Stream. | |||
* @retval None | |||
*/ | |||
void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma) | |||
{ | |||
/* Transfer Error Interrupt management ***************************************/ | |||
if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET) | |||
{ | |||
if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TE) != RESET) | |||
{ | |||
/* Disable the transfer error interrupt */ | |||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE); | |||
/* Clear the transfer error flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)); | |||
/* Update error code */ | |||
hdma->ErrorCode |= HAL_DMA_ERROR_TE; | |||
/* Change the DMA state */ | |||
hdma->State = HAL_DMA_STATE_ERROR; | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hdma); | |||
if(hdma->XferErrorCallback != NULL) | |||
{ | |||
/* Transfer error callback */ | |||
hdma->XferErrorCallback(hdma); | |||
} | |||
} | |||
} | |||
/* FIFO Error Interrupt management ******************************************/ | |||
if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_FE_FLAG_INDEX(hdma)) != RESET) | |||
{ | |||
if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_FE) != RESET) | |||
{ | |||
/* Disable the FIFO Error interrupt */ | |||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_FE); | |||
/* Clear the FIFO error flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_FE_FLAG_INDEX(hdma)); | |||
/* Update error code */ | |||
hdma->ErrorCode |= HAL_DMA_ERROR_FE; | |||
/* Change the DMA state */ | |||
hdma->State = HAL_DMA_STATE_ERROR; | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hdma); | |||
if(hdma->XferErrorCallback != NULL) | |||
{ | |||
/* Transfer error callback */ | |||
hdma->XferErrorCallback(hdma); | |||
} | |||
} | |||
} | |||
/* Direct Mode Error Interrupt management ***********************************/ | |||
if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_DME_FLAG_INDEX(hdma)) != RESET) | |||
{ | |||
if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_DME) != RESET) | |||
{ | |||
/* Disable the direct mode Error interrupt */ | |||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_DME); | |||
/* Clear the direct mode error flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_DME_FLAG_INDEX(hdma)); | |||
/* Update error code */ | |||
hdma->ErrorCode |= HAL_DMA_ERROR_DME; | |||
/* Change the DMA state */ | |||
hdma->State = HAL_DMA_STATE_ERROR; | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hdma); | |||
if(hdma->XferErrorCallback != NULL) | |||
{ | |||
/* Transfer error callback */ | |||
hdma->XferErrorCallback(hdma); | |||
} | |||
} | |||
} | |||
/* Half Transfer Complete Interrupt management ******************************/ | |||
if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)) != RESET) | |||
{ | |||
if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_HT) != RESET) | |||
{ | |||
/* Multi_Buffering mode enabled */ | |||
if(((hdma->Instance->CR) & (uint32_t)(DMA_SxCR_DBM)) != 0) | |||
{ | |||
/* Clear the half transfer complete flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); | |||
/* Current memory buffer used is Memory 0 */ | |||
if((hdma->Instance->CR & DMA_SxCR_CT) == 0) | |||
{ | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_READY_HALF_MEM0; | |||
} | |||
/* Current memory buffer used is Memory 1 */ | |||
else if((hdma->Instance->CR & DMA_SxCR_CT) != 0) | |||
{ | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_READY_HALF_MEM1; | |||
} | |||
} | |||
else | |||
{ | |||
/* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */ | |||
if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0) | |||
{ | |||
/* Disable the half transfer interrupt */ | |||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT); | |||
} | |||
/* Clear the half transfer complete flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); | |||
/* Change DMA peripheral state */ | |||
hdma->State = HAL_DMA_STATE_READY_HALF_MEM0; | |||
} | |||
if(hdma->XferHalfCpltCallback != NULL) | |||
{ | |||
/* Half transfer callback */ | |||
hdma->XferHalfCpltCallback(hdma); | |||
} | |||
} | |||
} | |||
/* Transfer Complete Interrupt management ***********************************/ | |||
if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)) != RESET) | |||
{ | |||
if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TC) != RESET) | |||
{ | |||
if(((hdma->Instance->CR) & (uint32_t)(DMA_SxCR_DBM)) != 0) | |||
{ | |||
/* Clear the transfer complete flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); | |||
/* Current memory buffer used is Memory 1 */ | |||
if((hdma->Instance->CR & DMA_SxCR_CT) == 0) | |||
{ | |||
if(hdma->XferM1CpltCallback != NULL) | |||
{ | |||
/* Transfer complete Callback for memory1 */ | |||
hdma->XferM1CpltCallback(hdma); | |||
} | |||
} | |||
/* Current memory buffer used is Memory 0 */ | |||
else if((hdma->Instance->CR & DMA_SxCR_CT) != 0) | |||
{ | |||
if(hdma->XferCpltCallback != NULL) | |||
{ | |||
/* Transfer complete Callback for memory0 */ | |||
hdma->XferCpltCallback(hdma); | |||
} | |||
} | |||
} | |||
/* Disable the transfer complete interrupt if the DMA mode is not CIRCULAR */ | |||
else | |||
{ | |||
if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0) | |||
{ | |||
/* Disable the transfer complete interrupt */ | |||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_TC); | |||
} | |||
/* Clear the transfer complete flag */ | |||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); | |||
/* Update error code */ | |||
hdma->ErrorCode |= HAL_DMA_ERROR_NONE; | |||
/* Change the DMA state */ | |||
hdma->State = HAL_DMA_STATE_READY_MEM0; | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hdma); | |||
if(hdma->XferCpltCallback != NULL) | |||
{ | |||
/* Transfer complete callback */ | |||
hdma->XferCpltCallback(hdma); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup DMA_Exported_Functions_Group3 | |||
* | |||
@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 Stream. | |||
* @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 Stream. | |||
* @retval DMA Error Code | |||
*/ | |||
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma) | |||
{ | |||
return hdma->ErrorCode; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_DMA_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,817 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_flash.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @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 Errors 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 and cache lines. | |||
[..] The FLASH main features are: | |||
(+) Flash memory read operations | |||
(+) Flash memory program/erase operations | |||
(+) Read / write protections | |||
(+) Prefetch on I-Code | |||
(+) 64 cache lines of 128 bits on I-Code | |||
(+) 8 cache lines of 128 bits on D-Code | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] | |||
This driver provides functions and macros to configure and program the FLASH | |||
memory of all STM32F7xx devices. | |||
(#) FLASH Memory IO Programming functions: | |||
(++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and | |||
HAL_FLASH_Lock() functions | |||
(++) Program functions: byte, half word, word and double word | |||
(++) There Two modes of programming : | |||
(+++) Polling mode using HAL_FLASH_Program() function | |||
(+++) Interrupt mode using HAL_FLASH_Program_IT() function | |||
(#) Interrupts and flags management functions : | |||
(++) Handle FLASH interrupts by calling HAL_FLASH_IRQHandler() | |||
(++) Wait for last FLASH operation according to its status | |||
(++) Get error flag status by calling HAL_SetErrorCode() | |||
[..] | |||
In addition to these functions, this driver includes a set of macros allowing | |||
to handle the following operations: | |||
(+) Set the latency | |||
(+) Enable/Disable the prefetch buffer | |||
(+) Enable/Disable the Instruction cache and the Data cache | |||
(+) Reset the Instruction cache and the Data cache | |||
(+) Enable/Disable the FLASH interrupts | |||
(+) Monitor the FLASH flags status | |||
[..] | |||
(@) For any Flash memory program operation (erase or program), the CPU clock frequency | |||
(HCLK) must be at least 1MHz. | |||
(@) The contents of the Flash memory are not guaranteed if a device reset occurs during | |||
a Flash memory operation. | |||
(@) Any attempt to read the Flash memory while it is being written or erased, causes the | |||
bus to stall. Read operations are processed correctly once the program operation has | |||
completed. This means that code or data fetches cannot be performed while a write/erase | |||
operation is ongoing. | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup FLASH FLASH | |||
* @brief FLASH HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_FLASH_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/** @addtogroup FLASH_Private_Constants | |||
* @{ | |||
*/ | |||
#define SECTOR_MASK ((uint32_t)0xFFFFFF07) | |||
#define FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/** @addtogroup FLASH_Private_Variables | |||
* @{ | |||
*/ | |||
/* Variable used for Erase sectors under interruption */ | |||
FLASH_ProcessTypeDef pFlash; | |||
/** | |||
* @} | |||
*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/** @addtogroup FLASH_Private_Functions | |||
* @{ | |||
*/ | |||
/* Program operations */ | |||
static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data); | |||
static void FLASH_Program_Word(uint32_t Address, uint32_t Data); | |||
static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data); | |||
static void FLASH_Program_Byte(uint32_t Address, uint8_t Data); | |||
static void FLASH_SetErrorCode(void); | |||
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup FLASH_Exported_Functions FLASH Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions | |||
* @brief Programming operation functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Programming operation functions ##### | |||
=============================================================================== | |||
[..] | |||
This subsection provides a set of functions allowing to manage the FLASH | |||
program operations. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Program byte, halfword, word or double word at a specified address | |||
* @param TypeProgram: Indicate the way to program at a specified address. | |||
* This parameter can be a value of @ref FLASH_Type_Program | |||
* @param Address: specifies the address to be programmed. | |||
* @param Data: specifies 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; | |||
/* Process Locked */ | |||
__HAL_LOCK(&pFlash); | |||
/* Check the parameters */ | |||
assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram)); | |||
/* Wait for last operation to be completed */ | |||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); | |||
if(status == HAL_OK) | |||
{ | |||
switch(TypeProgram) | |||
{ | |||
case FLASH_TYPEPROGRAM_BYTE : | |||
{ | |||
/*Program byte (8-bit) at a specified address.*/ | |||
FLASH_Program_Byte(Address, (uint8_t) Data); | |||
break; | |||
} | |||
case FLASH_TYPEPROGRAM_HALFWORD : | |||
{ | |||
/*Program halfword (16-bit) at a specified address.*/ | |||
FLASH_Program_HalfWord(Address, (uint16_t) Data); | |||
break; | |||
} | |||
case FLASH_TYPEPROGRAM_WORD : | |||
{ | |||
/*Program word (32-bit) at a specified address.*/ | |||
FLASH_Program_Word(Address, (uint32_t) Data); | |||
break; | |||
} | |||
case FLASH_TYPEPROGRAM_DOUBLEWORD : | |||
{ | |||
/*Program double word (64-bit) at a specified address.*/ | |||
FLASH_Program_DoubleWord(Address, Data); | |||
break; | |||
} | |||
default : | |||
break; | |||
} | |||
/* Wait for last operation to be completed */ | |||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); | |||
/* If the program operation is completed, disable the PG Bit */ | |||
FLASH->CR &= (~FLASH_CR_PG); | |||
} | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(&pFlash); | |||
return status; | |||
} | |||
/** | |||
* @brief Program byte, halfword, word or double word at a specified address with interrupt enabled. | |||
* @param TypeProgram: Indicate the way to program at a specified address. | |||
* This parameter can be a value of @ref FLASH_Type_Program | |||
* @param Address: specifies the address to be programmed. | |||
* @param Data: specifies the data to be programmed | |||
* | |||
* @retval 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)); | |||
/* Enable End of FLASH Operation interrupt */ | |||
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP); | |||
/* Enable Error source interrupt */ | |||
__HAL_FLASH_ENABLE_IT(FLASH_IT_ERR); | |||
/* Clear pending flags (if any) */ | |||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |\ | |||
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_ERSERR); | |||
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAM; | |||
pFlash.Address = Address; | |||
switch(TypeProgram) | |||
{ | |||
case FLASH_TYPEPROGRAM_BYTE : | |||
{ | |||
/*Program byte (8-bit) at a specified address.*/ | |||
FLASH_Program_Byte(Address, (uint8_t) Data); | |||
break; | |||
} | |||
case FLASH_TYPEPROGRAM_HALFWORD : | |||
{ | |||
/*Program halfword (16-bit) at a specified address.*/ | |||
FLASH_Program_HalfWord(Address, (uint16_t) Data); | |||
break; | |||
} | |||
case FLASH_TYPEPROGRAM_WORD : | |||
{ | |||
/*Program word (32-bit) at a specified address.*/ | |||
FLASH_Program_Word(Address, (uint32_t) Data); | |||
break; | |||
} | |||
case FLASH_TYPEPROGRAM_DOUBLEWORD : | |||
{ | |||
/*Program double word (64-bit) at a specified address.*/ | |||
FLASH_Program_DoubleWord(Address, Data); | |||
break; | |||
} | |||
default : | |||
break; | |||
} | |||
return status; | |||
} | |||
/** | |||
* @brief This function handles FLASH interrupt request. | |||
* @retval None | |||
*/ | |||
void HAL_FLASH_IRQHandler(void) | |||
{ | |||
uint32_t temp = 0; | |||
/* If the program operation is completed, disable the PG Bit */ | |||
FLASH->CR &= (~FLASH_CR_PG); | |||
/* If the erase operation is completed, disable the SER Bit */ | |||
FLASH->CR &= (~FLASH_CR_SER); | |||
FLASH->CR &= SECTOR_MASK; | |||
/* if the erase operation is completed, disable the MER Bit */ | |||
FLASH->CR &= (~FLASH_MER_BIT); | |||
/* Check FLASH End of Operation flag */ | |||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP) != RESET) | |||
{ | |||
switch (pFlash.ProcedureOnGoing) | |||
{ | |||
case FLASH_PROC_SECTERASE : | |||
{ | |||
/* Nb of sector to erased can be decreased */ | |||
pFlash.NbSectorsToErase--; | |||
/* Check if there are still sectors to erase */ | |||
if(pFlash.NbSectorsToErase != 0) | |||
{ | |||
temp = pFlash.Sector; | |||
/* Indicate user which sector has been erased */ | |||
HAL_FLASH_EndOfOperationCallback(temp); | |||
/* Clear pending flags (if any) */ | |||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP); | |||
/* Increment sector number */ | |||
temp = ++pFlash.Sector; | |||
FLASH_Erase_Sector(temp, pFlash.VoltageForErase); | |||
} | |||
else | |||
{ | |||
/* No more sectors to Erase, user callback can be called.*/ | |||
/* Reset Sector and stop Erase sectors procedure */ | |||
pFlash.Sector = temp = 0xFFFFFFFF; | |||
/* FLASH EOP interrupt user callback */ | |||
HAL_FLASH_EndOfOperationCallback(temp); | |||
/* Sector Erase procedure is completed */ | |||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE; | |||
/* Clear FLASH End of Operation pending bit */ | |||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP); | |||
} | |||
break; | |||
} | |||
case FLASH_PROC_MASSERASE : | |||
{ | |||
/* MassErase ended. Return the selected bank : in this product we don't have Banks */ | |||
/* FLASH EOP interrupt user callback */ | |||
HAL_FLASH_EndOfOperationCallback(0); | |||
/* MAss Erase procedure is completed */ | |||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE; | |||
/* Clear FLASH End of Operation pending bit */ | |||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP); | |||
break; | |||
} | |||
case FLASH_PROC_PROGRAM : | |||
{ | |||
/*Program ended. Return the selected address*/ | |||
/* FLASH EOP interrupt user callback */ | |||
HAL_FLASH_EndOfOperationCallback(pFlash.Address); | |||
/* Programming procedure is completed */ | |||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE; | |||
/* Clear FLASH End of Operation pending bit */ | |||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP); | |||
break; | |||
} | |||
default : | |||
break; | |||
} | |||
} | |||
/* Check FLASH operation error flags */ | |||
if(__HAL_FLASH_GET_FLAG((FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR )) != RESET) | |||
{ | |||
switch (pFlash.ProcedureOnGoing) | |||
{ | |||
case FLASH_PROC_SECTERASE : | |||
{ | |||
/* return the faulty sector */ | |||
temp = pFlash.Sector; | |||
pFlash.Sector = 0xFFFFFFFF; | |||
break; | |||
} | |||
case FLASH_PROC_MASSERASE : | |||
{ | |||
/* No return in case of Mass Erase */ | |||
temp = 0; | |||
break; | |||
} | |||
case FLASH_PROC_PROGRAM : | |||
{ | |||
/*return the faulty address*/ | |||
temp = pFlash.Address; | |||
break; | |||
} | |||
default : | |||
break; | |||
} | |||
/*Save the Error code*/ | |||
FLASH_SetErrorCode(); | |||
/* FLASH error interrupt user callback */ | |||
HAL_FLASH_OperationErrorCallback(temp); | |||
/* Clear FLASH error pending bits */ | |||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR ); | |||
/*Stop the procedure ongoing */ | |||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE; | |||
} | |||
if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE) | |||
{ | |||
/* Disable End of FLASH Operation interrupt */ | |||
__HAL_FLASH_DISABLE_IT(FLASH_IT_EOP); | |||
/* Disable Error source interrupt */ | |||
__HAL_FLASH_DISABLE_IT(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 | |||
* - Sectors Erase: Sector which has been erased (if 0xFFFFFFFF, it means that | |||
* all the selected sectors have been erased) | |||
* - Program : Address which was selected for data program | |||
* - Mass Erase : No return value expected | |||
* @retval None | |||
*/ | |||
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t 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 | |||
* - Sectors Erase: Sector which has been erased (if 0xFFFFFFFF, it means that | |||
* all the selected sectors have been erased) | |||
* - Program : Address which was selected for data program | |||
* - Mass Erase : No return value expected | |||
* @retval None | |||
*/ | |||
__weak void HAL_FLASH_OperationErrorCallback(uint32_t 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) | |||
{ | |||
if((FLASH->CR & FLASH_CR_LOCK) != RESET) | |||
{ | |||
/* Authorize the FLASH Registers access */ | |||
FLASH->KEYR = FLASH_KEY1; | |||
FLASH->KEYR = FLASH_KEY2; | |||
} | |||
else | |||
{ | |||
return HAL_ERROR; | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @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 */ | |||
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((FLASH->OPTCR & FLASH_OPTCR_OPTLOCK) != RESET) | |||
{ | |||
/* Authorizes the Option Byte register programming */ | |||
FLASH->OPTKEYR = FLASH_OPT_KEY1; | |||
FLASH->OPTKEYR = FLASH_OPT_KEY2; | |||
} | |||
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) | |||
{ | |||
/* Set the OPTLOCK Bit to lock the FLASH Option Byte Registers access */ | |||
FLASH->OPTCR |= FLASH_OPTCR_OPTLOCK; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Launch the option byte loading. | |||
* @retval HAL Status | |||
*/ | |||
HAL_StatusTypeDef HAL_FLASH_OB_Launch(void) | |||
{ | |||
/* Set the OPTSTRT bit in OPTCR register */ | |||
FLASH->OPTCR |= FLASH_OPTCR_OPTSTRT; | |||
/* Wait for last operation to be completed */ | |||
return(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE)); | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Exported_Functions_Group3 Peripheral State and Errors functions | |||
* @brief Peripheral Errors functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Peripheral Errors functions ##### | |||
=============================================================================== | |||
[..] | |||
This subsection permits 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: | |||
* @arg FLASH_ERROR_ERS: FLASH Erasing Sequence error flag | |||
* @arg FLASH_ERROR_PGP: FLASH Programming Parallelism error flag | |||
* @arg FLASH_ERROR_PGA: FLASH Programming Alignment error flag | |||
* @arg FLASH_ERROR_WRP: FLASH Write protected error flag | |||
* @arg FLASH_ERROR_OPERATION: FLASH operation Error flag | |||
*/ | |||
uint32_t HAL_FLASH_GetError(void) | |||
{ | |||
return pFlash.ErrorCode; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @brief Wait for a FLASH operation to complete. | |||
* @param Timeout: maximum flash operationtimeout | |||
* @retval HAL Status | |||
*/ | |||
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout) | |||
{ | |||
uint32_t tickstart = 0; | |||
/* Clear Error Code */ | |||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; | |||
/* 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 */ | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET) | |||
{ | |||
if(Timeout != HAL_MAX_DELAY) | |||
{ | |||
if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
} | |||
if(__HAL_FLASH_GET_FLAG((FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \ | |||
FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR )) != RESET) | |||
{ | |||
/*Save the error code*/ | |||
FLASH_SetErrorCode(); | |||
return HAL_ERROR; | |||
} | |||
/* If there is an error flag set */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Program a double word (64-bit) at a specified address. | |||
* @note This function must be used when the device voltage range is from | |||
* 2.7V to 3.6V and an External Vpp is present. | |||
* | |||
* @note If an erase and a program operations are requested simultaneously, | |||
* the erase operation is performed before the program one. | |||
* | |||
* @param Address: specifies the address to be programmed. | |||
* @param Data: specifies the data to be programmed. | |||
* @retval None | |||
*/ | |||
static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_FLASH_ADDRESS(Address)); | |||
/* If the previous operation is completed, proceed to program the new data */ | |||
FLASH->CR &= CR_PSIZE_MASK; | |||
FLASH->CR |= FLASH_PSIZE_DOUBLE_WORD; | |||
FLASH->CR |= FLASH_CR_PG; | |||
*(__IO uint64_t*)Address = Data; | |||
/* Data synchronous Barrier (DSB) Just after the write operation | |||
This will force the CPU to respect the sequence of instruction (no optimization).*/ | |||
__DSB(); | |||
} | |||
/** | |||
* @brief Program word (32-bit) at a specified address. | |||
* @note This function must be used when the device voltage range is from | |||
* 2.7V to 3.6V. | |||
* | |||
* @note If an erase and a program operations are requested simultaneously, | |||
* the erase operation is performed before the program one. | |||
* | |||
* @param Address: specifies the address to be programmed. | |||
* @param Data: specifies the data to be programmed. | |||
* @retval None | |||
*/ | |||
static void FLASH_Program_Word(uint32_t Address, uint32_t Data) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_FLASH_ADDRESS(Address)); | |||
/* If the previous operation is completed, proceed to program the new data */ | |||
FLASH->CR &= CR_PSIZE_MASK; | |||
FLASH->CR |= FLASH_PSIZE_WORD; | |||
FLASH->CR |= FLASH_CR_PG; | |||
*(__IO uint32_t*)Address = Data; | |||
/* Data synchronous Barrier (DSB) Just after the write operation | |||
This will force the CPU to respect the sequence of instruction (no optimization).*/ | |||
__DSB(); | |||
} | |||
/** | |||
* @brief Program a half-word (16-bit) at a specified address. | |||
* @note This function must be used when the device voltage range is from | |||
* 2.7V to 3.6V. | |||
* | |||
* @note If an erase and a program operations are requested simultaneously, | |||
* the erase operation is performed before the program one. | |||
* | |||
* @param Address: specifies the address to be programmed. | |||
* @param Data: specifies the data to be programmed. | |||
* @retval None | |||
*/ | |||
static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_FLASH_ADDRESS(Address)); | |||
/* If the previous operation is completed, proceed to program the new data */ | |||
FLASH->CR &= CR_PSIZE_MASK; | |||
FLASH->CR |= FLASH_PSIZE_HALF_WORD; | |||
FLASH->CR |= FLASH_CR_PG; | |||
*(__IO uint16_t*)Address = Data; | |||
/* Data synchronous Barrier (DSB) Just after the write operation | |||
This will force the CPU to respect the sequence of instruction (no optimization).*/ | |||
__DSB(); | |||
} | |||
/** | |||
* @brief Program byte (8-bit) at a specified address. | |||
* @note This function must be used when the device voltage range is from | |||
* 2.7V to 3.6V. | |||
* | |||
* @note If an erase and a program operations are requested simultaneously, | |||
* the erase operation is performed before the program one. | |||
* | |||
* @param Address: specifies the address to be programmed. | |||
* @param Data: specifies the data to be programmed. | |||
* @retval None | |||
*/ | |||
static void FLASH_Program_Byte(uint32_t Address, uint8_t Data) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_FLASH_ADDRESS(Address)); | |||
/* If the previous operation is completed, proceed to program the new data */ | |||
FLASH->CR &= CR_PSIZE_MASK; | |||
FLASH->CR |= FLASH_PSIZE_BYTE; | |||
FLASH->CR |= FLASH_CR_PG; | |||
*(__IO uint8_t*)Address = Data; | |||
/* Data synchronous Barrier (DSB) Just after the write operation | |||
This will force the CPU to respect the sequence of instruction (no optimization).*/ | |||
__DSB(); | |||
} | |||
/** | |||
* @brief Set the specific FLASH error flag. | |||
* @retval None | |||
*/ | |||
static void FLASH_SetErrorCode(void) | |||
{ | |||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) != RESET) | |||
{ | |||
pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP; | |||
} | |||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR) != RESET) | |||
{ | |||
pFlash.ErrorCode |= HAL_FLASH_ERROR_PGA; | |||
} | |||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGPERR) != RESET) | |||
{ | |||
pFlash.ErrorCode |= HAL_FLASH_ERROR_PGP; | |||
} | |||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_ERSERR) != RESET) | |||
{ | |||
pFlash.ErrorCode |= HAL_FLASH_ERROR_ERS; | |||
} | |||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPERR) != RESET) | |||
{ | |||
pFlash.ErrorCode |= HAL_FLASH_ERROR_OPERATION; | |||
} | |||
} | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_FLASH_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,817 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_flash_ex.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Extended FLASH HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities of the FLASH extension peripheral: | |||
* + Extended programming operations functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### Flash Extension features ##### | |||
============================================================================== | |||
[..] Comparing to other previous devices, the FLASH interface for STM32F727xx/437xx and | |||
devices contains the following additional features | |||
(+) Capacity up to 2 Mbyte with dual bank architecture supporting read-while-write | |||
capability (RWW) | |||
(+) Dual bank memory organization | |||
(+) PCROP protection for all banks | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] This driver provides functions to configure and program the FLASH memory | |||
of all STM32F7xx devices. It includes | |||
(#) FLASH Memory Erase functions: | |||
(++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and | |||
HAL_FLASH_Lock() functions | |||
(++) Erase function: Erase sector, erase all sectors | |||
(++) There are two modes of erase : | |||
(+++) Polling Mode using HAL_FLASHEx_Erase() | |||
(+++) Interrupt Mode using HAL_FLASHEx_Erase_IT() | |||
(#) Option Bytes Programming functions: Use HAL_FLASHEx_OBProgram() to : | |||
(++) Set/Reset the write protection | |||
(++) Set the Read protection Level | |||
(++) Set the BOR level | |||
(++) Program the user Option Bytes | |||
(#) Advanced Option Bytes Programming functions: Use HAL_FLASHEx_AdvOBProgram() to : | |||
(++) Extended space (bank 2) erase function | |||
(++) Full FLASH space (2 Mo) erase (bank 1 and bank 2) | |||
(++) Dual Boot activation | |||
(++) Write protection configuration for bank 2 | |||
(++) PCROP protection configuration and control for both banks | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup FLASHEx FLASHEx | |||
* @brief FLASH HAL Extension module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_FLASH_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/** @addtogroup FLASHEx_Private_Constants | |||
* @{ | |||
*/ | |||
#define SECTOR_MASK ((uint32_t)0xFFFFFF07) | |||
#define FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/** @addtogroup FLASHEx_Private_Variables | |||
* @{ | |||
*/ | |||
extern FLASH_ProcessTypeDef pFlash; | |||
/** | |||
* @} | |||
*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/** @addtogroup FLASHEx_Private_Functions | |||
* @{ | |||
*/ | |||
/* Option bytes control */ | |||
static void FLASH_MassErase(uint8_t VoltageRange); | |||
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector); | |||
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector); | |||
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint32_t Level); | |||
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t Wwdg, uint32_t Iwdg, uint32_t Stop, uint32_t Stdby, uint32_t Iwdgstop, uint32_t Iwdgstdby); | |||
static HAL_StatusTypeDef FLASH_OB_BOR_LevelConfig(uint8_t Level); | |||
static HAL_StatusTypeDef FLASH_OB_BootAddressConfig(uint32_t BootOption, uint32_t Address); | |||
static uint32_t FLASH_OB_GetUser(void); | |||
static uint32_t FLASH_OB_GetWRP(void); | |||
static uint8_t FLASH_OB_GetRDP(void); | |||
static uint32_t FLASH_OB_GetBOR(void); | |||
static uint32_t FLASH_OB_GetBootAddress(uint32_t BootOption); | |||
extern HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup FLASHEx_Exported_Functions_Group1 Extended IO operation functions | |||
* @brief Extended IO operation functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Extended programming operation functions ##### | |||
=============================================================================== | |||
[..] | |||
This subsection provides a set of functions allowing to manage the Extension FLASH | |||
programming operations Operations. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Perform a mass erase or erase the specified FLASH memory sectors | |||
* @param[in] pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that | |||
* contains the configuration information for the erasing. | |||
* | |||
* @param[out] SectorError: pointer to variable that | |||
* contains the configuration information on faulty sector in case of error | |||
* (0xFFFFFFFF means that all the sectors have been correctly erased) | |||
* | |||
* @retval HAL Status | |||
*/ | |||
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError) | |||
{ | |||
HAL_StatusTypeDef status = HAL_ERROR; | |||
uint32_t index = 0; | |||
/* Process Locked */ | |||
__HAL_LOCK(&pFlash); | |||
/* Check the parameters */ | |||
assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); | |||
/* Wait for last operation to be completed */ | |||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); | |||
if(status == HAL_OK) | |||
{ | |||
/*Initialization of SectorError variable*/ | |||
*SectorError = 0xFFFFFFFF; | |||
if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) | |||
{ | |||
/*Mass erase to be done*/ | |||
FLASH_MassErase((uint8_t) pEraseInit->VoltageRange); | |||
/* 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 */ | |||
FLASH->CR &= (~FLASH_MER_BIT); | |||
} | |||
else | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_FLASH_NBSECTORS(pEraseInit->NbSectors + pEraseInit->Sector)); | |||
/* Erase by sector by sector to be done*/ | |||
for(index = pEraseInit->Sector; index < (pEraseInit->NbSectors + pEraseInit->Sector); index++) | |||
{ | |||
FLASH_Erase_Sector(index, (uint8_t) pEraseInit->VoltageRange); | |||
/* Wait for last operation to be completed */ | |||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); | |||
/* If the erase operation is completed, disable the SER Bit */ | |||
FLASH->CR &= (~FLASH_CR_SER); | |||
FLASH->CR &= SECTOR_MASK; | |||
if(status != HAL_OK) | |||
{ | |||
/* In case of error, stop erase procedure and return the faulty sector*/ | |||
*SectorError = index; | |||
break; | |||
} | |||
} | |||
} | |||
} | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(&pFlash); | |||
return status; | |||
} | |||
/** | |||
* @brief Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled | |||
* @param pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that | |||
* contains the configuration information for the erasing. | |||
* | |||
* @retval HAL Status | |||
*/ | |||
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) | |||
{ | |||
HAL_StatusTypeDef status = HAL_OK; | |||
/* Process Locked */ | |||
__HAL_LOCK(&pFlash); | |||
/* Check the parameters */ | |||
assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); | |||
/* Enable End of FLASH Operation interrupt */ | |||
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP); | |||
/* Enable Error source interrupt */ | |||
__HAL_FLASH_ENABLE_IT(FLASH_IT_ERR); | |||
/* Clear pending flags (if any) */ | |||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |\ | |||
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_ERSERR); | |||
if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) | |||
{ | |||
/*Mass erase to be done*/ | |||
pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE; | |||
FLASH_MassErase((uint8_t) pEraseInit->VoltageRange); | |||
} | |||
else | |||
{ | |||
/* Erase by sector to be done*/ | |||
/* Check the parameters */ | |||
assert_param(IS_FLASH_NBSECTORS(pEraseInit->NbSectors + pEraseInit->Sector)); | |||
pFlash.ProcedureOnGoing = FLASH_PROC_SECTERASE; | |||
pFlash.NbSectorsToErase = pEraseInit->NbSectors; | |||
pFlash.Sector = pEraseInit->Sector; | |||
pFlash.VoltageForErase = (uint8_t)pEraseInit->VoltageRange; | |||
/*Erase 1st sector and wait for IT*/ | |||
FLASH_Erase_Sector(pEraseInit->Sector, pEraseInit->VoltageRange); | |||
} | |||
return status; | |||
} | |||
/** | |||
* @brief Program option bytes | |||
* @param pOBInit: pointer to an FLASH_OBInitStruct structure that | |||
* contains the configuration information for the programming. | |||
* | |||
* @retval 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 Sector*/ | |||
status = FLASH_OB_EnableWRP(pOBInit->WRPSector); | |||
} | |||
else | |||
{ | |||
/*Disable of Write protection on the selected Sector*/ | |||
status = FLASH_OB_DisableWRP(pOBInit->WRPSector); | |||
} | |||
} | |||
/* Read protection configuration */ | |||
if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) | |||
{ | |||
status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel); | |||
} | |||
/* USER configuration */ | |||
if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) | |||
{ | |||
status = FLASH_OB_UserConfig(pOBInit->USERConfig & OB_WWDG_SW, | |||
pOBInit->USERConfig & OB_IWDG_SW, | |||
pOBInit->USERConfig & OB_STOP_NO_RST, | |||
pOBInit->USERConfig & OB_STDBY_NO_RST, | |||
pOBInit->USERConfig & OB_IWDG_STOP_ACTIVE, | |||
pOBInit->USERConfig & OB_IWDG_STDBY_ACTIVE); | |||
} | |||
/* BOR Level configuration */ | |||
if((pOBInit->OptionType & OPTIONBYTE_BOR) == OPTIONBYTE_BOR) | |||
{ | |||
status = FLASH_OB_BOR_LevelConfig(pOBInit->BORLevel); | |||
} | |||
/* Boot 0 Address configuration */ | |||
if((pOBInit->OptionType & OPTIONBYTE_BOOTADDR_0) == OPTIONBYTE_BOOTADDR_0) | |||
{ | |||
status = FLASH_OB_BootAddressConfig(OPTIONBYTE_BOOTADDR_0, pOBInit->BootAddr0); | |||
} | |||
/* Boot 1 Address configuration */ | |||
if((pOBInit->OptionType & OPTIONBYTE_BOOTADDR_1) == OPTIONBYTE_BOOTADDR_1) | |||
{ | |||
status = FLASH_OB_BootAddressConfig(OPTIONBYTE_BOOTADDR_1, pOBInit->BootAddr1); | |||
} | |||
/* 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 |\ | |||
OPTIONBYTE_BOR | OPTIONBYTE_BOOTADDR_0 | OPTIONBYTE_BOOTADDR_1; | |||
/*Get WRP*/ | |||
pOBInit->WRPSector = FLASH_OB_GetWRP(); | |||
/*Get RDP Level*/ | |||
pOBInit->RDPLevel = FLASH_OB_GetRDP(); | |||
/*Get USER*/ | |||
pOBInit->USERConfig = FLASH_OB_GetUser(); | |||
/*Get BOR Level*/ | |||
pOBInit->BORLevel = FLASH_OB_GetBOR(); | |||
/*Get Boot Address when Boot pin = 0 */ | |||
pOBInit->BootAddr0 = FLASH_OB_GetBootAddress(OPTIONBYTE_BOOTADDR_0); | |||
/*Get Boot Address when Boot pin = 1 */ | |||
pOBInit->BootAddr1 = FLASH_OB_GetBootAddress(OPTIONBYTE_BOOTADDR_1); | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @brief Full erase of FLASH memory sectors | |||
* @param VoltageRange: The device voltage range which defines the erase parallelism. | |||
* This parameter can be one of the following values: | |||
* @arg VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V, | |||
* the operation will be done by byte (8-bit) | |||
* @arg VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V, | |||
* the operation will be done by half word (16-bit) | |||
* @arg VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V, | |||
* the operation will be done by word (32-bit) | |||
* @arg VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp, | |||
* the operation will be done by double word (64-bit) | |||
* | |||
* @retval HAL Status | |||
*/ | |||
static void FLASH_MassErase(uint8_t VoltageRange) | |||
{ | |||
uint32_t tmp_psize = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_VOLTAGERANGE(VoltageRange)); | |||
/* if the previous operation is completed, proceed to erase all sectors */ | |||
FLASH->CR &= CR_PSIZE_MASK; | |||
FLASH->CR |= tmp_psize; | |||
FLASH->CR |= FLASH_CR_MER; | |||
FLASH->CR |= FLASH_CR_STRT; | |||
/* Data synchronous Barrier (DSB) Just after the write operation | |||
This will force the CPU to respect the sequence of instruction (no optimization).*/ | |||
__DSB(); | |||
} | |||
/** | |||
* @brief Erase the specified FLASH memory sector | |||
* @param Sector: FLASH sector to erase | |||
* The value of this parameter depend on device used within the same series | |||
* @param VoltageRange: The device voltage range which defines the erase parallelism. | |||
* This parameter can be one of the following values: | |||
* @arg FLASH_VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V, | |||
* the operation will be done by byte (8-bit) | |||
* @arg FLASH_VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V, | |||
* the operation will be done by half word (16-bit) | |||
* @arg FLASH_VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V, | |||
* the operation will be done by word (32-bit) | |||
* @arg FLASH_VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp, | |||
* the operation will be done by double word (64-bit) | |||
* | |||
* @retval None | |||
*/ | |||
void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange) | |||
{ | |||
uint32_t tmp_psize = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_FLASH_SECTOR(Sector)); | |||
assert_param(IS_VOLTAGERANGE(VoltageRange)); | |||
if(VoltageRange == FLASH_VOLTAGE_RANGE_1) | |||
{ | |||
tmp_psize = FLASH_PSIZE_BYTE; | |||
} | |||
else if(VoltageRange == FLASH_VOLTAGE_RANGE_2) | |||
{ | |||
tmp_psize = FLASH_PSIZE_HALF_WORD; | |||
} | |||
else if(VoltageRange == FLASH_VOLTAGE_RANGE_3) | |||
{ | |||
tmp_psize = FLASH_PSIZE_WORD; | |||
} | |||
else | |||
{ | |||
tmp_psize = FLASH_PSIZE_DOUBLE_WORD; | |||
} | |||
/* If the previous operation is completed, proceed to erase the sector */ | |||
FLASH->CR &= CR_PSIZE_MASK; | |||
FLASH->CR |= tmp_psize; | |||
FLASH->CR &= SECTOR_MASK; | |||
FLASH->CR |= FLASH_CR_SER | (Sector << POSITION_VAL(FLASH_CR_SNB)); | |||
FLASH->CR |= FLASH_CR_STRT; | |||
/* Data synchronous Barrier (DSB) Just after the write operation | |||
This will force the CPU to respect the sequence of instruction (no optimization).*/ | |||
__DSB(); | |||
} | |||
/** | |||
* @brief Enable the write protection of the desired bank1 or bank 2 sectors | |||
* | |||
* @note When the memory read protection level is selected (RDP level = 1), | |||
* it is not possible to program or erase the flash sector i if CortexM4 | |||
* debug features are connected or boot code is executed in RAM, even if nWRPi = 1 | |||
* @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1). | |||
* | |||
* @param WRPSector: specifies the sector(s) to be write protected. | |||
* This parameter can be one of the following values: | |||
* @arg WRPSector: A value between OB_WRP_SECTOR_0 and OB_WRP_SECTOR_7 | |||
* @arg OB_WRP_SECTOR_All | |||
* | |||
* @retval HAL FLASH State | |||
*/ | |||
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector) | |||
{ | |||
HAL_StatusTypeDef status = HAL_OK; | |||
/* Check the parameters */ | |||
assert_param(IS_OB_WRP_SECTOR(WRPSector)); | |||
/* Wait for last operation to be completed */ | |||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); | |||
if(status == HAL_OK) | |||
{ | |||
/*Write protection enabled on sectors */ | |||
FLASH->OPTCR &= (~WRPSector); | |||
} | |||
return status; | |||
} | |||
/** | |||
* @brief Disable the write protection of the desired bank1 or bank 2 sectors | |||
* | |||
* @note When the memory read protection level is selected (RDP level = 1), | |||
* it is not possible to program or erase the flash sector i if CortexM4 | |||
* debug features are connected or boot code is executed in RAM, even if nWRPi = 1 | |||
* | |||
* @param WRPSector: specifies the sector(s) to be write protected. | |||
* This parameter can be one of the following values: | |||
* @arg WRPSector: A value between OB_WRP_SECTOR_0 and OB_WRP_SECTOR_7 | |||
* @arg OB_WRP_Sector_All | |||
* | |||
* | |||
* @retval HAL Status | |||
*/ | |||
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector) | |||
{ | |||
HAL_StatusTypeDef status = HAL_OK; | |||
/* Check the parameters */ | |||
assert_param(IS_OB_WRP_SECTOR(WRPSector)); | |||
/* Wait for last operation to be completed */ | |||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); | |||
if(status == HAL_OK) | |||
{ | |||
/* Write protection disabled on sectors */ | |||
FLASH->OPTCR |= (WRPSector); | |||
} | |||
return status; | |||
} | |||
/** | |||
* @brief Set the read protection level. | |||
* @param Level: specifies the read protection level. | |||
* This parameter can be one of the following values: | |||
* @arg OB_RDP_LEVEL_0: No protection | |||
* @arg OB_RDP_LEVEL_1: Read protection of the memory | |||
* @arg 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(uint32_t Level) | |||
{ | |||
HAL_StatusTypeDef status = HAL_OK; | |||
/* Check the parameters */ | |||
assert_param(IS_OB_RDP_LEVEL(Level)); | |||
/* Wait for last operation to be completed */ | |||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); | |||
if(status == HAL_OK) | |||
{ | |||
MODIFY_REG(FLASH->OPTCR, FLASH_OPTCR_RDP, Level); | |||
} | |||
return status; | |||
} | |||
/** | |||
* @brief Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY. | |||
* @param Wwdg: Selects the IWDG mode | |||
* This parameter can be one of the following values: | |||
* @arg OB_WWDG_SW: Software WWDG selected | |||
* @arg OB_WWDG_HW: Hardware WWDG selected | |||
* @param Iwdg: Selects the WWDG mode | |||
* This parameter can be one of the following values: | |||
* @arg OB_IWDG_SW: Software IWDG selected | |||
* @arg OB_IWDG_HW: Hardware IWDG selected | |||
* @param Stop: Reset event when entering STOP mode. | |||
* This parameter can be one of the following values: | |||
* @arg OB_STOP_NO_RST: No reset generated when entering in STOP | |||
* @arg OB_STOP_RST: Reset generated when entering in STOP | |||
* @param Stdby: Reset event when entering Standby mode. | |||
* This parameter can be one of the following values: | |||
* @arg OB_STDBY_NO_RST: No reset generated when entering in STANDBY | |||
* @arg OB_STDBY_RST: Reset generated when entering in STANDBY | |||
* @param Iwdgstop: Independent watchdog counter freeze in Stop mode. | |||
* This parameter can be one of the following values: | |||
* @arg OB_IWDG_STOP_FREEZE: Freeze IWDG counter in STOP | |||
* @arg OB_IWDG_STOP_ACTIVE: IWDG counter active in STOP | |||
* @param Iwdgstdby: Independent watchdog counter freeze in standby mode. | |||
* This parameter can be one of the following values: | |||
* @arg OB_IWDG_STDBY_FREEZE: Freeze IWDG counter in STANDBY | |||
* @arg OB_IWDG_STDBY_ACTIVE: IWDG counter active in STANDBY | |||
* @retval HAL Status | |||
*/ | |||
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t Wwdg, uint32_t Iwdg, uint32_t Stop, uint32_t Stdby, uint32_t Iwdgstop, uint32_t Iwdgstdby ) | |||
{ | |||
uint32_t useroptionmask = 0x00; | |||
uint32_t useroptionvalue = 0x00; | |||
HAL_StatusTypeDef status = HAL_OK; | |||
/* Check the parameters */ | |||
assert_param(IS_OB_WWDG_SOURCE(Wwdg)); | |||
assert_param(IS_OB_IWDG_SOURCE(Iwdg)); | |||
assert_param(IS_OB_STOP_SOURCE(Stop)); | |||
assert_param(IS_OB_STDBY_SOURCE(Stdby)); | |||
assert_param(IS_OB_IWDG_STOP_FREEZE(Iwdgstop)); | |||
assert_param(IS_OB_IWDG_STDBY_FREEZE(Iwdgstdby)); | |||
/* Wait for last operation to be completed */ | |||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); | |||
if(status == HAL_OK) | |||
{ | |||
useroptionmask = (FLASH_OPTCR_WWDG_SW | FLASH_OPTCR_IWDG_SW | FLASH_OPTCR_nRST_STOP | \ | |||
FLASH_OPTCR_nRST_STDBY | FLASH_OPTCR_IWDG_STOP | FLASH_OPTCR_IWDG_STDBY); | |||
useroptionvalue = (Iwdg | Wwdg | Stop | Stdby | Iwdgstop | Iwdgstdby); | |||
/* Update User Option Byte */ | |||
MODIFY_REG(FLASH->OPTCR, useroptionmask, useroptionvalue); | |||
} | |||
return status; | |||
} | |||
/** | |||
* @brief Set the BOR Level. | |||
* @param Level: specifies the Option Bytes BOR Reset Level. | |||
* This parameter can be one of the following values: | |||
* @arg OB_BOR_LEVEL3: Supply voltage ranges from 2.7 to 3.6 V | |||
* @arg OB_BOR_LEVEL2: Supply voltage ranges from 2.4 to 2.7 V | |||
* @arg OB_BOR_LEVEL1: Supply voltage ranges from 2.1 to 2.4 V | |||
* @arg OB_BOR_OFF: Supply voltage ranges from 1.62 to 2.1 V | |||
* @retval HAL Status | |||
*/ | |||
static HAL_StatusTypeDef FLASH_OB_BOR_LevelConfig(uint8_t Level) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_OB_BOR_LEVEL(Level)); | |||
/* Set the BOR Level */ | |||
MODIFY_REG(FLASH->OPTCR, FLASH_OPTCR_BOR_LEV, Level); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Configure Boot base address. | |||
* | |||
* @param BootOption : specifies Boot base address depending from Boot pin = 0 or pin = 1 | |||
* This parameter can be one of the following values: | |||
* @arg OPTIONBYTE_BOOTADDR_0 : Boot address based when Boot pin = 0 | |||
* @arg OPTIONBYTE_BOOTADDR_1 : Boot address based when Boot pin = 1 | |||
* @param Address: specifies Boot base address | |||
* This parameter can be one of the following values: | |||
* @arg OB_BOOTADDR_ITCM_RAM : Boot from ITCM RAM (0x00000000) | |||
* @arg OB_BOOTADDR_SYSTEM : Boot from System memory bootloader (0x00100000) | |||
* @arg OB_BOOTADDR_ITCM_FLASH : Boot from Flash on ITCM interface (0x00200000) | |||
* @arg OB_BOOTADDR_AXIM_FLASH : Boot from Flash on AXIM interface (0x08000000) | |||
* @arg OB_BOOTADDR_DTCM_RAM : Boot from DTCM RAM (0x20000000) | |||
* @arg OB_BOOTADDR_SRAM1 : Boot from SRAM1 (0x20010000) | |||
* @arg OB_BOOTADDR_SRAM2 : Boot from SRAM2 (0x2004C000) | |||
* | |||
* @retval HAL Status | |||
*/ | |||
static HAL_StatusTypeDef FLASH_OB_BootAddressConfig(uint32_t BootOption, uint32_t Address) | |||
{ | |||
HAL_StatusTypeDef status = HAL_OK; | |||
/* Check the parameters */ | |||
assert_param(IS_OB_BOOT_ADDRESS(Address)); | |||
/* Wait for last operation to be completed */ | |||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); | |||
if(status == HAL_OK) | |||
{ | |||
if(BootOption == OPTIONBYTE_BOOTADDR_0) | |||
{ | |||
MODIFY_REG(FLASH->OPTCR1, FLASH_OPTCR1_BOOT_ADD0, Address); | |||
} | |||
else | |||
{ | |||
MODIFY_REG(FLASH->OPTCR1, FLASH_OPTCR1_BOOT_ADD1, (Address << 16)); | |||
} | |||
} | |||
return status; | |||
} | |||
/** | |||
* @brief Return the FLASH User Option Byte value. | |||
* @retval uint32_t FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1) | |||
* and RST_STDBY(Bit2). | |||
*/ | |||
static uint32_t FLASH_OB_GetUser(void) | |||
{ | |||
/* Return the User Option Byte */ | |||
return ((uint32_t)(FLASH->OPTCR & 0xC00000F0)); | |||
} | |||
/** | |||
* @brief Return the FLASH Write Protection Option Bytes value. | |||
* @retval uint32_t FLASH Write Protection Option Bytes value | |||
*/ | |||
static uint32_t FLASH_OB_GetWRP(void) | |||
{ | |||
/* Return the FLASH write protection Register value */ | |||
return ((uint32_t)(FLASH->OPTCR & 0x00FF0000)); | |||
} | |||
/** | |||
* @brief Returns the FLASH Read Protection level. | |||
* @retval FlagStatus FLASH ReadOut Protection Status: | |||
* This parameter can be one of the following values: | |||
* @arg OB_RDP_LEVEL_0: No protection | |||
* @arg OB_RDP_LEVEL_1: Read protection of the memory | |||
* @arg OB_RDP_LEVEL_2: Full chip protection | |||
*/ | |||
static uint8_t FLASH_OB_GetRDP(void) | |||
{ | |||
uint8_t readstatus = OB_RDP_LEVEL_0; | |||
if (((FLASH->OPTCR & FLASH_OPTCR_RDP) >> 8) == OB_RDP_LEVEL_0) | |||
{ | |||
readstatus = OB_RDP_LEVEL_0; | |||
} | |||
else if (((FLASH->OPTCR & FLASH_OPTCR_RDP) >> 8) == OB_RDP_LEVEL_2) | |||
{ | |||
readstatus = OB_RDP_LEVEL_2; | |||
} | |||
else | |||
{ | |||
readstatus = OB_RDP_LEVEL_1; | |||
} | |||
return readstatus; | |||
} | |||
/** | |||
* @brief Returns the FLASH BOR level. | |||
* @retval uint32_t The FLASH BOR level: | |||
* - OB_BOR_LEVEL3: Supply voltage ranges from 2.7 to 3.6 V | |||
* - OB_BOR_LEVEL2: Supply voltage ranges from 2.4 to 2.7 V | |||
* - OB_BOR_LEVEL1: Supply voltage ranges from 2.1 to 2.4 V | |||
* - OB_BOR_OFF : Supply voltage ranges from 1.62 to 2.1 V | |||
*/ | |||
static uint32_t FLASH_OB_GetBOR(void) | |||
{ | |||
/* Return the FLASH BOR level */ | |||
return ((uint32_t)(FLASH->OPTCR & 0x0C)); | |||
} | |||
/** | |||
* @brief Configure Boot base address. | |||
* | |||
* @param BootOption : specifies Boot base address depending from Boot pin = 0 or pin = 1 | |||
* This parameter can be one of the following values: | |||
* @arg OPTIONBYTE_BOOTADDR_0 : Boot address based when Boot pin = 0 | |||
* @arg OPTIONBYTE_BOOTADDR_1 : Boot address based when Boot pin = 1 | |||
* | |||
* @retval uint32_t Boot Base Address: | |||
* - OB_BOOTADDR_ITCM_RAM : Boot from ITCM RAM (0x00000000) | |||
* - OB_BOOTADDR_SYSTEM : Boot from System memory bootloader (0x00100000) | |||
* - OB_BOOTADDR_ITCM_FLASH : Boot from Flash on ITCM interface (0x00200000) | |||
* - OB_BOOTADDR_AXIM_FLASH : Boot from Flash on AXIM interface (0x08000000) | |||
* - OB_BOOTADDR_DTCM_RAM : Boot from DTCM RAM (0x20000000) | |||
* - OB_BOOTADDR_SRAM1 : Boot from SRAM1 (0x20010000) | |||
* - OB_BOOTADDR_SRAM2 : Boot from SRAM2 (0x2004C000) | |||
*/ | |||
static uint32_t FLASH_OB_GetBootAddress(uint32_t BootOption) | |||
{ | |||
uint32_t Address = 0; | |||
/* Return the Boot base Address */ | |||
if(BootOption == OPTIONBYTE_BOOTADDR_0) | |||
{ | |||
Address = FLASH->OPTCR1 & FLASH_OPTCR1_BOOT_ADD0; | |||
} | |||
else | |||
{ | |||
Address = ((FLASH->OPTCR1 & FLASH_OPTCR1_BOOT_ADD1) >> 16); | |||
} | |||
return Address; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_FLASH_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,540 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_gpio.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @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 | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### GPIO Peripheral features ##### | |||
============================================================================== | |||
[..] | |||
Subject to the specific hardware characteristics of each I/O port listed in the datasheet, each | |||
port bit of the General Purpose IO (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. | |||
[..] | |||
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 PC15, 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 PH0 and PH1, respectively, when the HSE oscillator is off. | |||
The HSE has priority over the GPIO function. | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup GPIO GPIO | |||
* @brief GPIO HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_GPIO_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/** @addtogroup GPIO_Private_Constants GPIO Private Constants | |||
* @{ | |||
*/ | |||
#define GPIO_MODE ((uint32_t)0x00000003) | |||
#define EXTI_MODE ((uint32_t)0x10000000) | |||
#define GPIO_MODE_IT ((uint32_t)0x00010000) | |||
#define GPIO_MODE_EVT ((uint32_t)0x00020000) | |||
#define RISING_EDGE ((uint32_t)0x00100000) | |||
#define FALLING_EDGE ((uint32_t)0x00200000) | |||
#define GPIO_OUTPUT_TYPE ((uint32_t)0x00000010) | |||
#define GPIO_NUMBER ((uint32_t)16) | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup GPIO_Exported_Functions GPIO Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup GPIO_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @brief Initialization and Configuration functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Initialization and de-initialization functions ##### | |||
=============================================================================== | |||
[..] | |||
This section provides functions allowing to initialize and de-initialize the GPIOs | |||
to be ready for use. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init. | |||
* @param GPIOx: where x can be (A..K) to select the GPIO peripheral. | |||
* @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 = 0x00; | |||
uint32_t ioposition = 0x00; | |||
uint32_t iocurrent = 0x00; | |||
uint32_t temp = 0x00; | |||
/* 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)); | |||
assert_param(IS_GPIO_PULL(GPIO_Init->Pull)); | |||
/* Configure the port pins */ | |||
for(position = 0; position < GPIO_NUMBER; position++) | |||
{ | |||
/* Get the IO position */ | |||
ioposition = ((uint32_t)0x01) << position; | |||
/* Get the current IO position */ | |||
iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition; | |||
if(iocurrent == ioposition) | |||
{ | |||
/*--------------------- GPIO Mode Configuration ------------------------*/ | |||
/* In case of Alternate function mode selection */ | |||
if((GPIO_Init->Mode == GPIO_MODE_AF_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_OD)) | |||
{ | |||
/* Check the Alternate function parameter */ | |||
assert_param(IS_GPIO_AF(GPIO_Init->Alternate)); | |||
/* Configure Alternate function mapped with the current IO */ | |||
temp = GPIOx->AFR[position >> 3]; | |||
temp &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ; | |||
temp |= ((uint32_t)(GPIO_Init->Alternate) << (((uint32_t)position & (uint32_t)0x07) * 4)); | |||
GPIOx->AFR[position >> 3] = temp; | |||
} | |||
/* Configure IO Direction mode (Input, Output, Alternate or Analog) */ | |||
temp = GPIOx->MODER; | |||
temp &= ~(GPIO_MODER_MODER0 << (position * 2)); | |||
temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2)); | |||
GPIOx->MODER = temp; | |||
/* In case of Output or Alternate function mode selection */ | |||
if((GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_PP) || | |||
(GPIO_Init->Mode == GPIO_MODE_OUTPUT_OD) || (GPIO_Init->Mode == GPIO_MODE_AF_OD)) | |||
{ | |||
/* Check the Speed parameter */ | |||
assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); | |||
/* Configure the IO Speed */ | |||
temp = GPIOx->OSPEEDR; | |||
temp &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2)); | |||
temp |= (GPIO_Init->Speed << (position * 2)); | |||
GPIOx->OSPEEDR = temp; | |||
/* Configure the IO Output Type */ | |||
temp = GPIOx->OTYPER; | |||
temp &= ~(GPIO_OTYPER_OT_0 << position) ; | |||
temp |= (((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4) << position); | |||
GPIOx->OTYPER = temp; | |||
} | |||
/* Activate the Pull-up or Pull down resistor for the current IO */ | |||
temp = GPIOx->PUPDR; | |||
temp &= ~(GPIO_PUPDR_PUPDR0 << (position * 2)); | |||
temp |= ((GPIO_Init->Pull) << (position * 2)); | |||
GPIOx->PUPDR = temp; | |||
/*--------------------- EXTI Mode Configuration ------------------------*/ | |||
/* Configure the External Interrupt or event for the current IO */ | |||
if((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE) | |||
{ | |||
/* Enable SYSCFG Clock */ | |||
__HAL_RCC_SYSCFG_CLK_ENABLE(); | |||
temp = SYSCFG->EXTICR[position >> 2]; | |||
temp &= ~(((uint32_t)0x0F) << (4 * (position & 0x03))); | |||
temp |= ((uint32_t)(GPIO_GET_INDEX(GPIOx)) << (4 * (position & 0x03))); | |||
SYSCFG->EXTICR[position >> 2] = temp; | |||
/* Clear EXTI line configuration */ | |||
temp = EXTI->IMR; | |||
temp &= ~((uint32_t)iocurrent); | |||
if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT) | |||
{ | |||
temp |= iocurrent; | |||
} | |||
EXTI->IMR = temp; | |||
temp = EXTI->EMR; | |||
temp &= ~((uint32_t)iocurrent); | |||
if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT) | |||
{ | |||
temp |= iocurrent; | |||
} | |||
EXTI->EMR = temp; | |||
/* Clear Rising Falling edge configuration */ | |||
temp = EXTI->RTSR; | |||
temp &= ~((uint32_t)iocurrent); | |||
if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE) | |||
{ | |||
temp |= iocurrent; | |||
} | |||
EXTI->RTSR = temp; | |||
temp = EXTI->FTSR; | |||
temp &= ~((uint32_t)iocurrent); | |||
if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE) | |||
{ | |||
temp |= iocurrent; | |||
} | |||
EXTI->FTSR = temp; | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* @brief De-initializes the GPIOx peripheral registers to their default reset values. | |||
* @param GPIOx: where x can be (A..K) to select the GPIO peripheral. | |||
* @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; | |||
uint32_t ioposition = 0x00; | |||
uint32_t iocurrent = 0x00; | |||
uint32_t tmp = 0x00; | |||
/* Check the parameters */ | |||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); | |||
/* Configure the port pins */ | |||
for(position = 0; position < GPIO_NUMBER; position++) | |||
{ | |||
/* Get the IO position */ | |||
ioposition = ((uint32_t)0x01) << position; | |||
/* Get the current IO position */ | |||
iocurrent = (GPIO_Pin) & ioposition; | |||
if(iocurrent == ioposition) | |||
{ | |||
/*------------------------- GPIO Mode Configuration --------------------*/ | |||
/* Configure IO Direction in Input Floating Mode */ | |||
GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (position * 2)); | |||
/* Configure the default Alternate Function in current IO */ | |||
GPIOx->AFR[position >> 3] &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ; | |||
/* Configure the default value for IO Speed */ | |||
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2)); | |||
/* Configure the default value IO Output Type */ | |||
GPIOx->OTYPER &= ~(GPIO_OTYPER_OT_0 << position) ; | |||
/* Deactivate the Pull-up and Pull-down resistor for the current IO */ | |||
GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << (position * 2)); | |||
/*------------------------- EXTI Mode Configuration --------------------*/ | |||
tmp = SYSCFG->EXTICR[position >> 2]; | |||
tmp &= (((uint32_t)0x0F) << (4 * (position & 0x03))); | |||
if(tmp == ((uint32_t)(GPIO_GET_INDEX(GPIOx)) << (4 * (position & 0x03)))) | |||
{ | |||
/* Configure the External Interrupt or event for the current IO */ | |||
tmp = ((uint32_t)0x0F) << (4 * (position & 0x03)); | |||
SYSCFG->EXTICR[position >> 2] &= ~tmp; | |||
/* Clear EXTI line configuration */ | |||
EXTI->IMR &= ~((uint32_t)iocurrent); | |||
EXTI->EMR &= ~((uint32_t)iocurrent); | |||
/* Clear Rising Falling edge configuration */ | |||
EXTI->RTSR &= ~((uint32_t)iocurrent); | |||
EXTI->FTSR &= ~((uint32_t)iocurrent); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup GPIO_Exported_Functions_Group2 IO operation functions | |||
* @brief GPIO Read and Write | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### IO operation functions ##### | |||
=============================================================================== | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Reads the specified input port pin. | |||
* @param GPIOx: where x can be (A..K) to select the GPIO peripheral. | |||
* @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 Sets or clears the selected data port bit. | |||
* | |||
* @note This function uses GPIOx_BSRR register 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..K) to select the GPIO peripheral. | |||
* @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 = GPIO_Pin; | |||
} | |||
else | |||
{ | |||
GPIOx->BSRR = (uint32_t)GPIO_Pin << 16; | |||
} | |||
} | |||
/** | |||
* @brief Toggles the specified GPIO pins. | |||
* @param GPIOx: Where x can be (A..I) to select the GPIO peripheral. | |||
* @param GPIO_Pin: Specifies the pins to be toggled. | |||
* @retval None | |||
*/ | |||
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_GPIO_PIN(GPIO_Pin)); | |||
GPIOx->ODR ^= GPIO_Pin; | |||
} | |||
/** | |||
* @brief Locks 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 STM32F7 family | |||
* @param GPIO_Pin: specifies the port bit 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_PIN(GPIO_Pin)); | |||
/* Apply lock key write sequence */ | |||
tmp |= GPIO_Pin; | |||
/* Set LCKx bit(s): LCKK='1' + LCK[15-0] */ | |||
GPIOx->LCKR = tmp; | |||
/* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */ | |||
GPIOx->LCKR = GPIO_Pin; | |||
/* Set LCKx bit(s): LCKK='1' + LCK[15-0] */ | |||
GPIOx->LCKR = tmp; | |||
/* Read LCKK bit*/ | |||
tmp = GPIOx->LCKR; | |||
if((GPIOx->LCKR & GPIO_LCKR_LCKK) != RESET) | |||
{ | |||
return HAL_OK; | |||
} | |||
else | |||
{ | |||
return HAL_ERROR; | |||
} | |||
} | |||
/** | |||
* @brief This function handles EXTI interrupt request. | |||
* @param GPIO_Pin: Specifies the pins connected 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) != RESET) | |||
{ | |||
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin); | |||
HAL_GPIO_EXTI_Callback(GPIO_Pin); | |||
} | |||
} | |||
/** | |||
* @brief EXTI line detection callbacks. | |||
* @param GPIO_Pin: Specifies the pins connected EXTI line | |||
* @retval None | |||
*/ | |||
__weak void HAL_GPIO_EXTI_Callback(uint16_t 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 */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,197 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_pcd_ex.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief PCD HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities of the USB Peripheral Controller: | |||
* + Extended features functions | |||
* | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup PCDEx PCDEx | |||
* @brief PCD Extended HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_PCD_MODULE_ENABLED | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions | |||
* @brief PCDEx control functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Extended features functions ##### | |||
=============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Update FIFO configuration | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Set Tx FIFO | |||
* @param hpcd: PCD handle | |||
* @param fifo: The number of Tx fifo | |||
* @param size: Fifo size | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size) | |||
{ | |||
uint8_t i = 0; | |||
uint32_t Tx_Offset = 0; | |||
/* TXn min size = 16 words. (n : Transmit FIFO index) | |||
When a TxFIFO is not used, the Configuration should be as follows: | |||
case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes) | |||
--> Txm can use the space allocated for Txn. | |||
case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes) | |||
--> Txn should be configured with the minimum space of 16 words | |||
The FIFO is used optimally when used TxFIFOs are allocated in the top | |||
of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones. | |||
When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */ | |||
Tx_Offset = hpcd->Instance->GRXFSIZ; | |||
if(fifo == 0) | |||
{ | |||
hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (size << 16) | Tx_Offset; | |||
} | |||
else | |||
{ | |||
Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16; | |||
for (i = 0; i < (fifo - 1); i++) | |||
{ | |||
Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16); | |||
} | |||
/* Multiply Tx_Size by 2 to get higher performance */ | |||
hpcd->Instance->DIEPTXF[fifo - 1] = (size << 16) | Tx_Offset; | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Set Rx FIFO | |||
* @param hpcd: PCD handle | |||
* @param size: Size of Rx fifo | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size) | |||
{ | |||
hpcd->Instance->GRXFSIZ = size; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief HAL_PCDEx_ActivateLPM : active LPM Feature | |||
* @param hpcd: PCD handle | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd) | |||
{ | |||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; | |||
hpcd->lpm_active = ENABLE; | |||
hpcd->LPM_State = LPM_L0; | |||
USBx->GINTMSK |= USB_OTG_GINTMSK_LPMINTM; | |||
USBx->GLPMCFG |= (USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief HAL_PCDEx_DeActivateLPM : de-active LPM feature | |||
* @param hpcd: PCD handle | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd) | |||
{ | |||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; | |||
hpcd->lpm_active = DISABLE; | |||
USBx->GINTMSK &= ~USB_OTG_GINTMSK_LPMINTM; | |||
USBx->GLPMCFG &= ~(USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief HAL_PCDEx_LPM_Callback : Send LPM message to user layer | |||
* @param hpcd: PCD handle | |||
* @param msg: LPM message | |||
* @retval HAL status | |||
*/ | |||
__weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) | |||
{ | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_PCD_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,609 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_pwr.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief PWR HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities of the Power Controller (PWR) peripheral: | |||
* + Initialization and de-initialization functions | |||
* + Peripheral Control functions | |||
* | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup PWR PWR | |||
* @brief PWR HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_PWR_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/** @addtogroup PWR_Private_Constants | |||
* @{ | |||
*/ | |||
/** @defgroup PWR_PVD_Mode_Mask PWR PVD Mode Mask | |||
* @{ | |||
*/ | |||
#define PVD_MODE_IT ((uint32_t)0x00010000) | |||
#define PVD_MODE_EVT ((uint32_t)0x00020000) | |||
#define PVD_RISING_EDGE ((uint32_t)0x00000001) | |||
#define PVD_FALLING_EDGE ((uint32_t)0x00000002) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_ENABLE_WUP_Mask PWR Enable WUP Mask | |||
* @{ | |||
*/ | |||
#define PWR_EWUP_MASK ((uint32_t)0x00003F00) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* 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 HAL 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 2, 3, ..31 is used as the RTC clock, the | |||
* Backup Domain Access should be kept enabled. | |||
* @retval None | |||
*/ | |||
void HAL_PWR_EnableBkUpAccess(void) | |||
{ | |||
/* Enable access to RTC and backup registers */ | |||
SET_BIT(PWR->CR1, PWR_CR1_DBP); | |||
} | |||
/** | |||
* @brief Disables access to the backup domain (RTC registers, RTC | |||
* backup data registers and backup SRAM). | |||
* @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the | |||
* Backup Domain Access should be kept enabled. | |||
* @retval None | |||
*/ | |||
void HAL_PWR_DisableBkUpAccess(void) | |||
{ | |||
/* Disable access to RTC and backup registers */ | |||
CLEAR_BIT(PWR->CR1, PWR_CR1_DBP); | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions | |||
* @brief Low Power modes configuration functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Peripheral Control functions ##### | |||
=============================================================================== | |||
*** PVD configuration *** | |||
========================= | |||
[..] | |||
(+) 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. | |||
*** Wake-up pin configuration *** | |||
================================ | |||
[..] | |||
(+) Wake-up pin is used to wake up the system from Standby mode. This pin is | |||
forced in input pull-down configuration and is active on rising edges. | |||
(+) There are to 6 Wake-up pin in the STM32F7 devices family | |||
*** Low Power modes configuration *** | |||
===================================== | |||
[..] | |||
The devices feature 3 low-power modes: | |||
(+) Sleep mode: Cortex-M7 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. | |||
*** Sleep mode *** | |||
================== | |||
[..] | |||
(+) Entry: | |||
The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI) | |||
functions with | |||
(++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction | |||
(++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction | |||
-@@- The Regulator parameter is not used for the STM32F7 family | |||
and is kept as parameter just to maintain compatibility with the | |||
lower power families (STM32L). | |||
(+) 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.2V 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 In Stop mode, FLASH can be powered off before | |||
entering the Stop mode using the HAL_PWREx_EnableFlashPowerDown() function. | |||
It can be switched on again by software after exiting the Stop mode using | |||
the HAL_PWREx_DisableFlashPowerDown() function. | |||
(+) Entry: | |||
The Stop mode is entered using the HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON) | |||
function with: | |||
(++) Main regulator ON. | |||
(++) Low Power regulator ON. | |||
(+) Exit: | |||
Any EXTI Line (Internal or External) configured in Interrupt/Event mode. | |||
*** Standby mode *** | |||
==================== | |||
[..] | |||
(+) | |||
The Standby mode allows to achieve the lowest power consumption. It is based | |||
on the Cortex-M7 deep sleep mode, with the voltage regulator disabled. | |||
The 1.2V 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 or falling 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 or a time-stamp 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_RTCEx_SetTimeStamp_IT() or HAL_RTCEx_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_RTCEx_SetWakeUpTimer_IT() function. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @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->CR1, PWR_CR1_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) | |||
{ | |||
/* Enable the power voltage detector */ | |||
SET_BIT(PWR->CR1, PWR_CR1_PVDE); | |||
} | |||
/** | |||
* @brief Disables the Power Voltage Detector(PVD). | |||
* @retval None | |||
*/ | |||
void HAL_PWR_DisablePVD(void) | |||
{ | |||
/* Disable the power voltage detector */ | |||
CLEAR_BIT(PWR->CR1, PWR_CR1_PVDE); | |||
} | |||
/** | |||
* @brief Enable the WakeUp PINx functionality. | |||
* @param WakeUpPinPolarity: Specifies which Wake-Up pin to enable. | |||
* This parameter can be one of the following legacy values, which sets the default polarity: | |||
* detection on high level (rising edge): | |||
* @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3, PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5, PWR_WAKEUP_PIN6 | |||
* or one of the following value where the user can explicitly states the enabled pin and | |||
* the chosen polarity | |||
* @arg PWR_WAKEUP_PIN1_HIGH or PWR_WAKEUP_PIN1_LOW | |||
* @arg PWR_WAKEUP_PIN2_HIGH or PWR_WAKEUP_PIN2_LOW | |||
* @arg PWR_WAKEUP_PIN3_HIGH or PWR_WAKEUP_PIN3_LOW | |||
* @arg PWR_WAKEUP_PIN4_HIGH or PWR_WAKEUP_PIN4_LOW | |||
* @arg PWR_WAKEUP_PIN5_HIGH or PWR_WAKEUP_PIN5_LOW | |||
* @arg PWR_WAKEUP_PIN6_HIGH or PWR_WAKEUP_PIN6_LOW | |||
* @note PWR_WAKEUP_PINx and PWR_WAKEUP_PINx_HIGH are equivalent. | |||
* @retval None | |||
*/ | |||
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity) | |||
{ | |||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinPolarity)); | |||
/* Enable wake-up pin */ | |||
SET_BIT(PWR->CSR2, (PWR_EWUP_MASK & WakeUpPinPolarity)); | |||
/* Specifies the Wake-Up pin polarity for the event detection | |||
(rising or falling edge) */ | |||
MODIFY_REG(PWR->CR2, (PWR_EWUP_MASK & WakeUpPinPolarity), (WakeUpPinPolarity >> 0x06)); | |||
} | |||
/** | |||
* @brief Disables the WakeUp PINx functionality. | |||
* @param WakeUpPinx: Specifies the Power Wake-Up pin to disable. | |||
* This parameter can be one of the following values: | |||
* @arg PWR_WAKEUP_PIN1 | |||
* @arg PWR_WAKEUP_PIN2 | |||
* @arg PWR_WAKEUP_PIN3 | |||
* @arg PWR_WAKEUP_PIN4 | |||
* @arg PWR_WAKEUP_PIN5 | |||
* @arg PWR_WAKEUP_PIN6 | |||
* @retval None | |||
*/ | |||
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx) | |||
{ | |||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx)); | |||
CLEAR_BIT(PWR->CSR2, WakeUpPinx); | |||
} | |||
/** | |||
* @brief Enters Sleep mode. | |||
* | |||
* @note In Sleep mode, all I/O pins keep the same state as in Run mode. | |||
* | |||
* @note In Sleep mode, the systick is stopped to avoid exit from this mode with | |||
* systick interrupt when used as time base for Timeout | |||
* | |||
* @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 is not used for the STM32F7 family and is kept as parameter | |||
* just to maintain compatibility with the lower power families. | |||
* @param SLEEPEntry: Specifies if SLEEP mode in entered with WFI or WFE instruction. | |||
* 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_REGULATOR(Regulator)); | |||
assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry)); | |||
/* Clear SLEEPDEEP bit of Cortex System Control Register */ | |||
CLEAR_BIT(SCB->SCR, ((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 = 0; | |||
/* 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->CR1; | |||
/* Clear PDDS and LPDS bits */ | |||
tmpreg &= (uint32_t)~(PWR_CR1_PDDS | PWR_CR1_LPDS); | |||
/* Set LPDS, MRLVDS and LPLVDS bits according to Regulator value */ | |||
tmpreg |= Regulator; | |||
/* Store the new value */ | |||
PWR->CR1 = 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_AF1 pin (PC13) if configured for tamper, time-stamp, RTC | |||
* Alarm out, or RTC clock calibration out. | |||
* - RTC_AF2 pin (PI8) if configured for tamper or time-stamp. | |||
* - WKUP pins if enabled. | |||
* @retval None | |||
*/ | |||
void HAL_PWR_EnterSTANDBYMode(void) | |||
{ | |||
/* Select Standby mode */ | |||
PWR->CR1 |= PWR_CR1_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 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 | |||
*/ | |||
} | |||
/** | |||
* @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 */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,564 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_pwr_ex.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Extended PWR HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities of PWR extension peripheral: | |||
* + Peripheral Extended features functions | |||
* | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup PWREx PWREx | |||
* @brief PWR HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_PWR_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/** @addtogroup PWREx_Private_Constants | |||
* @{ | |||
*/ | |||
#define PWR_OVERDRIVE_TIMEOUT_VALUE 1000 | |||
#define PWR_UDERDRIVE_TIMEOUT_VALUE 1000 | |||
#define PWR_BKPREG_TIMEOUT_VALUE 1000 | |||
#define PWR_VOSRDY_TIMEOUT_VALUE 1000 | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup PWREx_Exported_Functions PWREx Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended features functions | |||
* @brief Peripheral Extended features functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Peripheral extended features functions ##### | |||
=============================================================================== | |||
*** Main and Backup Regulators configuration *** | |||
================================================ | |||
[..] | |||
(+) The backup domain includes 4 Kbytes of backup SRAM accessible only from | |||
the CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is | |||
retained even in Standby or VBAT mode when the low power backup regulator | |||
is enabled. It can be considered as an internal EEPROM when VBAT is | |||
always present. You can use the HAL_PWREx_EnableBkUpReg() function to | |||
enable the low power backup regulator. | |||
(+) 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. | |||
(+) The main internal regulator can be configured to have a tradeoff between | |||
performance and power consumption when the device does not operate at | |||
the maximum frequency. This is done through __HAL_PWR_MAINREGULATORMODE_CONFIG() | |||
macro which configure VOS bit in PWR_CR register | |||
Refer to the product datasheets for more details. | |||
*** FLASH Power Down configuration **** | |||
======================================= | |||
[..] | |||
(+) By setting the FPDS bit in the PWR_CR register by using the | |||
HAL_PWREx_EnableFlashPowerDown() function, the Flash memory also enters power | |||
down mode when the device enters Stop mode. When the Flash memory | |||
is in power down mode, an additional startup delay is incurred when | |||
waking up from Stop mode. | |||
*** Over-Drive and Under-Drive configuration **** | |||
================================================= | |||
[..] | |||
(+) In Run mode: the main regulator has 2 operating modes available: | |||
(++) Normal mode: The CPU and core logic operate at maximum frequency at a given | |||
voltage scaling (scale 1, scale 2 or scale 3) | |||
(++) Over-drive mode: This mode allows the CPU and the core logic to operate at a | |||
higher frequency than the normal mode for a given voltage scaling (scale 1, | |||
scale 2 or scale 3). This mode is enabled through HAL_PWREx_EnableOverDrive() function and | |||
disabled by HAL_PWREx_DisableOverDrive() function, to enter or exit from Over-drive mode please follow | |||
the sequence described in Reference manual. | |||
(+) In Stop mode: the main regulator or low power regulator supplies a low power | |||
voltage to the 1.2V domain, thus preserving the content of registers | |||
and internal SRAM. 2 operating modes are available: | |||
(++) Normal mode: the 1.2V domain is preserved in nominal leakage mode. This mode is only | |||
available when the main regulator or the low power regulator is used in Scale 3 or | |||
low voltage mode. | |||
(++) Under-drive mode: the 1.2V domain is preserved in reduced leakage mode. This mode is only | |||
available when the main regulator or the low power regulator is in low voltage mode. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Enables the Backup Regulator. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void) | |||
{ | |||
uint32_t tickstart = 0; | |||
/* Enable Backup regulator */ | |||
PWR->CSR1 |= PWR_CSR1_BRE; | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
/* Wait till Backup regulator ready flag is set */ | |||
while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) == RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Disables the Backup Regulator. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void) | |||
{ | |||
uint32_t tickstart = 0; | |||
/* Disable Backup regulator */ | |||
PWR->CSR1 &= (uint32_t)~((uint32_t)PWR_CSR1_BRE); | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
/* Wait till Backup regulator ready flag is set */ | |||
while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) != RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Enables the Flash Power Down in Stop mode. | |||
* @retval None | |||
*/ | |||
void HAL_PWREx_EnableFlashPowerDown(void) | |||
{ | |||
/* Enable the Flash Power Down */ | |||
PWR->CR1 |= PWR_CR1_FPDS; | |||
} | |||
/** | |||
* @brief Disables the Flash Power Down in Stop mode. | |||
* @retval None | |||
*/ | |||
void HAL_PWREx_DisableFlashPowerDown(void) | |||
{ | |||
/* Disable the Flash Power Down */ | |||
PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_FPDS); | |||
} | |||
/** | |||
* @brief Enables Main Regulator low voltage mode. | |||
* @retval None | |||
*/ | |||
void HAL_PWREx_EnableMainRegulatorLowVoltage(void) | |||
{ | |||
/* Enable Main regulator low voltage */ | |||
PWR->CR1 |= PWR_CR1_MRUDS; | |||
} | |||
/** | |||
* @brief Disables Main Regulator low voltage mode. | |||
* @retval None | |||
*/ | |||
void HAL_PWREx_DisableMainRegulatorLowVoltage(void) | |||
{ | |||
/* Disable Main regulator low voltage */ | |||
PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_MRUDS); | |||
} | |||
/** | |||
* @brief Enables Low Power Regulator low voltage mode. | |||
* @retval None | |||
*/ | |||
void HAL_PWREx_EnableLowRegulatorLowVoltage(void) | |||
{ | |||
/* Enable low power regulator */ | |||
PWR->CR1 |= PWR_CR1_LPUDS; | |||
} | |||
/** | |||
* @brief Disables Low Power Regulator low voltage mode. | |||
* @retval None | |||
*/ | |||
void HAL_PWREx_DisableLowRegulatorLowVoltage(void) | |||
{ | |||
/* Disable low power regulator */ | |||
PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_LPUDS); | |||
} | |||
/** | |||
* @brief Activates the Over-Drive mode. | |||
* @note This mode allows the CPU and the core logic to operate at a higher frequency | |||
* than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3). | |||
* @note It is recommended to enter or exit Over-drive mode when the application is not running | |||
* critical tasks and when the system clock source is either HSI or HSE. | |||
* During the Over-drive switch activation, no peripheral clocks should be enabled. | |||
* The peripheral clocks must be enabled once the Over-drive mode is activated. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void) | |||
{ | |||
uint32_t tickstart = 0; | |||
__HAL_RCC_PWR_CLK_ENABLE(); | |||
/* Enable the Over-drive to extend the clock frequency to 216 MHz */ | |||
__HAL_PWR_OVERDRIVE_ENABLE(); | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY)) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
/* Enable the Over-drive switch */ | |||
__HAL_PWR_OVERDRIVESWITCHING_ENABLE(); | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY)) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Deactivates the Over-Drive mode. | |||
* @note This mode allows the CPU and the core logic to operate at a higher frequency | |||
* than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3). | |||
* @note It is recommended to enter or exit Over-drive mode when the application is not running | |||
* critical tasks and when the system clock source is either HSI or HSE. | |||
* During the Over-drive switch activation, no peripheral clocks should be enabled. | |||
* The peripheral clocks must be enabled once the Over-drive mode is activated. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void) | |||
{ | |||
uint32_t tickstart = 0; | |||
__HAL_RCC_PWR_CLK_ENABLE(); | |||
/* Disable the Over-drive switch */ | |||
__HAL_PWR_OVERDRIVESWITCHING_DISABLE(); | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY)) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
/* Disable the Over-drive */ | |||
__HAL_PWR_OVERDRIVE_DISABLE(); | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY)) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Enters in Under-Drive STOP mode. | |||
* | |||
* @note This mode can be selected only when the Under-Drive is already active | |||
* | |||
* @note This mode is enabled only with STOP low power mode. | |||
* In this mode, the 1.2V domain is preserved in reduced leakage mode. This | |||
* mode is only available when the main regulator or the low power regulator | |||
* is in low voltage mode | |||
* | |||
* @note If the Under-drive mode was enabled, it is automatically disabled after | |||
* exiting Stop mode. | |||
* When the voltage regulator operates in Under-drive mode, an additional | |||
* startup delay is induced when waking up from 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_UNDERDRIVE_ON: Main Regulator in under-drive mode | |||
* and Flash memory in power-down when the device is in Stop under-drive mode | |||
* @arg PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON: Low Power Regulator in under-drive mode | |||
* and Flash memory in power-down when the device is in Stop under-drive mode | |||
* @param STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction. | |||
* This parameter can be one of the following values: | |||
* @arg PWR_SLEEPENTRY_WFI: enter STOP mode with WFI instruction | |||
* @arg PWR_SLEEPENTRY_WFE: enter STOP mode with WFE instruction | |||
* @retval None | |||
*/ | |||
HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry) | |||
{ | |||
uint32_t tempreg = 0; | |||
uint32_t tickstart = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_PWR_REGULATOR_UNDERDRIVE(Regulator)); | |||
assert_param(IS_PWR_STOP_ENTRY(STOPEntry)); | |||
/* Enable Power ctrl clock */ | |||
__HAL_RCC_PWR_CLK_ENABLE(); | |||
/* Enable the Under-drive Mode ---------------------------------------------*/ | |||
/* Clear Under-drive flag */ | |||
__HAL_PWR_CLEAR_ODRUDR_FLAG(); | |||
/* Enable the Under-drive */ | |||
__HAL_PWR_UNDERDRIVE_ENABLE(); | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
/* Wait for UnderDrive mode is ready */ | |||
while(__HAL_PWR_GET_FLAG(PWR_FLAG_UDRDY)) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > PWR_UDERDRIVE_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
/* Select the regulator state in STOP mode ---------------------------------*/ | |||
tempreg = PWR->CR1; | |||
/* Clear PDDS, LPDS, MRLUDS and LPLUDS bits */ | |||
tempreg &= (uint32_t)~(PWR_CR1_PDDS | PWR_CR1_LPDS | PWR_CR1_LPUDS | PWR_CR1_MRUDS); | |||
/* Set LPDS, MRLUDS and LPLUDS bits according to PWR_Regulator value */ | |||
tempreg |= Regulator; | |||
/* Store the new value */ | |||
PWR->CR1 = tempreg; | |||
/* Set SLEEPDEEP bit of Cortex System Control Register */ | |||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; | |||
/* Select STOP mode entry --------------------------------------------------*/ | |||
if(STOPEntry == PWR_SLEEPENTRY_WFI) | |||
{ | |||
/* Request Wait For Interrupt */ | |||
__WFI(); | |||
} | |||
else | |||
{ | |||
/* Request Wait For Event */ | |||
__WFE(); | |||
} | |||
/* Reset SLEEPDEEP bit of Cortex System Control Register */ | |||
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Returns Voltage Scaling Range. | |||
* @retval VOS bit field (PWR_REGULATOR_VOLTAGE_SCALE1, PWR_REGULATOR_VOLTAGE_SCALE2 or | |||
* PWR_REGULATOR_VOLTAGE_SCALE3)PWR_REGULATOR_VOLTAGE_SCALE1 | |||
*/ | |||
uint32_t HAL_PWREx_GetVoltageRange(void) | |||
{ | |||
return (PWR->CR1 & PWR_CR1_VOS); | |||
} | |||
/** | |||
* @brief Configures the main internal regulator output voltage. | |||
* @param VoltageScaling: specifies the regulator output voltage to achieve | |||
* a tradeoff between performance and power consumption. | |||
* This parameter can be one of the following values: | |||
* @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output range 1 mode, | |||
* typical output voltage at 1.4 V, | |||
* system frequency up to 216 MHz. | |||
* @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output range 2 mode, | |||
* typical output voltage at 1.2 V, | |||
* system frequency up to 180 MHz. | |||
* @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output range 2 mode, | |||
* typical output voltage at 1.00 V, | |||
* system frequency up to 151 MHz. | |||
* @note To update the system clock frequency(SYSCLK): | |||
* - Set the HSI or HSE as system clock frequency using the HAL_RCC_ClockConfig(). | |||
* - Call the HAL_RCC_OscConfig() to configure the PLL. | |||
* - Call HAL_PWREx_ConfigVoltageScaling() API to adjust the voltage scale. | |||
* - Set the new system clock frequency using the HAL_RCC_ClockConfig(). | |||
* @note The scale can be modified only when the HSI or HSE clock source is selected | |||
* as system clock source, otherwise the API returns HAL_ERROR. | |||
* @note When the PLL is OFF, the voltage scale 3 is automatically selected and the VOS bits | |||
* value in the PWR_CR1 register are not taken in account. | |||
* @note This API forces the PLL state ON to allow the possibility to configure the voltage scale 1 or 2. | |||
* @note The new voltage scale is active only when the PLL is ON. | |||
* @retval HAL Status | |||
*/ | |||
HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling) | |||
{ | |||
uint32_t tickstart = 0; | |||
assert_param(IS_PWR_REGULATOR_VOLTAGE(VoltageScaling)); | |||
/* Enable Power ctrl clock */ | |||
__HAL_RCC_PWR_CLK_ENABLE(); | |||
/* Check if the PLL is used as system clock or not */ | |||
if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL) | |||
{ | |||
/* Disable the main PLL */ | |||
__HAL_RCC_PLL_DISABLE(); | |||
/* Get Start Tick */ | |||
tickstart = HAL_GetTick(); | |||
/* Wait till PLL is disabled */ | |||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
/* Set Range */ | |||
__HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling); | |||
/* Enable the main PLL */ | |||
__HAL_RCC_PLL_ENABLE(); | |||
/* Get Start Tick */ | |||
tickstart = HAL_GetTick(); | |||
/* Wait till PLL is ready */ | |||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
/* Get Start Tick */ | |||
tickstart = HAL_GetTick(); | |||
while((__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY) == RESET)) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
return HAL_ERROR; | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_PWR_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,861 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_rcc_ex.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief Extension RCC HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities RCC extension peripheral: | |||
* + Extended Peripheral Control functions | |||
* | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup RCCEx RCCEx | |||
* @brief RCCEx HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_RCC_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/** @defgroup RCCEx_Private_Defines RCCEx Private Defines | |||
* @{ | |||
*/ | |||
#define PLLI2S_TIMEOUT_VALUE 100 /* Timeout value fixed to 100 ms */ | |||
#define PLLSAI_TIMEOUT_VALUE 100 /* Timeout value fixed to 100 ms */ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/** @defgroup RCCEx_Private_Macros RCCEx Private Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RCCEx_Private_Macros RCCEx Private Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions | |||
* @brief Extended Peripheral Control functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Extended Peripheral Control functions ##### | |||
=============================================================================== | |||
[..] | |||
This subsection provides a set of functions allowing to control the RCC Clocks | |||
frequencies. | |||
[..] | |||
(@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to | |||
select the RTC clock source; in this case the Backup domain will be reset in | |||
order to modify the RTC Clock source, as consequence RTC registers (including | |||
the backup registers) and RCC_BDCR register will be set to their reset values. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Initializes the RCC extended peripherals clocks according to the specified | |||
* parameters in the RCC_PeriphCLKInitTypeDef. | |||
* @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that | |||
* contains the configuration information for the Extended Peripherals | |||
* clocks(I2S, SAI, LTDC RTC, TIM, UARTs, USARTs, LTPIM, SDMMC...). | |||
* | |||
* @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select | |||
* the RTC clock source; in this case the Backup domain will be reset in | |||
* order to modify the RTC Clock source, as consequence RTC registers (including | |||
* the backup registers) and RCC_BDCR register are set to their reset values. | |||
* | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit) | |||
{ | |||
uint32_t tickstart = 0; | |||
uint32_t tmpreg0 = 0; | |||
uint32_t tmpreg1 = 0; | |||
uint32_t plli2sused = 0; | |||
uint32_t pllsaiused = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection)); | |||
/*----------------------------------- I2S configuration ----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == (RCC_PERIPHCLK_I2S)) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_I2SCLKSOURCE(PeriphClkInit->I2sClockSelection)); | |||
/* Configure I2S Clock source */ | |||
__HAL_RCC_I2S_CONFIG(PeriphClkInit->I2sClockSelection); | |||
/* Enable the PLLI2S when it's used as clock source for I2S */ | |||
if(PeriphClkInit->I2sClockSelection == RCC_I2SCLKSOURCE_PLLI2S) | |||
{ | |||
plli2sused = 1; | |||
} | |||
} | |||
/*------------------------------------ SAI1 configuration --------------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == (RCC_PERIPHCLK_SAI1)) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_SAI1CLKSOURCE(PeriphClkInit->Sai1ClockSelection)); | |||
/* Configure SAI1 Clock source */ | |||
__HAL_RCC_SAI1_CONFIG(PeriphClkInit->Sai1ClockSelection); | |||
/* Enable the PLLI2S when it's used as clock source for SAI */ | |||
if(PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLI2S) | |||
{ | |||
plli2sused = 1; | |||
} | |||
/* Enable the PLLSAI when it's used as clock source for SAI */ | |||
if(PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLSAI) | |||
{ | |||
pllsaiused = 1; | |||
} | |||
} | |||
/*------------------------------------ SAI2 configuration --------------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == (RCC_PERIPHCLK_SAI2)) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_SAI2CLKSOURCE(PeriphClkInit->Sai2ClockSelection)); | |||
/* Configure SAI2 Clock source */ | |||
__HAL_RCC_SAI2_CONFIG(PeriphClkInit->Sai2ClockSelection); | |||
/* Enable the PLLI2S when it's used as clock source for SAI */ | |||
if(PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLI2S) | |||
{ | |||
plli2sused = 1; | |||
} | |||
/* Enable the PLLSAI when it's used as clock source for SAI */ | |||
if(PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLSAI) | |||
{ | |||
pllsaiused = 1; | |||
} | |||
} | |||
/*-------------------------------------- SPDIF-RX Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPDIFRX) == RCC_PERIPHCLK_SPDIFRX) | |||
{ | |||
plli2sused = 1; | |||
} | |||
/*------------------------------------ RTC configuration --------------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == (RCC_PERIPHCLK_RTC)) | |||
{ | |||
/* Reset the Backup domain only if the RTC Clock source selection is modified */ | |||
if((RCC->BDCR & RCC_BDCR_RTCSEL) != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL)) | |||
{ | |||
/* Enable Power Clock*/ | |||
__HAL_RCC_PWR_CLK_ENABLE(); | |||
/* Enable write access to Backup domain */ | |||
PWR->CR1 |= PWR_CR1_DBP; | |||
/* Get Start Tick*/ | |||
tickstart = HAL_GetTick(); | |||
/* Wait for Backup domain Write protection disable */ | |||
while((PWR->CR1 & PWR_CR1_DBP) == RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
/* Store the content of BDCR register before the reset of Backup Domain */ | |||
tmpreg0 = (RCC->BDCR & ~(RCC_BDCR_RTCSEL)); | |||
/* RTC Clock selection can be changed only if the Backup Domain is reset */ | |||
__HAL_RCC_BACKUPRESET_FORCE(); | |||
__HAL_RCC_BACKUPRESET_RELEASE(); | |||
/* Restore the Content of BDCR register */ | |||
RCC->BDCR = tmpreg0; | |||
/* If LSE is selected as RTC clock source, wait for LSE reactivation */ | |||
if (HAL_IS_BIT_SET(tmpreg0, RCC_BDCR_LSERDY)) | |||
{ | |||
/* Get Start Tick*/ | |||
tickstart = HAL_GetTick(); | |||
/* Wait till LSE is ready */ | |||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
} | |||
__HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection); | |||
} | |||
} | |||
/*------------------------------------ TIM configuration --------------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM) == (RCC_PERIPHCLK_TIM)) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_TIMPRES(PeriphClkInit->TIMPresSelection)); | |||
/* Configure Timer Prescaler */ | |||
__HAL_RCC_TIMCLKPRESCALER(PeriphClkInit->TIMPresSelection); | |||
} | |||
/*-------------------------------------- I2C1 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_I2C1CLKSOURCE(PeriphClkInit->I2c1ClockSelection)); | |||
/* Configure the I2C1 clock source */ | |||
__HAL_RCC_I2C1_CONFIG(PeriphClkInit->I2c1ClockSelection); | |||
} | |||
/*-------------------------------------- I2C2 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_I2C2CLKSOURCE(PeriphClkInit->I2c2ClockSelection)); | |||
/* Configure the I2C2 clock source */ | |||
__HAL_RCC_I2C2_CONFIG(PeriphClkInit->I2c2ClockSelection); | |||
} | |||
/*-------------------------------------- I2C3 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_I2C3CLKSOURCE(PeriphClkInit->I2c3ClockSelection)); | |||
/* Configure the I2C3 clock source */ | |||
__HAL_RCC_I2C3_CONFIG(PeriphClkInit->I2c3ClockSelection); | |||
} | |||
/*-------------------------------------- I2C4 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C4) == RCC_PERIPHCLK_I2C4) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_I2C4CLKSOURCE(PeriphClkInit->I2c4ClockSelection)); | |||
/* Configure the I2C4 clock source */ | |||
__HAL_RCC_I2C4_CONFIG(PeriphClkInit->I2c4ClockSelection); | |||
} | |||
/*-------------------------------------- USART1 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_USART1CLKSOURCE(PeriphClkInit->Usart1ClockSelection)); | |||
/* Configure the USART1 clock source */ | |||
__HAL_RCC_USART1_CONFIG(PeriphClkInit->Usart1ClockSelection); | |||
} | |||
/*-------------------------------------- USART2 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_USART2CLKSOURCE(PeriphClkInit->Usart2ClockSelection)); | |||
/* Configure the USART2 clock source */ | |||
__HAL_RCC_USART2_CONFIG(PeriphClkInit->Usart2ClockSelection); | |||
} | |||
/*-------------------------------------- USART3 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_USART3CLKSOURCE(PeriphClkInit->Usart3ClockSelection)); | |||
/* Configure the USART3 clock source */ | |||
__HAL_RCC_USART3_CONFIG(PeriphClkInit->Usart3ClockSelection); | |||
} | |||
/*-------------------------------------- UART4 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_UART4CLKSOURCE(PeriphClkInit->Uart4ClockSelection)); | |||
/* Configure the UART4 clock source */ | |||
__HAL_RCC_UART4_CONFIG(PeriphClkInit->Uart4ClockSelection); | |||
} | |||
/*-------------------------------------- UART5 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART5) == RCC_PERIPHCLK_UART5) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_UART5CLKSOURCE(PeriphClkInit->Uart5ClockSelection)); | |||
/* Configure the UART5 clock source */ | |||
__HAL_RCC_UART5_CONFIG(PeriphClkInit->Uart5ClockSelection); | |||
} | |||
/*-------------------------------------- USART6 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART6) == RCC_PERIPHCLK_USART6) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_USART6CLKSOURCE(PeriphClkInit->Usart6ClockSelection)); | |||
/* Configure the USART6 clock source */ | |||
__HAL_RCC_USART6_CONFIG(PeriphClkInit->Usart6ClockSelection); | |||
} | |||
/*-------------------------------------- UART7 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART7) == RCC_PERIPHCLK_UART7) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_UART7CLKSOURCE(PeriphClkInit->Uart7ClockSelection)); | |||
/* Configure the UART7 clock source */ | |||
__HAL_RCC_UART7_CONFIG(PeriphClkInit->Uart7ClockSelection); | |||
} | |||
/*-------------------------------------- UART8 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART8) == RCC_PERIPHCLK_UART8) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_UART8CLKSOURCE(PeriphClkInit->Uart8ClockSelection)); | |||
/* Configure the UART8 clock source */ | |||
__HAL_RCC_UART8_CONFIG(PeriphClkInit->Uart8ClockSelection); | |||
} | |||
/*--------------------------------------- CEC Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CEC) == RCC_PERIPHCLK_CEC) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_CECCLKSOURCE(PeriphClkInit->CecClockSelection)); | |||
/* Configure the CEC clock source */ | |||
__HAL_RCC_CEC_CONFIG(PeriphClkInit->CecClockSelection); | |||
} | |||
/*-------------------------------------- CK48 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CLK48) == RCC_PERIPHCLK_CLK48) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_CLK48SOURCE(PeriphClkInit->Clk48ClockSelection)); | |||
/* Configure the CLK48 source */ | |||
__HAL_RCC_CLK48_CONFIG(PeriphClkInit->Clk48ClockSelection); | |||
/* Enable the PLLSAI when it's used as clock source for CK48 */ | |||
if(PeriphClkInit->Clk48ClockSelection == RCC_CLK48SOURCE_PLLSAIP) | |||
{ | |||
pllsaiused = 1; | |||
} | |||
} | |||
/*-------------------------------------- LTDC Configuration -----------------------------------*/ | |||
#if defined(STM32F756xx) || defined(STM32F746xx) | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LTDC) == RCC_PERIPHCLK_LTDC) | |||
{ | |||
pllsaiused = 1; | |||
} | |||
#endif /* STM32F756xx || STM32F746xx */ | |||
/*-------------------------------------- LPTIM1 Configuration -----------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_LPTIM1CLK(PeriphClkInit->Lptim1ClockSelection)); | |||
/* Configure the LTPIM1 clock source */ | |||
__HAL_RCC_LPTIM1_CONFIG(PeriphClkInit->Lptim1ClockSelection); | |||
} | |||
/*------------------------------------- SDMMC Configuration ------------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_SDMMC1CLKSOURCE(PeriphClkInit->Sdmmc1ClockSelection)); | |||
/* Configure the SDMMC1 clock source */ | |||
__HAL_RCC_SDMMC1_CONFIG(PeriphClkInit->Sdmmc1ClockSelection); | |||
} | |||
/*-------------------------------------- PLLI2S Configuration ---------------------------------*/ | |||
/* PLLI2S is configured when a peripheral will use it as source clock : SAI1, SAI2, I2S or SPDIF-RX */ | |||
if((plli2sused == 1) || (PeriphClkInit->PeriphClockSelection == RCC_PERIPHCLK_PLLI2S)) | |||
{ | |||
/* Disable the PLLI2S */ | |||
__HAL_RCC_PLLI2S_DISABLE(); | |||
/* Get Start Tick*/ | |||
tickstart = HAL_GetTick(); | |||
/* Wait till PLLI2S is disabled */ | |||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) | |||
{ | |||
/* return in case of Timeout detected */ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
/* check for common PLLI2S Parameters */ | |||
assert_param(IS_RCC_PLLI2SN_VALUE(PeriphClkInit->PLLI2S.PLLI2SN)); | |||
/*----------------- In Case of PLLI2S is selected as source clock for I2S -------------------*/ | |||
if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == RCC_PERIPHCLK_I2S) && (PeriphClkInit->I2sClockSelection == RCC_I2SCLKSOURCE_PLLI2S))) | |||
{ | |||
/* check for Parameters */ | |||
assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR)); | |||
/* Read PLLI2SP and PLLI2SQ value from PLLI2SCFGR register (this value is not needed for I2S configuration) */ | |||
tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SP)); | |||
tmpreg1 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SQ)); | |||
/* Configure the PLLI2S division factors */ | |||
/* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLM) */ | |||
/* I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */ | |||
__HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , tmpreg0, tmpreg1, PeriphClkInit->PLLI2S.PLLI2SR); | |||
} | |||
/*----------------- In Case of PLLI2S is selected as source clock for SAI -------------------*/ | |||
if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) && (PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLI2S)) || | |||
((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) && (PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLI2S))) | |||
{ | |||
/* Check for PLLI2S Parameters */ | |||
assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ)); | |||
/* Check for PLLI2S/DIVQ parameters */ | |||
assert_param(IS_RCC_PLLI2S_DIVQ_VALUE(PeriphClkInit->PLLI2SDivQ)); | |||
/* Read PLLI2SP and PLLI2SR values from PLLI2SCFGR register (this value is not needed for SAI configuration) */ | |||
tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SP)); | |||
tmpreg1 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR)); | |||
/* Configure the PLLI2S division factors */ | |||
/* PLLI2S_VCO Input = PLL_SOURCE/PLLM */ | |||
/* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */ | |||
/* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */ | |||
__HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN, tmpreg0, PeriphClkInit->PLLI2S.PLLI2SQ, tmpreg1); | |||
/* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */ | |||
__HAL_RCC_PLLI2S_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLI2SDivQ); | |||
} | |||
/*----------------- In Case of PLLI2S is selected as source clock for SPDIF-RX -------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPDIFRX) == RCC_PERIPHCLK_SPDIFRX) | |||
{ | |||
/* check for Parameters */ | |||
assert_param(IS_RCC_PLLI2SP_VALUE(PeriphClkInit->PLLI2S.PLLI2SP)); | |||
/* Read PLLI2SR value from PLLI2SCFGR register (this value is not needed for SPDIF-RX configuration) */ | |||
tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SQ)); | |||
tmpreg1 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR)); | |||
/* Configure the PLLI2S division factors */ | |||
/* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLM) */ | |||
/* SPDIFCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SP */ | |||
__HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SP, tmpreg0, tmpreg1); | |||
} | |||
/*----------------- In Case of PLLI2S is just selected -----------------*/ | |||
if((PeriphClkInit->PeriphClockSelection & RCC_PERIPHCLK_PLLI2S) == RCC_PERIPHCLK_PLLI2S) | |||
{ | |||
/* Check for Parameters */ | |||
assert_param(IS_RCC_PLLI2SN_VALUE(PeriphClkInit->PLLI2S.PLLI2SN)); | |||
assert_param(IS_RCC_PLLI2SP_VALUE(PeriphClkInit->PLLI2S.PLLI2SP)); | |||
assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR)); | |||
assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ)); | |||
/* Configure the PLLI2S division factors */ | |||
/* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLI2SM) */ | |||
/* SPDIFRXCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SP */ | |||
__HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SP, PeriphClkInit->PLLI2S.PLLI2SQ, PeriphClkInit->PLLI2S.PLLI2SR); | |||
} | |||
/* Enable the PLLI2S */ | |||
__HAL_RCC_PLLI2S_ENABLE(); | |||
/* Get Start Tick*/ | |||
tickstart = HAL_GetTick(); | |||
/* Wait till PLLI2S is ready */ | |||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) | |||
{ | |||
/* return in case of Timeout detected */ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
} | |||
/*-------------------------------------- PLLSAI Configuration ---------------------------------*/ | |||
/* PLLSAI is configured when a peripheral will use it as source clock : SAI1, SAI2, LTDC or CK48 */ | |||
if(pllsaiused == 1) | |||
{ | |||
/* Disable PLLSAI Clock */ | |||
__HAL_RCC_PLLSAI_DISABLE(); | |||
/* Get Start Tick*/ | |||
tickstart = HAL_GetTick(); | |||
/* Wait till PLLSAI is disabled */ | |||
while(__HAL_RCC_PLLSAI_GET_FLAG() != RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart) > PLLSAI_TIMEOUT_VALUE) | |||
{ | |||
/* return in case of Timeout detected */ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
/* Check the PLLSAI division factors */ | |||
assert_param(IS_RCC_PLLSAIN_VALUE(PeriphClkInit->PLLSAI.PLLSAIN)); | |||
/*----------------- In Case of PLLSAI is selected as source clock for SAI -------------------*/ | |||
if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) && (PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLSAI)) || | |||
((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) && (PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLSAI))) | |||
{ | |||
/* check for PLLSAIQ Parameter */ | |||
assert_param(IS_RCC_PLLSAIQ_VALUE(PeriphClkInit->PLLSAI.PLLSAIQ)); | |||
/* check for PLLSAI/DIVQ Parameter */ | |||
assert_param(IS_RCC_PLLSAI_DIVQ_VALUE(PeriphClkInit->PLLSAIDivQ)); | |||
/* Read PLLSAIP value from PLLSAICFGR register (this value is not needed for SAI configuration) */ | |||
tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIP)); | |||
tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIR)); | |||
/* PLLSAI_VCO Input = PLL_SOURCE/PLLM */ | |||
/* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */ | |||
/* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */ | |||
__HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , tmpreg0, PeriphClkInit->PLLSAI.PLLSAIQ, tmpreg1); | |||
/* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */ | |||
__HAL_RCC_PLLSAI_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLSAIDivQ); | |||
} | |||
/*----------------- In Case of PLLSAI is selected as source clock for CLK48 -------------------*/ | |||
/* In Case of PLLI2S is selected as source clock for CK48 */ | |||
if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CLK48) == RCC_PERIPHCLK_CLK48) && (PeriphClkInit->Clk48ClockSelection == RCC_CLK48SOURCE_PLLSAIP)) | |||
{ | |||
/* check for Parameters */ | |||
assert_param(IS_RCC_PLLSAIP_VALUE(PeriphClkInit->PLLSAI.PLLSAIP)); | |||
/* Read PLLSAIQ and PLLSAIR value from PLLSAICFGR register (this value is not needed for CK48 configuration) */ | |||
tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIQ)); | |||
tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIR) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIR)); | |||
/* Configure the PLLSAI division factors */ | |||
/* PLLSAI_VCO = f(VCO clock) = f(PLLSAI clock input) x (PLLI2SN/PLLM) */ | |||
/* 48CLK = f(PLLSAI clock output) = f(VCO clock) / PLLSAIP */ | |||
__HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , PeriphClkInit->PLLSAI.PLLSAIP, tmpreg0, tmpreg1); | |||
} | |||
#if defined(STM32F756xx) || defined(STM32F746xx) | |||
/*---------------------------- LTDC configuration -------------------------------*/ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LTDC) == (RCC_PERIPHCLK_LTDC)) | |||
{ | |||
assert_param(IS_RCC_PLLSAIR_VALUE(PeriphClkInit->PLLSAI.PLLSAIR)); | |||
assert_param(IS_RCC_PLLSAI_DIVR_VALUE(PeriphClkInit->PLLSAIDivR)); | |||
/* Read PLLSAIP and PLLSAIQ value from PLLSAICFGR register (these value are not needed for LTDC configuration) */ | |||
tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIQ)); | |||
tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIP)); | |||
/* PLLSAI_VCO Input = PLL_SOURCE/PLLM */ | |||
/* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */ | |||
/* LTDC_CLK(first level) = PLLSAI_VCO Output/PLLSAIR */ | |||
__HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , tmpreg1, tmpreg0, PeriphClkInit->PLLSAI.PLLSAIR); | |||
/* LTDC_CLK = LTDC_CLK(first level)/PLLSAIDIVR */ | |||
__HAL_RCC_PLLSAI_PLLSAICLKDIVR_CONFIG(PeriphClkInit->PLLSAIDivR); | |||
} | |||
#endif /* STM32F756xx || STM32F746xx */ | |||
/* Enable PLLSAI Clock */ | |||
__HAL_RCC_PLLSAI_ENABLE(); | |||
/* Get Start Tick*/ | |||
tickstart = HAL_GetTick(); | |||
/* Wait till PLLSAI is ready */ | |||
while(__HAL_RCC_PLLSAI_GET_FLAG() == RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart) > PLLSAI_TIMEOUT_VALUE) | |||
{ | |||
/* return in case of Timeout detected */ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Get the RCC_PeriphCLKInitTypeDef according to the internal | |||
* RCC configuration registers. | |||
* @param PeriphClkInit: pointer to the configured RCC_PeriphCLKInitTypeDef structure | |||
* @retval None | |||
*/ | |||
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit) | |||
{ | |||
uint32_t tempreg = 0; | |||
/* Set all possible values for the extended clock type parameter------------*/ | |||
PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_I2S | RCC_PERIPHCLK_LPTIM1 |\ | |||
RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 |\ | |||
RCC_PERIPHCLK_TIM | RCC_PERIPHCLK_RTC |\ | |||
RCC_PERIPHCLK_CEC | RCC_PERIPHCLK_I2C4 |\ | |||
RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 |\ | |||
RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_USART1 |\ | |||
RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 |\ | |||
RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 |\ | |||
RCC_PERIPHCLK_USART6 | RCC_PERIPHCLK_UART7 |\ | |||
RCC_PERIPHCLK_UART8 | RCC_PERIPHCLK_SDMMC1 |\ | |||
RCC_PERIPHCLK_CLK48; | |||
/* Get the PLLI2S Clock configuration -----------------------------------------------*/ | |||
PeriphClkInit->PLLI2S.PLLI2SN = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SN)); | |||
PeriphClkInit->PLLI2S.PLLI2SP = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SP)); | |||
PeriphClkInit->PLLI2S.PLLI2SQ = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SQ)); | |||
PeriphClkInit->PLLI2S.PLLI2SR = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR)); | |||
/* Get the PLLSAI Clock configuration -----------------------------------------------*/ | |||
PeriphClkInit->PLLSAI.PLLSAIN = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIN)); | |||
PeriphClkInit->PLLSAI.PLLSAIP = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIP)); | |||
PeriphClkInit->PLLSAI.PLLSAIQ = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIQ)); | |||
PeriphClkInit->PLLSAI.PLLSAIR = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIR) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIR)); | |||
/* Get the PLLSAI/PLLI2S division factors -------------------------------------------*/ | |||
PeriphClkInit->PLLI2SDivQ = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLI2SDIVQ) >> POSITION_VAL(RCC_DCKCFGR1_PLLI2SDIVQ)); | |||
PeriphClkInit->PLLSAIDivQ = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVQ) >> POSITION_VAL(RCC_DCKCFGR1_PLLSAIDIVQ)); | |||
PeriphClkInit->PLLSAIDivR = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVR) >> POSITION_VAL(RCC_DCKCFGR1_PLLSAIDIVR)); | |||
/* Get the SAI1 clock configuration ----------------------------------------------*/ | |||
PeriphClkInit->Sai1ClockSelection = __HAL_RCC_GET_SAI1_SOURCE(); | |||
/* Get the SAI2 clock configuration ----------------------------------------------*/ | |||
PeriphClkInit->Sai2ClockSelection = __HAL_RCC_GET_SAI2_SOURCE(); | |||
/* Get the I2S clock configuration ------------------------------------------*/ | |||
PeriphClkInit->I2sClockSelection = __HAL_RCC_GET_I2SCLKSOURCE(); | |||
/* Get the I2C1 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->I2c1ClockSelection = __HAL_RCC_GET_I2C1_SOURCE(); | |||
/* Get the I2C2 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->I2c2ClockSelection = __HAL_RCC_GET_I2C2_SOURCE(); | |||
/* Get the I2C3 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->I2c3ClockSelection = __HAL_RCC_GET_I2C3_SOURCE(); | |||
/* Get the I2C4 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->I2c4ClockSelection = __HAL_RCC_GET_I2C4_SOURCE(); | |||
/* Get the USART1 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->Usart1ClockSelection = __HAL_RCC_GET_USART1_SOURCE(); | |||
/* Get the USART2 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->Usart2ClockSelection = __HAL_RCC_GET_USART2_SOURCE(); | |||
/* Get the USART3 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->Usart3ClockSelection = __HAL_RCC_GET_USART3_SOURCE(); | |||
/* Get the UART4 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->Uart4ClockSelection = __HAL_RCC_GET_UART4_SOURCE(); | |||
/* Get the UART5 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->Uart5ClockSelection = __HAL_RCC_GET_UART5_SOURCE(); | |||
/* Get the USART6 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->Usart6ClockSelection = __HAL_RCC_GET_USART6_SOURCE(); | |||
/* Get the UART7 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->Uart7ClockSelection = __HAL_RCC_GET_UART7_SOURCE(); | |||
/* Get the UART8 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->Uart8ClockSelection = __HAL_RCC_GET_UART8_SOURCE(); | |||
/* Get the LPTIM1 clock configuration ------------------------------------------*/ | |||
PeriphClkInit->Lptim1ClockSelection = __HAL_RCC_GET_LPTIM1_SOURCE(); | |||
/* Get the CEC clock configuration -----------------------------------------------*/ | |||
PeriphClkInit->CecClockSelection = __HAL_RCC_GET_CEC_SOURCE(); | |||
/* Get the CK48 clock configuration -----------------------------------------------*/ | |||
PeriphClkInit->Clk48ClockSelection = __HAL_RCC_GET_CLK48_SOURCE(); | |||
/* Get the SDMMC clock configuration -----------------------------------------------*/ | |||
PeriphClkInit->Sdmmc1ClockSelection = __HAL_RCC_GET_SDMMC1_SOURCE(); | |||
/* Get the RTC Clock configuration -----------------------------------------------*/ | |||
tempreg = (RCC->CFGR & RCC_CFGR_RTCPRE); | |||
PeriphClkInit->RTCClockSelection = (uint32_t)((tempreg) | (RCC->BDCR & RCC_BDCR_RTCSEL)); | |||
/* Get the TIM Prescaler configuration --------------------------------------------*/ | |||
if ((RCC->DCKCFGR1 & RCC_DCKCFGR1_TIMPRE) == RESET) | |||
{ | |||
PeriphClkInit->TIMPresSelection = RCC_TIMPRES_DESACTIVATED; | |||
} | |||
else | |||
{ | |||
PeriphClkInit->TIMPresSelection = RCC_TIMPRES_ACTIVATED; | |||
} | |||
} | |||
/** | |||
* @brief Return the peripheral clock frequency for a given peripheral(SAI..) | |||
* @note Return 0 if peripheral clock identifier not managed by this API | |||
* @param PeriphClk: Peripheral clock identifier | |||
* This parameter can be one of the following values: | |||
* @arg RCC_PERIPHCLK_SAI1: SAI1 peripheral clock | |||
* @arg RCC_PERIPHCLK_SAI2: SAI2 peripheral clock | |||
* @retval Frequency in KHz | |||
*/ | |||
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk) | |||
{ | |||
uint32_t tmpreg = 0; | |||
/* This variable used to store the SAI clock frequency (value in Hz) */ | |||
uint32_t frequency = 0; | |||
/* This variable used to store the VCO Input (value in Hz) */ | |||
uint32_t vcoinput = 0; | |||
/* This variable used to store the SAI clock source */ | |||
uint32_t saiclocksource = 0; | |||
if ((PeriphClk == RCC_PERIPHCLK_SAI1) || (PeriphClk == RCC_PERIPHCLK_SAI2)) | |||
{ | |||
saiclocksource = RCC->DCKCFGR1; | |||
saiclocksource &= (RCC_DCKCFGR1_SAI1SEL | RCC_DCKCFGR1_SAI2SEL); | |||
switch (saiclocksource) | |||
{ | |||
case 0: /* PLLSAI is the clock source for SAI*/ | |||
{ | |||
/* Configure the PLLSAI division factor */ | |||
/* PLLSAI_VCO Input = PLL_SOURCE/PLLM */ | |||
if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI) | |||
{ | |||
/* In Case the PLL Source is HSI (Internal Clock) */ | |||
vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)); | |||
} | |||
else | |||
{ | |||
/* In Case the PLL Source is HSE (External Clock) */ | |||
vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM))); | |||
} | |||
/* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */ | |||
/* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */ | |||
tmpreg = (RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> 24; | |||
frequency = (vcoinput * ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> 6))/(tmpreg); | |||
/* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */ | |||
tmpreg = (((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVQ) >> 8) + 1); | |||
frequency = frequency/(tmpreg); | |||
break; | |||
} | |||
case RCC_DCKCFGR1_SAI1SEL_0: /* PLLI2S is the clock source for SAI*/ | |||
case RCC_DCKCFGR1_SAI2SEL_0: /* PLLI2S is the clock source for SAI*/ | |||
{ | |||
/* Configure the PLLI2S division factor */ | |||
/* PLLI2S_VCO Input = PLL_SOURCE/PLLM */ | |||
if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI) | |||
{ | |||
/* In Case the PLL Source is HSI (Internal Clock) */ | |||
vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)); | |||
} | |||
else | |||
{ | |||
/* In Case the PLL Source is HSE (External Clock) */ | |||
vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM))); | |||
} | |||
/* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */ | |||
/* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */ | |||
tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> 24; | |||
frequency = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6))/(tmpreg); | |||
/* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */ | |||
tmpreg = ((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLI2SDIVQ) + 1); | |||
frequency = frequency/(tmpreg); | |||
break; | |||
} | |||
case RCC_DCKCFGR1_SAI1SEL_1: /* External clock is the clock source for SAI*/ | |||
case RCC_DCKCFGR1_SAI2SEL_1: /* External clock is the clock source for SAI*/ | |||
{ | |||
frequency = EXTERNAL_CLOCK_VALUE; | |||
break; | |||
} | |||
default : | |||
{ | |||
break; | |||
} | |||
} | |||
} | |||
return frequency; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_RCC_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,510 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_hal_rng.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief RNG HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities of the Random Number Generator (RNG) peripheral: | |||
* + Initialization/de-initialization functions | |||
* + Peripheral Control functions | |||
* + Peripheral State functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] | |||
The RNG HAL driver can be used as follows: | |||
(#) Enable the RNG controller clock using __HAL_RCC_RNG_CLK_ENABLE() macro | |||
in HAL_RNG_MspInit(). | |||
(#) Activate the RNG peripheral using HAL_RNG_Init() function. | |||
(#) Wait until the 32 bit Random Number Generator contains a valid | |||
random data using (polling/interrupt) mode. | |||
(#) Get the 32 bit random number using HAL_RNG_GenerateRandomNumber() function. | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup RNG | |||
* @{ | |||
*/ | |||
#ifdef HAL_RNG_MODULE_ENABLED | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private defines -----------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @addtogroup RNG_Private_Constants | |||
* @{ | |||
*/ | |||
#define RNG_TIMEOUT_VALUE 2 | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/* Private functions prototypes ----------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup RNG_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup RNG_Exported_Functions_Group1 | |||
* @brief Initialization and de-initialization functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Initialization and de-initialization functions ##### | |||
=============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Initialize the RNG according to the specified parameters | |||
in the RNG_InitTypeDef and create the associated handle | |||
(+) DeInitialize the RNG peripheral | |||
(+) Initialize the RNG MSP | |||
(+) DeInitialize RNG MSP | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Initializes the RNG peripheral and creates the associated handle. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng) | |||
{ | |||
/* Check the RNG handle allocation */ | |||
if(hrng == NULL) | |||
{ | |||
return HAL_ERROR; | |||
} | |||
__HAL_LOCK(hrng); | |||
if(hrng->State == HAL_RNG_STATE_RESET) | |||
{ | |||
/* Allocate lock resource and initialize it */ | |||
hrng->Lock = HAL_UNLOCKED; | |||
/* Init the low level hardware */ | |||
HAL_RNG_MspInit(hrng); | |||
} | |||
/* Change RNG peripheral state */ | |||
hrng->State = HAL_RNG_STATE_BUSY; | |||
/* Enable the RNG Peripheral */ | |||
__HAL_RNG_ENABLE(hrng); | |||
/* Initialize the RNG state */ | |||
hrng->State = HAL_RNG_STATE_READY; | |||
__HAL_UNLOCK(hrng); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief DeInitializes the RNG peripheral. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng) | |||
{ | |||
/* Check the RNG handle allocation */ | |||
if(hrng == NULL) | |||
{ | |||
return HAL_ERROR; | |||
} | |||
/* Disable the RNG Peripheral */ | |||
CLEAR_BIT(hrng->Instance->CR, RNG_CR_IE | RNG_CR_RNGEN); | |||
/* Clear RNG interrupt status flags */ | |||
CLEAR_BIT(hrng->Instance->SR, RNG_SR_CEIS | RNG_SR_SEIS); | |||
/* DeInit the low level hardware */ | |||
HAL_RNG_MspDeInit(hrng); | |||
/* Update the RNG state */ | |||
hrng->State = HAL_RNG_STATE_RESET; | |||
/* Release Lock */ | |||
__HAL_UNLOCK(hrng); | |||
/* Return the function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Initializes the RNG MSP. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval None | |||
*/ | |||
__weak void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng) | |||
{ | |||
/* NOTE : This function should not be modified. When the callback is needed, | |||
function HAL_RNG_MspInit must be implemented in the user file. | |||
*/ | |||
} | |||
/** | |||
* @brief DeInitializes the RNG MSP. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval None | |||
*/ | |||
__weak void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng) | |||
{ | |||
/* NOTE : This function should not be modified. When the callback is needed, | |||
function HAL_RNG_MspDeInit must be implemented in the user file. | |||
*/ | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup RNG_Exported_Functions_Group2 | |||
* @brief Peripheral Control functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Peripheral Control functions ##### | |||
=============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Get the 32 bit Random number | |||
(+) Get the 32 bit Random number with interrupt enabled | |||
(+) Handle RNG interrupt request | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Generates a 32-bit random number. | |||
* @note Each time the random number data is read the RNG_FLAG_DRDY flag | |||
* is automatically cleared. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @param random32bit: pointer to generated random number variable if successful. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit) | |||
{ | |||
uint32_t tickstart = 0; | |||
HAL_StatusTypeDef status = HAL_OK; | |||
/* Process Locked */ | |||
__HAL_LOCK(hrng); | |||
/* Check RNG peripheral state */ | |||
if(hrng->State == HAL_RNG_STATE_READY) | |||
{ | |||
/* Change RNG peripheral state */ | |||
hrng->State = HAL_RNG_STATE_BUSY; | |||
/* Get tick */ | |||
tickstart = HAL_GetTick(); | |||
/* Check if data register contains valid random data */ | |||
while(__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) == RESET) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > RNG_TIMEOUT_VALUE) | |||
{ | |||
hrng->State = HAL_RNG_STATE_ERROR; | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hrng); | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
/* Get a 32bit Random number */ | |||
hrng->RandomNumber = hrng->Instance->DR; | |||
*random32bit = hrng->RandomNumber; | |||
hrng->State = HAL_RNG_STATE_READY; | |||
} | |||
else | |||
{ | |||
status = HAL_ERROR; | |||
} | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hrng); | |||
return status; | |||
} | |||
/** | |||
* @brief Generates a 32-bit random number in interrupt mode. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng) | |||
{ | |||
HAL_StatusTypeDef status = HAL_OK; | |||
/* Process Locked */ | |||
__HAL_LOCK(hrng); | |||
/* Check RNG peripheral state */ | |||
if(hrng->State == HAL_RNG_STATE_READY) | |||
{ | |||
/* Change RNG peripheral state */ | |||
hrng->State = HAL_RNG_STATE_BUSY; | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hrng); | |||
/* Enable the RNG Interrupts: Data Ready, Clock error, Seed error */ | |||
__HAL_RNG_ENABLE_IT(hrng); | |||
} | |||
else | |||
{ | |||
/* Process Unlocked */ | |||
__HAL_UNLOCK(hrng); | |||
status = HAL_ERROR; | |||
} | |||
return status; | |||
} | |||
/** | |||
* @brief Handles RNG interrupt request. | |||
* @note In the case of a clock error, the RNG is no more able to generate | |||
* random numbers because the PLL48CLK clock is not correct. User has | |||
* to check that the clock controller is correctly configured to provide | |||
* the RNG clock and clear the CEIS bit using __HAL_RNG_CLEAR_IT(). | |||
* The clock error has no impact on the previously generated | |||
* random numbers, and the RNG_DR register contents can be used. | |||
* @note In the case of a seed error, the generation of random numbers is | |||
* interrupted as long as the SECS bit is '1'. If a number is | |||
* available in the RNG_DR register, it must not be used because it may | |||
* not have enough entropy. In this case, it is recommended to clear the | |||
* SEIS bit using __HAL_RNG_CLEAR_IT(), then disable and enable | |||
* the RNG peripheral to reinitialize and restart the RNG. | |||
* @note User-written HAL_RNG_ErrorCallback() API is called once whether SEIS | |||
* or CEIS are set. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval None | |||
*/ | |||
void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng) | |||
{ | |||
/* RNG clock error interrupt occurred */ | |||
if((__HAL_RNG_GET_IT(hrng, RNG_IT_CEI) != RESET) || (__HAL_RNG_GET_IT(hrng, RNG_IT_SEI) != RESET)) | |||
{ | |||
/* Change RNG peripheral state */ | |||
hrng->State = HAL_RNG_STATE_ERROR; | |||
HAL_RNG_ErrorCallback(hrng); | |||
/* Clear the clock error flag */ | |||
__HAL_RNG_CLEAR_IT(hrng, RNG_IT_CEI|RNG_IT_SEI); | |||
} | |||
/* Check RNG data ready interrupt occurred */ | |||
if(__HAL_RNG_GET_IT(hrng, RNG_IT_DRDY) != RESET) | |||
{ | |||
/* Generate random number once, so disable the IT */ | |||
__HAL_RNG_DISABLE_IT(hrng); | |||
/* Get the 32bit Random number (DRDY flag automatically cleared) */ | |||
hrng->RandomNumber = hrng->Instance->DR; | |||
if(hrng->State != HAL_RNG_STATE_ERROR) | |||
{ | |||
/* Change RNG peripheral state */ | |||
hrng->State = HAL_RNG_STATE_READY; | |||
/* Data Ready callback */ | |||
HAL_RNG_ReadyDataCallback(hrng, hrng->RandomNumber); | |||
} | |||
} | |||
} | |||
/** | |||
* @brief Returns generated random number in polling mode (Obsolete) | |||
* Use HAL_RNG_GenerateRandomNumber() API instead. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval Random value | |||
*/ | |||
uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng) | |||
{ | |||
if(HAL_RNG_GenerateRandomNumber(hrng, &(hrng->RandomNumber)) == HAL_OK) | |||
{ | |||
return hrng->RandomNumber; | |||
} | |||
else | |||
{ | |||
return 0; | |||
} | |||
} | |||
/** | |||
* @brief Returns a 32-bit random number with interrupt enabled (Obsolete), | |||
* Use HAL_RNG_GenerateRandomNumber_IT() API instead. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval 32-bit random number | |||
*/ | |||
uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng) | |||
{ | |||
uint32_t random32bit = 0; | |||
/* Process locked */ | |||
__HAL_LOCK(hrng); | |||
/* Change RNG peripheral state */ | |||
hrng->State = HAL_RNG_STATE_BUSY; | |||
/* Get a 32bit Random number */ | |||
random32bit = hrng->Instance->DR; | |||
/* Enable the RNG Interrupts: Data Ready, Clock error, Seed error */ | |||
__HAL_RNG_ENABLE_IT(hrng); | |||
/* Return the 32 bit random number */ | |||
return random32bit; | |||
} | |||
/** | |||
* @brief Read latest generated random number. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval random value | |||
*/ | |||
uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng) | |||
{ | |||
return(hrng->RandomNumber); | |||
} | |||
/** | |||
* @brief Data Ready callback in non-blocking mode. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @param random32bit: generated random number. | |||
* @retval None | |||
*/ | |||
__weak void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit) | |||
{ | |||
/* NOTE : This function should not be modified. When the callback is needed, | |||
function HAL_RNG_ReadyDataCallback must be implemented in the user file. | |||
*/ | |||
} | |||
/** | |||
* @brief RNG error callbacks. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval None | |||
*/ | |||
__weak void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng) | |||
{ | |||
/* NOTE : This function should not be modified. When the callback is needed, | |||
function HAL_RNG_ErrorCallback must be implemented in the user file. | |||
*/ | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup RNG_Exported_Functions_Group3 | |||
* @brief Peripheral State functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Peripheral State functions ##### | |||
=============================================================================== | |||
[..] | |||
This subsection permits to get in run-time the status of the peripheral | |||
and the data flow. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Returns the RNG state. | |||
* @param hrng: pointer to a RNG_HandleTypeDef structure that contains | |||
* the configuration information for RNG. | |||
* @retval HAL state | |||
*/ | |||
HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng) | |||
{ | |||
return hrng->State; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_RNG_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,510 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32f7xx_ll_sdmmc.c | |||
* @author MCD Application Team | |||
* @version V1.0.1 | |||
* @date 25-June-2015 | |||
* @brief SDMMC Low Layer HAL module driver. | |||
* | |||
* This file provides firmware functions to manage the following | |||
* functionalities of the SDMMC peripheral: | |||
* + Initialization/de-initialization functions | |||
* + I/O operation functions | |||
* + Peripheral Control functions | |||
* + Peripheral State functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### SDMMC peripheral features ##### | |||
============================================================================== | |||
[..] The SD/SDMMC MMC card host interface (SDMMC) provides an interface between the APB2 | |||
peripheral bus and MultiMedia cards (MMCs), SD memory cards, SDMMC cards and CE-ATA | |||
devices. | |||
[..] The SDMMC features include the following: | |||
(+) Full compliance with MultiMedia Card System Specification Version 4.2. Card support | |||
for three different databus modes: 1-bit (default), 4-bit and 8-bit | |||
(+) Full compatibility with previous versions of MultiMedia Cards (forward compatibility) | |||
(+) Full compliance with SD Memory Card Specifications Version 2.0 | |||
(+) Full compliance with SD I/O Card Specification Version 2.0: card support for two | |||
different data bus modes: 1-bit (default) and 4-bit | |||
(+) Full support of the CE-ATA features (full compliance with CE-ATA digital protocol | |||
Rev1.1) | |||
(+) Data transfer up to 48 MHz for the 8 bit mode | |||
(+) Data and command output enable signals to control external bidirectional drivers. | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] | |||
This driver is a considered as a driver of service for external devices drivers | |||
that interfaces with the SDMMC peripheral. | |||
According to the device used (SD card/ MMC card / SDMMC card ...), a set of APIs | |||
is used in the device's driver to perform SDMMC operations and functionalities. | |||
This driver is almost transparent for the final user, it is only used to implement other | |||
functionalities of the external device. | |||
[..] | |||
(+) The SDMMC clock (SDMMCCLK = 48 MHz) is coming from a specific output of PLL | |||
(PLL48CLK). Before start working with SDMMC peripheral make sure that the | |||
PLL is well configured. | |||
The SDMMC peripheral uses two clock signals: | |||
(++) SDMMC adapter clock (SDMMCCLK = 48 MHz) | |||
(++) APB2 bus clock (PCLK2) | |||
-@@- PCLK2 and SDMMC_CK clock frequencies must respect the following condition: | |||
Frequency(PCLK2) >= (3 / 8 x Frequency(SDMMC_CK)) | |||
(+) Enable/Disable peripheral clock using RCC peripheral macros related to SDMMC | |||
peripheral. | |||
(+) Enable the Power ON State using the SDMMC_PowerState_ON(SDMMCx) | |||
function and disable it using the function SDMMC_PowerState_OFF(SDMMCx). | |||
(+) Enable/Disable the clock using the __SDMMC_ENABLE()/__SDMMC_DISABLE() macros. | |||
(+) Enable/Disable the peripheral interrupts using the macros __SDMMC_ENABLE_IT(hSDMMC, IT) | |||
and __SDMMC_DISABLE_IT(hSDMMC, IT) if you need to use interrupt mode. | |||
(+) When using the DMA mode | |||
(++) Configure the DMA in the MSP layer of the external device | |||
(++) Active the needed channel Request | |||
(++) Enable the DMA using __SDMMC_DMA_ENABLE() macro or Disable it using the macro | |||
__SDMMC_DMA_DISABLE(). | |||
(+) To control the CPSM (Command Path State Machine) and send | |||
commands to the card use the SDMMC_SendCommand(SDMMCx), | |||
SDMMC_GetCommandResponse() and SDMMC_GetResponse() functions. First, user has | |||
to fill the command structure (pointer to SDMMC_CmdInitTypeDef) according | |||
to the selected command to be sent. | |||
The parameters that should be filled are: | |||
(++) Command Argument | |||
(++) Command Index | |||
(++) Command Response type | |||
(++) Command Wait | |||
(++) CPSM Status (Enable or Disable). | |||
-@@- To check if the command is well received, read the SDMMC_CMDRESP | |||
register using the SDMMC_GetCommandResponse(). | |||
The SDMMC responses registers (SDMMC_RESP1 to SDMMC_RESP2), use the | |||
SDMMC_GetResponse() function. | |||
(+) To control the DPSM (Data Path State Machine) and send/receive | |||
data to/from the card use the SDMMC_DataConfig(), SDMMC_GetDataCounter(), | |||
SDMMC_ReadFIFO(), DIO_WriteFIFO() and SDMMC_GetFIFOCount() functions. | |||
*** Read Operations *** | |||
======================= | |||
[..] | |||
(#) First, user has to fill the data structure (pointer to | |||
SDMMC_DataInitTypeDef) according to the selected data type to be received. | |||
The parameters that should be filled are: | |||
(++) Data TimeOut | |||
(++) Data Length | |||
(++) Data Block size | |||
(++) Data Transfer direction: should be from card (To SDMMC) | |||
(++) Data Transfer mode | |||
(++) DPSM Status (Enable or Disable) | |||
(#) Configure the SDMMC resources to receive the data from the card | |||
according to selected transfer mode (Refer to Step 8, 9 and 10). | |||
(#) Send the selected Read command (refer to step 11). | |||
(#) Use the SDMMC flags/interrupts to check the transfer status. | |||
*** Write Operations *** | |||
======================== | |||
[..] | |||
(#) First, user has to fill the data structure (pointer to | |||
SDMMC_DataInitTypeDef) according to the selected data type to be received. | |||
The parameters that should be filled are: | |||
(++) Data TimeOut | |||
(++) Data Length | |||
(++) Data Block size | |||
(++) Data Transfer direction: should be to card (To CARD) | |||
(++) Data Transfer mode | |||
(++) DPSM Status (Enable or Disable) | |||
(#) Configure the SDMMC resources to send the data to the card according to | |||
selected transfer mode. | |||
(#) Send the selected Write command. | |||
(#) Use the SDMMC flags/interrupts to check the transfer status. | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32f7xx_hal.h" | |||
/** @addtogroup STM32F7xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup SDMMC_LL SDMMC Low Layer | |||
* @brief Low layer module for SD | |||
* @{ | |||
*/ | |||
#if defined (HAL_SD_MODULE_ENABLED) || defined(HAL_MMC_MODULE_ENABLED) | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup SDMMC_LL_Exported_Functions SDMMC Low Layer Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup HAL_SDMMC_LL_Group1 Initialization de-initialization functions | |||
* @brief Initialization and Configuration functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Initialization/de-initialization functions ##### | |||
=============================================================================== | |||
[..] This section provides functions allowing to: | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Initializes the SDMMC according to the specified | |||
* parameters in the SDMMC_InitTypeDef and create the associated handle. | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @param Init: SDMMC initialization structure | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef SDMMC_Init(SDMMC_TypeDef *SDMMCx, SDMMC_InitTypeDef Init) | |||
{ | |||
uint32_t tmpreg = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_SDMMC_ALL_INSTANCE(SDMMCx)); | |||
assert_param(IS_SDMMC_CLOCK_EDGE(Init.ClockEdge)); | |||
assert_param(IS_SDMMC_CLOCK_BYPASS(Init.ClockBypass)); | |||
assert_param(IS_SDMMC_CLOCK_POWER_SAVE(Init.ClockPowerSave)); | |||
assert_param(IS_SDMMC_BUS_WIDE(Init.BusWide)); | |||
assert_param(IS_SDMMC_HARDWARE_FLOW_CONTROL(Init.HardwareFlowControl)); | |||
assert_param(IS_SDMMC_CLKDIV(Init.ClockDiv)); | |||
/* Set SDMMC configuration parameters */ | |||
tmpreg |= (Init.ClockEdge |\ | |||
Init.ClockBypass |\ | |||
Init.ClockPowerSave |\ | |||
Init.BusWide |\ | |||
Init.HardwareFlowControl |\ | |||
Init.ClockDiv | |||
); | |||
/* Write to SDMMC CLKCR */ | |||
MODIFY_REG(SDMMCx->CLKCR, CLKCR_CLEAR_MASK, tmpreg); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup HAL_SDMMC_LL_Group2 IO operation functions | |||
* @brief Data transfers functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### I/O operation functions ##### | |||
=============================================================================== | |||
[..] | |||
This subsection provides a set of functions allowing to manage the SDMMC data | |||
transfers. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Read data (word) from Rx FIFO in blocking mode (polling) | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @retval HAL status | |||
*/ | |||
uint32_t SDMMC_ReadFIFO(SDMMC_TypeDef *SDMMCx) | |||
{ | |||
/* Read data from Rx FIFO */ | |||
return (SDMMCx->FIFO); | |||
} | |||
/** | |||
* @brief Write data (word) to Tx FIFO in blocking mode (polling) | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @param pWriteData: pointer to data to write | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef SDMMC_WriteFIFO(SDMMC_TypeDef *SDMMCx, uint32_t *pWriteData) | |||
{ | |||
/* Write data to FIFO */ | |||
SDMMCx->FIFO = *pWriteData; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup HAL_SDMMC_LL_Group3 Peripheral Control functions | |||
* @brief management functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Peripheral Control functions ##### | |||
=============================================================================== | |||
[..] | |||
This subsection provides a set of functions allowing to control the SDMMC data | |||
transfers. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Set SDMMC Power state to ON. | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef SDMMC_PowerState_ON(SDMMC_TypeDef *SDMMCx) | |||
{ | |||
/* Set power state to ON */ | |||
SDMMCx->POWER = SDMMC_POWER_PWRCTRL; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Set SDMMC Power state to OFF. | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef SDMMC_PowerState_OFF(SDMMC_TypeDef *SDMMCx) | |||
{ | |||
/* Set power state to OFF */ | |||
SDMMCx->POWER = (uint32_t)0x00000000; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Get SDMMC Power state. | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @retval Power status of the controller. The returned value can be one of the | |||
* following values: | |||
* - 0x00: Power OFF | |||
* - 0x02: Power UP | |||
* - 0x03: Power ON | |||
*/ | |||
uint32_t SDMMC_GetPowerState(SDMMC_TypeDef *SDMMCx) | |||
{ | |||
return (SDMMCx->POWER & SDMMC_POWER_PWRCTRL); | |||
} | |||
/** | |||
* @brief Configure the SDMMC command path according to the specified parameters in | |||
* SDMMC_CmdInitTypeDef structure and send the command | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @param Command: pointer to a SDMMC_CmdInitTypeDef structure that contains | |||
* the configuration information for the SDMMC command | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef SDMMC_SendCommand(SDMMC_TypeDef *SDMMCx, SDMMC_CmdInitTypeDef *Command) | |||
{ | |||
uint32_t tmpreg = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_SDMMC_CMD_INDEX(Command->CmdIndex)); | |||
assert_param(IS_SDMMC_RESPONSE(Command->Response)); | |||
assert_param(IS_SDMMC_WAIT(Command->WaitForInterrupt)); | |||
assert_param(IS_SDMMC_CPSM(Command->CPSM)); | |||
/* Set the SDMMC Argument value */ | |||
SDMMCx->ARG = Command->Argument; | |||
/* Set SDMMC command parameters */ | |||
tmpreg |= (uint32_t)(Command->CmdIndex |\ | |||
Command->Response |\ | |||
Command->WaitForInterrupt |\ | |||
Command->CPSM); | |||
/* Write to SDMMC CMD register */ | |||
MODIFY_REG(SDMMCx->CMD, CMD_CLEAR_MASK, tmpreg); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Return the command index of last command for which response received | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @retval Command index of the last command response received | |||
*/ | |||
uint8_t SDMMC_GetCommandResponse(SDMMC_TypeDef *SDMMCx) | |||
{ | |||
return (uint8_t)(SDMMCx->RESPCMD); | |||
} | |||
/** | |||
* @brief Return the response received from the card for the last command | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @param Response: Specifies the SDMMC response register. | |||
* This parameter can be one of the following values: | |||
* @arg SDMMC_RESP1: Response Register 1 | |||
* @arg SDMMC_RESP2: Response Register 2 | |||
* @arg SDMMC_RESP3: Response Register 3 | |||
* @arg SDMMC_RESP4: Response Register 4 | |||
* @retval The Corresponding response register value | |||
*/ | |||
uint32_t SDMMC_GetResponse(SDMMC_TypeDef *SDMMCx, uint32_t Response) | |||
{ | |||
__IO uint32_t tmp = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_SDMMC_RESP(Response)); | |||
/* Get the response */ | |||
tmp = (uint32_t)&(SDMMCx->RESP1) + Response; | |||
return (*(__IO uint32_t *) tmp); | |||
} | |||
/** | |||
* @brief Configure the SDMMC data path according to the specified | |||
* parameters in the SDMMC_DataInitTypeDef. | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @param Data : pointer to a SDMMC_DataInitTypeDef structure | |||
* that contains the configuration information for the SDMMC data. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef SDMMC_DataConfig(SDMMC_TypeDef *SDMMCx, SDMMC_DataInitTypeDef* Data) | |||
{ | |||
uint32_t tmpreg = 0; | |||
/* Check the parameters */ | |||
assert_param(IS_SDMMC_DATA_LENGTH(Data->DataLength)); | |||
assert_param(IS_SDMMC_BLOCK_SIZE(Data->DataBlockSize)); | |||
assert_param(IS_SDMMC_TRANSFER_DIR(Data->TransferDir)); | |||
assert_param(IS_SDMMC_TRANSFER_MODE(Data->TransferMode)); | |||
assert_param(IS_SDMMC_DPSM(Data->DPSM)); | |||
/* Set the SDMMC Data TimeOut value */ | |||
SDMMCx->DTIMER = Data->DataTimeOut; | |||
/* Set the SDMMC DataLength value */ | |||
SDMMCx->DLEN = Data->DataLength; | |||
/* Set the SDMMC data configuration parameters */ | |||
tmpreg |= (uint32_t)(Data->DataBlockSize |\ | |||
Data->TransferDir |\ | |||
Data->TransferMode |\ | |||
Data->DPSM); | |||
/* Write to SDMMC DCTRL */ | |||
MODIFY_REG(SDMMCx->DCTRL, DCTRL_CLEAR_MASK, tmpreg); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Returns number of remaining data bytes to be transferred. | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @retval Number of remaining data bytes to be transferred | |||
*/ | |||
uint32_t SDMMC_GetDataCounter(SDMMC_TypeDef *SDMMCx) | |||
{ | |||
return (SDMMCx->DCOUNT); | |||
} | |||
/** | |||
* @brief Get the FIFO data | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @retval Data received | |||
*/ | |||
uint32_t SDMMC_GetFIFOCount(SDMMC_TypeDef *SDMMCx) | |||
{ | |||
return (SDMMCx->FIFO); | |||
} | |||
/** | |||
* @brief Sets one of the two options of inserting read wait interval. | |||
* @param SDMMCx: Pointer to SDMMC register base | |||
* @param SDMMC_ReadWaitMode: SDMMC Read Wait operation mode. | |||
* This parameter can be: | |||
* @arg SDMMC_READ_WAIT_MODE_CLK: Read Wait control by stopping SDMMCCLK | |||
* @arg SDMMC_READ_WAIT_MODE_DATA2: Read Wait control using SDMMC_DATA2 | |||
* @retval None | |||
*/ | |||
HAL_StatusTypeDef SDMMC_SetSDMMCReadWaitMode(SDMMC_TypeDef *SDMMCx, uint32_t SDMMC_ReadWaitMode) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_SDMMC_READWAIT_MODE(SDMMC_ReadWaitMode)); | |||
/* Set SDMMC read wait mode */ | |||
SDMMCx->DCTRL |= SDMMC_ReadWaitMode; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* (HAL_SD_MODULE_ENABLED) || (HAL_MMC_MODULE_ENABLED) */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |