2 ******************************************************************************
3 * @file stm32l0xx_hal_firewall.h
4 * @author MCD Application Team
6 * @date 06-February-2015
7 * @brief Header file of FIREWALL HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32L0xx_HAL_FIREWALL_H
40 #define __STM32L0xx_HAL_FIREWALL_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32l0xx_hal_def.h"
49 /** @addtogroup STM32L0xx_HAL_Driver
53 /** @addtogroup FIREWALL FIREWALL
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup FIREWALL_Exported_Types FIREWALL Exported Types
63 * @brief FIREWALL Initialization Structure definition
67 uint32_t CodeSegmentStartAddress; /*!< Protected code segment start address. This value is 24-bit long, the 8 LSB bits are
68 reserved and forced to 0 in order to allow a 256-byte granularity. */
70 uint32_t CodeSegmentLength; /*!< Protected code segment length in bytes. This value is 22-bit long, the 8 LSB bits are
71 reserved and forced to 0 for the length to be a multiple of 256 bytes. */
73 uint32_t NonVDataSegmentStartAddress; /*!< Protected non-volatile data segment start address. This value is 24-bit long, the 8 LSB
74 bits are reserved and forced to 0 in order to allow a 256-byte granularity. */
76 uint32_t NonVDataSegmentLength; /*!< Protected non-volatile data segment length in bytes. This value is 22-bit long, the 8 LSB
77 bits are reserved and forced to 0 for the length to be a multiple of 256 bytes. */
79 uint32_t VDataSegmentStartAddress; /*!< Protected volatile data segment start address. This value is 17-bit long, the 6 LSB bits
80 are reserved and forced to 0 in order to allow a 64-byte granularity. */
82 uint32_t VDataSegmentLength; /*!< Protected volatile data segment length in bytes. This value is 17-bit long, the 6 LSB
83 bits are reserved and forced to 0 for the length to be a multiple of 64 bytes. */
85 uint32_t VolatileDataExecution; /*!< Set VDE bit specifying whether or not the volatile data segment can be executed.
86 When VDS = 1 (set by parameter VolatileDataShared), VDE bit has no meaning.
87 This parameter can be a value of @ref FIREWALL_VolatileData_Executable */
89 uint32_t VolatileDataShared; /*!< Set VDS bit in specifying whether or not the volatile data segment can be shared with a
90 non-protected application code.
91 This parameter can be a value of @ref FIREWALL_VolatileData_Shared */
93 }FIREWALL_InitTypeDef;
101 /* Exported constants --------------------------------------------------------*/
102 /** @defgroup FIREWALL_Exported_Constants FIREWALL Exported Constants
106 /** @defgroup FIREWALL_VolatileData_Executable FIREWALL volatile data segment execution status
109 #define FIREWALL_VOLATILEDATA_NOT_EXECUTABLE ((uint32_t)0x0000)
110 #define FIREWALL_VOLATILEDATA_EXECUTABLE ((uint32_t)FW_CR_VDE)
115 /** @defgroup FIREWALL_VolatileData_Shared FIREWALL volatile data segment share status
118 #define FIREWALL_VOLATILEDATA_NOT_SHARED ((uint32_t)0x0000)
119 #define FIREWALL_VOLATILEDATA_SHARED ((uint32_t)FW_CR_VDS)
124 /** @defgroup FIREWALL_Pre_Arm FIREWALL pre arm status
127 #define FIREWALL_PRE_ARM_RESET ((uint32_t)0x0000)
128 #define FIREWALL_PRE_ARM_SET ((uint32_t)FW_CR_FPA)
138 /* Private macros --------------------------------------------------------*/
139 /** @defgroup FIREWALL_Private_Macros FIREWALL Private Macros
142 #define IS_FIREWALL_CODE_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x080FFFFF))
143 #define IS_FIREWALL_CODE_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= 0x080FFFFF)
145 #define IS_FIREWALL_NONVOLATILEDATA_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x080FFFFF))
146 #define IS_FIREWALL_NONVOLATILEDATA_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= 0x080FFFFF)
148 #define IS_FIREWALL_VOLATILEDATA_SEGMENT_ADDRESS(ADDRESS) (((ADDRESS) >= 0x20000000) && ((ADDRESS) <= 0x20017FFF))
149 #define IS_FIREWALL_VOLATILEDATA_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= 0x20017FFF)
152 #define IS_FIREWALL_VOLATILEDATA_SHARE(SHARE) (((SHARE) == FIREWALL_VOLATILEDATA_NOT_SHARED) || \
153 ((SHARE) == FIREWALL_VOLATILEDATA_SHARED))
155 #define IS_FIREWALL_VOLATILEDATA_EXECUTE(EXECUTE) (((EXECUTE) == FIREWALL_VOLATILEDATA_NOT_EXECUTABLE) || \
156 ((EXECUTE) == FIREWALL_VOLATILEDATA_EXECUTABLE))
162 /* Exported macros -----------------------------------------------------------*/
163 /** @defgroup FIREWALL_Exported_Macros FIREWALL Exported Macros
167 /** @brief Check whether or not the FIREWALL is enabled
168 * @retval FIREWALL enabling status (TRUE or FALSE).
170 #define __HAL_FIREWALL_IS_ENABLED() HAL_IS_BIT_CLR(SYSCFG->CFGR2, SYSCFG_CFGR2_FWDISEN)
173 /** @brief Enable FIREWALL pre arm.
174 * @note When FPA bit is set, any code executed outside the protected segment
175 * closes the Firewall, otherwise it generates a system reset.
176 * @note This macro provides the same service as HAL_FIREWALL_EnablePreArmFlag() API
177 * but can be executed inside a code area protected by the Firewall.
178 * @note This macro can be executed whatever the Firewall state (opened or closed) when
179 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
180 * 0, that is, when the non volatile data segment is defined), the macro can be
181 * executed only when the Firewall is opened.
183 #define __HAL_FIREWALL_PREARM_ENABLE() \
185 __IO uint32_t tmpreg; \
186 SET_BIT(FW->CR, FW_CR_FPA) ; \
187 /* Read bit back to ensure it is taken into account by IP */ \
188 /* (introduce proper delay inside macro execution) */ \
189 tmpreg = READ_BIT(FW->CR, FW_CR_FPA) ; \
195 /** @brief Disable FIREWALL pre arm.
196 * @note When FPA bit is set, any code executed outside the protected segment
197 * closes the Firewall, otherwise, it generates a system reset.
198 * @note This macro provides the same service as HAL_FIREWALL_DisablePreArmFlag() API
199 * but can be executed inside a code area protected by the Firewall.
200 * @note This macro can be executed whatever the Firewall state (opened or closed) when
201 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
202 * 0, that is, when the non volatile data segment is defined), the macro can be
203 * executed only when the Firewall is opened.
205 #define __HAL_FIREWALL_PREARM_DISABLE() \
207 __IO uint32_t tmpreg; \
208 CLEAR_BIT(FW->CR, FW_CR_FPA) ; \
209 /* Read bit back to ensure it is taken into account by IP */ \
210 /* (introduce proper delay inside macro execution) */ \
211 tmpreg = READ_BIT(FW->CR, FW_CR_FPA) ; \
215 /** @brief Enable volatile data sharing in setting VDS bit.
216 * @note When VDS bit is set, the volatile data segment is shared with non-protected
217 * application code. It can be accessed whatever the Firewall state (opened or closed).
218 * @note This macro can be executed inside a code area protected by the Firewall.
219 * @note This macro can be executed whatever the Firewall state (opened or closed) when
220 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
221 * 0, that is, when the non volatile data segment is defined), the macro can be
222 * executed only when the Firewall is opened.
224 #define __HAL_FIREWALL_VOLATILEDATA_SHARED_ENABLE() \
226 __IO uint32_t tmpreg; \
227 SET_BIT(FW->CR, FW_CR_VDS) ; \
228 /* Read bit back to ensure it is taken into account by IP */ \
229 /* (introduce proper delay inside macro execution) */ \
230 tmpreg = READ_BIT(FW->CR, FW_CR_VDS) ; \
234 /** @brief Disable volatile data sharing in resetting VDS bit.
235 * @note When VDS bit is reset, the volatile data segment is not shared and cannot be
236 * hit by a non protected executable code when the Firewall is closed. If it is
237 * accessed in such a condition, a system reset is generated by the Firewall.
238 * @note This macro can be executed inside a code area protected by the Firewall.
239 * @note This macro can be executed whatever the Firewall state (opened or closed) when
240 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
241 * 0, that is, when the non volatile data segment is defined), the macro can be
242 * executed only when the Firewall is opened.
244 #define __HAL_FIREWALL_VOLATILEDATA_SHARED_DISABLE() \
246 __IO uint32_t tmpreg; \
247 CLEAR_BIT(FW->CR, FW_CR_VDS) ; \
248 /* Read bit back to ensure it is taken into account by IP */ \
249 /* (introduce proper delay inside macro execution) */ \
250 tmpreg = READ_BIT(FW->CR, FW_CR_VDS) ; \
254 /** @brief Enable volatile data execution in setting VDE bit.
255 * @note VDE bit is ignored when VDS is set. IF VDS = 1, the Volatile data segment can be
256 * executed whatever the VDE bit value.
257 * @note When VDE bit is set (with VDS = 0), the volatile data segment is executable. When
258 * the Firewall call is closed, a "call gate" entry procedure is required to open
259 * first the Firewall.
260 * @note This macro can be executed inside a code area protected by the Firewall.
261 * @note This macro can be executed whatever the Firewall state (opened or closed) when
262 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
263 * 0, that is, when the non volatile data segment is defined), the macro can be
264 * executed only when the Firewall is opened.
266 #define __HAL_FIREWALL_VOLATILEDATA_EXECUTION_ENABLE() \
268 __IO uint32_t tmpreg; \
269 SET_BIT(FW->CR, FW_CR_VDE) ; \
270 /* Read bit back to ensure it is taken into account by IP */ \
271 /* (introduce proper delay inside macro execution) */ \
272 tmpreg = READ_BIT(FW->CR, FW_CR_VDE) ; \
276 /** @brief Disable volatile data execution in resetting VDE bit.
277 * @note VDE bit is ignored when VDS is set. IF VDS = 1, the Volatile data segment can be
278 * executed whatever the VDE bit value.
279 * @note When VDE bit is reset (with VDS = 0), the volatile data segment cannot be executed.
280 * @note This macro can be executed inside a code area protected by the Firewall.
281 * @note This macro can be executed whatever the Firewall state (opened or closed) when
282 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
283 * 0, that is, when the non volatile data segment is defined), the macro can be
284 * executed only when the Firewall is opened.
286 #define __HAL_FIREWALL_VOLATILEDATA_EXECUTION_DISABLE() \
288 __IO uint32_t tmpreg; \
289 CLEAR_BIT(FW->CR, FW_CR_VDE) ; \
290 /* Read bit back to ensure it is taken into account by IP */ \
291 /* (introduce proper delay inside macro execution) */ \
292 tmpreg = READ_BIT(FW->CR, FW_CR_VDE) ; \
297 /** @brief Check whether or not the volatile data segment is shared.
298 * @note This macro can be executed inside a code area protected by the Firewall.
299 * @note This macro can be executed whatever the Firewall state (opened or closed) when
300 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
301 * 0, that is, when the non volatile data segment is defined), the macro can be
302 * executed only when the Firewall is opened.
303 * @retval VDS bit setting status (TRUE or FALSE).
305 #define __HAL_FIREWALL_GET_VOLATILEDATA_SHARED() ((FW->CR & FW_CR_VDS) == FW_CR_VDS)
307 /** @brief Check whether or not the volatile data segment is declared executable.
308 * @note This macro can be executed inside a code area protected by the Firewall.
309 * @note This macro can be executed whatever the Firewall state (opened or closed) when
310 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
311 * 0, that is, when the non volatile data segment is defined), the macro can be
312 * executed only when the Firewall is opened.
313 * @retval VDE bit setting status (TRUE or FALSE).
315 #define __HAL_FIREWALL_GET_VOLATILEDATA_EXECUTION() ((FW->CR & FW_CR_VDE) == FW_CR_VDE)
317 /** @brief Check whether or not the Firewall pre arm bit is set.
318 * @note This macro can be executed inside a code area protected by the Firewall.
319 * @note This macro can be executed whatever the Firewall state (opened or closed) when
320 * NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
321 * 0, that is, when the non volatile data segment is defined), the macro can be
322 * executed only when the Firewall is opened.
323 * @retval FPA bit setting status (TRUE or FALSE).
325 #define __HAL_FIREWALL_GET_PREARM() ((FW->CR & FW_CR_FPA) == FW_CR_FPA)
332 /* Exported functions --------------------------------------------------------*/
334 /** @addtogroup FIREWALL_Exported_Functions FIREWALL Exported Functions
338 /** @addtogroup FIREWALL_Exported_Functions_Group1 Initialization Functions
339 * @brief Initialization and Configuration Functions
343 /* Initialization functions ********************************/
344 HAL_StatusTypeDef HAL_FIREWALL_Config(FIREWALL_InitTypeDef * fw_init);
345 void HAL_FIREWALL_GetConfig(FIREWALL_InitTypeDef * fw_config);
346 void HAL_FIREWALL_EnableFirewall(void);
347 void HAL_FIREWALL_EnablePreArmFlag(void);
348 void HAL_FIREWALL_DisablePreArmFlag(void);
370 #endif /* __STM32L0xx_HAL_FIREWALL_H */
372 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/