I am trying to st GPIO 17 as an output. I am using Pi 2 model B. By searching for the base address of peripherals, I found that it is 0x3F000000. I want to write a code in assembly language, Following is my code

.section .init
.globl _start
ldr r0,=0x3F000000
mov r1,#1
lsl r1,#21
str r1, [r0,#4]
b loop$

I have saved the above code as gpio.s and then run the following commands to assemble it and linking it

as -o gpio.o gpio.s
ld -o gpio gpio.o

But by running it through

sudo ./gpio

The program does not set pin 17 as an output?

Any help will be useful.


You are running this under userland Linux.

Userland address spaces are virtual address spaces which bear no relationship to physical (hardware address spaces).

The Memory Management Unit (MMU) maps virtual addresses to physical addresses.

You need to tell your program to allow access to physical address 0x3F000000.

In C you would use mmap. I have no idea how you will achieve the same from assembler.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.