Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What Frame configuration bits are included in the CO_IF_FRM.Identifier variable? #76

Open
sudoDavi opened this issue Nov 19, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@sudoDavi
Copy link

Is your question related to a problem? Please describe.
I'm writing a driver for the STM32F207 and I need to know how the CO_IF_FRM received in DrvCanSend is formated so I can setup the Hardware specific header in the correct way. What does frm->Identifier contain?

I couldn't find this info in the documentation and source files how it sets up this configurations bits, and from reading the CiA 301 spec there are instances where a RTR is sent or that a network can use Extended CAN Frames.

Below I have some code I've written for another CANopen stack where the configurations bits are sent on the identifier of the frame so you need to mask them to check.

Example of configuration of a CAN Frame header, specific to STM32F207


static int16_t DrvCanSend(CO_IF_FRM *frm)
{
    uint8_t success = 0;
    static CAN_TxHeaderTypeDef tx_header;
    tx_header.StdId = frm->ident & CAN_ID_MASK;
    tx_header.ExtId = 0x01; // This won't be used if using a standard ID frame
    tx_header.RTR = (frm->ident & FLAG_RTR) ? CAN_RTR_REMOTE : CAN_RTR_DATA; // This configures the type of frame RTR or Data frame
    tx_header.IDE = CAN_ID_STD; // This configures the frame to either be a standard or extended ID frame
    tx_header.DLC = frm->DLC;
    tx_header.TransmitGlobalTime = DISABLE;
    success = HAL_CAN_AddTxMessage(CANmodule->CANptr, &tx_header, buffer->data, &TxMailbox);
    
    // Example of transmission handling for CANopen-stack
    if(success == HAL_OK)
    {
	    // Successful transmission
	    return sizeof(CO_IF_FRM);
    }
    else if(success == HAL_ERROR)
    {
	    // An error occurred and it isn't related to the tx mailboxes being full
	    return (int16_t)-1;
    }
}
@michael-hillmann
Copy link
Contributor

As remote transfers and extended CAN Ids are not implemented, we can take your suggestion.
Currently the stack is working with standard CAN identifiers only.

@michael-hillmann michael-hillmann self-assigned this Jan 28, 2022
@michael-hillmann michael-hillmann added the enhancement New feature or request label Jan 28, 2022
@michael-hillmann michael-hillmann added this to the 4.2.0 milestone Jan 28, 2022
@dozack
Copy link
Contributor

dozack commented Feb 28, 2022

CO_IF_FRM Identifier

Currently CO_IF_FRM Identifier contains only CAN-ID information. Detection of extended ids is supported if user configures it so (SYNC, SDO, even PDO, see [CiA 301]) and imho straightforward:

static int16_t STM32FdcanCanSend(CO_IF_FRM *frame) {
    FDCAN_TxHeaderTypeDef txHeader;
    static uint8_t frameMarker;

    /*
     * Translate canopen-stack frame type to HAL header
     */

    txHeader.Identifier                     = (uint32_t) frame->Identifier;
    txHeader.IdType                         = (frame->Identifier > 0x7ff) ? (FDCAN_EXTENDED_ID) : (FDCAN_STANDARD_ID);
    txHeader.TxFrameType                    = FDCAN_DATA_FRAME;
    txHeader.DataLength                     = (frame->DLC << 16);
    txHeader.ErrorStateIndicator            = 0;
    txHeader.BitRateSwitch                  = 0;
    txHeader.FDFormat                       = FDCAN_CLASSIC_CAN;
    txHeader.TxEventFifoControl             = FDCAN_NO_TX_EVENTS;
    txHeader.MessageMarker                  = (uint32_t) frameMarker++;

    if (HAL_FDCAN_AddMessageToTxFifoQ(&CoFdcan, &txHeader, &frame->Data[0]) != HAL_OK) {
        /* 👍 for @sudoDavi, there i should distinguish between interface busy and error results :) */
        return (0u);
    }

    return sizeof(CO_IF_FRM);
}

RTR frames

In case of RTR frames, i would suggest against supporting this feature with reference to CiA AN802. Most of hardware products nowadays utilize version of CANOpen that supports functionality beyond requiring RTR frame transmission.

@michael-hillmann michael-hillmann modified the milestones: 4.2.0, 4.2.1 Apr 1, 2022
@michael-hillmann michael-hillmann removed this from the 4.2.1 milestone Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants