moonglow / pcan_pro_x

:alien: XCAN PRO/PRO FD/FD USB2CAN firmware implementation for cheap STM32F4 hardware
Do What The F*ck You Want To Public License
231 stars 140 forks source link

Make it crash if CAN Init fails. #10

Closed tomaszduda23 closed 3 years ago

tomaszduda23 commented 3 years ago

Otherwise it crashes later on during port open.

moonglow commented 3 years ago

assert != crash, it is just checking for fatal condition, like in your case because hardware was miss-configured correctly #8 . It will also disappear if user will set NDEBUG define during build, so i think for future purpose we need some better solution if you want try to check hardware during runtime.

tomaszduda23 commented 3 years ago

The problem is that CAN Init fail (pcan_can_init_ex) is not handled in any way. There are several ways that it could be done:

  1. Do not create USB endpoint if CAN Init fails for given bus
  2. Try to reinit during opening the device

If CAN Init fails HAL_CAN_ActivateNotification is never called again which seems to be a bug. Anyway there is a several ways to solve it. assert was just simple enough and worked perfect for me.

moonglow commented 3 years ago

it will happens only if your hardware is connected wrong way, I'm sorry but i really don't like such solution. I do not want to tell that current solution is OK, but we need something better.

tomaszduda23 commented 3 years ago

I agree that it is bad solution. It was just good enough for the problem which I had. Maybe you can consider this as "improvement request". It would be nice if HW misconfiguration is handled somehow. I guess I'm not going to be only one who run into this problem.