[H743VIT] Custom variant attempt clock speed issue

Post here first, or if you can't find a relevant section!
Post Reply
Senna-chan
Posts: 5
Joined: Thu Sep 17, 2020 1:49 pm
Answers: 1

[H743VIT] Custom variant attempt clock speed issue

Post by Senna-chan »

Hello,

I am trying to create the variant STM32H743VITx but I am stumbling on a really weird issue.
The clock is setup to be 480 Mhz and when I toggle a LED with a delay of 10ms in STM32CubeIDE it really shows 10 ms.
When I try the same in Arduino it is 3.2 ms.
I copied the SystemClock_Config from the CubeIDE project.

What could be the issue here?
by Senna-chan » Sun Sep 20, 2020 2:11 pm
That was not the problem but it was in the right way
This piece of code was the culprit

Code: Select all

// HSE default value is 25MHz in HAL
// HSE_BYPASS is 8MHz
#ifndef HSE_BYPASS_NOT_USED
#define HSE_VALUE 8000000
#endif
HSE_BYPASS_NOT_USED is not defined and HSE_VALUE must be 25000000 since the crystal on this board is 25 Mhz
After changing that the clock issue is solved. 115200 baudrate is really 115200 and F_CPU is 480000000

I still need to check the other peripherals but I think that this issue is solved
Go to full post
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: [H743VIT] Custom variant attempt clock speed issue

Post by fpiSTM »

The main difference in your test is the CUBE IDE has probably the latest Cube Fw version for H7 ( HAL/LL and CMSIS device).
The updated one will be in the next release of the core (2.0.0). It is already available in the GitHub repo.
Senna-chan
Posts: 5
Joined: Thu Sep 17, 2020 1:49 pm
Answers: 1

Re: [H743VIT] Custom variant attempt clock speed issue

Post by Senna-chan »

After updating to the latest git version I still got the issue.
The board that I use is a MCUDev DevEBox STM32H7XX_M board with the H743
This is the SystemClock_Config code that I use.

Code: Select all

 void SystemClock_Config(void)
{
    RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
    RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
    RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 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_SCALE0);

    while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
    /** Macro to configure the PLL clock source
    */
    __HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_PLLSOURCE_HSE);
    /** Initializes the RCC Oscillators according to the specified parameters
    * in the RCC_OscInitTypeDef structure.
    */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSI
        | RCC_OSCILLATORTYPE_HSE;
    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
    RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
    RCC_OscInitStruct.HSI48State = RCC_HSI48_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)
    {
        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_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)
    {
        Error_Handler();
    }
    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_FDCAN
        | RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_SPI4
        | RCC_PERIPHCLK_SPI1 | RCC_PERIPHCLK_SPI2
        | RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_ADC
        | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_USB
        | RCC_PERIPHCLK_QSPI;
    PeriphClkInitStruct.PLL2.PLL2M = 5;
    PeriphClkInitStruct.PLL2.PLL2N = 96;
    PeriphClkInitStruct.PLL2.PLL2P = 2;
    PeriphClkInitStruct.PLL2.PLL2Q = 2;
    PeriphClkInitStruct.PLL2.PLL2R = 2;
    PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_2;
    PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;
    PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
    PeriphClkInitStruct.QspiClockSelection = RCC_QSPICLKSOURCE_D1HCLK;
    PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL;
    PeriphClkInitStruct.Spi45ClockSelection = RCC_SPI45CLKSOURCE_D2PCLK1;
    PeriphClkInitStruct.FdcanClockSelection = RCC_FDCANCLKSOURCE_HSE;
    PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1;
    PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_HSI;
    PeriphClkInitStruct.I2c123ClockSelection = RCC_I2C123CLKSOURCE_D2PCLK1;
    PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
    PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
    {
        Error_Handler();
    }
    /** Enable USB Voltage detector
    */
    HAL_PWREx_EnableUSBVoltageDetector();
}

I will admit that configuring the clock is a bit new for me and that this MCU clock config is pretty complicated but I hope that this is good enough
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: [H743VIT] Custom variant attempt clock speed issue

Post by fpiSTM »

Maybe you can try to disable the D/I cache

Add a file named "build_opt.h" with:

Code: Select all

-DI_CACHE_DISABLED -DD_CACHE_DISABLED
Senna-chan
Posts: 5
Joined: Thu Sep 17, 2020 1:49 pm
Answers: 1

Re: [H743VIT] Custom variant attempt clock speed issue

Post by Senna-chan »

It didn't work. Still a 3.2 ms pulse. Serial is also to fast. I use it at 115200 baud but the monitor needs to be at 368640. F_CPU also raports a wrong value of 153600000
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: [H743VIT] Custom variant attempt clock speed issue

Post by fpiSTM »

OK I think I've found your issue.

I think your board has an HSE of 8MHz while by default in the HAL conf this is a 25 MHz.
So you have to define in your variant:

Code: Select all

#define HSE_VALUE    (8000000UL) /*!< Value of the External oscillator in Hz */
Senna-chan
Posts: 5
Joined: Thu Sep 17, 2020 1:49 pm
Answers: 1

Re: [H743VIT] Custom variant attempt clock speed issue

Post by Senna-chan »

That was not the problem but it was in the right way
This piece of code was the culprit

Code: Select all

// HSE default value is 25MHz in HAL
// HSE_BYPASS is 8MHz
#ifndef HSE_BYPASS_NOT_USED
#define HSE_VALUE 8000000
#endif
HSE_BYPASS_NOT_USED is not defined and HSE_VALUE must be 25000000 since the crystal on this board is 25 Mhz
After changing that the clock issue is solved. 115200 baudrate is really 115200 and F_CPU is 480000000

I still need to check the other peripherals but I think that this issue is solved
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: [H743VIT] Custom variant attempt clock speed issue

Post by fpiSTM »

Right. By default the Nucleo H743 used the HSE bypass.
I though you used a custom variant too.
Senna-chan
Posts: 5
Joined: Thu Sep 17, 2020 1:49 pm
Answers: 1

Re: [H743VIT] Custom variant attempt clock speed issue

Post by Senna-chan »

Yes I do use a custom variant but it was not a supported board so I used the Nucleo H743 as base for the variant since it was the same chip.

I still have some clock issues but the main one is fixed. The peripheral clocks are still wrong like for canbus but I think I can solve them.
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: [H743VIT] Custom variant attempt clock speed issue

Post by fpiSTM »

For other clock issue. Use CubeMX and enable the desired peripherals like CAN then you will be able to properly configure the clock.
Post Reply

Return to “General discussion”