Few years back a solution to annoying problem was to bypass *.ino and use modified Arduino copy of standard main() function.
It is no longer a problem , however, after using “BareMinimun” as a starting point for my code I have decided to go back to main().
To avoid any confusion – no , I do not have to use main(), my apps works fine in Setup() , happily dodging Loop().
The reason for this post is that current (1.6.11.) main() code does some strange things when used direct, without modification. ( see attached )
- init() activates WDT causing reset at about 12 seconds
This has been discussed here recently and hack was found to stop WDT. - initVariant(); supposedly allows for 3rd party something, but it is obviously already implemented and causes multiple main definitions so basically defeats the “weak” attribute function concept
( Similar hack is applied to UOTGHS_Handler weak function with “strong” function defined in core. It works, but user should define the strong function, not the core code. ) -
#if defined(USBCON) I am not sure what this does, I’ll find out later
USBDevice.attach();
#endif
I have no illusions or quarrel with “BareMinimum” hide main() function concept, and have no desire to discuss that.
I just like to know why useful options like weak attributes functions are being castrated and main() is no longer useful without digging into basic like init()- as in case of WDT.
Jim
/*
main.cpp - Main loop for Arduino sketches
Copyright (c) 2005-2013 Arduino Team. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <Arduino.h>
// Declared weak in Arduino.h to allow user redefinitions.
int atexit(void (* /*func*/ )()) { return 0; }
// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
void initVariant() { }
void setupUSB() __attribute__((weak));
void setupUSB() { }
int main(void)
{
init();
initVariant();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}