STM32L4xx_HAL_Driver  1.14.0

Initialization and Configuration Functions. More...

Functions

HAL_StatusTypeDef HAL_FIREWALL_Config (FIREWALL_InitTypeDef *fw_init)
 Initialize the Firewall according to the FIREWALL_InitTypeDef structure parameters. More...
 
void HAL_FIREWALL_GetConfig (FIREWALL_InitTypeDef *fw_config)
 Retrieve the Firewall configuration. More...
 
void HAL_FIREWALL_EnableFirewall (void)
 Enable FIREWALL. More...
 
void HAL_FIREWALL_EnablePreArmFlag (void)
 Enable FIREWALL pre arm. More...
 
void HAL_FIREWALL_DisablePreArmFlag (void)
 Disable FIREWALL pre arm. More...
 

Detailed Description

Initialization and Configuration Functions.

===============================================================================
            ##### Initialization and Configuration functions #####
 ===============================================================================
    [..]
    This subsection provides the functions allowing to initialize the Firewall.
    Initialization is done by HAL_FIREWALL_Config():

      (+) Enable the Firewall clock thru __HAL_RCC_FIREWALL_CLK_ENABLE() macro.

      (+) Set the protected code segment address start and length.

      (+) Set the protected non-volatile and/or volatile data segments
          address starts and lengths if applicable.

      (+) Set the volatile data segment execution and sharing status.

      (+) Length must be set to 0 for an unprotected segment.

Function Documentation

◆ HAL_FIREWALL_Config()

HAL_StatusTypeDef HAL_FIREWALL_Config ( FIREWALL_InitTypeDef *  fw_init)

Initialize the Firewall according to the FIREWALL_InitTypeDef structure parameters.

Parameters
fw_initFirewall initialization structure
Note
The API returns HAL_ERROR if the Firewall is already enabled.
Return values
HALstatus

Definition at line 103 of file stm32l4xx_hal_firewall.c.

104 {
105  /* Check the Firewall initialization structure allocation */
106  if(fw_init == NULL)
107  {
108  return HAL_ERROR;
109  }
110 
111  /* Enable Firewall clock */
112  __HAL_RCC_FIREWALL_CLK_ENABLE();
113 
114  /* Make sure that Firewall is not enabled already */
115  if (__HAL_FIREWALL_IS_ENABLED() != RESET)
116  {
117  return HAL_ERROR;
118  }
119 
120  /* Check Firewall configuration addresses and lengths when segment is protected */
121  /* Code segment */
122  if (fw_init->CodeSegmentLength != 0U)
123  {
124  assert_param(IS_FIREWALL_CODE_SEGMENT_ADDRESS(fw_init->CodeSegmentStartAddress));
125  assert_param(IS_FIREWALL_CODE_SEGMENT_LENGTH(fw_init->CodeSegmentStartAddress, fw_init->CodeSegmentLength));
126  /* Make sure that NonVDataSegmentLength is properly set to prevent code segment access */
127  if (fw_init->NonVDataSegmentLength < 0x100U)
128  {
129  return HAL_ERROR;
130  }
131  }
132  /* Non volatile data segment */
133  if (fw_init->NonVDataSegmentLength != 0U)
134  {
135  assert_param(IS_FIREWALL_NONVOLATILEDATA_SEGMENT_ADDRESS(fw_init->NonVDataSegmentStartAddress));
136  assert_param(IS_FIREWALL_NONVOLATILEDATA_SEGMENT_LENGTH(fw_init->NonVDataSegmentStartAddress, fw_init->NonVDataSegmentLength));
137  }
138  /* Volatile data segment */
139  if (fw_init->VDataSegmentLength != 0U)
140  {
141  assert_param(IS_FIREWALL_VOLATILEDATA_SEGMENT_ADDRESS(fw_init->VDataSegmentStartAddress));
142  assert_param(IS_FIREWALL_VOLATILEDATA_SEGMENT_LENGTH(fw_init->VDataSegmentStartAddress, fw_init->VDataSegmentLength));
143  }
144 
145  /* Check Firewall Configuration Register parameters */
146  assert_param(IS_FIREWALL_VOLATILEDATA_EXECUTE(fw_init->VolatileDataExecution));
147  assert_param(IS_FIREWALL_VOLATILEDATA_SHARE(fw_init->VolatileDataShared));
148 
149 
150  /* Configuration */
151 
152  /* Protected code segment start address configuration */
153  WRITE_REG(FIREWALL->CSSA, (FW_CSSA_ADD & fw_init->CodeSegmentStartAddress));
154  /* Protected code segment length configuration */
155  WRITE_REG(FIREWALL->CSL, (FW_CSL_LENG & fw_init->CodeSegmentLength));
156 
157  /* Protected non volatile data segment start address configuration */
158  WRITE_REG(FIREWALL->NVDSSA, (FW_NVDSSA_ADD & fw_init->NonVDataSegmentStartAddress));
159  /* Protected non volatile data segment length configuration */
160  WRITE_REG(FIREWALL->NVDSL, (FW_NVDSL_LENG & fw_init->NonVDataSegmentLength));
161 
162  /* Protected volatile data segment start address configuration */
163  WRITE_REG(FIREWALL->VDSSA, (FW_VDSSA_ADD & fw_init->VDataSegmentStartAddress));
164  /* Protected volatile data segment length configuration */
165  WRITE_REG(FIREWALL->VDSL, (FW_VDSL_LENG & fw_init->VDataSegmentLength));
166 
167  /* Set Firewall Configuration Register VDE and VDS bits
168  (volatile data execution and shared configuration) */
169  MODIFY_REG(FIREWALL->CR, FW_CR_VDS|FW_CR_VDE, fw_init->VolatileDataExecution|fw_init->VolatileDataShared);
170 
171  return HAL_OK;
172 }
return HAL_OK
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_FIREWALL_DisablePreArmFlag()

void HAL_FIREWALL_DisablePreArmFlag ( void  )

Disable FIREWALL pre arm.

Note
When FPA bit is reset, any code executed outside the protected segment when the Firewall is opened will generate a system reset.
This API provides the same service as __HAL_FIREWALL_PREARM_DISABLE() macro but can't be executed inside a code area protected by the Firewall.
When the Firewall is disabled, user can resort to HAL_FIREWALL_EnablePreArmFlag() API any time.
When the Firewall is enabled and NVDSL register is equal to 0 (that is, when the non volatile data segment is not defined), ** this API can be executed when the Firewall is closed ** when the Firewall is opened, user should resort to __HAL_FIREWALL_PREARM_DISABLE() macro instead
When the Firewall is enabled and NVDSL register is different from 0 (that is, when the non volatile data segment is defined) ** FW_CR register can be accessed only when the Firewall is opened: user should resort to __HAL_FIREWALL_PREARM_DISABLE() macro instead.
Return values
None

Definition at line 272 of file stm32l4xx_hal_firewall.c.

273 {
274  /* Clear FPA bit */
275  CLEAR_BIT(FIREWALL->CR, FW_CR_FPA);
276 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)

◆ HAL_FIREWALL_EnableFirewall()

void HAL_FIREWALL_EnableFirewall ( void  )

Enable FIREWALL.

Note
Firewall is enabled in clearing FWDIS bit of SYSCFG CFGR1 register. Once enabled, the Firewall cannot be disabled by software. Only a system reset can set again FWDIS bit.
Return values
None

Definition at line 221 of file stm32l4xx_hal_firewall.c.

222 {
223  /* Clears FWDIS bit of SYSCFG CFGR1 register */
224  CLEAR_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_FWDIS);
225 
226 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)

◆ HAL_FIREWALL_EnablePreArmFlag()

void HAL_FIREWALL_EnablePreArmFlag ( void  )

Enable FIREWALL pre arm.

Note
When FPA bit is set, any code executed outside the protected segment will close the Firewall.
This API provides the same service as __HAL_FIREWALL_PREARM_ENABLE() macro but can't be executed inside a code area protected by the Firewall.
When the Firewall is disabled, user can resort to HAL_FIREWALL_EnablePreArmFlag() API any time.
When the Firewall is enabled and NVDSL register is equal to 0 (that is, when the non volatile data segment is not defined), ** this API can be executed when the Firewall is closed ** when the Firewall is opened, user should resort to __HAL_FIREWALL_PREARM_ENABLE() macro instead
When the Firewall is enabled and NVDSL register is different from 0 (that is, when the non volatile data segment is defined) ** FW_CR register can be accessed only when the Firewall is opened: user should resort to __HAL_FIREWALL_PREARM_ENABLE() macro instead.
Return values
None

Definition at line 246 of file stm32l4xx_hal_firewall.c.

247 {
248  /* Set FPA bit */
249  SET_BIT(FIREWALL->CR, FW_CR_FPA);
250 }

◆ HAL_FIREWALL_GetConfig()

void HAL_FIREWALL_GetConfig ( FIREWALL_InitTypeDef *  fw_config)

Retrieve the Firewall configuration.

Parameters
fw_configFirewall configuration, type is same as initialization structure
Note
This API can't be executed inside a code area protected by the Firewall when the Firewall is enabled
If NVDSL register is different from 0, that is, if the non volatile data segment is defined, this API can't be executed when the Firewall is enabled.
User should resort to __HAL_FIREWALL_GET_PREARM() macro to retrieve FPA bit status
Return values
None

Definition at line 184 of file stm32l4xx_hal_firewall.c.

185 {
186 
187  /* Enable Firewall clock, in case no Firewall configuration has been carried
188  out up to this point */
189  __HAL_RCC_FIREWALL_CLK_ENABLE();
190 
191  /* Retrieve code segment protection setting */
192  fw_config->CodeSegmentStartAddress = (READ_REG(FIREWALL->CSSA) & FW_CSSA_ADD);
193  fw_config->CodeSegmentLength = (READ_REG(FIREWALL->CSL) & FW_CSL_LENG);
194 
195  /* Retrieve non volatile data segment protection setting */
196  fw_config->NonVDataSegmentStartAddress = (READ_REG(FIREWALL->NVDSSA) & FW_NVDSSA_ADD);
197  fw_config->NonVDataSegmentLength = (READ_REG(FIREWALL->NVDSL) & FW_NVDSL_LENG);
198 
199  /* Retrieve volatile data segment protection setting */
200  fw_config->VDataSegmentStartAddress = (READ_REG(FIREWALL->VDSSA) & FW_VDSSA_ADD);
201  fw_config->VDataSegmentLength = (READ_REG(FIREWALL->VDSL) & FW_VDSL_LENG);
202 
203  /* Retrieve volatile data execution setting */
204  fw_config->VolatileDataExecution = (READ_REG(FIREWALL->CR) & FW_CR_VDE);
205 
206  /* Retrieve volatile data shared setting */
207  fw_config->VolatileDataShared = (READ_REG(FIREWALL->CR) & FW_CR_VDS);
208 
209  return;
210 }