mcu frequency problem

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
toxygen
Posts: 24
Joined: Tue Mar 13, 2012 9:54 pm

mcu frequency problem

Post by toxygen »

Hello,
I'm using my own board with STM32F103RET.

I've ran into weird problem - when I'm using slightly modified board config from Olimex STM32-P103, everything runs fine (led blinking correctly, uart2 communication).
The problem is, my board is using 24MHz crystal, not 8MHz like Olimex.

As I said, everything runs fine with "wrong" config:

Code: Select all

//board.h
#define STM32_HSECLK           8000000


Code: Select all

//mcuconf.h
#define STM32_NO_INIT                       FALSE
#define STM32_HSI_ENABLED                   FALSE
#define STM32_LSI_ENABLED                   FALSE
#define STM32_HSE_ENABLED                   TRUE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSE
#define STM32_PLLXTPRE                      STM32_PLLXTPRE_DIV1
#define STM32_PLLMUL_VALUE                  9
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE1                         STM32_PPRE1_DIV2
#define STM32_PPRE2                         STM32_PPRE2_DIV2
#define STM32_ADCPRE                        STM32_ADCPRE_DIV4
#define STM32_USB_CLOCK_REQUIRED            TRUE
#define STM32_USBPRE                        STM32_USBPRE_DIV1P5
#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK
#define STM32_RTCSEL                        STM32_RTCSEL_HSEDIV
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0


when I try to change the config to real values of the board

Code: Select all

//board.h
#define STM32_HSECLK           24000000

Code: Select all

//mcuconf.h
...
#define STM32_PLLMUL_VALUE                  3
...


the processor seems to run at 2/3rds of the previous speed. The led is blinking slower and uart2 stops working (just gibberish on the output).

Is there anything I'm missing?
How to determine the running frequency from runtime?
Why are wrong values in config working whilst real ones are not?
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: mcu frequency problem

Post by Tectu »

Are you 100% sure that you have a 24MHz crystal? Do you have a custom board or a well known like another Olimex board?


~ Tectu
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: mcu frequency problem

Post by Giovanni »

Hi,

At runtime the frequency is the macro STM32_HCLK, you may assign it to a variable and the inspect it. You could also activate the MCO pin and measure the actual frequency.

Giovanni
User avatar
toxygen
Posts: 24
Joined: Tue Mar 13, 2012 9:54 pm

Re: mcu frequency problem

Post by toxygen »

Tectu wrote:Are you 100% sure that you have a 24MHz crystal? Do you have a custom board or a well known like another Olimex board?


I have this custom board http://www.mlab.cz/Server/GenIndex/GenIndex.php?path=%2FModules%2FARM&lang=en (souhrn.pdf is schematic).
I'm attaching photo of the crystal.

Giovanni wrote:At runtime the frequency is the macro STM32_HCLK, you may assign it to a variable and the inspect it. You could also activate the MCO pin and measure the actual frequency.
Giovanni


Yes, that didn't cross my mind. The STM32_HCLK macro gets evaluated to 72000000 with the 8 MHz config. I cannot inspect it with the 24 MHz config through uart, nevertheless, when I compile with gcc -E flag, it's clear that the macro gets evaluated to 72 MHz also (((24000000 / 1) * 3) / 1).
Attachments
24mhz crystal
24mhz crystal
crystal.jpg (232 KiB) Viewed 7642 times
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: mcu frequency problem

Post by Giovanni »

The crystal looks far away from the MCU in that picture, also, I don't see the two capacitors. Could this be the problem?

BTW, it is on socket, try swapping it with a 8MHz one.

Giovanni
User avatar
toxygen
Posts: 24
Joined: Tue Mar 13, 2012 9:54 pm

Re: mcu frequency problem

Post by toxygen »

Giovanni wrote:The crystal looks far away from the MCU in that picture

in the schematics (black/white diagram) you can see it's almost next to the processor from the opposite side.

Giovanni wrote:also, I don't see the two capacitors. Could this be the problem?

they are in the schematics, 22pF ones.

Giovanni wrote:BTW, it is on socket, try swapping it with a 8MHz one.

I will. I don't have them handy right now, but I'll try it first thing tomorrow.
I also talked to the friend who also uses the board and he said he also experienced problems with high frequency crystal configuration. Maybe it's the bug in the board, I'll investigate and will post later.
User avatar
toxygen
Posts: 24
Joined: Tue Mar 13, 2012 9:54 pm

Re: mcu frequency problem

Post by toxygen »

I think I might have found the clue to the problem. There might be installed 10pF capacitors instead of 22pF.
lmamakos
Posts: 20
Joined: Sun May 13, 2012 3:59 pm

Re: mcu frequency problem

Post by lmamakos »

I wonder if that's a 24MHz 3rd-overtone crystal, oscillating at it's base frequency of 8 MHz? I think that the capacitance in the circuit is somewhat critical based on what I remembered reading some app notes about this sort of thing months ago. I think it's fairly unusual to have a socket in this application since the recommendation is to have the crystal usually as close as possible to the pins on the package. Perhaps the 10pf vs. 22pf change reflects the expected stray capacitance due to the socket?
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: mcu frequency problem

Post by Tectu »

In this applications, the value of the capacitors don't matter that much, from what I have learned. Important is - as said many times before - that everything is a close to the pins as possible. What's also more important at high frequencies is, that both traces do have the same length. This is something many people forget. There can be noticable issues when one trace is just 1/2 longer than the other, even at those low frequencies.


~ Tectu
User avatar
toxygen
Posts: 24
Joined: Tue Mar 13, 2012 9:54 pm

Re: mcu frequency problem

Post by toxygen »

lmamakos wrote:I wonder if that's a 24MHz 3rd-overtone crystal, oscillating at it's base frequency of 8 MHz?


Indeed, you were right. The crystal oscillate at 8 MHz, as I checked today with oscilloscope. So it's my fault and I'm sorry for the confusion.
Thank you for pointing this out.
Post Reply