stm32l0xx_hal_firewall.h 18 KB

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