Skip to content

Commit

Permalink
stmhal: Fix HAL error raising; make test for it.
Browse files Browse the repository at this point in the history
Addresses issue #968.
  • Loading branch information
dpgeorge committed Nov 15, 2014
1 parent aec189a commit 224fee0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stmhal/mphal.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ const byte mp_hal_status_to_errno_table[4] = {
};

NORETURN void mp_hal_raise(HAL_StatusTypeDef status) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, (mp_obj_t)(mp_uint_t)mp_hal_status_to_errno_table[status]));
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(mp_hal_status_to_errno_table[status])));
}
15 changes: 15 additions & 0 deletions tests/pyb/halerror.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# test hal errors

import pyb

i2c = pyb.I2C(2, pyb.I2C.MASTER)
try:
i2c.recv(1, 1)
except OSError as e:
print(repr(e))

can = pyb.CAN(1, pyb.CAN.NORMAL)
try:
can.send('1', 1, timeout=50)
except OSError as e:
print(repr(e))
2 changes: 2 additions & 0 deletions tests/pyb/halerror.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OSError(5,)
OSError(116,)

0 comments on commit 224fee0

Please sign in to comment.