SPI Flash spin2 code
VonSzarvas
Posts: 3,450
in Propeller 2
Is there any spin2 code out there yet, to read/write from Flash memory, such as the Flash on the EVAL board ?
something as simple as this would be plenty:
Init
Write(addr, value)
Read(addr, value)
something as simple as this would be plenty:
Init
Write(addr, value)
Read(addr, value)
Comments
That seems like a perfect addition to GitHub, regardless of any other possible options. If you attach the code file here I could get it added to GitHub. Or submit at Github in the usual way if you prefer that route.
Oh, and thanks for sharing!
http://forums.parallax.com/discussion/171517/
You can read and write files, as if were uSD card...
Way I remember it is that formatting makes it all ones. Writing just turns some ones into zeros...
I've just created a pull request. Should be available within some days...
https://github.com/parallaxinc/propeller/tree/master/libraries/community/p2/Data Storage
I'm going to test the code tomorrow morning.
Having an issue with the WritePage function, as it appears to block and not return from Spi_Wait()
I have the Dip-Switch FLASH setting on, so that CS is connected to P61. And removed the SD card.
(This is with an Eval RevB and on-board flash)
Code attempted (which I expected from the code comments to copy 256 bytes from hub to flash):
WritePage($400, 0) ' hubAdr, flashAdr
I'm wondering if we need to call erase before write, or some other thing.
Would you have a example program you could share, perhaps that writes and verifies a 256 byte block?
In case, I tried the suggestion : spi.WritePage($400, $10_0000) ' hubAdr, flashAdr
However, same hang issue.
You might also be onto something about the indentation. Will be able to take a look in the morning- maybe something will stand out with another pair of eyes on the code.
Instructions:
Hardware : P2 Eval board, set the FLASH dip switch to ON, connect to PC with USB cable
Software : Open Propeller Tool and Parallax Serial Terminal
Load/run the file "FlashDemo"
Within 2 seconds, Enable the Parallax Serial Terminal (or equivalent)
Expected output on serial terminal :
Note: This archive includes a modified version of the @ManAtWork SpiFlash library, which works with PNut/PropellerTool
Caveat: The library works with the FlashDemo, but not tested beyond that. This submission not formatted, documented nor proven ready for GitHub yet.
Maybe cs or clock is getting held in smartpin mode, and so ignoring the drive low or high pin actions to release when needed. <guess> <guess>
1. If you don't test it it won't work no matter how trivial the task may seem.
2. A library that works in all cases is always at least 10 times harder to write than a short test that works on only one board.
I just ran a test with a repeat 100 loop of a erase-write-verify cycles for 5 times. It did 500 cycles without an error. Unfortunatelly I don't have the original P2EVAL board. I think I had connected the flash IC the samy way but maybe some pullup/pulldowns are different.
That shouldn't matter as long as the /CS signal is held high. Anyway, I don't reset or disable the clock smartpin at the end of an operation. I just output a finite sequence of 16 transitions = 8 pulses with wypin #16,#spi_ck. SPI_CK should stay stable when the counter expires.
I also checked the phase relation between CK and DI (P2 out) with the scope and it looks good. The only thing that is a bit uncertain is the delay between the CK edge and the sample point of the DO (P2 in) signal. But that shouldn't cause a hang. If the setup or hold time is violated, false data is read what only can cause a verify or read to fail or a Spi_Wait() finish too early or too late.
VonSzarvas, could you please test this one? the original 4 nops (without rep) were probably a bit close to the edge. Waitx #2 + rep should be equivalent to 3 nops and might work better.
Strange... and even more weired: If I take the bad code and remove one NOP it works, again! I have to disassemble the machine code to find the difference
Verify still misbehaving. That seems to work when verifying 64 bytes, but not 128 or 256
Not looked any further yet.
ps. Thanks for the update @ManAtWork , and for the extra tip @ersmith
By fixed, I mean that I replaced the RdByte code with that 3 posts up, and edited the rep.loop line ersmith suggested.
The buffer is cleared to -2 before each operation.
Only 0-63 can be read back at the moment.
<guess> Spi_RdByte doesn't understand values above 6 bits, or requires an extra pause or cs toggle each X bytes read ?