CAN peripheral in S32K144 not working with SDK 4.0.3

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

CAN peripheral in S32K144 not working with SDK 4.0.3

421 Views
Kunal_Gettobyte
Contributor II

We are running CAN peripheral on S32K144 Custom board. We want to run CAN peripheral via polling method, sp using following set of API's.

/* Including necessary configuration files. */
#include "sdk_project_config.h"

volatile int exit_code = 0;
/* User includes */

/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/

#define TX_MAILBOX 1UL
#define TX_MSG_ID 1UL
#define RX_MAILBOX 1UL
#define RX_MSG_ID 2UL
#define size 5UL


uint8_t data[] = "Kunal";

int main(void)
{
    /* Write your code here */

	/* Configure clocks for PORT */
	CLOCK_DRV_Init(&clockMan1_InitConfig0);

    PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);


    status_t x;
    FLEXCAN_DRV_Init(INST_FLEXCAN_CONFIG_1, &flexcanState0, &flexcanInitConfig0);

    flexcan_data_info_t dataInfo =
    {
            .data_length = size,
            .msg_id_type = FLEXCAN_MSG_ID_STD,
            .enable_brs  = false,
            .fd_enable   = false,
            .fd_padding  = 0U
    };

    flexcan_msgbuff_t recvBuff;
    for(;;)
    {
        FLEXCAN_DRV_ConfigTxMb(INST_FLEXCAN_CONFIG_1, TX_MAILBOX, &dataInfo , TX_MSG_ID);

       x = FLEXCAN_DRV_SendBlocking(INST_FLEXCAN_CONFIG_1, TX_MAILBOX, &dataInfo, TX_MSG_ID,  data, 1000 );

//        FLEXCAN_DRV_ConfigRxMb(INST_FLEXCAN_CONFIG_1, RX_MAILBOX, &dataInfo, RX_MSG_ID);
//
//
//        FLEXCAN_DRV_Receive(INST_FLEXCAN_CONFIG_1, RX_MAILBOX, &recvBuff);

        OSIF_TimeDelay(1000);

    }
    return exit_code;
}

 

Configured the CAN peripheral with these values: 

flexcan_user_config_t flexcanInitConfig0 = {
  .flexcanMode = FLEXCAN_NORMAL_MODE,
  .fd_enable = false,
  .payload = FLEXCAN_PAYLOAD_SIZE_8,
  .max_num_mb = 10UL,
  .num_id_filters = FLEXCAN_RX_FIFO_ID_FILTERS_8,
  .is_rx_fifo_needed = false,
  .transfer_type = FLEXCAN_RXFIFO_USING_INTERRUPTS,
  .rxFifoDMAChannel = 0U,
  .pe_clock = FLEXCAN_CLK_SOURCE_OSC,
  .bitrate = {
    .propSeg = 7UL,
    .phaseSeg1 = 4UL,
    .phaseSeg2 = 1UL,
    .preDivider = 0UL,
    .rJumpwidth = 1UL
  }
};

 

But on running the code, can messages are not sending, i always get STATUS_TIMEOUT as return code from this API: FLEXCAN_DRV_SendBlocking from main.

What wrong am i doing? Is their any configuration which is left from my side or is their issue in SDK of CAN for S32K144

0 Kudos
7 Replies

306 Views
Kunal_Gettobyte
Contributor II

I did check. I am able to get signals of physical layer. I checked it via logic analyzer. 

Kunal_Gettobyte_0-1713114250891.png

 

But I am not able to receive any message.

 

What chronological set of API's to use for receiving data on CAN in blocking methode

0 Kudos

286 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

SDK demo example shows polling method usage. You can have something like this...

/* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, RX_MSG_ID);
 
while(1)
{
/* Start receiving data in RX_MAILBOX. */
FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff);
 
while(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) == STATUS_BUSY);
 
// process received data 
}
 
 
BR, Petr
0 Kudos

256 Views
Kunal_Gettobyte
Contributor II

This implementation is not via interrupts?  I was using FLEXCAN_DRV_ReceiveBlocking() API for pooling as if now. If not then what is the purpose this API and when/how to use?

 

Also, i want to get affirmation on Mailbox and Message ID configuration in CAN transmission and reception.

There is one S32K144(Master), which is sending data, its Mailbox and message ID are these:

#define TX_MAILBOX 1UL
#define TX_MSG_ID 1UL

As if now, in S32K144(master) i have written this piece code code but from FLEXCAN_DRV_TransmitBlocking() API i always get STATUS_TIMEOUT error code even though CAN data is transmitted and can be seen on physical layer, but in software CAN transmit API always returns TIMEOUT error, on furtehr debugging i found it is not able to find the semaphorse because of which CAN software driver returns timeout.

int main(void)
{
    /* Write your code here */

	/* Configure clocks for PORT */
	CLOCK_DRV_Init(&clockMan1_InitConfig0);

    PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);


    FLEXCAN_DRV_Init(INST_FLEXCAN_CONFIG_1, &flexcanState0, &flexcanInitConfig0);

    flexcan_data_info_t dataInfo =
    {
            .data_length = size,
            .msg_id_type = FLEXCAN_MSG_ID_STD,
            .enable_brs  = false,
            .fd_enable   = false,
            .fd_padding  = 0U
    };

    flexcan_msgbuff_t recvBuff;

    status_t x;


    for(;;)
    {
       x =  FLEXCAN_DRV_ConfigTxMb(INST_FLEXCAN_CONFIG_1, TX_MAILBOX, &dataInfo , TX_MSG_ID);

        x = FLEXCAN_DRV_SendBlocking(INST_FLEXCAN_CONFIG_1, TX_MAILBOX, &dataInfo, TX_MSG_ID,  data, 1000 );

//    	x =  FLEXCAN_DRV_ConfigRxMb(INST_FLEXCAN_CONFIG_1, RX_MAILBOX, &dataInfo, RX_MSG_ID);
//
//
//    	x =  FLEXCAN_DRV_ReceiveBlocking(INST_FLEXCAN_CONFIG_1, RX_MAILBOX, &recvBuff, 10000);

        OSIF_TimeDelay(1000);

    }
    return exit_code;
}

 

There is another S32K144(Slave), which is receiving data, its mailbox and message buffer are these:

#define RX_MAILBOX 1UL
#define RX_MSG_ID 1UL

 

As if now, in S32K144(slave) i have written this piece code code but it is not getting blocked in FLEXCAN_DRV_ReceiveBlocking() API, instead it gets out of it everytime after timeout amount that is specified in last paramter of its call.

int main(void)
{
    /* Write your code here */

	/* Configure clocks for PORT */
	CLOCK_DRV_Init(&clockMan1_InitConfig0);

    PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);


    FLEXCAN_DRV_Init(INST_FLEXCAN_CONFIG_1, &flexcanState0, &flexcanInitConfig0);

    flexcan_data_info_t dataInfo =
    {
            .data_length = size,
            .msg_id_type = FLEXCAN_MSG_ID_STD,
            .enable_brs  = false,
            .fd_enable   = false,
            .fd_padding  = 0U
    };

    flexcan_msgbuff_t recvBuff;

    status_t x;


    for(;;)
    {
    	x =  FLEXCAN_DRV_ConfigRxMb(INST_FLEXCAN_CONFIG_1, RX_MAILBOX, &dataInfo, RX_MSG_ID);


    	x =  FLEXCAN_DRV_ReceiveBlocking(INST_FLEXCAN_CONFIG_1, RX_MAILBOX, &recvBuff, 10000);

        OSIF_TimeDelay(1000);

    }
    return exit_code;
}

 

But i guess this implementation is wrong correct? Let me know if my understanding is wrong and what is the gap here.

0 Kudos

217 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

SDK driver is always using MB interrupts, I think.
In your case it seems sent message is not ACKed from other node, in this case blocking function will return timeout as message is not successfully transmitted due to error detected . You can check ECR/ESR1 register.
You can use below code for TX/RX code.

#define TX_MAILBOX 1UL
#define RX_MAILBOX 0UL
 
/* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, RX_MSG_ID);
 
/* Start receiving data in RX_MAILBOX. */
FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff);
 
FLEXCAN_DRV_ConfigTxMb(INST_FLEXCAN_CONFIG_1, TX_MAILBOX, &dataInfo , TX_MSG_ID);
 
while(1)
{
          FLEXCAN_DRV_SendBlocking(INST_FLEXCAN_CONFIG_1, TX_MAILBOX, &dataInfo, TX_MSG_ID,  data, 1000 ); 
          if(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) == STATUS_SUCCESS);
          {
               // process received data 
 
               /* Start receiving data in RX_MAILBOX again */
               FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff);
          }
}
 
BR, Petr
0 Kudos

127 Views
Kunal_Gettobyte
Contributor II

In your case it seems sent message is not ACKed from other node, in this case blocking function will return timeout as message is not successfully transmitted due to error detected. 

 

u mentioned not successfully transmitted, but then how come it is showing signals in logic analyzer?

Because i also thought same, but if it is showing signals on logic analyzer then it means controller has transmitted the signals? correct?

0 Kudos

114 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

does your analyzer ACK CAN message? If not FlexCAN is transmitting message on bus repeatedly until it is ACKed or aborted by user.

BR, Petr

0 Kudos

359 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

ideally use different MB for TX and RX operation, seems you have selected MB1 for both.
If message is not send successfully check MCU to CAN transceiver connection, be sure transceiver is active and properly terminated. Also is other node connected so message can be ACKed?
Moreover you can measure TXD/RXD,CAN lines to be sure of signal there, then check FlexCAN ECR/ESR1 registers to know possible error detected.

BR, Petr

0 Kudos