Flexcan K70 with CAN0 and CAN1 with Mqx driver

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

Flexcan K70 with CAN0 and CAN1 with Mqx driver

1,087 Views
gianfranco_camo
Contributor I

Hi to all

I'm try to use in the K70 the CAN0 and CAN1 connected to two different Can Bus.

If I configure only 1 of this, it's work good but if I configure this, the result of second "flexcan_init" is error 1040.

it's not important which CAN is configured like second....it's doesn't work.

this is my code :

uint32_t u32_error = 0;

uint32_t u32_bitrate_get = 0;

uint32_t rx_fifo_id[8];

      /* Set CAN1 device parameters */

     instance = CAN_1;                       

     flexcan1_data.num_mb = 16;

     flexcan1_data.max_num_mb = 16;

     flexcan1_data.num_id_filters = kFlexCanRxFifoIDFilters_8;

     flexcan1_data.is_rx_fifo_needed = FALSE;

     flexcan1_data.is_rx_mb_needed = TRUE;

    

     /* Set rx code status params  */

     rx_cs1.code = kFlexCanRX_Ranswer;

     rx_cs1.msg_id_type = kFlexCanMbId_Std;

     rx_cs1.data_length = 1;

     rx_cs1.substitute_remote = 0;

     rx_cs1.remote_transmission = 0;

     rx_cs1.local_priority_enable = 0;

     rx_cs1.local_priority_val = 0;

    

     id_table.is_extended_mb = 0;

     id_table.is_remote_mb = 0;

     id_table.id_filter = rx_fifo_id;

    

     /* Init CAN device */

      u32_error = flexcan_init(instance, &flexcan1_data, FALSE);

      if (u32_error){

          return u32_error;

      }

     

      /* Set CAN bitrate */

      u32_error = flexcan_set_bitrate(instance, 1000000);

     if (u32_error){

         return u32_error;

     }

     /* Get CAN bitrate */

     u32_error = flexcan_get_bitrate(instance, &u32_bitrate_get);

     if (u32_error){

         return u32_error;

     }

    

     /* Set mask type */

     u32_error = flexcan_set_mask_type(instance, kFlexCanRxMask_Global);

     if (u32_error){

         return u32_error;

     }

     /* Set CAN rx fifo and mailbox mask */    

     if (flexcan1_data.is_rx_fifo_needed) {

         u32_error = flexcan_set_rx_fifo_global_mask(instance, kFlexCanMbId_Std, 0x7FF);

         if (u32_error){

             return u32_error;

         }

     }

     if (flexcan1_data.is_rx_mb_needed) {

         u32_error = flexcan_set_rx_mb_global_mask(instance, kFlexCanMbId_Std, u32_MyAddressCan);       

         if (u32_error){

             return u32_error;

         }

     }

    

     /* Configure CAN rx resources for selected instance  */

     if (flexcan1_data.is_rx_fifo_needed){

         u32_error = flexcan_rx_fifo_config(instance, &flexcan1_data, kFlexCanRxFifoIdElementFormat_A, &id_table);

         if (u32_error){

             return u32_error;

         }

     }

    

      /* Set CAN0 device parameters */

     instance = CAN_0;                       

     flexcan0_data.num_mb = 16;

     flexcan0_data.max_num_mb = 16;

     flexcan0_data.num_id_filters = kFlexCanRxFifoIDFilters_8;

     flexcan0_data.is_rx_fifo_needed = FALSE;

     flexcan0_data.is_rx_mb_needed = TRUE;

    

     /* Set rx code status params  */

     rx_cs0.code = kFlexCanRX_Ranswer;

     rx_cs0.msg_id_type = kFlexCanMbId_Std;

     rx_cs0.data_length = 1;

     rx_cs0.substitute_remote = 0;

     rx_cs0.remote_transmission = 0;

     rx_cs0.local_priority_enable = 0;

     rx_cs0.local_priority_val = 0;

    

     id_table.is_extended_mb = 0;

     id_table.is_remote_mb = 0;

     id_table.id_filter = rx_fifo_id;

    

     /* Init CAN device */

      u32_error = flexcan_init(instance, &flexcan0_data, FALSE);                         // <----- ERROR -----    u32_error exit with value 1040

      if (u32_error){

          return u32_error;

      }

     

      /* Set CAN bitrate */

      u32_error = flexcan_set_bitrate(instance, 1000000);

     if (u32_error){

         return u32_error;

     }

     /* Get CAN bitrate */

     u32_error = flexcan_get_bitrate(instance, &u32_bitrate_get);

     if (u32_error){

         return u32_error;

     }

    

     /* Set mask type */

     u32_error = flexcan_set_mask_type(instance, kFlexCanRxMask_Global);

     if (u32_error){

         return u32_error;

     }

     /* Set CAN rx fifo and mailbox mask */    

     if (flexcan0_data.is_rx_fifo_needed) {

         u32_error = flexcan_set_rx_fifo_global_mask(instance, kFlexCanMbId_Std, 0x7FF);

         if (u32_error){

             return u32_error;

         }

     }

     if (flexcan0_data.is_rx_mb_needed) {

         u32_error = flexcan_set_rx_mb_global_mask(instance, kFlexCanMbId_Std, u32_MyAddressCan);       

         if (u32_error){

             return u32_error;

         }

     }

    

     /* Configure CAN rx resources for selected instance  */

     if (flexcan0_data.is_rx_fifo_needed){

         u32_error = flexcan_rx_fifo_config(instance, &flexcan0_data, kFlexCanRxFifoIdElementFormat_A, &id_table);

         if (u32_error){

             return u32_error;

         }

     }

I'm using MQX 3.9

thanks.

gianfranco

0 Kudos
Reply
2 Replies

633 Views
soledad
NXP Employee
NXP Employee

Hello Gianfranco,

Please check the below "known Issues" from the Getting Started with Freescale MQX™ RTOS

Known Issues:

• FlexCAN1 pins PTC16 and PTC17 are shared with NAND flash memory pins on the TWR-K70FN1M Rev. A board.

These pins are correctly set for the FlexCAN1 functionality. CAN1_RX / CAN1_TX signals are not correctly routed to

the TJA1050 High speed CAN transceiver on the TWR-SER board. This prevents a correct FlexCAN example

functionality.

• For a successful test of the FlexCAN example, insert R22 and R23 on TWR_K70F120M.

• Because RTC and CTS signals are not routed correctly from the TWR-K70FN1M Rev. A board to the RS485

connector of the TWR-SER board, the RS485 demo application does not function correctly.


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

633 Views
vicentegomez
NXP TechSupport
NXP TechSupport

Gianfranco

Can you please try on MQX 4.2, this is the last version of MQX that have several fixes.

I hope this will help you.

Vicente

0 Kudos
Reply