No App Boot on Power Cycle *Solved*

So, to preface, this isn't an ordinary configuration. First, this is a Mega 2560 R3 board.

I have setup AVR Studio 5.1 to build my Arduino Projects and I can flash them with AVR Dude and they work as expected. I can reset or power cycle the unit and it works as expected.

I have also setup Femto OS and it also works as expected on, flash, reset or power cycle.

Now, I combine the two together into a single project and now I have Arduino Libraries inlcuded with Femto OS and I can build that project and after flashing, everything works as expected. However, now if I power cycle the unit or hit the reset button, the sketch does not load. It just powers up and the pin 13 LED is solid on. I am sure it has something to do with the entry point and I not sure where that is set in either Femto OS or the Arduino IDE.

If anyone can point me in the right direction that would be awesome... I am sooooo close!

Brandon

Bah! More information... the Arduino Ethernet shield is the culprit. If I comment out any code dealing with that shield the system works as expected... so now to figure out what portion of the code is actually breaking things.

Okay, basically it comes down to delay’s. This took a while to figure out because I was heading the wrong direction for a while. Ultimately you need to do this in setup() for the ATMega2560

        pinMode(4, OUTPUT);
	digitalWrite(4, HIGH);
	pinMode(53, OUTPUT);
	pinMode(10, OUTPUT);
	digitalWrite(53, LOW);
	digitalWrite(10, LOW);
	delay(5000);
        Ethernet.begin(mac);
	delay(10000);

Also, in Dhcp.cpp in the function

uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId)

Change

    while(_dhcpUdpSocket.parsePacket() <= 0)
    {
        if((millis() - startTime) > responseTimeout)
        {
            return 255;
        }
        delay(50);
    }

to this:

    delay(100);
    while(_dhcpUdpSocket.parsePacket() <= 0)
    {
        if((millis() - startTime) > responseTimeout)
        {
            return 255;
        }
        delay(100);
    }

That is what got it to work properly for me. All of those delay’s need to be in place at those levels. Your results may vary and it may work with lower delay’s but this is what worked on my hardware. The only difference for a 328 is the pin selection. For a 328 you would not need to setup pin 53.

Brandon