S32K311 SPI communication sample project

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

S32K311 SPI communication sample project

1,115 Views
gayathri123
Contributor I

can anyone support SPI_DMA configuration in s32k311 for tx and rx data

0 Kudos
Reply
3 Replies

1,084 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @gayathri123 

Refer to the example code below. It should help as guidance for the implementation you intend to achieve.

Example S32K31 SPI multiple packet Transmit & Receive : solution for DMA Cache issue

 

BR, VaneB

0 Kudos
Reply

1,036 Views
gayathri123
Contributor I

gayathri123_0-1765988285652.pnggayathri123_1-1765988292018.png

but in your example code Enable Cache support is enabled under cache driver configuration not in MCL cache configuration like 2nd image

 

0 Kudos
Reply

1,027 Views
gayathri123
Contributor I

 

gayathri123_1-1765993708929.pnggayathri123_2-1765993719097.pnggayathri123_3-1765993725725.pnggayathri123_4-1765993733762.pnggayathri123_5-1765993740308.pnggayathri123_6-1765993749270.pnggayathri123_7-1765993756562.pnggayathri123_8-1765993765588.png

/*
* ExternalMemory.c
*
* Created on: Dec 13, 2025
* Author: Ajay Gupta
*/
#include "ExternalMemory.h"
#include "Siul2_Port_Ip.h"
#include "Siul2_Dio_Ip.h"
#include "Cache_Ip.h"
#include "Lpspi_Ip.h"
#include "CDD_Rm.h"
#include "Dma_Ip.h"
#include <string.h>
volatile bool g_spiTransferComplete = false;
volatile uint32_t g_W25Q_ID = 0;
#ifdef USE_NON_CHACHABLE_REGION
/* Allocated in non-cacheable RAM: No manual cache cleaning needed */
#pragma GCC section bss ".mcal_bss_no_cacheable"
__attribute__(( aligned(32) )) uint8_t RxBuffer[BCC_MSG_SIZE];
#pragma GCC section bss

#pragma GCC section data ".mcal_data_no_cacheable"
__attribute__(( aligned(32) )) uint8_t TxBuffer[BCC_MSG_SIZE] = {0};
#pragma GCC section data
#else
/* Allocated in cacheable RAM: Requires Cache_Ip_Clean/Invalidate */
__attribute__(( aligned(32) )) uint8_t RxBuffer[BCC_MSG_SIZE];
__attribute__(( aligned(32) )) uint8_t TxBuffer[BCC_MSG_SIZE];
#endif
/*
* winbond W25Q16JV - 16 megabits in size.

W25Q16 pins Spi pins in Mcu
Cs pin connected to Fcs(SPI2)
Data out connected to Miso(SPI2)
Data in connected to Mosi(SPI2)
Clock connected to clock(SPI2)

Standard(single)SPI has 4 pins: Clk, CS, Din, Dout.
this 16 megabits variant has the memory distributed among the 8192 programmable pages, each page being 256 bytes in size.
We can program 256 bytes at once.
we can't erase a single page but we can erase a grp of 16 pages which is called a sector and is 4kb in size that can be erased.
we can also erase a block which is a group of 128 pages(32Kb)or 256 pages(64Kb)

block diagram of memory:
for ex: we have 1 block which has 16 sectors, each sector is 4 kb in size and contains 16 pages. 1 block =16sector x 16 pages =256 pages.

in w25q16jv we have 32 blocks in total 256 pages for 1 block x 32 block=8192 pages.
*/

void lpspi_callback_dma(uint8 Instance, Lpspi_Ip_EventType Event)
{
if(Event == LPSPI_IP_EVENT_END_TRANSFER)
{
/* If cacheable, Invalidate ensures we fetch the fresh DMA data from main memory */
#ifndef USE_NON_CHACHABLE_REGION
Cache_Ip_InvalidateByAddr(CACHE_IP_CORE, CACHE_IP_DATA, (uint32)&RxBuffer[0U], BCC_MSG_SIZE);
#endif

g_spiTransferComplete = true;
}
else if (Event == LPSPI_IP_EVENT_FAULT)
{
g_spiTransferComplete = true;
}
}

 

/*
* Function Name: W25Q_Reset
* Description: Before starting a new session with the chip we should reset it.
* This would terminate any on going operation and the device will return to its default power-on state.
* It will lose all the current volatile settings, such as Volatile Status Register bits, Write Enable Latch (WEL) status, Program/Erase Suspend status, Read parameter setting (P7-P0) and Wrap Bit setting (W6-W4).
* To avoid the accidental Reset, a Reset command is made of 2 instructions. these Instructions, “Enable Reset (66h)” and “Reset (99h)” must be issues in a sequence. Once the Reset command is accepted by the device, the device will take approximately 30us to reset. During this period, no command will be accepted.
*/
Lpspi_Ip_StatusType W25Q_Reset(void)
{
Lpspi_Ip_StatusType status;

/* Enable Reset (0x66) */
memset(TxBuffer, 0, BCC_MSG_SIZE);
TxBuffer[0] = 0x66;
g_spiTransferComplete = false;

#ifndef USE_NON_CHACHABLE_REGION
Cache_Ip_CleanByAddr(CACHE_IP_CORE, CACHE_IP_DATA, TRUE, (uint32)&TxBuffer[0U], 1);
#endif

status = Lpspi_Ip_AsyncTransmit(&MASTER_EXTERNAL_DEVICE, TxBuffer, NULL, 1, lpspi_callback_dma);
if (status != LPSPI_IP_STATUS_SUCCESS) return status;
while(g_spiTransferComplete == false);

/* Reset (0x99) */
TxBuffer[0] = 0x99;
g_spiTransferComplete = false;

#ifndef USE_NON_CHACHABLE_REGION
Cache_Ip_CleanByAddr(CACHE_IP_CORE, CACHE_IP_DATA, TRUE, (uint32)&TxBuffer[0U], 1);
#endif

status = Lpspi_Ip_AsyncTransmit(&MASTER_EXTERNAL_DEVICE, TxBuffer, NULL, 1, lpspi_callback_dma);
if (status != LPSPI_IP_STATUS_SUCCESS) return status;
while(g_spiTransferComplete == false);

for (volatile uint32 i = 0; i < 5000; i++);

return LPSPI_IP_STATUS_SUCCESS;
}
Lpspi_Ip_StatusType W25Q_ReadID(void)
{
Lpspi_Ip_StatusType status;

memset(TxBuffer, 0, BCC_MSG_SIZE);
memset(RxBuffer, 0, BCC_MSG_SIZE);
TxBuffer[0] = 0x9F;
g_spiTransferComplete = false;

#ifndef USE_NON_CHACHABLE_REGION
Cache_Ip_CleanByAddr(CACHE_IP_CORE, CACHE_IP_DATA, TRUE, (uint32)&TxBuffer[0U], 4);
#endif

/* Send 1 cmd byte and receive 3 ID bytes */
status = Lpspi_Ip_AsyncTransmit(&MASTER_EXTERNAL_DEVICE, TxBuffer, RxBuffer, 4, lpspi_callback_dma);
if (status != LPSPI_IP_STATUS_SUCCESS) return status;

while(g_spiTransferComplete == false);


g_W25Q_ID = ((uint32_t)RxBuffer[1] << 16) | ((uint32_t)RxBuffer[2] << | (uint32_t)RxBuffer[3];

return LPSPI_IP_STATUS_SUCCESS;
}

 

 

 

 

/*
* ExternalMemory.h
*
* Created on: Dec 13, 2025
* Author: Ajay Gupta
*/

#ifndef EXTERNALMEMORY_EXTERNALMEMORY_H_
#define EXTERNALMEMORY_EXTERNALMEMORY_H_

#include <stdint.h>
#include <stdbool.h>
#include "Cache_Ip.h"
#include "Lpspi_Ip.h"
#include "CDD_Rm.h"
#include "Dma_Ip.h"

#define USE_NON_CHACHABLE_REGION 1
#define No_of_Blocks 32
#define BCC_MSG_SIZE 12U
#define MASTER_EXTERNAL_DEVICE Lpspi_Ip_DeviceAttributes_SpiExternalDevice_0_Instance_2
extern Lpspi_Ip_StatusType lpspi_status;
extern Lpspi_Ip_HwStatusType lpspi_hw_status;
extern volatile bool g_spiTransferComplete;
void lpspi_callback_dma(uint8 Instance, Lpspi_Ip_EventType Event);


Lpspi_Ip_StatusType W25Q_Reset (void);
Lpspi_Ip_StatusType W25Q_ReadID (void);
#endif /* EXTERNALMEMORY_EXTERNALMEMORY_H_ */

 

 

void SPI_DMA_Init(void)
{
    /* Initialize Dma */
    Dma_Ip_Init(&Dma_Ip_xDmaInitPB);
 
    /* Initialize Rm driver for using DmaMux*/
    Rm_Init(&Rm_Config);
 
    IntCtrl_Ip_EnableIrq(DMATCD0_IRQn);
    IntCtrl_Ip_EnableIrq(DMATCD1_IRQn);
 
    /* Initialise the LPSPI module*/
    lpspi_status = Lpspi_Ip_Init(&Lpspi_Ip_PhyUnitConfig_SpiPhyUnit_1_Instance_2);
 
    Lpspi_Ip_UpdateTransferMode(MASTER_EXTERNAL_DEVICE.Instance, LPSPI_IP_INTERRUPT);
}

clock and pin initialization also i have done can anyone check whether this configuration is correct

 

 

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2263871%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K311%20SPI%20communication%20sample%20project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2263871%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3Ecan%20anyone%20support%20SPI_DMA%20configuration%20in%20s32k311%20for%20tx%20and%20rx%20data%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2264146%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K311%20SPI%20communication%20sample%20project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2264146%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F256645%22%20target%3D%22_blank%22%3E%40gayathri123%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERefer%20to%20the%20example%20code%20below.%20It%20should%20help%20as%20guidance%20for%20the%20implementation%20you%20intend%20to%20achieve.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FExample-S32K31-SPI-multiple-packet-Transmit-amp-Receive-solution%2Fta-p%2F2130091%22%20target%3D%22_blank%22%3EExample%20S32K31%20SPI%20multiple%20packet%20Transmit%20%26amp%3B%20Receive%20%3A%20solution%20for%20DMA%20Cache%20issue%3C%2FA%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBR%2C%20VaneB%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2265244%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K311%20SPI%20communication%20sample%20project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2265244%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CBR%20%2F%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gayathri123_1-1765993708929.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_1-1765993708929.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_1-1765993708929.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370488i8E636331513493CD%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gayathri123_1-1765993708929.png%22%20alt%3D%22gayathri123_1-1765993708929.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gayathri123_2-1765993719097.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_2-1765993719097.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_2-1765993719097.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370489i32A2B23A8E6774E2%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gayathri123_2-1765993719097.png%22%20alt%3D%22gayathri123_2-1765993719097.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gayathri123_3-1765993725725.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_3-1765993725725.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_3-1765993725725.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370491iE237EF885B6C656F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gayathri123_3-1765993725725.png%22%20alt%3D%22gayathri123_3-1765993725725.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gayathri123_4-1765993733762.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_4-1765993733762.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_4-1765993733762.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370492i93B1DECD1C1F9433%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gayathri123_4-1765993733762.png%22%20alt%3D%22gayathri123_4-1765993733762.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gayathri123_5-1765993740308.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_5-1765993740308.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_5-1765993740308.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370493i0163E7D2C3AA9F92%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gayathri123_5-1765993740308.png%22%20alt%3D%22gayathri123_5-1765993740308.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gayathri123_6-1765993749270.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_6-1765993749270.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_6-1765993749270.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370494i10182F0D8C68B96D%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gayathri123_6-1765993749270.png%22%20alt%3D%22gayathri123_6-1765993749270.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gayathri123_7-1765993756562.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_7-1765993756562.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_7-1765993756562.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370495i62B1B86217DAEC2D%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gayathri123_7-1765993756562.png%22%20alt%3D%22gayathri123_7-1765993756562.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gayathri123_8-1765993765588.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_8-1765993765588.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_8-1765993765588.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370496i95DB70F970576F22%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gayathri123_8-1765993765588.png%22%20alt%3D%22gayathri123_8-1765993765588.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%2F*%3CBR%20%2F%3E*%20ExternalMemory.c%3CBR%20%2F%3E*%3CBR%20%2F%3E*%20Created%20on%3A%20Dec%2013%2C%202025%3CBR%20%2F%3E*%20Author%3A%20Ajay%20Gupta%3CBR%20%2F%3E*%2F%3CBR%20%2F%3E%23include%20%22ExternalMemory.h%22%3CBR%20%2F%3E%23include%20%22Siul2_Port_Ip.h%22%3CBR%20%2F%3E%23include%20%22Siul2_Dio_Ip.h%22%3CBR%20%2F%3E%23include%20%22Cache_Ip.h%22%3CBR%20%2F%3E%23include%20%22Lpspi_Ip.h%22%3CBR%20%2F%3E%23include%20%22CDD_Rm.h%22%3CBR%20%2F%3E%23include%20%22Dma_Ip.h%22%3CBR%20%2F%3E%23include%20%3CSTRING.H%3E%3CBR%20%2F%3Evolatile%20bool%20g_spiTransferComplete%20%3D%20false%3B%3CBR%20%2F%3Evolatile%20uint32_t%20g_W25Q_ID%20%3D%200%3B%3CBR%20%2F%3E%23ifdef%20USE_NON_CHACHABLE_REGION%3CBR%20%2F%3E%2F*%20Allocated%20in%20non-cacheable%20RAM%3A%20No%20manual%20cache%20cleaning%20needed%20*%2F%3CBR%20%2F%3E%23pragma%20GCC%20section%20bss%20%22.mcal_bss_no_cacheable%22%3CBR%20%2F%3E__attribute__((%20aligned(32)%20))%20uint8_t%20RxBuffer%5BBCC_MSG_SIZE%5D%3B%3CBR%20%2F%3E%23pragma%20GCC%20section%20bss%3C%2FSTRING.H%3E%3C%2FP%3E%3CP%3E%23pragma%20GCC%20section%20data%20%22.mcal_data_no_cacheable%22%3CBR%20%2F%3E__attribute__((%20aligned(32)%20))%20uint8_t%20TxBuffer%5BBCC_MSG_SIZE%5D%20%3D%20%7B0%7D%3B%3CBR%20%2F%3E%23pragma%20GCC%20section%20data%3CBR%20%2F%3E%23else%3CBR%20%2F%3E%2F*%20Allocated%20in%20cacheable%20RAM%3A%20Requires%20Cache_Ip_Clean%2FInvalidate%20*%2F%3CBR%20%2F%3E__attribute__((%20aligned(32)%20))%20uint8_t%20RxBuffer%5BBCC_MSG_SIZE%5D%3B%3CBR%20%2F%3E__attribute__((%20aligned(32)%20))%20uint8_t%20TxBuffer%5BBCC_MSG_SIZE%5D%3B%3CBR%20%2F%3E%23endif%3CBR%20%2F%3E%2F*%3CBR%20%2F%3E*%20winbond%20W25Q16JV%20-%2016%20megabits%20in%20size.%3C%2FP%3E%3CP%3EW25Q16%20pins%20Spi%20pins%20in%20Mcu%3CBR%20%2F%3ECs%20pin%20connected%20to%20Fcs(SPI2)%3CBR%20%2F%3EData%20out%20connected%20to%20Miso(SPI2)%3CBR%20%2F%3EData%20in%20connected%20to%20Mosi(SPI2)%3CBR%20%2F%3EClock%20connected%20to%20clock(SPI2)%3C%2FP%3E%3CP%3EStandard(single)SPI%20has%204%20pins%3A%20Clk%2C%20CS%2C%20Din%2C%20Dout.%3CBR%20%2F%3Ethis%2016%20megabits%20variant%20has%20the%20memory%20distributed%20among%20the%208192%20programmable%20pages%2C%20each%20page%20being%20256%20bytes%20in%20size.%3CBR%20%2F%3EWe%20can%20program%20256%20bytes%20at%20once.%3CBR%20%2F%3Ewe%20can't%20erase%20a%20single%20page%20but%20we%20can%20erase%20a%20grp%20of%2016%20pages%20which%20is%20called%20a%20sector%20and%20is%204kb%20in%20size%20that%20can%20be%20erased.%3CBR%20%2F%3Ewe%20can%20also%20erase%20a%20block%20which%20is%20a%20group%20of%20128%20pages(32Kb)or%20256%20pages(64Kb)%3C%2FP%3E%3CP%3Eblock%20diagram%20of%20memory%3A%3CBR%20%2F%3Efor%20ex%3A%20we%20have%201%20block%20which%20has%2016%20sectors%2C%20each%20sector%20is%204%20kb%20in%20size%20and%20contains%2016%20pages.%201%20block%20%3D16sector%20x%2016%20pages%20%3D256%20pages.%3C%2FP%3E%3CP%3Ein%20w25q16jv%20we%20have%2032%20blocks%20in%20total%20256%20pages%20for%201%20block%20x%2032%20block%3D8192%20pages.%3CBR%20%2F%3E*%2F%3C%2FP%3E%3CP%3Evoid%20lpspi_callback_dma(uint8%20Instance%2C%20Lpspi_Ip_EventType%20Event)%3CBR%20%2F%3E%7B%3CBR%20%2F%3Eif(Event%20%3D%3D%20LPSPI_IP_EVENT_END_TRANSFER)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%2F*%20If%20cacheable%2C%20Invalidate%20ensures%20we%20fetch%20the%20fresh%20DMA%20data%20from%20main%20memory%20*%2F%3CBR%20%2F%3E%23ifndef%20USE_NON_CHACHABLE_REGION%3CBR%20%2F%3ECache_Ip_InvalidateByAddr(CACHE_IP_CORE%2C%20CACHE_IP_DATA%2C%20(uint32)%26amp%3BRxBuffer%5B0U%5D%2C%20BCC_MSG_SIZE)%3B%3CBR%20%2F%3E%23endif%3C%2FP%3E%3CP%3Eg_spiTransferComplete%20%3D%20true%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3Eelse%20if%20(Event%20%3D%3D%20LPSPI_IP_EVENT_FAULT)%3CBR%20%2F%3E%7B%3CBR%20%2F%3Eg_spiTransferComplete%20%3D%20true%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%2F*%3CBR%20%2F%3E*%20Function%20Name%3A%20W25Q_Reset%3CBR%20%2F%3E*%20Description%3A%20Before%20starting%20a%20new%20session%20with%20the%20chip%20we%20should%20reset%20it.%3CBR%20%2F%3E*%20This%20would%20terminate%20any%20on%20going%20operation%20and%20the%20device%20will%20return%20to%20its%20default%20power-on%20state.%3CBR%20%2F%3E*%20It%20will%20lose%20all%20the%20current%20volatile%20settings%2C%20such%20as%20Volatile%20Status%20Register%20bits%2C%20Write%20Enable%20Latch%20(WEL)%20status%2C%20Program%2FErase%20Suspend%20status%2C%20Read%20parameter%20setting%20(P7-P0)%20and%20Wrap%20Bit%20setting%20(W6-W4).%3CBR%20%2F%3E*%20To%20avoid%20the%20accidental%20Reset%2C%20a%20Reset%20command%20is%20made%20of%202%20instructions.%20these%20Instructions%2C%20%E2%80%9CEnable%20Reset%20(66h)%E2%80%9D%20and%20%E2%80%9CReset%20(99h)%E2%80%9D%20must%20be%20issues%20in%20a%20sequence.%20Once%20the%20Reset%20command%20is%20accepted%20by%20the%20device%2C%20the%20device%20will%20take%20approximately%2030us%20to%20reset.%20During%20this%20period%2C%20no%20command%20will%20be%20accepted.%3CBR%20%2F%3E*%2F%3CBR%20%2F%3ELpspi_Ip_StatusType%20W25Q_Reset(void)%3CBR%20%2F%3E%7B%3CBR%20%2F%3ELpspi_Ip_StatusType%20status%3B%3C%2FP%3E%3CP%3E%2F*%20Enable%20Reset%20(0x66)%20*%2F%3CBR%20%2F%3Ememset(TxBuffer%2C%200%2C%20BCC_MSG_SIZE)%3B%3CBR%20%2F%3ETxBuffer%5B0%5D%20%3D%200x66%3B%3CBR%20%2F%3Eg_spiTransferComplete%20%3D%20false%3B%3C%2FP%3E%3CP%3E%23ifndef%20USE_NON_CHACHABLE_REGION%3CBR%20%2F%3ECache_Ip_CleanByAddr(CACHE_IP_CORE%2C%20CACHE_IP_DATA%2C%20TRUE%2C%20(uint32)%26amp%3BTxBuffer%5B0U%5D%2C%201)%3B%3CBR%20%2F%3E%23endif%3C%2FP%3E%3CP%3Estatus%20%3D%20Lpspi_Ip_AsyncTransmit(%26amp%3BMASTER_EXTERNAL_DEVICE%2C%20TxBuffer%2C%20NULL%2C%201%2C%20lpspi_callback_dma)%3B%3CBR%20%2F%3Eif%20(status%20!%3D%20LPSPI_IP_STATUS_SUCCESS)%20return%20status%3B%3CBR%20%2F%3Ewhile(g_spiTransferComplete%20%3D%3D%20false)%3B%3C%2FP%3E%3CP%3E%2F*%20Reset%20(0x99)%20*%2F%3CBR%20%2F%3ETxBuffer%5B0%5D%20%3D%200x99%3B%3CBR%20%2F%3Eg_spiTransferComplete%20%3D%20false%3B%3C%2FP%3E%3CP%3E%23ifndef%20USE_NON_CHACHABLE_REGION%3CBR%20%2F%3ECache_Ip_CleanByAddr(CACHE_IP_CORE%2C%20CACHE_IP_DATA%2C%20TRUE%2C%20(uint32)%26amp%3BTxBuffer%5B0U%5D%2C%201)%3B%3CBR%20%2F%3E%23endif%3C%2FP%3E%3CP%3Estatus%20%3D%20Lpspi_Ip_AsyncTransmit(%26amp%3BMASTER_EXTERNAL_DEVICE%2C%20TxBuffer%2C%20NULL%2C%201%2C%20lpspi_callback_dma)%3B%3CBR%20%2F%3Eif%20(status%20!%3D%20LPSPI_IP_STATUS_SUCCESS)%20return%20status%3B%3CBR%20%2F%3Ewhile(g_spiTransferComplete%20%3D%3D%20false)%3B%3C%2FP%3E%3CP%3Efor%20(volatile%20uint32%20i%20%3D%200%3B%20i%20%26lt%3B%205000%3B%20i%2B%2B)%3B%3C%2FP%3E%3CP%3Ereturn%20LPSPI_IP_STATUS_SUCCESS%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3ELpspi_Ip_StatusType%20W25Q_ReadID(void)%3CBR%20%2F%3E%7B%3CBR%20%2F%3ELpspi_Ip_StatusType%20status%3B%3C%2FP%3E%3CP%3Ememset(TxBuffer%2C%200%2C%20BCC_MSG_SIZE)%3B%3CBR%20%2F%3Ememset(RxBuffer%2C%200%2C%20BCC_MSG_SIZE)%3B%3CBR%20%2F%3ETxBuffer%5B0%5D%20%3D%200x9F%3B%3CBR%20%2F%3Eg_spiTransferComplete%20%3D%20false%3B%3C%2FP%3E%3CP%3E%23ifndef%20USE_NON_CHACHABLE_REGION%3CBR%20%2F%3ECache_Ip_CleanByAddr(CACHE_IP_CORE%2C%20CACHE_IP_DATA%2C%20TRUE%2C%20(uint32)%26amp%3BTxBuffer%5B0U%5D%2C%204)%3B%3CBR%20%2F%3E%23endif%3C%2FP%3E%3CP%3E%2F*%20Send%201%20cmd%20byte%20and%20receive%203%20ID%20bytes%20*%2F%3CBR%20%2F%3Estatus%20%3D%20Lpspi_Ip_AsyncTransmit(%26amp%3BMASTER_EXTERNAL_DEVICE%2C%20TxBuffer%2C%20RxBuffer%2C%204%2C%20lpspi_callback_dma)%3B%3CBR%20%2F%3Eif%20(status%20!%3D%20LPSPI_IP_STATUS_SUCCESS)%20return%20status%3B%3C%2FP%3E%3CP%3Ewhile(g_spiTransferComplete%20%3D%3D%20false)%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3Eg_W25Q_ID%20%3D%20((uint32_t)RxBuffer%5B1%5D%20%26lt%3B%26lt%3B%2016)%20%7C%20((uint32_t)RxBuffer%5B2%5D%20%26lt%3B%26lt%3B%20%3CLI-EMOJI%20id%3D%22lia_smiling-face-with-sunglasses%22%20title%3D%22%3Asmiling_face_with_sunglasses%3A%22%3E%3C%2FLI-EMOJI%3E%20%7C%20(uint32_t)RxBuffer%5B3%5D%3B%3C%2FP%3E%3CP%3Ereturn%20LPSPI_IP_STATUS_SUCCESS%3B%3CBR%20%2F%3E%7D%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CP%3E%2F*%3CBR%20%2F%3E*%20ExternalMemory.h%3CBR%20%2F%3E*%3CBR%20%2F%3E*%20Created%20on%3A%20Dec%2013%2C%202025%3CBR%20%2F%3E*%20Author%3A%20Ajay%20Gupta%3CBR%20%2F%3E*%2F%3C%2FP%3E%3CP%3E%23ifndef%20EXTERNALMEMORY_EXTERNALMEMORY_H_%3CBR%20%2F%3E%23define%20EXTERNALMEMORY_EXTERNALMEMORY_H_%3C%2FP%3E%3CP%3E%23include%20%3CSTDINT.H%3E%3CBR%20%2F%3E%23include%20%3CSTDBOOL.H%3E%3CBR%20%2F%3E%23include%20%22Cache_Ip.h%22%3CBR%20%2F%3E%23include%20%22Lpspi_Ip.h%22%3CBR%20%2F%3E%23include%20%22CDD_Rm.h%22%3CBR%20%2F%3E%23include%20%22Dma_Ip.h%22%3C%2FSTDBOOL.H%3E%3C%2FSTDINT.H%3E%3C%2FP%3E%3CP%3E%23define%20USE_NON_CHACHABLE_REGION%201%3CBR%20%2F%3E%23define%20No_of_Blocks%2032%3CBR%20%2F%3E%23define%20BCC_MSG_SIZE%2012U%3CBR%20%2F%3E%23define%20MASTER_EXTERNAL_DEVICE%20Lpspi_Ip_DeviceAttributes_SpiExternalDevice_0_Instance_2%3CBR%20%2F%3Eextern%20Lpspi_Ip_StatusType%20lpspi_status%3B%3CBR%20%2F%3Eextern%20Lpspi_Ip_HwStatusType%20lpspi_hw_status%3B%3CBR%20%2F%3Eextern%20volatile%20bool%20g_spiTransferComplete%3B%3CBR%20%2F%3Evoid%20lpspi_callback_dma(uint8%20Instance%2C%20Lpspi_Ip_EventType%20Event)%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ELpspi_Ip_StatusType%20W25Q_Reset%20(void)%3B%3CBR%20%2F%3ELpspi_Ip_StatusType%20W25Q_ReadID%20(void)%3B%3CBR%20%2F%3E%23endif%20%2F*%20EXTERNALMEMORY_EXTERNALMEMORY_H_%20*%2F%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CDIV%3Evoid%20SPI_DMA_Init(void)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Initialize%20Dma%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20Dma_Ip_Init(%26amp%3BDma_Ip_xDmaInitPB)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Initialize%20Rm%20driver%20for%20using%20DmaMux*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20Rm_Init(%26amp%3BRm_Config)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20IntCtrl_Ip_EnableIrq(DMATCD0_IRQn)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20IntCtrl_Ip_EnableIrq(DMATCD1_IRQn)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Initialise%20the%20LPSPI%20module*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20lpspi_status%20%3D%20Lpspi_Ip_Init(%26amp%3BLpspi_Ip_PhyUnitConfig_SpiPhyUnit_1_Instance_2)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20Lpspi_Ip_UpdateTransferMode(MASTER_EXTERNAL_DEVICE.Instance%2C%20LPSPI_IP_INTERRUPT)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CP%3Eclock%20and%20pin%20initialization%20also%20i%20have%20done%20can%20anyone%20check%20whether%20this%20configuration%20is%20correct%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2265178%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K311%20SPI%20communication%20sample%20project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2265178%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gayathri123_0-1765988285652.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_0-1765988285652.png%22%20style%3D%22width%3A%20374px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370469iBF76D8F91071F893%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gayathri123_0-1765988285652.png%22%20alt%3D%22gayathri123_0-1765988285652.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gayathri123_1-1765988292018.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22gayathri123_1-1765988292018.png%22%20style%3D%22width%3A%20322px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370470iE43B14B993412770%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gayathri123_1-1765988292018.png%22%20alt%3D%22gayathri123_1-1765988292018.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Ebut%20in%20your%20example%20code%20Enable%20Cache%20support%20is%20enabled%20under%20cache%20driver%20configuration%20not%20in%20MCL%20cache%20configuration%20like%202nd%20image%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E