2 years, 9 months ago.

Nucleo F103 infinite loop in can_frequency(can_t *obj, int f)

Can not use CAN with Nucleo F103 because CAN init fails when setting default CAN frequency.

#include "mbed.h"

CAN can(PA_11, PA_12);

int main()
{
    while (true)
    {
        
    }
}

Nucleo F103 can_api.c line 180 infinite loop. Method called by CAN's constructor.

https://developer.mbed.org/users/mbed_official/code/mbed-dev/file/ff67d9f36b67/targets/TARGET_STM/TARGET_STM32F1/can_api.c

Infinite loop in CAN frequency

int can_frequency(can_t *obj, int f) 
{
    int pclk = HAL_RCC_GetPCLK1Freq();
    int btr = can_speed(pclk, (unsigned int)f, 1);
    CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
 
    if (btr > 0) {
        can->MCR |= CAN_MCR_INRQ ;
        while((can->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) {
        }
        can->BTR = btr;
        can->MCR &= ~(uint32_t)CAN_MCR_INRQ;
        while((can->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) {
        }
        return 1;
    } else {
        return 0;
    }
}
Comment on this question
Be the first to answer this question.

You need to log in to post a question