
Memory Management
One of the main functionalities of our printer is the ability to read instructions from a GCODE file. We decided on using USB for its ubiquity. We have also developed and tested using an SD flash card instead of a USB. The flashcard was a backup in case we could not get the USB to work. Below is a block diagram of memory. You can see that we do not just read a USB drive, but instead store it to a local NOR flash memory chip. Since we cannot store the entire GCODE file in the MCU we would have to either read from the USB in chunks or store it locally. Reading from the USB in chunks introduces huge latencies between every read. Thus to avoid those problems, we used a NOR flash memory chip to store the GCODE file and provide a fast recall of instructions.
​
The overall process of the memory chain is to read from the USB in chunks using DMA. Then we transfer that chunk to the flash memory. This process is repeated until the entire file is stored in the flash chip, ready to issue instructions to the motors.

NOR Flash Memory
We chose to use a Winbond memory chip. The part number is W25Q32FV. It can store up to 32 MB, which is large enough to hold multiple GCODE files. It can operate on clocks up to 104 MHz. We use it in normal SPI operation and can read 2.6 million GCODE instructions per second. This is more than enough to keep up with the operation of the motors. Below is the schematic for the chip.


A couple of notes on operation: a sector must be erased before written. Furthermore, during our testing, we were writing to the same memory address every time. This wore out those bits and caused unreliable reads. The solution was to keep a temporary copy of the instruction and after every write, read the instruction back and compare it to the original. If the instruction was not stored correctly, rewrite the instruction until it is stored correctly. A checksum could also be used if MCU memory is scarce.
​
We were not able to implement the full storing algorithm. It would be very similar to the current one but increment sectors every chunk stored.
USB

Testing USB:
​
For our initial testing of USB, we used Sparkfun's USB Type A breakout and first worked on reading a file from the USB and printing it out to UART. We used Tiva's libraries and found usb_host_msc to have the most similar code to what we were trying to accomplish. However there were some changes to be made since their code only prints the file structure and we wanted to read the file in addition to printing the file structure. To test we were writing the entire file we would write it to flash, read it back from flash, and read it from the USB. Then we would compare the two files over UART to ensure that the file was written correctly.
On our board set up, we connected PD4: D- and PD5: D+
​
​
​
​


USB Code Initialization:
Here is an example of our initialization code for USB, more extensive code can be found in the code section of this website and our Github.

SD Card
The primary purpose of using an SD card before USB, was so that we would have a backup in case USB proved to be overly difficult. Additionally it put us in a good position knowledge wise to understand the overall methods of interfacing memory.
Similarly to USB we used UART to see what files we were writing and reading back. We ended up finding an example code that provided us with the ability to use command line commands to read files back. We demonstrated this functionality in our Proof of Concept demonstrations to show we were transferring files from SD->Flash correctly.
​

Here we show our main function for the SD card read with the flash. We only tested with smaller files so that we could just prove some sort of functionality for demos since we planned (and accomplished) reading larger files with USB. Here we have a busy loop that waits until the user enters a command that is "cat filename" then the filename is written to flash, read back, and printed over UART to verify it was written correctly. The rest of the code with descriptive comments can be found in our github linked to in the code section of this website.


