stm32-rs / bxcan

bxCAN peripheral driver for STM32 chips
Apache License 2.0
31 stars 22 forks source link

Enter init mode in builder fn #49

Closed systec-ms closed 2 years ago

systec-ms commented 2 years ago

Good day,

I am a little surprised that no one ran into it, so the following may be absolute nonsense.

I have tried both the example of the stm32f7xx-hal (STM32F767 example adapted to bxcan v0.6) and the stm32f4xx-hal (STM32F407). With both the bxcan::CanBuilder::set_bit_timing function and probably also the other implemented functions, which access the CAN_BTR register, has no functionality. This is caused by the fact that the CAN is not in initialization mode.

Page 1561 RM0410 Rev 4:

This register can only be accessed by the software when the CAN hardware is in initialization mode.

bxcan_1_BTR_wrong

With the function can.modify_config().set_bit_timing(0x001c_0018).enable(); it works, but this sets the initialization mode before.

bxcan_2_BTR_ok

My customization also does this in the bxcan::Can::builder function, after the customization, it works as I would expect it to.

bxcan_3_after_modification

jonas-schievink commented 2 years ago

Oh, nice catch! I agree with the solution, entering init mode in Can::builder seems like the right way to do this.

bors r+

bors[bot] commented 2 years ago

Build succeeded: