What could have corrupted NVM?

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
OutstandingBill
 
Posts: 60
Joined: Fri Nov 29, 2019 3:22 pm

What could have corrupted NVM?

Post by OutstandingBill »

I have an Itsy M4. I've been happily storing and retrieving a bunch of things in NVM for a while now.

Today, I added a couple of features to my code. If one of the pins is held low during boot, these new things happen:
1. boot.py does

Code: Select all

storage.remount("/", False)
.
2. code.py reads stuff from NVM and writes it to a text file on the board.
3. First time through, the code that writes the file must have had a bug in it, because it went through the "except" block. This may have been due to it writing an array where a string was expected. I wrapped it in "str()" and it avoided the "except" block after that.

Here's boot.py

Code: Select all

import time
import board
import digitalio
import storage

switch = digitalio.DigitalInOut(board.D7)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP

isUserWriteable = switch.value

if not isUserWriteable:
	storage.remount("/", False)

switch = None
Here's code.py

Code: Select all

def BackupWaveforms():
	saved = False
	try:
		waveforms = str(nvm.GetWaveforms())
		with open("/waveforms-backup.txt", "a") as fp:
			fp.write(waveforms)
		saved = True
	except Exception as e:
		saved = False
		print(e)
Immediately afterward this had run twice (once without "str", once with "str") , I found that there were a bunch of 0x00s scattered throughout NVM.

I can't imagine why any of that would have interacted with NVM, but since I haven't thought of a better explanation yet, I thought I'd ask...

Could any of those things have corrupted NVM?

User avatar
OutstandingBill
 
Posts: 60
Joined: Fri Nov 29, 2019 3:22 pm

Re: What could have corrupted NVM?

Post by OutstandingBill »

Is it perhaps because I didn't flush?

Code: Select all

fp.flush()
That does seem to have fixed it anyway.

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”