[SOLVED] Avoid blocking code execution (erase flash) for TWAI

leschge
Posts: 36
Joined: Fri May 06, 2022 1:38 pm

Re: Avoid blocking code execution (erase flash)

Postby leschge » Fri Apr 05, 2024 11:31 am

DrMickeyLauer wrote:
Thu Apr 04, 2024 10:03 am
I'm not sure I entirely understand your code, but: Here's a way to serve TWAI efficiently:

1. CONFIG_TWAI_ISR_IN_IRAM=y
2. When calling twai_driver_install(), the intr_flags member of twai_general_config_t should set the ESP_INTR_FLAG_IRAM set.
3. Create a mid-high priority TWAI receiver task that blocks in twai_receive until cancelled. Upon receiving a frame, put it into a FreeRTOS queue with sufficient number of elements (I use 558 to accommodate for a complete ISOTP frame). Put this code in IRAM.
4. In your "normal" code, have a task that blocks on the FreeRTOS queue forever and handles the arriving frames.
5. Don't print anything other than, say, an accumulated number of frames arriving per second. Printing is SLOW
Thank you very much, this did the trick! Seems to be working stable now.

Who is online

Users browsing this forum: Bing [Bot], ShinyGlossy and 231 guests