- kevin_the_cabbage
- Posts: 1
- Joined: Sat Apr 05, 2025 9:18 pm
Enabling ARM Timer interrupts on RPi Zero
Hello,
I'm trying to set up ARM timer interrupts on the Raspberry Pi Zero. Below, I have posted a minimal example which (I think) correctly enables hardware interrupts and ARM timer interrupts specifically. However, even in this example, the IRQ handler is never reached, which I know because the LED never turns on. Is there something I'm missing that I need to enable interrupts, or am I misunderstanding how interrupts are implemented in bare-metal assembly?
kernel.s:
Vector table:
IRQ handler (simply turns on LED):
constants.s:
I'm trying to set up ARM timer interrupts on the Raspberry Pi Zero. Below, I have posted a minimal example which (I think) correctly enables hardware interrupts and ARM timer interrupts specifically. However, even in this example, the IRQ handler is never reached, which I know because the LED never turns on. Is there something I'm missing that I need to enable interrupts, or am I misunderstanding how interrupts are implemented in bare-metal assembly?
kernel.s:
Code: Select all
.include "constants.s"
.equ timer_enable_bit, (1 << 5)
.equ timer_irq_bit, (1 << 7)
.section .text
.global _start
_start:
@ Enable timer IRQ interrupts
ldr r0, =IRQ_ENABLE_BASIC
ldr r1, [r0]
orr r1, r1, #irq_timer_bit
str r1, [r0]
@ Enable ARM timer and ARM timer interrupts (bits 5 and 7)
ldr r0, =ARM_TIMER_CONTROL
ldr r1, [r0]
orr r1, r1, #(timer_enable_bit | timer_irq_bit)
@ Set timer prescale to 1 (bits 2 and 3)
bic r1, r1, #(0b11 << 2)
str r1, [r0]
@ Enable interrupts globally
cpsie i
@ Set first timer interrupt cycle
@ For 1Hz, we load 1e6 (-> 1us * 1e6 = 1s)
ldr r0, =ARM_TIMER_LOAD
ldr r1, =arm_timer_interval
str r1, [r0]
@ Set vector base address to 0x0 (by linker script)
ldr r0, =_vectors
mcr p15, 0, r0, c12, c0, 0
@ Loop continuously
b .
Code: Select all
.section .vectors
.align 4
.global _vectors
_vectors:
b . @ Reset
b .
b . @ Supervisor call (software interrupt)
b . @ Prefetch abort
b . @ Data abort
b .
b _irq_handler
b . @ FIQ
Code: Select all
.include "constants.s"
.section .text
.align 4
.global _irq_handler
_irq_handler:
@ Turn on LED
ldr r3, =GPCLEAR1
mov r4, #led_bit
str r4, [r3]
Code: Select all
@ This file defines some useful constants used across files
@ General IRQ registers
.equ IRQ_ENABLE_BASIC, 0x2000b218
.equ irq_timer_bit, 1
@ ARM timer
.equ ARM_TIMER_LOAD, 0x2000b400
.equ ARM_TIMER_CONTROL, 0x2000b408
.equ ARM_TIMER_MASKED_IRQ, 0x2000b414
.equ ARM_TIMER_RAW_IRQ, 0x2000b410
.equ arm_timer_interval, 1000000
@ LED on/off
.equ GPSET1, 0x20200020
.equ GPCLEAR1, 0x2020002c
.equ led_bit, (1 << 15)
Return to "Bare metal, Assembly language"
Jump to
- Community
- General discussion
- Announcements
- Other languages
- Deutsch
- Español
- Français
- Italiano
- Nederlands
- 日本語
- Polski
- Português
- Русский
- Türkçe
- User groups and events
- Raspberry Pi Official Magazine
- Using the Raspberry Pi
- Beginners
- Troubleshooting
- Advanced users
- Assistive technology and accessibility
- Education
- Picademy
- Teaching and learning resources
- Staffroom, classroom and projects
- Astro Pi
- Mathematica
- High Altitude Balloon
- Weather station
- Programming
- C/C++
- Java
- Python
- Scratch
- Other programming languages
- Windows 10 for IoT
- Wolfram Language
- Bare metal, Assembly language
- Graphics programming
- OpenGLES
- OpenVG
- OpenMAX
- General programming discussion
- Projects
- Networking and servers
- Automation, sensing and robotics
- Graphics, sound and multimedia
- Other projects
- Media centres
- Gaming
- AIY Projects
- Hardware and peripherals
- Camera board
- Compute Module
- Official Display
- HATs and other add-ons
- Device Tree
- Interfacing (DSI, CSI, I2C, etc.)
- Keyboard computers (400, 500, 500+)
- Raspberry Pi Pico
- General
- SDK
- MicroPython
- Other RP2040 boards
- Zephyr
- Rust
- AI Accelerator
- AI Camera - IMX500
- Hailo
- Software
- Raspberry Pi OS
- Raspberry Pi Connect
- Raspberry Pi Desktop for PC and Mac
- Beta testing
- Other
- Android
- Debian
- FreeBSD
- Gentoo
- Linux Kernel
- NetBSD
- openSUSE
- Plan 9
- Puppy
- Arch
- Pidora / Fedora
- RISCOS
- Ubuntu
- Ye Olde Pi Shoppe
- For sale
- Wanted
- Off topic
- Off topic discussion