Skip to content

Timer driver

OwnTech Timer driver Zephyr Module is in charge of STM32 G4 Timers.


Driver capabilities

The Timer driver module allows you to control a timer on the STM32 G4 board. Currently, only Timer 6 and 7 are supported.

The following functions are provided by the Timer driver module:

  • void timer_config(const struct device* dev, const struct timer_config_t* config)
  • void timer_start(const struct device* dev, uint32_t t_usec)
  • uint32_t timer_get_count(const struct device* dev)

How to use

Getting access to the driver

To use the Timer driver module, you have to include "timer.h" in your source file:

Zephyr uses device-tree macros to interact with drivers. The correct macro must be declared and used to obtain a pointer to the driver structure from Zephyr:

Using this pointer, the user is able to interact with the driver functions. The pointer must be provided as first argument of all driver-related functions.


The timer_config() function takes a parameter which is a configuration structure, defined as follows:

This structure is used to configure the callback function called when the timer times out.


The timer_start() function is used to start the timer. It takes as a parameter the duration of the timer, in µs. The allowed values for duration is an integer within range [ 1 : 6553 ].


Finally, the timer_get_count() function can be called to read the current value of the timer counter.


Technical information

This driver has a Zephyr-style implementation. It does use the standard DEVICE_DT_DEFINE() macro that allows it to be loaded automatically if the module is enabled and the device is activated in the device tree. It also provides a board-agnostic layer that would allow, if wanted, to write Timer drivers for other boards.

The only difference with a Zephyr driver would be that it explicitly and individually checks for the presence and status of timers6 and timers7 nodes in the device tree instead of being fully generic and run as many drivers as there are compatible nodes.

Enabling or disabling the module

The module is loaded by default. The user explicitly has to set CONFIG_OWNTECH_TIMER_DRIVER=n in prj.conf to prevent the driver from loading.

Do not disable the module if you're using the Quick Start library as it makes use to Timer 6.