cancel
Showing results for 
Search instead for 
Did you mean: 

stm32h755 Clock setup: HAL_RCC_ClockConfig returns error.

Mark12
Associate II

Hi all,

I am having issues with Clock setup for Stm32h755. Especially regarding the M4 core. Currently, I only run the M4 core. The M7 core has no valid firmware. Is that even a supported mode?

I try to setup a rather basic clock setup but the setup keeps failing at the call: HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4), which will return an not ok return value.

I also tried using HSI and other different setups. But it seems the keep failing in the same way. Interestingly... When I simply ignore the error. Then most stuff seems to work just fine. I got ADC, SPI, Timers working. However, I am not sure where the issue is with the clock configuration.

The entire clock setup: 

static void SystemClock_Config(void) {
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

    __HAL_RCC_SYSCFG_CLK_ENABLE();

    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE;
    RCC_OscInitStruct.HSEState       = RCC_HSE_ON;
    RCC_OscInitStruct.HSIState       = RCC_HSI_ON;
    RCC_OscInitStruct.PLL.PLLState   = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource  = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLM       = 5;
    RCC_OscInitStruct.PLL.PLLN       = 192;
    RCC_OscInitStruct.PLL.PLLP       = 2;
    RCC_OscInitStruct.PLL.PLLQ       = 2;
    RCC_OscInitStruct.PLL.PLLR       = 2;
    RCC_OscInitStruct.PLL.PLLRGE     = RCC_PLL1VCIRANGE_2;
    RCC_OscInitStruct.PLL.PLLVCOSEL  = RCC_PLL1VCOWIDE;
    RCC_OscInitStruct.PLL.PLLFRACN   = 0;
    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
        // print error
    }

    /** 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_DIV2;
    RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
    RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;

    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) {
        // print error
    }
}


Best regards

Mark


Edited to apply proper source code formatting - please see How to insert source code for future reference.

3 REPLIES 3
TDK
Super User

The clock failing to start can suggest the HSE design is not correct. Perhaps incorrect load caps.

Guidelines for oscillator design on STM8AF/AL/S and STM32 MCUs/MPUs - Application note

 

M4 having no firmware is fine. You can set option bytes such that the M4 core doesn't boot, but it's not an issue here.

If you feel a post has answered your question, please click "Accept as Solution".
Andrew Neil
Super User

@Mark12 wrote:

the call: HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_4 ), which will return an not ok return value..


Have you tried stepping into that function to see where & why, exactly, it is failing?

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

Hello,

Which board are you using? Nucleo board?

If it's the case, you need to set HSE in Bypass mode as the clock source is provided from the STLINK (STLINK_MCO) and there is no crystal on the board:

mALLEm_0-1762275019446.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.