Hello,
Each time you have a question, it's recommended to first refer to the documentation either the reference manual or the datasheet.
In your case you need to refer to RM0090:
Figure 345:

Page 1108:

As you see TEC and REC counters are read only bits. So you can't reset them by software but you need conditions described in the CAN standard to reset them.
See for example this link https://www.csselectronics.com/pages/can-bus-errors-intro-tutorial#:~:text=Specifically%2C%20every%20CAN%20node%20keeps,if%20the%20TEC%20exceeds%20255
Especially the section CAN node states & error counters

But as you have errors with only two nodes you need to check your hardware, your tranceiver, its power supply, your wiring, what about terminating resistors ? do you have any EMI issues? see this link.
To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.