STM32L486xx 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 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 00036 /* Define to prevent recursive inclusion -------------------------------------*/ 00037 #ifndef __STM32L4xx_HAL_FIREWALL_H 00038 #define __STM32L4xx_HAL_FIREWALL_H 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 /* Includes ------------------------------------------------------------------*/ 00045 #include "stm32l4xx_hal_def.h" 00046 00047 /** @addtogroup STM32L4xx_HAL_Driver 00048 * @{ 00049 */ 00050 00051 /** @addtogroup FIREWALL FIREWALL 00052 * @{ 00053 */ 00054 00055 /* Exported types ------------------------------------------------------------*/ 00056 /** @defgroup FIREWALL_Exported_Types FIREWALL Exported Types 00057 * @{ 00058 */ 00059 00060 /** 00061 * @brief FIREWALL Initialization Structure definition 00062 */ 00063 typedef struct 00064 { 00065 uint32_t CodeSegmentStartAddress; /*!< Protected code segment start address. This value is 24-bit long, the 8 LSB bits are 00066 reserved and forced to 0 in order to allow a 256-byte granularity. */ 00067 00068 uint32_t CodeSegmentLength; /*!< Protected code segment length in bytes. This value is 22-bit long, the 8 LSB bits are 00069 reserved and forced to 0 for the length to be a multiple of 256 bytes. */ 00070 00071 uint32_t NonVDataSegmentStartAddress; /*!< Protected non-volatile data segment start address. This value is 24-bit long, the 8 LSB 00072 bits are reserved and forced to 0 in order to allow a 256-byte granularity. */ 00073 00074 uint32_t NonVDataSegmentLength; /*!< Protected non-volatile data segment length in bytes. This value is 22-bit long, the 8 LSB 00075 bits are reserved and forced to 0 for the length to be a multiple of 256 bytes. */ 00076 00077 uint32_t VDataSegmentStartAddress; /*!< Protected volatile data segment start address. This value is 17-bit long, the 6 LSB bits 00078 are reserved and forced to 0 in order to allow a 64-byte granularity. */ 00079 00080 uint32_t VDataSegmentLength; /*!< Protected volatile data segment length in bytes. This value is 17-bit long, the 6 LSB 00081 bits are reserved and forced to 0 for the length to be a multiple of 64 bytes. */ 00082 00083 uint32_t VolatileDataExecution; /*!< Set VDE bit specifying whether or not the volatile data segment can be executed. 00084 When VDS = 1 (set by parameter VolatileDataShared), VDE bit has no meaning. 00085 This parameter can be a value of @ref FIREWALL_VolatileData_Executable */ 00086 00087 uint32_t VolatileDataShared; /*!< Set VDS bit in specifying whether or not the volatile data segment can be shared with a 00088 non-protected application code. 00089 This parameter can be a value of @ref FIREWALL_VolatileData_Shared */ 00090 00091 }FIREWALL_InitTypeDef; 00092 00093 00094 /** 00095 * @} 00096 */ 00097 00098 00099 /* Exported constants --------------------------------------------------------*/ 00100 /** @defgroup FIREWALL_Exported_Constants FIREWALL Exported Constants 00101 * @{ 00102 */ 00103 00104 /** @defgroup FIREWALL_VolatileData_Executable FIREWALL volatile data segment execution status 00105 * @{ 00106 */ 00107 #define FIREWALL_VOLATILEDATA_NOT_EXECUTABLE ((uint32_t)0x0000) 00108 #define FIREWALL_VOLATILEDATA_EXECUTABLE ((uint32_t)FW_CR_VDE) 00109 /** 00110 * @} 00111 */ 00112 00113 /** @defgroup FIREWALL_VolatileData_Shared FIREWALL volatile data segment share status 00114 * @{ 00115 */ 00116 #define FIREWALL_VOLATILEDATA_NOT_SHARED ((uint32_t)0x0000) 00117 #define FIREWALL_VOLATILEDATA_SHARED ((uint32_t)FW_CR_VDS) 00118 /** 00119 * @} 00120 */ 00121 00122 /** @defgroup FIREWALL_Pre_Arm FIREWALL pre arm status 00123 * @{ 00124 */ 00125 #define FIREWALL_PRE_ARM_RESET ((uint32_t)0x0000) 00126 #define FIREWALL_PRE_ARM_SET ((uint32_t)FW_CR_FPA) 00127 00128 /** 00129 * @} 00130 */ 00131 00132 /** 00133 * @} 00134 */ 00135 00136 /* Private macros --------------------------------------------------------*/ 00137 /** @defgroup FIREWALL_Private_Macros FIREWALL Private Macros 00138 * @{ 00139 */ 00140 #define IS_FIREWALL_CODE_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((ADDRESS) < (FLASH_BASE + FLASH_SIZE))) 00141 #define IS_FIREWALL_CODE_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= (FLASH_BASE + FLASH_SIZE)) 00142 00143 #define IS_FIREWALL_NONVOLATILEDATA_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((ADDRESS) < (FLASH_BASE + FLASH_SIZE))) 00144 #define IS_FIREWALL_NONVOLATILEDATA_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= (FLASH_BASE + FLASH_SIZE)) 00145 00146 #define IS_FIREWALL_VOLATILEDATA_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= SRAM1_BASE) && ((ADDRESS) < (SRAM1_BASE + SRAM1_SIZE_MAX))) 00147 #define IS_FIREWALL_VOLATILEDATA_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= (SRAM1_BASE + SRAM1_SIZE_MAX)) 00148 00149 00150 #define IS_FIREWALL_VOLATILEDATA_SHARE(SHARE) (((SHARE) == FIREWALL_VOLATILEDATA_NOT_SHARED) || \ 00151 ((SHARE) == FIREWALL_VOLATILEDATA_SHARED)) 00152 00153 #define IS_FIREWALL_VOLATILEDATA_EXECUTE(EXECUTE) (((EXECUTE) == FIREWALL_VOLATILEDATA_NOT_EXECUTABLE) || \ 00154 ((EXECUTE) == FIREWALL_VOLATILEDATA_EXECUTABLE)) 00155 /** 00156 * @} 00157 */ 00158 00159 00160 /* Exported macros -----------------------------------------------------------*/ 00161 /** @defgroup FIREWALL_Exported_Macros FIREWALL Exported Macros 00162 * @{ 00163 */ 00164 00165 /** @brief Check whether the FIREWALL is enabled or not. 00166 * @retval FIREWALL enabling status (TRUE or FALSE). 00167 */ 00168 #define __HAL_FIREWALL_IS_ENABLED() HAL_IS_BIT_CLR(SYSCFG->CFGR1, SYSCFG_CFGR1_FWDIS) 00169 00170 00171 /** @brief Enable FIREWALL pre arm. 00172 * @note When FPA bit is set, any code executed outside the protected segment 00173 * closes the Firewall, otherwise it generates a system reset. 00174 * @note This macro provides the same service as HAL_FIREWALL_EnablePreArmFlag() API 00175 * but can be executed inside a code area protected by the Firewall. 00176 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00177 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00178 * 0, that is, when the non volatile data segment is defined), the macro can be 00179 * executed only when the Firewall is opened. 00180 */ 00181 #define __HAL_FIREWALL_PREARM_ENABLE() \ 00182 do { \ 00183 __IO uint32_t tmpreg; \ 00184 SET_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 00185 /* Read bit back to ensure it is taken into account by IP */ \ 00186 /* (introduce proper delay inside macro execution) */ \ 00187 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 00188 UNUSED(tmpreg); \ 00189 } while(0) 00190 00191 00192 00193 /** @brief Disable FIREWALL pre arm. 00194 * @note When FPA bit is set, any code executed outside the protected segment 00195 * closes the Firewall, otherwise, it generates a system reset. 00196 * @note This macro provides the same service as HAL_FIREWALL_DisablePreArmFlag() API 00197 * but can be executed inside a code area protected by the Firewall. 00198 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00199 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00200 * 0, that is, when the non volatile data segment is defined), the macro can be 00201 * executed only when the Firewall is opened. 00202 */ 00203 #define __HAL_FIREWALL_PREARM_DISABLE() \ 00204 do { \ 00205 __IO uint32_t tmpreg; \ 00206 CLEAR_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 00207 /* Read bit back to ensure it is taken into account by IP */ \ 00208 /* (introduce proper delay inside macro execution) */ \ 00209 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 00210 UNUSED(tmpreg); \ 00211 } while(0) 00212 00213 /** @brief Enable volatile data sharing in setting VDS bit. 00214 * @note When VDS bit is set, the volatile data segment is shared with non-protected 00215 * application code. It can be accessed whatever the Firewall state (opened or closed). 00216 * @note This macro can be executed inside a code area protected by the Firewall. 00217 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00218 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00219 * 0, that is, when the non volatile data segment is defined), the macro can be 00220 * executed only when the Firewall is opened. 00221 */ 00222 #define __HAL_FIREWALL_VOLATILEDATA_SHARED_ENABLE() \ 00223 do { \ 00224 __IO uint32_t tmpreg; \ 00225 SET_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 00226 /* Read bit back to ensure it is taken into account by IP */ \ 00227 /* (introduce proper delay inside macro execution) */ \ 00228 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 00229 UNUSED(tmpreg); \ 00230 } while(0) 00231 00232 /** @brief Disable volatile data sharing in resetting VDS bit. 00233 * @note When VDS bit is reset, the volatile data segment is not shared and cannot be 00234 * hit by a non protected executable code when the Firewall is closed. If it is 00235 * accessed in such a condition, a system reset is generated by the Firewall. 00236 * @note This macro can be executed inside a code area protected by the Firewall. 00237 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00238 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00239 * 0, that is, when the non volatile data segment is defined), the macro can be 00240 * executed only when the Firewall is opened. 00241 */ 00242 #define __HAL_FIREWALL_VOLATILEDATA_SHARED_DISABLE() \ 00243 do { \ 00244 __IO uint32_t tmpreg; \ 00245 CLEAR_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 00246 /* Read bit back to ensure it is taken into account by IP */ \ 00247 /* (introduce proper delay inside macro execution) */ \ 00248 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 00249 UNUSED(tmpreg); \ 00250 } while(0) 00251 00252 /** @brief Enable volatile data execution in setting VDE bit. 00253 * @note VDE bit is ignored when VDS is set. IF VDS = 1, the Volatile data segment can be 00254 * executed whatever the VDE bit value. 00255 * @note When VDE bit is set (with VDS = 0), the volatile data segment is executable. When 00256 * the Firewall call is closed, a "call gate" entry procedure is required to open 00257 * first the Firewall. 00258 * @note This macro can be executed inside a code area protected by the Firewall. 00259 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00260 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00261 * 0, that is, when the non volatile data segment is defined), the macro can be 00262 * executed only when the Firewall is opened. 00263 */ 00264 #define __HAL_FIREWALL_VOLATILEDATA_EXECUTION_ENABLE() \ 00265 do { \ 00266 __IO uint32_t tmpreg; \ 00267 SET_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 00268 /* Read bit back to ensure it is taken into account by IP */ \ 00269 /* (introduce proper delay inside macro execution) */ \ 00270 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 00271 UNUSED(tmpreg); \ 00272 } while(0) 00273 00274 /** @brief Disable volatile data execution in resetting VDE bit. 00275 * @note VDE bit is ignored when VDS is set. IF VDS = 1, the Volatile data segment can be 00276 * executed whatever the VDE bit value. 00277 * @note When VDE bit is reset (with VDS = 0), the volatile data segment cannot be executed. 00278 * @note This macro can be executed inside a code area protected by the Firewall. 00279 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00280 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00281 * 0, that is, when the non volatile data segment is defined), the macro can be 00282 * executed only when the Firewall is opened. 00283 */ 00284 #define __HAL_FIREWALL_VOLATILEDATA_EXECUTION_DISABLE() \ 00285 do { \ 00286 __IO uint32_t tmpreg; \ 00287 CLEAR_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 00288 /* Read bit back to ensure it is taken into account by IP */ \ 00289 /* (introduce proper delay inside macro execution) */ \ 00290 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 00291 UNUSED(tmpreg); \ 00292 } while(0) 00293 00294 00295 /** @brief Check whether or not the volatile data segment is shared. 00296 * @note This macro can be executed inside a code area protected by the Firewall. 00297 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00298 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00299 * 0, that is, when the non volatile data segment is defined), the macro can be 00300 * executed only when the Firewall is opened. 00301 * @retval VDS bit setting status (TRUE or FALSE). 00302 */ 00303 #define __HAL_FIREWALL_GET_VOLATILEDATA_SHARED() ((FIREWALL->CR & FW_CR_VDS) == FW_CR_VDS) 00304 00305 /** @brief Check whether or not the volatile data segment is declared executable. 00306 * @note This macro can be executed inside a code area protected by the Firewall. 00307 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00308 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00309 * 0, that is, when the non volatile data segment is defined), the macro can be 00310 * executed only when the Firewall is opened. 00311 * @retval VDE bit setting status (TRUE or FALSE). 00312 */ 00313 #define __HAL_FIREWALL_GET_VOLATILEDATA_EXECUTION() ((FIREWALL->CR & FW_CR_VDE) == FW_CR_VDE) 00314 00315 /** @brief Check whether or not the Firewall pre arm bit is set. 00316 * @note This macro can be executed inside a code area protected by the Firewall. 00317 * @note This macro can be executed whatever the Firewall state (opened or closed) when 00318 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 00319 * 0, that is, when the non volatile data segment is defined), the macro can be 00320 * executed only when the Firewall is opened. 00321 * @retval FPA bit setting status (TRUE or FALSE). 00322 */ 00323 #define __HAL_FIREWALL_GET_PREARM() ((FIREWALL->CR & FW_CR_FPA) == FW_CR_FPA) 00324 00325 00326 /** 00327 * @} 00328 */ 00329 00330 /* Exported functions --------------------------------------------------------*/ 00331 00332 /** @addtogroup FIREWALL_Exported_Functions FIREWALL Exported Functions 00333 * @{ 00334 */ 00335 00336 /** @addtogroup FIREWALL_Exported_Functions_Group1 Initialization Functions 00337 * @brief Initialization and Configuration Functions 00338 * @{ 00339 */ 00340 00341 /* Initialization functions ********************************/ 00342 HAL_StatusTypeDef HAL_FIREWALL_Config(FIREWALL_InitTypeDef * fw_init); 00343 void HAL_FIREWALL_GetConfig(FIREWALL_InitTypeDef * fw_config); 00344 void HAL_FIREWALL_EnableFirewall(void); 00345 void HAL_FIREWALL_EnablePreArmFlag(void); 00346 void HAL_FIREWALL_DisablePreArmFlag(void); 00347 00348 /** 00349 * @} 00350 */ 00351 00352 /** 00353 * @} 00354 */ 00355 00356 /** 00357 * @} 00358 */ 00359 00360 /** 00361 * @} 00362 */ 00363 00364 #ifdef __cplusplus 00365 } 00366 #endif 00367 00368 #endif /* __STM32L4xx_HAL_FIREWALL_H */ 00369 00370 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/