Skip to content

mcan驱动,在边界条件下,由于fifo的put_index不一致,导致发错帧 #123

@zhangjiance

Description

@zhangjiance

在发送压力测试场景下,busload仅60%左右,就很容易出现错帧情况。

测试场景

发送端:HPM5321
接收端:PCAN FD

发送端以1ms周期,发送四帧报文,id1、id2、id3、id4,在接收端观察接收统计

问题:

发送端,id1,id2,id3,id4 发送统计为每个ID各50000帧
接收端,四个id的接收帧数统计与发送端不一致,但帧数总和一致

BUG

排查后发现,mcan_transmit_via_txfifo_nonblocking函数,在边界条件下,msg数据填充索引与请求发送索引不一致
手动修改SDK,确保填充索引和请求发送索引一致,即可解决该问题

建议修改

diff --git a/drivers/inc/hpm_mcan_drv.h b/drivers/inc/hpm_mcan_drv.h
index 9a8e9da0..26164a16 100644
--- a/drivers/inc/hpm_mcan_drv.h
+++ b/drivers/inc/hpm_mcan_drv.h
@@ -1702,7 +1702,7 @@ hpm_stat_t mcan_write_txbuf(MCAN_Type *ptr, uint32_t index, mcan_tx_frame_t *tx_
  * @param [in] tx_frame TX frame
  * @return status_success if no errors reported
  */
-hpm_stat_t mcan_write_txfifo(MCAN_Type *ptr, mcan_tx_frame_t *tx_frame);
+hpm_stat_t mcan_write_txfifo(MCAN_Type *ptr, mcan_tx_frame_t *tx_frame,uint32_t *fifo_index);
 
 /**
  * @brief Read message from CAN RXBUF
diff --git a/drivers/src/hpm_mcan_drv.c b/drivers/src/hpm_mcan_drv.c
index 5957f493..25ec25ba 100644
--- a/drivers/src/hpm_mcan_drv.c
+++ b/drivers/src/hpm_mcan_drv.c
@@ -1525,7 +1525,7 @@ hpm_stat_t mcan_write_txbuf(MCAN_Type *ptr, uint32_t index, mcan_tx_frame_t *tx_
     return status;
 }
 
-hpm_stat_t mcan_write_txfifo(MCAN_Type *ptr, mcan_tx_frame_t *tx_frame)
+hpm_stat_t mcan_write_txfifo(MCAN_Type *ptr, mcan_tx_frame_t *tx_frame,uint32_t *fifo_index)
 {
     hpm_stat_t status = status_invalid_argument;
 
@@ -1545,6 +1545,9 @@ hpm_stat_t mcan_write_txfifo(MCAN_Type *ptr, mcan_tx_frame_t *tx_frame)
             for (uint32_t i = 0; i < msg_size_words; i++) {
                 msg_data[i] = tx_frame->data_32[i];
             }
+            if (fifo_index != NULL) {
+                *fifo_index = put_index;
+            }
             status = status_success;
         } else {
             status = status_mcan_txfifo_full;
@@ -1756,14 +1759,9 @@ hpm_stat_t mcan_request_and_fill_txfifo(MCAN_Type *ptr, mcan_tx_frame_t *tx_fram
             break;
         }
 
-        status = mcan_write_txfifo(ptr, tx_frame);
+        status = mcan_write_txfifo(ptr, tx_frame,fifo_index);
         HPM_BREAK_IF(status != status_success);
 
-        uint32_t put_index = mcan_get_txfifo_put_index(ptr);
-
-        if (fifo_index != NULL) {
-            *fifo_index = put_index;
-        }
     } while (false);
     return status;
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions