STM32F072 on exernal clock.

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

Moderators: RoccoMarco, barthess

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

STM32F072 on exernal clock.

Postby rew » Sat Apr 29, 2017 6:06 pm

I have built a clock, and it seems to run significantly fast. Of course it is still running on HSI with an allowed tolerance of 1%. I measured that it was 0.05% fast.... Still two seconds every hour is something that catches my eye within the hour....

I changed the clock section I copied from an example to:

Code: Select all

#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
#undef STM32_HSECLK
#undef STM32_HSE_BYPASS
#define STM32_HSECLK                        8000000U
#if STM32_HSE_ENABLED == TRUE
#define STM32_PLLSRC                        STM32_PLLSRC_HSE
#else
#define STM32_PLLSRC                        STM32_PLLSRC_HSI_DIV2
#endif
#define STM32_PREDIV_VALUE                  1
#define STM32_PLLMUL_VALUE                  6

The #if HSE_ENABLED allows me to switch between HSE and non-HSE by only changing just the HSE-enabled define.

I just realized that I changed the multiplier from 12 to 6, so I should be running at 24MHz, now, instead of originally at 48. Still everything seems to work just fine. Not 2 seconds (real time)/second (on the clock).

Anyway, when I use HSE, the CPU goes "unhandled exception" after a few hundred miliseconds (but before the first second-rollover).

Code: Select all

(gdb) where
#0  _unhandled_exception ()
    at chibios/os/common/startup/ARMCMx/compilers/GCC/vectors.c:46
#1  <signal handler called>
#2  0x55555554 in ?? ()


Any suggestions as to what I might be doing wrong?

[edit/update:] The milisecond timer is at 901 miliseconds when the crash happens. 5 times in a row.

User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Re: STM32F072 on exernal clock.

Postby RoccoMarco » Sat Apr 29, 2017 6:43 pm

Hi,
I got lost at certain point. BTW, in chconf.h enable the debug options and see what happens.
Ciao,
RM

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: STM32F072 on exernal clock.

Postby rew » Sat Apr 29, 2017 6:58 pm

only the statistics and the profiling deubg options are not enabled. those cannot be enabled without changing other things IIRC.

User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Re: STM32F072 on exernal clock.

Postby RoccoMarco » Sat Apr 29, 2017 7:02 pm

Take a look to datasheet. Are all the absolute maximum rating respected?
Ciao,
RM

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: STM32F072 on exernal clock.

Postby rew » Sat Apr 29, 2017 7:23 pm

It runs 0.05% faster than nominal on the internal clock. I don't see why anything would become more critical when running 0.05% slower. ....

On a whim I canged the delay from 1000 to 1500 in:

Code: Select all

  usbDisconnectBus(serusbcfg.usbp);
  chThdSleepMilliseconds(1500);
  usbStart(serusbcfg.usbp, &usbcfg);
  usbConnectBus(serusbcfg.usbp);

and now the crash happens 0.5 seconds later, milisecond timer at 401 and the display 1 second advanced from inital value.... It has something to do with USB....

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: STM32F072 on exernal clock.

Postby rew » Sat Apr 29, 2017 7:59 pm

With the clock source set to "HSE", the clock runs too fast. Chibios' concept of time is warped. As if I mounted a 16MHz crystal instead of the 8MHz that I wanted. checking.... OK. Some dufus mounted a 16Mhz crystal... :-) ...
The schematic clearly says 8MHz, but we were populating similar boards when this one was populated and those do need a 16Mhz crystal.

Edit: OK. Running simply on HSE and setting the clock frequency to 16MHz then the clock seems to be running just 126ppm too fast.
Still odd that I can't get the PLL to do "times 3".
Ok. It seems that setting the PLL to 8 MHz * 3 does not work when the crystal is in reality 16MHz. Oh, wait! Does Chibios calculate that the clock frequency is 24MHz or below, and then configures flash as zero waitstates, instead of the 1 waitstate required for 48?

Confirmed: waitstates = 0 when I configure 8MHZ *3, Basically you'd expect chibios's impression of time to be off, but it's the flash waitstates that mess things up. Interesting to see that with the bad settings I could get it to run just fine until USB started.... It might be possible to overclock the '072 to close to 96MHz, if we could insert more flash waitstates. Probably the logic for more than one waitstate is not implemented, even though the datasheet documents the LATENCY[2:1] bits as existing.


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 22 guests