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

nRF52840 SDK16 - QSPI example - External flash memory

Hi everyone,

I am following the qspi example to communicate with MX25R6435F flash memory. This is my first time interacting with a flash memory and I have some questions regarding writting the flash memory

According to the example, to write the flash the following function is used

* @param[in] p_tx_buffer      Pointer to the writing buffer.
 * @param[in] tx_buffer_length Size of the data to write.
 * @param[in] dst_address      Address in memory to write to.
 *
 * @retval NRFX_SUCCESS            The operation was successful (blocking mode) or operation
 *                                 was commissioned (handler mode).
 * @retval NRFX_ERROR_BUSY         The driver currently handles other operation.
 * @retval NRFX_ERROR_INVALID_ADDR The provided buffer is not placed in the Data RAM region
 *                                 or its address is not aligned to a 32-bit word.
 */
nrfx_err_t nrfx_qspi_write(void const * p_tx_buffer,
                           size_t       tx_buffer_length,
                           uint32_t     dst_address);

So, I want to store the data from an IMU and the payload is 38 bytes. So in order to write the first 38bytes:

nrf_drv_qspi_write(m_buffer_tx, QSPI_TEST_DATA_SIZE, 0);

The next 38bytes

nrf_drv_qspi_write(m_buffer_tx, QSPI_TEST_DATA_SIZE, 0x26);

The next 38bytes

nrf_drv_qspi_write(m_buffer_tx, QSPI_TEST_DATA_SIZE, 0x4C);

and so on.. Is this correct?

Is it correct to set the QSPI_TEST_DATA_SIZE equals to 38 or it should be 256?

In general I have to always keep track of the current memory segment that is written right?

What is happening when flash is full? I have to erase memory block before write new data or I can just overwrite the existing?

Is there any example with a filling system using MX25R6435F and QSPI?

Thanks in advance

Nick

Parents
  • Hi Nick

    A critical aspect of the QSPI interface is that it can only write or read 32-bit values. This means that the data you send or receive has to be 4 byte aligned. 

    In other words writing 38 bytes in one go will not work, you have to pad it up to 40 bytes. 

    Other than that you can change the tx_buffer_length to other values if you like, it doesn't have to be 256 bytes. 

    In general I have to always keep track of the current memory segment that is written right?

    That is probably the best approach. 

    You could read back the external data content to see how much of the memory you have used, but this would lead to more overhead than if you just store the current address in the RAM of the nRF52840 device. 

    What is happening when flash is full? I have to erase memory block before write new data or I can just overwrite the existing?

     Because of the way flash memory works you have to erase the entire page before you can write new data, that is correct. The page size depends on the memory module used. 

    Is there any example with a filling system using MX25R6435F and QSPI?

    Not quite sure what you mean about a filling system?

    The only examples we have for QSPI are the following:

    \nRF5_SDK_17.0.2_d674dde\examples\peripheral\qspi

    \nRF5_SDK_17.0.2_d674dde\examples\peripheral\usbd_msc

    Best regards
    Torbjørn

  • Thank you for your great answer!!

    Not quite sure what you mean about a filling system?

    Sorry, I mean file system. Because if I have understand correclty fds module can only be used with the internal flash..

  • Hi Nick

    The usbd_msc example uses the fat_fs file system to write to the external flash, or to an SD card if you set the USE_SD_CARD define in main.c

    Essentially the fat_fs driver is designed to allow you to easily replace the hardware interface, depending on which of the nrf_block_dev_xxx.c implementations you use. 

    nrf_block_dev_qspi.c uses QSPI, while the nrf_block_dev_sdc.c implementation uses SPI. 

    Best regards
    Torbjørn

  • I am happy to help Nick. Good luck with your project Slight smile

Reply Children
No Data
Related