cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L452RET6 HardFault from HSE

Anton Doinikov
Associate II
Posted on July 10, 2018 at 11:14

Hello, Help me please. I configuration STM32L452RET6 in the CUBEMX, how on the pictures. Then I build project in the Attolic and go to debuger and then when MCU is starting work, it go in the HardFault_Handler(void) through 1-5 seconds. Why? I can't find problem. Maybe anyone know?

Crystal clock is Abracon LLC ABM9- 8.000MHZ-10-D-1U-T.

/**

******************************************************************************

* @file : main.c

* @brief : Main program body

******************************************************************************

*/

/* Includes ------------------------------------------------------------------*/

&sharpinclude 'main.h'

&sharpinclude 'stm32l4xx_hal.h'

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

/* USER CODE BEGIN PFP */

/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**

* @brief The application entry point.

*

* @retval None

*/

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();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */

MX_GPIO_Init();

/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_12);

HAL_Delay(300);

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}

/**

* @brief System Clock Configuration

* @retval None

*/

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct;

RCC_ClkInitTypeDef RCC_ClkInitStruct;

/**Initializes the CPU, AHB and APB busses clocks

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Initializes the CPU, AHB and APB busses clocks

*/

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Enables the Clock Security System

*/

HAL_RCC_EnableCSS();

/**Configure the main internal regulator output voltage

*/

if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Configure the Systick interrupt time

*/

HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

/**Configure the Systick

*/

HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

/* SysTick_IRQn interrupt configuration */

HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

/** Configure pins as

* Analog

* Input

* Output

* EVENT_OUT

* EXTI

*/

static void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOC_CLK_ENABLE();

__HAL_RCC_GPIOH_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

__HAL_RCC_GPIOB_CLK_ENABLE();

/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);

/*Configure GPIO pin : PA12 */

GPIO_InitStruct.Pin = GPIO_PIN_12;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**

* @brief Period elapsed callback in non blocking mode

* @note This function is called when TIM2 interrupt took place, inside

* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment

* a global variable 'uwTick' used as application time base.

* @param htim : TIM handle

* @retval None

*/

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

/* USER CODE BEGIN Callback 0 */

/* USER CODE END Callback 0 */

if (htim->Instance == TIM2) {

HAL_IncTick();

}

/* USER CODE BEGIN Callback 1 */

/* USER CODE END Callback 1 */

}

/**

* @brief This function is executed in case of error occurrence.

* @param file: The file name as string.

* @param line: The line in file as a number.

* @retval None

*/

void _Error_Handler(char *file, int line)

{

/* USER CODE BEGIN Error_Handler_Debug */

/* User can add his own implementation to report the HAL error return state */

while(1)

{

}

/* USER CODE END Error_Handler_Debug */

}

&sharpifdef USE_FULL_ASSERT

/**

* @brief Reports the name of the source file and the source line number

* where the assert_param error has occurred.

* @param file: pointer to the source file name

* @param line: assert_param error line source number

* @retval None

*/

void assert_failed(uint8_t* file, uint32_t line)

{

/* USER CODE BEGIN 6 */

/* User can add his own implementation to report the file name and line number,

tex: printf('Wrong parameters value: file %s on line %d\r\n', file, line) */

/* USER CODE END 6 */

}

&sharpendif /* USE_FULL_ASSERT */

/**

* @}

*/

/**

* @}

*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

#stm32l452 #stm32l4 #no-working-hse-stm32l4
12 REPLIES 12
Posted on July 11, 2018 at 11:03

I am cheking clock signal on the MCO pin and signal is very good.

I check 

define for HSE_VALUE in stm32xxxx_hal_conf.h. It is 8 MHz.

If I stand crystal clock on the 16 MHz and AHB Prescaler = 2, board is working. But if I stand crystal clock on the 8 MHz, MCU go to 

HardFault_Handler(void) on the Debagger mode. But if I disconnect Debugger, and reseting MCU. MCU work stably. Why? Do you know?

Posted on July 11, 2018 at 12:13

Read out the content of relevant RCC registers in case of problem and check/post.

JW

Posted on July 11, 2018 at 12:21

Hi Anton,

In both configuration case, are you able to debug step by step your SystemClock_Config() function by placing a breakpoint at the beginning. Then step into HAL_RCC_OscConfig(&RCC_OscInitStruct) to troubleshoot the Hard Fault ?

In addition, what is your hardware? Is it a board that you designed yourself? Or a NucleoL452?

BR

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.