add fatfs update when there is usbmsc write
This commit is contained in:
1 parent
ee5a2e490a
commit
09bf2f47b8
5 files changed
+32
-17
No files matched your search
@@ -155,7 +155,10 @@ bool FatFS::begin (void)
|
||||
|
||||
bool FatFS::format (bool eraseall)
|
||||
{
|
||||
if ( eraseall ) VERIFY(flash_qspi_chiperase());
|
||||
if ( eraseall )
|
||||
{
|
||||
VERIFY(flash_qspi_chiperase());
|
||||
}
|
||||
|
||||
uint8_t workbuf[FF_MAX_SS];
|
||||
VERIFY_FAT(f_mkfs("", FM_FAT | FM_SFD, 4096, workbuf, FF_MAX_SS), false);
|
||||
@@ -359,6 +362,22 @@ void FatFS::_f_rewindDirectory (void* fhdl)
|
||||
VERIFY_FAT(f_rewinddir((DIR * ) fhdl),);
|
||||
}
|
||||
|
||||
// for USB MSC to check and update fatfs sector cache
|
||||
void FatFS::_usbmsc_write (uint32_t lba, void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
VERIFY(_fs,);
|
||||
if ( (lba <= _fs->winsect) && (_fs->winsect < (lba + bufsize / FF_MAX_SS)) )
|
||||
{
|
||||
memcpy(_fs->win, buffer + FF_MAX_SS * (_fs->winsect - lba), FF_MAX_SS);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void ExternalFS_usbmsc_write (uint32_t lba, void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
ExternalFS._usbmsc_write(lba, buffer, bufsize);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -69,6 +69,9 @@ class FatFS: public BluefuritLib::FileSystemClass
|
||||
virtual BluefuritLib::File _f_openNextFile (void* fhdl, char const* cwd, uint8_t mode);
|
||||
virtual void _f_rewindDirectory (void* fhdl);
|
||||
|
||||
// called when Flash contents is changed out of the awareness of ExternalFS such as USB MSC write
|
||||
void _usbmsc_write (uint32_t lba, void const* buffer, uint32_t bufsize);
|
||||
|
||||
private:
|
||||
FATFS* _fs;
|
||||
bool _begun;
|
||||
@@ -79,4 +82,8 @@ class FatFS: public BluefuritLib::FileSystemClass
|
||||
|
||||
extern FatFS ExternalFS;
|
||||
|
||||
// C to CPP call bridge for update fatfs cached sector
|
||||
extern "C" void ExternalFS_usbmsc_write (uint32_t lba, void const* buffer, uint32_t bufsize);
|
||||
|
||||
|
||||
#endif /* EXTERNALFS_H_ */
|
||||
Reference in new issue
Block a user