Posts: 2
Joined: Sun Jul 01, 2018 1:32 am

Can only get one GPIO pin to blink.

Wed Jul 04, 2018 9:08 pm

EDIT: Figured it out, was using board pin #s when I should have been using GPIO pin #s

I have a RPi 3 B+ and am trying to write a simple C interface to the GPIO pins. I've gotten the UART working great, but I'm having trouble getting most of the other GPIO pins to blink a LED. I'm going to refer to the pins 0-indexed. The only pins I've gotten to work are pin 2 and pins 7 and 9 (UART). The following code should make pin 4 blink, however nothing happens. A slight variation definitely works to make pin 2 blink, so not sure what's up. Does anything look wrong? I'm wondering if it could be possible that I somehow fried all the GPIO pins except for 2,7, and 9? Just seems odd that only those would be unharmed.

Code: Select all

#define PBASE 0x3F000000
#define GPBASE (PBASE + 0x00200000)
#define GPSET0 (GPBASE + 0x1C)
#define GPCLR0 (GPBASE + 0x28)
void kernel_main(void) {
  *((uint32_t *)GPBASE) = 0b001000000000000;
  while (1) {
    *((uint32_t *)GPSET0) = 0b10000;
    *((uint32_t *)GPCLR0) = 0b10000;

Posts: 133
Joined: Sat Jan 13, 2018 12:29 am

Re: Can only get one GPIO pin to blink.

Fri Jul 06, 2018 11:12 am

Your code should work. I havn't tested it however it follows the same logic as everyone else, it uses the same registers, and the same addresses. I'm not sure why it wouldn't work. You realise you are using the BCM system numbering right? not the order of the pins? If you haven't already here is a useful site for the pinout. https://pinout.xyz/#

Good luck!

Return to “Bare metal, Assembly language”