Adding EEPROM reading/writing to test shell

Posted on Sat 13 July 2024 in MUPS16

Before testing the new control boards, all of which are driven off a single SPI EEPROM chip containing the microcode, I needed to add code to the Arduino server to read and write SPI ROMs, again - this was in the old version of the server, but not ported over.

Adding custom commands is pretty easy. The only wrinkle was that since we can't send the whole contents in one message (the Arduino does not have enough RAM to buffer it), I had to add support for reading multiple messages for one command, so a write consists of sending a WriteEEPROMMessage with the last flag set to 0, then multiple MemoryDataMessage s.

ROM writing seemed to work fine, first time, which was a surprise.

First ROM read looks good. For a read from address 0x10 we see the 0x3 byte for READ, then the 0x0010 address (MSB first):

Repeating the exact same read shows the first byte of the address missing:

The only thing that fixes this is power-cycling the Arduino.

Update: this turned out to be because I was missing calls to SPI.begin() and SPI.end() at the start and end of my Arduino code to read the ROM chip. According to the source code if the cs line changes to an input and goes high at any point the Arduino switches to slave mode, which might explain the strange behaviour (I revert the cs line to its previous mode - which defaults to input on startup - at the end of each SPI operation) . With calls to SPI.begin() and SPI.end() added it works properly.

(normal ROM contents replaced with Sherlock Holmes, since I find it much easier to spot mistakes, gaps, repetition etc. in plain text). Note to self: don't forget to flash the proper memory contents back afterwards next time - that caused a good few minutes of puzzlement trying to work out why the control unit was misbehaving so badly suddenly, as it tried to interpret Sir Arthur Conan Doyle's finest as microcode.