cancel
Showing results for 
Search instead for 
Did you mean: 

stm32u585 clock config

Ephraimoved
Associate III

Dear Sir.

Attached a code of SystemClock_Config();

void SystemClock_Config(void)
{
	  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
	  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
	  /** Configure the main internal regulator output voltage
	  */
	  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
	  {
	    Error_Handler();
	  }
 
	  /** Configure LSE Drive Capability
	  */
	  HAL_PWR_EnableBkUpAccess();
	  __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH);
 
	  /** Initializes the CPU, AHB and APB buses clocks
	  */
	  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|
			  	  	  	  	  	  	  	 RCC_OSCILLATORTYPE_LSE|
										 RCC_OSCILLATORTYPE_MSI;
 
	  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
	  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
	  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
	  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
	  RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
	  RCC_OscInitStruct.MSIClockRange =       RCC_MSIRANGE_0;
	  RCC_OscInitStruct.PLL.PLLState =        RCC_PLL_NONE;
 
 
	  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_PCLK3;
	  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
	  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
	  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
	  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
	  RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
 
 
	  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
	  {
	    Error_Handler();
	  }
 
	  /** LSCO configuration  , 32.768 khz to LPTIM2. */
	  HAL_RCCEx_EnableLSCO(RCC_MCO1SOURCE_LSE);
 
	  /** MCO configuration  , 32.768 khz to MAX3000X. */
	  HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_LSE, RCC_MCODIV_1);
 
#endif

when line 24 is enabled RCC_OscInitStruct.LSEState = RCC_LSE_ON;

I get 32.khz on pin PA2 , even if PA2 is configures as analog input.

When line 24 is commented , no 32khz on PA2.

How to resolve this issue . I must use PA2 as analog. The PCB is already designed.

Please Advise.

1 ACCEPTED SOLUTION

Accepted Solutions
Jaroslav JANOS
ST Employee

OK, so "getting close" means that there is some output of the ADC, which is not correct?

If you can swap the inputs on the PCB, do it. Otherwise you will need to compute the correct value in software.

BR,

Jaroslav

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

9 REPLIES 9
Jaroslav JANOS
ST Employee

Hi @Community member​,

in your code (line 56), you have switched on the LSCO (low-speed clock output), which is on STM32U5xx only on pin PA2:

	  /** LSCO configuration  , 32.768 khz to LPTIM2. */
	  HAL_RCCEx_EnableLSCO(RCC_MCO1SOURCE_LSE);

If you do not need the low-speed clock external output, you can delete this line. After that, you won't see those 32 kHz on PA2.

BR,

Jaroslav

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.

Ephraimoved
Associate III

Hi.

To be more spsecific I need the following

  1. LSE running and on PA8.
  2. PA2 configured wit PA1 as Analog diffrentisl mode.

I deleted the line HAL_RCCEx_EnableLSCO(RCC_MCO1SOURCE_LSE);

32khz still appears on PA2 ,

Only if I add the line HAL_RCCEx_DisableLSCO(); I don't get 32kz on PA2 ,

but PA2 is not working well as analog diffferenatil

Thans

Jaroslav JANOS
ST Employee

Hi,

regarding your questions:

  1. Disabling LSCO has no influence on MCO on PA8, which you (correctly) configure on line 59. So even now you should see 32 kHz on PA8.
  2. Yes, that should be possible. Could you please explain "is not working well" in a greater detail? Is the ADC in the differential mode working? If not, could you please attach your ADC configuration code?
  3. The configuration of LSCO might have stayed in the backup domain register, I forgot to advise you to totally power-off the device, sorry. Anyway, disabling it with this function call is also valid.

BR,

Jaroslav

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.

Ephraimoved
Associate III

Hi.

I can send you github link . How can I do it privately ?

Jaroslav JANOS
ST Employee

You can send me a private message here, or contact me via e-mail jaroslav.janos@st.com

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.

Ephraimoved
Associate III

Hi

We are getting close , attched a pic

See PZO_AUDIO is the positive into PA2 .

E4_VREF is the negative into PA1 .

Should I swpa the pins ( by hardware ) or any workaround in software ?

Please Advise

Instead of posting code/link to code, read out and check/post content of ADC and relevant GPIO registers; and describe what's your related hardware, how do you observe the "is not working well" state and how does it differ from your expectations.

Also note, that in STM32, ADC in differential mode has a very restricted common-mode voltage.range.

JW

Jaroslav JANOS
ST Employee

OK, so "getting close" means that there is some output of the ADC, which is not correct?

If you can swap the inputs on the PCB, do it. Otherwise you will need to compute the correct value in software.

BR,

Jaroslav

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.

Ephraimoved
Associate III

Hi.

It works fine , Many Thanks