From 185cb0d943aa73485a83e1c146d9db899973378d Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 23 Oct 2014 14:25:32 +0100 Subject: stmhal: Use OSError with POSIX error code for HAL errors. Addresses issue #921. --- stmhal/uart.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'stmhal/uart.c') diff --git a/stmhal/uart.c b/stmhal/uart.c index 9abe4713e..e06ee6b46 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -29,8 +29,6 @@ #include #include -#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; } } -- cgit v1.2.3