chigley
Posts: 2
Joined: Mon Dec 10, 2012 2:37 pm

GPIO Controller Segmentation Fault

Mon Dec 10, 2012 2:42 pm

Hi,

I'm trying to use the below assembly code to set GPIO pin 16 high, taken from this tutorial:

Code: Select all

.align 2
.globl main
main:
    ldr r0,=0x20200000

    mov r1,#1
    lsl r1,#18

    str r1,[r0,#4]

    mov r1,#1
    lsl r1,#16

    str r1,[r0,#40]

loop$:
    b loop$
I'm compiling it with GCC, and when I debug with GDB, the following error occurs:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
main () at pinHigh.s:42
42	str r1,[r0,#4]
I believe that the address value in r0 is correct, as a C file which correctly compiles and runs has the following definitions at the top:

Code: Select all

// Access from ARM Running Linux

#define BCM2708_PERI_BASE        0x20000000
#define GPIO_BASE                (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
Any advice would be appreciated!

Cheers

chigley
Posts: 2
Joined: Mon Dec 10, 2012 2:37 pm

Re: GPIO Controller Segmentation Fault

Mon Dec 10, 2012 4:02 pm

I should add, I'm running with sudo permissions, as I understand that this is required for GPIO.

User avatar
joan
Posts: 14196
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO Controller Segmentation Fault

Mon Dec 10, 2012 4:43 pm

If you are using Linux (which mention of gdb, sudo etc. suggests) then you'll need to memory map fron Linux virtual addresses to the hardware physical address.

Return to “Bare metal, Assembly language”