summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/uart.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-10-23 14:25:32 +0100
committerDamien George <damien.p.george@gmail.com>2014-10-23 14:25:32 +0100
commit185cb0d943aa73485a83e1c146d9db899973378d (patch)
tree4e3128ddb6e30ba15f666aabbddb82f8df3729c1 /stmhal/uart.c
parente7bb0443cda9bfb88791c3a99bf0331217390eb4 (diff)
downloadmicropython-185cb0d943aa73485a83e1c146d9db899973378d.tar.gz
micropython-185cb0d943aa73485a83e1c146d9db899973378d.zip
stmhal: Use OSError with POSIX error code for HAL errors.
Addresses issue #921.
Diffstat (limited to 'stmhal/uart.c')
-rw-r--r--stmhal/uart.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/stmhal/uart.c b/stmhal/uart.c
index 9abe4713ed..e06ee6b46e 100644
--- a/stmhal/uart.c
+++ b/stmhal/uart.c
@@ -29,8 +29,6 @@
#include <stdarg.h>
#include <errno.h>
-#include "stm32f4xx_hal.h"
-
#include "mpconfig.h"
#include "nlr.h"
#include "misc.h"
@@ -40,6 +38,7 @@
#include "stream.h"
#include "uart.h"
#include "pybioctl.h"
+#include MICROPY_HAL_H
/// \moduleref pyb
/// \class UART - duplex serial communication bus
@@ -94,14 +93,6 @@ struct _pyb_uart_obj_t {
byte *read_buf; // byte or uint16_t, depending on char size
};
-// this table converts from HAL_StatusTypeDef to POSIX errno
-STATIC const byte hal_status_to_errno_table[4] = {
- [HAL_OK] = 0,
- [HAL_ERROR] = EIO,
- [HAL_BUSY] = EBUSY,
- [HAL_TIMEOUT] = ETIMEDOUT,
-};
-
// pointers to all UART objects (if they have been created)
STATIC pyb_uart_obj_t *pyb_uart_obj_all[6];
@@ -563,7 +554,7 @@ STATIC mp_obj_t pyb_uart_writechar(mp_obj_t self_in, mp_obj_t char_in) {
HAL_StatusTypeDef status = HAL_UART_Transmit(&self->uart, (uint8_t*)&data, 1, self->timeout);
if (status != HAL_OK) {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, (mp_obj_t)(mp_uint_t)hal_status_to_errno_table[status]));
+ mp_hal_raise(status);
}
return mp_const_none;
@@ -713,7 +704,7 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
// return number of bytes written
return size;
} else {
- *errcode = hal_status_to_errno_table[status];
+ *errcode = mp_hal_status_to_errno_table[status];
return MP_STREAM_ERROR;
}
}