Raspberry Pi GPFSEL, GPIO, and PADS Status Viewer

      3 Comments

The gpfsel_list (I maybe should have called it lsgpio) utility displays a list of the currently configured function selections across all available GPIO pins and, for pins configured as GPIO, the current state of the pins. For pins configured with ALTn functions, the selected function is listed according to the datasheet information.

It also shows the state of the PADS registers to display the configured drive current, hysteresis, and slew setting for the three groups of pins (GPIO 0-27, 28-45, and 46-53).

It’s been written to produce output that’s easy to grep and cut, and performs only read operations on the registers – it can’t be used to modify settings, though I suppose this could change in future.

The purpose of the program is simply to get an overview of how the peripherals are configured, for example when asking for help in forum posts or when a pin isn’t behaving as expected. The output looks something like this: –

root@pi:~# ./gpfsel_list
PADS configuration
  GPIO  0-27: DRIVE  8ma, HYST On, SLEW Off
  GPIO 28-45: DRIVE 16ma, HYST On, SLEW Off
  GPIO 46-53: DRIVE  8ma, HYST On, SLEW Off
GPFSELn states
  FSEL0 (GPFSEL0[00-02]) = 4 (ALT0 - SDA0)
  FSEL1 (GPFSEL0[03-05]) = 4 (ALT0 - SCL0)
  FSEL2 (GPFSEL0[06-08]) = 4 (ALT0 - SDA1)
  FSEL3 (GPFSEL0[09-11]) = 4 (ALT0 - SCL1)
  FSEL4 (GPFSEL0[12-14]) = 0 (GPIO In - [Low])
  FSEL5 (GPFSEL0[15-17]) = 4 (ALT0 - GPCLK1)
  FSEL6 (GPFSEL0[18-20]) = 1 (GPIO Out - [High])
  FSEL7 (GPFSEL0[21-23]) = 4 (ALT0 - SPI0_CE1_N)
  FSEL8 (GPFSEL0[24-26]) = 4 (ALT0 - SPI0_CE0_N)
  FSEL9 (GPFSEL0[27-29]) = 4 (ALT0 - SPI0_MISO)
  FSEL10 (GPFSEL1[00-02]) = 4 (ALT0 - SPI0_MOSI)
  FSEL11 (GPFSEL1[03-05]) = 4 (ALT0 - SPI0_SCLK)
  FSEL12 (GPFSEL1[06-08]) = 0 (GPIO In - [Low])
  FSEL13 (GPFSEL1[09-11]) = 0 (GPIO In - [Low])
  FSEL14 (GPFSEL1[12-14]) = 4 (ALT0 - TXD0)
  FSEL15 (GPFSEL1[15-17]) = 4 (ALT0 - RXD0)
  FSEL16 (GPFSEL1[18-20]) = 1 (GPIO Out - [High])
  FSEL17 (GPFSEL1[21-23]) = 1 (GPIO Out - [Low])
  FSEL18 (GPFSEL1[24-26]) = 0 (GPIO In - [Low])
  FSEL19 (GPFSEL1[27-29]) = 0 (GPIO In - [Low])
  FSEL20 (GPFSEL2[00-02]) = 0 (GPIO In - [Low])
  FSEL21 (GPFSEL2[03-05]) = 0 (GPIO In - [Low])
  FSEL22 (GPFSEL2[06-08]) = 0 (GPIO In - [Low])
  FSEL23 (GPFSEL2[09-11]) = 0 (GPIO In - [Low])
  FSEL24 (GPFSEL2[12-14]) = 0 (GPIO In - [Low])
  FSEL25 (GPFSEL2[15-17]) = 0 (GPIO In - [Low])
  FSEL26 (GPFSEL2[18-20]) = 0 (GPIO In - [Low])
  FSEL27 (GPFSEL2[21-23]) = 1 (GPIO Out - [Low])
  FSEL28 (GPFSEL2[24-26]) = 0 (GPIO In - [High])
  FSEL29 (GPFSEL2[27-29]) = 0 (GPIO In - [Low])
  FSEL30 (GPFSEL3[00-02]) = 0 (GPIO In - [Low])
  FSEL31 (GPFSEL3[03-05]) = 0 (GPIO In - [Low])
  FSEL32 (GPFSEL3[06-08]) = 0 (GPIO In - [Low])
  FSEL33 (GPFSEL3[09-11]) = 0 (GPIO In - [Low])
  FSEL34 (GPFSEL3[12-14]) = 0 (GPIO In - [Low])
  FSEL35 (GPFSEL3[15-17]) = 0 (GPIO In - [Low])
  FSEL36 (GPFSEL3[18-20]) = 0 (GPIO In - [Low])
  FSEL37 (GPFSEL3[21-23]) = 0 (GPIO In - [Low])
  FSEL38 (GPFSEL3[24-26]) = 0 (GPIO In - [Low])
  FSEL39 (GPFSEL3[27-29]) = 0 (GPIO In - [Low])
  FSEL40 (GPFSEL4[00-02]) = 4 (ALT0 - PWM0)
  FSEL41 (GPFSEL4[03-05]) = 0 (GPIO In - [Low])
  FSEL42 (GPFSEL4[06-08]) = 0 (GPIO In - [Low])
  FSEL43 (GPFSEL4[09-11]) = 0 (GPIO In - [Low])
  FSEL44 (GPFSEL4[12-14]) = 0 (GPIO In - [Low])
  FSEL45 (GPFSEL4[15-17]) = 4 (ALT0 - PWM1)
  FSEL46 (GPFSEL4[18-20]) = 0 (GPIO In - [Low])
  FSEL47 (GPFSEL4[21-23]) = 0 (GPIO In - [Low])
  FSEL48 (GPFSEL4[24-26]) = 7 (ALT3 -   -  )
  FSEL49 (GPFSEL4[27-29]) = 7 (ALT3 -   -  )
  FSEL50 (GPFSEL5[00-02]) = 7 (ALT3 -   -  )
  FSEL51 (GPFSEL5[03-05]) = 7 (ALT3 -   -  )
  FSEL52 (GPFSEL5[06-08]) = 7 (ALT3 -   -  )
  FSEL53 (GPFSEL5[09-11]) = 7 (ALT3 -   -  )

The columns of the output are FSELn number (effectively the GPIO number), the GPFSELn register number and associated bit-numbers, the function number (0-7), the function name (In, Out, ALT0-ALT5), and the descriptive name for the ALT function according to the GPIO pin it’s associated with.

The C source code is linked below. Download the files onto your Raspberry Pi, then compile and run (as root) with: –

root@pi:~# gcc -o gpfsel_list gpfsel_list.c
root@pi:~# ./gpfsel_list

There are no special dependencies, so the code should work on any GNU/Linux image that includes GCC.

 

3 thoughts on “Raspberry Pi GPFSEL, GPIO, and PADS Status Viewer

Leave a Reply to JBeale Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>