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

fix bug in CanPinInitialiser for F4 devices #145

Closed spiralray closed 8 years ago

spiralray commented 8 years ago

I found some serious problems related to CAN Interface.

First, CanPinInitialiser for F4 devices mistakenly initialize CAN_RX as Gpio::INPUT. This pin must be initialized as Gpio::ALTERNATE_FUNCTION.

Second, baudrate of CAN isn`t calculated correctly. Baudrate is more important than sample point for CAN interface, but the previous program doesn't work so.

I might fixed these problems, but only tested on STM32F407. We should tested on other series.

spiralray commented 8 years ago

I tested on STM32F103VET6 and the fixed program worked successfully.

spiralray commented 8 years ago

I also verified that CAN2 successfully worked on F4 devices. My sample program is here. https://github.com/spiralray/stm32f4_template/blob/master/src/sample/f4mini/can/main.cpp

andysworkshop commented 8 years ago

Thanks for this. Would you be able to eliminate the use of floating point instructions? They bring with them a significant increase in flash usage that I'd prefer to avoid on the smaller MCUs if possible. One way is to perform all your calculations scaled up then divide down when you're finished.

spiralray commented 8 years ago

Okay, I fixed the problem, and tested on F4 devices.

andysworkshop commented 8 years ago

Many thanks!