2019-11-10 12:54 PM
Hi all,
I’m trying to test the can bus function with the STM32F042, I’ve studied all the Datasheet but I’m trying to find the best solution for an efficient store for incoming messages..
My question is if I don’t know the right amount of incoming ID how can I set the right size of the array used to store messages?
Thanks in advance.
2019-11-10 02:06 PM
Not sure anyone here understands your application better than you do..
How long do you need to "store" the messages?
How long do you take to process/dispatch the messages to other layers of your application?
Presumably just be adding an SD card you card record whatever depth of messages your users might conceivably want.
'
Make a queue structure. Dynamically allocate on start-up based on user configuration.
2019-11-10 11:47 PM
That depends on your application.
CAN application, or devices mainly using CAN, are usually cycle-based.
My company mainly works with CANopen, and operates on a 10ms cycle. Some periodic communication is based on multiples of this 10ms base cycle.
Each message is supposedly processed in/during this cycle.
And, as suggested, the event-based CAN bus is decoupled via input and output queues.
Our applications use data transferred via CAN (like sensor values, set values) for control operation, but does not store CAN messages itself.
That messages become obsolete in the next cycle.
Unless you want to build a CAN trace device.
2019-11-11 12:43 AM
Thank you all for the answer,
No I don't want to trace the CAN bus but my question is if I have e.g. the following IDs 0x200 & 0x10, for save this messages on my application I've to create an array of 200 so I burn a lot of memory.. It is usuful to use the FMI (Filter Match Index) number but I read on some discussion that is does not work perfectly. Another way for me is to create a table for compering the ID, 0x200 -> 0 ; 0x10 -> 1 .... Could I spend too much time on interrupt routine?
Thanks.
2019-11-11 01:12 AM
> ... but my question is if I have e.g. the following IDs 0x200 & 0x10, ...
Not quite sure what you mean.
To be honest, I didn't use CAN on STM32 MCUs. My company's devices are built on other MCUs (many of them CortexM3/4, too).
We do not use message filtering either, because with CANopen, your device gets a bunch of "scattered" CAN-IDs to react to.
This is what the CAN stack takes care of - pull the received messages out of the hardware buffer (mailbox), and either drop it, or copy it into the appropriate software queue. This could be done in an interrupt context, but anything else in the "normal" application context.
> .... Could I spend too much time on interrupt routine?
Definitely. A common problem, especially with Cube/HAL code. Depending on priorities, you might block other interrupts as well.
> ...for save this messages on my application I've to create an array of 200 so I burn a lot of memory ...
I don't know your application, so storing a certain amount of values might be indicated.
First, I would reduce the size of the stored object to a minimum - a CAn message has a max. payload size of 8 bytes.
Second, you could investigate alternatives algorithms - similar to a moving average method versus full iterations.
2019-11-11 03:18 AM
I think the filter and prioritization was aimed at slower machines. Given the minimal packet size it shouldn't be a challenge to dispatch/discard.
I think the interrupt should not be processing requests, it should use queues and leave. How deep the queues need to be depends on how efficiently you digest and process messages. If you are getting overwhelmed you probably need to review your approach and streamline or pipeline the requests and processing algorithm.