Beagle Bone BlackのPRUを学ぶ(その3)

前回に引き続き、以下のチュートリアルの追試行を行う。
BeagleBone Black: Introduction to PRU-ICSS
Example 2 – PRU0 PWM

ここでのPWMはAM335xのペリフェラルとしてのPWMではなく、PRUでソフト的にPWMを生成するもの。
ARM Coretex-A8側からの連携例として、10msec毎にUser-Landでsin波形を生成し、10msec毎に値を書き換える事により正弦波波形を出力する。
使用するポートはExample 1と同じpr1_pru0_pru_r30[14]/GPIO1[12]で、LEDを接続しておくと点滅ではなく緩やかに明滅するはずだ。

手順をなぞる。

サンプルの取得と開梱。

debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/led/obj$ cd ../..
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps$ mkdir pwm
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps$ cd pwm/
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ wget http://analogdigitallab.org/sites/default/files/pwm.zip
--2014-10-21 14:32:11--  http://analogdigitallab.org/sites/default/files/pwm.zip
Resolving analogdigitallab.org (analogdigitallab.org)... 188.93.153.77
Connecting to analogdigitallab.org (analogdigitallab.org)|188.93.153.77|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14438 (14K) [application/zip]
Saving to: `pwm.zip'

100%[======================================>] 14,438      51.3K/s   in 0.3s

2014-10-21 14:32:12 (51.3 KB/s) - `pwm.zip' saved [14438/14438]

ebian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ unzip pwm.zip
Archive:  pwm.zip
  inflating: pwm.bin
  inflating: pwm.c
  inflating: pwm.hp
  inflating: pwm.p
  inflating: pwm
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$

ソースとDIRSとMakefileの修正。

debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ mkdir obj
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ cp ./pwm.c ./pwm.c.backup
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ nano -w pwm.c
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ diff -u ./pwm.c ./pwm.c.backup
--- ./pwm.c     2014-10-21 14:51:49.702172738 +0000
+++ ./pwm.c.backup      2014-10-21 14:50:17.399438352 +0000
@@ -87,7 +87,7 @@

        prussdrv_pru_wait_event(PRU_EVTOUT_0);
        printf("\tINFO: PRU completed transfer.\r\n");
-       prussdrv_pru_clear_event(PRU_EVTOUT_0,PRU0_ARM_INTERRUPT);
+       prussdrv_pru_clear_event(PRU0_ARM_INTERRUPT);

        // Disable PRU and close memory mapping
        prussdrv_pru_disable(PRU_NUM);

debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ cd ..
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps$ nano -w DIRS
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps$ cat DIRS
APP_DIRS :=

APP_DIRS += PRU_memAccess_DDR_PRUsharedRAM
APP_DIRS += PRU_memAccessPRUDataRam
APP_DIRS += PRU_PRUtoPRU_Interrupt
APP_DIRS += led
APP_DIRS += pwm


ASSEM_FILES :=

ASSEM_FILES += PRU_memAccess_DDR_PRUsharedRAM/PRU_memAcc_DDR_sharedRAM.p
ASSEM_FILES += PRU_memAccessPRUDataRam/PRU_memAccessPRUDataRam.p
ASSEM_FILES += PRU_PRUtoPRU_Interrupt/PRU_PRU0toPRU1_Interrupt.p
ASSEM_FILES += PRU_PRUtoPRU_Interrupt/PRU_PRU1toPRU0_Interrupt.p
ASSEM_FILES += led/led.p
ASSEM_FILES += pwm/pwm.p


BIN_FILES :=

BIN_FILES += PRU_memAcc_DDR_sharedRAM.bin
BIN_FILES += PRU_memAccessPRUDataRam.bin
BIN_FILES += PRU_PRU0toPRU1_Interrupt.bin
BIN_FILES += PRU_PRU1toPRU0_Interrupt.bin
BIN_FILES += led.bin
BIN_FILES += pwm.bin

debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps$ cd pwm/
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ cp ../led/Makefile ./
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ nano -w Makefile
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ diff -u ../led/Makefile ./Makefile
--- ../led/Makefile     2014-10-21 13:40:34.881859728 +0000
+++ ./Makefile  2014-10-21 15:13:55.946313521 +0000
@@ -5,14 +5,14 @@
 BINDIR?=../bin

 CFLAGS+= -Wall -I$(INCDIR_APP_LOADER) -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a
-LDFLAGS+=-L$(LIBDIR_APP_LOADER) -lprussdrv -lpthread
+LDFLAGS+=-L$(LIBDIR_APP_LOADER) -lprussdrv -lpthread -lm
 OBJDIR=obj
-TARGET=$(BINDIR)/led
+TARGET=$(BINDIR)/pwm

 _DEPS =
 DEPS = $(patsubst %,$(INCDIR_APP_LOADER)/%,$(_DEPS))

-_OBJ = led.o
+_OBJ = pwm.o
 OBJ = $(patsubst %,$(OBJDIR)/%,$(_OBJ))


debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$

math.hをリンクするためにとりあえずLDFLAGSに-lmを付与している。

makeを実行。

debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm$ cd ..
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps$ make clean
for dir in  PRU_memAccess_DDR_PRUsharedRAM PRU_memAccessPRUDataRam PRU_PRUtoPRU_Interrupt led pwm; do make -C $dir clean LIBDIR_APP_LOADER="../../app_loader/lib" LIBDIR_EDMA_DRIVER="" INCDIR_APP_LOADER="../../app_loader/include" INCDIR_EDMA_DRIVER="" BINDIR="../bin"; done
make[1]: Entering directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_memAccess_DDR_PRUsharedRAM'
rm -rf obj/ *~  ../../app_loader/include/*~  ../bin/PRU_memAcc_DDR_sharedRAM
make[1]: Leaving directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_memAccess_DDR_PRUsharedRAM'
make[1]: Entering directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_memAccessPRUDataRam'
rm -rf obj/ *~  ../../app_loader/include/*~  ../bin/PRU_memAccessPRUDataRam
make[1]: Leaving directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_memAccessPRUDataRam'
make[1]: Entering directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_PRUtoPRU_Interrupt'
rm -rf obj/ *~  ../../app_loader/include/*~  ../bin/PRU_PRUtoPRU_Interrupt
make[1]: Leaving directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_PRUtoPRU_Interrupt'
make[1]: Entering directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/led'
rm -rf obj/ *~  ../../app_loader/include/*~  ../bin/led
make[1]: Leaving directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/led'
make[1]: Entering directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/pwm'
rm -rf obj/ *~  ../../app_loader/include/*~  ../bin/pwm
make[1]: Leaving directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/pwm'
for bin_file in  PRU_memAcc_DDR_sharedRAM.bin PRU_memAccessPRUDataRam.bin PRU_PRU0toPRU1_Interrupt.bin PRU_PRU1toPRU0_Interrupt.bin led.bin pwm.bin; do rm -fr bin/$bin_file; done
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps$ make
mkdir -p bin
for dir in  PRU_memAccess_DDR_PRUsharedRAM PRU_memAccessPRUDataRam PRU_PRUtoPRU_Interrupt led pwm; do make -C $dir CROSS_COMPILE="" LIBDIR_APP_LOADER="../../app_loader/lib" LIBDIR_EDMA_DRIVER="" INCDIR_APP_LOADER="../../app_loader/include" INCDIR_EDMA_DRIVER="" BINDIR="../bin"; done
make[1]: Entering directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_memAccess_DDR_PRUsharedRAM'
gcc -Wall -I../../app_loader/include -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a -c -o obj/PRU_memAcc_DDR_sharedRAM.o PRU_memAcc_DDR_sharedRAM.c
gcc -Wall -I../../app_loader/include -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a -o ../bin/PRU_memAcc_DDR_sharedRAM obj/PRU_memAcc_DDR_sharedRAM.o -L../../app_loader/lib -lprussdrv
make[1]: Leaving directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_memAccess_DDR_PRUsharedRAM'
make[1]: Entering directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_memAccessPRUDataRam'
gcc -Wall -I../../app_loader/include -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a -c -o obj/PRU_memAccessPRUDataRam.o PRU_memAccessPRUDataRam.c
gcc -Wall -I../../app_loader/include -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a -o ../bin/PRU_memAccessPRUDataRam obj/PRU_memAccessPRUDataRam.o -L../../app_loader/lib -lprussdrv
make[1]: Leaving directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_memAccessPRUDataRam'
make[1]: Entering directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_PRUtoPRU_Interrupt'
gcc -I../../app_loader/include -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a -c -o obj/PRU_PRUtoPRU_Interrupt.o PRU_PRUtoPRU_Interrupt.c
gcc -I../../app_loader/include -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a -o ../bin/PRU_PRUtoPRU_Interrupt obj/PRU_PRUtoPRU_Interrupt.o -L../../app_loader/lib -lprussdrv
make[1]: Leaving directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/PRU_PRUtoPRU_Interrupt'
make[1]: Entering directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/led'
gcc -Wall -I../../app_loader/include -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a -c -o obj/led.o led.c
gcc -Wall -I../../app_loader/include -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a -o ../bin/led obj/led.o -L../../app_loader/lib -lprussdrv -lpthread
make[1]: Leaving directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/led'
make[1]: Entering directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/pwm'
gcc -Wall -I../../app_loader/include -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a -c -o obj/pwm.o pwm.c
gcc -Wall -I../../app_loader/include -D__DEBUG -O2 -mtune=cortex-a8 -march=armv7-a -o ../bin/pwm obj/pwm.o -L../../app_loader/lib -lprussdrv -lpthread -lm
make[1]: Leaving directory `/home/debian/pru/am335x_pru_package/pru_sw/example_apps/pwm'
for a_file in  PRU_memAccess_DDR_PRUsharedRAM/PRU_memAcc_DDR_sharedRAM.p PRU_memAccessPRUDataRam/PRU_memAccessPRUDataRam.p PRU_PRUtoPRU_Interrupt/PRU_PRU0toPRU1_Interrupt.p PRU_PRUtoPRU_Interrupt/PRU_PRU1toPRU0_Interrupt.p led/led.p pwm/pwm.p ; \
        do \
          ../utils/pasm_2 -V3 -b $a_file ; \
        done ; \
        mv *.bin bin


PRU Assembler Version 0.86
Copyright (C) 2005-2013 by Texas Instruments Inc.


Pass 2 : 0 Error(s), 0 Warning(s)

Writing Code Image of 16 word(s)



PRU Assembler Version 0.86
Copyright (C) 2005-2013 by Texas Instruments Inc.


Pass 2 : 0 Error(s), 0 Warning(s)

Writing Code Image of 14 word(s)



PRU Assembler Version 0.86
Copyright (C) 2005-2013 by Texas Instruments Inc.


Pass 2 : 0 Error(s), 0 Warning(s)

Writing Code Image of 16 word(s)



PRU Assembler Version 0.86
Copyright (C) 2005-2013 by Texas Instruments Inc.


Pass 2 : 0 Error(s), 0 Warning(s)

Writing Code Image of 14 word(s)



PRU Assembler Version 0.86
Copyright (C) 2005-2013 by Texas Instruments Inc.


Pass 2 : 0 Error(s), 0 Warning(s)

Writing Code Image of 19 word(s)



PRU Assembler Version 0.86
Copyright (C) 2005-2013 by Texas Instruments Inc.


Pass 2 : 0 Error(s), 0 Warning(s)

Writing Code Image of 25 word(s)

pwm.outを生成させる。

debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps$ cd bin/
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/bin$ cp ./pwm.bin ../pwm/obj/
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/bin$ cd ../pwm/obj/
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm/obj$ gcc pwm.o -L../../../app_loader/lib -lprussdrv -lpthread -lm -o pwm.out
debian@beaglebone:~/pru/am335x_pru_package/pru_sw/example_apps/pwm/obj$ sudo ./pwm.out

今度はLEDが明るくなったり暗くなったりを繰り返す。
サンプルの実行は成功。

タイトルとURLをコピーしました