Compatibility with Visual Micro?

Started by mwolter, July 31, 2018, 10:08:29 PM

mwolter

Been using the Moteinos and Moteino Megas for a few months and thought I'd give the M0's a try for a new project where I need to dynamically adjust PWM frequency. Just getting started with them and ran into an issue with Visual Micro.

Has anyone had success uploading or using the serial monitor with the Moteino M0 board type selected in Visual Micro? For some reason, the only way I can upload a sketch is to put the M0  in bootloader mode (then select the comm port that appears) and the serial monitor does not work at all. I've tried searching for settings to adjust but have found nothing.

I can only get the Visual Micro serial monitor to work if I choose Arduino/Genuino Zero (Native USB Port) as the board type, but the sketch upload still doesn't work. However, sketch upload and serial monitor appear to work fine in the Arduino IDE.

Basically, I am not able to upload a sketch whenever I feel like it. It has to be right after the M0 was connected via USB. I also tried this on two different hubs to be sure the issue wasn't the power. 

Wondering if anyone has had success or has any tips?

Update:
After compiling in Visual Studio using the Arduino/Genuino Zero (Native USB Port) board type, I am now able to switch back to the Moteino M0 board type and access the serial monitor.  But sketch upload does not appear to be working properly! If I unplug and reconnect the USB port I am able to upload the sketch, but if I open the serial monitor then try to upload the sketch, nothing. Says "The uploader process failed. No device found on COM6". I have to upload the sketch before opening the serial monitor to get it to upload.

Very weird. I had no issues with the Moteinos and Moteino Megas.

Felix

The M0 is a very different board than the AVR Moteinos.
Please note that as you switch from the sketch into bootloader, the USB will emulate different COM (serial) ports. This happens instantly. It might be the reason why, you're picking the COM port while the board is running a sketch, then bootloading it makes it drop the old port and emulate a new one. So try to make sure the port you're uploading to is the one that's actually running the bootloader.

mwolter

#2
Hi Felix,
I believe the root of the issue is that the M0 isn't switching into bootloader when the sketch is to be uploaded via Visual Micro, I have to do it manually. Like I mentioned, the Arduino IDE doesn't appear to have this issue. It switches to bootloader and receives the sketch if I have the serial monitor open or not. If the serial monitor was opened previously, or not. It works every time.

Is there anything I should be doing differently with Visual Micro? Is there a tweak to the board library that would help with this? Have you tested your boards with Visual Micro?

Thanks!

Felix

I've not tested with Visual Micro.
One thing the IDE does is being able to do the reset itself and then automatically switch the port to that of the bootloader. I suspect VMicro does not do that.

Uncle Buzz

In VisualMicro, on serial monitor you have some options like "dtr" and "rts" you don't have on the Arduino IDE, try to change them, maybe one of them can ask to the moteino MO to restart (and first use the bootloader port com) ?

Felix

UncleBuzz,

AFAIK:
- The SAMD21 does not work like that, it's not a conventional serial port.
- The Arduino IDE has a special serial message pattern which will make it reset the board. This is baked in the USB stack that gets on the chip. When the chip sees that message, it will reset and enter bootloader which will be ready to accept the new sketch.

Does VisualMicro support other SAMD21 boards?

Uncle Buzz

It uses same boards list than Arduino IDE (not same instance for both software, but use same source to update the boards list), but I don't know if it' enough to conclude it supports them all...


mwolter

#7
The M0 is quite different from previous boards, especially where the USB serial port is concerned.

From what I can tell, the IDE and Visual Micro don't actually use serial to communicate with the M0. At least not like we're used to. The first indicator was that the baud rate doesn't matter. You can set it to anything you want and it still works! I thought something was wrong at first.

Felix, Visual Micro actually does switch to the other com port.

Compiling 'EBIS_MO' for 'Moteino M0'
Program size: 29,404 bytes (used 12% of a 253,952 byte maximum) (3.12 secs)
 
Uploading 'EBIS_MO' to 'Moteino M0' using 'COM6'
Atmel SMART device 0x10010005 found
Device       : ATSAMD21G18A
Chip ID      : 10010005
Version      : v2.0 [Arduino:XYZ] [LowPowerLab:FlashBoot_v1] May 21 2018 16:06:41
Address      : 8192
Pages        : 3968
Page Size    : 64 bytes
Total Size   : 248KB
Planes       : 1
Lock Regions : 16
Locked       : none
Security     : false
Boot Flash   : true
BOD          : true
BOR          : true
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
done in 0.875 seconds
Write 29916 bytes to flash (468 pages)
[====                          ] 13% (64/468 pages)
[========                      ] 27% (128/468 pages)
[============                  ] 41% (192/468 pages)
[================              ] 54% (256/468 pages)
[====================          ] 68% (320/468 pages)
[========================      ] 82% (384/468 pages)
[============================  ] 95% (448/468 pages)
	The upload process has finished. via 'COM7'
[==============================] 100% (468/468 pages)
done in 0.234 seconds
Verify 29916 bytes of flash with checksum.
Verify successful
done in 0.078 seconds
CPU reset.


I think the issue is that it's not proper signaling the MO to go into bootloader mode. Not sure why because as UncleBuzz mentioned, it uses the same board libraries as the IDE.

Highly recommend installing Visual Studio 2017 and Visual Micro, it makes coding so much more intuitive. Renaming, autocomplete (intelisense) repositories, online Visual Studio Team Services (check-in/out, branching, etc.). It uses the standard Arduino code and board libraries. Oh and it's free :) I ended up buying a Visual Micro license, but you don't have to. Thought it only fair since the developer had done a great job, but Visual Studio and the online portion is free.

Felix

mwolter,
I don't know for sure what it really is but I think it's the switching and serial signalling to SAMD21 devices that may not be implemented in VMicro.
Maybe the Visual Micro guys have something to say?
Do you have any other SAMD21 device to try?

PS: Please use M0 (M digit Zero) not MO (M letter O), so people would find the thread if they search by "M0". Thanks!

mwolter

Corrected the names in the previous posts  ;D

I found a post on the Visual Micro and the Arduino boards regarding this issue but they haven't found a solution yet. Appears to be an avrdude issue. Thanks for your help and in case anyone else experiences this issue, please follow the links below.

https://www.visualmicro.com/forums/YaBB.pl?num=1498648612/0#0
http://forum.arduino.cc/index.php?topic=541638.0

Felix

FWIW - avrdude cannot be used for upload to SAMD21 devices. It uses a program called bossa which comes with the Moteino boards package when you install that in the IDE.
So it sounds like VMicro does not support SAMD21 devices.

mwolter

#11
Updated to the latest version of Visual Micro (1807.8 ) and it appears to be working better. It still needs the reset button pressed before uploading, but that's better than it was. 

mwolter

In case anyone else runs into inconsistent SerialUSB sketch upload issues, disabling all debug printing to SerialUSB and instead using an FTDI adapter on Serial (pins 30 and 31) works much better.

Sketch runs much faster (120 microseconds instead of 5 milliseconds) and the sketchs upload every time via USB. Via USB sketches can now be consistently uploaded to the primary COM port (in my case COM 3) and not to the bootloader COM port (in my case COM 4).

Hopefully, this helps save someone getting a few gray hairs :)

Felix

I appreciate the follow up information, I hope it helps someone as well, many thanks!