diff options
author | Damien George <damien.p.george@gmail.com> | 2014-11-15 20:39:44 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-11-15 20:39:44 +0000 |
commit | 224fee0e1080fa7cd654de240c32c8433bb07cf9 (patch) | |
tree | acec380a63a2fe5bb6e8e33aa899749e39fba94f | |
parent | aec189a5ba4e1feac82625507851d4188f6dd510 (diff) | |
download | micropython-224fee0e1080fa7cd654de240c32c8433bb07cf9.tar.gz micropython-224fee0e1080fa7cd654de240c32c8433bb07cf9.zip |
stmhal: Fix HAL error raising; make test for it.
Addresses issue #968.
-rw-r--r-- | stmhal/mphal.c | 2 | ||||
-rw-r--r-- | tests/pyb/halerror.py | 15 | ||||
-rw-r--r-- | tests/pyb/halerror.py.exp | 2 |
3 files changed, 18 insertions, 1 deletions
diff --git a/stmhal/mphal.c b/stmhal/mphal.c index e8f242051e..7fcd982dcb 100644 --- a/stmhal/mphal.c +++ b/stmhal/mphal.c @@ -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]))); } diff --git a/tests/pyb/halerror.py b/tests/pyb/halerror.py new file mode 100644 index 0000000000..1a6bce1a7e --- /dev/null +++ b/tests/pyb/halerror.py @@ -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)) diff --git a/tests/pyb/halerror.py.exp b/tests/pyb/halerror.py.exp new file mode 100644 index 0000000000..09c9f7ad92 --- /dev/null +++ b/tests/pyb/halerror.py.exp @@ -0,0 +1,2 @@ +OSError(5,) +OSError(116,) |