cancel
Showing results for 
Search instead for 
Did you mean: 

Newbie with newbie problems Oscillator start up ?

John_S
Associate II

Hi People,

for the since start of year i've been setting up boards with Texas C2000 , and for the past 6 months infineon tri-core processors.  I may be changing jobs and it involves STM32 so i'm getting a head start. I have a STM32373C-EVAL , as i need TFT display and CAN. i have attempted to make a 'blinky ' project. Compiles fine but when it runs it hangs on the oscilator start up . Fresh install of STM32CubeIDE so used the config tool and let it do all the defaults.. The dev kit has solder bridges for crystal - they are open , but i've let it use the PLL.  it wont let me 

John_S_0-1726412883613.png

When running in debug it 'hangs' on stopping the code , its in the error handler from the system clock settings , if i comment out the error handler it runs . 

 

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};





/** Initializes the RCC Oscillators according to the specified parameters

* in the RCC_OscInitTypeDef structure.

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;

RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

Error_Handler(); // sometimes comment this out

}



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

*/

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

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_1) != HAL_OK)

{

// Error_Handler(); // wont get past this one either , but still runs ok ... why ?

}

}

Has anyone else have this grief ?

Are u supposed to do something about this... Other micros i've used you just set them up and job done ?!?!

 

for now i'm leaving the check commented out so i can carry on .. Some advice would be helpful though

 

Thanks In Advance

 

1 ACCEPTED SOLUTION

Accepted Solutions

@John_S 

Again check the Crystal connection or simply replace it.

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.

View solution in original post

14 REPLIES 14
SofLit
ST Employee

Hello @John_S and welcome to the community,

According to your Clock config and the screenshot you shared, you are using the internal clock HSI as clock source for the system not HSE (for external crystal usage):

SofLit_0-1726419849681.png

And from your code:

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;

RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

That's strange!

Could you please attach your ioc file?

 

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.
Rob.Riggs
Senior III

I don't see anything that stands out as a problem. It has been a while since I worked with an STM32F3. Are you sure that the sysclock is actually running at 36MHz when it returns with an error?

I recommend stepping through the code in the debugger to see where it is returning with an error.

Set a breakpoint on the line that calls HAL_RCC_ClockConfig() and step into that function until an error is returned. It should provide a bit more information on what is triggering the failure.

Andrew Neil
Evangelist III

@John_S wrote:

The dev kit has solder bridges for crystal - they are open , but i've let it use the PLL.  it wont let me 

John_S_0-1726412883613.png

 


Not quite sure what you mean here?

As shown (as @SofLit said) you are using HSI - is that the case which fails?

Or are you trying to use HSE, and that's the case which fails?

To use HSE, you'll need an external crystal connected - ie, the solder bridges closed

John_S
Associate II

config file ..

plus 

Main.c

I was going to upload the whole project but wont accept .zip ... 

Project made fresh in STM32cubeMX then loaded in to cubeIDE ..

as a test i shut down IDE .. pulled the ST/link out so no power . Put plug back in (nothing ) , reloaded IDE up loaded with debug the file that was just working ... nothing .....  i'm a bit confused 

 

 

 

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 

/** Initializes the RCC Oscillators according to the specified parameters

* in the RCC_OscInitTypeDef structure.

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;

RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

Error_Handler(); // ********** Sometimes hangs here

}

 

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

*/

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

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_1) != HAL_OK)

{

Error_Handler(); // ************ Hangs here if its going to

} // if i comment out this if statement the micro wont run but

// when i uncomment after and rebuild it will now run...

// strange as hell

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB|RCC_PERIPHCLK_USART2

|RCC_PERIPHCLK_CEC|RCC_PERIPHCLK_I2C1

|RCC_PERIPHCLK_I2C2|RCC_PERIPHCLK_ADC1

|RCC_PERIPHCLK_SDADC;

PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;

PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI;

PeriphClkInit.I2c2ClockSelection = RCC_I2C2CLKSOURCE_HSI;

PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL;

PeriphClkInit.CecClockSelection = RCC_CECCLKSOURCE_HSI;

PeriphClkInit.SdadcClockSelection = RCC_SDADCSYSCLK_DIV8;

PeriphClkInit.Adc1ClockSelection = RCC_ADC1PCLK2_DIV2;

 

if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

{

Error_Handler();

}

HAL_PWREx_EnableSDADC(PWR_SDADC_ANALOG1);

HAL_PWREx_EnableSDADC(PWR_SDADC_ANALOG2);

}

 

Hello,

That config is different from what you posted in the first post:

SofLit_2-1726500712157.png

The first one is using HSI and now it is using HSE. Please try to not induce us to confusions during the discussions.

Are you sure X2 crystal is mounted on its socket? Is R38 soldered?

SofLit_1-1726500552699.png

 

 

 

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.
John_S
Associate II

sorry i've been trying different configurations to see what works... I may have got mixed up between the two. 

Yes crystal is in and r38 is in (0 ohm ) 

And if you revert o the first config: HSI (remove USB function for the moment), do you get the same behavior?

SofLit_0-1726501358157.png

SofLit_1-1726501390732.png

 

 

 

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.
John_S
Associate II

The code runs  

but i've had to comment out the I2C1_init  functions ...

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_ADC1_Init();

MX_COMP2_Init();

MX_HDMI_CEC_Init();

// MX_I2C1_Init();

// MX_I2C2_SMBUS_Init();

// MX_I2S1_Init();

MX_SDADC1_Init();

MX_SDADC2_Init();

MX_SPI3_Init();

MX_TSC_Init();

MX_USART2_UART_Init();

/* USER CODE BEGIN 2 */

First, in next time please use </> button to share your code. I'm editing your post then .

Second, as with HSI is working, I'm pretty sure it's something related to the crystal. Be sure the crystal has contact in the socket. Maybe to apply a bit pressure on it with your finger.

 

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.