AnsweredAssumed Answered

Stm32F405 CubeMX code lead to Hardfault

Question asked by saperlot on Mar 4, 2014
Latest reply on Mar 5, 2014 by saperlot
Hi
I'm exploring the STM32F405 and for this, i wanted to create the initial project with the Cube MX tool. 
I've settet all the things up to my configuration. In minimal i just set the hole clock thing up.

I've burned this down to the chip just to make sure if the thing going to my while(1).

But the generated code leads to the Hardfault error handler.
I discovered that the fault is happening somewhere around when it calculates the latency for flash read write. 
This is in the beginning of the method: HAL_RCC_ClockConfig  located in stm32f4xx_hal_rcc.c

It jumps directly after command " if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE) "  (Line 782) to Address 0

I don't think that i have to change some lines in the library.. 
Probably the clock is set the wrong way.
here are the values out of the generated code:

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE;
  RCC_OscInitStruct.LSEState = RCC_LSE_BYPASS;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 6;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 10;
  RCC_OscInitStruct.PLL.PLLN = 210;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);


  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);

Outcomes