SAM3 programming fails

pi@rpi-keith:~/matrix-creator-hal/demos $ sudo /usr/share/admobilize/matrix-creator/creator-init.bash
XC3SPROG © 2004-2011 xc3sprog project $Rev: 774 $ OS: Linux
Free software: If you contribute nothing, expect nothing!
Feedback on success/failure/enhancement requests:
http://sourceforge.net/mail/?group_id=170565
Check Sourceforge for updates:
http://sourceforge.net/projects/xc3sprog/develop

DNA is 0x19c083e0e588e7fd
**** FPGA programmed!
./radio-init.bash: line 3: echo: write error: Device or resource busy
./radio-init.bash: line 10: echo: write error: Device or resource busy
./radio-init.bash: line 17: echo: write error: Device or resource busy
**** Could not program SAM3 MCU, you must be check the logfile /tmp/sam3-program.log

pi@rpi-keith:~/matrix-creator-hal/demos $ cat /tmp/sam3-program.log
Open On-Chip Debugger 0.10.0-dev-00286-g83b68a2-dirty (2016-08-30-15:18)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
BCM2835 GPIO config: tck = 17, tms = 4, tdi = 22, tdo = 27
BCM2835 GPIO config: trst = 18
trst_only separate trst_push_pull
adapter speed: 512 kHz
Warn : em357.bs: nonstandard IR value
Warn : Specify TAP ‘sam3n.cpu.cpu’ by name, not number 3
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : JTAG only mode enabled (specify swclk and swdio gpio to add SWD mode)
Info : clock speed 512 kHz
Info : JTAG tap: em357.cpu tap/device found: 0x3ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x3)
Info : JTAG tap: em357.bs tap/device found: 0x069aa62b (mfg: 0x315 (Ember Corporation), part: 0x69aa, ver: 0x0)
Info : JTAG tap: xc6sxl4.fpga.fpga tap/device found: 0x24000093 (mfg: 0x049 (Xilinx), part: 0x4000, ver: 0x2)
Info : JTAG tap: sam3n.cpu.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Error: xc6sxl4.fpga.fpga: IR capture error; saw 0x35 not 0x11
Warn : Bypassing JTAG setup events due to errors
Info : sam3n.cpu: hardware has 6 breakpoints, 4 watchpoints
sam3n.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x21000000 pc: 0x00403972 psp: 0x200015e0
#0 : at91sam3 at 0x00400000, size 0x00020000, buswidth 0, chipwidth 0
# 0: 0x00000000 (0x4000 16kB) not protected
# 1: 0x00004000 (0x4000 16kB) not protected
# 2: 0x00008000 (0x4000 16kB) not protected
# 3: 0x0000c000 (0x4000 16kB) not protected
# 4: 0x00010000 (0x4000 16kB) not protected
# 5: 0x00014000 (0x4000 16kB) not protected
# 6: 0x00018000 (0x4000 16kB) not protected
# 7: 0x0001c000 (0x4000 16kB) not protected
flash ‘at91sam3’ found at 0x00400000
Error: Invalid ACK (0) in DAP response
Error: Failed to write memory at 0x00400a00
Error: SAM3: Failed to write (buffer) page at phys address 0x00400900
Error: error writing to flash at address 0x00400000 at offset 0x00000000

Hi @rkeithbeal,

Can you give us more info about your test when you are getting this result?

Following these instructions:

https://matrix-io.github.io/matrix-documentation/Hardware/sam3mcu-programming/

The gpio commands to enable the update seem to be the cause of the failure

No flashing LED after programming
I tried the prebuilt firmware-08 and the version I built.

N flashing LED after programming.

root@rpi-keith:/home/pi/matrix-creator-mcu/firmware-0.8# echo 18 > /sys/class/gpio/export
bash: echo: write error: Device or resource busy

I think the problem cones from here…

I freshened and re-built the mcu ch.block without error

Hi @rkeithbeal,

Did you used sudo with the “echo” commands?

Also wanted to ask you if you already have this folder: cd /usr/share/admobilize/matrix-creator/ . This folder is created when you install MALOS https://matrix-io.github.io/matrix-documentation/MALOS/overview/. Once you install MALOS you will get everithing done after rebbot. By everything I mean:
1.SAM3 progaming
2. FPGA programing
3. MALOS service start

If you haven’t install MALOS yet go ahead , tested and tell us if is working after that.

If you already have MALOS install and you are just trying to program the SAM3 by yourself is better to use this script:
sudo /usr/share/admobilize/matrix-creator/sam3-program.bash

The malos stuff is running in the background.

Is the malos_eye stuff screwing-up the update?

pi@rpi-keith:~ $ malos


MALOS starting


You can query specific driver info using port 20012.
terminate called after throwing an instance of 'zmq::error_t’
what(): Address already in use
Aborted
pi@rpi-keith:~ $ ps -ealf | grep malos
4 S root 471 1 7 80 0 - 316640 - 09:34 ? 00:08:06 /usr/bin/malos
4 S root 473 1 0 80 0 - 31293 - 09:34 ? 00:00:01 /usr/bin/malos_eye
0 S pi 27776 24308 0 80 0 - 1070 pipe_w 11:26 pts/2 00:00:00 grep --color=auto malos

If you want to re-program the SAM3 or the FPGA is better to stop MALOS first.
$ sudo pkill malos

I did the pkill ans it makes no difference

It seems pretty clear it is a gpio access issue

pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ sudo echo 18 > /sys/class/gpio/export
echo: write error: Device or resource busy

Here is the transcript of the entire session:

pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ sudo pkill malos
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ cd ~/matrix-creator-mcu
pi@rpi-keith:~/matrix-creator-mcu $ cd firmware-0.8/
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ echo 18 > /sys/class/gpio/export
-bash: echo: write error: Device or resource busy
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ echo out > /sys/class/gpio/gpio18/direction
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ echo 1 > /sys/class/gpio/gpio18/value
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ echo 0 > /sys/class/gpio/gpio18/value
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ echo 1 > /sys/class/gpio/gpio18/value
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ sudo openocd -f cfg/sam3s.cfg
Open On-Chip Debugger 0.10.0-dev-00286-g83b68a2-dirty (2016-08-30-15:18)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
BCM2835 GPIO config: tck = 17, tms = 4, tdi = 22, tdo = 27
BCM2835 GPIO config: trst = 18
trst_only separate trst_push_pull
adapter speed: 512 kHz
Warn : em357.bs: nonstandard IR value
Warn : Specify TAP ‘sam3n.cpu.cpu’ by name, not number 3
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : JTAG only mode enabled (specify swclk and swdio gpio to add SWD mode)
Info : clock speed 512 kHz
Info : JTAG tap: em357.cpu tap/device found: 0x3ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x3)
Info : JTAG tap: em357.bs tap/device found: 0x069aa62b (mfg: 0x315 (Ember Corporation), part: 0x69aa, ver: 0x0)
Info : JTAG tap: xc6sxl4.fpga.fpga tap/device found: 0x24000093 (mfg: 0x049 (Xilinx), part: 0x4000, ver: 0x2)
Info : JTAG tap: sam3n.cpu.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Error: xc6sxl4.fpga.fpga: IR capture error; saw 0x35 not 0x11
Warn : Bypassing JTAG setup events due to errors
Info : sam3n.cpu: hardware has 6 breakpoints, 4 watchpoints
Error: sam3n.cpu – clearing lockup after double fault
Polling target sam3n.cpu failed, trying to reexamine
Info : sam3n.cpu: hardware has 6 breakpoints, 4 watchpoints
#0 : at91sam3 at 0x00400000, size 0x00020000, buswidth 0, chipwidth 0
# 0: 0x00000000 (0x4000 16kB) not protected
# 1: 0x00004000 (0x4000 16kB) not protected
# 2: 0x00008000 (0x4000 16kB) not protected
# 3: 0x0000c000 (0x4000 16kB) not protected
# 4: 0x00010000 (0x4000 16kB) not protected
# 5: 0x00014000 (0x4000 16kB) not protected
# 6: 0x00018000 (0x4000 16kB) not protected
# 7: 0x0001c000 (0x4000 16kB) not protected
flash ‘at91sam3’ found at 0x00400000
Error: Invalid ACK (0) in DAP response
Error: Failed to read memory at 0x400e0a0c
Error: SAM3: Error performing Erase & Write page @ phys address 0x00402a00
wrote 35220 bytes from file blob/ch.bin to flash bank 0 at offset 0x00000000 in 1.186224s (28.995 KiB/s)
Info : JTAG tap: em357.cpu tap/device found: 0x3ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x3)
Info : JTAG tap: em357.bs tap/device found: 0x069aa62b (mfg: 0x315 (Ember Corporation), part: 0x69aa, ver: 0x0)
Info : JTAG tap: xc6sxl4.fpga.fpga tap/device found: 0x24000093 (mfg: 0x049 (Xilinx), part: 0x4000, ver: 0x2)
Info : JTAG tap: sam3n.cpu.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Error: xc6sxl4.fpga.fpga: IR capture error; saw 0x35 not 0x11
Warn : Bypassing JTAG setup events due to errors
Warn : Only resetting the Cortex-M core, use a reset-init event handler to reset any peripherals or configure hardware srst support.
shutdown command invoked

The LED does not start flashing and the sensors all read o

I removed the stderr redirection in the call to

#super_reset 2>/dev/null
super_reset
in /usr/share/admobilize/matrix-creator/sam3-program.bash

It is pretty clear there is a problem writing to /sys/class/gpio/export

sudo /usr/share/admobilize/matrix-creator/sam3-program.bash
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 8: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 12: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 16: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 17: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 22: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 26: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 30: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 34: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 35: /sys/class/gpio/gpio4/direction: No such file or directory
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 38: echo: write error: Device or resource busy
**** Could not program SAM3 MCU, you must be check the logfile /tmp/sam3-program.log

Hi @rkeithbeal,

We are following this. we need yoou to run this commands to give us more information about what’s happening.

$ cat /etc/os-release
$ sudo xc3sprog -c matrix_pi
& sudo /usr/share/admobilize/matrix-creator/sam3-program.bash

Please send us all the outputs and after that disconnect everything from power and connect everything back again and test if the MCU is working (if you get values from de sensors).

Yoel

The problem is pretty clear - somehting to do with the gpio.

pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ sudo xc3sprog -c matrix_pi
XC3SPROG © 2004-2011 xc3sprog project $Rev: 774 $ OS: Linux
Free software: If you contribute nothing, expect nothing!
Feedback on success/failure/enhancement requests:
http://sourceforge.net/mail/?group_id=170565
Check Sourceforge for updates:
http://sourceforge.net/projects/xc3sprog/develop

JTAG loc.: 0 IDCODE: 0x4ba00477 Desc: ARM_Cortex-M3_r1p1-01rel0 Rev: E IR length: 4
JTAG loc.: 1 IDCODE: 0x24000093 Desc: XC6SLX4 Rev: C IR length: 6
JTAG loc.: 2 IDCODE: 0x069aa62b Desc: EM358 Rev: A IR length: 4
JTAG loc.: 3 IDCODE: 0x3ba00477 Desc: ARM_Cortex-M3_r1p1-01rel0 Rev: C IR length: 4
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ sudo /usr/share/admobilize/matrix-creator/sam3-program.bash
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 8: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 12: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 16: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 17: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 22: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 26: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 30: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 34: echo: write error: Device or resource busy
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 35: /sys/class/gpio/gpio4/direction: No such file or directory
/usr/share/admobilize/matrix-creator/sam3-program.bash: line 38: echo: write error: Device or resource busy
**** Could not program SAM3 MCU, you must be check the logfile /tmp/sam3-program.log
pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $

NOTE: The error messages WERE suppressed by an IO redirection of sterrr to null.
In my previous message I indicated this.

The super_reset function in the script is failing because it cannot write to
/sys/class/gpio/export
It complains of a device error on echo: write error!

Were the commands you had me type to diagnose why the GPIO isn’t writable?
I don’t see how they help with the diagnosis.

I have 2 of Matrix Creator boards and it is the same with both and with 2 different RPis

What do you get when you run those commands?

Her is the log…

pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ cat /tmp/sam3-program.log
Open On-Chip Debugger 0.10.0-dev-00286-g83b68a2-dirty (2016-08-30-15:18)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
BCM2835 GPIO config: tck = 17, tms = 4, tdi = 22, tdo = 27
BCM2835 GPIO config: trst = 18
trst_only separate trst_push_pull
adapter speed: 512 kHz
Warn : em357.bs: nonstandard IR value
Warn : Specify TAP ‘sam3n.cpu.cpu’ by name, not number 3
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : JTAG only mode enabled (specify swclk and swdio gpio to add SWD mode)
Info : clock speed 512 kHz
Info : JTAG tap: em357.cpu tap/device found: 0x3ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x3)
Info : JTAG tap: em357.bs tap/device found: 0x069aa62b (mfg: 0x315 (Ember Corporation), part: 0x69aa, ver: 0x0)
Info : JTAG tap: xc6sxl4.fpga.fpga tap/device found: 0x24000093 (mfg: 0x049 (Xilinx), part: 0x4000, ver: 0x2)
Info : JTAG tap: sam3n.cpu.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Error: xc6sxl4.fpga.fpga: IR capture error; saw 0x35 not 0x11
Warn : Bypassing JTAG setup events due to errors
Info : sam3n.cpu: hardware has 6 breakpoints, 4 watchpoints
sam3n.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x21000000 pc: 0x00403990 psp: 0x200015e0
#0 : at91sam3 at 0x00400000, size 0x00020000, buswidth 0, chipwidth 0
# 0: 0x00000000 (0x4000 16kB) not protected
# 1: 0x00004000 (0x4000 16kB) not protected
# 2: 0x00008000 (0x4000 16kB) not protected
# 3: 0x0000c000 (0x4000 16kB) not protected
# 4: 0x00010000 (0x4000 16kB) not protected
# 5: 0x00014000 (0x4000 16kB) not protected
# 6: 0x00018000 (0x4000 16kB) not protected
# 7: 0x0001c000 (0x4000 16kB) not protected
flash ‘at91sam3’ found at 0x00400000
wrote 35220 bytes from file blob/ch.bin to flash bank 0 at offset 0x00000000 in 1.943551s (17.697 KiB/s)
Info : JTAG tap: em357.cpu tap/device found: 0x3ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x3)
Info : JTAG tap: em357.bs tap/device found: 0x069aa62b (mfg: 0x315 (Ember Corporation), part: 0x69aa, ver: 0x0)
Info : JTAG tap: xc6sxl4.fpga.fpga tap/device found: 0x24000093 (mfg: 0x049 (Xilinx), part: 0x4000, ver: 0x2)
Info : JTAG tap: sam3n.cpu.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Error: xc6sxl4.fpga.fpga: IR capture error; saw 0x35 not 0x11
Warn : Bypassing JTAG setup events due to errors
Warn : Only resetting the Cortex-M core, use a reset-init event handler to reset any peripherals or configure hardware srst support.
shutdown command invoked

Do you get different results from echo 18 > /sys/class/gpio/export?

pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ echo 18 > /sys/class/gpio/export
-bash: echo: write error: Device or resource busy

https://www.kernel.org/doc/Documentation/gpio/sysfs.txt

The documentation for “gpiolib” says

The control interfaces are write-only:

/sys/class/gpio/

	"export" ... Userspace may ask the kernel to export control of
	a GPIO to userspace by writing its number to this file.

	Example:  "echo 19 > export" will create a "gpio19" node
	for GPIO #19, if that's not requested by kernel code.

Is this normal?

pi@rpi-keith:~/matrix-creator-mcu/firmware-0.8 $ ls -l /sys/class/gpio
total 0
-rwxrwx— 1 root gpio 4096 Nov 25 18:56 export
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio13 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio13
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio17 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio17
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio18 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio18
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio19 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio19
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio20 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio20
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio21 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio21
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio22 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio22
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio23 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio23
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio27 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio27
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio5 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio5
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpio6 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpio6
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpiochip0 -> …/…/devices/platform/soc/3f200000.gpio/gpio/gpiochip0
lrwxrwxrwx 1 root gpio 0 Nov 22 12:16 gpiochip100 -> …/…/devices/platform/soc/soc:virtgpio/gpio/gpiochip100
-rwxrwx— 1 root gpio 4096 Nov 22 12:16 unexport

I had the exact same issue when running sudo /usr/share/admobilize/matrix-creator/sam3-program.bash with the same results in /tmp/sam3-program.log.

Here is what I did to get it to work

sudo apt-get remove matrix-creator-init matrix-creator-malos matrix-creator-openocd

shutdown the Pi

Removed the Matrix hardware from the Pi and powered back up.

ran sudo apt-get install matrix-creator-init

After install I shutdown the Pi and plugged the Matrix back onto the Pi. Started backup and ran sudo /usr/share/admobilize/matrix-creator/sam3-program.bash and it worked. After re-installing matrix-creator-malos and matrix-creator-openocd the I now have full access to the sensor’s. Hope this helps.