1
votes

I have started developing CAN applications using an STM32 microcontroller and HAL libraries. So I have some questions to do in order to testing an application that will transmit two characters in an infinite loop.

I'm working with a Discovery kit with the STM32L4F6 microcontroller. I've configured the CAN controller parameters via the HAL_CAN library. There, I have noticed that using this library, the user can only have access from the ID frame field to the end of the data field (for transmissions). I must guess that the CRC, ACK and EOF fields are configured in the HAL lowest layers, independently of the user code. Am I wrong?

  • If not, hence, what does it mean if the ESR register contains an 010 error field that indicates "form error" (according the datasheet) when I debug my code?

  • If I'm wrong, please, where can I fill in these fields or how do I access them through the HAL_CAN driver (of course, from my user code)?

Here is my configure frame parameters:

CAN_HandleTypeDef HCAN_Struct; // Type defined in HAL third-party library

void Can_ConfigureFrame(void)
{
    //TX
    HCAN_Struct.pTxMsg->StdId = 0x321;
    HCAN_Struct.pTxMsg->ExtId = 0x01; // 29 bits
    HCAN_Struct.pTxMsg->IDE   = CAN_ID_STD;
    HCAN_Struct.pTxMsg->RTR   = CAN_RTR_DATA;
    HCAN_Struct.pTxMsg->DLC   = DATABTXLONG;//1-9
    HCAN_Struct.Instance->MCR &= (~(uint32_t)CAN_MCR_DBF); // Descongelar el bus CAN en modo debug bit --> dbf=0
}

Here is the init function where more parameters are configured and those ones:

void App_Task_CAN_init(void)
{
    static CanTxMsgTypeDef        TxMessage;
    static CanRxMsgTypeDef        RxMessage;

    /* Configuracion timing para obtener 500kb/s */
    HCAN_Struct.Instance = CAN1;

    HCAN_Struct.pTxMsg = &TxMessage;
    HCAN_Struct.pRxMsg = &RxMessage;
    HCAN_Struct.Init.Prescaler = 1;
    HCAN_Struct.Init.Mode = CAN_MODE_NORMAL;
    HCAN_Struct.Init.SJW = CAN_SJW_1TQ;
    HCAN_Struct.Init.BS1 = CAN_BS1_6TQ; // Segment point at 87.5%
    HCAN_Struct.Init.BS2 = CAN_BS2_1TQ;
    HCAN_Struct.Init.TTCM = DISABLE;
    HCAN_Struct.Init.ABOM = DISABLE;
    HCAN_Struct.Init.AWUM = DISABLE;
    HCAN_Struct.Init.NART = DISABLE;
    HCAN_Struct.Init.RFLM = DISABLE; // FIFO locked mode disabled
    HCAN_Struct.Init.TXFP = DISABLE; // Prioridad de tx por id (más bajo más     prioridad)

    if (HAL_CAN_Init(&HCAN_Struct) != HAL_OK)
    {
        TaskCan_Error_Handler();
    }
    Can_ConfigureFrame();
}
1
As far as I know CRC and EOF fields are not software configurable. They are done by the CAN controller hardware.Koorosh Hajiani
@KooroshHajiani I think so, but since I have got "form error" code at ESR register I want to ensure I was not missing anything. Lot of thanks.Suvi_Eu

1 Answers

1
votes

CRC, ACK and EOF are indeed not configurable by software since they are specified in the CAN standard and implemented by hardware.

Under 42.7.6 Error management in the STM32F43xxx Reference Manual p.1368:

The error management as described in the CAN protocol is handled entirely by hardware using a Transmit Error Counter. (TEC value, in CAN_ESR register) and a Receive Error Counter (REC value, in the CAN_ESR register), which get incremented or decremented according to the error condition. For detailed information about TEC and REC management, refer to the CAN standard.

I can't judge why the Form Error occurs. Maybe you should double-check your GPIO configuration.