Program gets stuck in Default_handler infinite loop: STM32G473QET6 custom board

I am setting my custom board up as a modbus RS485 slave on Serial2 and running tests on it. When I use my computer as a master to read registers that I have set up in the code, the slave responds correctly however, the board freezes after its response and ends up stuck in an infinite loop in the default handler. I have attached my code below

and also attached a screen grab of the debug console:

I have been stuck with this problem for over a week now, so any help would be greatly appreciated.

Is any backtrace / callstack available at all?

If in doubt, execute where in the “Debug Console”.

Sure, I have attached both:

I figured it out, the sendPDU function didn’t have a return statement, upon adding that in, everything works fine

Okay, but both library versions I’m seeing at here and here are either return type void (so no return value needed) or have return type bool but return true; is done – which library version are using in the platformio.ini? Maybe you just need a simple version update there. Editing files in .pio/libdeps is not persistent and may be eventually lost.