How to write to an external memory - Kyuchumimo/Micro-Joy-Home-Video-Computer GitHub Wiki
⚠️ Before continuing, make sure you have the libraries corresponding to the type of memory you want to work with.
See: https://github.com/peterhinch/micropython_eeprom/ and https://github.com/micropython/micropython-lib/blob/master/micropython/drivers/storage/sdcard/sdcard.py/
Flashing is useful for saving your programs or data to a medium or for writing a binary to the flash memory of the WT588D voice module.
There are two ways to access external memory: via byte-level access or via virtual filesystem access.
Byte-level access
With byte-level access, you have access to the entire memory space and can read and write bytes in the same way you would with bytearrays. This method is useful for writing raw data, such as a disk image, binary file, or ROM, to external memory.
A tool for this task can be found in this same repository. See: tools/wt588d_flash.py
To write a binary to external memory, you must upload the binary within the development board virtual filesystem. If the binary is too large for the internal memory of the development board, you can use and mount another external memory to the development board virtual filesystem like an SD card as shown below in the “Virtual filesystem access” section.
The tool is programmed to use SD cards by default, but you can use any medium. Just import the libraries to the corresponding medium, its pinout, and the path of the binary to be written in the filename variable, run the script, and after a few seconds it will be finished.
Virtual filesystem access
⚠️ If the medium is blank, you must first format it before mounting so that it is compatible with the development board virtual filesystem. Use the FAT12/16/32 format for SD cards and the littlefs v2 format for FLASH, EEPROM, FRAM, and SPIRAM memory types.
With virtual file system access, you can create, upload, move, rename, and delete files and directories on external memory as if it were a mass storage device. This is useful for writing all types of files, including audio, images, documents, videos, programs, etc.
First, you must mount the external memory so that it is accessible to the virtual file system. Once this is done, the external memory should appear as a new folder corresponding to the medium (The naming convention is "sd" for SD card, "fl_ext" for FLASH, "eeprom" for EEPROM, "fram" for FRAM and "ram" for SPIRAM. Alternatively, you can name the devices as you see fit). Remember to use the refresh option if you do not see the aforementioned folder.
Thonny's File explorer
To view the file system in Thonny, simply go to the “View” tab and select the “Files” option. A column will then appear on the left side of the window showing the files on your personal computer at the top and your development board at the bottom, where you can manage them.