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 Reply
  • 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,

Children
  • 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);

  • Hi everyone,
    After 2 ~ 3 days of hard work, it successfully read and write Fatfs files at 52832.
    See attachment

    00> <info> app: Setting vector table to bootloader: 0x00078000
    00> 
    00> <info> app: Setting vector table to main app: 0x00026000
    00> 
    00> <info> app: system reaset:00000004
    00> 
    00> 
    00> 
    00> <info> app: soft reaset!
    00> 
    00> 
    00> 
    00> <info> app: Adv name:COVE10
    00> 
    00> <info> app: Firmware version:v0.00.03
    00> 
    00> <info> app: HRS FreeRTOS example started.
    00> 
    00> <info> app: 140: width:80,height:160
    00> 
    00> 
    00> 
    00> <info> app: indev button init done
    00> 
    00> <info> app: Initializing disk 0 (SPI FLASH)...
    00> 
    00> <info> app: jedec_id=0xB4014
    00> 
    00> <info> app: Disk initialization success.
    00> 
    00> <info> app: display notif test
    00> 
    00> <info> app: display notif test
    00> 
    00> <info> app: jedec_id=0xB4014
    00> 
    00> <info> app: Open file :0[0:create,Other:len]
    00> 
    00> <info> app: Writing to file cove.bin ...
    00> 
    00> <info> app: 15 bytes written.
    00> 
    00> <info> app: Close to file cove.bin ...
    00> 
    00> <info> app: Unmount...
    00> 
    00> <info> app: display notif test
    00> 
    00> <info> app: display notif test
    00> 
    00> <info> app: display notif test
    00> 
    (Connection lost)
    00> <info> app: Setting vector table to bootloader: 0x00078000
    00> 
    00> <info> app: Setting vector table to main app: 0x00026000
    00> 
    00> <info> app: system reaset:00000004
    00> 
    00> 
    00> 
    00> <info> app: soft reaset!
    00> 
    00> 
    00> 
    00> <info> app: Adv name:COVE10
    00> 
    00> <info> app: Firmware version:v0.00.03
    00> 
    00> <info> app: HRS FreeRTOS example started.
    00> 
    00> <info> app: 140: width:80,height:160
    00> 
    00> 
    00> 
    00> <info> app: indev button init done
    00> 
    00> <info> app: Initializing disk 0 (SPI FLASH)...
    00> 
    00> <info> app: jedec_id=0xB4014
    00> 
    00> <info> app: Disk initialization success.
    00> 
    00> <info> app: display notif test
    00> 
    00> <info> app: display notif test
    00> 
    00> <info> app: jedec_id=0xB4014
    00> 
    00> <info> app: Open file :15[0:create,Other:len]
    00> 
    00> <info> app: Listing directory: /
    00> 
    00> File name len:8,contant:KAHA.TXT
    00> 
    00> File name len:8,contant:COVE.BIN
    00> 
    00> <info> app: Reading to file cove.bin ...
    00> 
    00> read len:15,content:www.coveiot.com
    00> 
    00> <info> app: Close to file cove.bin ...
    00> 
    00> <info> app: Unmount...
    00> 
    00> <info> app: display notif test
    00> 
    00> <info> app: display notif test
    00> 
    00> <info> app: display notif test
    00> 
    (Connection lost)

    The two functions of disk_read () and disk_write () are mainly implemented through the SPI interface.
    The main technique is to solve the interface limitation of n52832 and use 251bytes instead of 256bytes page operation. So 1MB Flash changed from the original 256Sector (1024 * 1024/4096) to 240Sector.

    Thanks,

  • Hi  I am working on the same application. Can you please share some example code? 

Related