1
\$\begingroup\$

Hardware Target: I am using the STM32L4R9IDISCOVERY board

enter image description here

Achievement 1: Building a little-fs file system, reading & writing files in the OSPI Flash memory with these functions:

int block_device_read(const struct lfs_config *c, lfs_block_t block,
    lfs_off_t off, void *buffer, lfs_size_t size)
{
    BSP_OSPI_NOR_Read((uint8_t*) buffer, (block * c->block_size + off), size);
    return 0;
}
int block_device_prog(const struct lfs_config *c, lfs_block_t block,
    lfs_off_t off, const void *buffer, lfs_size_t size)
{
    BSP_OSPI_NOR_Write((uint8_t*)buffer, (block * c->block_size + off), size);
    return 0;
}
int block_device_erase(const struct lfs_config *c, lfs_block_t block)
{
    BSP_OSPI_NOR_Erase_Block(block);
    return 0;
}
int block_device_sync(const struct lfs_config *c)
{
    return 0;
}

Achievement 2: To be able to load the USB Device Mass Storage Stack & use it with RAM Memory, configuring correctly the usbd_storage_if.c file:

uint8_t buffer[STORAGE_BLK_NBR*STORAGE_BLK_SIZ];

int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
  memcpy(buf, &buffer[blk_addr*STORAGE_BLK_SIZ], blk_len*STORAGE_BLK_SIZ);
}
int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
  memcpy(&buffer[blk_addr*STORAGE_BLK_SIZ], buf, blk_len*STORAGE_BLK_SIZ);
}

Functional target: Now, I am trying to use the OSPI External Flash with a USB Device access. I would like to be able to plug the board on my computer to detect it as a USB Mass Storage so using FATFS and not little-fs

The OSPI Flash memory is the same 512Mbit NOR Flash (Ref MX25LM51245G).

I don't find how to code the same STORAGE_Read_FS & STORAGE_Write_FS functions. With many tries, sometimes the USB device is not recognized and some times I am not able to format the file system. How to adapt my BSP_OSPI_NOR_Write & BSP_OSPI_NOR_Read functions to these USB functions?

Additional information: The flash internal configuration is the following:

#define MX25LM51245G_FLASH_SIZE                   0x4000000 /* 512 MBits => 64 MBytes */
#define MX25LM51245G_BLOCK_SIZE                   0x10000   /* 1024 blocks of 64 KBytes */
#define MX25LM51245G_SECTOR_SIZE                  0x1000    /* 16384 sectors of 4 kBytes */
#define MX25LM51245G_PAGE_SIZE                    0x100     /* 262144 pages of 256 bytes */
\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.