cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to set the system clock on an stm32f3discovery board yields an hard fault.

SStel
Associate

Hi.,

I am very very new to micro controller programming and hit a wall very early on.

I have an stm32f3 discovery board which is an stm32f303 vct6.

I generated code with PINs 8 through 15 being output pins within stm32 cube and imported that code into crossworks. It loads, compiles and starts fine.

However, during system clock configuration it hard faults.

```

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

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

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

 RCC_OscInitStruct.HSIState = RCC_HSI_ON;

 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** 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_HSI;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

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

 {

  Error_Handler();

 }

}

```

This is the generated init function for the clock. When I debug this, I notice, that the argument to HAL_RCC_OscConfig is passed correctly via r0, but when my IDE jumps to the called function, the parameter seems to be 0xffffffff. 

It looks like as soon as the parameter is to be touched, the board hard faults.

I do not understand what Im doing wrong here. I attempt to run the board at 8 MHz.

If I skip the call to HAL_RCC_OscConfig, everything runs fine. But eventually I want to play with the clock. Any help is appreciated.

Thanks

1 REPLY 1

The part is running from the HSI when it starts.

If the clock/PLL is faster, you'd need to increase the flash latency appropriately.

Should be examples in HAL library that run the board at 72 MHz, should probably build and try those.

Try a different compiler/toolchain. Most of the test apps will build with demo versions of Keil or IAR.

Update the ST-LINK firmware, probably rather old on the F3-DISCO

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..