ΥڡϤƤʥ֥åޡɲΥڡޤϤƤʥ֥åޡ Υڡlivedoor åפɲΥڡޤlivedoor å

ܼ

GPIO椹

  • Raspberry Pi 1SoCBCM28352BCM2836Ǥ롣
  • 54ĤGPIOġ

[]Raspberry Pi 2BǤϡGPIOإåˤϡGPIO2GPIO27¸ߤʤ

¾GPIOϼΤ褦ġ

  • GPIO16ϾɽLEDD5ˤ椹̾SDɤΥˡ
  • GPIO28GPIO31ϥܡIDˤäƻȤ졢R3R10ҤäƤR1ΥܡɤΤߡˡ
  • GPIO40GPIO45ϥʥǻȤ졢PWM򥵥ݡȤ롣R21R27𤷤ơʥ˷Ҥ롣
  • GPIO46HDMIΥۥåȥץ饰Τ롣
  • GPIO47GPIO53SDɤΥ󥿥ե˻ȤƤ롣
    • GPIO47SDθΥå˷ҤäƤ롣
    • GPIO48GPIO53R45R50𤷤SDɥ󥿥ե³롣

asmˤ

  • ʪ֤ˤơѤΥ֤Υ١ɥ쥹ϡ0x20000000BCM2835ξˤ뤤0x0x3F000000BCM2836ξˤǤ롣
  • GPIOΥ١ɥ쥹0x20200000BCM2835ξˤ뤤0x0x3F200000BCM2836ξ

ǤRaspberry Pi 2BѤΤǡʹߤBCM2836äʤ롣

GPIO

GPIO򤹤뤿ˡGPFSELGPIO Function SelectˤѰդƤ롣GPFSELGPFSEL0GPFSEL5Ȥ5Ĥʬ롣줾32ӥå롣֤1Хȡʡ8ӥåȡˤΥ꤬¤ΤǤ롣ĤޤꡢGPFSELΤϥΥɥ쥹0x3F2000000x3F200017Ѥ롣

No̾OffsetGPIO Pin#*1ɥ쥹
0GPFSEL0#00-90x3F2000000x3F200003
1GPFSEL1#410-1903F2000040x3F200007
2GPFSEL2#820-290x3F2000080x3F20000B
3GPFSEL3#1230-390x3F20000C0x3F20000F
4GPFSEL4#1640-490x3F2000100x3F200013
5GPFSEL5#2050-530x3F2000140x3F200017

ܺ٤ɽϼΤ褦ˤʤ롣

bit313029282726252423222120191817161514131211109876543210
GPFSEL0--pin #9pin #8pin #7pin #6pin #5pin #4pin #3pin #2pin #1pin #0
GPFSEL1--pin #19pin #18pin #17pin #16pin #15pin #14pin #13pin #12pin #11pin #10
GPFSEL2--pin #29pin #28pin #27pin #26pin #25pin #24pin #23pin #22pin #21pin #20
GPFSEL3--pin #39pin #38pin #37pin #36pin #35pin #34pin #33pin #32pin #31pin #30
GPFSEL4--pin #49pin #48pin #47pin #46pin #45pin #44pin #43pin #42pin #41pin #40
GPFSEL5--------pin #53pin #52pin #51pin #50

Pin3ӥåȳƤƤꡢ3ӥåȤGPIOư⡼ɤ뤳ȤǤ롣Ĥޤ8̤ʡ23ˤư⡼ɤǤ롣000ʤϡ001ʤнϤˤʤ롣

  • GPFSELΥɥ쥹0x3F2000004ߡPinֹ10dzäȤ͡
    • Pinֹ10dzäȤͤ05ϰϤǤ롣
    • 嵭ɽΥեåͤƤ褤
  • եȤӥåȿ3ߡPinֹ10dzäȤ;

㤨СGPIO21ϥ⡼ɤˤʤСΤ褦˵뤳ȤǤ롣

  • GPFSEL2
  • GPFSELΥɥ쥹0x3F2000008=0x3F200008
  • եȤӥåȿ313
  • եȤ̤Υӥåȡ00100010ʿ8

GPIO

GPIOϥ⡼ɤˤ硢0ϡפȡ1ϡפʬ롣ԤǤGPSET0ԤǤGPSET1Ȥ

No̾OffsetGPIO Pin#ɥ쥹
7GPSET0(GPIO Pin Set 0)#280-310x3F20001C0x3F20001F
8GPSET1(GPIO Pin Set 1)#3232-530x3F2000200x3F200023
9GPCLR0(GPIO Output Clear 0)#400-310x3F2000280x3F20002B
10GPCLR1(GPIO Output Clear 1)#4432-530x3F20002C0x3F20002F
11GPLEV0#480-310x3F2000340x3F200037
12GPLEV1#5232-530x3F2000380x3F20003B

㤨СGPIO211ϤˤϡGPSET0Ȥޤ0ϤˤϡGPCLR0ȤդˡϤǥԥξ֤ɤ߹ˤϡGPLEV0Ȥ

δŪήϼ̤Ǥ롣

@ GPFSELν
.input
LDR	R3, #3F200000		@ GPIO١ɥ쥹0x3F200000
MOV	R5, R3			@ ǻȤR5ˤȤäƤ.
ADD	R3, R3, #8		@ GPIO21GPFSEL2ʤΤǡեå8. R3GPFSEL2Υɥ쥹0x3F200008
MOV	R2, R3			@ GPFSEL2Υɥ쥹R2˥ԡ.
LDR	R2, [R2, #0]		@ R2GPFSEL2Υɥ쥹ǤϤʤGPFSEL2ͤǼ.
BIC	R2, R2, #0b111<<3	@ 3ӥåȺեȤơGPIO21ΤȤ򥯥ꥢ. R2******** ******** ******** **000***b
STR	R2, [R3, #0]		@ ǡGPFSEL2˽񤭹.

.output:
MOV	R2, R3			@ R2GPFSEL2Υɥ쥹
LDR	R2, [R2, #0]		@ ɥ쥹ͤ. R2******** ******** ******** **000***b
ORR	R2, R2, #1<<3		@ LSB1Υǡ¨001򥻥åȤ. R2******** ******** ******** **001***b
STR	R2, [R3, #0]		@ ǡGPFSEL2˽񤭹.

@ GPFSETν
MOV	R3, R5			@ ǽ˼äƤ١ɥ쥹Ȥ. R3GPIO١ɥ쥹
ADD	R3, R3, #28		@ GPIO21Ρ1ϤϡפGPFSET0ʤΤǡեå28. R3GPFSET0Υɥ쥹0x3F20001C
MOV	R4, #1
MOV	R2, R4, LSL #21		@ ե̿Ȥäơ21ӥåܤ1ˤǡ. R200000000 00100000 00000000 00000000b
STR	R2, [R3, #0]		@ ǡGPFSET0˽񤭹.

ʾƧޤƥǥ󥰤ȼ̤ˤʤ롣

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
    .global    main
main:
    SUB    SP, SP, #16    @ 16ХȤΰ.
 
openfile:
    LDR    R0, .addr_file
    LDR    R1, .flags
    BL    open
 
map:
    STR    R0, [SP, #12]    @ եϥɥֹ
    LDR    R3, [SP, #12]    @ եϥɥ.
    STR    R3, [SP, #0]    @ åΥȥåפ˥եϥɥǼ.
    LDR    R3, .gpiobase    @ 0x3F200000.
    STR    R3, [SP, #4]    @ ʹmmapΰ.GPIO١ɥ쥹
    MOV    R0, #0
    MOV    R1, #4096    @ R1=֥å
    MOV    R2, #3
    MOV    R3, #1        @ R3=1(stdout)
    BL    mmap
    
close:
    STR    R0, [SP, #16]    @ SP+16ϲۥꥢɥ쥹
    LDR    R3, [SP, #16]
    ADD    R3, R3, #8    @ եåȡ֥å2ʬ8
    LDR    R2, [SP, #16]
    ADD    R2, R2, #8
    LDR    R2, [R2, #0]
    BIC    R2, R2, #0b111<<3    @ GPIO21򥯥ꥢ.
    STR    R2, [R3, #0]
    LDR    R3, [SP, #16]
    ADD    R3, R3, #8
    LDR    R2, [SP, #16]
    ADD    R2, R2, #8
    LDR    R2, [R2, #0]
    ORR    R2, R2, #1<<3    @ OUTPUT=ONΥǡ.
    STR    R2, [R3, #0]
    LDR    R3, [SP, #16]
    ADD    R3, R3, #28    @ եåȡ28
    MOV    R4, #1
    MOV    R2, R4, LSL#21    @ GPFSETΥǡ.
    STR    R2, [R3, #0]
    LDR    R0, [SP, #12]    @ եϥɥ.
    BL    close
 
    ADD    SP, SP, #16
 
    MOV    R7, #1
    SWI    0
 
.addr_file:    .word    .file
.flags:        .word    1576962
.gpiobase:    .word    1059061760
 
    .data
.file:        .ascii    "/dev/mem\000"
  • GitHub
  • 15ܤSP+4GPIO١ɥ쥹򥻥åȤƤ롣mmap()ΰ5ĤꡢR0R3Ķʬmmap()ϤǤ롣

ΥץlibcƤӽФƤΤǡΤ褦gccǥѥ뤹롣

$ gcc -o on21 on21.s

¹ˡWebIOPiǾ֤ǧƤ

ǥեȤǤGPIO21ϡINפˤʤäƤ뤳ȤǧǤ롣

Ǥϥץ¹Ԥ롣

$ sudo ./on21¹ԤϴԸ¤ǹԤʤȡSegmation falutȯ롣

[]GDBDzϤϡgccǥѥ-Sץդgdb¹ԻˤsudoȤ

¹ԸˡWebIOPiǾ֤ǧȡGPIO21OUTĽϡON*2ˤʤäƤ뤳Ȥ狼롣

ȤꤢWebIOPiΥܥǾ֤INפᤷƤ

ʸ

  • Raspberry Pi ASSEMBLY LANGUAGE


*1 ޤGPIOֹ˳롣ԥإåγƥԥֹǤϤʤ㤨СGPIO Pin #21GPIO21Pin #40
*2 ONOFF