GPIO

From XApple
Jump to: navigation, search

Bubblegum S500 GPIO

Boards based on Actions Semi Bubblegum S500 reference design have a 40 pin "Raspberry Pi compatible" header with the following layout.

GPIO# 2nd func pin# pin# 2nd func GPIO#
N/A +3V3 power output 1 2 +5V power output N/A
E1 I2C1_SDATA 3 4 +5V power output N/A
E0 I2C1_SCLK 5 6 GND N/A
D28 PCM1_IN 7 8 UART0_TX C27
N/A GND 9 10 UART0_RX C26
D29 PCM1_CLK 11 12 I2S_BCLK0 A28
D30 PCM1_SYNC 13 14 GND N/A
D31 PCM1_OUT 15 16 UART5_RX D24
N/A +3V3 power output 17 18 UART5_TX D25
D13 SPI2_MOSI 19 20 GND N/A
D12 SPI2_MISO 21 22 MMC1_CMD C20
D14 SPI2_SCLK 23 24 NAND_CEB2 D16
N/A GND 25 26 SIRQ1 A25
C14 MMC1_D0 27 28 UART2_RTSB D20
C15 MMC1_D1 29 30 GND N/A
C16 MMC1_D2 31 32 UART3_TX D23
C17 MMC1_D3 33 34 GND N/A
A29 I2S_LRCLK0 35 36 UART3_RX D22
C21 MMC1_CLK 37 38 I2S_D1 A31
N/A GND 39 40 I2S_D0 A27

GPIO naming

The GPIO pin mapping and naming are related among SoC, GPIO headers and compatible library such as WiringPi to Raspberry Pi.


There is a good article to understand the definitions about BCM pin number, WiringPi pin number and the location of Raspberry Pi 2 compatible 40-pin headers(BOARD pins).


WiringPi GPIO Pinout at Raspberry Pi GPIO Pinout [1]


In addition, CPU's definition is so-called RAW numbers.

For example, in S500 platform, the RAW numbers are counted as below. The RAW number mapping GPIO operation is enabled in the kernel by default. But you need to know the correct number from the GPIO group and its number.


GPIO-GroupAlphabet-Number stands for: 

GPIO A group =   0 + *NUMBER*.  For example, GPIOA29 = 0+29 = 29 (also point to BOARD pin number = 35)

GPIO B group =  32 + *NUMBER*.  For example, GPIOB32 = 16+32 = 48 (not point to any BOARD pin number) 

GPIO C group =  64 + *NUMBER*.  For example, GPIOC27 = 64+27 = 91 (also point to BOARD pin number = 8)

GPIO D group =  96 + *NUMBER*.  For example, GPIOD13 = 96+13 = 109 (also point to BOARD pin number = 19)

GPIO E group = 128 + *NUMBER*.  For example, GPIOE1 = 128+1 = 129 (also point to BOARD pin number =3)


The mapping table of RaPi.GPIO library between BOARD pin and S500 RAW number should be listed.


Important Notice about enabling special GPIO pins

1. Three GPIO pins including GPIOD28, GPIOD29, GPIOD31

In order to output those three pins, we need to set CPU_PWR_CTL before enabling.

IO_WRITEU32(CPU_PWR_CTL,0x000000f0);//gpio_pad_en0123 enable for GPIOD28~31 out enable

2. Four GPIO pins including GPIOA27, GPIOA28, GPIOA29, GPIOA31

Because there is an I2S_SELECTION to switch between internal audio codec of PMU and external codec, we need to configure this I2S_SELECTION to correctly before we start to control them as GPIO functions. Then configure those GPIO as out enable.

IO_WRITEU32(0xB01B000C,2);//GPIOB1 output enable
IO_OR_U32(0xB01B0014,2);//GPIOB1 output "high" to enable GPIO header pins.

GPIO control example code

There are some sample Python code to know how to control the GPIO pins in RoseapplePi RaPi.GPIO library(S500 platform). For example, the led.py in test folder can control a LED flashing periodically.

#!/usr/bin/env python
import RaPi.GPIO as GPIO
import time

#LED Mode BCM
#PINs = [2,3,4,14,15,17,18,27,22,23,24,10,9,25,11,8,7,0,1,5,6,12,13,19,16,26,20,,21]
#[2,3,4,14,18,23,24,10,9,11,8,7,0,1,5,6,12,13,19,16,26,20,21]
#[15,17,27,22,25]
#GPIO.setmode(GPIO.BCM)

#LED Mode BOARD
#PINs = [3,5,7,8,10,11,12,13,15,16,18,19,21,22,23,24,26,27,28,29,31,32,33,35,36,,37,38,40]
#[3,5,7,8,12,16,18,19,21,23,24,26,27,28,29,31,32,33,35,36,37,38,40]
#[10,11,13,15,22]
PINs = [10]
GPIO.setmode(GPIO.BOARD)

while True:
	for PIN_NUM in range(len(PINs)):
		try:
			GPIO.setup(PINs[PIN_NUM], GPIO.OUT)
		except:
			print("Failed to setup GPIO %d", PIN_NUM)

		GPIO.output(PINs[PIN_NUM], True)
		time.sleep(0.5)
		GPIO.output(PINs[PIN_NUM], False)
                time.sleep(0.5)

Please kindly check the GPIO.setmode with correct GPIO naming rule.

Meanwhile, please check the different GPIO library import name for different platform. (Raspberry Pi -> RPi.GPIO; Roseapple Pi -> RaPi.GPIO; LeMaker Guitar -> LMK.GPIO)

Personal tools
Namespaces

Variants
Actions
Navigation
Tools