segmentation fault PRU

Hello! I’m trying to use PRU for PWM with am335x_pru_package ( https://github.com/beagleboard/am335x_pru_package ). I use code from a book Derek Molloy (Listing 13.6, page 525; if you need code i can send that). Built goes fine - 0 errors, but when i execute, i have error “Segmentation fault”. I don’t know, where is problem… Maybe who faced this problem?
My sudo /opt/scripts/tools/version.sh
git:/opt/scripts/:[1aa73453b2c980b75e31e83dab7dd8b6696f10c7]
eeprom:[A335BNLT00C04619BBBK08BF]
model:[TI_AM335x_BeagleBone_Black]
dogtag:[BeagleBoard.org Debian Image 2018-10-07]
bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot 2018.09-00002-g0b54a51eee]:[location: dd MBR]
kernel:[4.14.71-ti-r80]
nodejs:[v6.14.4]
uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-14-TI-00A0.dtbo]
uboot_overlay_options:[enable_uboot_cape_universal=1]
pkg check: to individually upgrade run: [sudo apt install --only-upgrade ]
pkg:[bb-cape-overlays]:[4.4.20180928.0-0rcnee0~stretch+20180928]
pkg:[bb-wl18xx-firmware]:[1.20180517-0rcnee0~stretch+20180517]
pkg:[kmod]:[23-2rcnee1~stretch+20171005]
pkg:[librobotcontrol]:[1.0.3-git20181005.0-0rcnee0~stretch+20181005]
pkg:[firmware-ti-connectivity]:[20170823-1rcnee1~stretch+20180328]
groups:[debian : debian adm kmem dialout cdrom floppy audio dip video plugdev users systemd-journal i2c bluetooth netdev cloud9ide gpio pwm eqep admin spi tisdk weston-launch xenomai]
cmdline:[console=ttyO0,115200n8 bone_capemgr.uboot_capemgr_enabled=1 root=/dev/mmcblk1p1 ro rootfstype=ext4 rootwait coherent_pool=1M net.ifnames=0 quiet]
dmesg | grep pinctrl-single
[ 1.119780] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size 568
dmesg | grep gpio-of-helper
[ 1.131811] gpio-of-helper ocp:cape-universal: ready

END

Hello! I'm trying to use PRU for PWM with am335x_pru_package
( GitHub - beagleboard/am335x_pru_package ). I use code from a
book Derek Molloy (Listing 13.6, page 525; if you need code i can send

  Which edition of the book? Probably first edition since page 525 in my
2nd edition has a figure 11-11 about GMail Security Settings. The PRU is
covered in chapter 15, starting at page 673.

dogtag:[BeagleBoard.org Debian Image 2018-10-07]

  That's a somewhat old image...

bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot
2018.09-00002-g0b54a51eee]:[location: dd MBR]
kernel:[4.14.71-ti-r80]
nodejs:[v6.14.4]

dogtag:[BeagleBoard.org Debian Image 2019-08-03]
bootloader:[microSD-(push-button)]:[/dev/mmcblk0]:[U-Boot
2019.04-00002-gbb4af0f50f]:[location: dd MBR]
bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot
2019.04-00002-gbb4af0f50f]:[location: dd MBR]
kernel:[4.14.108-ti-r113]
nodejs:[v6.17.0]

(Note: booting from SD card)

uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-14-TI-00A0.dtbo]
uboot_overlay_options:[enable_uboot_cape_universal=1]
pkg check: to individually upgrade run: [sudo apt install --only-upgrade
<pkg>]
pkg:[bb-cape-overlays]:[4.4.20180928.0-0rcnee0~stretch+20180928]
pkg:[bb-wl18xx-firmware]:[1.20180517-0rcnee0~stretch+20180517]
pkg:[kmod]:[23-2rcnee1~stretch+20171005]
pkg:[librobotcontrol]:[1.0.3-git20181005.0-0rcnee0~stretch+20181005]
pkg:[firmware-ti-connectivity]:[20170823-1rcnee1~stretch+20180328]
groups:[debian : debian adm kmem dialout cdrom floppy audio dip video
plugdev users systemd-journal i2c bluetooth netdev cloud9ide gpio pwm eqep
admin spi tisdk weston-launch xenomai]
cmdline:[console=ttyO0,115200n8 bone_capemgr.uboot_capemgr_enabled=1
root=/dev/mmcblk1p1 ro rootfstype=ext4 rootwait coherent_pool=1M
net.ifnames=0 quiet]
dmesg | grep pinctrl-single
[ 1.119780] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size
568
dmesg | grep gpio-of-helper
[ 1.131811] gpio-of-helper ocp:cape-universal: ready

END

  Might be significant that nothing lists the PRUs in that... Compare...

cmdline:[console=ttyO0,115200n8 bone_capemgr.uboot_capemgr_enabled=1
root=/dev/mmcblk0p1 ro rootfstype=ext4 rootwait coherent_pool=1M
net.ifnames=0 rng_core.default_quality=100 quiet]
dmesg | grep remote
[ 1.306197] remoteproc remoteproc0: wkup_m3 is available
[ 1.394863] remoteproc remoteproc0: powering up wkup_m3
[ 1.394979] remoteproc remoteproc0: Booting fw image
am335x-pm-firmware.elf, size 217168
[ 1.399441] remoteproc remoteproc0: remote processor wkup_m3 is now up
[ 25.652003] remoteproc remoteproc1: 4a334000.pru is available
[ 25.659497] remoteproc remoteproc2: 4a338000.pru is available
dmesg | grep pru
[ 25.622919] pruss 4a300000.pruss: creating PRU cores and other child
platform devices
[ 25.652003] remoteproc remoteproc1: 4a334000.pru is available
[ 25.652130] pru-rproc 4a334000.pru: PRU rproc node
/ocp/pruss_soc_bus@4a326004/pruss@0/pru@34000 probed successfully
[ 25.659497] remoteproc remoteproc2: 4a338000.pru is available
[ 25.659623] pru-rproc 4a338000.pru: PRU rproc node
/ocp/pruss_soc_bus@4a326004/pruss@0/pru@38000 probed successfully
dmesg | grep pinctrl-single
[ 0.949560] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size
568
dmesg | grep gpio-of-helper
[ 0.962136] gpio-of-helper ocp:cape-universal: ready
lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
END

NOTE: I've never used the PRUs (I really need to go through the Molloy
books [BBB and R-Pi]), so don't have any idea what dummy process is running
on the PRUs above. Secondary note: not shown but I appear to have also
turned off the HDMI or that is inherent in the IoT image.

o/~ Talking to myself in public o/~

Which edition of the book? Probably first edition since page 525 in my
2nd edition has a figure 11-11 about GMail Security Settings. The PRU is
covered in chapter 15, starting at page 673.

  Note that first edition has a copyright in 2015. That is Debian 7.x
timeframe -- AKA Wheezy while...

dogtag:[BeagleBoard.org Debian Image 2018-10-07]

That's a somewhat old image...

... that is Debian 9.5 -- AKA Stretch.

  There have been a number of significant changes since the first edition
book came out.

  Debian is phasing out sys-v init for systemd

  UIO PRU access phased out for remoteproc by default. Refer to
http://catch22.eu/beaglebone/beaglebone-pru-uio/ for candidate instructions
on enabling UIO (though those instructions are based upon ONE Debian 8.x --
Jessie image -- Implication is that images newer than 8.6 only function
with remoteproc unless one changes the OS kernel). Similar instructions at
GitHub - sbarral/prusst: A convenient interface to the UIO kernel module for TI Programmable Real-time Units

  Consider
https://www.element14.com/community/community/designcenter/single-board-computers/next-genbeaglebone/blog/2019/05/14/coding-for-the-beaglebone-pru-with-c-in-2019
which is based on Debian 9.5 -- using remoteproc, or
http://ianrrees.github.io/2016/11/20/getting-started-with-beaglebone-pru-programming-the-new-way.html

  OTOH, it may be something as simple as needing to run using sudo (as
mentioned about halfway down http://exploringbeaglebone.com/chapter15/ [a
lot of the commentary on that page applies to first edition based upon the
date stamps -- a big jump from June 2016 to March 2019 when the 2nd edition
came out])

Thanks! I will definitely study your links

Hi!


i am using pocket beagle board, am335x & i want to read data from DDR but SEGMENTATION FAULT arises. can anyone would help?

Many times that is a pointer related issue.

Make sure your pointers are declared and initialized properly.

If the program is short and you don’t have a debugger just insert some printf(“function 1 just executed”) in your code before and after using pointers. Arrays can be problematic too, your last printf will be just before the you go out of bounds so name the output appropriately.

Have you tested your compiler with a simple printf(“it works”); ?

Also, pretty sure you need the correct device tree overlay active when using the PRU.