STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_firewall.h 00004 * @author MCD Application Team 00005 * @brief Header file of FIREWALL HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 00019 /* Define to prevent recursive inclusion -------------------------------------*/ 00020 #ifndef STM32L4xx_HAL_FIREWALL_H 00021 #define STM32L4xx_HAL_FIREWALL_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm32l4xx_hal_def.h" 00029 00030 /** @addtogroup STM32L4xx_HAL_Driver 00031 * @{ 00032 */ 00033 00034 /** @addtogroup FIREWALL FIREWALL 00035 * @{ 00036 */ 00037 00038 /* Exported types ------------------------------------------------------------*/ 00039 /** @defgroup FIREWALL_Exported_Types FIREWALL Exported Types 00040 * @{ 00041 */ 00042 00043 /** 00044 * @brief FIREWALL Initialization Structure definition 00045 */ 00046 typedef struct 00047 { 00048 uint32_t CodeSegmentStartAddress; /*!< Protected code segment start address. This value is 24-bit long, the 8 LSB bits are 00049 reserved and forced to 0 in order to allow a 256-byte granularity. */ 00050 00051 uint32_t CodeSegmentLength; /*!< Protected code segment length in bytes. This value is 22-bit long, the 8 LSB bits are 00052 reserved and forced to 0 for the length to be a multiple of 256 bytes. */ 00053 00054 uint32_t NonVDataSegmentStartAddress; /*!< Protected non-volatile data segment start address. This value is 24-bit long, the 8 LSB 00055 bits are reserved and forced to 0 in order to allow a 256-byte granularity. */ 00056 00057 uint32_t NonVDataSegmentLength; /*!< Protected non-volatile data segment length in bytes. This value is 22-bit long, the 8 LSB 00058 bits are reserved and forced to 0 for the length to be a multiple of 256 bytes. */ 00059 00060 uint32_t VDataSegmentStartAddress; /*!< Protected volatile data segment start address. This value is 17-bit long, the 6 LSB bits 00061 are reserved and forced to 0 in order to allow a 64-byte granularity. */ 00062 00063 uint32_t VDataSegmentLength; /*!< Protected volatile data segment length in bytes. This value is 17-bit long, the 6 LSB 00064 bits are reserved and forced to 0 for the length to be a multiple of 64 bytes. */ 00065 00066 uint32_t VolatileDataExecution; /*!< Set VDE bit specifying whether or not the volatile data segment can be executed. 00067 When VDS = 1 (set by parameter VolatileDataShared), VDE bit has no meaning. 00068 This parameter can be a value of @ref FIREWALL_VolatileData_Executable */ 00069 00070 uint32_t VolatileDataShared; /*!< Set VDS bit in specifying whether or not the volatile data segment can be shared with a 00071 non-protected application code. 00072 This parameter can be a value of @ref FIREWALL_VolatileData_Shared */ 00073 00074 }FIREWALL_InitTypeDef; 00075 00076 00077 /** 00078 * @} 00079 */ 00080 00081 00082 /* Exported constants --------------------------------------------------------*/ 00083 /** @defgroup FIREWALL_Exported_Constants FIREWALL Exported Constants 00084 * @{ 00085 */ 00086 00087 /** @defgroup FIREWALL_VolatileData_Executable FIREWALL volatile data segment execution status 00088 * @{ 00089 */ 00090 #define FIREWALL_VOLATILEDATA_NOT_EXECUTABLE ((uint32_t)0x0000) 00091 #define FIREWALL_VOLATILEDATA_EXECUTABLE ((uint32_t)FW_CR_VDE) 00092 /** 00093 * @} 00094 */ 00095 00096 /** @defgroup FIREWALL_VolatileData_Shared FIREWALL volatile data segment share status 00097 * @{ 00098 */ 00099 #define FIREWALL_VOLATILEDATA_NOT_SHARED ((uint32_t)0x0000) 00100 #define FIREWALL_VOLATILEDATA_SHARED ((uint32_t)FW_CR_VDS) 00101 /** 00102 * @} 00103 */ 00104 00105 /** @defgroup FIREWALL_Pre_Arm FIREWALL pre arm status 00106 * @{ 00107 */ 00108 #define FIREWALL_PRE_ARM_RESET ((uint32_t)0x0000) 00109 #define FIREWALL_PRE_ARM_SET ((uint32_t)FW_CR_FPA) 00110 00111 /** 00112 * @} 00113 */ 00114 00115 /** 00116 * @} 00117 */ 00118 00119 /* Private macros --------------------------------------------------------*/ 00120 /** @defgroup FIREWALL_Private_Macros FIREWALL Private Macros 00121 * @{ 00122 */ 00123 #define IS_FIREWALL_CODE_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((ADDRESS) < (FLASH_BASE + FLASH_SIZE))) 00124 #define IS_FIREWALL_CODE_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= (FLASH_BASE + FLASH_SIZE)) 00125 00126 #define IS_FIREWALL_NONVOLATILEDATA_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((ADDRESS) < (FLASH_BASE + FLASH_SIZE))) 00127 #define IS_FIREWALL_NONVOLATILEDATA_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= (FLASH_BASE + FLASH_SIZE)) 00128 00129 #define IS_FIREWALL_VOLATILEDATA_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= SRAM1_BASE) && ((ADDRESS) < (SRAM1_BASE + SRAM1_SIZE_MAX))) 00130 #define IS_FIREWALL_VOLATILEDATA_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= (SRAM1_BASE + SRAM1_SIZE_MAX)) 00131 00132 00133 #define IS_FIREWALL_VOLATILEDATA_SHARE(SHARE) (((SHARE) == FIREWALL_VOLATILEDATA_NOT_SHARED) || \ 00134 ((SHARE) == FIREWALL_VOLATILEDATA_SHARED)) 00135 00136 #define IS_FIREWALL_VOLATILEDATA_EXECUTE(EXECUTE) (((EXECUTE) == FIREWALL_VOLATILEDATA_NOT_EXECUTABLE) || \ 00137 ((EXECUTE) == FIREWALL_VOLATILEDATA_EXECUTABLE)) 00138 /** 00139 * @} 00140 */ 00141 00142 00143 /* Exported macros -----------------------------------------------------------*/ 00144 /** @defgroup FIREWALL_Exported_Macros FIREWALL Exported Macros 00145 * @{ 00146 */ 00147 00148 /** @brief Check whether the FIREWALL is enabled or not. 00149 * @retval FIREWALL enabling status (TRUE or FALSE). 00150 */ 00151 #define __HAL_FIREWALL_IS_ENABLED() HAL_IS_BIT_CLR(SYSCFG->CFGR1, SYSCFG_CFGR1_FWDIS) 00152 00153 00154 /** @brief Enable FIREWALL pre arm. 00155 * @note When FPA bit is set, any code executed outside the protected segment 00156 * closes the Firewall, otherwise it generates a system reset. 00157 * @note This macro provides the same service as HAL_FIREWALL_EnablePreArmFlag() API 00158 * but can be executed inside a code area protected by the Firewall. 00159 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00160 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00161 * 0, that is, when the non volatile data segment is defined), the macro can be 00162 * executed only when the Firewall is opened. 00163 */ 00164 #define __HAL_FIREWALL_PREARM_ENABLE() \ 00165 do { \ 00166 __IO uint32_t tmpreg; \ 00167 SET_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 00168 /* Read bit back to ensure it is taken into account by Peripheral */ \ 00169 /* (introduce proper delay inside macro execution) */ \ 00170 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 00171 UNUSED(tmpreg); \ 00172 } while(0) 00173 00174 00175 00176 /** @brief Disable FIREWALL pre arm. 00177 * @note When FPA bit is set, any code executed outside the protected segment 00178 * closes the Firewall, otherwise, it generates a system reset. 00179 * @note This macro provides the same service as HAL_FIREWALL_DisablePreArmFlag() API 00180 * but can be executed inside a code area protected by the Firewall. 00181 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00182 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00183 * 0, that is, when the non volatile data segment is defined), the macro can be 00184 * executed only when the Firewall is opened. 00185 */ 00186 #define __HAL_FIREWALL_PREARM_DISABLE() \ 00187 do { \ 00188 __IO uint32_t tmpreg; \ 00189 CLEAR_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 00190 /* Read bit back to ensure it is taken into account by Peripheral */ \ 00191 /* (introduce proper delay inside macro execution) */ \ 00192 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 00193 UNUSED(tmpreg); \ 00194 } while(0) 00195 00196 /** @brief Enable volatile data sharing in setting VDS bit. 00197 * @note When VDS bit is set, the volatile data segment is shared with non-protected 00198 * application code. It can be accessed whatever the Firewall state (opened or closed). 00199 * @note This macro can be executed inside a code area protected by the Firewall. 00200 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00201 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00202 * 0, that is, when the non volatile data segment is defined), the macro can be 00203 * executed only when the Firewall is opened. 00204 */ 00205 #define __HAL_FIREWALL_VOLATILEDATA_SHARED_ENABLE() \ 00206 do { \ 00207 __IO uint32_t tmpreg; \ 00208 SET_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 00209 /* Read bit back to ensure it is taken into account by Peripheral */ \ 00210 /* (introduce proper delay inside macro execution) */ \ 00211 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 00212 UNUSED(tmpreg); \ 00213 } while(0) 00214 00215 /** @brief Disable volatile data sharing in resetting VDS bit. 00216 * @note When VDS bit is reset, the volatile data segment is not shared and cannot be 00217 * hit by a non protected executable code when the Firewall is closed. If it is 00218 * accessed in such a condition, a system reset is generated by the Firewall. 00219 * @note This macro can be executed inside a code area protected by the Firewall. 00220 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00221 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00222 * 0, that is, when the non volatile data segment is defined), the macro can be 00223 * executed only when the Firewall is opened. 00224 */ 00225 #define __HAL_FIREWALL_VOLATILEDATA_SHARED_DISABLE() \ 00226 do { \ 00227 __IO uint32_t tmpreg; \ 00228 CLEAR_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 00229 /* Read bit back to ensure it is taken into account by Peripheral */ \ 00230 /* (introduce proper delay inside macro execution) */ \ 00231 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 00232 UNUSED(tmpreg); \ 00233 } while(0) 00234 00235 /** @brief Enable volatile data execution in setting VDE bit. 00236 * @note VDE bit is ignored when VDS is set. IF VDS = 1, the Volatile data segment can be 00237 * executed whatever the VDE bit value. 00238 * @note When VDE bit is set (with VDS = 0), the volatile data segment is executable. When 00239 * the Firewall call is closed, a "call gate" entry procedure is required to open 00240 * first the Firewall. 00241 * @note This macro can be executed inside a code area protected by the Firewall. 00242 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00243 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00244 * 0, that is, when the non volatile data segment is defined), the macro can be 00245 * executed only when the Firewall is opened. 00246 */ 00247 #define __HAL_FIREWALL_VOLATILEDATA_EXECUTION_ENABLE() \ 00248 do { \ 00249 __IO uint32_t tmpreg; \ 00250 SET_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 00251 /* Read bit back to ensure it is taken into account by Peripheral */ \ 00252 /* (introduce proper delay inside macro execution) */ \ 00253 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 00254 UNUSED(tmpreg); \ 00255 } while(0) 00256 00257 /** @brief Disable volatile data execution in resetting VDE bit. 00258 * @note VDE bit is ignored when VDS is set. IF VDS = 1, the Volatile data segment can be 00259 * executed whatever the VDE bit value. 00260 * @note When VDE bit is reset (with VDS = 0), the volatile data segment cannot be executed. 00261 * @note This macro can be executed inside a code area protected by the Firewall. 00262 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00263 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00264 * 0, that is, when the non volatile data segment is defined), the macro can be 00265 * executed only when the Firewall is opened. 00266 */ 00267 #define __HAL_FIREWALL_VOLATILEDATA_EXECUTION_DISABLE() \ 00268 do { \ 00269 __IO uint32_t tmpreg; \ 00270 CLEAR_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 00271 /* Read bit back to ensure it is taken into account by Peripheral */ \ 00272 /* (introduce proper delay inside macro execution) */ \ 00273 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 00274 UNUSED(tmpreg); \ 00275 } while(0) 00276 00277 00278 /** @brief Check whether or not the volatile data segment is shared. 00279 * @note This macro can be executed inside a code area protected by the Firewall. 00280 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00281 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00282 * 0, that is, when the non volatile data segment is defined), the macro can be 00283 * executed only when the Firewall is opened. 00284 * @retval VDS bit setting status (TRUE or FALSE). 00285 */ 00286 #define __HAL_FIREWALL_GET_VOLATILEDATA_SHARED() ((FIREWALL->CR & FW_CR_VDS) == FW_CR_VDS) 00287 00288 /** @brief Check whether or not the volatile data segment is declared executable. 00289 * @note This macro can be executed inside a code area protected by the Firewall. 00290 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00291 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00292 * 0, that is, when the non volatile data segment is defined), the macro can be 00293 * executed only when the Firewall is opened. 00294 * @retval VDE bit setting status (TRUE or FALSE). 00295 */ 00296 #define __HAL_FIREWALL_GET_VOLATILEDATA_EXECUTION() ((FIREWALL->CR & FW_CR_VDE) == FW_CR_VDE) 00297 00298 /** @brief Check whether or not the Firewall pre arm bit is set. 00299 * @note This macro can be executed inside a code area protected by the Firewall. 00300 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00301 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00302 * 0, that is, when the non volatile data segment is defined), the macro can be 00303 * executed only when the Firewall is opened. 00304 * @retval FPA bit setting status (TRUE or FALSE). 00305 */ 00306 #define __HAL_FIREWALL_GET_PREARM() ((FIREWALL->CR & FW_CR_FPA) == FW_CR_FPA) 00307 00308 00309 /** 00310 * @} 00311 */ 00312 00313 /* Exported functions --------------------------------------------------------*/ 00314 00315 /** @addtogroup FIREWALL_Exported_Functions FIREWALL Exported Functions 00316 * @{ 00317 */ 00318 00319 /** @addtogroup FIREWALL_Exported_Functions_Group1 Initialization Functions 00320 * @brief Initialization and Configuration Functions 00321 * @{ 00322 */ 00323 00324 /* Initialization functions ********************************/ 00325 HAL_StatusTypeDef HAL_FIREWALL_Config(FIREWALL_InitTypeDef * fw_init); 00326 void HAL_FIREWALL_GetConfig(FIREWALL_InitTypeDef * fw_config); 00327 void HAL_FIREWALL_EnableFirewall(void); 00328 void HAL_FIREWALL_EnablePreArmFlag(void); 00329 void HAL_FIREWALL_DisablePreArmFlag(void); 00330 00331 /** 00332 * @} 00333 */ 00334 00335 /** 00336 * @} 00337 */ 00338 00339 /** 00340 * @} 00341 */ 00342 00343 /** 00344 * @} 00345 */ 00346 00347 #ifdef __cplusplus 00348 } 00349 #endif 00350 00351 #endif /* STM32L4xx_HAL_FIREWALL_H */