Commit 75337003 authored by Damien George's avatar Damien George
Browse files

stmhal: Rename USART to UART.

It's really a UART because there is no external clock line (and hence no
synchronous ability, at least in the implementation of this module).
USART should be reserved for a module that has "S"ynchronous capabilities.

Also, UART is shorter and easier to type :)
parent 806f4aef
...@@ -66,7 +66,10 @@ SRC_C = \ ...@@ -66,7 +66,10 @@ SRC_C = \
led.c \ led.c \
pin.c \ pin.c \
pin_named_pins.c \ pin_named_pins.c \
usart.c \ bufhelper.c \
i2c.c \
spi.c \
uart.c \
usb.c \ usb.c \
printf.c \ printf.c \
math.c \ math.c \
...@@ -97,9 +100,6 @@ SRC_C = \ ...@@ -97,9 +100,6 @@ SRC_C = \
servo.c \ servo.c \
dac.c \ dac.c \
adc.c \ adc.c \
bufhelper.c \
i2c.c \
spi.c \
# pybwlan.c \ # pybwlan.c \
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "pyexec.h" #include "pyexec.h"
#include "i2c.h" #include "i2c.h"
#include "spi.h" #include "spi.h"
#include "usart.h" #include "uart.h"
#include "timer.h" #include "timer.h"
#include "led.h" #include "led.h"
#include "pin.h" #include "pin.h"
...@@ -267,20 +267,20 @@ soft_reset: ...@@ -267,20 +267,20 @@ soft_reset:
// GC init // GC init
gc_init(&_heap_start, &_heap_end); gc_init(&_heap_start, &_heap_end);
// Change #if 0 to #if 1 if you want REPL on USART_6 (or another usart) // Change #if 0 to #if 1 if you want REPL on UART_6 (or another uart)
// as well as on USB VCP // as well as on USB VCP
#if 0 #if 0
{ {
mp_obj_t args[2] = { mp_obj_t args[2] = {
MP_OBJ_NEW_SMALL_INT(PYB_USART_6), MP_OBJ_NEW_SMALL_INT(PYB_UART_6),
MP_OBJ_NEW_SMALL_INT(115200), MP_OBJ_NEW_SMALL_INT(115200),
}; };
pyb_usart_global_debug = pyb_usart_type.make_new((mp_obj_t)&pyb_usart_type, pyb_uart_global_debug = pyb_uart_type.make_new((mp_obj_t)&pyb_uart_type,
sizeof(args) / sizeof(args[0]), sizeof(args) / sizeof(args[0]),
0, args); 0, args);
} }
#else #else
pyb_usart_global_debug = NULL; pyb_uart_global_debug = NULL;
#endif #endif
// Micro Python init // Micro Python init
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "rtc.h" #include "rtc.h"
#include "i2c.h" #include "i2c.h"
#include "spi.h" #include "spi.h"
#include "usart.h" #include "uart.h"
#include "adc.h" #include "adc.h"
#include "storage.h" #include "storage.h"
#include "sdcard.h" #include "sdcard.h"
...@@ -292,7 +292,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = { ...@@ -292,7 +292,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_LED), (mp_obj_t)&pyb_led_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_LED), (mp_obj_t)&pyb_led_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_i2c_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_i2c_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SPI), (mp_obj_t)&pyb_spi_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_SPI), (mp_obj_t)&pyb_spi_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_USART), (mp_obj_t)&pyb_usart_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_ADCAll), (mp_obj_t)&pyb_adc_all_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_ADCAll), (mp_obj_t)&pyb_adc_all_type },
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#if 0 #if 0
#include "lcd.h" #include "lcd.h"
#endif #endif
#include "usart.h" #include "uart.h"
#include "usb.h" #include "usb.h"
#if MICROPY_ENABLE_FLOAT #if MICROPY_ENABLE_FLOAT
...@@ -170,11 +170,11 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) { ...@@ -170,11 +170,11 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
} }
void stdout_print_strn(void *data, const char *str, unsigned int len) { void stdout_print_strn(void *data, const char *str, unsigned int len) {
// send stdout to USART, USB CDC VCP, and LCD if nothing else // send stdout to UART, USB CDC VCP, and LCD if nothing else
bool any = false; bool any = false;
if (pyb_usart_global_debug != PYB_USART_NONE) { if (pyb_uart_global_debug != PYB_UART_NONE) {
usart_tx_strn_cooked(pyb_usart_global_debug, str, len); uart_tx_strn_cooked(pyb_uart_global_debug, str, len);
any = true; any = true;
} }
if (usb_vcp_is_enabled()) { if (usb_vcp_is_enabled()) {
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include "stream.h" #include "stream.h"
#include "pybstdio.h" #include "pybstdio.h"
#include "usb.h" #include "usb.h"
#include "usart.h" #include "uart.h"
void stdout_tx_str(const char *str) { void stdout_tx_str(const char *str) {
if (pyb_usart_global_debug != PYB_USART_NONE) { if (pyb_uart_global_debug != PYB_UART_NONE) {
usart_tx_str(pyb_usart_global_debug, str); uart_tx_str(pyb_uart_global_debug, str);
} }
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD #if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
lcd_print_str(str); lcd_print_str(str);
...@@ -23,8 +23,8 @@ void stdout_tx_str(const char *str) { ...@@ -23,8 +23,8 @@ void stdout_tx_str(const char *str) {
} }
void stdout_tx_strn(const char *str, uint len) { void stdout_tx_strn(const char *str, uint len) {
if (pyb_usart_global_debug != PYB_USART_NONE) { if (pyb_uart_global_debug != PYB_UART_NONE) {
usart_tx_strn(pyb_usart_global_debug, str, len); uart_tx_strn(pyb_uart_global_debug, str, len);
} }
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD #if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
lcd_print_strn(str, len); lcd_print_strn(str, len);
...@@ -45,8 +45,8 @@ int stdin_rx_chr(void) { ...@@ -45,8 +45,8 @@ int stdin_rx_chr(void) {
#endif #endif
if (usb_vcp_rx_num() != 0) { if (usb_vcp_rx_num() != 0) {
return usb_vcp_rx_get(); return usb_vcp_rx_get();
} else if (pyb_usart_global_debug != PYB_USART_NONE && usart_rx_any(pyb_usart_global_debug)) { } else if (pyb_uart_global_debug != PYB_UART_NONE && uart_rx_any(pyb_uart_global_debug)) {
return usart_rx_char(pyb_usart_global_debug); return uart_rx_char(pyb_uart_global_debug);
} }
__WFI(); __WFI();
} }
......
...@@ -79,8 +79,8 @@ Q(off) ...@@ -79,8 +79,8 @@ Q(off)
Q(toggle) Q(toggle)
Q(intensity) Q(intensity)
// for USART class // for UART class
Q(USART) Q(UART)
Q(baudrate) Q(baudrate)
Q(bits) Q(bits)
Q(stop) Q(stop)
......
...@@ -10,47 +10,47 @@ ...@@ -10,47 +10,47 @@
#include "obj.h" #include "obj.h"
#include "runtime.h" #include "runtime.h"
#include "bufhelper.h" #include "bufhelper.h"
#include "usart.h" #include "uart.h"
// Usage model: // Usage model:
// //
// See usage model of I2C in i2c.c. USART is very similar. Main difference is // See usage model of I2C in i2c.c. UART is very similar. Main difference is
// parameters to init the USART bus: // parameters to init the UART bus:
// //
// from pyb import USART // from pyb import UART
// usart = USART(1, 9600) # init with given baudrate // uart = UART(1, 9600) # init with given baudrate
// usart.init(9600, bits=8, stop=1, parity=None) # init with given parameters // uart.init(9600, bits=8, stop=1, parity=None) # init with given parameters
// //
// Bits can be 8 or 9, stop can be 1 or 2, parity can be None, 0 (even), 1 (odd). // Bits can be 8 or 9, stop can be 1 or 2, parity can be None, 0 (even), 1 (odd).
// //
// Extra method: // Extra method:
// //
// usart.any() # returns True if any characters waiting // uart.any() # returns True if any characters waiting
struct _pyb_usart_obj_t { struct _pyb_uart_obj_t {
mp_obj_base_t base; mp_obj_base_t base;
pyb_usart_t usart_id; pyb_uart_t uart_id;
bool is_enabled; bool is_enabled;
UART_HandleTypeDef uart; UART_HandleTypeDef uart;
}; };
pyb_usart_obj_t *pyb_usart_global_debug = NULL; pyb_uart_obj_t *pyb_uart_global_debug = NULL;
// assumes Init parameters have been set up correctly // assumes Init parameters have been set up correctly
bool usart_init2(pyb_usart_obj_t *usart_obj) { bool uart_init2(pyb_uart_obj_t *uart_obj) {
USART_TypeDef *USARTx = NULL; USART_TypeDef *UARTx = NULL;
uint32_t GPIO_Pin = 0; uint32_t GPIO_Pin = 0;
uint8_t GPIO_AF_USARTx = 0; uint8_t GPIO_AF_UARTx = 0;
GPIO_TypeDef* GPIO_Port = NULL; GPIO_TypeDef* GPIO_Port = NULL;
switch (usart_obj->usart_id) { switch (uart_obj->uart_id) {
// USART1 is on PA9/PA10, PB6/PB7 // USART1 is on PA9/PA10 (CK on PA8), PB6/PB7
case PYB_USART_1: case PYB_UART_1:
USARTx = USART1; UARTx = USART1;
GPIO_AF_USARTx = GPIO_AF7_USART1; GPIO_AF_UARTx = GPIO_AF7_USART1;
#if defined(PYBV10) #if defined (PYBV4) || defined(PYBV10)
GPIO_Port = GPIOB; GPIO_Port = GPIOB;
GPIO_Pin = GPIO_PIN_6 | GPIO_PIN_7; GPIO_Pin = GPIO_PIN_6 | GPIO_PIN_7;
#else #else
...@@ -61,23 +61,21 @@ bool usart_init2(pyb_usart_obj_t *usart_obj) { ...@@ -61,23 +61,21 @@ bool usart_init2(pyb_usart_obj_t *usart_obj) {
__USART1_CLK_ENABLE(); __USART1_CLK_ENABLE();
break; break;
#if !defined(PYBV10) // USART2 is on PA2/PA3 (CK on PA4), PD5/PD6 (CK on PD7)
// USART2 is on PA2/PA3, PD5/PD6 case PYB_UART_2:
case PYB_USART_2: UARTx = USART2;
USARTx = USART2; GPIO_AF_UARTx = GPIO_AF7_USART2;
GPIO_AF_USARTx = GPIO_AF7_USART2;
GPIO_Port = GPIOD; GPIO_Port = GPIOA;
GPIO_Pin = GPIO_PIN_5 | GPIO_PIN_6; GPIO_Pin = GPIO_PIN_2 | GPIO_PIN_3;
__USART2_CLK_ENABLE(); __USART2_CLK_ENABLE();
break; break;
#endif
// USART3 is on PB10/PB11, PC10/PC11, PD8/PD9 // USART3 is on PB10/PB11 (CK on PB12), PC10/PC11 (CK on PC12), PD8/PD9 (CK on PD10)
case PYB_USART_3: case PYB_UART_3:
USARTx = USART3; UARTx = USART3;
GPIO_AF_USARTx = GPIO_AF7_USART3; GPIO_AF_UARTx = GPIO_AF7_USART3;
#if defined(PYBV3) || defined(PYBV4) | defined(PYBV10) #if defined(PYBV3) || defined(PYBV4) | defined(PYBV10)
GPIO_Port = GPIOB; GPIO_Port = GPIOB;
...@@ -90,9 +88,9 @@ bool usart_init2(pyb_usart_obj_t *usart_obj) { ...@@ -90,9 +88,9 @@ bool usart_init2(pyb_usart_obj_t *usart_obj) {
break; break;
// UART4 is on PA0/PA1, PC10/PC11 // UART4 is on PA0/PA1, PC10/PC11
case PYB_USART_4: case PYB_UART_4:
USARTx = UART4; UARTx = UART4;
GPIO_AF_USARTx = GPIO_AF8_UART4; GPIO_AF_UARTx = GPIO_AF8_UART4;
GPIO_Port = GPIOA; GPIO_Port = GPIOA;
GPIO_Pin = GPIO_PIN_0 | GPIO_PIN_1; GPIO_Pin = GPIO_PIN_0 | GPIO_PIN_1;
...@@ -100,10 +98,10 @@ bool usart_init2(pyb_usart_obj_t *usart_obj) { ...@@ -100,10 +98,10 @@ bool usart_init2(pyb_usart_obj_t *usart_obj) {
__UART4_CLK_ENABLE(); __UART4_CLK_ENABLE();
break; break;
// USART6 is on PC6/PC7 // USART6 is on PC6/PC7 (CK on PC8)
case PYB_USART_6: case PYB_UART_6:
USARTx = USART6; UARTx = USART6;
GPIO_AF_USARTx = GPIO_AF8_USART6; GPIO_AF_UARTx = GPIO_AF8_USART6;
GPIO_Port = GPIOC; GPIO_Port = GPIOC;
GPIO_Pin = GPIO_PIN_6 | GPIO_PIN_7; GPIO_Pin = GPIO_PIN_6 | GPIO_PIN_7;
...@@ -121,20 +119,20 @@ bool usart_init2(pyb_usart_obj_t *usart_obj) { ...@@ -121,20 +119,20 @@ bool usart_init2(pyb_usart_obj_t *usart_obj) {
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_PULLUP; GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Alternate = GPIO_AF_USARTx; GPIO_InitStructure.Alternate = GPIO_AF_UARTx;
HAL_GPIO_Init(GPIO_Port, &GPIO_InitStructure); HAL_GPIO_Init(GPIO_Port, &GPIO_InitStructure);
// init USARTx // init UARTx
usart_obj->uart.Instance = USARTx; uart_obj->uart.Instance = UARTx;
HAL_UART_Init(&usart_obj->uart); HAL_UART_Init(&uart_obj->uart);
usart_obj->is_enabled = true; uart_obj->is_enabled = true;
return true; return true;
} }
bool usart_init(pyb_usart_obj_t *usart_obj, uint32_t baudrate) { bool uart_init(pyb_uart_obj_t *uart_obj, uint32_t baudrate) {
UART_HandleTypeDef *uh = &usart_obj->uart; UART_HandleTypeDef *uh = &uart_obj->uart;
memset(uh, 0, sizeof(*uh)); memset(uh, 0, sizeof(*uh));
uh->Init.BaudRate = baudrate; uh->Init.BaudRate = baudrate;
uh->Init.WordLength = UART_WORDLENGTH_8B; uh->Init.WordLength = UART_WORDLENGTH_8B;
...@@ -143,12 +141,12 @@ bool usart_init(pyb_usart_obj_t *usart_obj, uint32_t baudrate) { ...@@ -143,12 +141,12 @@ bool usart_init(pyb_usart_obj_t *usart_obj, uint32_t baudrate) {
uh->Init.Mode = UART_MODE_TX_RX; uh->Init.Mode = UART_MODE_TX_RX;
uh->Init.HwFlowCtl = UART_HWCONTROL_NONE; uh->Init.HwFlowCtl = UART_HWCONTROL_NONE;
uh->Init.OverSampling = UART_OVERSAMPLING_16; uh->Init.OverSampling = UART_OVERSAMPLING_16;
return usart_init2(usart_obj); return uart_init2(uart_obj);
} }
void usart_deinit(pyb_usart_obj_t *usart_obj) { void uart_deinit(pyb_uart_obj_t *uart_obj) {
usart_obj->is_enabled = false; uart_obj->is_enabled = false;
UART_HandleTypeDef *uart = &usart_obj->uart; UART_HandleTypeDef *uart = &uart_obj->uart;
HAL_UART_DeInit(uart); HAL_UART_DeInit(uart);
if (uart->Instance == USART1) { if (uart->Instance == USART1) {
__USART1_FORCE_RESET(); __USART1_FORCE_RESET();
...@@ -173,50 +171,50 @@ void usart_deinit(pyb_usart_obj_t *usart_obj) { ...@@ -173,50 +171,50 @@ void usart_deinit(pyb_usart_obj_t *usart_obj) {
} }
} }
bool usart_rx_any(pyb_usart_obj_t *usart_obj) { bool uart_rx_any(pyb_uart_obj_t *uart_obj) {
return __HAL_UART_GET_FLAG(&usart_obj->uart, UART_FLAG_RXNE); return __HAL_UART_GET_FLAG(&uart_obj->uart, UART_FLAG_RXNE);
} }
int usart_rx_char(pyb_usart_obj_t *usart_obj) { int uart_rx_char(pyb_uart_obj_t *uart_obj) {
uint8_t ch; uint8_t ch;
if (HAL_UART_Receive(&usart_obj->uart, &ch, 1, 0) != HAL_OK) { if (HAL_UART_Receive(&uart_obj->uart, &ch, 1, 0) != HAL_OK) {
ch = 0; ch = 0;
} }
return ch; return ch;
} }
void usart_tx_char(pyb_usart_obj_t *usart_obj, int c) { void uart_tx_char(pyb_uart_obj_t *uart_obj, int c) {
uint8_t ch = c; uint8_t ch = c;
HAL_UART_Transmit(&usart_obj->uart, &ch, 1, 100000); HAL_UART_Transmit(&uart_obj->uart, &ch, 1, 100000);
} }
void usart_tx_str(pyb_usart_obj_t *usart_obj, const char *str) { void uart_tx_str(pyb_uart_obj_t *uart_obj, const char *str) {
HAL_UART_Transmit(&usart_obj->uart, (uint8_t*)str, strlen(str), 100000); HAL_UART_Transmit(&uart_obj->uart, (uint8_t*)str, strlen(str), 100000);
} }
void usart_tx_strn(pyb_usart_obj_t *usart_obj, const char *str, uint len) { void uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len) {
HAL_UART_Transmit(&usart_obj->uart, (uint8_t*)str, len, 100000); HAL_UART_Transmit(&uart_obj->uart, (uint8_t*)str, len, 100000);
} }
void usart_tx_strn_cooked(pyb_usart_obj_t *usart_obj, const char *str, uint len) { void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len) {
for (const char *top = str + len; str < top; str++) { for (const char *top = str + len; str < top; str++) {
if (*str == '\n') { if (*str == '\n') {
usart_tx_char(usart_obj, '\r'); uart_tx_char(uart_obj, '\r');
} }
usart_tx_char(usart_obj, *str); uart_tx_char(uart_obj, *str);
} }
} }
/******************************************************************************/ /******************************************************************************/
/* Micro Python bindings */ /* Micro Python bindings */
STATIC void pyb_usart_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { STATIC void pyb_uart_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_usart_obj_t *self = self_in; pyb_uart_obj_t *self = self_in;
if (!self->is_enabled) { if (!self->is_enabled) {
print(env, "USART(%lu)", self->usart_id); print(env, "UART(%lu)", self->uart_id);
} else { } else {
print(env, "USART(%lu, baudrate=%u, bits=%u, stop=%u", print(env, "UART(%lu, baudrate=%u, bits=%u, stop=%u",
self->usart_id, self->uart.Init.BaudRate, self->uart_id, self->uart.Init.BaudRate,
self->uart.Init.WordLength == UART_WORDLENGTH_8B ? 8 : 9, self->uart.Init.WordLength == UART_WORDLENGTH_8B ? 8 : 9,
self->uart.Init.StopBits == UART_STOPBITS_1 ? 1 : 2); self->uart.Init.StopBits == UART_STOPBITS_1 ? 1 : 2);
if (self->uart.Init.Parity == UART_PARITY_NONE) { if (self->uart.Init.Parity == UART_PARITY_NONE) {
...@@ -227,20 +225,20 @@ STATIC void pyb_usart_print(void (*print)(void *env, const char *fmt, ...), void ...@@ -227,20 +225,20 @@ STATIC void pyb_usart_print(void (*print)(void *env, const char *fmt, ...), void
} }
} }
STATIC const mp_arg_parse_t pyb_usart_init_accepted_args[] = { STATIC const mp_arg_parse_t pyb_uart_init_accepted_args[] = {
{ MP_QSTR_baudrate, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_INT, {.u_int = 9600} }, { MP_QSTR_baudrate, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_INT, {.u_int = 9600} },
{ MP_QSTR_bits, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 8} }, { MP_QSTR_bits, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 8} },
{ MP_QSTR_stop, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 1} }, { MP_QSTR_stop, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 1} },
{ MP_QSTR_parity, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_parity, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_OBJ, {.u_obj = mp_const_none} },
}; };
#define PYB_USART_INIT_NUM_ARGS (sizeof(pyb_usart_init_accepted_args) / sizeof(pyb_usart_init_accepted_args[0])) #define PYB_UART_INIT_NUM_ARGS (sizeof(pyb_uart_init_accepted_args) / sizeof(pyb_uart_init_accepted_args[0]))
STATIC mp_obj_t pyb_usart_init_helper(pyb_usart_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// parse args // parse args
mp_arg_parse_val_t vals[PYB_USART_INIT_NUM_ARGS]; mp_arg_parse_val_t vals[PYB_UART_INIT_NUM_ARGS];
mp_arg_parse_all(n_args, args, kw_args, PYB_USART_INIT_NUM_ARGS, pyb_usart_init_accepted_args, vals); mp_arg_parse_all(n_args, args, kw_args, PYB_UART_INIT_NUM_ARGS, pyb_uart_init_accepted_args, vals);
// set the USART configuration values // set the UART configuration values
memset(&self->uart, 0, sizeof(self->uart)); memset(&self->uart, 0, sizeof(self->uart));
UART_InitTypeDef *init = &self->uart.Init; UART_InitTypeDef *init = &self->uart.Init;
init->BaudRate = vals[0].u_int; init->BaudRate = vals[0].u_int;
...@@ -259,90 +257,90 @@ STATIC mp_obj_t pyb_usart_init_helper(pyb_usart_obj_t *self, uint n_args, const ...@@ -259,90 +257,90 @@ STATIC mp_obj_t pyb_usart_init_helper(pyb_usart_obj_t *self, uint n_args, const
init->HwFlowCtl = UART_HWCONTROL_NONE; init->HwFlowCtl = UART_HWCONTROL_NONE;
init->OverSampling = UART_OVERSAMPLING_16; init->OverSampling = UART_OVERSAMPLING_16;
// init USART (if it fails, it's because the port doesn't exist) // init UART (if it fails, it's because the port doesn't exist)
if (!usart_init2(self)) { if (!uart_init2(self)) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "USART port %d does not exist", self->usart_id)); nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART port %d does not exist", self->uart_id));
} }
return mp_const_none; return mp_const_none;
} }
STATIC mp_obj_t pyb_usart_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// check arguments // check arguments
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
// create object // create object
pyb_usart_obj_t *o = m_new_obj(pyb_usart_obj_t); pyb_uart_obj_t *o = m_new_obj(pyb_uart_obj_t);
o->base.type = &pyb_usart_type; o->base.type = &pyb_uart_type;
// work out port // work out port
o->usart_id = 0; o->uart_id = 0;
if (MP_OBJ_IS_STR(args[0])) { if (MP_OBJ_IS_STR(args[0])) {
const char *port = mp_obj_str_get_str(args[0]); const char *port = mp_obj_str_get_str(args[0]);
if (0) { if (0) {
#if defined(PYBV10) #if defined(PYBV10)
} else if (strcmp(port, "XA") == 0) { } else if (strcmp(port, "XA") == 0) {
o->usart_id = PYB_USART_XA; o->uart_id = PYB_UART_XA;
} else if (strcmp(port, "XB") == 0) { } else if (strcmp(port, "XB") == 0) {
o->usart_id = PYB_USART_XB; o->uart_id = PYB_UART_XB;
} else if (strcmp(port, "YA") == 0) { } else if (strcmp(port, "YA") == 0) {
o->usart_id = PYB_USART_YA; o->uart_id = PYB_UART_YA;
} else if (strcmp(port, "YB") == 0) { } else if (strcmp(port, "YB") == 0) {
o->usart_id = PYB_USART_YB; o->uart_id = PYB_UART_YB;
#endif #endif