This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Port fatfs to external SPI FLASH on 52832?

Hi All,

We have a product that requires the use of the file system Fatfs, which is plugged into the external SPI FLASH.
Therefore, the hardware platform used is: n52832 + W25x10 (NOR FLASH)
The software uses SDK16.0, the path from the SDK .. \ examples \ peripheral \ fatfs uses the SD card, I want to realize the function of loading external FLASH to load Fatfs on the basis of this project?

I checked the example code of fatfs and found that the path: .. \ components \ libraries \ block_dev supports multiple media, but unfortunately there is no NOR FLASH.
How to load fatfs in NOR FLASH?

Thanks,

Parents
  • There is is a old French saying for "T'en a du pain sur la planche".  Which means you got work to do.  First of, Flash is not Fat formatted so you got to format it yourself. Second Flash erasable block varies from 4KB to 64KB.  So before a write can be made.  You need to erase the whole block. You got to manually manage that too. You are going to have fun with it because each sector size is 512 bytes.  So each time you write a sector, you copy a full block from flash to Ram. Write your sector to ram block at the right offset. Erase the flash block. Write the block from ram back to flash. I would recommend you use MMC instead. It's equivalent to SDCard but in form if chip. 

  • Thank you for your reply, this is really a difficult task.
    FLASH capacity is 1Mbytes, sector unit is 4kbytes, block size is 64kbytes / 32kbytes, page size is 256bytes.
    Write support page, erase support sector and block.

    So, I have many questions, please support:
    1. How to format flash to Fat?
    Is this reasonable?
    ff_result = f_mkfs ("0:", FM_FAT, 0, gFsWork, 4096);
    2. I understand the operation of the flash block, read it first, then erase it, and write it again.
    The block size is 64k / 32k, and the total memory size of n52832 is only 64k. This problem is too difficult. So I can choose to erase by sector, which only takes up 4k of memory.
    I found result = MMC_disk_write (buff, sector, count); and result = MMC_disk_read (buff, sector, count) in the driver file of fatfs.
    Flashes are operated by the sector, so I only need to erase the sector before disk_write?

    Sector operations do bring speed limitations.

    Thanks

  • Not sure what will to happen when you set a sector of 4KB.  A disk sector is 512 bytes and cluster can be 4KB but sector of 4KB ??? Don't know.  Let me know the results.

Reply Children
  • This is the FLASH DS that I used.
    The size of the sector marked above is 4k.

    XTX_SPI_NOR_XT25F08B_Rev 1.5.pdf

  • I didn't mean the flash.  I meant the Fat Filesystem specs.

  • Sorry,Fatfs for ffconf.h code:ffconf.h

    #define	_MIN_SS		4096
    #define	_MAX_SS		4096
    /* These options configure the range of sector size to be supported. (512, 1024,
    /  2048 or 4096) Always set both 512 for most systems, all type of memory cards and
    /  harddisk. But a larger value may be required for on-board flash memory and some
    /  type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
    /  to variable sector size and GET_SECTOR_SIZE command must be implemented to the
    /  disk_ioctl() function. */

    The path of the file is:..\external\fatfs\src

    Thanks,

  • Ok, that's great.  Then it shouldn't be a problem.  I didn't it supports larger sector size.  good to know.

  • So,is there a good way to implement the following two driver functions?
    The n52832's spi interface limits 255B, which means read up to 255B and write up to 251B, and the fatfs interface is sector (4K)

    I found result = MMC_disk_write (buff, sector, count); and result = MMC_disk_read (buff, sector, count) in the driver file of fatfs.

    /**
     * @brief Function for starting the SPI data transfer.
     *
     * If an event handler was provided in the @ref nrf_drv_spi_init call, this function
     * returns immediately and the handler is called when the transfer is done.
     * Otherwise, the transfer is performed in blocking mode, which means that this function
     * returns when the transfer is finished.
     *
     * @note Peripherals using EasyDMA (for example, SPIM) require the transfer buffers
     *       to be placed in the Data RAM region. If they are not and an SPIM instance is
     *       used, this function will fail with the error code NRF_ERROR_INVALID_ADDR.
     *
     * @param[in] p_instance       Pointer to the driver instance structure.
     * @param[in] p_tx_buffer      Pointer to the transmit buffer. Can be NULL
     *                             if there is nothing to send.
     * @param     tx_buffer_length Length of the transmit buffer.
     * @param[in] p_rx_buffer      Pointer to the receive buffer. Can be NULL
     *                             if there is nothing to receive.
     * @param     rx_buffer_length Length of the receive buffer.
     *
     * @retval NRF_SUCCESS            If the operation was successful.
     * @retval NRF_ERROR_BUSY         If a previously started transfer has not finished
     *                                yet.
     * @retval NRF_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data
     *                                RAM region.
     */
    __STATIC_INLINE
    ret_code_t nrf_drv_spi_transfer(nrf_drv_spi_t const * const p_instance,
                                    uint8_t const * p_tx_buffer,
                                    uint8_t         tx_buffer_length,
                                    uint8_t       * p_rx_buffer,
                                    uint8_t         rx_buffer_length);

Related