stmhal: Fix HAL error raising; make test for it.

Addresses issue #968.