Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

code.py is corrupted
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

code.py is corrupted

by amosmj on Mon Jun 05, 2017 9:29 pm

I'm a total newb so apologies if this an obvious one. I was playing around with trying to run a servo off my Metro Express. I was using Mu at the time. I began to get warnings that code.py is corrupt. I've tried using Notepad and Spyder but get the same result. On the drive code.py is shown as 0 kb.

My instinct is to go over to the Metro Express page where I think I recall seeing guidance for installing a bootoader from scratch but thought I would ask here before I did anything that I might regret. Suggetions?

amosmj
 
Posts: 5
Joined: Mon May 08, 2017 10:24 am

Re: code.py is corrupted

by dhalbert on Mon Jun 05, 2017 10:53 pm

Are you using Windows, and is it reporting that the CIRCUITPY filesystem is corrupt or similar? The filesystem provided by CircuitPython can become corrupt if you press the reset button before Windows writes out the entire file. Due to a flaw in the Windows driver for small USB drives, this can take tens of seconds. You can get around this delay by doing an "Eject" on the CIRCUITPY drive after you write the file. That finishes writing the file immediately.

You don't need to reinstall the bootloader but you do need to erase the SPI flash chip so that CircuitPython will re-create the filesystem there. Load this library into Arduino and then run the flash_erase.ino sketch you'll find in the library examples: https://github.com/adafruit/Adafruit_SPIFlash/releases.

dhalbert
 
Posts: 401
Joined: Tue Feb 17, 2015 6:18 pm

Re: code.py is corrupted

by amosmj on Tue Jun 06, 2017 8:38 pm

dhalbert wrote:Are you using Windows, and is it reporting that the CIRCUITPY filesystem is corrupt or similar? ...

You don't need to reinstall the bootloader but you do need to erase the SPI flash chip so that CircuitPython will re-create the filesystem there. Load this library into Arduino and then run the flash_erase.ino sketch you'll find in the library examples: https://github.com/adafruit/Adafruit_SPIFlash/releases.


Sorry, I didn't post a very well formulated query. You're absolutely right that I'm on Windows. I probably did something dumb like hitting reset while the file was still writing.

Now I shall further prove my ignorance.
I downloaded the file you indicated, included the library and ran it and got an error:
exit status 1
'SS1' was not declared in this scope

I tried to look through the code and output to see what is going on and this is what I saw. Towards the top there is a Define SSI = SS1 statement. I get a message that: flash_erase:33: error: 'SS1' was not declared in this scope
I tried reading through the documentation here on Adafruit and saw a reference to SCK and tried that and at least it didn't error on compilation, on that line. I then get and error on the subsequent line: flash_erase:34: error: 'SPI1' was not declared in this scope
I went back to the documentation and found the page that talks about SPI Flash and they code that they quote is the exact code that you have me running.

sorry. do you have any suggestions to help me progress beyond these errors?

amosmj
 
Posts: 5
Joined: Mon May 08, 2017 10:24 am

Re: code.py is corrupted

by dhalbert on Tue Jun 06, 2017 9:06 pm

You'll need to install the latest SAMD board packages in the Arduino IDE: Arduino SAMD and Adafruit SAMD. Then select "Metro M0 Express" from the boards menu (it will be way down at the bottom -- you'll have to move to the arrow to scroll to the end). Then it should build without error.

Use Arduino 1.8.2 or the latest 1.8.3 from http://arduino.cc. This guide will get you started if you're unfamiliar with how to set up the Arduino IDE for the Metro M0 Express: https://learn.adafruit.com/adafruit-met ... thon/setup.

I would just note that even though the board packages are already installed, you may need to update them. I myself had older versions of the packages and hit the same error that you did until I updated them.

dhalbert
 
Posts: 401
Joined: Tue Feb 17, 2015 6:18 pm

Re: code.py is corrupted

by amosmj on Fri Jun 16, 2017 9:49 pm

Sorry for being kind of slow in replying. It's been a combo of life happening and trying to be sure I had done as much as I could before asking again.

I have updated Arduino to 1.8.3. I have verified that my SAMD boards are on version 1.0.17. I have tried all three COM ports that I have available, 3, 4, and 7. Both 3 and 7 say that they see no device. COM 4 says the following:
processing.app.debug.RunnerException
at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:160)
at cc.arduino.UploaderUtils.upload(UploaderUtils.java:78)
at processing.app.SketchController.upload(SketchController.java:713)
at processing.app.SketchController.exportApplet(SketchController.java:686)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2149)
at java.lang.Thread.run(Thread.java:745)
Caused by: processing.app.SerialException: Error touching serial port 'COM4'.
at processing.app.Serial.touchForCDCReset(Serial.java:99)
at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:144)
... 5 more
Caused by: jssc.SerialPortException: Port name - COM4; Method name - openPort(); Exception type - Port busy.
at jssc.SerialPort.openPort(SerialPort.java:164)
at processing.app.Serial.touchForCDCReset(Serial.java:93)
... 6 more


I'd take any additional suggestions.

amosmj
 
Posts: 5
Joined: Mon May 08, 2017 10:24 am

Re: code.py is corrupted

by dhalbert on Fri Jun 16, 2017 10:29 pm

Are you using Windows 7 or Windows 10? If Windows 10, try uninstalling all the drivers with "Adafruit" in their name in the list of installed programs (Settings->Apps).

dhalbert
 
Posts: 401
Joined: Tue Feb 17, 2015 6:18 pm

Re: code.py is corrupted

by amosmj on Mon Jun 19, 2017 10:08 pm

I'm on Windows 10. I went into apps but found nothing with Adafruit in the name. I also can't think of any application I've ever installed from Adafruit. You aid Drivers though so I wonder if I'm looking at the wrong thing. I tried removing the board packages that had Adafruit in the name but that put me back to having SS1 throw an error in the code.
After adding back the Adafruit SAMD boards I get a message "bootloader file specific but misisng: C:\...\Arduino15\packages\adafruit\hardware\samd\1.0.17\boorloaders\metro\samed21_sam_ba.bin. I haven't quite tracked down when/where I would have picked up this file, I'm guess as I've popped different board groups in an out. I have to check out for the night but this is what I plan to come back to later this week and hope I can figure out how to get the board back up and running again.

amosmj
 
Posts: 5
Joined: Mon May 08, 2017 10:24 am

Re: code.py is corrupted

by dhalbert on Mon Jun 19, 2017 10:20 pm

I meant drivers in the Apps list, not anything in the Arduino IDE. The board packages are fine. In the Arduino Boards Manager, install Arduino SAMD and Adafruit SAMD (reinstall if that's what you removed).

After you do that, trying compiling and uploading the example Blink sketch from the Arduino IDE and get it to run? Try the double-click technique described here: https://learn.adafruit.com/adafruit-met ... help#faq-3. Once you get Blink to upload and work, then try flash_erase again. Finally reload CircuitPython by double-clicking and then copying the CircuitPython .uf2 file to METROBOOT.

dhalbert
 
Posts: 401
Joined: Tue Feb 17, 2015 6:18 pm

Re: code.py is corrupted

by dhalbert on Mon Jun 19, 2017 11:12 pm

Forgot to say: flash_erase prompts you from the serial console in Arduino to confirm you really want to erase the flash.

As an alternative to all that, I've created a version of flash_erase for the Metro M0 Express that you can just upload to erase the flash, without prompting. This will be much easier than getting Arduino working. This is experimental. Warning to others: this will erase everything in CIRCUITPY!

1. Download https://drive.google.com/file/d/0B4kZE3 ... sp=sharing. It will be named flash_erase_no_prompt.ino.metro_m0.uf2.
2. Double-click reset on your Metro M0 Express. METROBOOT should appear as a drive.
3. Drag flash_erase_no_prompt.ino.metro_m0.uf2 to METROBOOT. It will start executing.
4. After 10-15 seconds, the small LED nearest the USB connector should start blinking once per second. If it blinks twice or three times a second, something has failed.
5. Double-click reset again and drag the CircuitPython .uf2 you want to use to METROBOOT.
6. CIRCUITPY will appear and will now be empty except for the file boot_out.txt.

Let me know if that works.

dhalbert
 
Posts: 401
Joined: Tue Feb 17, 2015 6:18 pm

Re: code.py is corrupted

by amosmj on Wed Jul 05, 2017 9:01 pm

That totally nailed it.

Sorry for the slow reply. We were busy selling our house and it ate up more time than I expected.

That solution was great. I spent 90 minutes working on this on my own this evening before wandering back to this thread to see what you called for next. I wish I had come sooner, I could have been playing with a bread board that whole time.

Thank you very much for you patience.

amosmj
 
Posts: 5
Joined: Mon May 08, 2017 10:24 am

Re: code.py is corrupted

by tannewt on Wed Jul 05, 2017 9:58 pm

Glad you got it going @amosmj! Thanks for your awesome instructions @dhalbert.

tannewt
 
Posts: 1837
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.