Description
Description of defect
Algorithm for calculating the CAN bus timing settings in method int can_frequency(can_t *obj, int f) appears to be wrong.
It differs from the method applied in _can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz) which yields - to my understanding - the correct settings.
The main difference is in the file targets/TARGET_STM/can_api.c in line 145 vs line 312:
can_init_freq_direct() uses macro IS_FDCAN_NOMINAL_TSEG1 whereas can_frequency() uses macro IS_FDCAN_DATA_TSEG1 for calculation of the nominalPrescaler. Macro IS_FDCAN_DATA_TSEG1 is meaningful only for FDCAN which is not supported by Mbed.
The impact is that the CAN bus timing settings lead to a deviation from the desired CAN transmission speed.
Other CAN controllers will not be able to receive CAN messages and - therefore- will not acknowledge CAN transmissions.
This leads to transmission errors: either other parties on the CAN bus send error frames or they do not send an acknowledge
and finally this leads to a "bus off" state in the STM32G4 CAN controller.
Target(s) affected by this defect ?
I faced this issue on NucleoG474RE board, but likely all STM32G4 boards are affected.
Toolchain(s) (name and version) displaying this defect ?
GCC 10.2.1 arm-none-eabi
What version of Mbed-os are you using (tag or sha) ?
6.16.0
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
mbed-cmake
How is this defect reproduced ?
I can reproduce the issue by:
- Use board NucleoG474RE and a second CAN enabled board (in my case LPC4088 with older Mbed, but another Nucleo G474RE board should do the job). Setup CAN connection (requires CAN transceivers).
- Create main() with CAN instance for both boards.
- Set CAN frequency using method frequency() to 100kHz (default frequency) for one NucleoG474RE board.
- Send messages to the other board in a loop.
- Check for transmit errors. NucleoG474RE will enter "bus off" due to too many transmission errors.
I faced the issue in https://forums.mbed.com/t/no-successful-can-bus-sending-with-nucleog474re.