cancel
Showing results for 
Search instead for 
Did you mean: 

Clock issues in STM32H753ZI100_24 - SystemClock_Config() hangs

santhosh16
Associate III

I have been using the STM32H753ZI100_24  for getting pressure data from the MS5611-01BA03 mems sensor. The debugger stops at SystemClock_Config() function in the code of reading prom registers from the MS5611-01BA03  sensor as per the datasheet Barometre datasheet 

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MPU Configuration--------------------------------------------------------*/
  MPU_Config();

  /* 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();
  MX_SPI1_Init();
  /* USER CODE BEGIN 2 */
  uint16_t prom[8] = {0};

  uint8_t rst_cmd = 0x1E; // Reset command
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
  HAL_SPI_Transmit(&hspi1, &rst_cmd, 1, HAL_MAX_DELAY);
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
  HAL_Delay(3);



//  if (MS5611_ReadPROM(prom) == HAL_OK) {
//  // Now prom[] contains all PROM coefficients including factory data and CRC
//  for (int i = 0; i < 8; i++) {
//	  printf("PROM[%d] = %u\n", i, prom[i]);
//  }
//   } else {
//      printf("Error reading PROM!\n");
//  }

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
	  MS5611_ReadPROM(prom);
	  HAL_Delay(1000);
  }
  /* USER CODE END 3 */
}

I will also attach the SystemClock_Config function.

 
void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};


/** Supply configuration update enable

 */

 HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);


/** Configure the main internal regulator output voltage

 */

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);


while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}


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

 * in the RCC_OscInitTypeDef structure.

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

 RCC_OscInitStruct.HSEState = RCC_HSE_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

 RCC_OscInitStruct.PLL.PLLM = 25;

 RCC_OscInitStruct.PLL.PLLN = 200;

 RCC_OscInitStruct.PLL.PLLP = 20;

 RCC_OscInitStruct.PLL.PLLQ = 20;

 RCC_OscInitStruct.PLL.PLLR = 2;

 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_0;

 RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;

 RCC_OscInitStruct.PLL.PLLFRACN = 0;

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_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;

 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;


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

 {

 Error_Handler();

 }

}

Here the debugger stops at the Error_Handler() function of the statement

 
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

 Error_Handler();

 }

So I step into HAL_RCC_OscConfig() function where it shows

_weak HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef  *RCC_OscInitStruct)
{
  uint32_t tickstart;
  uint32_t temp1_pllckcfg, temp2_pllckcfg;

  /* Check Null pointer */
  if (RCC_OscInitStruct == NULL)
  {
    return HAL_ERROR;
  }

  /* Check the parameters */
  assert_param(IS_RCC_OSCILLATORTYPE(RCC_OscInitStruct->OscillatorType));
  /*------------------------------- HSE Configuration ------------------------*/
  if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE)
  {
    /* Check the parameters */
    assert_param(IS_RCC_HSE(RCC_OscInitStruct->HSEState));

    const uint32_t temp_sysclksrc=__HAL_RCC_GET_SYSCLK_SOURCE();
    const uint32_t temp_pllckselr = RCC->PLLCKSELR;
    /* When the HSE is used as system clock or clock source for PLL in these cases HSE will not disabled */
    if ((temp_sysclksrc== RCC_CFGR_SWS_HSE) || ((temp_sysclksrc== RCC_CFGR_SWS_PLL1) && ((temp_pllckselr & RCC_PLLCKSELR_PLLSRC) == RCC_PLLCKSELR_PLLSRC_HSE)))
    {
      if ((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != 0U) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF))
      {
        return HAL_ERROR;
      }
    }
    else
    {
      /* Set the new HSE configuration ---------------------------------------*/
      __HAL_RCC_HSE_CONFIG(RCC_OscInitStruct->HSEState);

      /* Check the HSE State */
      if (RCC_OscInitStruct->HSEState != RCC_HSE_OFF)
      {
        /* Get Start Tick*/
        tickstart = HAL_GetTick();

        /* Wait till HSE is ready */
        while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == 0U)
        {
          if ((uint32_t)(HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
          {
            return HAL_TIMEOUT;
          }
        }
      }
      else
      {
        /* Get Start Tick*/
        tickstart = HAL_GetTick();

        /* Wait till HSE is disabled */
        while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != 0U)
        {
          if ((uint32_t)(HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
          {
            return HAL_TIMEOUT;
          }
        }
      }
    }
  }

In this function since i have only enable HSE clock but our custom board have both HSE and LSE in it.

Coming back to code in this HAL_RCC_OscConfig() function the debugger stops at the below while loop

while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == 0U)
        {
          if ((uint32_t)(HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
          {
            return HAL_TIMEOUT;
          }
        }

it toggles between while() statement and if() statement. is it normal for the oscillator to start after toggling it so many times or is the there any problem in enabling clock from my side
the clock for spi is connected to APB2 which is 25 MHz. I have attach the photo of the clock configuration of the above project.
Screenshot from 2025-06-02 18-09-03.png

 

and the stm32 datasheet stm32 datasheet which we are using.

23 REPLIES 23

@santhosh16 wrote:

hey andrew, thanks for the reply i check with the team yes its the problem with the oscillator. 


OK - I'll edit the title to clarify.

 


@santhosh16 wrote:

 now, if i get data from the prom register how can i ...


That's an entirely different question!

You won't be able to do anything at all until you have fixed the clock problem.

 

For how to communicate with the MS5611-01BA03 mems sensor, and interpret the data from it, you will have to study the manufacturer's datasheet & any other supporting information.

The MS5611-01BA03 is a TE product - nothing to do with ST - so you will need to contact TE for support with it.

 

The recommended approach would be to get a development/evaluation kit from TE, and use an ST board (eg, Nucleo) to get you started with known-good hardware.

 

It seems that 3rd-party breakout boards are also available; eg,

https://www.amazon.co.uk/MS5611-01BA03-Atmospheric-Pressure-Altimeter-Electronic/dp/B07Y1QZKF4

AndrewNeil_1-1748873892831.png

 

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@santhosh16 wrote:

 the problem with the oscillator. now


Are you, perhaps, getting confused with which oscillator we're talking about here?

 

The one which causes the SystemClock_Config() to fail is the one within your STM32.

 

The MS5611-01BA03 mems sensor does also have its own internal oscillator - but that has nothing to do with this problem.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
mƎALLEm
ST Employee

@santhosh16 

Please state on this post. Did you solve the issue?

If one of the comments answered your question or at least guided you to the solution, please accept it as solution by clicking the button:

mALLEm_0-1749473450862.png

Thank you for your understanding.

 

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.

but before i try one of these solutions, i got the error stlink is not initialized  which i queried before in this community. so once after clear that issue i can come into solving this.

Hey friends@mƎALLEm and @TDK ,

as a recent update my board got connected to the cubeprogrammer as said in this stackoverflow forum in 2nd point of just reducing the swd frequency to lesser than 4000 khz i.e. 480 khz. Now after connected, it is even got connected in 4000 khz also. now i will share my code to you to read the barometer sensor i have coded the below one. is this anything affects my  hardware which goes to chip id as 0x0000
This is the main code

 

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MPU Configuration--------------------------------------------------------*/
  MPU_Config();

  /* 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();
  MX_SPI1_Init();
  /* USER CODE BEGIN 2 */
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);

  uint16_t prom[8] = {0};
  uint8_t rst_cmd = 0x1E; // Reset command
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET);
  HAL_SPI_Transmit(&hspi1, &rst_cmd, 1, HAL_MAX_DELAY);
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);
  HAL_Delay(30000);

//  if (MS5611_ReadPROM(prom) == HAL_OK) {
//  // Now prom[] contains all PROM coefficients including factory data and CRC
//  for (int i = 0; i < 8; i++) {
//	  printf("PROM[%d] = %u\n", i, prom[i]);
//  }
//   } else {
//      printf("Error reading PROM!\n");
//  }

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
	  MS5611_ReadPROM(prom);
	  HAL_Delay(1000);
  }
  /* USER CODE END 3 */
}

 

and this is the MS5611_ReadPROM() function

 

HAL_StatusTypeDef MS5611_ReadPROM(uint16_t *promData) {
    HAL_StatusTypeDef status;
    uint8_t prom_cmd;
    uint8_t rx_buf[2]={0,0};

    for (uint8_t ptr = 0; ptr < 8; ptr++) {
        prom_cmd = 0xA0 + (ptr * 2);  // PROM read commands: 0xA0, 0xA2, ..., 0xAE

        HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET);

        // Send PROM read command
        status = HAL_SPI_Transmit(&hspi1, &prom_cmd, 1, HAL_MAX_DELAY);
        if (status != HAL_OK) {
        	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);
            return status;
        }

        // Receive 2 bytes PROM data (MSB, LSB)
        for (uint8_t ctr = 0; ctr < 2; ctr++){
        status = HAL_SPI_Receive(&hspi1, rx_buf, 2, HAL_MAX_DELAY);
        }
    	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);

        if (status != HAL_OK) {
            return status;
        }

        // Combine MSB and LSB
        promData[ptr] = (rx_buf[0] << 8) | rx_buf[1];
    }
    return HAL_OK;
}

 


 is there any errors in this code which affects hardware

You still haven't shown the schematic of your custom board.

Have you done basic checks - with oscilloscope and/or logic analyser - to see what's actually happening on the lines between your STM32 and the sensor?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@santhosh16 wrote:

as a recent update my board got connected to the cubeprogrammer as said in this stackoverflow forum


Please update your other thread with that information, and mark that as the solution in that thread.

See: https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

I'm not sure I understood you replies.

Your initial issue was the fact you can't pass SystemClock_Config()!

Did you solve that issue or not?

If not remove all the code after SystemClock_Config() and test again.

If yes you need to close that thread by marking the reply as Accepted solution and open a newer thread specific for your sensor issue.

Thank you for your cooperation.

 

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.

yeah for this thread external oscillator is the problem, so i marked it as the solution.

yeah sure i will open a new thread i marked the solution for this one too.