Page 1 of 1

Another beginner GPIO first try that doesn't work... Sorry.

Posted: Sun Jan 07, 2018 6:53 pm
by zedrummer
Hello

Like a lot of people out there, I have a brand new Raspberry Pi 3b on which I would like to try bare metal assembler.

I used the tutorials here:
https://github.com/adamransom/bare_metal

On Ubuntu, I compiled all 3 examples and transfered the "kernel.img" to the root directory and that are worked as expected.
So I decided to keep the led01 example, keep the frame and replace the code with:

Code: Select all

.global _start

.section .text
_start:
	ldr r0, =0x3f200000	@; GPIO base address for RPi3

	mov r1,#001			@; Ouput mode
	lsl r1,#24			@; 3*8=#24, so we work with the x8th pin
	str r1,[r0,#0]			@; 0*4=#0, so we work on GPIO 0 to 9 (so on GPIO #8)

	mov r1,#1			
	lsl r1,#8				@; still on the GPIO #8
	str r1,[r0,#0x28]		@; and we clear it

hang:
    b hang				@; Give the CPU something to do ad infinitum
The Makefile remains the same, I changed nothing else.

If I'm right, when you look at the RPi3 from the pins 0 up left to the 40 down right, the 8th GPIO is the second to the left column, so if I connect a voltmeter between the first in the left column (+3.3V) and this one, I should have 3.3V, but it remains 0V!
I tried changing the "str r1,[r0,#0x28]" with "str r1,[r0,#0x1c]" to SET the pin and not CLEAR it, but the result is the same.

Any help would be appreciated
Thanks to all the helpers.

Cathy L.

Re: Another beginner GPIO first try that doesn't work... Sorry.

Posted: Sun Jan 07, 2018 8:48 pm
by FTrevorGowen
zedrummer wrote: ...
If I'm right, when you look at the RPi3 from the pins 0 up left to the 40 down right, the 8th GPIO is the second to the left column, so if I connect a voltmeter between the first in the left column (+3.3V) and this one, I should have 3.3V, but it remains 0V!
I tried changing the "str r1,[r0,#0x28]" with "str r1,[r0,#0x1c]" to SET the pin and not CLEAR it, but the result is the same.
Any help would be appreciated
Thanks to all the helpers.
Cathy L.
Although I'm not a "bare metal" programmer (well not of a pi, 'though I have programmed quite a few 8-bit micro.'s in the distant past ....) I suspect your assumptions w.r.t. to GPIO number/label schemes (there are several "conventions") are wrong. Perhaps this info. will help:

Code: Select all

pi@raspiP3B16Gb:~ $ uname -a
Linux raspiP3B16Gb 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux
pi@raspiP3B16Gb:~ $ gpio readall
 +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT5 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT5 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
NB: the relationship between the BroadCoM labels and the physical (connector) pin numbers.
Trev.

Re: Another beginner GPIO first try that doesn't work... Sorry.

Posted: Sun Jan 07, 2018 9:00 pm
by rpiMike

Re: Another beginner GPIO first try that doesn't work... Sorry.

Posted: Sun Jan 07, 2018 9:14 pm
by zedrummer
So the numbers for the GPIO used when you code with bare metal are "BCM"?
Thanks a lot
You save me hours of trying different connections...
Cathy L.