cancel
Showing results for 
Search instead for 
Did you mean: 

issue of ThreadX and FDCAN function

dqsh06
Senior

Hello @D.Botelho @mƎALLEm 

I had an issue of ThreadX and FDCAN transmit as below.

I use the stm32g474 and config a threadx and fdcan with stm32cubemx, so far it works well.

but when i add some fdcan transmit code, it comes strangely.

the code as below

void appThread2(ULONG thread_input)
{
  while(1)
  {
    if(fdcan1_RXFlag == 1)
    {
      fdcan1_RXFlag = 0; // Clear the receive flag
      for(int i = 0; i < 8; i++)
      {
        fdcan1TxData[i] = fdcan1RxData[i]+1; // Copy received data to transmit buffer
      }

      my_FDCAN1_Transmit(fdcan1TxData); // Echo back the received data
      printf("FDCAN1 Received data: ");
      for (int i = 0; i < 8; i++)
      {
        printf("%02X ", fdcan1RxData[i]);
      }
      printf("\r\n");
    }

    // // 发送 0x12
    fdcan1TxHeader.Identifier=0x012;
    fdcan1TxData[0] = (dis_sensor_data1.dis1 >> 0) & 0xff;
    fdcan1TxData[1] = (dis_sensor_data1.dis1 >> 8) & 0xff;
    fdcan1TxData[2] = (dis_sensor_data1.dis2 >> 0) & 0xff;
    fdcan1TxData[3] = (dis_sensor_data1.dis2 >> 8) & 0xff;
    fdcan1TxData[4] = (dis_sensor_data1.dis3 >> 0) & 0xff;
    fdcan1TxData[5] = (dis_sensor_data1.dis3 >> 8) & 0xff;
    fdcan1TxData[6] = (dis_sensor_data1.dis4 >> 0) & 0xff;
    fdcan1TxData[7] = (dis_sensor_data1.dis4 >> 8) & 0xff;
    my_FDCAN1_Transmit(fdcan1TxData);

    // // 发送 0x13
    fdcan1TxHeader.Identifier=0x013;
    fdcan1TxData[0] = (dis_sensor_data2.dis1 >> 0) & 0xff;
    fdcan1TxData[1] = (dis_sensor_data2.dis1 >> 8) & 0xff;
    fdcan1TxData[2] = (dis_sensor_data2.dis2 >> 0) & 0xff;
    fdcan1TxData[3] = (dis_sensor_data2.dis2 >> 8) & 0xff;
    fdcan1TxData[4] = (dis_sensor_data2.dis3 >> 0) & 0xff;
    fdcan1TxData[5] = (dis_sensor_data2.dis3 >> 8) & 0xff;
    fdcan1TxData[6] = (dis_sensor_data2.dis4 >> 0) & 0xff;
    fdcan1TxData[7] = (dis_sensor_data2.dis4 >> 8) & 0xff;
    my_FDCAN1_Transmit(fdcan1TxData);

    // // 发送 0x14
    fdcan1TxHeader.Identifier=0x014;
    fdcan1TxData[0] = sbusHandle.isExist;   // 遥控器工作状态
    fdcan1TxData[1] = sys_status;           // 系统状态
    fdcan1TxData[2] = (encoder_data1.counter >> 0) & 0xff;
    fdcan1TxData[3] = (encoder_data1.counter >> 8) & 0xff;
    fdcan1TxData[4] = (encoder_data2.counter >> 0) & 0xff;
    fdcan1TxData[5] = (encoder_data2.counter >> 8) & 0xff;
    fdcan1TxData[6] = encoder_data1.direction;
    fdcan1TxData[7] = encoder_data1.direction;
    my_FDCAN1_Transmit(fdcan1TxData);

    // 发送 0x15
    fdcan1TxHeader.Identifier=0x015;
    fdcan1TxData[0] = RS485_RXData[0]+0x0A;
    fdcan1TxData[1] = RS485_RXData[1];         
    fdcan1TxData[2] = RS485_RXData[2];
    fdcan1TxData[3] = RS485_RXData[3];
    fdcan1TxData[4] = RS485_RXData[4];
    fdcan1TxData[5] = RS485_RXData[5];
    fdcan1TxData[6] = RS485_RXData[6];
    fdcan1TxData[7] = RS485_RXData[7];
    my_FDCAN1_Transmit(fdcan1TxData);

    tx_thread_sleep(20); // Sleep for 20 ticks
  }
}

I use a thread to send can message with a peroid of 20ms.

the CAN message ID is 0x12, 0x13, 0x14, 0x15.

as the code above,  when i compiled the code and programming to mcu, just after 1s, the system stack and Error_Handler() called. when I comment out 0x15 CAN transimt, only transmit 0x12, 0x13, 0x14, it works well. 

why?

I have increased the thread_stack of appThread2, but it seems the issue still exists.

how should i do to fix this issue?

 

Thanks,

dqsh06

11 REPLIES 11

1. extend the can2.0 to canfd, that means 1 transmit including 64bytes payload, then i dont need send 5-6 times of 8bytes with  different canID.


You don't need a different CAN ID to send several packets of data to complete data that is more than 8 bytes. The 1st byte in every message can use 1 bit to indicate 1st frame and the 7 bits can be the amount of data to complete it. Then the rest of the messages the 1st frame bit is false, then the 7 bits count up to the amount of bytes. Then the receiving node will know when the data has completed.  

 

Look at my signature for CANable V3. It shows how i queue CAN messages for Tx and Rx.

It uses standard CAN 2.0b but you can look in the data structure, replace CAN_RxHeaderTypeDef, CAN_TxHeaderTypeDef with the FDCAN type FDCAN_RxHeaderTypeDef, FDCAN_TxHeaderTypeDef.

You'll have to replace some of the copying of data with the FDCAN Tx/Rx header equivalent. 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool
CANableV3 Open Source

hello @Karl Yamashita @Ozone ,

this afternoon I get the CAN tool, now I am trying to extend CAN2.0 to CANFD with 64bytes payload, it is quite straightforward, just change the frame to FD frame and change rxbuffer size, txbuffer size, it seems i can send and receive 64bytes payload now.

dqsh06_0-1756366708855.png

Best Regards,