How to config Freemaster over CAN bus?

cancel
Showing results for 
Search instead for 
Did you mean: 

How to config Freemaster over CAN bus?

Jump to solution
383 Views
Z2D
Contributor I

Hello,

I want to use freemaster to communicate with the mcu over CAN bus.

I have googled the tutorial but found nothing. Is there any demo which can explain the basic how-to? I want to know how to add the related code to my project in S32DS. I am using S32K144-EVB.

0 Kudos
1 Solution
356 Views
iulian_stan
NXP Employee
NXP Employee

Hi @Z2D,

There are 2 things that need minor adjustments, one is in your code and another one related to the SDK:

  • In your code: you are using Short Interrupt Mode (#define FMSTR_SHORT_INTR 1) but you miss the piece that attaches FreeMASTER handler to CAN communication interrupt
    #if FMSTR_SHORT_INTR || FMSTR_LONG_INTR
        INT_SYS_InstallHandler(CAN0_ORed_0_15_MB_IRQn, FMSTR_Isr, NULL);
        INT_SYS_EnableIRQ(CAN0_ORed_0_15_MB_IRQn);
    #endif​
     If you don't want to use interrupts, you can switch to polling mode:
    #define FMSTR_LONG_INTR        0    /* Complete message processing in interrupt */
    #define FMSTR_SHORT_INTR       0    /* SCI FIFO-queuing done in interrupt */
    #define FMSTR_POLL_DRIVEN      1    /* No interrupt needed, polling only */​
  • The SDK: this reply explains the change. TLDR add this snippet after CAN initialization: 
    /* Enter Freeze mode */
    CAN0->MCR |= (CAN_MCR_FRZ_MASK | CAN_MCR_HALT_MASK);
    CAN0->MCR &= ~CAN_MCR_MDIS_MASK;
    while((CAN0->MCR & CAN_MCR_FRZACK_MASK ) == 0){}
    /* Disable abort mechanism  MCR[AEN] = 0 */
    CAN0->MCR &= ~CAN_MCR_AEN_MASK;
    /* Enable the FlexCAN module */
    CAN0->MCR &= ~(CAN_MCR_FRZ_MASK | CAN_MCR_HALT_MASK);​

I also attached my main.c that should work in both modes. Let me know if it helps fixing your issue.

Regards,
Iulian

View solution in original post

0 Kudos
4 Replies
369 Views
iulian_stan
NXP Employee
NXP Employee

Hi @Z2D,

Could you please provide some additional details about your case:

  • Are you trying to add FreeMASTER Driver to you project and configure it for CAN communication or the Driver is already enabled and you have issues configuring it ?
  • What versions of S32DS IDE and S32K1xx SDK are you using ?

In the meantime you can check this post - it's a bit outdated, but can give a base understanding of FreeMASTER Driver. I will provide updated instructions to match the tools you are working with.

Kind regards,
Iulian

0 Kudos
363 Views
Z2D
Contributor I

Hello, iulianstan

Thank you for your reply.

The driver is already enabled and I have issues configuring it.

I use S32DS for ARM 2.2 and S32K144_SDK 3.0.0.

Let me describe the issue in detail.

I have created a new project and configure the can_pal.

1.PNG

2.PNG

I have changed the configuration in freemaster_cfg.h to use the can bus.

3.PNG

In the main function, I initialized the clock and can peripherals. And the FMSTR_Init(), FMSTR_Poll() functions were also added.

8.PNG

Then I compiled the program and flashed it.

A freemaster project has been created to test the demo. I choose to connect the board over can bus.

4.PNG

5.PNG

Then I clicked the Plug-in Configuration.

6.PNG

I use GY8507 interface card from GLINKER. It seems the driver is ok. When I clicked the Test Connection, an error occured.

7.PNG

I think I should have missed  some configuration in the code. Please see the project in the attachment.

By the way, I have tested the model in the MBDT named "CAN_With_FreeMASTER_over_CAN", it works.

9.PNG

0 Kudos
357 Views
iulian_stan
NXP Employee
NXP Employee

Hi @Z2D,

There are 2 things that need minor adjustments, one is in your code and another one related to the SDK:

  • In your code: you are using Short Interrupt Mode (#define FMSTR_SHORT_INTR 1) but you miss the piece that attaches FreeMASTER handler to CAN communication interrupt
    #if FMSTR_SHORT_INTR || FMSTR_LONG_INTR
        INT_SYS_InstallHandler(CAN0_ORed_0_15_MB_IRQn, FMSTR_Isr, NULL);
        INT_SYS_EnableIRQ(CAN0_ORed_0_15_MB_IRQn);
    #endif​
     If you don't want to use interrupts, you can switch to polling mode:
    #define FMSTR_LONG_INTR        0    /* Complete message processing in interrupt */
    #define FMSTR_SHORT_INTR       0    /* SCI FIFO-queuing done in interrupt */
    #define FMSTR_POLL_DRIVEN      1    /* No interrupt needed, polling only */​
  • The SDK: this reply explains the change. TLDR add this snippet after CAN initialization: 
    /* Enter Freeze mode */
    CAN0->MCR |= (CAN_MCR_FRZ_MASK | CAN_MCR_HALT_MASK);
    CAN0->MCR &= ~CAN_MCR_MDIS_MASK;
    while((CAN0->MCR & CAN_MCR_FRZACK_MASK ) == 0){}
    /* Disable abort mechanism  MCR[AEN] = 0 */
    CAN0->MCR &= ~CAN_MCR_AEN_MASK;
    /* Enable the FlexCAN module */
    CAN0->MCR &= ~(CAN_MCR_FRZ_MASK | CAN_MCR_HALT_MASK);​

I also attached my main.c that should work in both modes. Let me know if it helps fixing your issue.

Regards,
Iulian

View solution in original post

0 Kudos
349 Views
Z2D
Contributor I

Hi, @iulian_stan 

Your solution works! Thank you very much.

0 Kudos