Open rtek1000 opened 5 years ago
Currently attempting to implement USB mass storage on the STM32 with a spiflash. My understanding is W25QXX chips run at a page size of 256 bytes, meanwhile the standard assumption of sd cards (subsequently sdfat) is a sector size of 512 bytes. This means the read and write would end up with incomplete data.
bool write(const uint8_t *writebuff, uint32_t startSector, uint16_t numSectors) {
// return sd.card()->writeBlocks(startSector, writebuff, numSectors);
return flash.writeBlocks(startSector, writebuff, numSectors);
}
bool read(uint8_t *readbuff, uint32_t startSector, uint16_t numSectors) {
// return sd.card()->readBlocks(startSector, readbuff, numSectors);
return flash.readBlocks(startSector, readbuff, numSectors);
}
My idea is to have it read 2 pages and write 2 pages (note I've used different libraries, untested code):
bool write(const uint8_t *writebuff, uint32_t startSector, uint16_t numSectors) {
flash.releasePowerDown();
for (int i = 0; i < numSectors; i++)
{
for (int j = 0; j < 256; j++)
{
flash.write((startSector + i) * 2, j, *(writebuff + j));
}
for (int j = 0; j < 256; j++)
{
flash.write(((startSector + i) * 2) + 1, j, *(writebuff + j + 256));
}
}
flash.powerDown();
return true;
}
bool read(uint8_t *readbuff, uint32_t startSector, uint16_t numSectors) {
flash.releasePowerDown();
for (int i = 0; i < numSectors; i++)
{
for (int j = 0; j < 256; j++)
{
*(readbuff + j) = flash.read((startSector + i) * 2, j);
}
for (int j = 0; j < 256; j++)
{
*(readbuff + j + 256) = flash.read(((startSector + i) * 2) + 1, j);
}
}
flash.powerDown();
return true;
}
I will report back later.
Regarding the formatting, what is the issue with formatting via windows into a fat16? I don't have a very good understanding of how it all works, but isn't it just reading/writing raw bytes at the end of the day?
With the help of another library, it was possible to replace the SD card with a SPI flash memory.
But Windows cannot format the memory.
W25Q64 flash memory is only 8MB (64Mbit) and if the library's own formatter is used, Windows can correctly find the available 8MB space. But when trying to format in Windows 10 x64 Explorer, the size of 4GB appears and then the formatting does not end.
Formatter:
Source: https://github.com/adafruit/Adafruit_SPIFlash/tree/master/examples/SdFat_format
USB Reader:
Adafruit SPI Flash, for FAT filesystems on SPI flash chips: https://github.com/adafruit/Adafruit_SPIFlash
[Blue Pill STM32F103C8T6] Works!!! USB Mass Storage W28Q64 (Like a SD card Reader): https://github.com/adafruit/Adafruit_SPIFlash/issues/24#issue-496958474