STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

Post by enrico.dallavia »

Hi,
with the new version of ChibiOS (4.0.4) I found a difference about clock configuration.
In particular I'm thinking about the macro STM32_HSE_BYPASS and the behavior of crystal oscillator and cpu clock speed.
Because in the past, I've usually changed the settings in mcuconf.h, like

Code: Select all

#define STM32_NO_INIT                       FALSE
#define STM32_HSI_ENABLED                   TRUE
#define STM32_LSI_ENABLED                   TRUE
#define STM32_HSE_ENABLED                   TRUE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_CLOCK48_REQUIRED              TRUE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSE
#define STM32_PLLM_VALUE                    12
#define STM32_PLLN_VALUE                    168
#define STM32_PLLP_VALUE                    2 //168Mhz
#define STM32_PLLQ_VALUE                    7
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE1                         STM32_PPRE1_DIV4
#define STM32_PPRE2                         STM32_PPRE2_DIV2
#define STM32_RTCSEL                        STM32_RTCSEL_LSI
#define STM32_RTCPRE_VALUE                  8
#define STM32_MCO1SEL                       STM32_MCO1SEL_HSI
#define STM32_MCO1PRE                       STM32_MCO1PRE_DIV1
#define STM32_MCO2SEL                       STM32_MCO2SEL_SYSCLK
#define STM32_MCO2PRE                       STM32_MCO2PRE_DIV5
#define STM32_I2SSRC                        STM32_I2SSRC_CKIN // disable I2S PLL
#define STM32_SAISRC                        STM32_SAISRC_PLL  // enable SAI PLL
#define STM32_PLLSAIN_VALUE                 126 // x 2MHz = 252MHz
#define STM32_PLLSAIQ_VALUE                 8 // PLLSAICLK, not used
#define STM32_PLLSAIR_VALUE                 5 // PLLLCDCLK = fVCO/5 = 50.4MHz
#define STM32_PLLSAIR_POST                  STM32_SAIR_DIV2 // hw minimum = 25.2MHz
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0
#define STM32_BKPRAM_ENABLE                 FALSE

and board.h

Code: Select all

#if !defined(STM32_HSECLK)
#define STM32_HSECLK                24000000U
#endif

/*
 * Board voltages.
 * Required for performance limits calculation.
 */
#define STM32_VDD                   300U


but now from the default configuration of STM32F072-DISCOVERY I've got

Code: Select all

#define STM32_NO_INIT                       FALSE
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0
#define STM32_HSI_ENABLED                   TRUE
#define STM32_HSI14_ENABLED                 TRUE
#define STM32_HSI48_ENABLED                 FALSE
#define STM32_LSI_ENABLED                   TRUE
#define STM32_HSE_ENABLED                   FALSE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSI_DIV2
#define STM32_PREDIV_VALUE                  1
#define STM32_PLLMUL_VALUE                  12
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE                          STM32_PPRE_DIV1
#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK
#define STM32_MCOPRE                        STM32_MCOPRE_DIV1
#define STM32_PLLNODIV                      STM32_PLLNODIV_DIV2
#define STM32_USBSW                         STM32_USBSW_HSI48
#define STM32_CECSW                         STM32_CECSW_HSI
#define STM32_I2C1SW                        STM32_I2C1SW_HSI
#define STM32_USART1SW                      STM32_USART1SW_PCLK
#define STM32_RTCSEL                        STM32_RTCSEL_LSI

and in board.h

Code: Select all

#if !defined(STM32_LSECLK)
#define STM32_LSECLK                0U
#endif

#define STM32_LSEDRV                (3U << 3U)

#if !defined(STM32_HSECLK)
#define STM32_HSECLK                0U
#endif

#define STM32_HSE_BYPASS


Can I still use the old way to change the settings?
In particular I have a custom board based on STM32F072RB which I want to use with 12Mhz external oscillator and CPU speed of 48MHz, with ST's excel I've got the values in the image below.

Thanks
Attachments
clock_config_stm32F0.png
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

Post by Giovanni »

Settings are different but I don't understand what you mean with "Can I still use the old way to change the settings?".

The settings in mcuconf.h is what you can change.

Giovanni
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

Post by enrico.dallavia »

Thanks for the reply.
What I meant is, since I'm used to see the system working by external oscillator, and with the discovery board I did not see this settings (but the board is working, I have it now on my desk) I would like to know how to setup the oscillator and frequency of the processor with ChibiOS 4.0.4. Is it the same as 3.x branch?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

Post by Giovanni »

Yes.
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

Post by enrico.dallavia »

I have a problem,
I've tried to setup external oscillator,8MHz, on the discovery board with the following settings:

Code: Select all

#define STM32_NO_INIT                       FALSE
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0
#define STM32_HSI_ENABLED                   TRUE
#define STM32_HSI14_ENABLED                 TRUE
#define STM32_HSI48_ENABLED                 FALSE
#define STM32_LSI_ENABLED                    TRUE
#define STM32_HSE_ENABLED                   TRUE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSE //STM32_PLLSRC_HSI_DIV2
#define STM32_PREDIV_VALUE                  1
#define STM32_PLLMUL_VALUE                  6 //12
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE                          STM32_PPRE_DIV1
#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK
#define STM32_MCOPRE                        STM32_MCOPRE_DIV1
#define STM32_PLLNODIV                      STM32_PLLNODIV_DIV2
#define STM32_USBSW                         STM32_USBSW_HSI48
#define STM32_CECSW                         STM32_CECSW_HSI
#define STM32_I2C1SW                        STM32_I2C1SW_HSI
#define STM32_USART1SW                      STM32_USART1SW_PCLK
#define STM32_RTCSEL                        STM32_RTCSEL_LSI


and inside board.h I modified the original example with those lines:

Code: Select all

#if !defined(STM32_HSECLK)
#define STM32_HSECLK                8000000U
#endif

//#define STM32_HSE_BYPASS


but after flashing the new firmware the board did not starts
no blinking led, no output from serial

What could be the problem? The values I've changed were according to the ST's excel clock configuration for F0xx device

Thanks!
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

Post by Giovanni »

If you have an oscillator then you need the bypass.

Giovanni
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

Post by enrico.dallavia »

Thanks,
I've just tried with that, but nothing changed

Code: Select all

#if !defined(STM32_HSECLK)
#define STM32_HSECLK                8000000U
#endif

#define STM32_HSE_BYPASS
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

Post by enrico.dallavia »

No matter what I'm doing I can't made the discovery board work. It works only with HSI and the macro STM32_HSE_BYPASS is indifferent (with or without the board starts)
If I try to use external oscillator, the system did not start at all :(
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

Post by Giovanni »

Make sure you are injecting the clock on the right pin and that it is correctly configured.
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: STM32_HSE_BYPASS vs STM32_HSE_ENABLED and STM32_HSECLK

Post by enrico.dallavia »

from the datasheet of the discovery:
By default, the STM32F072RBT6 clock source is the High-speed internal (HSI) RC
oscillator


So I'm wondering if other clock source can me used without hardware modification on the board.

Thanks Giovanni for the suggestion I did not think about the pin configuration at all!
Post Reply