andysworkshop / stm32plus

The C++ library for the STM32 F0, F100, F103, F107 and F4 microcontrollers
http://www.andybrown.me.uk
Other
745 stars 224 forks source link

Improvements for CAN error handling #191

Open martin31821 opened 8 years ago

martin31821 commented 8 years ago

For a project of mine, I needed more error handling and management when using the CAN bus, this is more a proposal than a bug.

CAN in the STM32 series is structured with mailboxes which are essential when sending CAN messages. My proposal is to change the following methods:

/* change */ uint8_t Can::send(...);
//to return the mailbox used or CAN_TxStatus_NoMailBox if all mailboxes are in use

/* add */ bool Can::transmittionPending(uint8_t mbox);
//to check if the transmission is pending in the given mailbox

/* add */ bool Can::hasErrors();
//to check if errors occured during the last transmissions 
//this method should set the ErrorCode in the errorProvider, so it can be tracked down.

Please also note that this proposal breaks the current Can API. An implementation can be seen in my fork