Tony201800
Posts: 2
Joined: Sun Sep 09, 2018 9:57 am

Accessing GPIO Pins via Bare Metal

Sun Sep 09, 2018 11:12 am

Hi there,

I have secured a pi 3 b+ recently and trying out bare metal programming on it. I know the board itself has 2 banks each having 20x header pins made up of ground, vdd, gpio etc...

I have seen a handful of online tuts of what others have done using bare metal to blink the onboard ACT led etc.. but I have yet to find someone who has atleast attempted to bare metal program an LED on a breadborad connected to the pi 3 b+ via the header pins. This is exactly what I am trying to achieve.

Could someone please guide me on the process here. I will boot into this little program (which in most cases does sound like my own little OS/kernel) only that it will blink an LED connected to a bread board via the header pins. I know the electrical side of it i.e., connecting the LED on the breadboard and then hooking the breadboard to the pi 3 b+ so I just need to know ARM's integration into it. What are the GPIO pins/registers etc...on the bc2387 that control the onboard header pins.

Any help will be immensely appreciated.

Many thanks,
Tony

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

Re: Accessing GPIO Pins via Bare Metal

Sun Sep 09, 2018 12:36 pm

The tutorials you are referring to are probably doing what you want. They are using the GPIO peripheral to blink a LED. For convenience they are using the GPIO connected to the on-board LED. You just need to change from that GPIO number to the number of the GPIO you want to use.

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

Re: Accessing GPIO Pins via Bare Metal

Sun Sep 09, 2018 7:37 pm

On the Pi3B+ GPIO port 29 is the activity led

You will need to decide if you are going to do 32bit or 64bit, the PI3B+ does both.

You will have to learn or borrow a little assembler code in whichever you chose to at least get the Pi3 up and running even if you are going to write in C/C++. There is some minimal stuff you have to do on bootup such as set a stack pointer.

The main tutorials are in the top two posts that are permanently stickied there start there and ask questions if you get stuck.

Tony201800
Posts: 2
Joined: Sun Sep 09, 2018 9:57 am

Re: Accessing GPIO Pins via Bare Metal

Thu Oct 11, 2018 3:55 am

Hi LdB/Joan,

Many thanks for your replies. I have been reading up on the architecture but the white paper on ARM CortexA53 the chip used for pi 3 b+ is simply one of the most challenging & daunting tasks to undertake :).

I went through the bcm2387 peripherals guide which sadly borrows alot of its content from its predecessor the bcm2385. On page 89 (ch.6) of the bcm2387 guide it mentions..."54 gpio lines split into two banks". The physical board has the gpio header with 40 pins split into rwo banks of 20 pins.

Could you or anyone else in the forumn please explain the correlation between the header pins on the board and the 54 pins mentioned in the guide.

Best regards,
Tony

User avatar
rpdom
Posts: 12884
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: Accessing GPIO Pins via Bare Metal

Thu Oct 11, 2018 4:47 am

Tony201800 wrote:
Thu Oct 11, 2018 3:55 am
I went through the bcm2387 peripherals guide which sadly borrows alot of its content from its predecessor the bcm2385.
Why "sadly"? The GPIO hardware on the two chips is pretty much identical. The main differences were the CPU cores used and the bootrom update.
please explain the correlation between the header pins on the board and the 54 pins mentioned in the guide.
Look at https://pinout.xyz/ to see the relationship between the pins and the GPIO numbers. Only 28 of those 54 GPIOs (all from the first bank) are brought out to the header connector. The BCM numbers on the diagram are the ones you need to use.

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

Re: Accessing GPIO Pins via Bare Metal

Thu Oct 11, 2018 4:57 am

There is no logic behind the correlation the numbers you see in code are the GPIO numbers which is how they come in as registers.

The physical is just how the board designer took them to a physical header if at all. So you end up with a mapping of GPIO
numbers on physical pin numbers. They basically set GPIO 02-26 on pins . You will find huge numbers of diagrams on the net
showing you the mapping the board designer settled on like
Image

My only word of warning that once caught me out once there is a 3rd numbering system that kicks around on the net which is some abstract linux IO numbers. Why anyone would ever use scheme is beyond me but in baremetal you would never use it as it just adds a layer of confusion.

It would be rare on this section of the the forum to use anything other than GPIO programming number, we would assume you would know the mapping to the physical pin on the board you are using. If you did try to talk about a physical pin on a model most would immediately turn it to a GPIO number and talk about that.

Finally the GPIO has a max speed of about 68-71Mhz on the Pi3B+, just because the ARM can run at 1.4Ghz do not expect that from the GPIO.

Return to “Bare metal, Assembly language”