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
@@ -58,7 +58,7 @@ static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len);
|
||||
static uint32_t fal_read (void* dst, uint32_t src, uint32_t len);
|
||||
static bool fal_verify (uint32_t addr, void const * buf, uint32_t len);
|
||||
|
||||
uint8_t _cache_buffer[FLASH_CACHE_SIZE] __attribute__((aligned(4)));
|
||||
static uint8_t _cache_buffer[FLASH_CACHE_SIZE] __attribute__((aligned(4)));
|
||||
|
||||
static flash_cache_t _cache = {
|
||||
.erase = fal_erase,
|
||||
|
||||
@@ -82,7 +82,7 @@ static uint32_t fal_qspi_program (uint32_t dst, void const * src, uint32_t len);
|
||||
static uint32_t fal_qspi_read (void* dst, uint32_t src, uint32_t len);
|
||||
static bool fal_qspi_verify (uint32_t addr, void const * buf, uint32_t len);
|
||||
|
||||
uint8_t _cache_buffer[FLASH_CACHE_SIZE] __attribute__((aligned(4)));
|
||||
static uint8_t _cache_buffer[FLASH_CACHE_SIZE] __attribute__((aligned(4)));
|
||||
|
||||
static flash_cache_t _cache = {
|
||||
.erase = fal_qspi_erase,
|
||||
|
||||
@@ -109,22 +109,11 @@ int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* bu
|
||||
{
|
||||
(void) lun;
|
||||
|
||||
#ifdef MICROPY_HW_LED_MSC
|
||||
nrf_gpio_pin_write(MICROPY_HW_LED_MSC, MICROPY_HW_LED_MSC_ACTIVE_LEVEL);
|
||||
#endif
|
||||
|
||||
uint32_t wrcount = flash_qspi_write(lba * CFG_TUD_MSC_BLOCK_SZ + offset, buffer, bufsize);
|
||||
|
||||
// update fatfs's cache if address matches
|
||||
// fs_user_mount_t* vfs = MP_STATE_VM(vfs_mount_table)->obj;
|
||||
//
|
||||
// if ( (lba <= vfs->fatfs.winsect) && (vfs->fatfs.winsect <= (lba + bufsize / FLASH_API_BLOCK_SIZE)) ) {
|
||||
// memcpy(vfs->fatfs.win, buffer + FLASH_API_BLOCK_SIZE * (vfs->fatfs.winsect - lba), FLASH_API_BLOCK_SIZE);
|
||||
// }
|
||||
|
||||
#ifdef MICROPY_HW_LED_MSC
|
||||
nrf_gpio_pin_write(MICROPY_HW_LED_MSC, 1 - MICROPY_HW_LED_MSC_ACTIVE_LEVEL);
|
||||
#endif
|
||||
// update fatfs's cache if address matches
|
||||
extern ExternalFS_usbmsc_write (uint32_t lba, void const* buffer, uint32_t bufsize) ATTR_WEAK;
|
||||
if ( ExternalFS_usbmsc_write ) ExternalFS_usbmsc_write(lba, buffer, bufsize);
|
||||
|
||||
return wrcount;
|
||||
}
|
||||
|
||||
@@ -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