0

Metro M0 Express Atmel Studio Serial Print Issue
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro M0 Express Atmel Studio Serial Print Issue

by chuckph on Wed Dec 26, 2018 12:44 pm

I have developed C programs for the Arduino Zero, which compile, execute, and debug nicely on Atmel Studio using vMicro. Lately, the Zero has become unavailable, so I am migrating my code the Metro M0 Express. Within Atmel Studio, I have written a simple "Hello World" program using Serial.print( ). The text is properly output to the serial monitor. However, serial prints fail to provide output when used in complex applications. Since the Metro 0 does not provide EDBG debugging and USB serial does not work, I have no visibility into this issue.

Web documentation from Adafruit suggests using SerialUSB rather than Serial commands. This, however, has proven to be an undefined term. Elsewhere in the forum, it is also suggested that SerialUSB no longer exists.

Perhaps my code is using a resource that is required or lacking a required definition. Please let me know your thoughts.

NEWS FLASH: I have resolved this issue. Looking more closely at the following webpage (https://learn.adafruit.com/adafruit-met ... hes-to-m0#), I noticed that the text did not agree with the illustrated example. When I used the syntax provided in the the text (#define Serial SERIAL_PORT_USBVIRTUAL) serial output began to appear on the Serial Monitor. However, two issues remain:

1. The very first print command does not output to the monitor: Serial.println("Topper setup entered");. The print command that fails is issued as the first command within setup( ). The print commands that work are within loop( );

2. The build process now pulls in CDC.cpp, which contains the following compile errors:

unsigned long Serial_::baud() {return _usbLineInfo.dwDTERate;} (return type differs from that in the definition)

void Serial_::begin(uint32_t /* baud_count */, uint8_t /* config */) {// uart config is ignored in USB-CDC } ('begin' does not match any declaration in Serial_)

Please let me know your thoughts regarding these two issues.

chuckph
 
Posts: 9
Joined: Mon Jan 15, 2018 3:25 pm

Re: Metro M0 Express Atmel Studio Serial Print Issue

by adafruit_support_mike on Fri Dec 28, 2018 2:37 am

That's far enough outside standard usage that you'll probably have to edit the low-level files to make the details line up.

The error for Serial_::baud() looks like a difference in default variable types between the boards or between IDEs. You'll have to trace the origin of the retun value back to where it's defined and see how it compares to (unsigned long). Best case, you can just throw a type cast into the return value for that function and make things play nicely.

The error related to Serial_::begin() looks like a header problem. Find the file that contains the class definition and see what methods are actually defined. Best case, you can just add a declaration for begin(uint32_t,uint8_t) and get things working.

adafruit_support_mike
 
Posts: 57131
Joined: Thu Feb 11, 2010 2:51 pm

Re: Metro M0 Express Atmel Studio Serial Print Issue

by chuckph on Fri Dec 28, 2018 2:02 pm

Thanks for the reply. It appears that the two errant lines of code were not needed. I was able to comment them out without any negative effects.

However, the issue still exists that my very first call to printf does not work. Subsequent calls to printf do work. As mentioned, the failing call is made as the first statement in setup(), after serial.begin. The calls the work are made by various routines that are called from loop(). No additional serial configuration commands are made between the failing printf and those that work. Is a time delay required after the initial serial configuration?

chuckph
 
Posts: 9
Joined: Mon Jan 15, 2018 3:25 pm

Re: Metro M0 Express Atmel Studio Serial Print Issue

by adafruit_support_mike on Sun Dec 30, 2018 2:33 am

There shouldn't be any significant time delay, but you might run into a clock synchronization delay for the SERCOM peripheral.

The SAMD21's peripherals can run from clocks that are completely independent of the microcontroller's CPU clock. To make that work, there are sync intervals that make sure different parts of the chip can talk to each other.

Go ahead and try some delays to see if that helps, but it might be easier to add a dummy print() statement that can be ignored before calling the function again. You'd probably need to step through the code with a JTAG pod to identify the actual cause.

adafruit_support_mike
 
Posts: 57131
Joined: Thu Feb 11, 2010 2:51 pm

Re: Metro M0 Express Atmel Studio Serial Print Issue

by westfw on Tue Jan 08, 2019 6:59 am

Do you have the:
Code: Select all | TOGGLE FULL SIZE
while (!Serial)
   ;

That is usually used with native usb serial after Serial.begin() ?
westfw
 
Posts: 1522
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Please be positive and constructive with your questions and comments.