Added support for SAM C21 J18A
- Device.cpp and Device.h adapted to know Sam C21
- Added sleep after command executing which is specified in Sam C2x/D2x datasheet
Using sleep to control program flow is almost always a bad idea and leads to brittle and difficult to maintain code. How were the sleep times determined and proven to be correct? How do the sleeps impact other devices in the D2xNvm family? Was this tested with all other devices in the D2xNvm family? What if the next device down the road needs a longer sleep?
If this device drops serial communication for some time after the command, then you should implement a retry loop in waitReady() instead of using sleep. I'm assuming the problem is that Samba::readWord is timing out and throwing an error. You should catch the error in waitReady() and retry the readWord a sane number of times before throwing an error. This type of implementation doesn't impact existing devices and is likely to work with devices down the road.
I got your point. I want to answer your questions anyway:
Sleep times: I have checked all supported device datasheets (D20/D21/R21/L20/L21/C20/C21) to make sure that they have all the same timings (NVM characteristics tFPP and tFRE)
Other devices and next devices: Currently all supported devices have the same characteristics. Only impact is that throwing the error will be delayed by 6ms (for supported and unsupported devices when failing)
Testing: Physically tested on C21 /D21 and D20 explained boards with SAM-BA firmware from ASF3 / SAM-BA windows PC application and BOSSA under linux.
I need to figure out if the SAM-BA firmware wont stuck when implementing a retry loop. Your assumption is right regarding waitReady.
But: From my point of view (3 explained boards / just using vanilla code) the current implementation wont work anyway (at least on todays fast PCs, might be working on a very slow one).
All-in-all one question is: How current code was proofen to be working when the problem is a systematic one (NVM page programming time and row erase time) ? Just want to understand why my setup fails without these modifications...