chipKIT uC32 with Dragino YUN shield

ltheoret
Posts: 50
Joined: Wed Dec 23, 2015 9:19 pm

Re: chipKIT uC32 with Dragino YUN shield

Post by ltheoret » Fri Feb 26, 2016 7:55 pm

Hi,
I have some bad news. This mod fails 100% of the time on the uC32.
On the wf32 it works 100% of the time if I upload Blink. but if I upload a bridge software then try to upload blink again it fails until I reset the HU. and I only send a signal on the bridge every 5 second.
Still work 100% of the time with my infiduino set to 3.3V but that uses the SPI buss not the UART.

There must be a software conflict in there to.
Did not damage the UART as the database is still being updated with the WF32 and it also updates with the uC32 (not the one I tampered with).

OK. I re-programed by USB my uC32 with blink now I cam program it till I'm blue in the face (with Blin) but if I use the bridge I'm hooped.
Yes it's not only my database software it's also a web based temperature demo.

Luc

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: chipKIT uC32 with Dragino YUN shield

Post by majenko » Sun Feb 28, 2016 1:19 pm

I have just found that I don't need to bundle the ftdi and cdc/acm drivers, they are already there:

Code: Select all

# opkg update
...
# opkg install kmod-usb-serial-ftdi
# opkg install kmod-usb-acm
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: chipKIT uC32 with Dragino YUN shield

Post by majenko » Thu Mar 03, 2016 4:21 pm

Ok, I am gradually getting to the bottom of this now.

It's not easy. The problem is the serial console login that is used by bridge.

Disabling it and reenabling it doesn't seem to be possible. To disable it you need to:

1. Comment out the line in /etc/inittab
2. Killall -HUP init
3. Kill the bridge python process
4. Kill any ash processes running on serial

Then you can upload code reliably.

But you then cannot use bridge. At all. Uncommenting the line in /etc/inittab and HUPing init has no effect. The only way to get bridge working again is to reboot the dragino.

Sucks.

Sent from my SM-T555 using Tapatalk
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

ltheoret
Posts: 50
Joined: Wed Dec 23, 2015 9:19 pm

Re: chipKIT uC32 with Dragino YUN shield

Post by ltheoret » Fri Mar 04, 2016 5:50 am

I found on the Arduino.cc website:
https://www.arduino.cc/en/Tutorial/YunSerialTerminal
a little peace of code that is supposed to disable the bridge from the from the Arduino side. I don't know if it disables it on the OpenWRT side.

Luc

ltheoret
Posts: 50
Joined: Wed Dec 23, 2015 9:19 pm

Re: chipKIT uC32 with Dragino YUN shield

Post by ltheoret » Fri Mar 04, 2016 5:58 am

Hi,

the line from the link above is

Code: Select all

SERIAL_PORT_HARDWARE.write((uint8_t *)"\xff\0\0\x05XXXXX\x7f\xf9", 11); // send "bridge shutdown" command
sent via serial port

Luc

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: chipKIT uC32 with Dragino YUN shield

Post by majenko » Fri Mar 04, 2016 11:56 am

That would just exit the bridge server, it won't affect the fact that init is listening on the serial port and intercepting the data.

I think I am going to have to delve into the source code of busybox to see what is going on.

Sent from my SM-T555 using Tapatalk
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: chipKIT uC32 with Dragino YUN shield

Post by majenko » Fri Mar 04, 2016 5:58 pm

Wow... ok, so I think I may have it!

After much use of `strace` and `pstree` and similar tools I have it nailed. I *think* I now know exactly what happens.

It's a comedy of errors...

Ok... first off when you disable the inittab entry and HUP init it *doesn't kill the redundant processes*. Those have to be done manually - and not just the python process, but the /bin/ash process as well. And they have to be killed with extreme prejudice.

Then you can use pic32prog to program the target, which is nice.

Then the next tricky part is getting things running again... Here's where the comedy begins:

When you re-enable the inittab entry and HUP init it starts the UART up at the wrong baud rate!!! Yep, it configures it for 115200 baud instead of 230400 baud (which actually seems to be 250000 baud). And no, it's not pic32prog leaving it at that rate. If you change the rate to 230400 before HUPing init it resets it back to 115200 baud. So you have to change the baud rate AFTER HUPing init.

But that's not the worst of it...

If the bridge is running on the target then init has an absolute eppy fit and /bin/ash keeps crashing and looping.
Mar 4 16:13:15 init: process '/bin/ash --login' (pid 11427) exited. Scheduling for restart.
So you need to make sure that the UART's level shifter is set to disable the UART access before HUPing init and setting the baud rate, and waiting long enough for init to have finished cloning itself before then re-enabling the UART so that the bridge can start communicating!

What a laugh, eh?

So now my run-pic32prog script looks like this:

Code: Select all

#!/bin/sh

# First we need to disable the login:
sed -e '/ttyATH0/ s/^#*/#/' -i /etc/inittab
killall -HUP init
PYTHON_PID=`ps | grep python | grep bridge.py | awk '{print $1}'`
ASH_PID=`grep PPid: /proc/${PYTHON_PID}/status | awk '{print $2}'`

# Kill python
kill -9 ${PYTHON_PID}
# Kill ash
kill -9 ${ASH_PID}

# We need to save the current state of the UART connection
UART_SET=`cat /sys/class/gpio/gpio24/value`
# and enable the UART if needed
echo 1 > /sys/class/gpio/gpio24/value

sleep 1
# Now reset the MCU and run pic32prog
reset-mcu
pic32prog -d /dev/ttyATH0 -S $*

# Disable the UART so that init can re-enable the TTY properly
echo 0 > /sys/class/gpio/gpio24/value

# And finally return the login
sed -e '/ttyATH0/ s/^#*//' -i /etc/inittab
killall -HUP init
sleep 1
stty -F /dev/ttyATH0 ispeed 230400 ospeed 230400

# Put the UART setting back to what it was:
echo ${UART_SET} > /sys/class/gpio/gpio24/value
I'll look at releasing a new pic32prog package with it in.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: chipKIT uC32 with Dragino YUN shield

Post by majenko » Fri Mar 04, 2016 11:38 pm

Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: chipKIT uC32 with Dragino YUN shield

Post by majenko » Fri Mar 04, 2016 11:45 pm

Oh, one other thing... I have it working perfectly on a Wi-Fire. There's a small modification you need to make though - and this probably applies to other chipKIT boards as well.

You need to disconnect the SS pin on the ISP header. On the Wi-Fire there's a jumper with a hard-wired link that you need to cut. It's JP5 and the link is on the underside. An xacto or something similar (I actually used my needle tweezers) can break that track between the pads. If you should ever need to undo it it's simple enough by soldering a link between the pads of the jumper (that's what it's there for).
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

ltheoret
Posts: 50
Joined: Wed Dec 23, 2015 9:19 pm

Re: chipKIT uC32 with Dragino YUN shield

Post by ltheoret » Sat Mar 05, 2016 7:12 pm

Hi,
just itching to try this new fix.
Well it works with my uC32. Can I remove those 2 wires that bypass the level shifters.

Luc

Post Reply