1) What I want to do
I am currently working on an OpenMV Cam M7 and trying to implement CAN communication with another STM32 card that transmits a lot of messages (some every 10ms). As the microcontroller can only store 3 messages in its FIFO and as the CAN bus 2 (the only one available on the OpenMV Cam) only has 2 FIFO (that I can specify through the Filters), I want to implement a software FIFO.
2) The problem
The problem is that the function to extract a message from the FIFO (CAN.recv(fifo)) cannot be used in an ISR because it allocates some memory and that allocating memory cannot be done in an ISR. Has anyone managed to solve this problem ?
3) Places where this question was already answered
I found some people that already had this problem but it wasn't resolved or can't / don't know how to do it on the OpenMV Cam
viewtopic.php?f=14&t=2099&p=11871&hilit ... ecv#p11871
viewtopic.php?t=1967
CAN ISR - MemoryError due to can.recv(0)
Re: CAN ISR - MemoryError due to can.recv(0)
Kind of a sticky one. It would be nice if there were a version of CAN.recv() that wrote to a pre-allocated buffer.
My first thought would be to use array.array() to pre-allocate a buffer, and then write the call-back as inline assembly that read from the hardware registers and wrote to the pre-allocated buffer. Kind of painful but that's the best suggestion I have right now.
My first thought would be to use array.array() to pre-allocate a buffer, and then write the call-back as inline assembly that read from the hardware registers and wrote to the pre-allocated buffer. Kind of painful but that's the best suggestion I have right now.
Re: CAN ISR - MemoryError due to can.recv(0)
Thank you for the reply.
I ended up going through another microcontroller (programmed in C++) to control my peripherals and limiting the amount of message going to the micropython board.
I ended up going through another microcontroller (programmed in C++) to control my peripherals and limiting the amount of message going to the micropython board.
Re: CAN ISR - MemoryError due to can.recv(0)
Note that "softirq" functionality as mentioned in one of your linked threads became micropython.schedule(), which is parhaps another solution to this problem.