FreeRTOS with CAN interrupt. It seems like im missing messages when using CAN with freertos. I know that the CAN bus is half duplex. Since i have no control over the Rx messages, how do i sync the tx task with the rx callback?
You don't have to task switch on the interrupt, and you don't need to use the HAL callback methodology.
If you use the callbacks, do very little and leave quickly, if you block or do unnecessary processing you will likely get data loss. Make sure you extract all the data from the peripheral.
The peripheral should manage the RX/TX on the bus.
1. You don't have to task switch on the interrupt, and you don't need to
use the HAL callback methodology.
are you saying that i should call HAL_CAN_Receive_IT and
HAL_CAN_Transmit_IT from the same thread (task) so i don't have to worry
about them being call at the same time?
Currently In "HAL_CAN_RxCpltCallback" I am using "msg_CAN_rx =
(CanRxMsgTypeDef *) osMailAlloc(CAN_rx_mail_box, 0);" to malloc the memory
needed to add to "osMailPut(CAN_rx_mail_box, msg_CAN_rx);". it works fine
if i send CAN messages slowly from my PC CAN tool (about 3 pre sec).
Do you recommend using a single task to Rx and Tx CAN messages, then use a
separate task to parse the CAN rx data? I can use the mail box to queue the
messages then pass it to the CAN_Rx_Parse() task.
thanks for the help.
On Thu, Oct 5, 2017 at 2:06 PM, Clive One <firstname.lastname@example.org>
It is important to understand the callback is under interrupt context, so additional ones are unlikely to preempt, allocating memory or printing also should be avoided.
I'm not a huge fan of the HAL paradigm, and I'm saying don't be bound by it, or assume it is thread safe. Walk the library code and understand how it interacts with itself and the peripheral.
I use the BxCan on MBED and RTOS and Bare Metal.
all in the same processor family, STM32F series. '072 '091 '767
Definitely, as Clive says above, you want to exit any interrupt very quickly.
it is best to receive under interrupt, then write to a buffer and exit.
I use a 64 deep buffer, upto 64 message will be received under interrupt control before a buffer overrun will occur.
then in the foreground you can leisurely check each frame from the buffer
I have many posts here describing my work, maybe you can search for them
Retrieving data ...