This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

tcan4550 linux driver配置运行无法发送数据

Other Parts Discussed in Thread: TCAN4550

hi,

tcan4550调试,从linux-5.14版本获取了tcan4x5x的驱动,调试发现如下问题:

1、设备驱动在读取ID作为匹配时,调用tcan4x5x_read_reg,此函数在地址位中对所有地址偏移加0x1000,发送地址数据为0x41100001,而根据手册实际应该为0x41000001,修改后读取ID正常;

2、根据m_can_check_core_release()中读取ID后的逻辑判断,读取ID0的ID根据手册与实际测量结果应该为0x4e414354,恒无法满足后面的版本判断的30--32的判断逻辑,我推测是否要读取ID1的值0x30353534,后面逻辑判断为30,符合后面版本的判断;

3、驱动修改部分后能够正常加载,结合can设备加载成功后在应用层socket调用,应用程序write提示“No buffer space available”;

4、spi为大端传输(spi问题),芯片无响应,修改后响应正常;

目前未解决的问题是3。

  • m_can.h

    tcan4x5x.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    // SPDX-License-Identifier: GPL-2.0
    // SPI to CAN driver for the Texas Instruments TCAN4x5x
    // Copyright (C) 2018-19 Texas Instruments Incorporated - http://www.ti.com/
    #include <linux/regmap.h>
    #include <linux/spi/spi.h>
    #include <linux/regulator/consumer.h>
    #include <linux/gpio/consumer.h>
    #include "m_can.h"
    #define DEVICE_NAME "tcan4x5x"
    #define TCAN4X5X_EXT_CLK_DEF 40000000
    #define TCAN4X5X_DEV_ID0 0x00
    #define TCAN4X5X_DEV_ID1 0x04
    #define TCAN4X5X_REV 0x08
    #define TCAN4X5X_STATUS 0x0C
    #define TCAN4X5X_ERROR_STATUS 0x10
    #define TCAN4X5X_CONTROL 0x14
    #define TCAN4X5X_CONFIG 0x800
    #define TCAN4X5X_TS_PRESCALE 0x804
    #define TCAN4X5X_TEST_REG 0x808
    #define TCAN4X5X_INT_FLAGS 0x820
    #define TCAN4X5X_MCAN_INT_REG 0x824
    #define TCAN4X5X_INT_EN 0x830
    /* Interrupt bits */
    #define TCAN4X5X_CANBUSTERMOPEN_INT_EN BIT(30)
    #define TCAN4X5X_CANHCANL_INT_EN BIT(29)
    #define TCAN4X5X_CANHBAT_INT_EN BIT(28)
    #define TCAN4X5X_CANLGND_INT_EN BIT(27)
    #define TCAN4X5X_CANBUSOPEN_INT_EN BIT(26)
    #define TCAN4X5X_CANBUSGND_INT_EN BIT(25)
    #define TCAN4X5X_CANBUSBAT_INT_EN BIT(24)
    #define TCAN4X5X_UVSUP_INT_EN BIT(22)
    #define TCAN4X5X_UVIO_INT_EN BIT(21)
    #define TCAN4X5X_TSD_INT_EN BIT(19)
    #define TCAN4X5X_ECCERR_INT_EN BIT(16)
    #define TCAN4X5X_CANINT_INT_EN BIT(15)
    #define TCAN4X5X_LWU_INT_EN BIT(14)
    #define TCAN4X5X_CANSLNT_INT_EN BIT(10)
    #define TCAN4X5X_CANDOM_INT_EN BIT(8)
    #define TCAN4X5X_CANBUS_ERR_INT_EN BIT(5)
    #define TCAN4X5X_BUS_FAULT BIT(4)
    #define TCAN4X5X_MCAN_INT BIT(1)
    #define TCAN4X5X_ENABLE_TCAN_INT \
    (TCAN4X5X_MCAN_INT | TCAN4X5X_BUS_FAULT | \
    TCAN4X5X_CANBUS_ERR_INT_EN | TCAN4X5X_CANINT_INT_EN)
    /* MCAN Interrupt bits */
    #define TCAN4X5X_MCAN_IR_ARA BIT(29)
    #define TCAN4X5X_MCAN_IR_PED BIT(28)
    #define TCAN4X5X_MCAN_IR_PEA BIT(27)
    #define TCAN4X5X_MCAN_IR_WD BIT(26)
    #define TCAN4X5X_MCAN_IR_BO BIT(25)
    #define TCAN4X5X_MCAN_IR_EW BIT(24)
    #define TCAN4X5X_MCAN_IR_EP BIT(23)
    #define TCAN4X5X_MCAN_IR_ELO BIT(22)
    #define TCAN4X5X_MCAN_IR_BEU BIT(21)
    #define TCAN4X5X_MCAN_IR_BEC BIT(20)
    #define TCAN4X5X_MCAN_IR_DRX BIT(19)
    #define TCAN4X5X_MCAN_IR_TOO BIT(18)
    #define TCAN4X5X_MCAN_IR_MRAF BIT(17)
    #define TCAN4X5X_MCAN_IR_TSW BIT(16)
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    m_can.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    // SPDX-License-Identifier: GPL-2.0
    // CAN bus driver for Bosch M_CAN controller
    // Copyright (C) 2014 Freescale Semiconductor, Inc.
    // Dong Aisheng <b29396@freescale.com>
    // Copyright (C) 2018-19 Texas Instruments Incorporated - http://www.ti.com/
    /* Bosch M_CAN user manual can be obtained from:
    * http://www.bosch-semiconductors.de/media/pdf_1/ipmodules_1/m_can/
    * mcan_users_manual_v302.pdf
    */
    #include <linux/interrupt.h>
    #include <linux/io.h>
    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/netdevice.h>
    #include <linux/of.h>
    #include <linux/of_device.h>
    #include <linux/platform_device.h>
    #include <linux/pm_runtime.h>
    #include <linux/iopoll.h>
    #include <linux/can/dev.h>
    #include <linux/pinctrl/consumer.h>
    #include "m_can.h"
    /* registers definition */
    enum m_can_reg {
    M_CAN_CREL = 0x0,
    M_CAN_ENDN = 0x4,
    M_CAN_CUST = 0x8,
    M_CAN_DBTP = 0xc,
    M_CAN_TEST = 0x10,
    M_CAN_RWD = 0x14,
    M_CAN_CCCR = 0x18,
    M_CAN_NBTP = 0x1c,
    M_CAN_TSCC = 0x20,
    M_CAN_TSCV = 0x24,
    M_CAN_TOCC = 0x28,
    M_CAN_TOCV = 0x2c,
    M_CAN_ECR = 0x40,
    M_CAN_PSR = 0x44,
    /* TDCR Register only available for version >=3.1.x */
    M_CAN_TDCR = 0x48,
    M_CAN_IR = 0x50,
    M_CAN_IE = 0x54,
    M_CAN_ILS = 0x58,
    M_CAN_ILE = 0x5c,
    M_CAN_GFC = 0x80,
    M_CAN_SIDFC = 0x84,
    M_CAN_XIDFC = 0x88,
    M_CAN_XIDAM = 0x90,
    M_CAN_HPMS = 0x94,
    M_CAN_NDAT1 = 0x98,
    M_CAN_NDAT2 = 0x9c,
    M_CAN_RXF0C = 0xa0,
    M_CAN_RXF0S = 0xa4,
    M_CAN_RXF0A = 0xa8,
    M_CAN_RXBC = 0xac,
    M_CAN_RXF1C = 0xb0,
    M_CAN_RXF1S = 0xb4,
    M_CAN_RXF1A = 0xb8,
    M_CAN_RXESC = 0xbc,
    M_CAN_TXBC = 0xc0,
    M_CAN_TXFQS = 0xc4,
    M_CAN_TXESC = 0xc8,
    M_CAN_TXBRP = 0xcc,
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • 由于问题比较复杂,已将您的问题上传给产品工程师,你可以点击下帖查看进展:

    https://e2e.ti.com/support/interface/f/138/t/907268

    一旦收到回复,我也会给您更新。

  • 请问您是否尝试过:sudo ifconfig can0 txqueuelen 1000

    另外,请确保至少有两个节点连接到总线。 这是正确操作所必需的,因为每个TX帧都将期待来自接收节点的ACK。

  • 当然,这些我都试过,现在问题有进展了,发送数据已经正常,接收数据还在修改中。

    基本问题如下:

    1、

    https://www.kernel.org/doc/Documentation/devicetree/bindings/net/can/m_can.txt

    e2e.ti.com/.../3171152下参考配置的

    bosch,mram-cfg会使驱动配置的MRAM远大于实际MRAM的2k,造成配置的TX缓冲buf为非法地址;
    2、m_can_open()中有部分初始化有问题,根据手册修改后正常;

    现有的接收数据异常导致rx fifo满的问题我相信应该也是配置问题,通过修改寄存器配置应该可以搞定。

  • 处理这些问题相对有些难度,更具体的信息可以帮助我们找到问题所在。请您提供

    • 完整的device tree,TCAN4550寄存器和MRAM配置
    • 您收到的确切错误消息

    以便我们检查它们的错误吗?

  • 当然,之前提的问题我基本都解决了,主要还是MRAM配置与驱动中有些寄存器配置的问题,接收数据时quota变量被固定赋值为1被我修改了,根据一次接受的数据数量来赋值或者读取0x1050来决定,现在解决后数据收发都正常了,奉上修改后的代码与配置,感谢。3757.m_can.c

    7026.tcan4x5x.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    // SPDX-License-Identifier: GPL-2.0
    // SPI to CAN driver for the Texas Instruments TCAN4x5x
    // Copyright (C) 2018-19 Texas Instruments Incorporated - http://www.ti.com/
    #include <linux/regmap.h>
    #include <linux/spi/spi.h>
    #include <linux/regulator/consumer.h>
    #include <linux/gpio/consumer.h>
    #include <linux/gpio.h>
    #include <linux/byteorder/little_endian.h>
    //#include <linux/byteorder/big_endian.h>
    #include "m_can.h"
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • 很高兴您的问题已经解决,并且谢谢您的分享!
  • 你好,我这边也遇到接收异常问题,按照你的配置文件修改也不行,想咨询下你还修改了别的地方吗?