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

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

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

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

*******************************************************************************

 The purpose of this demo application is to present a usage of the
 LPSPI IP Driver for the S32K3xx MCU.

 The example uses LPSPI2 for transmit & receive Twelve bytes using the DMA.
MOSI MISO connected on Hardware in loopback.


 ------------------------------------------------------------------------------
* Test HW: S32K3X2EVB-Q172
* MCU: S32K312
* Compiler: S32DS3.5
* SDK release: RTD 3.0.0
* Debugger: PE micro
* Target: internal_FLASH
********************************************************************************

DATA and Instruction CACHE is enabled by default --> in startup code :--

Dinesh_Guleria_5-1751970200614.png
 
Dinesh_Guleria_4-1751970159453.png

Dinesh_Guleria_6-1751970233008.png

 

========= This selection enable the use of CACHE driver API =========

Dinesh_Guleria_8-1751970355740.png

 

Dinesh_Guleria_7-1751970322758.png

 
============= Use this MACRO ====================

#define USE_NON_CHACHABLE_REGION 1

This MACRO comment & uncomment will allocate the buffer in cachable & non cacable region of memory. You can allocate the SPI buffer in in cachable & non cacable region of memory.

Enabling & disabling of this MACRO will adjust the example code.

Dinesh_Guleria_9-1751971251496.png

 

 
============ How this example works : Cacheable region used ============

I have connected MOSI and MISO pins of spi at hardware level.
Whenever I am  sending and receiving total 10 numbers of 12 byte packet

On each transmission of 12 byte packet I am incrementing the first bite of transmit buffer just to distinguish between packets at the receive side

Cache_Ip_InvalidateByAddr() --> I have to call this API every time I receive 12 byte of data on receive buffer

Cache_Ip_CleanByAddr() --> every time after incrementing the transmit buffer first byte ...I have to call this API then only the correct data is transmitted otherwise it will transmit the same data which was available at first time transfer


================ Cache API operation ==============

  • Cache_Ip_InvalidateByAddr() is for the  invalidate operation.
  • Cache_Ip_CleanByAddr() is for the clean operation or clean&invalidate operation that can be chosen by param of this api: @Param[in]  enInvalidate      Specifies to execute operation Clean&Invalidate.

Clean: This operation ensures that all dirty lines—data in the cache that has been modified but not yet written back to the main memory—are written back to the main memory ->(push data from cache memory to main memory) 

Invalidate: This operation marks the cache lines as invalid, ensuring that any subsequent access to these lines results in a fetch from the main memory, thus ensuring data consistency ->(push data from main memory to cache memory)

Clean&invalidate : A cache clean and invalidate operation behaves as the execution of a clean operation followed immediately by an invalidate operation. Both operations are performed to the same location.



================ Pins used ======================

Dinesh_Guleria_0-1751969916564.png

 

 

Attachments
No ratings
Version history
Last update:
‎09-23-2025 04:06 AM
Updated by: