Bluepill can bus random problems

arrowcircle
Tue, 08 Sep 2020 07:14:50 +0000
Mbed OS

Hi! I have a strange problem with can bus, bluepill and mbed os. I use platformio to build project with added LINKFLAGS --specs=nano.specs (this only affects debug size to fit in the flash. problem stays without it too). Mbed OS version is 5.15.

Problem is at random time can1.write starts to return errors. But if I look into can1 registers with debugger, it says that everything is ok and state is READY and error bits are 0. But all consecutive writes fail. If I reset can interface it starts to work again, but then randomly stops to send messages.

First error appears before 100 messages was sent, but number is random.

Here is a link to the code

gist.github.com

https://gist.github.com/arrowcircle/27faccbd12990d4ad0080445e9b498fb

CANMsg.h

#ifndef CANMSG_H
#define CANMSG_H

/* CAN message container.
 * Provides "<<" (append) and ">>" (extract) operators to simplyfy
 * adding/getting data items to/from a CAN message.
 * Usage is similar to the C++ io-stream operators.
 * Data length of CAN message is automatically updated when using "<<" or ">>" operators.
 *
 * See Wiki page <https://developer.mbed.org/users/hudakz/code/CAN_Hello/> for demo.
This file has been truncated. show original
add_nanolib.py

Import("env")
env.Append(LINKFLAGS=["--specs=nano.specs"])

main.cpp

#include <mbed.h>
#include "CANMsg.h"

#define USE_PLL_HSE_XTAL 1
#define CAN_DELAY 15

CAN can1(PA_11, PA_12);

static bool can_status = false;
DigitalOut led(PC_13);
This file has been truncated. show original
There are more than three files. show original

Any ideas how to solve this problem?

11 posts - 2 participants