I'm trying to run some bare-metal code on my raspi 3. This is my first time doing any sort of bare-metal programming, so first things first I want to turn on my ACT led as a kind of hello-world type program but I can't for the life of me get it to turn on.

From what I've gathered:

  • the act led is on gpio pin 47
  • I need to set this pin to an output using gpio function select
  • this pin is active low so to turn it on I need to clear it

My sd card is a raspbian image but I replaced the kernel.img with my own. Also the config.txt is completely empty at the moment.Below is the assembly code I'm running, my linker sets .init to be 0x8000

.section .init
.global _start

GPIO_BASE = 0x3F200000
GPFSEL4 = 0x10
GPSET1 = 0x20
GPCLR1 = 0x2C

    ldr r0,=GPIO_BASE

    //set ACT led to output
    mov r1,#1
    lsl r1,#21 //gpio 47 = 21-23
    str r1,[r0,#GPFSEL4] 

    //turn on ACT led
    mov r1,#1
    lsl r1,#16
    str r1,[r0,#GPCLR1]
    b loop

4 Answers 4


Models A and B

  • The green activity LED (GPIO 16) may be written.

Models A+ and B+

  • The green activity LED (GPIO 47) may be written.
  • The red power LED (GPIO 35) may be written.
  • The high USB power mode (GPIO 38) may be written.

Pi Zero and Pi Zero W

  • The green activity LED (GPIO 47) may be written.


  • The green activity LED (GPIO 47) may be written.
  • The red power LED (GPIO 35) may be written.
  • The high USB power mode (GPIO 38) may be written.


  • The green activity LED and the red power LED are not directly writeable. They are not connected to the GPIO. On the Pi3 the LEDs are connected to an I2C port expander. There is a method to write the LEDs but I think it uses the mailbox interface to the GPU.
  • The USB power mode is fixed at 1.2 amps (high power).
  • Where did you find that Pi3B info about the I2C port expander? I haven't ever seen anything about that
    – Ripread
    Commented May 24, 2017 at 0:27
  • @Ripread I'm not sure where I first saw. See raspberrypi.org/forums/viewtopic.php?p=1080502#p1080502 for useful info.
    – joan
    Commented May 24, 2017 at 3:00
  • For Pi3B+ it should be GPIO29
    – filippo
    Commented Nov 30, 2018 at 23:05

Expanding joan's answer:

Raspberry Pi 3 B+ (1 GiB RAM) and A+ (512 MiB RAM)

  • The green activity LED (GPIO 29) may be written

    • The red power LED is connected to MXL7704 power management IC and is not available to software
  • The USB power mode is fixed at high power


You are shifting the r1 register 16 bits left, this clears the 16th pin. You should instead shift the r1 register 47 bits left to clear pin 47(the ACT LED). As posted above, you cannot access the ACT LED through the GPIO controller, but you can on the RPI Zero/RPI Zero W, so your code should work on those.


The shift should be 15 bits not 16, your 1 as the first bit would already be in bit 0 before the shift and needs to be in bit 15, ie the 16th bit.

Your code is placing a 1 in the 17th bit so is in the wrong place. Shifting by 47 will not work as the 1 will drop off the end of a 32 bit number, lsl doesn't roll, it fills with zeros.

Note: 47-32=15, hence the lsl r1,#15 instead. The first 32 bits would be for GPIOs 0 to 31 via GPSET0 and GPCLR0, offsets 0x1C and 0x28, GPIOs 32 to 53 via GPSET1 and GPCLR1, offsets 0x20 and 0x2C, all offsets relative to the respective base GPIO address of the Pi. However, as noted, the LED control has moved in different Pi versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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