Make colorchord work with W25Q40 memory, using the window of flash after the IRAM loaded section.

This commit is contained in:
cnlohr 2015-08-28 02:36:36 -04:00
parent c90a00e290
commit 997ad27cc2
6 changed files with 60 additions and 13 deletions

View file

@ -6,6 +6,26 @@
#include "spi_flash.h"
#include "ets_sys.h"
uint32 mfs_at = 0;
void FindMPFS()
{
uint32 mfs_check[2];
EnterCritical();
flashchip->chip_size = 0x01000000;
spi_flash_read( MFS_START, mfs_check, sizeof( mfs_check ) );
if( strncmp( "MPFSPFS", mfs_check ) == 0 ) { mfs_at = MFS_START; goto done; }
spi_flash_read( MFS_ALTERNATIVE_START, mfs_check, sizeof( mfs_check ) );
if( strncmp( "MPFSPFS", mfs_check ) == 0 ) { mfs_at = MFS_ALTERNATIVE_START; goto done; }
done:
flashchip->chip_size = 0x00080000;
ExitCritical();
}
extern SpiFlashChip * flashchip;
//Returns 0 on succses.
@ -14,9 +34,18 @@ extern SpiFlashChip * flashchip;
//Returns -1 if can't find file or reached end of file list.
int8_t MFSOpenFile( const char * fname, struct MFSFileInfo * mfi )
{
if( mfs_at == 0 )
{
FindMPFS();
}
if( mfs_at == 0 )
{
return -1;
}
EnterCritical();
flashchip->chip_size = 0x01000000;
uint32 ptr = MFS_START;
uint32 ptr = mfs_at;
struct MFSFileEntry e;
while(1)
{
@ -51,7 +80,7 @@ int32_t MFSReadSector( uint8_t* data, struct MFSFileInfo * mfi )
EnterCritical();
flashchip->chip_size = 0x01000000;
spi_flash_read( MFS_START+mfi->offset, (uint32*)data, MFS_SECTOR );
spi_flash_read( mfs_at+mfi->offset, (uint32*)data, MFS_SECTOR );
flashchip->chip_size = 0x00080000;
ExitCritical();

View file

@ -11,6 +11,10 @@
#include "mystuff.h"
//SPI_FLASH_SEC_SIZE 4096
//If you are on a chip with limited space, MFS can alternatively live here, with a max size of 180kB.
#define MFS_ALTERNATIVE_START 0x10000
#define MFS_STARTFLASHSECTOR 0x100
#define MFS_START (MFS_STARTFLASHSECTOR*SPI_FLASH_SEC_SIZE)
#define MFS_SECTOR 256