I'm working on a project using a FRDM-KL82Z board, with the MKL82Z128 microcontroller. I use the SEGGER J-Link EDU programmer and MCUXpresso 10.0.2 IDE.
I want to write data from the MCU to the external flash, which is the MX25L12845G.
I have no experience working with neither QSPI nor flash, so I've taken the frdmkl82z_driver_examples_qspi_polling_transfer example from the SDK and the datasheet as a reference. I think I more or less understand how to make it work, although I have some questions.
I've been able to write data with size between 16 and 64 bytes (limits included) and more or equal to 80 bytes. I know how to manage the jump to the next page and so on. In the flash datasheet (MX25L12845G, Page 6) it says that it can be written in byte, word or page mode.
From my understanding, the way to write to Flash is writing data into the TxFIFO (which has 16 positions of 4 bytes each = 64 bytes). The example uses the QSPI_WriteBlocking function, which asks for 16 or more bytes of data with the initial assert. If I want to write more than 64 bytes, once the TxFIFO is full the QSPI_WriteBlocking function waits until there's a free position in the FIFO and adds the next one.
I have tried to modify the assert in the QSPI_WriteBlockingi function to see what happens if I try to write less than 16 bytes (12, 8 or 4 bytes) and the program writes the number or elements I tell him but it writes all 0s. If I follow the fsl functions I see that the QuadSPI TBDR (TX Buffer Data Register) gets the values I tell him, so it seems as something in a lower level. The IP commands doesn't seem to have any parameter that could solve this, except the QSPI_SetIPCommandSize, which I give the number of bytes to write and seems to work for the range of values that I mentioned before.
Also, I don't know when the QSPI_SoftwareReset function is needed to be used. The SDK example uses it every page write, but there's no info about why it is needed.
Does anyone know how to do it? I'd be very grateful as I've been some days trying to figure it out but I haven't succeeded.
Thank you so much,
you can write any number of data into NOR flash byte QSPI interface. There is 3 point you must take care. for example, if you want to write a byte into flash:
1. In LUT, you must set the data number to 1, looks like
 = QSPI_LUT_SEQ(QSPI_WRITE, QSPI_PAD_1, 0x1, 0, 0, 0),
2. Write the data number into IPCR register
3. A write transaction on the flash with data size of less than 32 bits will lead to the removal of four data entry from the TX buffer. The valid bits will be used and the rest of the bits will be discarded. So, you should write data 4 times even only 1 byte write.
Thank you so much jingpan, the LUT setting is what I was missing, now it lets me write. For anyone doing the same as me, be careful with clearing the FIFO, you may need to do so depending on how you organise your writes!