Skip to content

Commit 224fee0

Browse files
committed
stmhal: Fix HAL error raising; make test for it.
Addresses issue adafruit#968.
1 parent aec189a commit 224fee0

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

stmhal/mphal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ const byte mp_hal_status_to_errno_table[4] = {
1616
};
1717

1818
NORETURN void mp_hal_raise(HAL_StatusTypeDef status) {
19-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, (mp_obj_t)(mp_uint_t)mp_hal_status_to_errno_table[status]));
19+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(mp_hal_status_to_errno_table[status])));
2020
}

tests/pyb/halerror.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# test hal errors
2+
3+
import pyb
4+
5+
i2c = pyb.I2C(2, pyb.I2C.MASTER)
6+
try:
7+
i2c.recv(1, 1)
8+
except OSError as e:
9+
print(repr(e))
10+
11+
can = pyb.CAN(1, pyb.CAN.NORMAL)
12+
try:
13+
can.send('1', 1, timeout=50)
14+
except OSError as e:
15+
print(repr(e))

tests/pyb/halerror.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
OSError(5,)
2+
OSError(116,)

0 commit comments

Comments
 (0)