Skip to content

Add STM32 support #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 24, 2025
Merged

Add STM32 support #12

merged 4 commits into from
Apr 24, 2025

Conversation

BrechtSerckx
Copy link
Contributor

@BrechtSerckx BrechtSerckx commented Feb 19, 2025

Hi! Thanks for the project!

I added support for STM32 boards with built-in CAN controller using https://github.com/pazi88/STM32_CAN.
As far as I can see, the example seems to work with my ODrive S1 and Adafruit STM32F405 Feather Express.

Please note that I am not comfortable with C++ programming, please let me know of any improvements I can make.

Thanks!

@BrechtSerckx BrechtSerckx force-pushed the stm32 branch 3 times, most recently from 097a73f to 6ddc5df Compare February 19, 2025 21:46
@BrechtSerckx BrechtSerckx marked this pull request as ready for review February 19, 2025 21:48
@CLAassistant
Copy link

CLAassistant commented Apr 24, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@samuelsadok samuelsadok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks generally good, see one comment.
I also added a basic CI compile test, so when you push again it will pick up the new test and might require additional changes.

I'm a bit surprised that the STM32 Arduino core doesn't already come with a standard HardwareCAN implementation. Is pazi88/STM32_CAN.git the go-to CAN library that people use on STM32 Arduinos?


static bool sendMsg(STM32_CAN& can_intf, uint32_t id, uint8_t length, const uint8_t* data) {
CanMsg msg;
msg.id = id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The top three bits of id are reserved, with the MSB meaning "extended". Additionally, if data is null, it should send a remote request frame if the CAN lib supports it.

Suggested change
msg.id = id;
msg.id = id & 0x1ffffff;
msg.flags.extended = id & 0x80000000;
msg.flags.remote = data;

(not tested)

@BrechtSerckx
Copy link
Contributor Author

I'm a bit surprised that the STM32 Arduino core doesn't already come with a standard HardwareCAN implementation. Is pazi88/STM32_CAN.git the go-to CAN library that people use on STM32 Arduinos?

There is no CAN support in STM32duino, see this issue: stm32duino/Arduino_Core_STM32#259. From the thread it seems like pazi88/STM32_CAN is a decent implementation that works on most STM32 devies.

`msg.flags.remote = data;` caused the example to stop working.
ChatGPT suggested `msg.flags.remote = (data == nullptr);` which seems to work.
@samuelsadok
Copy link
Member

Ah yes I got the polarity flipped in my suggestion. msg.flags.remote = !data; would also have worked.

@samuelsadok samuelsadok merged commit 8479e07 into odriverobotics:master Apr 24, 2025
2 checks passed
@samuelsadok
Copy link
Member

Thanks for adding this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants