STM32F103VET6 Timestamps and time measurement

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

Moderator: RoccoMarco

Post Reply
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

STM32F103VET6 Timestamps and time measurement

Post by franek.bmw »

Hello,
I need in my program based on ChibiOS time measurement with microsecond accuracy. It will be used as the system clock for event timestamps and for time synchronization of some tasks. Also I need to be able to set the system time. What is the best way to do this on ChibiOS? I looked throuhgt the docs but i have not found tools to do this. Please advice how to do this.

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

Re: STM32F103VET6 Timestamps and time measurement

Post by Giovanni »

In 2.6 there is a "Time Measurement" driver in the HAL. In 3.0 it is part of the RT kernel. See the time measurement section in the documentation.

http://chibios.sourceforge.net/docs3/rt ... ement.html

Giovanni
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

Re: STM32F103VET6 Timestamps and time measurement

Post by franek.bmw »

I think this is not exactly what I mean. I need something like RTC with us accuracy with some function like gettime and settime. Any ideas?
Second question is how to read the current value of the timer using GPT?

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

Re: STM32F103VET6 Timestamps and time measurement

Post by Giovanni »

You can use the system time, in 3.0 it is possible to set it to 1MHz (or even higher) on F4 devices when the tickless mode is activated.

Giovanni
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

Re: STM32F103VET6 Timestamps and time measurement

Post by franek.bmw »

But what if I use chibios 2.6 and stm32f103?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F103VET6 Timestamps and time measurement

Post by Giovanni »

In that case:

Code: Select all

/**
 * @name    Macro Functions
 * @{
 */
/**
 * @brief   Returns the current value of the system free running counter.
 * @note    This is an optional service that could not be implemented in
 *          all HAL implementations.
 * @note    This function can be called from any context.
 *
 * @return              The value of the system free running counter of
 *                      type halrtcnt_t.
 *
 * @special
 */
#define halGetCounterValue() hal_lld_get_counter_value()

/**
 * @brief   Realtime counter frequency.
 * @note    This is an optional service that could not be implemented in
 *          all HAL implementations.
 * @note    This function can be called from any context.
 *
 * @return              The realtime counter frequency of type halclock_t.
 *
 * @special
 */
#define halGetCounterFrequency() hal_lld_get_counter_frequency()
/** @} */


However this only works on M3 and M4 targets, not M0. This API is no more present in 3.0, replaced by the mechanism I mentioned before.

Giovanni
Post Reply