Page 1 of 1
How do I get system clock frequency?
Posted: Mon Feb 03, 2014 1:56 am
by dhruvin91
Hi,
I am looking to add 10 ms delay in the code. I am not sure if there is any delay function in chibios. But I can add a delay function if I knew the clock frequency. I tried to find out what clock frequency my code has but didn't get anywhere.
Does anyone know how to find clock frequency in mycode or add delay?
Thank you.
Re: How do I get system clock frequency?
Posted: Mon Feb 03, 2014 9:27 am
by Giovanni
It is in any demo...
chThdSleepMilliseconds()
...or in the documentation...
http://chibios.sourceforge.net/html/gro ... e4cad9f56f...or you may also look at this article...
http://www.chibios.org/dokuwiki/doku.ph ... :kb:timingGiovanni
Re: How do I get system clock frequency?
Posted: Fri Feb 07, 2014 2:21 am
by dhruvin91
does this work when I am not using threads?
Thank you.
Re: How do I get system clock frequency?
Posted: Fri Mar 07, 2014 8:39 pm
by Faisal Mehmood
I guess you would have figured it out already. In case you didn't:
When the kernel has been initialized, the main() function becomes a thread as well. It is documented in the demo:
Code: Select all
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
(remaining demo follows...)
ChThdSleepMilliseconds() will 'sleep' the main 'thread' for the specified milliseconds.
Re: How do I get system clock frequency?
Posted: Thu Sep 06, 2018 9:40 pm
by Guillaume227
Going back to the title question (the op was actually interested in adding delay to his code so the discussion stopped there) :
I do not see anywhere in the API a method that returns the clock frequency which the MCU is set to.
What's the recommended way to access that value?
Re: How do I get system clock frequency?
Posted: Thu Sep 06, 2018 10:23 pm
by Giovanni
Hi,
For STM32 it is STM32_HCLK, it is HAL exporting it.
Giovanni
Re: How do I get system clock frequency?
Posted: Sun Sep 09, 2018 8:00 pm
by electronic_eel
Wouldn't it make sense to provide the frequency in a hardware-independent way?
Or is there some limitation that makes it hardware dependant?