2024-10-08 10:43 PM - edited 2024-10-08 10:45 PM
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!
2024-10-09 02:28 AM
Hello @K_K ,
Are you sure it's not the watch dog causing the behavior?
Start with a very simple project by toggling a LED, do you have the same behavior?
2024-10-09 03:49 AM
Hello @SofLit
Yes, I am sure that the issue is not related to the watchdog, as this problem arises when I power up the board, and the code fails to reach the MX_GPIO_Init() line.
Additionally, I have tested a simple program and did not encounter this issue. I have already compared the project settings of both codes, and they are identical.
One observation is that I maintain revisions by copying and pasting the entire code folder. This problem typically occurs when I change the folder name and import it at IDE startup.
For example, when I rename my code folder from 0.0.1 to 0.0.2, I start encountering issues. I do clean, refresh, and rebuild everything after the import.
Thanks!
2024-10-09 03:58 AM
@K_K wrote:
For example, when I rename my code folder from 0.0.1 to 0.0.2, I start encountering issues.
That's a strange behavior!
2024-10-09 04:10 AM
Hmm seems more as hw not sw trouble. 1. BOOT pins is managed right ? 2. HSE is managed right ?
2024-10-09 04:42 AM
@K_K wrote:I have turned ON three LEDs in the MX_GPIO_Init() function, but they do not light up when the code execution fails.
So try lighting LEDs at earlier points in the code - to see where it's actually getting to.
Also have something to tell you when Hard Fault and Error Handler are hit ...
2024-10-10 12:38 AM
Hi,
I don't see any problem related to hardware and software configuration.
Here are the hardware details:
When the RELEASE macro is disabled, the first function called after clock configuration is MX_GPIO_Init(), and in this function LEDs are initialized very first.
Please let me know if there's anything else I should check.
Thanks
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/*AXI clock gating */
RCC->CKGAENR = 0xFFFFFFFF;
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 5;
RCC_OscInitStruct.PLL.PLLN = 96;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 10;
RCC_OscInitStruct.PLL.PLLR = 8;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief Peripherals Common Clock Configuration
* @retval None
*/
void PeriphCommonClock_Config(void)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_FDCAN;
PeriphClkInitStruct.PLL2.PLL2M = 5;
PeriphClkInitStruct.PLL2.PLL2N = 32;
PeriphClkInitStruct.PLL2.PLL2P = 4;
PeriphClkInitStruct.PLL2.PLL2Q = 4;
PeriphClkInitStruct.PLL2.PLL2R = 2;
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_2;
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;
PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
PeriphClkInitStruct.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL2;
PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
}
2024-10-10 12:44 AM
Remove HSE 25M from board, config your sw to HSI and test. If all work OK = your HSE is problem.
2024-10-10 01:29 AM
Please post the schematic
2024-10-10 04:15 AM
Please note that this behavior is occurring across all boards.
Schematic attached.