I would like to use two timers on my custom carrier board for the
Colibri IMX7D 1GB and I therefore have to modify the device tree. This is what I plan to configure:
Timer GPT1 (mainly to divide an input frequency and put it on an output):
SODIMM pin 93 as GPT1.COMPARE1
SODIMM pin 60 as GPT1.CLK
Timer GPT4 (used to get a precise time pulse from a GPS module)
SODIMM 23 as GPT4.CAPTURE_2
Modifying the device tree and creating a new image (based on
torizon-core-docker-colibri-imx7-emmc-Tezi_5.6.0+build.13) is not a problem, I already successfully made a number of changes for my board.
But I don’t have any clue on how to define the timers in the device tree or how to use them from C/C++.
=> Could you give me any hints on how to declare them in the device tree?
=> Are there any examples on how to use them from C/C+?
Any help is welcome !
The GPT sub-system isn’t something we have a whole lot of experience with ourselves, but I did some research on this and here’s what I was able to find.
In the Linux kernel source itself we have the following:
As for user-space examples of using GPT, information was more scarce. Nevertheless here’s what I was able to find:
- NXP forum post with attached code and firmware guide regarding GPT. However this was for the i.MX6 not the i.MX7. While similar there’s for sure some differences here and there. Strangely enough I could not find a public firmware guide for the i.MX7. Perhaps this is something that can be asked/requested from NXP: Solved: iMX6 General Purpose Timer - NXP Community
- Other than this there’s also the i.MX7 reference manual and the i.MX Linux Reference manual. Both these documents can be downloaded from NXP and contain some information on GPT. Though the information is a bit higher level and doesn’t include many actual code examples.
This is the information I was able to find publicly. Perhaps inquiring NXP about i.MX7 GPT on their forums may yield more information. They may have code samples and such lying around as they did for the i.MX6 as seen in the other forum post.
I’ll have a look at the proposed links and will do some research et NXP.
At least there is a base definition for the GPTs in Toradex’s device trees so with a bit of luck, there is no need to fiddle them.
If you do happen to find or get any additional information on this topic from NXP please do share. It would be appreciated since information on this topic isn’t very well documented publicly.
I promise I’ll share my experience when I get the timer running!
As promised, here’s how I got timer do what I wanted.
I got GPT1 running but only via the M4 processor.
After having disabled it in the device tree, I configured the IO-Mux for the GPT_CLK1 and GPT1_COMPARE1 signals to be present on the associated pads of the i.MX7D.
Using the ‘driver’ code in gpt.c under
FreeRTOS/platform/drivers/src I managed to output a signal with the required frequency based on the external 4MHz input in GPT_CLK1.
As mentioned in imx7-m4-timers-in-freertos, GPT1 is NOT used by the Linux kernel and can be used in your application.
Useful documentation for those who want to play around with peripherals in FreeRTOS:
- i.MX 7Dual Applications Processor Reference Manual
This document describes all drivers that are provided with the FreeRTOS distribution for the i.MX7D.
It is part of the FreeRTOS repository and can be found under the
Hopefully, this may be useful to some people.