Lib to switch the clock speed of the ST Nucleo to 84MHz. The internal RC oscillator is multiplied with the PLL.

Dependents:   Nucleo_spi_master_20MHz Nucleo_vs_Arduino_Speed_Test DMA_I2S_Test MPU9150AHRS ... more

Issue: Nucleo at 84MHz: Serial.printf() prints gibberish

Hi Peter,

I followed your instructions to speed up my Nucleo F4 board. I use an external 20MHz crystal and calculated the settings with ST's CubeMX tool: PPLM = 18, PLLN = 302, PLLP = PLLQ = 4. I get a clock of 83.89MHz (verified with frequency counter). My issue is that I can't get 'Serial.printf()' working with this setup. The text is only gibberish so I expect the baud settings to be off. From your information I understood that I have to patch the variable SystemCoreClock to 83890000 but I am not clear where I should do this. I tried to put it before and after the call to 'SystemCoreClockUpdate();' but both didn't work.

Any ideas?

Cheers, Uwe.

My code:

#include "stm32f4xx_hal.h"
#include "mbed.h"

void setup(void)
{
    RCC_ClkInitTypeDef RCC_ClkInitStruct;
    RCC_OscInitTypeDef RCC_OscInitStruct;

    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
    RCC_OscInitStruct.LSIState = RCC_LSI_ON;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLM = 18;
    RCC_OscInitStruct.PLL.PLLN = 302;
    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
    RCC_OscInitStruct.PLL.PLLQ = 4;
    HAL_RCC_OscConfig(&RCC_OscInitStruct);

    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
    
    SystemCoreClockUpdate();
    SystemCoreClock = 83890000;
    
    //HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1);        // output SYSCLOCK to pin PC9 to monitor frequency
};

void loop() {
    Serial pc(SERIAL_TX,SERIAL_RX);

    while(1) {
        pc.printf("huhu\n");
    }
}

int main()
{
    setup();
    loop(); 
}

1 comment:

28 Mar 2014

With help from Peter I've got it working. In my project I had to import the mbed-src library and remove the mbed library. Then I had to modify mbed-src/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_conf.h

Not far from the top I modified the HSE_VALUE from 8,000,000 to 20,000,000:

#if !defined  (HSE_VALUE) 
  #define HSE_VALUE    ((uint32_t)20000000) /*!< Value of the External crystal in Hz */
#endif /* HSE_VALUE */

and that was it.

Cheers, Uwe.