Open equinox311 opened 1 year ago
does the regular write(msg) work? if so, try to cast the 10 --> write((FLEXCAN_MAILBOX)10,msg)
I don’t recall if it worked or not, I believe it did not but I cannot remember the behavior when I tried the regular write.
I will confirm and try the cast though. Thanks :)
Same behavior as original issue.
Doing a malloc for the size of the message structure seemed to get the program to at least reset… however no change in behavior as far as proper functioning.
So I think I figured this out. Using your FlexCAN_T4 object as an extern in a different C file creates allll sorts of issues. I moved everything into one file and it seemed to work out.
Not sure if this is how this is supposed to work (C++ classes are still confusing to me), but that one threw me through a loop.
Should also note, using a pointer instead of extern also created the same issues.
Can confirm this and am seeing hard lockups when the FlexCAN_T4 object is declared extern within .h/.cpp files. Lockups occur every time when calling .write()
under these conditions, but probably can be triggered in other ways also.
Strangely this does not seem to be occurring if all files are using .ino extensions. I believe when using the arduino/PIO compile scripts with .ino files, the scope of the Can0 object will become global and the extern is ignored.
Attached is a simple example showing this. It has been tested on a Teensy 3.5
This will send a msg every 500ms and report back over Serial the total number of msgs sent. By default the Can0 object is not declared extern and everything works fine.
If you uncomment the //#define USE_EXTERN
line in FLEXCAN_T4_Issue.h
however, Can0 will be declared extern and the msg will be (or should be) sent from a function in CAN_comms.cpp
. This however causes the board to lockup as soon as .write() is called within the sendReply() function.
Hey, not sure if this is the right mechanism to explain this issue, but I am trying to call the write(mb,msg) function from a function called by a pointer, and the entire program crashes and does not recover. I do get one CAN TX, that is not always packed correctly, but that is all.
I don't know enough about all of this to make a call what is wrong, or if I am out of line trying to call a write with a function pointer, but here is the relevant code snippets minus some of the CAN setup:
Setup:
Pointer call:
Function from pointer function:
Not sure if this is an library issue, or just my bad code. Function pointer calls work great with any other function though.