Intermittent M4 Upload Errors

Discussion in 'UDOO NEO' started by William Warke, Dec 11, 2016.

  1. William Warke

    William Warke New Member

    Joined:
    Oct 5, 2016
    Messages:
    7
    Likes Received:
    3
    I am currently experiencing intermittent M4 upload errors which I can produce using both the internal (flash: uploading input firmware failed) and external (UDOONeo M4 Sketch START failed: reboot system!) Arduino IDEs. By intermittent I mean that I can upload the sketch and it will work flawlessly, then click upload again and receive an error in the process. I'd say it's about 50/50 on whether it will work, although the M4 often locks up completely during the process, requiring me to delete m4last.fw and reboot to get it back up and running.

    I would post the code for reference, but it is quite extensive (6 files + 2 customized libraries) and I can't seem to boil it down to a version which fails consistently. For now I am really just looking for common pitfalls that lead to the M4 programming error, so I will document what my program is doing and what I've done so far to troubleshoot:
    • My program extensively uses the gyro (via Wire1 I2C), Serial0 port, and 4 PWMs for ESC control.
    • In each loop iteration, I am taking gyro readings and checking Serial0 for commands from an external receiver as well as periodically writing debugging data to Serial0.
    • I am also using delay() and delayMicroseconds() within each loop iteration.
    • Up until this point, I have tested every subsystem and it all works perfectly until I combine everything, and even then it is fully functional except for the intermittent upload errors.
    • It seems like the combination of Wire1 and Serial0 is related to the cause of the problem, because I only have the issue when both are used in the program.
    • I will mention that I had to completely rewrite the gyro library (FXAS21002C.cpp/h). See this thread: http://www.udoo.org/forum/threads/how-to-read-the-angle-from-the-gyro-fxas21002c.4777/#post-21348 for the reasons why.
    • My issue is very similar to this one: http://www.udoo.org/forum/threads/m4-sketch-start-failed-reboot-system.5147/, except that I am not using an external timing library.
    Does this seem at all familiar to you guys? Has anyone successfully used both the onboard gyro and Serial0 read/write extensively in the same M4 program? Please let me know what you think and in the meantime I will keep trying to isolate the problem so I can post a minimal sketch.

    Thanks!
     
  2. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
  3. Maurice

    Maurice Active Member

    Joined:
    Oct 13, 2015
    Messages:
    394
    Likes Received:
    87
    See my post on serial communication between the i.MX6, M4 and a Arduino Mega (Serial 0). I think it is not a problem of the gyro, but of the Serial communication. I hope 'someone' (@Andrea Rovai please trigger that someone...) from UDOO will start to read these threads and help us out.
     
  4. William Warke

    William Warke New Member

    Joined:
    Oct 5, 2016
    Messages:
    7
    Likes Received:
    3
    Thanks for the feedback guys. I verified that I could consistently use Wire1 and Serial0 separately, but even just adding a .begin() for both of them and using only the Serial0 port in the code causes the problem to occur intermittently. I've come up with a sketch below that consistently recreates the problem using only the native Wire.h library and the Serial0 port.

    To reproduce it, try uploading this code 3-5 times in succession with a continuous transmitter connected to the Serial0 receive pin (Pin 0). For me it's about 50/50 with this sketch. I've found that it will upload just fine if I don't connect anything to Serial0, but unplugging the active transmitter and then trying to upload causes it to fail sometimes. The most bizarre part to me is that if I leave out Wire1.begin(), the problem never manifests itself at all no matter what I do with the transmitter.

    Additionally, the more complicated my program gets in terms of processing Serial0 and gyro data, the more often the problem occurs and I have to remove the sketch and reboot, to the point that my current program will not upload more than once. I will stress that it pretty consistently uploads the first time after a reboot, and even works as expected without crashing until I try to upload a second time, so I don't understand how it could be caused by a bug in the code itself.

    Please give this a shot and let me know what happens so we can work towards a solution together. I really appreciate your help on this.

    Code:
    #include <Wire.h>
    
    bool dataReceived = false;
    unsigned long currentTime = 0, readTime = 0;
    
    void setup() {
        Serial0.begin(115200);
        delay(100);
    
        Wire1.begin();
        delay(100);
    
        Serial0.println("Waiting for input...");
    }
    
    void loop() {
        if (dataReceived) {
            //Process data here
            dataReceived = false;
        }
    }
    
    void serialEvent0() {
        uint8_t inByte;
        readTime = millis();
    
        int index = 0;
        while (Serial0.available() > 0) {
    
            inByte =  Serial0.read();
            currentTime = millis();
    
            //Timeout check
            if (currentTime - readTime > 1000) {
                Serial0.println("Error: Serial0 read timeout!");
                return;
            }
        }
        dataReceived = true;
    }
     

Share This Page