1 /** 2 ****************************************************************************** 3 * @file stm32l0xx_hal_firewall.h 4 * @author MCD Application Team 5 * @brief Header file of FIREWALL HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2016 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef __STM32L0xx_HAL_FIREWALL_H 21 #define __STM32L0xx_HAL_FIREWALL_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #if !defined (STM32L010xB) && !defined (STM32L010x8) && !defined (STM32L010x6) && !defined (STM32L010x4) && !defined (STM32L011xx) && !defined (STM32L021xx) && !defined (STM32L031xx) && !defined (STM32L041xx) 28 29 /* Includes ------------------------------------------------------------------*/ 30 #include "stm32l0xx_hal_def.h" 31 32 /** @addtogroup STM32L0xx_HAL_Driver 33 * @{ 34 */ 35 36 /** @defgroup FIREWALL FIREWALL 37 * @{ 38 */ 39 40 /* Exported types ------------------------------------------------------------*/ 41 /** @defgroup FIREWALL_Exported_Types FIREWALL Exported Types 42 * @{ 43 */ 44 45 /** 46 * @brief FIREWALL Initialization Structure definition 47 */ 48 typedef struct 49 { 50 uint32_t CodeSegmentStartAddress; /*!< Protected code segment start address. This value is 24-bit long, the 8 LSB bits are 51 reserved and forced to 0 in order to allow a 256-byte granularity. */ 52 53 uint32_t CodeSegmentLength; /*!< Protected code segment length in bytes. This value is 22-bit long, the 8 LSB bits are 54 reserved and forced to 0 for the length to be a multiple of 256 bytes. */ 55 56 uint32_t NonVDataSegmentStartAddress; /*!< Protected non-volatile data segment start address. This value is 24-bit long, the 8 LSB 57 bits are reserved and forced to 0 in order to allow a 256-byte granularity. */ 58 59 uint32_t NonVDataSegmentLength; /*!< Protected non-volatile data segment length in bytes. This value is 22-bit long, the 8 LSB 60 bits are reserved and forced to 0 for the length to be a multiple of 256 bytes. */ 61 62 uint32_t VDataSegmentStartAddress; /*!< Protected volatile data segment start address. This value is 17-bit long, the 6 LSB bits 63 are reserved and forced to 0 in order to allow a 64-byte granularity. */ 64 65 uint32_t VDataSegmentLength; /*!< Protected volatile data segment length in bytes. This value is 17-bit long, the 6 LSB 66 bits are reserved and forced to 0 for the length to be a multiple of 64 bytes. */ 67 68 uint32_t VolatileDataExecution; /*!< Set VDE bit specifying whether or not the volatile data segment can be executed. 69 When VDS = 1 (set by parameter VolatileDataShared), VDE bit has no meaning. 70 This parameter can be a value of @ref FIREWALL_VolatileData_Executable */ 71 72 uint32_t VolatileDataShared; /*!< Set VDS bit in specifying whether or not the volatile data segment can be shared with a 73 non-protected application code. 74 This parameter can be a value of @ref FIREWALL_VolatileData_Shared */ 75 76 }FIREWALL_InitTypeDef; 77 78 79 /** 80 * @} 81 */ 82 83 84 /* Exported constants --------------------------------------------------------*/ 85 /** @defgroup FIREWALL_Exported_Constants FIREWALL Exported Constants 86 * @{ 87 */ 88 89 /** @defgroup FIREWALL_VolatileData_Executable FIREWALL volatile data segment execution status 90 * @{ 91 */ 92 #define FIREWALL_VOLATILEDATA_NOT_EXECUTABLE (0x0000U) 93 #define FIREWALL_VOLATILEDATA_EXECUTABLE FW_CR_VDE 94 /** 95 * @} 96 */ 97 98 /** @defgroup FIREWALL_VolatileData_Shared FIREWALL volatile data segment share status 99 * @{ 100 */ 101 #define FIREWALL_VOLATILEDATA_NOT_SHARED (0x0000U) 102 #define FIREWALL_VOLATILEDATA_SHARED FW_CR_VDS 103 /** 104 * @} 105 */ 106 107 /** @defgroup FIREWALL_Pre_Arm FIREWALL pre arm status 108 * @{ 109 */ 110 #define FIREWALL_PRE_ARM_RESET (0x0000U) 111 #define FIREWALL_PRE_ARM_SET FW_CR_FPA 112 113 /** 114 * @} 115 */ 116 117 /** 118 * @} 119 */ 120 121 /* Private macros --------------------------------------------------------*/ 122 /** @addtogroup FIREWALL_Private 123 * @{ 124 */ 125 #define IS_FIREWALL_CODE_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((ADDRESS) < (FLASH_BASE + FLASH_SIZE))) 126 #define IS_FIREWALL_CODE_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= (FLASH_BASE + FLASH_SIZE)) 127 128 #define IS_FIREWALL_NONVOLATILEDATA_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((ADDRESS) < (FLASH_BASE + FLASH_SIZE))) 129 #define IS_FIREWALL_NONVOLATILEDATA_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= (FLASH_BASE + FLASH_SIZE)) 130 131 #define IS_FIREWALL_VOLATILEDATA_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= SRAM_BASE) && ((ADDRESS) < (SRAM_BASE + SRAM_SIZE_MAX))) 132 #define IS_FIREWALL_VOLATILEDATA_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= (SRAM_BASE + SRAM_SIZE_MAX)) 133 134 135 #define IS_FIREWALL_VOLATILEDATA_SHARE(SHARE) (((SHARE) == FIREWALL_VOLATILEDATA_NOT_SHARED) || \ 136 ((SHARE) == FIREWALL_VOLATILEDATA_SHARED)) 137 138 #define IS_FIREWALL_VOLATILEDATA_EXECUTE(EXECUTE) (((EXECUTE) == FIREWALL_VOLATILEDATA_NOT_EXECUTABLE) || \ 139 ((EXECUTE) == FIREWALL_VOLATILEDATA_EXECUTABLE)) 140 /** 141 * @} 142 */ 143 144 145 /* Exported macros -----------------------------------------------------------*/ 146 /** @defgroup FIREWALL_Exported_Macros FIREWALL Exported Macros 147 * @{ 148 */ 149 150 /** @brief Check whether the FIREWALL is enabled or not. 151 * @retval FIREWALL enabling status (TRUE or FALSE). 152 */ 153 #define __HAL_FIREWALL_IS_ENABLED() HAL_IS_BIT_CLR(SYSCFG->CFGR2, SYSCFG_CFGR2_FWDISEN) 154 155 156 /** @brief Enable FIREWALL pre arm. 157 * @note When FPA bit is set, any code executed outside the protected segment 158 * closes the Firewall, otherwise it generates a system reset. 159 * @note This macro provides the same service as HAL_FIREWALL_EnablePreArmFlag() API 160 * but can be executed inside a code area protected by the Firewall. 161 * @note This macro can be executed whatever the Firewall state (opened or closed) when 162 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 163 * 0, that is, when the non volatile data segment is defined), the macro can be 164 * executed only when the Firewall is opened. 165 */ 166 #define __HAL_FIREWALL_PREARM_ENABLE() \ 167 do { \ 168 __IO uint32_t tmpreg; \ 169 SET_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 170 /* Read bit back to ensure it is taken into account by Peripheral */ \ 171 /* (introduce proper delay inside macro execution) */ \ 172 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 173 UNUSED(tmpreg); \ 174 } while(0) 175 176 177 178 /** @brief Disable FIREWALL pre arm. 179 * @note When FPA bit is set, any code executed outside the protected segment 180 * closes the Firewall, otherwise, it generates a system reset. 181 * @note This macro provides the same service as HAL_FIREWALL_DisablePreArmFlag() API 182 * but can be executed inside a code area protected by the Firewall. 183 * @note This macro can be executed whatever the Firewall state (opened or closed) when 184 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 185 * 0, that is, when the non volatile data segment is defined), the macro can be 186 * executed only when the Firewall is opened. 187 */ 188 #define __HAL_FIREWALL_PREARM_DISABLE() \ 189 do { \ 190 __IO uint32_t tmpreg; \ 191 CLEAR_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 192 /* Read bit back to ensure it is taken into account by Peripheral */ \ 193 /* (introduce proper delay inside macro execution) */ \ 194 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_FPA) ; \ 195 UNUSED(tmpreg); \ 196 } while(0) 197 198 /** @brief Enable volatile data sharing in setting VDS bit. 199 * @note When VDS bit is set, the volatile data segment is shared with non-protected 200 * application code. It can be accessed whatever the Firewall state (opened or closed). 201 * @note This macro can be executed inside a code area protected by the Firewall. 202 * @note This macro can be executed whatever the Firewall state (opened or closed) when 203 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 204 * 0, that is, when the non volatile data segment is defined), the macro can be 205 * executed only when the Firewall is opened. 206 */ 207 #define __HAL_FIREWALL_VOLATILEDATA_SHARED_ENABLE() \ 208 do { \ 209 __IO uint32_t tmpreg; \ 210 SET_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 211 /* Read bit back to ensure it is taken into account by Peripheral */ \ 212 /* (introduce proper delay inside macro execution) */ \ 213 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 214 UNUSED(tmpreg); \ 215 } while(0) 216 217 /** @brief Disable volatile data sharing in resetting VDS bit. 218 * @note When VDS bit is reset, the volatile data segment is not shared and cannot be 219 * hit by a non protected executable code when the Firewall is closed. If it is 220 * accessed in such a condition, a system reset is generated by the Firewall. 221 * @note This macro can be executed inside a code area protected by the Firewall. 222 * @note This macro can be executed whatever the Firewall state (opened or closed) when 223 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 224 * 0, that is, when the non volatile data segment is defined), the macro can be 225 * executed only when the Firewall is opened. 226 */ 227 #define __HAL_FIREWALL_VOLATILEDATA_SHARED_DISABLE() \ 228 do { \ 229 __IO uint32_t tmpreg; \ 230 CLEAR_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 231 /* Read bit back to ensure it is taken into account by Peripheral */ \ 232 /* (introduce proper delay inside macro execution) */ \ 233 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDS) ; \ 234 UNUSED(tmpreg); \ 235 } while(0) 236 237 /** @brief Enable volatile data execution in setting VDE bit. 238 * @note VDE bit is ignored when VDS is set. IF VDS = 1, the Volatile data segment can be 239 * executed whatever the VDE bit value. 240 * @note When VDE bit is set (with VDS = 0), the volatile data segment is executable. When 241 * the Firewall call is closed, a "call gate" entry procedure is required to open 242 * first the Firewall. 243 * @note This macro can be executed inside a code area protected by the Firewall. 244 * @note This macro can be executed whatever the Firewall state (opened or closed) when 245 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 246 * 0, that is, when the non volatile data segment is defined), the macro can be 247 * executed only when the Firewall is opened. 248 */ 249 #define __HAL_FIREWALL_VOLATILEDATA_EXECUTION_ENABLE() \ 250 do { \ 251 __IO uint32_t tmpreg; \ 252 SET_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 253 /* Read bit back to ensure it is taken into account by Peripheral */ \ 254 /* (introduce proper delay inside macro execution) */ \ 255 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 256 UNUSED(tmpreg); \ 257 } while(0) 258 259 /** @brief Disable volatile data execution in resetting VDE bit. 260 * @note VDE bit is ignored when VDS is set. IF VDS = 1, the Volatile data segment can be 261 * executed whatever the VDE bit value. 262 * @note When VDE bit is reset (with VDS = 0), the volatile data segment cannot be executed. 263 * @note This macro can be executed inside a code area protected by the Firewall. 264 * @note This macro can be executed whatever the Firewall state (opened or closed) when 265 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 266 * 0, that is, when the non volatile data segment is defined), the macro can be 267 * executed only when the Firewall is opened. 268 */ 269 #define __HAL_FIREWALL_VOLATILEDATA_EXECUTION_DISABLE() \ 270 do { \ 271 __IO uint32_t tmpreg; \ 272 CLEAR_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 273 /* Read bit back to ensure it is taken into account by Peripheral */ \ 274 /* (introduce proper delay inside macro execution) */ \ 275 tmpreg = READ_BIT(FIREWALL->CR, FW_CR_VDE) ; \ 276 UNUSED(tmpreg); \ 277 } while(0) 278 279 280 /** @brief Check whether or not the volatile data segment is shared. 281 * @note This macro can be executed inside a code area protected by the Firewall. 282 * @note This macro can be executed whatever the Firewall state (opened or closed) when 283 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 284 * 0, that is, when the non volatile data segment is defined), the macro can be 285 * executed only when the Firewall is opened. 286 * @retval VDS bit setting status (TRUE or FALSE). 287 */ 288 #define __HAL_FIREWALL_GET_VOLATILEDATA_SHARED() ((FIREWALL->CR & FW_CR_VDS) == FW_CR_VDS) 289 290 /** @brief Check whether or not the volatile data segment is declared executable. 291 * @note This macro can be executed inside a code area protected by the Firewall. 292 * @note This macro can be executed whatever the Firewall state (opened or closed) when 293 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 294 * 0, that is, when the non volatile data segment is defined), the macro can be 295 * executed only when the Firewall is opened. 296 * @retval VDE bit setting status (TRUE or FALSE). 297 */ 298 #define __HAL_FIREWALL_GET_VOLATILEDATA_EXECUTION() ((FIREWALL->CR & FW_CR_VDE) == FW_CR_VDE) 299 300 /** @brief Check whether or not the Firewall pre arm bit is set. 301 * @note This macro can be executed inside a code area protected by the Firewall. 302 * @note This macro can be executed whatever the Firewall state (opened or closed) when 303 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from 304 * 0, that is, when the non volatile data segment is defined), the macro can be 305 * executed only when the Firewall is opened. 306 * @retval FPA bit setting status (TRUE or FALSE). 307 */ 308 #define __HAL_FIREWALL_GET_PREARM() ((FIREWALL->CR & FW_CR_FPA) == FW_CR_FPA) 309 310 311 /** 312 * @} 313 */ 314 315 /* Exported functions --------------------------------------------------------*/ 316 317 /** @defgroup FIREWALL_Exported_Functions FIREWALL Exported Functions 318 * @{ 319 */ 320 321 /** @defgroup FIREWALL_Exported_Functions_Group1 Initialization Functions 322 * @brief Initialization and Configuration Functions 323 * @{ 324 */ 325 326 /* Initialization functions ********************************/ 327 HAL_StatusTypeDef HAL_FIREWALL_Config(FIREWALL_InitTypeDef * fw_init); 328 void HAL_FIREWALL_GetConfig(FIREWALL_InitTypeDef * fw_config); 329 void HAL_FIREWALL_EnableFirewall(void); 330 void HAL_FIREWALL_EnablePreArmFlag(void); 331 void HAL_FIREWALL_DisablePreArmFlag(void); 332 333 /** 334 * @} 335 */ 336 337 /** 338 * @} 339 */ 340 /* Define the private group ***********************************/ 341 /**************************************************************/ 342 /** @defgroup FIREWALL_Private FIREWALL Private 343 * @{ 344 */ 345 /** 346 * @} 347 */ 348 /**************************************************************/ 349 350 /** 351 * @} 352 */ 353 354 /** 355 * @} 356 */ 357 358 359 #endif /* #if !defined (STM32L010xB) && !defined (STM32L010x8) && !defined (STM32L010x6) && !defined (STM32L010x4) && !defined (STM32L011xx) && !defined (STM32L021xx) && !defined (STM32L031xx) && !defined (STM32L041xx) */ 360 361 #ifdef __cplusplus 362 } 363 #endif 364 365 #endif /* __STM32L0xx_HAL_FIREWALL_H */ 366