S32K344 - LPSPI and DMA configuration

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

S32K344 - LPSPI and DMA configuration

ソリューションへジャンプ
2,537件の閲覧回数
il_ciancio
Contributor IV

Hello to all NXP experts!

I am starting to develop an SPI communication in loopback on my EVK.

Is there any example with SPI configured with  DMA for Tx and Rx (for both Master and Slave)?

 

Thanks a lot!

タグ(1)
1 解決策
2,286件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

Hi @il_ciancio 

I wanted to clarify my previous comment. My focus was on the implementation of your code. As you mentioned, the frame size can indeed be assigned up to 64.

I apologize if my earlier message was not clear. Thank you for bringing this up.

Regarding your second question, as you correctly noted, the Length parameter of the Lpspi_Ip_AsyncTransmit() function is used for both transmission and reception. Therefore, if you send less data than expected to be received, the master or the slave will remain in a waiting state until all the expected data is received.

元の投稿で解決策を見る

10 返答(返信)
2,471件の閲覧回数
il_ciancio
Contributor IV

Hi @VaneB,

I have done a little step, attached you will find a configuration were (I will update also for the other users):

  • LSPI2 is master with DMA;
  • LSPI0 is slave with DMA;
  • the description is updated with "new" wired connection.

Now I am able to trasmit and receive data between the channels with the API Lpspi_Ip_AsyncTransmit.

The first trasmission works correctly, when a I try to send again data, I will not see that the buffers are updated.

Debugging, I am reaching the DMA RX interrupt, but the RAW data are not "updated".

 

Any idea?

Thanks.

0 件の賞賛
返信
2,463件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

Hi @il_ciancio 

I have tested your code and have some observations. First, the S32K3 SPI Driver Integration Manual states that in DMA transfer mode, DMA transfers may cause cache coherency problems. To avoid possible coherency issues when D-CACHE is enabled, ensure that the buffers used as TCD source and destination are allocated in the NON-CACHEABLE area (using Spi_Memmap).

Regarding the buffer update problem, please test the following example code and let me know if you observe the same behavior. Note that this application uses the LPSPI driver to transfer data between LPSPI2 (master, no DMA) and LPSPI0 (slave, with DMA). Although both are not using DMA, this will help us verify the behavior.

NOTE: The example code was developed using RTD 5.0.0 and S32DS 3.5. We always recommend using the latest software and tool versions.

2,363件の閲覧回数
il_ciancio
Contributor IV

Hello @VaneB,

sorry for the late reply.

I have updated as you suggested my RTD, and I have imported  

  • Lpspi_Ip_Transfer_S32K344.zip.

I have specialized a little bit your code and with the Lpspi_Ip_SyncTransmit I am able to send again data.

Regarding:

I have tested your code and have some observations. First, the S32K3 SPI Driver Integration Manual states that in DMA transfer mode, DMA transfers may cause cache coherency problems. To avoid possible coherency issues when D-CACHE is enabled, ensure that the buffers used as TCD source and destination are allocated in the NON-CACHEABLE area (using Spi_Memmap).

I have added SPI_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE pragma between my buffers, but something changes.

Attached you will find the project. I have configured DMA for both LSPI channel, and I am working in interrupt mode for both channel. I am using Lpspi_Ip_AsyncTransmit because of DMA.

The first exchange between Master and Slave works correctly only for the SLAVE, the MASTER hasn't received correctly all the data.

il_ciancio_0-1746438679600.png

il_ciancio_1-1746438946372.png

.

After I clean the buffers, I am sending new data, but I have the same behaviours: the rx master buffer doesn't cotain all data. As I increase the data of the buffer as the lost data is increased.

Any idea?

Thanks a lot!

 

 

 

 

 

  •  
0 件の賞賛
返信
2,348件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

Hi @il_ciancio 

I believe there is a misunderstanding regarding the frame size you are assigning when calling the Lpspi_Ip_UpdateFrameSize() function. This value corresponds to each data length, not the number of data items you are transmitting. According to the TxBuffers FrameSize parameter, the function Lpspi_Ip_UpdateFrameSize() should be set to 8 instead of the 32 you are currently assigning.

Regarding your code, since the issue seems to be only from the master, I made a test by disconnecting the Slave pins and connecting the Master pins in a hardware loopback configuration (Master output connected to Master input). Please test this modified project on your side.

0 件の賞賛
返信
2,322件の閲覧回数
il_ciancio
Contributor IV

Hi @VaneB,

thanks to your suggestions I have done multiple messages exchange between LSPI0 and LSPI2, full duplex and with DMA, so thanks a lot, great job!

I have a question about:

According to the TxBuffers FrameSize parameter, the functionLpspi_Ip_UpdateFrameSize()should be set to 8 instead of the 32 you are currently assigning.

1) why can not I use 32 as frame size? Looking the configuration the max value could be 64 (now it is 64, I want to show you what i mean).

il_ciancio_0-1746533987119.png.

 

2)The API Lpspi_Ip_AsyncTransmit has as parameter Length "number of bytes to be sent", but It seems that It is used also as Rx side, not only for Tx side.

I have done an excercise where Master sends 1024 and receives 8, slave sends 8 and receives 1024, during the execution, the Master is always in BUSY status.

Any opinion on that?

il_ciancio_1-1746534304535.png

3) Why is there not an API/Driver only for receive (as slave) and only for send data (as master)?

It is attached also my project, maybe should be usefull for other users (RTD 5.0.0, S32D 3.5). In the project there are also the defines to test question 2.

 

Thanks!

 

0 件の賞賛
返信
2,287件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

Hi @il_ciancio 

I wanted to clarify my previous comment. My focus was on the implementation of your code. As you mentioned, the frame size can indeed be assigned up to 64.

I apologize if my earlier message was not clear. Thank you for bringing this up.

Regarding your second question, as you correctly noted, the Length parameter of the Lpspi_Ip_AsyncTransmit() function is used for both transmission and reception. Therefore, if you send less data than expected to be received, the master or the slave will remain in a waiting state until all the expected data is received.

2,258件の閲覧回数
il_ciancio
Contributor IV

Thanks for the support,

I will close this topic. For the third question I think the answer is the Half Duplex mode, where we can specify the sender and the receiver.

 

Thanks a lot!

0 件の賞賛
返信
2,501件の閲覧回数
VaneB
NXP TechSupport
NXP TechSupport

Hi @il_ciancio 

There is not a specific example code for SPI master and slave using both DMA, but the following examples might be useful:

 

BR, VaneB

0 件の賞賛
返信
2,483件の閲覧回数
il_ciancio
Contributor IV

Hi @VaneB,

attached you will find my project:

  • I have connected LPSPI0 (slave) and LPSPI2 (master);
  • LPSPI2 is working with DMA;
  • LPSPI0 is working without DMA;

running the code, I see that the data sent by LPSPI2 is received by LPSPI0, but the data sent by LPSPI0 is NOT received by LPSPI2.

Moreover, If I try to sent again data the code goes to in an HardFaultHandler.

Do you have any idea?

0 件の賞賛
返信
2,482件の閲覧回数
il_ciancio
Contributor IV
The hard faul handler was raised becaus of a typo error on line 220 of main.c:
Lpspi_Ip_AsyncTransmit(&MASTER_EXTERNAL_DEVICE, TxMasterBuffer, RxMasterBuffer, NUMBER_OF_BYTES, TIMEOUT);

I have changed TIMEOUT with a callback, but the data are not exchanged between the LSPI.

Thanks and sorry for the error.
0 件の賞賛
返信
%3CLINGO-SUB%20id%3D%22lingo-sub-2089294%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K344%20-%20LPSPI%20%E3%81%8A%E3%82%88%E3%81%B3%20DMA%20%E6%A7%8B%E6%88%90%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2089294%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3ENXP%E3%81%AE%E3%82%A8%E3%82%AD%E3%82%B9%E3%83%91%E3%83%BC%E3%83%88%E3%81%AE%E7%9A%86%E3%81%95%E3%82%93%E3%80%81%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF!%3C%2FP%3E%3CP%3E%E7%A7%81%E3%81%AFEVK%E3%81%AE%E3%83%AB%E3%83%BC%E3%83%97%E3%83%90%E3%83%83%E3%82%AF%E3%81%A7SPI%E9%80%9A%E4%BF%A1%E3%82%92%E9%96%8B%E7%99%BA%E3%81%97%E5%A7%8B%E3%82%81%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3ESPI%20%E3%81%8C%20Tx%20%E3%81%A8%20Rx%20(%E3%83%9E%E3%82%B9%E3%82%BF%E3%83%BC%E3%81%A8%E3%82%B9%E3%83%AC%E3%83%BC%E3%83%96%E3%81%AE%E4%B8%A1%E6%96%B9)%20%E3%81%AE%20DMA%20%E3%81%A7%E6%A7%8B%E6%88%90%E3%81%95%E3%82%8C%E3%81%9F%E4%BE%8B%E3%81%AF%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%81%8B%E3%80%82%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%E3%81%A9%E3%81%86%E3%82%82%E3%81%82%E3%82%8A%E3%81%8C%E3%81%A8%E3%81%86%E3%81%94%E3%81%96%E3%81%84%E3%81%BE%E3%81%99%EF%BC%81%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2093424%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E6%97%A5%E6%99%82%3AS32K344%20-%20LPSPI%E3%81%8A%E3%82%88%E3%81%B3DMA%E3%81%AE%E6%A7%8B%E6%88%90%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2093424%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E3%82%B5%E3%83%9D%E3%83%BC%E3%83%88%E3%81%97%E3%81%A6%E3%81%8F%E3%82%8C%E3%81%A6%E3%81%82%E3%82%8A%E3%81%8C%E3%81%A8%E3%81%86%E3%80%81%3C%2FP%3E%3CP%3E%E3%81%93%E3%81%AE%E3%83%88%E3%83%94%E3%83%83%E3%82%AF%E3%82%92%E7%B5%82%E4%BA%86%E3%81%97%E3%81%BE%E3%81%99%E3%80%823%E7%95%AA%E7%9B%AE%E3%81%AE%E8%B3%AA%E5%95%8F%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6%E3%81%AF%E3%80%81%E9%80%81%E4%BF%A1%E8%80%85%E3%81%A8%E5%8F%97%E4%BF%A1%E8%80%85%E3%82%92%E6%8C%87%E5%AE%9A%E3%81%A7%E3%81%8D%E3%82%8B%E5%8D%8A%E4%BA%8C%E9%87%8D%E3%83%A2%E3%83%BC%E3%83%89%E3%81%8C%E7%AD%94%E3%81%88%E3%81%A0%E3%81%A8%E6%80%9D%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%E3%81%A9%E3%81%86%E3%82%82%E3%81%82%E3%82%8A%E3%81%8C%E3%81%A8%E3%81%86%E3%81%94%E3%81%96%E3%81%84%E3%81%BE%E3%81%99%EF%BC%81%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2090026%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E6%97%A5%E6%99%82%3AS32K344%20-%20LPSPI%E3%81%8A%E3%82%88%E3%81%B3DMA%E3%81%AE%E6%A7%8B%E6%88%90%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2090026%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E3%83%8F%E3%83%BC%E3%83%89%20faul%20%E3%83%8F%E3%83%B3%E3%83%89%E3%83%A9%E3%81%AF%E3%80%81main.c%20%E3%81%AE%20220%20%E8%A1%8C%E7%9B%AE%E3%81%AE%E3%82%BF%E3%82%A4%E3%83%97%E3%83%9F%E3%82%B9%E3%81%8C%E5%8E%9F%E5%9B%A0%E3%81%A7%E7%99%BA%E7%94%9F%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82%3CBR%20%2F%3ELpspi_Ip_AsyncTransmit(%26amp%3BMASTER_EXTERNAL_DEVICE%2C%20TxMasterBuffer%2C%20RxMasterBuffer%2C%20NUMBER_OF_BYTES%2C%20TIMEOUT)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%E3%82%B3%E3%83%BC%E3%83%AB%E3%83%90%E3%83%83%E3%82%AF%E3%81%A7TIMEOUT%E3%82%92%E5%A4%89%E6%9B%B4%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F%E3%81%8C%E3%80%81LSPI%E9%96%93%E3%81%A7%E3%83%87%E3%83%BC%E3%82%BF%E3%81%8C%E4%BA%A4%E6%8F%9B%E3%81%95%E3%82%8C%E3%81%BE%E3%81%9B%E3%82%93%E3%80%82%3CBR%20%2F%3E%3CBR%20%2F%3E%E3%82%A8%E3%83%A9%E3%83%BC%E3%82%92%E3%81%82%E3%82%8A%E3%81%8C%E3%81%A8%E3%81%86%E3%80%81%E3%81%9D%E3%81%97%E3%81%A6%E7%94%B3%E3%81%97%E8%A8%B3%E3%81%82%E3%82%8A%E3%81%BE%E3%81%9B%E3%82%93%E3%80%82%3C%2FLINGO-BODY%3E