Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) Upload to mega 2560 fails for one particular project (Read 7050 times)
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Upload to mega 2560 fails for one particular project
Feb 19th, 2019 at 8:47pm
Print Post  
I had a hardware problem (since fixed) that caused a problem uploading a particular project to a Mega 2560.  Now that project won't upload at all - it  hangs with the following error:

Code
Select All
Writing | avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer 



I have verified that other projects will upload to the board correctly - it's just this one project that fails.  I have attached a text file containing the verbose output from the compile and the upload steps.  

I have attempted to capture the verbose output from a successful upload from another project so I could compare the two outputs line by line, but immediately after the upload step, the entire text is replaced by 'running the program' or words to that effect.  Is there a way to pipe the output to a file so I can capture it?

I have also tried to compare all the VM settings for the 'good' and 'bad' projects, and AFAICT, they are identical.

TIA,

Frank
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Upload to mega 2560 fails for one particular project
Reply #1 - Feb 20th, 2019 at 1:00pm
Print Post  
HI,

This is the build command, you can run it from outside visual micro in a command prompt.

Code
Select All
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude "-CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega2560 -cwiring "-PCOM8" -b115200 -D ga2560\Release/FourWD_WallE2_V1.ino.hex:i" 




Maybe the older avr chips don't like long file names. You can change with the hex file name and or command to try to eliminate the issues however as you can see you are outside of visual micro working directly with avrdude.exe

Hope that helps.
  
Back to top
WWW  
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: Upload to mega 2560 fails for one particular project
Reply #2 - Feb 20th, 2019 at 4:48pm
Print Post  
Tim,

The file uploads OK from the Arduino IDE, and I have been uploading this same project successfully for years using VS/VM.  So, it's not a long filename/path issue or an avrdude issue; it's got to be something about VM's configuration that got corrupted, although I can't seem to find anything different via a visual inspection of the various configuration dialogs.

Does VM store project-level configuration options in a file somewhere, or is it all in the registry?  If it's in a file, maybe I can replace the file in the failing project with one from a succeeding one?

TIA,

Frank
  
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: Upload to mega 2560 fails for one particular project
Reply #3 - Feb 20th, 2019 at 5:17pm
Print Post  
Tim,

I did a 'diff' of the .vxproj files from both the 'failing' and a 'working' project.  The only difference I can see is the 'UserProperties' entry.  In this line, everything is identical out to column 14982, and after that they are markedly different - could that be the reason one will upload and the other won't?

I have attached a text file containing the 'UserProperties' entry from both the 'failing' and 'working' projects.

TIA,

Frank
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: Upload to mega 2560 fails for one particular project
Reply #4 - Feb 20th, 2019 at 6:52pm
Print Post  
In an effort to troubleshoot the problem, I created a new Arduino project called 'UploadProblem' and copy/pasted my source code into the new project.  This should create entirely new support files like .vxproj, so if the problem was in one of these files it should now compile and upload properly.

Unfortunately, the new project fails to upload as well, with the same error messages.  However, it (and all my other projects) will upload properly using the Arduino IDE, to two different Mega 2560's using three different programming ports (I have two ways of programming my robot - one is wirelessly through a Wixel pair, and the other is via direct connection to the onboard Mega 2560).

Thoughts?

Frank
  
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: Upload to mega 2560 fails for one particular project
Reply #5 - Feb 20th, 2019 at 9:09pm
Print Post  
Next, I commented out all the code in 'UploadProblem.ino', leaving empty setup() and loop() functions.  this uploads correctly, and I have attached the verbose build output as 190220_EmptyUploadProblemSuccess.txt

Then I added all the setup code back in, plus whatever support functions the setup() routines need to function.  Compiles and uploads successfully. File attached as 190220_SetupOnlyUploadProblemSuccess.txt

Next I added back most of my loop() code, plus some needed support functions. Compiles and uploads successfully.  190220_SetupandLoopUploadProblemSuccess.txt

Next I added back some more support functions. Compiles and uploads successfully.  See 190220_MoreLoop1UploadProblemSuccess.txt

Next I added back almost everything.  Compiles and uploads successfully.  See 190220_AlmostEverythingUploadProblemSuccess.txt

Next I added the rest of the code, and this time the upload failed!  I was SURE I had nailed the problem down to some settings issue that got reset to a default value when I uploaded an empty project file.  Now it is back to failing again

Closed and reopened VS/VM, and now I can  upload successfully, with the last two additions commented back out.

Put the two additions in, and it failed to upload again.  Commented them back out (and closed/reopened VS/VM, and also disconnected/reconnected the physical USB cable), and now it uploads successfully.

The two functions that I'm commenting in/out to make this happen seem to be pretty simple:

In the main program:

Code
Select All
	//mode string
	char modestr[20];
	memset(modestr, 0, sizeof(modestr));
	//GetModeString(pkt.mode, modestr);

	//submode (wall tracking) string
	char trkstr[20];
	memset(trkstr, 0, sizeof(trkstr));
	//GetWallTrackString(pkt.submode, trkstr);

 



Uncommenting GetWallTrackString(pkt.submode, trkstr) and GetModeString(pkt.mode, modestr) causes the upload to fail.  These functions are shown below

Code
Select All
void GetModeString(int mode, char* bufptr)
{
	sprintf(bufptr, "%s", ModeStrArray[mode]);
}

void GetWallTrackString(int mode, char* bufptr)
{
	sprintf(bufptr, "%s", TrkStrArray[mode]);
}

 



ModeStrArray and TrkStrArray are defined as 

Code
Select All
const char* ModeStrArray[] = { "None", "Charge", "Home", "Wall", "DeadBatt" };
const char* TrkStrArray[] = { "None", "Left", "Right", "Neither" };
 



This has me completely mystified.  ALL this code has been in my project for weeks if not months, and has been uploaded to the robot multiple times. In addition, I can upload to the Mega from the Arduino IDE with no problem, with or without these function calls present.  It's hard for me to believe there can be anything in the source code that compiles OK, but causes problems on upload in VS/VM, but not in the Arduino IDE - how does that happen?

I wonder if this is yet another manifestation of an earlier problem I reported - that VS/VM insists on using the 5.40 compiler with it's known problems, while I have the Arduino IDE configured to use an earlier version of the compiler. Is that even possible?

As an end-cap to this whole discussion, I have included the verbose compile/upload output for the project, with the offending code still commented out. See  190220_VerboseCompileUploadAtEnd.txt and 190220_IDEVerboseCompileUploadAtEnd.txt

Out to lunch in Ohio

Frank









Frank
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: Upload to mega 2560 fails for one particular project
Reply #6 - Feb 20th, 2019 at 9:47pm
Print Post  
As a final check on all this, I loaded up my original project and commented out just the two lines identified in the work above, i.e.

Code
Select All
	//mode string
	char modestr[20];
	memset(modestr, 0, sizeof(modestr));
	//GetModeString(pkt.mode, modestr);

	//submode (wall tracking) string
	char trkstr[20];
	memset(trkstr, 0, sizeof(trkstr));
	//GetWallTrackString(pkt.submode, trkstr);

 



And now it compiles and uploads successfully - go figure.  Then I uncommented just the GetModeString(pkt.mode, modestr); line, and it still compiles/uploads correctly.  Then I uncommented the other line (//GetWallTrackString(pkt.submode, trkstr)Wink and the upload failed!

So, something to do with that one function call?!!!

Commented the line back out again, and now I can upload successfully.

Uncommented the GetWallTrackString(pkt.submode, trkstr); line, but commented out the one-line contents of the function, i.e. 
Code
Select All
void GetWallTrackString(int mode, char* bufptr)
{
	//sprintf(bufptr, "%s", TrkStrArray[mode]);
}
 



now it compiles and uploads correctly.   

So, the only thing I can think of is that the 'sprintf' operation is somehow screwing up the upload.  Maybe the compiler is allocating memory for the buffer that overwrites some bootloader code?  Again, the weird thing is, I can do this all day in the Arduino IDE and it never fails - just in the VS/VM environment.

Regarding the gcc 5.40 issue, I just noticed that the Arduino IDE got updated while I wasn't looking, so I'm back to using the 1.6.23 board manager version (same as the version shown in VS/VM board manager) which uses gcc 5.40.  So, both the Arduino IDE and the VS/VM environment should be using the same compiler version - stranger and stranger

Frank


  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Upload to mega 2560 fails for one particular project
Reply #7 - Feb 21st, 2019 at 12:33pm
Print Post  
You should do as I have suggested and run the upload from outside visual micro to confirm things

I would also reinstall the usb driver that can be found below the arduino ide \ drivers folder.

The arduino ide is available as a zip. the only reason for using the windows installer is to apply the usb drivers which you already have. So you can download any of the previous arduino zips and unpack to any folder then point vm to it. I would try a slightly older version. 

I would also click Rebuild instead of build just to be sure that everything for that project is clean.

I would uncomment the sprintf and add more code to the function. Then comment some other code to prove it's not sprintf.

Here are a few links to the same issue

https://forum.arduino.cc/index.php?topic=83079.0
https://stackoverflow.com/questions/19645441/avrdude-stk500v2-receivemessage-tim...
https://arduino.stackexchange.com/questions/33505/why-do-i-get-avrdude-stk500v2-...
https://www.robotshop.com/community/forum/t/arduino-mega-2560-programmer-communi...

« Last Edit: Feb 21st, 2019 at 12:37pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: Upload to mega 2560 fails for one particular project
Reply #8 - Feb 22nd, 2019 at 1:07am
Print Post  
Tim,

Thanks for the informative reply - you are doing great work here!

Tim@Visual Micro wrote on Feb 21st, 2019 at 12:33pm:
You should do as I have suggested and run the upload from outside visual micro to confirm things

I've done that multiple times.  All my projects will upload with no problems from Arduino IDE (1.8.7)

I would also reinstall the usb driver that can be found below the arduino ide \ drivers folder.

I'm not sure what you mean here. Is this a separate step (re-installing usb driver) or part of your next suggestion. I found this link for updating the usb driver - is that what you meant?

The arduino ide is available as a zip. the only reason for using the windows installer is to apply the usb drivers which you already have. So you can download any of the previous arduino zips and unpack to any folder then point vm to it. I would try a slightly older version. 

I downloaded the 1.8.5 version of the ide and extracted it to a folder on my PC.  Then, in VS/VM I changed the IDE location from the default C\Program Files (x86)\Arduino to C:\Users\Public\arduino-1.8.5-windows\arduino-1.8.5.   Then I compiled and uploaded the program successfully both with and without the sprintf line - woohoo!

I would also click Rebuild instead of build just to be sure that everything for that project is clean.

I've been doing that (clean build) pretty religiously ever since I started having problems

I would uncomment the sprintf and add more code to the function. Then comment some other code to prove it's not sprintf.

Did that multiple times - it's the 'sprintf(...) statement for sure



So now it appears there is some weird interaction between VS/VM and 1.8.7 that isn't present in 1.8.5.  This is somewhat mind boggling to me, because everything works fine (compile & upload) through the Arduino IDE even with 1.8.7, and I assumed that a VS/VM compile would produce an identical .HEX file. when using the same IDE location.  As an experiment I compared the .HEX files from a compile through the Arduino IDE to one from the compile of the identical source code through VS/VM, with VM set to the same IDE location as the IDE (i.e C:\Program Files (x86)\Arduino, and discovered that the .HEX files are indeed significantly different - yikes!  I was hoping an examination of the .HEX files would show just a few lines difference due to the problem 'printf' line, but this was apparently a naive view of the process Wink

Interestingly though, the .HEX files *are* identical for about 150 lines, from line 23 through line 170


Frank

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Upload to mega 2560 fails for one particular project
Reply #9 - Feb 22nd, 2019 at 3:10pm
Print Post  
After you had followed my request to test the upload outside vm I would have then suggested you switch on "file>preferences>upload verbose" in the arduino ide. I expected to see in the arduino ide verbose upload that it is not using its local avr toolchain but instead using a different/older version installed via board manager.
  
Back to top
WWW  
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: Upload to mega 2560 fails for one particular project
Reply #10 - Feb 22nd, 2019 at 5:24pm
Print Post  
Tim,

I think I did that two days ago. See 190220_IDEVerboseCompileUploadAtEnd.txt in the ZIP file I uploaded on 02/20/19 as part of 'Reply #5'.

I would attach another run, but I can't figure out how to upload an attachment to this reply - the 'Attachment' option is missing for some reason.

Frank
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Upload to mega 2560 fails for one particular project
Reply #11 - Feb 23rd, 2019 at 12:36pm
Print Post  
It's very important that when it fails you grab the upload command and try it from command prompt.

Thanks
  
Back to top
WWW  
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: Upload to mega 2560 fails for one particular project
Reply #12 - Feb 23rd, 2019 at 6:06pm
Print Post  
Tim,

I changed the IDE location back from C:\Users\Public\arduino-1.8.5-windows\arduino-1.8.5 to C:\Program Files (x86)\Arduino to see if I could capture then information you requested, but now I can't get the upload to fail - grrrr!  Checked it with two different Mega 2560's using two different COM ports.

And yes, I did check that the previously offending 'sprintf....' line is active - it is.

I've left the IDE location at the default C:\Program Files (x86)\Arduino setting, and I'll let you know if/when the upload fails again

Frank
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint