dewn2d
Posts: 6
Joined: Sat Dec 17, 2016 5:11 am

Pi zero gpio

Sun Dec 18, 2016 12:03 am

http://www.cl.cam.ac.uk/projects/raspbe ... orials/os/

i've been going through this tutorial for bare metal programming on the pi zero but im not sure what gpio pins and registers i should be using for the pi zero.

this is what i have written so far:

Code: Select all

.section .init
.globl _start
_start:

	@ ldr r0,=0x20200000  	@ Load r0 with hexadecimal number: 0x20200000 (Raspberry Pi 1)
	ldr r0,=0x3f200000  @ Load r0 with hexadecimal number: 0x3f200000 
	mov r1,#1	@ Move decimal number 1 to r1
	lsl r1,#21	@ Logical shift left the value in r1 by 21 places
	str r1,[r0,#16] @ Store r1 in the address calculated by [r0 + 16]

	mov r1,#1	
	lsl r1,#15	@  The left logical shift becomes only 15 for pin 47 because the GPSET1/GPCLR1 deal with pins 32 through 63 (47-32 = 15)
	str r1,[r0,#32]

loop$: 
	b loop$


baantonia
Posts: 63
Joined: Fri Feb 06, 2015 2:19 pm

Re: Pi zero gpio

Wed Dec 21, 2016 12:16 pm

I've found the PiZero to have the same GPIO memory mapping as the B+ starting at 0x20200000.
Setting GPIO 47 to output also sets all the other GPIO registers in that bank to input as a by product, but that's not important in the scheme of things.
Yes GPIO 47 should be set at the end of your code, when using the lower address space for the GPIO mapping.

I'm assuming you are trying to light the OK LED. Not sure which GPIO is attached to the OK LED on the PiZero, this has shifted from one Pi to another. Maybe someone else can enlighten this further.

LdB
Posts: 1220
Joined: Wed Dec 07, 2016 2:29 pm

Re: Pi zero gpio

Wed Dec 21, 2016 1:11 pm

Zero does not have a power LED, only an activity LED and it's backwards to original Pi in that low = on, high = off as the led is sinking from the positive rail into the GPIO pin.

You are correct about the addressing for the GPIO which is 0x20200000.

The activity LED is on GPIO port 47 on the zero same as Pi2B+. It was on GPIO port 18 on the Pi2 and GPIO port 16 on the Original raspberry Pi. Now on the Pi3 it isn't on any GPIO it is on the expansion bus :-)

baantonia
Posts: 63
Joined: Fri Feb 06, 2015 2:19 pm

Re: Pi zero gpio

Fri Dec 23, 2016 7:47 am

Thank you, I have not investigated LED settings for the zero, that is useful information which I have not come across in my searches.

Return to “Bare metal, Assembly language”