Skip to main content
aurelien23
Associate III
July 10, 2014
Question

canReceive using a fix mailbox number (do not use CAN_ANY_MAILBOX)

  • July 10, 2014
  • 7 replies
  • 1496 views
Posted on July 10, 2014 at 14:34

Hello,

I want to use canReceive and specify the mailbox to read (do not use CAN_ANY_MAILBOX). Example: if I want to check the first mailbox, I use:

canReceive(can1.

canp

, 1, &rxmsg, TIME_IMMEDIATE) == MSG_OK

canReceive first checks if the buffer received data using the can_lld_is_rx_nonempty function. If you give the mailbox number 1 to this function, it checks the mailbox 0 (BUF[0]).

The problem is that next to this check, the function can_lld_receive will access the second mailbox (BUF[1]).

To fix this, I suggest to define CAN_ANY_MAILBOX to 0xFF and change the switch values in can_lld_is_rx_nonempty from 1-8 to 0-7.

My target is SPC56EL60 but it applies to all families and I use SPC5 Studio.

Is it a bug or I missed something? I can't update SPC5 Studio at the moment, this bug is maybe already fixed.

EDIT: using CAN_ANY_MAILBOX make these 2 functions searching through all mailboxes. In my example they both found that the first mailbox contains data, so it works... All the examples I found are using  CAN_ANY_MAILBOX, did anybody tried to specify a mailbox number?
    This topic has been closed for replies.

    7 replies

    Erwan YVIN
    ST Technical Moderator
    July 10, 2014
    Posted on July 10, 2014 at 16:58

    Hello Aurelien ,

    Yes .. you have right

    there is an issue when we set in a specific mailbox id :

    from can_lld. part (can_lld_receive function):

      if(mailbox != CAN_ANY_MAILBOX) {

        mbid = mailbox;

      }

    we should have :

      if(mailbox != CAN_ANY_MAILBOX) {

        mbid = mailbox-1;

      }

    you can update manually :

    c:\SPC5Studio\eclipse\plugins\org.chibios.spc5.components.hal.platform.spc56elxx_1.0.0.xxxxxxxx\component\lib\src\can_lld.c

    the correction will be available in the next updated version in spc5-hal component (can low level driver)

       Best Regards

             Erwan

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
    aurelien23
    Associate III
    July 16, 2014
    Posted on July 16, 2014 at 15:01

    Hello,

    it sounds logic to do so but it doesn't work. In debug on SPC56EL60 the function

    can_lld_is_rx_nonempty always returns false and I can't explain why! If I use CAN_ANY_MAILBOX it works... And I verified that each mailbox scans (for loops) were finding the mailbox number I passed (to replace CAN_ANY_MAILBOX).

    And this solution doesn't allow to read the mailbox BUF[0] since CAN_ANY_MAILBOX is defined as 0... It's why I suggested to define it to 0xFF and change the switch cases 1-8 to 0-7 in

    can_lld_is_rx_nonempty.

    Aurélien

    Erwan YVIN
    ST Technical Moderator
    July 16, 2014
    Posted on July 16, 2014 at 18:04

     Hello Aurelien ,

    1) When we transmit into MailboxID 1 .. 

    in can_lld_is_rx_nonempty ... if canReceive (MailboxId=1), we are waiting for  BUF[0]

    BUT The data is received in BUF[1].

    2)  When we transmit into MailboxID 2 .. 

    in can_lld_is_rx_nonempty ... if canReceive (MailboxId=2), we are waiting for  BUF[1]

    BUT The data is received in BUF[1].

    your suggestion is good ;)

    We are working on this issue and deliver a patch as soon as possible.

         Best regards

                             Erwan

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
    Erwan YVIN
    ST Technical Moderator
    July 17, 2014
    Posted on July 17, 2014 at 14:51

    Hello Aurélien ,

    we can not set CAN_ANY_MAILBOX to 0xFF because this constant is used for others devices (STM32 and so on ..).

    in API level, the mailbox id should be between 1 and 8.

    the mailboxid for the reception depends on the EID used.

    our message has :txmsg.EID = 0x01234567;

    the CAN settings for OS-Less CAN application is (cf screenshot):

    Filter 0 Settings ==> Mailbox ID 1 (EID=0)

    Filter 1 Settings ==> Mailbox ID 2 (EID=0x01234567)

    Filter 2 Settings ==> Mailbox ID 3(EID=0)

    Filter 3 Settings ==> Mailbox ID 4 (EID=0)

    Filter 4 Settings ==> Mailbox ID 5 (EID=0)

    Filter 5 Settings ==> Mailbox ID 6 (EID=0)

    Filter 6 Settings ==> Mailbox ID 7 (EID=0)

    Filter 7 Settings ==> Mailbox ID 8 (EID=0)

    it means that if you transmit for a defined mailbox id :

    canTransmit(&CAND1,

    1 to 8, &txmsg, TIME_IMMEDIATE)

    you should receive the message in mailbox id 2 (EID comparison) (cf Filter Settings):

    canReceive(can1.canp,

    2, &rxmsg, TIME_IMMEDIATE) == MSG_OK

    the patch provided is working.

    It will be available in the official update site.

    i hope that i am clear.

    Best regards

    Erwan

    ________________

    Attachments :

    2014-07-17_144842.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006qWCb&d=%2Fa%2F0X0000000bo6%2FtBiD2ADDpYHHZ0TI3N2QHqCMzrb15BpXdaFTTe28fH8&asPdf=false
    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
    Erwan YVIN
    ST Technical Moderator
    July 18, 2014
    Posted on July 18, 2014 at 16:12

    Hello Aurélien ,

    Official update site has been updated.

    it contains :

    #280836 can low level driver : Mailbox id issue in can_lld_receive

    #266463

    Add Chibios Components / Test Applications for SPC56ECxx family              Best regards

                                 Erwan

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
    aurelien23
    Associate III
    July 22, 2014
    Posted on July 22, 2014 at 11:19

    Hello Erwan,

    I updated to org.chibios.spc5.components.hal.platform.spc56elxx_1.0.0.201407151616 and still it doesn't work when I use a mailbox number. In canReceive, the call of

    can_lld_receive is never reached. I configured mailboxes 1 to 3 and I successfully read their content when using CAN_ANY_MAILBOX. But when mentionning 1, 2 or 3, canReceive never return MSG_OK... I'm not in loopback mode. I send CAN frames using a PCAN interface.

    Can anyone confirm that it works?

    Regards,

    Aurélien

    Erwan YVIN
    ST Technical Moderator
    July 22, 2014
    Posted on July 22, 2014 at 11:41

    Hello Aurelien ,

    By using the default configuration ,

    and the patch, it is working well (cf Code Below)

    EID 0x1234567

    while (TRUE) {

    /*

    * Sends the TX CAN Message.

    */

    if (CANtransReq == 1) {

    if (canTransmit(&CAND1,

    1, &txmsg, TIME_IMMEDIATE) != MSG_TIMEOUT) {

    palTogglePad(PORT_D, PD_LED2);

    CANtransReq = 0;

    }

    }

    /*

    * Receives the RX CAN Message.

    */

    if (canReceive(can1.canp,

    2

    , &rxmsg, TIME_IMMEDIATE) == MSG_OK) {

    /* Process message.*/

    palTogglePad(PORT_D, can1.led);

    }

    }

    return 0;

    Write in BUF[1] (Cf Screenshot)

    Could you send me your application by email or forum ?

    Check your EID ''matching'' in Filter Settings ?

    Best Regards

    Erwan

    ________________

    Attachments :

    2014-07-22_114001.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006qWUp&d=%2Fa%2F0X0000000boL%2FlL1cPFGXSMdi2tnGCmBYA0mvjjhoIHJ_qUJbfwFjh8s&asPdf=false
    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.