K82 : qspi_polling example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K82 : qspi_polling example

Jump to solution
783 Views
EugeneHiihtaja
Senior Contributor I

Hello !

I would like to write data to NOT type of memory in small chunks 4-16 bytes long.

I'm looking example qspi_polling in latest SDK and can see the next implementation of function for write complete page :

/* Program page into serial flash using QSPI polling way */
void program_page(uint32_t dest_addr, uint32_t *src_addr)
{
.....

/* First write some data into TXFIFO to prevent from underrun */
QSPI_WriteBlocking(EXAMPLE_QSPI, src_addr, FSL_FEATURE_QSPI_TXFIFO_DEPTH * 4);  // 64 bytes ?
src_addr += FSL_FEATURE_QSPI_TXFIFO_DEPTH;

/* Start the program */
QSPI_SetIPCommandSize(EXAMPLE_QSPI, FLASH_PAGE_SIZE);
QSPI_ExecuteIPCommand(EXAMPLE_QSPI, 16U);

leftLongWords = FLASH_PAGE_SIZE - 16 * sizeof(uint32_t);


QSPI_WriteBlocking(EXAMPLE_QSPI, src_addr, leftLongWords);

....
}

What it means on practice ?

Can it be so than usage of QSPI features limits minimal data chunk to 64 bytes  ( 32 bytes ) ?

And if I would like to write data by small chunks, I should use just SPI driver and NOR  memory driver ?

It looks like for me that usage of QSPI and EDMA bring limitations for size of data chunks and for my case

it is little bit problematic to use those.

How long can be minimal data chunk in case of QSPI and EDMA usage ?

I can use minimal possible buffer and fill extra bytes with 0xFF for avoid writing. Some data alignment can be kept as well.

Regards,

Eugene

0 Kudos
1 Solution
640 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Eugene,

Yes, I think it's fine.

Regards,

Jing

View solution in original post

5 Replies
640 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Eugene,

You can write to QSPI flash in any size. Attachment shows how to write in word or byte.

Regards,

Jing

0 Kudos
640 Views
EugeneHiihtaja
Senior Contributor I

Hi Jing !

could you post attachment again. It is not visible.

Thank you !

Eugene

0 Kudos
640 Views
jingpan
NXP TechSupport
NXP TechSupport

Ok, I try again.

0 Kudos
640 Views
EugeneHiihtaja
Senior Contributor I

Hi Jing !

I have review one more time our requirement and find out that we can write data by 32 bytes aligned chunks only.

So what ever we write it always 32*n byte long and it help to cross page boundary.

For fullfll this requirement I follow your example and common sense and modify LUT table and create write 32 byte routine.

Could you look code below. How it is looks like ?

/* Seq4: Data Program */
/* CMD: 0x02 - Page Program, Single pad */
/* ADDR: 0x18 - 24bit address, Single pad */
[16] = QSPI_LUT_SEQ(QSPI_CMD, QSPI_PAD_1, 0x02, QSPI_ADDR, QSPI_PAD_1, 0x18),
[17] = QSPI_LUT_SEQ(QSPI_WRITE, QSPI_PAD_1, 32, 0, 0, 0),  // 32 bytes only

/* Program 32byte into serial flash using QSPI polling way */
void program_data_32(uint32_t dest_addr, uint32_t *src_addr, size_t size) // size = 32 bytes always
{
   assert(!(dest_addr % 32));
   assert(!(size % 32));

   while (QSPI_GetStatusFlags(EXAMPLE_QSPI) & kQSPI_Busy)
   {
   }
   QSPI_ClearFifo(EXAMPLE_QSPI, kQSPI_TxFifo);

   QSPI_SetIPCommandAddress(EXAMPLE_QSPI, dest_addr);
   cmd_write_enable();
   while (QSPI_GetStatusFlags(EXAMPLE_QSPI) & kQSPI_Busy)
   {
   }

   /* Put data to fifo */
   QSPI_WriteBlocking(EXAMPLE_QSPI, src_addr, size); // 32

   /* Start the program */
   QSPI_SetIPCommandSize(EXAMPLE_QSPI, size);
   QSPI_ExecuteIPCommand(EXAMPLE_QSPI, 16U);

   /* Wait until flash finished program */
   check_if_finished();
   while (QSPI_GetStatusFlags(EXAMPLE_QSPI) & (kQSPI_Busy | kQSPI_IPAccess))
   {
   }
}

Thank you !

Regards,

Eugene

0 Kudos
641 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Eugene,

Yes, I think it's fine.

Regards,

Jing