COM1 Starts Spewing CPU register values

Anyone know how or why my serial port COM1 all of a sudden becomes some type of debug port and starts spewing out cpu register data like:

EXCEPTION 0x06:
cpsr=0x00010010
pc =0xa0486ff8
lr =0xa0486fec
sp =0x10004a70
r00 =0x10004a28
r01 =0x00000000
r02 =0x00000001
r03 =0x00001000
r04 =0xa09f623c
r05 =0xa0486fec
r06 =0xa0486ff8
r07 =0x00010010
r08 =0xa09ffdc4
r09 =0xa0024f98
r10 =0x00000000
r11 =0x00000000
r12 =0xa09f623c

This is a system crash report. What version are you running, on what device, and how can we reproduce this error? Any info would help us in nailing this down.

Ah…thanks Gus!

Tiny Booter 4.3.4.0
Tinyclr 4.3.6.0

Cobra II eco with serial port module hooked to socket 5.

Connect serial cable between module and computer serial port. Run TeraTerm or other on PC. Run the following code:

namespace MFConsoleApplication1 {
public class Program {
private static System.IO.Ports.SerialPort _modemSerialPort = null;
private static byte[] _writeBuf = null;
private static byte[] _readBuf = new byte[256];

    public static void Main() {
        try {
            _modemSerialPort = new System.IO.Ports.SerialPort("COM1", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
            _modemSerialPort.ReadTimeout = 5000;
            _modemSerialPort.Open();

            Microsoft.SPOT.Debug.Print(_modemSerialPort.PortName);
            int cnt = -1;

            while (true) {
                if (_modemSerialPort.IsOpen) {
                    try {
                        _writeBuf = System.Text.Encoding.UTF8.GetBytes("Hello " + cnt.ToString() + "\r");
                        _modemSerialPort.Write(_writeBuf, 0, _writeBuf.Length);
                    } catch (Exception ey) {
                        Microsoft.SPOT.Debug.Print(ey.ToString()); //<-- Exception caught here
                        break;
                    }
                }
                cnt++;
            }
        } catch (Exception ez) {
            Microsoft.SPOT.Debug.Print(ez.ToString());
        }
    }
}

}

Output of Microsoft.SPOT.Debug.Print(ey.ToString());

Exception System.Exception - CLR_E_WRONG_TYPE (1)

#### Message: 
#### System.Text.UTF8Encoding::.ctor [IP: 0004] ####
#### System.Text.Encoding::get_UTF8 [IP: 0003] ####
#### MFConsoleApplication1.Program::Main [IP: 0047] ####

A first chance exception of type ‘System.Exception’ occurred in mscorlib.dll

Output of Stack Trace when inspecting Exception in Quick Watch

System.Text.UTF8Encoding::.ctor
System.Text.Encoding::get_UTF8
MFConsoleApplication1.Program::Main

andre.m,

Yes, it is part of the original post. The original post asked too many questions at once so I cut it down and set the subject to one element of the post that I am having a problem with.

Code tags?

Ah…Me no see at first the editing buttons, not sure if I did it correctly, but heres the code again.

using System;
using Microsoft.SPOT;

namespace MFConsoleApplication1 {
    public class Program {
        private static System.IO.Ports.SerialPort _modemSerialPort = null;
        private static byte[] _writeBuf = null;
        private static byte[] _readBuf = new byte[256];

        public static void Main() {
            try {
                _modemSerialPort = new System.IO.Ports.SerialPort("COM1", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
                _modemSerialPort.ReadTimeout = 5000;
                _modemSerialPort.Open();

                Microsoft.SPOT.Debug.Print(_modemSerialPort.PortName);
                int cnt = -1;

                while (true) {
                    if (_modemSerialPort.IsOpen) {
                        try {
                            _writeBuf = System.Text.Encoding.UTF8.GetBytes("Hello " + cnt.ToString() + "\r");
                            _modemSerialPort.Write(_writeBuf, 0, _writeBuf.Length);
                        } catch (Exception ey) {
                            Microsoft.SPOT.Debug.Print(ey.ToString()); //<-- Exception caught here
                            break;
                        }
                    }
                    cnt++;
                }
            } catch (Exception ez) {
                Microsoft.SPOT.Debug.Print(ez.ToString());
            }
        }
    }
}

@ mhardy - Do you see anything suspicious in the output window prior to the exception information. During the deployment/loading stage?

I have tried the piece of code that throws the exception and it worked for me without any problem…

Architect -

Once I saw the GC stuff shown below…it might be related, but I only saw it once out of maybe 30 runs. Usually the last I see in the output is COM1, which my debug.print statement outputs. Essentially the device just locks up… in lala land.

Right know the device is hung up but no crash info is being spewed over the serial port.
The crash info spewing is random to. Sometimes it happens, sometimes it does not.

Also, even though i have breakpoints set in the exception handlers, only once in awhile do they get hit.

The thing that is constant is that the device locks up.

GC: 1msec 286560 bytes used, 7053108 bytes available

Type 0F (STRING ): 24 bytes

Type 15 (FREEBLOCK ): 7053108 bytes

Type 17 (ASSEMBLY ): 21528 bytes

Type 1E (BINARY_BLOB_HEAD ): 264936 bytes

Type 34 (APPDOMAIN_HEAD ): 72 bytes

GC: performing heap compaction…

For reference here’s the exception information:
Output of Microsoft.SPOT.Debug.Print(ey.ToString());

Exception System.Exception - CLR_E_WRONG_TYPE (1)

#### Message: 
#### System.Text.UTF8Encoding::.ctor [IP: 0004] ####
#### System.Text.Encoding::get_UTF8 [IP: 0003] ####
#### MFConsoleApplication1.Program::Main [IP: 0047] ####

A first chance exception of type ‘System.Exception’ occurred in mscorlib.dll

Output of Stack Trace when inspecting Exception in Quick Watch

System.Text.UTF8Encoding::.ctor
System.Text.Encoding::get_UTF8
MFConsoleApplication1.Program::Main

@ mhardy - I would also add a sleep to your while loop. Similar to how it is done in the documentation.

https://www.ghielectronics.com/docs/15/uart-serial

Architect,

I added it in and will let it run…have meeting right now.
Still very unnerving that such work around’s are needed.

It should work with no thread.sleep(100),
would you not agree?

Architect,

I put the System.Threading.Thread.Sleep(100) in the code and still get the same error, exception, crash report, etc. Code is below:

using System;
using Microsoft.SPOT;

namespace MFConsoleApplication1 {
    public class Program {
        private static System.IO.Ports.SerialPort _modemSerialPort = null;
        private static byte[] _writeBuf = null;
        private static byte[] _readBuf = new byte[256];
        

        public static void Main() {
            string str = "";
            try {
                _modemSerialPort = new System.IO.Ports.SerialPort("COM1", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
                _modemSerialPort.ReadTimeout = 5000;
                _modemSerialPort.Open();

                Microsoft.SPOT.Debug.Print(_modemSerialPort.PortName);
                int cnt = -1;

                while (true) {
                    if (_modemSerialPort.IsOpen) {
                        try {
                            try {
                                str = "Hello " + cnt.ToString() + "\r";
                                if (null == str) {
                                    str = "Hello              ";
                                        cnt = 0;
                                }
                                _writeBuf = System.Text.Encoding.UTF8.GetBytes(str);
                            } catch (Exception ez) {
                                Microsoft.SPOT.Debug.Print(ez.ToString());
                                break;
                            }
                            _modemSerialPort.Write(_writeBuf, 0, _writeBuf.Length);
                        } catch (Exception ey) {
                            Microsoft.SPOT.Debug.Print(ey.ToString());
                            break;
                        }
                    }
                    System.Threading.Thread.Sleep(100);
                    cnt++;
                }
            } catch (Exception ez) {
                Microsoft.SPOT.Debug.Print(ez.ToString());
            }
        }
    }
}

Currently I am not reading from the serial port. I removed that part of the code to narrow down what the problem is.

The serial port is just spitting out data to TeraTerm.

The code example is just a small part of an entire program we are trying to move from the netDuino plus 2 platform to the G120.

Everything ran great on the netDuino (netMF 4.2). We decided to move to the G120 mainly because of IFU capabilities.

I am getting frightened that one of the simplest thing’s our code does (talk over a serial port) is fraught with this problem.

@ mhardy - Try a different G120 unit or Cobra II board, if available. I ran into inexplicable TinyCLR crashes like this on a few of my production G120 boards, which I [em]believe[/em] (but haven’t confirmed) is a result of the modules possibly being overbaked at my assembly house. I didn’t have time to troubleshoot further and left it at that.

Iggmoe…thanks.

I was starting to think along the same lines because I noticed that if you need to erase a runaway program it’s a crap shoot being able to get the TinyCLR in the right state to not load the user program by pushing LDR1 & Reset, releasing Reset then releasing LDR1. It took me probably 5 times to get TinyCLR in the right state?

GHI, do you have any info on this possible reason for the problems I am seeing?
I would be happy to the send the board to you to investigate.
In the mean time I will order a new Cobra II eco and see what happens…

@ mhardy - I doubt the board is defected. How are you powering the board?

Powering via USB.
Yes, that was another thought of mine.
Can I have the USB port connected and also apply power via the power jack?
If I can what is the voltage I should apply from a power source, i.e. wallwart?

I am using the USB (micro) client port.
It’s the port that connects to the cable that ships with the Cobra II eco, you debug over it.

I will get a 6V (1000 mA or greater) Wallwart from RadioShack tomorrow and give it a whirl!

All,

I purchased a 6V supply, connected it to the power jack w/usb debug connected.
It did not work.
The port starts spewing crash data after ~30sec.

I also added System.Threading.Thread.Sleep(100) in the loop.
It did not work.
The port starts spewing crash data after ~40min.

I disconnected usb debug and ran off the 6V supply (which I measured with DMM at 6.167V).
It did not work, same results.

I am at the point of assuming I have a bad Cobra II eco?
Any other ideas?

GHI / GUS, where would I send a board to be evaluated?

using System;
using Microsoft.SPOT;

namespace MFConsoleApplication1 {
    public class Program {
        private static System.IO.Ports.SerialPort _modemSerialPort = null;
        private static byte[] _writeBuf = null;
        private static byte[] _readBuf = new byte[256];
        
        public static void Main() {
            var encoder = System.Text.Encoding.UTF8;
            _modemSerialPort = new System.IO.Ports.SerialPort("COM1", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
            _modemSerialPort.ReadTimeout = 5000;
            _modemSerialPort.Open();

            Microsoft.SPOT.Debug.Print(_modemSerialPort.PortName);
            int cnt = -1;

            while (true) {
                if (_modemSerialPort.IsOpen) {
                    try {
                        _writeBuf = encoder.GetBytes("Hello " + cnt.ToString() + "\r");
                        _modemSerialPort.Write(_writeBuf, 0, _writeBuf.Length);
                    } catch (Exception ey) {
                        Microsoft.SPOT.Debug.Print(ey.ToString());
                        break;
                    }
                }
                System.Threading.Thread.Sleep(100);
                cnt++;
            }
        }
    }
}

Try reloading all the firmware…

Have you tried a higher voltage.
I think 7V is the minimum on a USB DP so everything runs well.

Reinhard,

I got a 6V supply because it was recommended in an earlier post.

I am confused as https://www.ghielectronics.com/catalog/product/399 shows
the power jack taking 7-30VDC?

The voltage I apply at the jack is dependent on which USB port I am using?

I am not familiar with the terminology:
USB DP
USB Client EDP

I assume the micro usb connector that one debugs over is the USB Client EDP?
If the debug port is USB DP, I will apply 12VDC.
If the debug port is USB Client EDP, what should I use? Was told earlier 6VDC should be used?

AFAIK, there is nothing in any of the doc’s that outline any of this!!!