S32K SDK LIN Stack not working properly with UDS

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

S32K SDK LIN Stack not working properly with UDS

Jump to solution
7,996 Views
joseponc
Contributor III

Hello.

 

I'm having some doubts regarding the Unified Bootloader Framework provided by NXP. I was looking through its code and trying to understand the way it works so I can port it into my application, which uses the LIN stack provided by the SDK. 

 

After looking deeper into the LIN stack, it seems there are only LIN diagnostic functions when we are functioning as a LIN Master(or at least that’s what I’ve found. I don’t know if there are newer driver versions? ). However, we are slaves in our application, and I wanted my application to manage UDS diagnostic frames to engage bootloader mode and function just as the application example for the Unified Bootloader Framework. I see in other posts (https://community.nxp.com/t5/S32K/S32K116-LIN-Diagnostic-Example/m-p/1196377)  that there are examples which modify the LIN driver’s callback to manage 0x3C and 0x3D PID. 

The implementation mentioned in the link above is very similar to the one found in the Unified Bootloader Framework’s application example, found in the following screenshot:

ublf.jpg

 

However, both implementations (the one from the another forum post and the one in the screenshot above), differ greatly from the one found in the SDK's LIN stack driver. It can be found in the following screenshot:

app_lin.jpg

 

So, it seems that the current SDK LIN stack driver doesn't handle 0x3C and 0x3D frames when our device is functioning as a slave. It also doesn't look feasible to copy and paste the implementations which do handle these frames without compromising to a certain point our current application. 

 

My question on this manner is:

What would you suggest me to do? Should I modify the LIN stack driver callback to match the two examples previously mentioned and try to avoid compromising our application? Or am I missing something on the topic? (maybe some functions I didn't find or maybe a newer LIN stack driver version which manages these diagnostic frames) 

 

Thanks for your help

 

Regards,

Jose.

 

 

 

 

0 Kudos
Reply
1 Solution
7,705 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Jose,

I'm posting an UDS project created by our LIN Stack SW team.

- Hardware: S32K116
- SDK release version: S32SDK_S32K1xx_RTM_3.0.0
- PEx: S32 Design Studio v2.2

The frames transmitted on bus as below:

danielmartynek_0-1631088198192.png

 

In the example, the Master node send an UDS frame with

NAD = 0x02, PCI = 0x06, SID = 0x23,

data = {0x03, 0x04, 0x05, 0x06, 0x07}
The Slave node responded with PSID = 0x63 (Value = SID + 0x40).

 

Regards,

Daniel

View solution in original post

0 Kudos
Reply
16 Replies
5,002 Views
Francesco_Solito
Contributor II

Good morning

I have a similar issue. The example shared above (with ld_receive_message, diag_get_flag, diag_clear_flag and ld_send_message) seems to work, but sometimes it fails (I get the diag_get_flag, but then the req_data buffer is full of 0s). I don't understand if there is a better way to manage the diagnostic services, different from polling.

Is it possible to have a more complex example, where more than one UDS is used? For instance the UDS 0x10 (session), 0x34 (download), 0x36 (transfer data) and so on. How to manage more than one UDS? How to manage negative responses for UDS servicese? (in particular how to manage the 0x78 (response pending) negative response?).

Could you please provide a feedback as soon as possible? It's very urgent in our development.

Is it possible to be contacted by phone (or through Meet or similar platforms) in order to discuss the topic in detail?

Thank you in advance and kind regards,

Francesco Solito

0 Kudos
Reply
4,995 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello @Francesco_Solito,

Please create a new thread.

This one has been market as Accepted solution.

 

Thank you,

Daniel

0 Kudos
Reply
5,309 Views
Anonymous1234
Contributor I

Hi Daniel,

I took the same example from above and tried to change the response length to 10 bytes but then lost communication. What could be the reason behind this ?

0 Kudos
Reply
7,927 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Jose,

Based on information I received from our LIN Stack SW team:

It seems like you have problems with receive and transmit the diagnostic frames (0x3C and 0x3D) with SDK LIN stack driver. However it looks like you are receiving and transmitting the diagnostic frames incorrectly.

Can you provide more information:

the .ldf file or the configuration files, diagnostic frames that want to receive and transmit.

I would like to share some information about diagnostic frame when the device is a slave node.

Receiving: The slave node only receive the diagnostic request(0x3D) contain correctly data or ld_receive_message() was called before.
e.g.: Assign NAD service request.

danielmartynek_0-1627638096244.jpeg

- Transmitting: The slave node will provide response to slave response frame (0x3D) when it receives a diagnostic request correctly or the ld_send_message() has been called before.
e.g.: Assign NAD service response.

danielmartynek_1-1627638120043.jpeg

Please check the following:

1. Make sure that ld_init() has been called before you use the transport layer.
2. Defined the UDS with correct SID.
3. Data length of UDS frame needs to be less than max message length that has been configured.

I have an example to implement the UDS frame base on SDK LIN stack release 4.0.2

1. On S32DS:
- Choose diagnostic class 3
- Set the max message length corresponding.
- Tick to use and configured UDS

danielmartynek_2-1627638316053.jpeg

2. The configuration files are generated

- lin_cfg.c

danielmartynek_3-1627638343721.jpeg

- Lin_cfg.h

danielmartynek_4-1627638367993.jpeg

3. This is the example code to implement the UDS frame:

l_u8 req_data[106] = {0};
ld_init(LI0);
l_ifc_init(LI0);
/* Infinite loop */
for (; ; )
{
#if (SUPPORT_PROTOCOL_21 == 1)
/* Set max message length before receive message */
length = 106;
ld_receive_message(LI0,&length, &nad, req_data);
#endif
#if (SUPPORT_DIAG_CLASS_III == 1)
if(diag_get_flag(LI0, LI0_DIAGSRV_USER_TL_ORDER))
/*Option 1*/
{
diag_clear_flag(LI0, LI0_DIAGSRV_USER_TL_ORDER);
req_data[0] += 0x40;

/* Send response 17 data bytes */
ld_send_message(LI0, 17,nad, req_data);

}
#endif
}

One more thing about the S32DS configuration.
Please tick on Use Transport Layer and Support Diagnostic Service as below:

danielmartynek_5-1627638452528.png

 

Thank you,

Regards,

Daniel

 

 

 

0 Kudos
Reply
7,869 Views
joseponc
Contributor III

Hello Daniel, sorry for the delayed response. Got busy with some other topics.

 

I followed all of your recommendations in a blank project, and I got almost everything you shared in your screenshots. I don't know if it's my configuration or my SDK. I tried using S32DS v2018 updated to rev 11 and S32DS v2.2 updated to rev 1, with the lastest LIN stack possible. 

My discrepancies are mostly related to the supported services part. I see that you have ticked supported services which you can not change, whereas I also can't change them, but they are unticked on my side. Please look at my screenshot below:

joseponc_0-1629389582558.png

  •  Red: These are the boxes which are not ticked for me. Unless I'm using the wrong SDK or LIN Stack, I don't see any reason as to why these are not ticked for me
  • Green: I ticked the options you suggested in your response, unless I'm missing something, my setup should be similar to yours
  • Gold: I don't think this could be a difference, but I configured this project like my original project, where we use LIN J2602.

What do you think I could be setting wrong in this case? 

Also, I could create my own user SID, which is also great. But this triggered a question on this manner:

After creating my SID, I tried to look in the code if there was a sort of handler for this user-defined SID. Sadly, I didn't find any. I found the following function, which seems to handle the admitted SIDs:

joseponc_1-1629390174582.png

This function performs a switch case over the received SID, to perform the desired action. However, I don't see a handler for my SID. Am I supposed to modify this part to add my own case for my SID? Or am I missing something here as well? 

joseponc_2-1629391172645.png

Sorry for all the confusion from my side. Thanks in advance for your help.

 

Regards,

Jose.

 

0 Kudos
Reply
7,850 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Jose,

I'm posting comments I received from the LIN Stack team,

Regarding the network configuration,

Red:

This are the services only supported by LIN21. So, they have been disabled in this case. You can check the LIN spec for details about the services that are supported.

Green:

If you want to use the service to transmit and receive UDS frames.

Gold:

Yes, you are right. You can use this service when you use LỊN2602. It will be base on the LIN version in the LDF file that you are using for this node.

 

Regarding the function you posted, this function only handles some services that have been defined in chapter 4.2.5 and 4.2.6 of LIN 2.2a specification. About UDS, only the service flag is enabled and then the user needs to implement these UDS frames manually in application.
This is an example code to implement an UDS frame:

 

l_u8 req_data[106] = {0};
ld_init(LI0);
l_ifc_init(LI0);
/* Infinite loop */
for (; ; )
{
   #if (SUPPORT_PROTOCOL_21 == 1)
     /* Set max message length before receive message */
     length = 106;
     ld_receive_message(LI0,&length, &nad, req_data);
   #endif

   #if (SUPPORT_DIAG_CLASS_III == 1)
      /* Check the flag when receive a UDS request */
      if(diag_get_flag(LI0, LI0_DIAGSRV_USER_TL_ORDER))
      /*Option 1*/
      {
        /* Handle UDS */
        diag_clear_flag(LI0, LI0_DIAGSRV_USER_TL_ORDER);
        req_data[0] += 0x40;

        /* Send response 17 data bytes */
        ld_send_message(LI0, 17,nad, req_data);
      }
   #endif
}

 

 

 

0 Kudos
Reply
7,841 Views
joseponc
Contributor III

Hello Daniel.

Thanks for the quick reply and for all your useful information! 

I have one last question on this manner before closing the thread:

Since UDS is managed through SID, SubFunction and sometimes even more bytes, I'm guessing I should be able to read all this data in some way. Taking your sample code as an example, I believe my implementation should look something like this to manage UDS frames:

joseponc_0-1629474117292.png

So, my question would be: 

Is there some sort of buffer storing this information? Is this information maybe stored in the TL descriptor structure? 

joseponc_1-1629474922587.png

Thanks a lot once again.

 

Regards,

Jose.

0 Kudos
Reply
7,822 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Jose,

Is there some sort of buffer storing this information? Is this information maybe stored in the TL descriptor structure?

You are right. This is the pointer to the transmit and receive queue on TL.
However, the user can implement the data that has been received by calling function ld_receive_message().

After that the data will be store in the user’s buffer.

Please see chapter ld_receive_message in the “Lin 2.2a specification” for more information.

And please see also the below example to know how to use it.

#if (SUPPORT_PROTOCOL_21 == 1)
  /* Set max message length before receive message */
  length = 106;
  ld_receive_message(LI0,&length, &nad, req_data);
#endif


#if (SUPPORT_DIAG_CLASS_III == 1)
  /* Check the flag when receive a UDS request */
  if(diag_get_flag(LI0, LI0_DIAGSRV_USER_TL_ORDER))
    /*Option 1*/
  {
    /* Handle UDS */
    diag_clear_flag(LI0, LI0_DIAGSRV_USER_TL_ORDER);
    /* Received data of the message has been stored in user’s buffer(req_data).
    Received message length has been stored in the length.
    Received NAD of message has been stored in the nad
    */
    req_data[0] += 0x40;

    /* Send response 17 data bytes */
    ld_send_message(LI0, 17,nad, req_data);

  }
#endif

 

Regards,

Daniel

0 Kudos
Reply
7,790 Views
joseponc
Contributor III

Hello Daniel, sorry to reopen once again this thread.

 

I followed step by step and tried to follow every step as close as possible to understand what could I be missing. My project already has its lin_cfg updated to handle user-defined UDS frames. However, I am never able to retrieve this data, even though the driver is recognizing the frames. 

I could follow my debug process until this point, where I could never get this condition to be met:

joseponc_0-1630372078830.png

 

This condition was not met and I'm calling ld_receive_message before. Am I missing something once again? Am I overlooking another step which is required to manage my frames? 

 

Also, what's your advice on how to make my application be able to handle UDS frames without constantly calling the function below?

ld_receive_message(LI0,&length, &nad, req_data);

 

Thanks in advance.

 

Regards,

Jose.

0 Kudos
Reply
7,773 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Jose,

Can you please provide the following:

The SDK version and hardware’s information, source files and configuration files generated by PEx/S32DS.

 

Thanks,

BR, Daniel

0 Kudos
Reply
7,768 Views
joseponc
Contributor III

Hello Daniel,

Thanks for your quick reponse.

 

Sure, find below my HW information:

S32K116, 48-pin. Part number: FS32K116BRM, below that it says ON96V and the last line says CTPPDK.

My SDK information is: 

joseponc_0-1630509022398.png+

Lastly, I'm doing everything on S32 Desing Studio v2.2 with rev 1 installed

 

About the source an configuration files, are you referring to my lin_cfg. c and .h? If so, I'm afraid I'm not allowed to share those files, I'm sorry. 

Or are you maybe referring to some other configuration files? 

 

Thanks.

Regards,

Jose.

0 Kudos
Reply
7,715 Views
joseponc
Contributor III

Hello Daniel,

 

Have you had the chance to check this case?

 

Thanks,

Regards, Jose.

0 Kudos
Reply
7,706 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Jose,

I'm posting an UDS project created by our LIN Stack SW team.

- Hardware: S32K116
- SDK release version: S32SDK_S32K1xx_RTM_3.0.0
- PEx: S32 Design Studio v2.2

The frames transmitted on bus as below:

danielmartynek_0-1631088198192.png

 

In the example, the Master node send an UDS frame with

NAD = 0x02, PCI = 0x06, SID = 0x23,

data = {0x03, 0x04, 0x05, 0x06, 0x07}
The Slave node responded with PSID = 0x63 (Value = SID + 0x40).

 

Regards,

Daniel

0 Kudos
Reply
4,184 Views
GiangHM
Contributor I

Hi Daniel

I just download your example but i  can't see any source code in dir SDK/midleware/lin . We have a project cooperate with nxp team and we really need this source of example. Can you share full source of this project for me.

0 Kudos
Reply
7,672 Views
joseponc
Contributor III

Hello Daniel.

 

Thanks a lot for your help! With your project, I could make mine respond work with UDS frames.

 

Regards,

Jose

 

 

0 Kudos
Reply
7,817 Views
joseponc
Contributor III

Thanks a lot Daniel! 

 

Now I have a better idea on what to do.

 

Regards,

Jose.

0 Kudos
Reply