-
Notifications
You must be signed in to change notification settings - Fork 2k
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
can stm32: add a driver for STM32 bxCAN peripheral #6178
Conversation
81d1f98
to
6d9394d
Compare
Rebased on latest #5793. |
0c3a99d
to
e0b7c9e
Compare
e0b7c9e
to
17b8255
Compare
0b72376
to
df1dce3
Compare
Rebased and adapted with the new autoinit process from #5793. |
add support for 3 CAN devices (stm32f413), it includes #6565 |
cdfb528
to
557cac8
Compare
b67eabf
to
6fb32f9
Compare
d35c765
to
3ff7184
Compare
8dacbac
to
c3501fc
Compare
dd5cff8
to
fd87d3f
Compare
Hi @vincent-d we tested again with your fix for STM F1 and it looks a bit better but also weird in other places. We have an oscilloscope capable of understanding CAN and when we use the nucleo-F1 and send something the osci can see the correct data and stuff but also errors stating "Missing ACK". However connecting 2 Nucleo F1s we only see error frames, also when using a CAN Tx/Rx to CAN High/Low translation module we only see error frames. So it seems that the sender is somehow detecting an error right from the start, maybe because the RX line is hold up (or down) incorrectly. @MrKevinWeiss had similar problems when using I2C on the F1 because of missing pull ups (or downs) on the signal lines, maybe that's the problem here, too. @MrKevinWeiss what did you do or try to make the I2C work on the F1? |
There were two things I had to do, one was a problem with alternate pin function, I had to enable the alt pin remap clock then specify the i2c pins to use the alternate function pin. The second thing was I updated some documentation because you cannot have pullups on alternate function pins. I had to physically add them when testing. |
First, you can't connect two CAN controllers directly, you need CAN transceivers in between, as in this picture:
Most of the transceivers have a low power mode where they can only pass received signals but not emit signals, so you have to ensure they are in normal mode. The bus also needs to be terminated by a 120 ohm reistor at both ends of the bus (between CAN high and CAN low), see https://en.wikipedia.org/wiki/CAN_bus#/media/File:CAN_ISO11898-2_Network.png . Missing ACK means that no node on the bus ACK'ed the frame (after the transmission, all nodes on the bus should write an ACK bit on the bus). |
@vincent-d thanks for the advice, we made some more tests with a proper setup and were able to send and receive to/from another (non-RIOT) device. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code is not a beauty (especially all the #ifdef
s are annoying) but it works, so there is room for improvement. Anyways, we should get this merged first ... see comments, and then also squash please!
Makefile.dep
Outdated
@@ -634,6 +634,10 @@ ifneq (,$(filter puf_sram,$(USEMODULE))) | |||
FEATURES_REQUIRED += puf_sram | |||
endif | |||
|
|||
ifneq (,$(filter can_stm32,$(USEMODULE))) | |||
USEMODULE += xtimer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? I didn't find any usage of timer, or did I miss something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably left-over, I'll remove
tests/conn_can/Makefile
Outdated
@@ -8,7 +8,15 @@ BOARD_INSUFFICIENT_MEMORY := arduino-duemilanove arduino-mega2560 arduino-uno \ | |||
nucleo-l053r8 stm32f0discovery telosb \ | |||
waspmote-pro wsn430-v1_3b wsn430-v1_4 z1 | |||
|
|||
CFLAGS += -DLOG_LEVEL=LOG_ALL | |||
BOARDS_WITH_STM32_CANDEV := nucleo-f072rb \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's that for? actually it would be better to have an ifeq
or something matching these boards and then add USEMODULE = periph_can
bc otherwise CAN is not pulled in. At least I had to specify the USEMODULE explicitly for my nucleo-f103rb, otherwise there was no can device available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a left-over, I'll remove.
The boards supporting CAN should have a FEATURES_PROVIDED += periph_can
in their Makefile.features
to pull it in (nucleo-f413zh has it, we can expand to other boards too)
This driver is compliant with the candev interface. It has been tested with STM32F0 and STM32F2 and STM32F413 ONLY at this time but should be compliant with other STM32Fx devices
@smlng thanks so much for the review and the test. I know there is room for clean-up and improvements here, but having this merged would be the first step! Squashed! |
I would agree to merge, however Murdock does not: some documentation issues, but also there is now an ESP32 providing |
Indeed, ESP32 needs adaptation...I can take a look, but I'll need help to test it. |
@sming @vincent-d I will take a look later today to this PR and how it is related to ESP. I'm out of office at the moment. |
@vincent-d You also implement the STM32 CAN interface according to CAN device driver interface. But instead defining an architecture specific auto initialization function, you also define a new low level peripheral interface The compilation error occurs since the board definition of Two options to solve the problem:
Maybe, the easiest way for the moment might be to follow option 1 and once your PR is merged I can try to realize option 2 as separate PR. |
yep, I was thinking the same, @vincent-d please add a commit commenting out |
please squash |
Build can_stm32 module on boards which have a stm32 CAN controller.
ACK & GO |
@vincent-d I'm going to change RIOT/sys/auto_init/can/auto_init_can.c Lines 67 to 71 in 6f14de3
|
@gschorcht indeed, it seems like leftovers that slipped through...This is dead code since Feel free to remove. And thanks for working on CAN ;) Let me know if I can help to review. |
This driver is compliant with the candev interface. It has been tested
with STM32F0 and STM32F2 only at this time but should be compliant with
other STM32Fx devices.
This is based on #5793.