cancel
Showing results for 
Search instead for 
Did you mean: 

How can I generate a periodic signal on a GPIO using timer interrupt in Linux kernel (STM32MP153a)?

vl4ever
Associate

Hi,

I am using STM32MP153a SOC.Linux kernel version is 5.4.56 (openstlinux-5.4-dunfell-mp1-20-11-12).

I would like to generate square signal of 50-200 uS on a certain GPIO every 40 ms using Linux kernel.Also ,at this point I need to read certain registers.

What are my options? If there is already an example/application note on the subject,please let me know.

I was looking into these options:

1)I have already a working timer on my system,which is arm arch timer.It's already generating interrupts ( I can see that number of interrupts is increasing in /proc/interrupts).The question is how do I configure it to generate interrupt every 40 ms and I how do I generate callback to have my registers reading.

2)TIM6/TIM12 -STM32 timer.

As far as I could see,current examples - pwm,counter,trigger ,does not fit my needs , since they don't have any form of periodic interrupt.

PWM example is the closest to what I need - it possibly could generate a signal that I need,but it doesn't have an option to have an interrupt function to read those registers

3)"st,stm32-timer" - I have stumbled into this option while digging throught the kernel source tree.It has clocksource and clockevents implementation ,but it seems that it works only with STM32F series.If it could work with TIMs of STM32MP15x series,please let me know.Also an example of usage would be useful.

Thank You!

1 ACCEPTED SOLUTION

Accepted Solutions
Kevin HUBER
ST Employee

Hello @vl4ever​ ,

This question was internally handled by me, so I will summaries here the information.

After a lot of tries on my side with TIM2, I asked an expert that confirmed me that the driver of Timer doesn't support the periodic interrupts.

At hardware level it is supported and the register UIF is raised, but there is no mechanism at driver level that throw an interrupt.

This feature of doing a periodic timer can be done easily by software, which avoid to clock the hardware.

For instance:

https://qnaplus.com/how-to-implement-periodic-timer-in-linux-kernel/

This link show how to do a periodic timer in a linux driver with an handler.

Some of these functions have a new name like "setup_timer" which is now "timer_setup".

https://lwn.net/Articles/735887/

I think this software solution, to use a software periodic timer that calls your function that reads registers, fills your need.

Hope it helps,

Regards,

Kevin

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
Kevin HUBER
ST Employee

Hello @vl4ever​ ,

This question was internally handled by me, so I will summaries here the information.

After a lot of tries on my side with TIM2, I asked an expert that confirmed me that the driver of Timer doesn't support the periodic interrupts.

At hardware level it is supported and the register UIF is raised, but there is no mechanism at driver level that throw an interrupt.

This feature of doing a periodic timer can be done easily by software, which avoid to clock the hardware.

For instance:

https://qnaplus.com/how-to-implement-periodic-timer-in-linux-kernel/

This link show how to do a periodic timer in a linux driver with an handler.

Some of these functions have a new name like "setup_timer" which is now "timer_setup".

https://lwn.net/Articles/735887/

I think this software solution, to use a software periodic timer that calls your function that reads registers, fills your need.

Hope it helps,

Regards,

Kevin

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.