How to change varaibles in array when sending message in spi master/slave mode | S32G274A

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

How to change varaibles in array when sending message in spi master/slave mode | S32G274A

ソリューションへジャンプ
1,369件の閲覧回数
zz22
Contributor II

Hi,NXP team.

I am using S32G-VNP-RDB2 S32G274A_M_core to implement spi slave function,But I had some problems

I create Spi_Ip_Transfer_S32G274A_M7 example project, and I can send spi message with function Spi_Ip_AsyncTransmit, but whenever I change the variable in the array, this function still send the initial value

 

 

uint8 TxBuffer[NUMBER_OF_BYTES] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14};  //  the array to be sent
// init spi and dma successful
while (1)  // the cycle in main()
{   // I want to change the variables but not work
    TxBuffer[0] += 1;
    TxBuffer[1] += 2;
    TxBuffer[2] += 3;
    TxBuffer[3] = 7;
    TxBuffer[4] = 6;
    TxBuffer[5] = 5;
    TxBuffer[6] = 4;
    TxBuffer[7] = 3;
    memset(TxBuffer,0,21);
Spi_Ip_AsyncTransmit(&Spi_Ip_DeviceAttributes_SpiExternalDevice_0_BOARD_InitPeripherals, TxBuffer, RxBuffer, NUMBER_OF_BYTES, NULL_PTR);
    do
    {
        Counter --;
        Status = Spi_Ip_GetStatus(Spi_Ip_DeviceAttributes_SpiExternalDevice_0_BOARD_InitPeripherals.Instance);
    }
    while ( (Counter > 0UL) && (Status != SPI_IP_IDLE) );
}

 

 

image.png

it is very strange, if I use Spi_Ip_AsyncTransmit to send several different arrays, it can send their initial variables correctly. 

And I use Spi_Ip_SyncTransmit to send data, it can send the modified variables correctly, but I don't want to use it because I want to use SPI slave mode and this function will block when waiting the master. 

I want to implement spi slave send function,before that, I need to fix the problem that this function can't send variables

My project file is down here, Thank you for your help!

Best regards.

                                                        ZC

 

0 件の賞賛
返信
1 解決策
1,253件の閲覧回数
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

It seems the problem is related due to "TxBuffer and RxBuffer not being effectively defined in the non-cacheable region".

By changing the declarations at the top of "main.c, the incorrect behavior should be solved:

#define MCL_START_SEC_VAR_INIT_UNSPECIFIED_NO_CACHEABLE
#include "Mcl_MemMap.h"

uint8 RxBuffer[NUMBER_OF_BYTES];
uint8 TxBuffer[NUMBER_OF_BYTES] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};

#define MCL_STOP_SEC_VAR_INIT_UNSPECIFIED_NO_CACHEABLE
#include "Mcl_MemMap.h"

From our side, this solution is working.

Please, let us know.

元の投稿で解決策を見る

7 返答(返信)
1,344件の閲覧回数
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

We are seeing that you commented all the memmap.h includes on your project, was there a reason for this?

Also, have you configured your SPI peripheral as Slave? Or are you using it as the example configured it?

We can recommend trying to run your code without optimization, might help with your problem.

Please, let us know.

0 件の賞賛
返信
1,332件の閲覧回数
zz22
Contributor II

Hello!

I un-commend all the #include "Spi_MemMap.h", but it doesn't seem to work, and I guess this file is of little use.

Then I close the optimiztion, and  my cs pins don't work. And I found that the data segment did not change.

lQLPJxMQMnBtDTDMnM0GGbDGORueK7IIngOfyAxDwAMA_1561_156.png_720x720q90g.jpg

Now I suspect that this problem is related to DAM or optimization.

zz22_1-1671719584783.png

My other attempts are also written in this png, I have been spending days on this issue, If you can tell me how to configure slave mode with SPI library is also OK, then I can skip the problem of SPI_IP library, Thank you!

Thank you for your reply!

Best regards!

                                                  ZC

0 件の賞賛
返信
1,324件の閲覧回数
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

This seems odd. I reproduced your problem, but when I pause execution and hover over the TxBuffer variable (which shows the updated information), it proceeds to send the updated information that was shown on the pop-up, like if it needed a refresh to understand that there was new information.

Let us investigate a little further and see why this is happening.

We will update you as soon as we can.

0 件の賞賛
返信
1,258件の閲覧回数
zz22
Contributor II

Hi, on the advice of my colleague, I solved the problem temporarily.

I used malloc to apply for a block of heap memory, and I use memcpy to paste the array I wanted to send into this heap, and fill the pointer of this heap to Spi_Ip_AsyncTransmit. This time I send the correct array, I overcame this difficulty, although I don't know the reason.

uint8 * TxPtr;
TxPtr = (uint8 *)malloc(21);
memcpy(TxPtr,TxBuffer1,21);
Spi_Ip_AsyncTransmit(&Spi_Ip_DeviceAttributes_SpiExternalDevice_0_BOARD_InitPeripherals, TxPtr, RxBuffer, 21, &Spi_Ipw_Callback);
free(TxPtr);

 

0 件の賞賛
返信
1,254件の閲覧回数
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

It seems the problem is related due to "TxBuffer and RxBuffer not being effectively defined in the non-cacheable region".

By changing the declarations at the top of "main.c, the incorrect behavior should be solved:

#define MCL_START_SEC_VAR_INIT_UNSPECIFIED_NO_CACHEABLE
#include "Mcl_MemMap.h"

uint8 RxBuffer[NUMBER_OF_BYTES];
uint8 TxBuffer[NUMBER_OF_BYTES] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};

#define MCL_STOP_SEC_VAR_INIT_UNSPECIFIED_NO_CACHEABLE
#include "Mcl_MemMap.h"

From our side, this solution is working.

Please, let us know.

1,247件の閲覧回数
zz22
Contributor II

Hi, your solution is working, thank you!

I want to know more about non-cacheable region, where can I download the relevant documents?

0 件の賞賛
返信
1,342件の閲覧回数
zz22
Contributor II

Hello!

Thank you for your reply!

When I add the SPI_IP component in my own project, the project printf it cannot find these memmap.h and cannot be built. Therefore I comment them in this example. I did overlook this and I will try to un-comment it tomorrow.

For faster debugging and to avoid running master device for a long time, I temporarily configured my SPI peripheral to master mode. 

I find that this project's default optimization setting is -Os, I try to configure it to -O0 then it cannot send anything. Only I turn on the optimization, the spi master can send messages, I don't know why.

Best Regards.

 

0 件の賞賛
返信