GalladeGuy
Posts: 1
Joined: Mon Aug 23, 2021 3:08 am

Pi 4 bare metal GPIO interrupt example?

Mon Aug 23, 2021 3:30 am

I'm currently working on a project that involves reading a very fast signal (a few MHz) from the GPIO. Right now I have it sort of working by just polling the GPIO event detect status register, but it's not registering on some clock pulses, which I suspect has to do with both the time wasted going through the loop and the small chance of the clock pulse happening between the instructions reading and clearing the register. I figured that using interrupts would be the best way to fix those problems, and the BCM2711 datasheet mentions that one of the possible sources for interrupts is the GPIO.

I think I understand the basics of how to get interrupts working (setting up the vector table, enabling the interrupt controller, etc.), but I'm not entirely sure of how to do all of that on the Pi 4. All of the guides and examples I've found so far have been for earlier versions of the Pi, and from what I've read, it seems like some things have been changed on the Pi 4 and these examples would no longer work. Are there any examples that work on the Pi 4 so that I could have something to work off of? It doesn't have to be an in-depth tutorial or anything, even just an open source program or library that uses interrupts would be fine.

User avatar
Ultibo
Posts: 163
Joined: Wed Sep 30, 2015 10:29 am
Location: Australia
Contact: Website

Re: Pi 4 bare metal GPIO interrupt example?

Wed Aug 25, 2021 3:15 am

GalladeGuy wrote:
Mon Aug 23, 2021 3:30 am
Are there any examples that work on the Pi 4 so that I could have something to work off of? It doesn't have to be an in-depth tutorial or anything, even just an open source program or library that uses interrupts would be fine.
There aren't many bare metal projects that work with Pi 4 yet, both Circle and Ultibo support the GICv2 interrupt controller in the Pi 4 and both can receive an interrupt from the GPIO so that gives you two working examples that might help.

There is an option on the Pi 4 to use the old legacy interrupt controller (which is still present) instead of the new GIC and that would mean that a lot of the pre Pi 4 interrupt examples would also be relevant to use. You just need to put enable_gic=0 in your config.txt to switch back to the legacy interrupt controller.

One more thing, receiving clock pulses at several MHz using interrupts will generate several million interrupts per second which is a pretty high number by any standard that may well exceed the capability of even the most carefully crafted code. We've tested generating hundreds of thousands of interrupts per second on a Pi 4 using Ultibo but never millions of interrupts per second.
Ultibo.org | Make something amazing
https://ultibo.org

Threads, multi-core, OpenGL, Camera, FAT, NTFS, TCP/IP, USB and more in 3MB with 2 second boot!

isometimes
Posts: 3
Joined: Sun Jul 12, 2020 9:04 pm
Location: Cambridge, UK
Contact: Website Twitter

Re: Pi 4 bare metal GPIO interrupt example?

Wed Oct 13, 2021 9:20 pm

This might be useful? It's tested on the RPi4, and I just published it tonight:

https://github.com/isometimes/rpi4-osde ... interrupts

This just hooks the system timer, but I'm sure it could be easily adapted for GPIO interrupts...
--
Adam Greenwood-Byrne
adam@isometim.es

Return to “Bare metal, Assembly language”