2025-01-09 12:33 PM - last edited on 2025-01-10 03:04 AM by SofLit
The author of this how to get CANopenNodeSTM32 working video is very good (The length of the video is 3:31:33; The part that is pertinent to this post 57:05 - 1:18:22). Unfortunately, this video targets FDCAN (but I don't have this available; my chip just supports plain CAN) and this video also targets bare metal (but I don't have this available; FreeRTOS is what I am using). I tried to follow all of the author's steps but was unable to. When I ran I got a HardFault with the CAN node never even coming online.
Executing this line is what causes the Hard fault
canopen_app_init(&canOpenNodeSTM32);
#include "CO_app_STM32.h"
osThreadId_t canOpenNodeTaskHandle;
const osThreadAttr_t canOpenNodeTask_attributes = {
.name = "task CAN",
.stack_size = 192,
.priority = (osPriority_t) osPriorityHigh,
};
static void MX_CAN1_Init(void);
void startCanOpenNodeTask(void *argument);
MX_CAN1_Init();
canOpenNodeTaskHandle = osThreadNew(startCanOpenNodeTask, NULL, &canOpenNodeTask_attributes);
static void MX_CAN1_Init(void)
{
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 40;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_12TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_4TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
Error_Handler();
}
}
__attribute__((noreturn)) void startCanOpenNodeTask(void *argument)
{
CANopenNodeSTM32 canOpenNodeSTM32;
//canOpenNodeSTM32.CANHandle = &hfdcan1;
canOpenNodeSTM32.CANHandle = &hcan1;
// canOpenNodeSTM32.HWInitFunction = MX_FDCAN1_Init;
canOpenNodeSTM32.HWInitFunction = MX_CAN1_Init;
// canOpenNodeSTM32.timerHandle = &htim17;
canOpenNodeSTM32.desiredNodeID = 21;
// canOpenNodeSTM32.baudrate = 125;
canopen_app_init(&canOpenNodeSTM32); // Hard fault
// never makes it to here because the line above Hard faults
for(;;)
{
// it makes no difference what is in here yet, because a Hard fault occurs when executing the above line
}
}
2025-01-10 01:07 AM
Hello,
Not obvious to watch a 3 hours video.
You are using STM32L452 having CAN 2.0 and in the video I can see some devices having also CAN 2.0 like F0.
I suggest you to follow the steps in the video of one of the devices having CAN2.0 and start with baremetal. Don't start with RTOS at this stage. Or contact the Youtuber.