I tried to blink the led that I connected to GPIO 4, and it blinks. But what confuses me is that activity LED (the green one) also blinks along with led on GPIO 4. Here is my code that just turns GPIO 4 on:
.section ".text.boot"
.globl notmain
.equ GPIOBASE, 0x3f200000
.equ FSEL0, 0x0
.equ SET_BIT12, 0x00001000
.equ SET_BIT12_MASK, 0x00007000
.equ SET_BIT4, 0x00000010
.equ GPSET0, 0x1c
.equ GPCLR0, 0x28
notmain:
ldr r0, =GPIOBASE
ldr r1, [r0, #FSEL0]
ldr r2, =SET_BIT12_MASK
mvn r2, r2
and r1, r1, r2
orr r1, r1, #SET_BIT12
ldr r0, =GPIOBASE
str r1, [r0, #FSEL0]
ldr r0, =GPIOBASE
ldr r1, [r0, #GPSET0]
orr r1, r1, #SET_BIT4
ldr r0, =GPIOBASE
str r1, [r0, #GPSET0]
loop:
b loop
If I replace #GPSET0 with #GPCLR0, activity led will also turn off. Why would those two things be connected?
GPSET and GPCLR registers are not intended to be read-modify write. They are intended to be written with a 1 where you want that action, so to set gpio 4 you write 1<<4 to GPSET, to clear gpio4 you write 1<<4 to GPCLR.
In your read-modify-write you are probably reading in some ones and then writing them back may change the state of those pins too. for CLR/SET writing a 0 does not change the state of a gpio pin, a 1 does, you can change one or some or all (to that state) in a single write.
User contributions licensed under CC BY-SA 3.0