You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

369 lines
18 KiB

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