We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

1 post • Page 1 of 1
kevin_the_cabbage
Posts: 1
Joined: Sat Apr 05, 2025 9:18 pm

Enabling ARM Timer interrupts on RPi Zero

Sat Apr 05, 2025 10:02 pm

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:

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 .
Vector table:

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
IRQ handler (simply turns on LED):

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]
constants.s:

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)

1 post • Page 1 of 1

Return to "Bare metal, Assembly language"

AltStyle によって変換されたページ (->オリジナル) /