Write Operation On QSPI Flash in S32G

cancel
Showing results for 
Search instead for 
Did you mean: 

Write Operation On QSPI Flash in S32G

129 Views
SivaPrakashReddy
Contributor I

Hello Support Team,

Currently I am working on Flash Write operation using QSPI in S32G.
I went through S32G reference manual and application note for QSPI.

I followed LUT instructions for erase and erase happening successfully.
Now, I tried for write operation using LUT instructions as per reference manual.
1. Clear Tx Buffer
2. Fill Tx buffer with required data
3. Update size of data to be transfer in IPCR register
4. Update flash location/address in SFAR register
5. set write enable
6. set flash address
7. Do Sub-Sector Erase
8. Do write
9. Disable write

QUADSPI.MCR.B.CLR_TXF = 0; // Clearing Tx Buff

for(uint32_t i=0; i<256; i++)
{
QUADSPI.TBDR.B.TXDATA = 0xA0A0A0A0;
}

/* Unlock the LUT */
QUADSPI.LUTKEY.B.KEY = 0x5AF05AF0uL;
QUADSPI.LCKCR.R = 0x00000002; // Unlock the LUT for update

/* Set Write Enable Cmd */
QUADSPI.LUT[5].B.OPRND0 = 0x06;
QUADSPI.LUT[5].B.PAD0 = 0;
QUADSPI.LUT[5].B.INSTR0 = QUADSPI_CMD; // Enable Write At Flash Chip

QUADSPI.LUT[5].B.OPRND1 = 0x00;
QUADSPI.LUT[5].B.PAD1 = 0;
QUADSPI.LUT[5].B.INSTR1 = QUADSPI_STOP;

/*Send address*/
QUADSPI.LUT[10].B.OPRND0 = 0x20;
QUADSPI.LUT[10].B.PAD0 = 0;
QUADSPI.LUT[10].B.INSTR0 = QUADSPI_CMD; // 4K Erase At Flash- Chip

QUADSPI.LUT[10].B.OPRND1 = 0x18;
QUADSPI.LUT[10].B.PAD1 = 0;
QUADSPI.LUT[10].B.INSTR1 = QUADSPI_ADDR;

QUADSPI.LUT[11].B.OPRND0 = 0x00;
QUADSPI.LUT[11].B.PAD0 = 0;
QUADSPI.LUT[11].B.INSTR0 = QUADSPI_STOP;

QUADSPI.LUT[11].B.OPRND1 = 0x00;
QUADSPI.LUT[11].B.PAD1 = 0;
QUADSPI.LUT[11].B.INSTR1 = QUADSPI_STOP;

/*Send address*/
QUADSPI.LUT[15].B.OPRND0 = 0x02; // Flash Program
QUADSPI.LUT[15].B.PAD0 = 0;
QUADSPI.LUT[15].B.INSTR0 = QUADSPI_CMD;

QUADSPI.LUT[15].B.OPRND1 = 0x18;
QUADSPI.LUT[15].B.PAD1 = 0;
QUADSPI.LUT[15].B.INSTR1 = QUADSPI_ADDR;

QUADSPI.LUT[16].B.OPRND0 = 256; // Write Size
QUADSPI.LUT[16].B.PAD0 = 0;
QUADSPI.LUT[16].B.INSTR0 = QUADSPI_WRITE;

QUADSPI.LUT[16].B.OPRND1 = 0x00;
QUADSPI.LUT[16].B.PAD1 = 0;
QUADSPI.LUT[16].B.INSTR1 = QUADSPI_STOP;


QUADSPI.LUT[20].B.OPRND0 = 0x04; // Disable Write At Flash Chip
QUADSPI.LUT[20].B.PAD0 = 0;
QUADSPI.LUT[20].B.INSTR0 = QUADSPI_CMD;

QUADSPI.LUT[20].B.OPRND1 = 0x00;
QUADSPI.LUT[20].B.PAD1 = 0;
QUADSPI.LUT[20].B.INSTR1 = QUADSPI_STOP;

QUADSPI.LUT[21].B.OPRND0 = 0x00;
QUADSPI.LUT[21].B.PAD0 = 0;
QUADSPI.LUT[21].B.INSTR0 = QUADSPI_STOP;

QUADSPI.LUT[21].B.OPRND1 = 0x00;
QUADSPI.LUT[21].B.PAD1 = 0;
QUADSPI.LUT[21].B.INSTR1 = QUADSPI_STOP;

/* Lock the LUT again */
QUADSPI.LUTKEY.B.KEY = 0x5AF05AF0;
QUADSPI.LCKCR.R = 0x00000001;

/*Write Flash Address Into SFAR Register*/
QUADSPI.SFAR.B.SFADR = 0x8DA000;
// QUADSPI.IPCR.B.IDATSZ = 256;
QUADSPI.BUF0CR.B.ADATSZ = 32;

// QUADSPI.IPCR.B.PAR_EN = 0;
QUADSPI.IPCR.B.SEQID = 1;
while(1 == QUADSPI.SR.B.BUSY);
while(0 == QUADSPI.FR.B.TFF);

QUADSPI.IPCR.B.SEQID = 2;
while(1 == QUADSPI.SR.B.BUSY);
while(0 == QUADSPI.FR.B.TFF);

QUADSPI.IPCR.B.SEQID = 3;
while(1 == QUADSPI.SR.B.BUSY);
while(0 == QUADSPI.FR.B.TFF);

QUADSPI.IPCR.B.SEQID = 4;
while(1 == QUADSPI.SR.B.BUSY);
while(0 == QUADSPI.FR.B.TFF);

 

Please review the above code snippet and help in resolving the issue in writing QSPI Flash.

 

Thanks and Regards,

Siva Prakash Reddy

0 Kudos
0 Replies