Skip to main content
Visitor II
September 6, 2022
Question

modify a CAN sample point

  • September 6, 2022
  • 2 replies
  • 2000 views

I using a STM32MP-157F-EV1 eval board with linux Version 4.0.1-openstlinux-5.15-yocto-kirkstone-mp1-v22.06.15.

CAN receive 500kBit/s fails, if I modify the sample point via an console command it works well. All other Bitrates 125kBit / 250kBit 1MBit are ok with the default values.

How could I set the sample point permant, is there a linux config-File, to get the modyfied value even after a reboot?

    This topic has been closed for replies.

    2 replies

    Graduate
    September 6, 2022

    Hi,

    if you are using the systemd, you can create a service that will run the command for you.

    [Unit]
    Description=Reconfigure CAN interface
    BindsTo=dev-can0.device
    After=dev-can0.device
     
    [Service]
    Type=simple
    ExecStart=/sbin/ip link set can0 up type can bitrate 500000 sample-point 0.5
     
    [Install]
    WantedBy=multi-user.target

    Or you can create a network file. Unfortunately, I can't test it but perhaps tomorrow.

    [Match]
    Name=can0
     
    [CAN]
    BitRate=500000
    SamplePoint=50%

    Hope this helps.

    Graduate
    September 8, 2022

    Hi,

    today I had time to test the second solution; it works fine and is a cleaner solution for me.

    The drawback can be that you are not using the systemd-networkd to manage the network interfaces and that the systemd version 250 is required (fine for ST 4.0.2), but it is easy to modify the configuration as you also need.

    Best regards,

    Tomas

    MaHaAuthor
    Visitor II
    September 9, 2022

    Hi Tomas,

    thank you for testing the second proposal. I will try it as well in my system.

    Best regards

    Manfred

    MaHaAuthor
    Visitor II
    September 7, 2022

    Hi Tomas,

    thank you very much for your support. I tried your first proposal,using systemd and it works well.:smiling_face_with_smiling_eyes:

    Our Customer uses fix 500kBit, so we have actually a solution.

    Now I looking for a possibility to modify the default values, because some other customer tried different Bitrates after power on. Maybe you have still an idea .

    Again, thank you for your good and fast support.

    Best wishes

    Manfred

    Graduate
    September 7, 2022

    Hello,

    if you want to easily modify the bitrate and do not change the systemd service, you can create a configuration file with the desired values and load it into the service.

    The service could look like this

    [Unit]
    Description=Reconfigure CAN interface
    BindsTo=dev-can0.device
    After=dev-can0.device
     
    [Service]
    Type=simple
    EnvironmentFile=-/etc/default/can_config
    ExecStart=/sbin/ip link set can0 up type can bitrate $CAN_CFG_BR sample-point $CAN_CFG_SP $CAN_CFG_EXTRA
     
    [Install]
    WantedBy=multi-user.target

    And the content of the /etc/default/can_config

    CAN_CFG_BR=500000
    CAN_CFG_SP="0.5"
    CAN_CFG_EXTRA=""

    Hope this helps.

    Tomas