cancel
Showing results for 
Search instead for 
Did you mean: 

Safe way to modify CAN message before forwarding

pulsar
Associate II

I'm doing some CAN messaging between the 2 CANs of F105 where I'm forwarding the message from one to the other but perform some modifications.

Right now I set a flag in the FIFO callback functions that a message was received and the in the main while() I perform the actual work.  Question is, is it safe to simply modify the original data param from HAL_CAN_GetRxMessage and then pass it to HAL_CAN_AddTxMessage or do I need to create a copy of the data and modify/pass that to HAL_CAN_AddTxMessage.

Modifying the original data param works in development, but is it safe in real world application?

2 REPLIES 2

You have all the source, check it

aData and pHeader are ram structures you provide, so will have whatever scope you choose for them to have.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Saket_Om
ST Employee

Hello @pulsar 

In context of interrupts or multiple threads, you need to ensure that the buffer is not being accessed simultaneously from different contexts (e.g., CAN receive interrupt overwriting the buffer before transmission is complete).

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om