Code execution fails on power up (STM32H7A3VGT6 with Cube IDE)
Hello,
I am currently using the STM32H7A3VGT6 along with STM32 Cube IDE for debugging. My code starts properly in debug mode, but when I power cycle the device without the ST link connected, it sometimes executes and sometimes does not. I have turned ON three LEDs in the MX_GPIO_Init() function, but they do not light up when the code execution fails.
To address this, I adjusted the optimization level from -Og (debug) to O1 (level-1), and the code ran as expected without the debugger. However, after a while, the code stopped executing at optimization level O1, prompting me to revert to -Og for it to work properly again.
I have attached the project settings, debug settings, and code initialization for your reference.
CubeIDE version: 1.14.1
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
#ifdef RELEASE
DisableIwdgInStopMode();
#endif
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
#ifdef RELEASE
MX_IWDG1_Init();
#endif
MX_DMA_Init();
MX_I2C2_Init();
MX_SPI1_Init();
MX_FDCAN1_Init();
PWM_Init();
MX_USART1_UART_Init(); // must be after read configuration
MX_USB_DEVICE_Init(); // must be after read configuration
MX_ADC1_Init();
MX_ADC2_Init();
Start_ADC();
MX_TIM1_Init();
//Test_Code();
/* USER CODE BEGIN 2 */
Key_Init();
HAL_TIM_OC_Start(&htim1,TIM_CHANNEL_1);
#ifdef POWER_CALC_OLD
MX_TIM3_Init();
#endif
MX_TIM2_Init();
// TIM3 for processing 5 ADC samples of each channel at 500usec
#ifdef POWER_CALC_OLD
HAL_TIM_Base_Start_IT(&htim3);
#endif
/* USER CODE BEGIN 2 */
Start_CAN();
while(1)
{
}
}


I would appreciate any assistance you can provide.
Thank you!
