Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Metro Express can't upload new code
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro Express can't upload new code

by SkyRyder on Thu Oct 21, 2021 8:07 pm

Hi all,

Been developing on a metro express... and all has been happy/good...

Then today, I can no longer upload sketches to the board.

The board is still running code fine... when I reset, I can see that what was in there last is still operating.

I did the "hold reset" cycle power, upload, release, thing... no change. The old code is still there.
When I unplug and plug in the board, I can see it disappear from the com port list, then returns (properly identified) when I plug it back in. I also tried a new cable.

It compiles the sketch... then says "uploading..." Nothing happens... seems to hang. I did see it throw an error message once...
Something about an error uploading then: "Error opening serial port com 7".

The board does not appear as a drive in windows explorer (I thought that previously it did).

Eventually this appears in the black window:

Code: Select all | TOGGLE FULL SIZE
C:\Users\rci\AppData\Local\Arduino15\packages\adafruit\tools\arm-none-eabi-gcc\9-2019q4/bin/arm-none-eabi-ar: unable to rename 'core\core.a'; reason: File exists
exit status 1
Error compiling for board Adafruit Metro M4 AirLift Lite (SAMD51).
Sketch uses 31232 bytes (6%) of program storage space. Maximum is 507904 bytes.
processing.app.debug.RunnerException
   at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152)
   at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77)
   at processing.app.SketchController.upload(SketchController.java:732)
   at processing.app.SketchController.exportApplet(SketchController.java:703)
   at processing.app.Editor$UploadHandler.run(Editor.java:2061)
   at java.lang.Thread.run(Thread.java:748)
Caused by: processing.app.SerialException: Error touching serial port 'COM7'.
   at processing.app.Serial.touchForCDCReset(Serial.java:107)
   at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136)
   ... 5 more
Caused by: jssc.SerialPortException: Port name - COM7; Method name - openPort(); Exception type - Port busy.
   at jssc.SerialPort.openPort(SerialPort.java:164)
   at processing.app.Serial.touchForCDCReset(Serial.java:101)
   ... 6 more
processing.app.SerialException: Error opening serial port 'COM7'.
   at processing.app.Serial.<init>(Serial.java:152)
   at processing.app.Serial.<init>(Serial.java:82)
   at processing.app.SerialMonitor$2.<init>(SerialMonitor.java:132)
   at processing.app.SerialMonitor.open(SerialMonitor.java:132)
   at processing.app.AbstractMonitor.resume(AbstractMonitor.java:132)
   at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2126)
   at processing.app.Editor.access$1300(Editor.java:116)
   at processing.app.Editor$UploadHandler.run(Editor.java:2095)
   at java.lang.Thread.run(Thread.java:748)
Caused by: jssc.SerialPortException: Port name - COM7; Method name - openPort(); Exception type - Port busy.
   at jssc.SerialPort.openPort(SerialPort.java:164)
   at processing.app.Serial.<init>(Serial.java:141)
   ... 8 more
Error opening serial port 'COM7'.


[UPDATE: I plugged the board into another Windows 10PC (which had never seen an arduino) and it recognized it correctly and (supposedly) "set it up". That particular machine does not have an IDE or anything set up on it so I could not test further.]

This is a serious bummer for me!

Please help if you can.

SkyRyder
 
Posts: 45
Joined: Fri Mar 06, 2020 6:05 pm

Re: Metro Express can't upload new code

by franklin97355 on Thu Oct 21, 2021 10:06 pm

What happens when you "double tap" the reset button? do you have a metro M4 with airlift?

franklin97355
 
Posts: 22320
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Metro Express can't upload new code

by SkyRyder on Thu Oct 21, 2021 10:18 pm

franklin97355 wrote:What happens when you "double tap" the reset button? do you have a metro M4 with airlift?


I do have the airlift board, yes.

When I double tap the reset, I get a rapidly flashing "L" light (red), about 2x/sec. (this is without the board connected to any PC).

When connected to a PC, the "L" light goes solid red, then begins pulsing slowly (2-3 seconds rate).

Interestingly, a "D:\" METROM4BOOT drive mounted during this.

Also, when setup and connected to another pc, the issue does not change... so it appears to be the board.

I have a capactive touchscreen on board (1947)

SkyRyder
 
Posts: 45
Joined: Fri Mar 06, 2020 6:05 pm

Re: Metro Express can't upload new code

by franklin97355 on Thu Oct 21, 2021 10:42 pm

If you want to use CircuitPython you need to download and install the uf2 file https://circuitpython.org/board/metro_m4_airlift_lite/ using this tutorial
https://learn.adafruit.com/adafruit-metro-m4-express-airlift-wifi

franklin97355
 
Posts: 22320
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Metro Express can't upload new code

by SkyRyder on Thu Oct 21, 2021 10:56 pm

franklin97355 wrote:If you want to use CircuitPython you need to download and install the uf2 file https://circuitpython.org/board/metro_m4_airlift_lite/ using this tutorial
https://learn.adafruit.com/adafruit-metro-m4-express-airlift-wifi



I do not want to do circuit python... CP has nothing to do with this issue in any way. I had been successfully developing a project in c++ when suddenly I can't upload any more sketches. I'm now suspecting that the serial port on the Metro is a bit hozed in some way for writes. (it can read over the serial port without problem).

Interestingly, it *acts* like I can create, copy and edit files on this METRO D: drive... but when I reopen it, the files I've manipulated are gone.

I can't figure this.

What can I try?

SkyRyder
 
Posts: 45
Joined: Fri Mar 06, 2020 6:05 pm

Re: Metro Express can't upload new code

by User_UMjT7KxnxP8YN8 on Sun Oct 24, 2021 10:33 am

I've seen this strange behavior with the M4 Airlift, and, to a lesser extent, with the M4 Express. In my experience it's usually caused by one of two things.

The first, and easiest to fix, is that your current firmware may start running immediately and be stuck in a tight loop that the IDE can't interrupt or is generating huge amounts of serial output. I usually put
Code: Select all | TOGGLE FULL SIZE
Serial.begin(baud_rate);
while (!Serial()) ;
as the first lines in setup() so my program has to wait for me to open the serial monitor or a KiTTy session before starting, and this helps prevent problems when uploading new firmware. But that won't help you get past the problem once you have it.

Double-clicking the reset button WHILE CONNECTED TO USEB to put your board into bootloader mode may solve your problem. You must do it pretty quickly to get it to work and it often requires multiple attempts to get it right. Search for 'double' in the Airlift Lite 'Technical Details' page https://learn.adafruit.com/adafruit-metro-m4-express-airlift-wifi#uf2-bootloader-details. When successful you'll see a file manager window open. If you haven't already updated your bootloader to something higher than 3.9, now would be a good time to do it as explained at https://forums.adafruit.com/viewtopic.php?f=63&t=165225 by dropping the latest bootloader UF2 (NOT Circuit Python) on that window and waiting for it to complete.

At that point you should be able to build and upload a new sketch; make sure to include the setup() code I mentioned.

Often Windows will re-enumerate the M4 boards after double-clicking to enter the bot loader; even though IDE messages say your sketch uploaded successfully you may not be able to open the serial monitor. Don't worry; just go to Tools=>Port in the IDE and select the new port. It usually re-enumerates again and changes back to the original port the next time you load new code.

The second, and more difficult to resolve, is that the M4 processor User Page startup settings can be overwritten. This requires a hardware debugger (e.g., J-Link) to fix, as well as a set of reasonable default values from another board. I did this once when experimenting with BOD33 to detect a low-battery condition, and used Atmel Studio 7 (now Microchip Studio) to read User Page settings from one M4 processor and write them into the one I'd overwritten. This got my board working again but probably not affected A/D accuracy and BOD33 behavior as they rely on factory-calibrated constants stored in the User Page. But this is probably not the problem you're seeing.

Hope that helps.

User_UMjT7KxnxP8YN8
 
Posts: 271
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro Express can't upload new code

by SkyRyder on Sun Oct 24, 2021 11:15 am

Thank you so much for the detailed reply!

First, I found that the setup code you presented didn't seem to validate... I ended up using this:
Serial.begin(9600);
while (!Serial) {
delay(10);
}

Next, I did update the bootloader successfully... installing 3.13.0 I had 3.3.0 installed, which seems odd to me as this is a brand new Metro directly from Adafruit... why is the boot loader so many revisions behind?

It took a couple tries and pointing at a different serial port to do it, but the board is back!

Thank you SO much...

SkyRyder
 
Posts: 45
Joined: Fri Mar 06, 2020 6:05 pm

Re: Metro Express can't upload new code

by SkyRyder on Sun Oct 24, 2021 12:42 pm

User_UMjT7KxnxP8YN8 wrote:I've seen this strange behavior with the M4 Airlift, and, to a lesser extent, with the M4 Express. In my experience it's usually caused by one of two things.

The first, and easiest to fix, is that your current firmware may start running immediately and be stuck in a tight loop that the IDE can't interrupt or is generating huge amounts of serial output. I usually put
Code: Select all | TOGGLE FULL SIZE
Serial.begin(baud_rate);
while (!Serial()) ;
as the first lines in setup() so my program has to wait for me to open the serial monitor.



With respect to this... I can see how that helps when connected to a PC... but for deployment in the field, where I need the firmware to come up whenever powered, this code can't be in the setup.

Is there some approach that would allow the unit to power-up/run but prevent the condition above?

I can see a "power-up" sequence where if an input (like a touch on a display) would put the code in a state where the IDE can easily assert itself and upload new code.

Is that reasonable? What kind of state should I put the firmware in to make it upload ready? Would a loop with a delay(xxx) work?
Is there a way to suspend the code altogether?

Thank you!

SkyRyder
 
Posts: 45
Joined: Fri Mar 06, 2020 6:05 pm

Re: Metro Express can't upload new code

by User_UMjT7KxnxP8YN8 on Sun Oct 24, 2021 11:00 pm

You're correct in thinking that waiting for the serial connection won't work in the field where you're not connected to anything, but you won't be uploading new firmware via the USB port either.

Arduino main(), looks like this. Notice the call to yield(). This is normally sufficient to permit the IDE to connect, but only if your program isn't hung up in a tight loop somewhere.

I use the M4's WatchDog timer to prevent this from happening. You initialize it in setup() then reset it periodically (you get to choose the required interval) to let it know your software is still running as expected. If it isn't reset in time, it reboots the system. You can find code to do this (including an example) at https://github.com/SapientHetero/Watchdog-Timer-for-ATSAMD51J19A.

Code: Select all | TOGGLE FULL SIZE
int main( void )
{
  init();

  __libc_init_array();

  initVariant();

  delay(1);

#if defined(USE_TINYUSB)
  TinyUSB_Device_Init(0);
#elif defined(USBCON)
  USBDevice.init();
  USBDevice.attach();
#endif

  setup();

  for (;;)
  {
    loop();
    yield(); // yield run usb background task

    if (serialEventRun) serialEventRun();
  }

  return 0;
}

User_UMjT7KxnxP8YN8
 
Posts: 271
Joined: Tue Jul 17, 2018 1:28 pm

Please be positive and constructive with your questions and comments.