Homepage GitHub

3 can bus on stm32f4


(kent.martin) #1

Hi all,
I have successfully got libcanard running on the stm32f413. I have only got one port to work at a time bit all 3 have run.
My goal is to have all 3 running at once with 3 different can busses.
So a few questions came up…
I noticed in the code it enables can1 when can2 is used, is this required for the 32f4 for both can2 and can3?
The code doesn’t appear to support running multiple ports at once, has anyone done this yet?
Is there any code out there which uses DMA instead of polling? I plan to make it DMA based in the end.

My next steps will be to try getting 3 going at once and then run an (free)RTOS and then support DMA.
Any help in these would be appreciated.
BTW the SPL libraries don’t play well with cubemx. I had to hack device header a lot to get SPL from STM to work with current device headers from cubemx. If there is a set of complete libraries and device headers for the 32f4 that would be great.
Thanks.


(kent.martin) #2

Hi,
I got 3 CAN buses operating simultaneously, and running with FreeRTOS.
It is still polled so not an event driven system yet.
Any help on the interrupt or DMA driven drivers would be good.

Thanks


(Pavel Kirienko) #3

The code doesn’t appear to support running multiple ports at once, has anyone done this yet?

You will need to make a custom driver for that. The case you’re describing is not supported because the stock driver is intended for basic applications only.

Is there any code out there which uses DMA instead of polling? I plan to make it DMA based in the end.
My next steps will be to try getting 3 going at once and then run an (free)RTOS and then support DMA.

IIRC bxCAN can’t trigger DMA transfers so what you are describing might be impossible to achieve with STM32.

BTW the SPL libraries don’t play well with cubemx. I had to hack device header a lot to get SPL from STM to work with current device headers from cubemx. If there is a set of complete libraries and device headers for the 32f4 that would be great.

My best advice is to remove all traces of SPL from your hard drive and never touch it again. Can’t say anything about CubeMX since I don’t have much experience with it, but based on my experience with SPL I wouldn’t expect exceptional quality there either. Just use the registers directly.


(kent.martin) #4

I changed the driver to suit multiple ports, so all good there.
If no DMA, then is there any interrupt driven samples?
I would ideally like to have an event generated system since I am using freeRTOS.
It is quite a simple program , just needs 3 ports, so libcanard is suiting it quite well at the moment.
The SPL will do for now, it’s been many a year since I wrote my own low level drivers from register defines only.
I usually write my own drivers but on top of the manufacturers drivers, but this takes time and
a lot of reading of datasheets, so can’t justify that just yet.
I’m also wondering what bootloader is used with libcanard as i’ll need to add that shorlty.

Thanks,
Kent


(Pavel Kirienko) #5

Of course, here in the STM32 driver for libuavcan:

There is no such thing as “bootloader for libcanard” because libcanard is a just a basic low-level library. If you need a bootloader, you could code your own or you could use Kocherga:

Or maybe you could use the PX4 Brickproof Bootloader (it’s not that well-documented and in some ways could be considered technically inferior to Kocherga):