hm_fa_da
Full Member level 5
Hello,
I have a question on C programming for STM32 by Keil compiler:
If I define a variable on top of my code, (before main() ) like:
/* USER CODE BEGIN PV */
uint8_t Var_x = 5;
/* USER CODE END PV */
int main(void)
{
program code ....
HAL_NVIC_SystemReset(); // **Software reset code
}
1- when the circuit is powered up and hardware reset, the Var_x will get value 5, right ?
2- How about if the code gets to the software reset function in main() ? would it set the Var_x value to 5 after software reset ?
or maybe I can ask the question in this way, is the below code functionality exactly same with the above one :
/* USER CODE BEGIN PV */
uint8_t Var_x;
/* USER CODE END PV */
int main(void)
{
Var_x = 5;
program code ....
HAL_NVIC_SystemReset(); // **Software reset code
}
In fact I am using the "HAL_NVIC_SystemReset();" in:
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
HAL_NVIC_SystemReset();
/* USER CODE END Error_Handler_Debug */
}
and:
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
HAL_NVIC_SystemReset();
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
I'm not sure if in these cases, the Var_x gets value 5 after software reset, I can't simulate this status (Hardfault or error handler) to check it ... I guess maybe hardfault condition makes it impossible to access memory after reset to set the Var_x to value 5 ... ?!
Thank you
I have a question on C programming for STM32 by Keil compiler:
If I define a variable on top of my code, (before main() ) like:
/* USER CODE BEGIN PV */
uint8_t Var_x = 5;
/* USER CODE END PV */
int main(void)
{
program code ....
HAL_NVIC_SystemReset(); // **Software reset code
}
1- when the circuit is powered up and hardware reset, the Var_x will get value 5, right ?
2- How about if the code gets to the software reset function in main() ? would it set the Var_x value to 5 after software reset ?
or maybe I can ask the question in this way, is the below code functionality exactly same with the above one :
/* USER CODE BEGIN PV */
uint8_t Var_x;
/* USER CODE END PV */
int main(void)
{
Var_x = 5;
program code ....
HAL_NVIC_SystemReset(); // **Software reset code
}
In fact I am using the "HAL_NVIC_SystemReset();" in:
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
HAL_NVIC_SystemReset();
/* USER CODE END Error_Handler_Debug */
}
and:
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
HAL_NVIC_SystemReset();
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
I'm not sure if in these cases, the Var_x gets value 5 after software reset, I can't simulate this status (Hardfault or error handler) to check it ... I guess maybe hardfault condition makes it impossible to access memory after reset to set the Var_x to value 5 ... ?!
Thank you
Last edited: