2 ******************************************************************************
3 * @file stm32h7xx_hal_otfdec.h
4 * @author MCD Application Team
5 * @brief Header file of OTFDEC HAL module.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2018 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef __STM32H7xx_HAL_OTFDEC_H
22 #define __STM32H7xx_HAL_OTFDEC_H
29 /* Includes ------------------------------------------------------------------*/
30 #include "stm32h7xx_hal_def.h"
32 /** @addtogroup STM32H7xx_HAL_Driver
36 /** @addtogroup OTFDEC
40 /* Exported types ------------------------------------------------------------*/
42 /** @defgroup OTFDEC_Exported_Types OTFDEC Exported Types
46 /** @defgroup OTFDEC_Exported_Types_Group1 OTFDEC region configuration definitions
51 * @brief OTFDEC region configuration structure definition
55 uint32_t Nonce
[2]; /*!< OTFDEC region nonce */
57 uint32_t StartAddress
; /*!< OTFDEC region start address */
59 uint32_t EndAddress
; /*!< OTFDEC region end address */
61 uint16_t Version
; /*!< OTFDEC region firmware version */
63 }OTFDEC_RegionConfigTypeDef
;
69 /** @defgroup OTFDEC_Exported_Types_Group2 OTFDEC Peripheral handle definitions
74 * @brief OTFDEC states structure definition
78 HAL_OTFDEC_STATE_RESET
= 0x00U
, /*!< OTFDEC not yet initialized or disabled */
79 HAL_OTFDEC_STATE_READY
= 0x01U
, /*!< OTFDEC initialized and ready for use */
80 HAL_OTFDEC_STATE_BUSY
= 0x02U
, /*!< OTFDEC internal processing is ongoing */
81 }HAL_OTFDEC_StateTypeDef
;
84 * @brief OTFDEC handle structure definition
86 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
87 typedef struct __OTFDEC_HandleTypeDef
90 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
92 OTFDEC_TypeDef
*Instance
; /*!< OTFDEC registers base address */
94 HAL_OTFDEC_StateTypeDef State
; /*!< OTFDEC state */
96 HAL_LockTypeDef Lock
; /*!< OTFDEC locking object */
98 __IO
uint32_t ErrorCode
; /*!< OTFDEC error code */
100 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
101 void (* ErrorCallback
)(struct __OTFDEC_HandleTypeDef
*hotfdec
); /*!< OTFDEC error callback */
103 void (* MspInitCallback
)(struct __OTFDEC_HandleTypeDef
*hotfdec
); /*!< OTFDEC Msp Init callback */
105 void (* MspDeInitCallback
)(struct __OTFDEC_HandleTypeDef
*hotfdec
); /*!< OTFDEC Msp DeInit callback */
106 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
108 }OTFDEC_HandleTypeDef
;
110 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
112 * @brief HAL OTFDEC Callback ID enumeration definition
116 HAL_OTFDEC_ERROR_CB_ID
= 0x00U
, /*!< OTFDEC error callback ID */
117 HAL_OTFDEC_MSPINIT_CB_ID
= 0x01U
, /*!< OTFDEC Msp DeInit callback ID */
118 HAL_OTFDEC_MSPDEINIT_CB_ID
= 0x02U
/*!< OTFDEC Msp DeInit callback ID */
119 } HAL_OTFDEC_CallbackIDTypeDef
;
122 * @brief HAL OTFDEC Callback pointer definition
124 typedef void (*pOTFDEC_CallbackTypeDef
)(OTFDEC_HandleTypeDef
*hotfdec
); /*!< pointer to a OTFDEC callback function */
126 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
136 /* Exported constants --------------------------------------------------------*/
137 /** @defgroup OTFDEC_Exported_Constants OTFDEC Exported Constants
141 /** @defgroup OTFDEC_Interrupts OTFDEC Interrupts
144 #define OTFDEC_SEC_ERROR_INT (OTFDEC_IER_SEIE ) /*!< OTFDEC security error interrupt */
145 #define OTFDEC_EXE_ERROR_INT ( OTFDEC_IER_XONEIE ) /*!< OTFDEC execution error interrupt */
146 #define OTFDEC_KEY_ERROR_INT ( OTFDEC_IER_KEIE) /*!< OTFDEC key error interrupt */
147 #define OTFDEC_SEC_EXE_ERROR_INT (OTFDEC_IER_SEIE|OTFDEC_IER_XONEIE ) /*!< OTFDEC security and execution errors interrupts */
148 #define OTFDEC_SEC_KEY_ERROR_INT (OTFDEC_IER_SEIE| OTFDEC_IER_KEIE) /*!< OTFDEC security and key errors interrupts */
149 #define OTFDEC_EXE_KEY_ERROR_INT ( OTFDEC_IER_XONEIE|OTFDEC_IER_KEIE) /*!< OTFDEC execution and key errors interrupts */
150 #define OTFDEC_ALL_INT (OTFDEC_IER_SEIE|OTFDEC_IER_XONEIE|OTFDEC_IER_KEIE) /*!< OTFDEC all interrupts */
155 /** @defgroup OTFDEC_Region_Enable OTFDEC Region Enable
158 #define OTFDEC_REG_CONFIGR_REG_DISABLE 0x00000000U /*!< OTFDEC region encryption or on-the-fly decryption disable */
159 #define OTFDEC_REG_CONFIGR_REG_ENABLE OTFDEC_REG_CONFIGR_REG_EN /*!< OTFDEC region encryption or on-the-fly decryption enable */
164 /** @defgroup OTFDEC_Region_Configuration_Lock OTFDEC Region Configuration Lock
167 #define OTFDEC_REG_CONFIGR_LOCK_DISABLE 0x00000000U /*!< OTFDEC region configuration lock disable */
168 #define OTFDEC_REG_CONFIGR_LOCK_ENABLE OTFDEC_REG_CONFIGR_CONFIGLOCK /*!< OTFDEC region configuration lock enable */
173 /** @defgroup OTFDEC_Region_Operating_Mode OTFDEC Region Operating Mode
176 #define OTFDEC_REG_MODE_INSTRUCTION_ACCESSES_ONLY 0x00000000U /*!< Only instruction accesses are decrypted */
177 #define OTFDEC_REG_MODE_DATA_ACCESSES_ONLY OTFDEC_REG_CONFIGR_MODE_0 /*!< Only data accesses are decrypted */
178 #define OTFDEC_REG_MODE_INSTRUCTION_OR_DATA_ACCESSES OTFDEC_REG_CONFIGR_MODE_1 /*!< All read accesses are decrypted */
179 #define OTFDEC_REG_MODE_INSTRUCTION_ACCESSES_ONLY_WITH_CIPHER OTFDEC_REG_CONFIGR_MODE /*!< Only instruction accesses are decrypted with proprietary cipher activated */
184 /** @defgroup OTFDEC_Error_Definition OTFDEC Error Definition
187 #define HAL_OTFDEC_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
188 #define HAL_OTFDEC_SECURITY_ERROR ((uint32_t)0x00000001U) /*!< Security error */
189 #define HAL_OTFDEC_EXECUTE_ERROR ((uint32_t)0x00000002U) /*!< Execute-only Execute-Never error */
190 #define HAL_OTFDEC_KEY_ERROR ((uint32_t)0x00000004U) /*!< Key error */
191 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
192 #define HAL_OTFDEC_ERROR_INVALID_CALLBACK ((uint32_t)0x00000008U) /*!< Invalid Callback error */
193 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
198 /** @defgroup OTFDEC_Regions_Index OTFDEC Regions Index
201 #define OTFDEC_REGION1 ((uint32_t)0x00000000U) /*!< OTFDEC region 1 */
202 #define OTFDEC_REGION2 ((uint32_t)0x00000001U) /*!< OTFDEC region 2 */
203 #define OTFDEC_REGION3 ((uint32_t)0x00000002U) /*!< OTFDEC region 3 */
204 #define OTFDEC_REGION4 ((uint32_t)0x00000003U) /*!< OTFDEC region 4 */
213 /* Exported macro ------------------------------------------------------------*/
214 /** @defgroup OTFDEC_Exported_Macros OTFDEC Exported Macros
218 /** @brief Reset OTFDEC handle state.
219 * @param __HANDLE__ pointer to an OTFDEC_HandleTypeDef structure that contains
220 * the configuration information for OTFDEC module
223 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
224 #define __HAL_OTFDEC_RESET_HANDLE_STATE(__HANDLE__) \
226 (__HANDLE__)->State = HAL_OTFDEC_STATE_RESET; \
227 (__HANDLE__)->MspInitCallback = NULL; \
228 (__HANDLE__)->MspDeInitCallback = NULL; \
231 #define __HAL_OTFDEC_RESET_HANDLE_STATE(__HANDLE__) \
232 ((__HANDLE__)->State = HAL_OTFDEC_STATE_RESET)
233 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
236 * @brief Enable OTFDEC peripheral interrupts combination
237 * @param __HANDLE__ pointer to an OTFDEC_HandleTypeDef structure that contains
238 * the configuration information for OTFDEC module
239 * @param __INTERRUPT__ mask on enabled interrupts
240 * This parameter can be one of the following values:
241 * @arg @ref OTFDEC_SEC_ERROR_INT OTFDEC security error interrupt
242 * @arg @ref OTFDEC_EXE_ERROR_INT OTFDEC execution error interrupt
243 * @arg @ref OTFDEC_KEY_ERROR_INT OTFDEC key error interrupt
244 * @arg @ref OTFDEC_SEC_EXE_ERROR_INT OTFDEC security and execution errors interrupts
245 * @arg @ref OTFDEC_SEC_KEY_ERROR_INT OTFDEC security and key errors interrupts
246 * @arg @ref OTFDEC_EXE_KEY_ERROR_INT OTFDEC execution and key errors interrupts
247 * @arg @ref OTFDEC_ALL_INT OTFDEC all interrupts
250 #define __HAL_OTFDEC_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT(((__HANDLE__)->Instance->IER), (__INTERRUPT__))
253 * @brief Disable OTFDEC peripheral interrupts combination
254 * @param __HANDLE__ pointer to an OTFDEC_HandleTypeDef structure that contains
255 * the configuration information for OTFDEC module
256 * @param __INTERRUPT__ mask on disabled interrupts
257 * This parameter can be one of the following values:
258 * @arg @ref OTFDEC_SEC_ERROR_INT OTFDEC security error interrupt
259 * @arg @ref OTFDEC_EXE_ERROR_INT OTFDEC execution error interrupt
260 * @arg @ref OTFDEC_KEY_ERROR_INT OTFDEC key error interrupt
261 * @arg @ref OTFDEC_SEC_EXE_ERROR_INT OTFDEC security and execution errors interrupts
262 * @arg @ref OTFDEC_SEC_KEY_ERROR_INT OTFDEC security and key errors interrupts
263 * @arg @ref OTFDEC_EXE_KEY_ERROR_INT OTFDEC execution and key errors interrupts
264 * @arg @ref OTFDEC_ALL_INT OTFDEC all interrupts
267 #define __HAL_OTFDEC_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT(((__HANDLE__)->Instance->IER), (__INTERRUPT__))
273 /* Exported functions --------------------------------------------------------*/
274 /** @defgroup OTFDEC_Exported_Functions OTFDEC Exported Functions
278 /** @addtogroup OTFDEC_Exported_Functions_Group1 Initialization and de-initialization functions
281 HAL_StatusTypeDef
HAL_OTFDEC_Init(OTFDEC_HandleTypeDef
*hotfdec
);
282 HAL_StatusTypeDef
HAL_OTFDEC_DeInit(OTFDEC_HandleTypeDef
*hotfdec
);
283 void HAL_OTFDEC_MspInit(OTFDEC_HandleTypeDef
*hotfdec
);
284 void HAL_OTFDEC_MspDeInit(OTFDEC_HandleTypeDef
*hotfdec
);
286 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
287 /* Callbacks Register/UnRegister functions ***********************************/
288 HAL_StatusTypeDef
HAL_OTFDEC_RegisterCallback(OTFDEC_HandleTypeDef
*hotfdec
, HAL_OTFDEC_CallbackIDTypeDef CallbackID
,
289 pOTFDEC_CallbackTypeDef pCallback
);
290 HAL_StatusTypeDef
HAL_OTFDEC_UnRegisterCallback(OTFDEC_HandleTypeDef
*hotfdec
, HAL_OTFDEC_CallbackIDTypeDef CallbackID
);
291 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
297 /** @addtogroup OTFDEC_Exported_Functions_Group2 OTFDEC IRQ handler management
300 void HAL_OTFDEC_IRQHandler(OTFDEC_HandleTypeDef
*hotfdec
);
301 void HAL_OTFDEC_ErrorCallback(OTFDEC_HandleTypeDef
*hotfdec
);
306 /** @addtogroup OTFDEC_Exported_Functions_Group3 Peripheral Control functions
309 HAL_StatusTypeDef
HAL_OTFDEC_RegionKeyLock(OTFDEC_HandleTypeDef
*hotfdec
, uint32_t RegionIndex
);
310 HAL_StatusTypeDef
HAL_OTFDEC_RegionSetKey(OTFDEC_HandleTypeDef
*hotfdec
, uint32_t RegionIndex
, uint32_t *pKey
);
311 HAL_StatusTypeDef
HAL_OTFDEC_RegionSetMode(OTFDEC_HandleTypeDef
*hotfdec
, uint32_t RegionIndex
, uint32_t mode
);
312 HAL_StatusTypeDef
HAL_OTFDEC_RegionConfig(OTFDEC_HandleTypeDef
*hotfdec
, uint32_t RegionIndex
, OTFDEC_RegionConfigTypeDef
*Config
, uint32_t lock
);
313 uint32_t HAL_OTFDEC_KeyCRCComputation(uint32_t *pKey
);
314 HAL_StatusTypeDef
HAL_OTFDEC_RegionEnable(OTFDEC_HandleTypeDef
*hotfdec
, uint32_t RegionIndex
);
315 HAL_StatusTypeDef
HAL_OTFDEC_RegionDisable(OTFDEC_HandleTypeDef
*hotfdec
, uint32_t RegionIndex
);
320 /** @addtogroup @addtogroup OTFDEC_Exported_Functions_Group4 Peripheral State and Status functions
323 HAL_OTFDEC_StateTypeDef
HAL_OTFDEC_GetState(OTFDEC_HandleTypeDef
*hotfdec
);
324 uint32_t HAL_OTFDEC_RegionGetKeyCRC(OTFDEC_HandleTypeDef
*hotfdec
, uint32_t RegionIndex
);
325 HAL_StatusTypeDef
HAL_OTFDEC_RegionGetConfig(OTFDEC_HandleTypeDef
*hotfdec
, uint32_t RegionIndex
, OTFDEC_RegionConfigTypeDef
*Config
);
334 /* Private types -------------------------------------------------------------*/
335 /** @defgroup OTFDEC_Private_Types OTFDEC Private Types
343 /* Private variables ---------------------------------------------------------*/
344 /** @defgroup OTFDEC_Private_Variables OTFDEC Private Variables
352 /* Private constants ---------------------------------------------------------*/
353 /** @defgroup OTFDEC_Private_Constants OTFDEC Private Constants
360 /* Private macros ------------------------------------------------------------*/
361 /** @defgroup OTFDEC_Private_Macros OTFDEC Private Macros
366 * @brief Verify the OTFDEC peripheral interrupts parameter.
367 * @param __INT__ OTFDEC peripheral set of interrupts parameter
368 * @retval SET (__INT__ is valid) or RESET (__INT__ is invalid)
370 #define IS_OTFDEC_INTERRUPTS(__INT__) (((__INT__) == OTFDEC_SEC_ERROR_INT) || \
371 ((__INT__) == OTFDEC_EXE_ERROR_INT) || \
372 ((__INT__) == OTFDEC_KEY_ERROR_INT) || \
373 ((__INT__) == OTFDEC_SEC_EXE_ERROR_INT) || \
374 ((__INT__) == OTFDEC_SEC_KEY_ERROR_INT) || \
375 ((__INT__) == OTFDEC_EXE_KEY_ERROR_INT) || \
376 ((__INT__) == OTFDEC_ALL_INT) )
379 * @brief Verify the OTFDEC region configuration lock parameter.
380 * @param __LOCK__ OTFDEC region lock parameter.
381 * @retval SET (__LOCK__ is valid) or RESET (__LOCK__ is invalid)
383 #define IS_OTFDEC_REGION_CONFIG_LOCK(__LOCK__) (((__LOCK__) == OTFDEC_REG_CONFIGR_LOCK_DISABLE) || \
384 ((__LOCK__) == OTFDEC_REG_CONFIGR_LOCK_ENABLE) )
387 * @brief Verify the OTFDEC region operating mode.
388 * @param __MODE__ OTFDEC region operating mode parameter.
389 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
391 #define IS_OTFDEC_REGION_OPERATING_MODE(__MODE__) (((__MODE__) == OTFDEC_REG_MODE_INSTRUCTION_ACCESSES_ONLY) || \
392 ((__MODE__) == OTFDEC_REG_MODE_DATA_ACCESSES_ONLY) || \
393 ((__MODE__) == OTFDEC_REG_MODE_INSTRUCTION_OR_DATA_ACCESSES) || \
394 ((__MODE__) == OTFDEC_REG_MODE_INSTRUCTION_ACCESSES_ONLY_WITH_CIPHER))
397 * @brief Verify the OTFDEC region index.
398 * @param __INDEX__ OTFDEC region index
399 * @retval SET (__INDEX__ is valid) or RESET (__INDEX__ is invalid)
401 #define IS_OTFDEC_REGIONINDEX(__INDEX__) (((__INDEX__) == OTFDEC_REGION1) || \
402 ((__INDEX__) == OTFDEC_REGION2) || \
403 ((__INDEX__) == OTFDEC_REGION3) || \
404 ((__INDEX__) == OTFDEC_REGION4) )
407 * @brief Verify the OTFDEC configuration attributes.
408 * @param __ATTRIBUTE__ OTFDEC region index
409 * @retval SET (__ATTRIBUTE__ is valid) or RESET (__ATTRIBUTE__ is invalid)
411 #define IS_OTFDEC_ATTRIBUTE(__ATTRIBUTE__) (((__ATTRIBUTE__) == OTFDEC_ATTRIBUTE_PRIV) || \
412 ((__ATTRIBUTE__) == OTFDEC_ATTRIBUTE_NPRIV) )
418 /* Private functions ---------------------------------------------------------*/
419 /** @defgroup OTFDEC_Private_Functions OTFDEC Private Functions
441 #endif /* __STM32H7xx_HAL_OTFDEC_H */
443 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/