RIOT-OS / RIOT

RIOT - The friendly OS for IoT
https://riot-os.org
GNU Lesser General Public License v2.1
4.82k stars 1.97k forks source link

can, driver/mcp2512: shows strange frame reordering #19940

Open kfessel opened 9 months ago

kfessel commented 9 months ago

Description

sending a group of multiple can frames shows a strange packet reordering issue

Steps to reproduce the issue

static int _send_fast(int argc, char **argv)
{
    (void) argc; (void) argv;
    int ret = 0;

    struct can_frame f = {
        .can_id = 1,
        .can_dlc = 8,
        .data = {0xff,0xff,0xff,0xff,
                 0xff,0xff,0xff,0xff}
    };
    uint8_t k = 1;
    for( int i = 8; i ; i --){
        f.data[0] = i;
        for(int j = 1 ; j<8; j++) f.data[j]=k++;
        ret = candev->driver->send(candev, &f);
        if (ret < 0) {
            puts("Failed to send CAN-message!");
        }    else {
            DEBUG("sent using mailbox: %d\n", ret);
        }

    }
    return 0;
}
and 
static const shell_command_t shell_commands[] = {
...
    { "send_fast", "send more data", _send_fast },
...
};

to tests/drivers/candev/

$ CAN_DRIVER=MCP2515 BOARD=same54-xpro make flash

into term

send_fast

CFLAGS +="-DCANDEV_MCP2515_DEFAULT_BITRATE=250000"

Expected results

listening on the can bus candump can0 I should receive:

  can0  001   [8]  08 01 02 03 04 05 06 07
  can0  001   [8]  07 08 09 0A 0B 0C 0D 0E
  can0  001   [8]  06 0F 10 11 12 13 14 15
  can0  001   [8]  05 16 17 18 19 1A 1B 1C
  can0  001   [8]  04 1D 1E 1F 20 21 22 23
  can0  001   [8]  03 24 25 26 27 28 29 2A
  can0  001   [8]  02 2B 2C 2D 2E 2F 30 31
  can0  001   [8]  01 32 33 34 35 36 37 38
... 
and so on 

Actual results

  can0  001   [8]  08 01 02 03 04 05 06 07
  can0  001   [8]  06 0F 10 11 12 13 14 15
  can0  001   [8]  07 08 09 0A 0B 0C 0D 0E
  can0  001   [8]  04 1D 1E 1F 20 21 22 23
  can0  001   [8]  02 2B 2C 2D 2E 2F 30 31
  can0  001   [8]  03 24 25 26 27 28 29 2A

packet 5 and 1 are missing "Failed to send CAN-message!"

packets 6 and 7 and 2 and 3 are mixed up

The issue is very timing dependent a simple puts in between each frame like puts("frame send") works around the problem ( may therefor not showup with faster data rates or slower mcu (same54 is used )

Versions

current riot/master

kfessel commented 9 months ago

it's probably happening due to the 2nd tx mailbox beeing used if the first one is in use but they are send by priority (if 1st has something the second one is delayed)

maybe the is a fifo mode somwhere in that can controler