I had 2 problems with the programming of the flash.
- The top two bits weren't getting set when they were different from the previous address bit.
- The first few writes after a sector erase were failing
I found the solution to each
The top two bits, i.e. bits 16 and 17 weren’t getting written. It turns out it’s because the Arduino Atmel part is a 16 bit address space and I had forgotten that sizeof(void) == sizeof(int). I was using void to show that the addresses were addresses. But, now they are proper 32 bit integers.
The other problem was thanks to my having forgotten which edge the write happens on write enable. I was bringing WR and CS down at the same time I started driving the data bus. Then I would be careful to ensure that the data was driven before and after the rising edge of WR. I actually have to ensure that the data bus is driven before the falling edge.
On top of that, I revamped the slow but simple serial protocol into something a little more complex and feature filled. The Arduino can now send back human readable progress strings while it’s doing its thing, so I don’t have to debug with the one LED. There is also support for sending bulk packets in 256 byte chunks for reading, writing, and verifying.
I did have a problem getting the serial port to work at 19200 baud. Set the baud rate to 19200 at both ends, and communication was not possible. So I’m back at 9600 for now. I suspect it’s a limitation of the virtual COM3 port that goes through the cable to the Arduino.