Rubydragon
Posts: 15
Joined: Sun Jan 15, 2017 10:18 pm

ACT LED on RPi Zero W

Thu Sep 28, 2017 7:28 pm

Hi,
I'm trying to follow the tutorials for bare metal programming on my Raspberry Pi Zero W at the moment and I can't get the ACT LED to turn on. I think it's because the LED is on another GPIO Pin on the Zero W than on the A or B, but I just can't find out what Pin it would be for me. The Raspberry is starting normally and blinking shortly once, indicating that it booted, but nothing more. I've tried two different versions of the same code for two different RPi Versions but neither worked.

Here are the two versions I tried. I had no build errors or anything. Everything worked, just the LED didn't stay on.

Code: Select all


.section .init
.globl _start
_start:

ldr r0,=0x20200000         // Load the GPIO address into r0.

mov r1,#1
lsl r1,#18
str r1,[r0,#4]

mov r1,#1
lsl r1,#16
str r1,[r0,#40]

loop$:
b loop$

Code: Select all


.section .init
.globl _start
_start:

ldr r0,=0x20200000         // Load the GPIO address into r0.

//
// Enable output on the GPIO 47 (OK led).
//

mov r1,#1
lsl r1,#18
str r1,[r0,#4]

//
// Set the GPIO 47 pin.
//

mov r1,#1
lsl r1,#16
str r1,[r0,#40]

loop$:
b loop$


User avatar
Ultibo
Posts: 173
Joined: Wed Sep 30, 2015 10:29 am
Location: Australia

Re: ACT LED on RPi Zero W

Fri Sep 29, 2017 12:02 am

Rubydragon wrote:
Thu Sep 28, 2017 7:28 pm
I think it's because the LED is on another GPIO Pin on the Zero W than on the A or B, but I just can't find out what Pin it would be for me.
On both the Zero and Zero W the Activity LED is on GPIO Pin 47, the same as the A+/B+/2B but different to the original A and B models (which are on GPIO pin 16).

The only other difference for the Zero/ZeroW is that you clear the pin to turn the LED on (and set the pin to turn the LED off) which is opposite to the A+/B+/2B.
Ultibo.org | Make something amazing
https://ultibo.org

Threads, multi-core, OpenGL, Camera, FAT, NTFS, TCP/IP, USB and more in 3MB with 2 second boot!

Rubydragon
Posts: 15
Joined: Sun Jan 15, 2017 10:18 pm

Re: ACT LED on RPi Zero W

Fri Sep 29, 2017 9:56 am

Ok thanks, I finally got it to work with this code:

Code: Select all

.section .init
.globl _start
_start:

ldr r0,=0x20200000         // Load the GPIO address into r0.

//
// Enable output on the GPIO 47 (OK led).
//

mov r1,#1
lsl r1,#21
str r1,[r0,#16]

//
// Clear the GPIO 47 pin.
//

mov r1,#1
lsl r1,#15
str r1,[r0,#44]

Loop:
    b Loop
This worked for me, I got it from this post: viewtopic.php?t=82871
I just had to clear the pin as you said instead of setting it so the LED turns on.
I'm still wondering though how I should have found this out myself, where would I search for this information other than get it from people that already know it? I couldn't find anything in the hardware manuals or that 200 page pdf about the processor so where would I search for this stuff?

Thanks anyways!

User avatar
Ultibo
Posts: 173
Joined: Wed Sep 30, 2015 10:29 am
Location: Australia

Re: ACT LED on RPi Zero W

Fri Sep 29, 2017 10:34 am

Rubydragon wrote:
Fri Sep 29, 2017 9:56 am
I'm still wondering though how I should have found this out myself, where would I search for this information other than get it from people that already know it?
The official schematics sort of almost show it but sometimes there is not enough detail or they are not released immediately with a new board so mostly these days the best source is the Linux device tree files which have to be accurate or Linux doesn't work.
Ultibo.org | Make something amazing
https://ultibo.org

Threads, multi-core, OpenGL, Camera, FAT, NTFS, TCP/IP, USB and more in 3MB with 2 second boot!

dwelch67
Posts: 1006
Joined: Sat May 26, 2012 5:32 pm

Re: ACT LED on RPi Zero W

Sat Sep 30, 2017 1:19 pm

This is how bare metal works. Writing the programs is the easy part, the information needed to write those programs is the hard(er) part. And there is no single answer, in this case a schematic would have been ideal, but they have been hit or miss with schematics after the first product. Sometimes you have to troll through linux sources, device tree as mentioned above, etc. Sometimes you just light up all the gpios one at a time and hope you dont smoke anything, sometimes disassemble some code that you are pretty sure talks to the thing. Or read through forums like this where someone has figured it out (or perhaps an employee or contractor with information has leaked it, not saying that happened here, but it is in the realm of possibilities, and does happen for products from time to time). You also have to assume that all documentation is wrong, not the whole document but just about every one of them for chips or peripherals has a t least one bug, if not great but so many of them do. Plus they are not all well done, or leave gaps, or make assumptions (like you work there and know something that the author knows that wasnt written down, or a document you dont have access to). Broadcom is the type of company that doesnt release anything without an NDA, and you could be a pretty big company and still not be big enough to be worthy of being a customer and thus no NDA because there is no way they will sell you parts. So what we were given was sadly not in the well done category of documentation (perhaps because they dont publish widely and thus dont know how?) or the version we got was banged out in a hurry or some other sort of haste makes waste. The community here has been awesome, on par with the avr freaks pre-arduino, there is a wiki page with errata to the documentation and this forum. You look at other similar vendors like Allwinner, whose customers tend to distribute the documentation (I would argue illegally, violating the NDA, look at the watermarks), or Nintendo (thinking GBA/NDS) where clearly someone either just gave out the docs and/or someone with the docs re-wrote them in a look what I figured out way. As with Broadcom and Allwinner chips like these that have open sourced linux drivers (or even broadcoms other product families) you can always fall back on that in combination with some hacking, if I set this bit like they do in the code does it do what the code implies it is doing or were there other things I had to do first that I have not found yet? There are some things that we never find, or in the case of 6502 things that were found decades later when they shaved the chip and took high resolution photos in order to be able to reverse engineer the chip at the transistor/metal layers, analyze and simulate it at the transistor/gate level.

Rubydragon
Posts: 15
Joined: Sun Jan 15, 2017 10:18 pm

Re: ACT LED on RPi Zero W

Sun Oct 01, 2017 1:38 am

Well, thanks for the insight :)
Anyways thanks for the help in general, everything now works fine, I just played with my Raspberry probably 6 hours coding the LED in Assembler and it's 3:40am so I should go to sleep. But I think it's a good sign ;)
Ruby

Spanyardie
Posts: 1
Joined: Thu Oct 08, 2020 6:11 pm

Re: ACT LED on RPi Zero W

Thu Oct 08, 2020 6:21 pm

Hi to all, have just joined and found good information that has helped a lot. I think I have this RP0 ACT LED thing sussed in my head now lol, so I'd like to add something to the post in the hope that it will help others - if there are any mistakes, please feel free to correct me - I'm a noob after all :D

Many thanks,

Code: Select all

.section .init
.globl _start
_start:

@********************************************************************
@ The start address of the GPIO controller data region 
@
	ldr r0,=0x20200000
@
@********************************************************************


@********************************************************************************
@ Prepare pin 47 for Output (which is the ACT LED on the Raspberry Pi Zero)  
@
@ Function select for GPIO pin 47 - FSEL47, bits 23-21 (001 is output) 
@
	mov r1,#1                                                                  
	lsl r1,#21                                                                 
@
@ GPIO Function select - GPFSEL4 (hex - 10, dec - 16)
@
	str r1,[r0,#16]                                                            
@
@*******************************************************************************

@*************************************************************************************************************************      
@ GPSETn - there are two registers, GPIO Output Set Registers 0 and 1
@
@ GPIO Output Set Register 0 - GPSET0 - corresponding to the GPIO pins 0 thru 31, address offset 28 (0x1C) - 31 (0x1F)
@ GPIO Output Set Register 1 - GPSET1 - corresponding to the GPIO pins 32 thru 53, address offset 32 (0x20) - 35 (0x23)
@
@ NOTE - Setting pins using GPSETn puts the specified pin HIGH (in the case of act LED this will turn it OFF)
@*************************************************************************************************************************      

@*************************************************************************************************************************      
@
@ GPCLRn - there are two registers, GPIO Output Clear Registers 0 and 1
@
@ GPIO Output Clear Register 0 - GPCLR0 - corresponding to the GPIO pins 0 thru 31, address offset 40 (0x28) - 43 (0x2B) 
@ GPIO Output Clear Register 1 - GPCLR1 - corresponding to the GPIO pins 32 thru 53, address offset 44 (0x2C) - 47 (0x2F)
@
@ NOTE - Clearing pins using GPCLRn puts the specified pin LOW (in the case of act LED this will turn it ON)
@*************************************************************************************************************************      

@*******************************************************************************
@ Clear the previously defined output pin 47 - this will put the pin LOW
@ Pin 47 is in Register GPCLR1 (pins 32 thru 53, as above), bit 15
@
	mov r1,#1                                                                  
	lsl r1,#15                                                                 
@
@ Data region offset for GPCLR1 starts at 44, as indicated above
	str r1,[r0,#44]                                                            
@
@*******************************************************************************

@*******************************************************************************
@ Now put the Pi into an infinite loop
@
loop$:                                                                         
	b loop$                                                                    
@
@*******************************************************************************

Return to “Bare metal, Assembly language”