refactor debug UART to console UART; get working on ESP32
This commit is contained in:
parent
b0efd130c9
commit
8bb369cac5
@ -60,7 +60,7 @@
|
|||||||
#define MICROPY_PORT_ROOT_POINTERS \
|
#define MICROPY_PORT_ROOT_POINTERS \
|
||||||
CIRCUITPY_COMMON_ROOT_POINTERS
|
CIRCUITPY_COMMON_ROOT_POINTERS
|
||||||
|
|
||||||
#define CIRCUITPY_DEBUG_UART_TX (&pin_GPIO14)
|
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO14)
|
||||||
#define CIRCUITPY_DEBUG_UART_RX (&pin_GPIO15)
|
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO15)
|
||||||
|
|
||||||
#endif // __INCLUDED_MPCONFIGPORT_H
|
#endif // __INCLUDED_MPCONFIGPORT_H
|
||||||
|
@ -47,5 +47,6 @@
|
|||||||
// Explanation of how a user got into safe mode
|
// Explanation of how a user got into safe mode
|
||||||
#define BOARD_USER_SAFE_MODE_ACTION translate("pressing SW38 button at start up.\n")
|
#define BOARD_USER_SAFE_MODE_ACTION translate("pressing SW38 button at start up.\n")
|
||||||
|
|
||||||
#define CIRCUITPY_DEBUG_UART_TX (&pin_GPIO8)
|
// UART pins attached to the USB-serial converter chip
|
||||||
#define CIRCUITPY_DEBUG_UART_RX (&pin_GPIO7)
|
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
|
||||||
|
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)
|
||||||
|
@ -37,5 +37,5 @@
|
|||||||
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
||||||
|
|
||||||
// Serial over UART
|
// Serial over UART
|
||||||
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
|
#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX
|
||||||
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX
|
#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX
|
||||||
|
@ -37,5 +37,5 @@
|
|||||||
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
||||||
|
|
||||||
// Serial over UART
|
// Serial over UART
|
||||||
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
|
#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX
|
||||||
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX
|
#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX
|
||||||
|
@ -37,5 +37,5 @@
|
|||||||
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
||||||
|
|
||||||
// Serial over UART
|
// Serial over UART
|
||||||
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
|
#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX
|
||||||
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX
|
#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
#define DEFAULT_UART_BUS_RX (&pin_GPIO20)
|
#define DEFAULT_UART_BUS_RX (&pin_GPIO20)
|
||||||
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
||||||
|
|
||||||
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
|
#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX
|
||||||
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX
|
#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
#define DEFAULT_UART_BUS_RX (&pin_GPIO20)
|
#define DEFAULT_UART_BUS_RX (&pin_GPIO20)
|
||||||
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
||||||
|
|
||||||
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
|
#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX
|
||||||
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX
|
#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX
|
||||||
|
@ -44,5 +44,5 @@
|
|||||||
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
|
||||||
|
|
||||||
// Serial over UART
|
// Serial over UART
|
||||||
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
|
#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX
|
||||||
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX
|
#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX
|
||||||
|
@ -50,8 +50,8 @@ static void uart_event_task(void *param) {
|
|||||||
if (xQueueReceive(self->event_queue, &event, portMAX_DELAY)) {
|
if (xQueueReceive(self->event_queue, &event, portMAX_DELAY)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case UART_PATTERN_DET:
|
case UART_PATTERN_DET:
|
||||||
// When the debug uart receives CTRL+C, wake the main task and schedule a keyboard interrupt
|
// When the console uart receives CTRL+C, wake the main task and schedule a keyboard interrupt
|
||||||
if (self->is_debug) {
|
if (self->is_console) {
|
||||||
port_wake_main_task();
|
port_wake_main_task();
|
||||||
if (mp_interrupt_char == CHAR_CTRL_C) {
|
if (mp_interrupt_char == CHAR_CTRL_C) {
|
||||||
uart_flush(self->uart_num);
|
uart_flush(self->uart_num);
|
||||||
@ -60,8 +60,8 @@ static void uart_event_task(void *param) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UART_DATA:
|
case UART_DATA:
|
||||||
// When the debug uart receives any key, wake the main task
|
// When the console uart receives any key, wake the main task
|
||||||
if (self->is_debug) {
|
if (self->is_console) {
|
||||||
port_wake_main_task();
|
port_wake_main_task();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -162,13 +162,15 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||||||
uart_set_mode(self->uart_num, mode) != ESP_OK) {
|
uart_set_mode(self->uart_num, mode) != ESP_OK) {
|
||||||
mp_raise_RuntimeError(translate("UART init"));
|
mp_raise_RuntimeError(translate("UART init"));
|
||||||
}
|
}
|
||||||
// On the debug uart, enable pattern detection to look for CTRL+C
|
|
||||||
#ifdef CIRCUITPY_DEBUG_UART_RX
|
// On the console uart, enable pattern detection to look for CTRL+C
|
||||||
if (rx == CIRCUITPY_DEBUG_UART_RX) {
|
#if CIRCUITPY_CONSOLE_UART
|
||||||
self->is_debug = true;
|
if (rx == CIRCUITPY_CONSOLE_UART_RX) {
|
||||||
|
self->is_console = true;
|
||||||
uart_enable_pattern_det_baud_intr(self->uart_num, CHAR_CTRL_C, 1, 1, 0, 0);
|
uart_enable_pattern_det_baud_intr(self->uart_num, CHAR_CTRL_C, 1, 1, 0, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Start a task to listen for uart events
|
// Start a task to listen for uart events
|
||||||
xTaskCreatePinnedToCore(
|
xTaskCreatePinnedToCore(
|
||||||
uart_event_task,
|
uart_event_task,
|
||||||
|
@ -46,7 +46,7 @@ typedef struct {
|
|||||||
uint8_t character_bits;
|
uint8_t character_bits;
|
||||||
bool rx_error;
|
bool rx_error;
|
||||||
uint32_t timeout_ms;
|
uint32_t timeout_ms;
|
||||||
bool is_debug;
|
bool is_console;
|
||||||
QueueHandle_t event_queue;
|
QueueHandle_t event_queue;
|
||||||
TaskHandle_t event_task;
|
TaskHandle_t event_task;
|
||||||
} busio_uart_obj_t;
|
} busio_uart_obj_t;
|
||||||
|
@ -196,7 +196,7 @@ void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool pin_number_is_free(gpio_num_t pin_number) {
|
bool pin_number_is_free(gpio_num_t pin_number) {
|
||||||
return in_use & PIN_BIT(pin_number);
|
return !(in_use & PIN_BIT(pin_number));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
|
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
|
||||||
|
@ -27,6 +27,10 @@
|
|||||||
#include "py/mpconfig.h"
|
#include "py/mpconfig.h"
|
||||||
#include "supervisor/serial.h"
|
#include "supervisor/serial.h"
|
||||||
|
|
||||||
|
#if CIRCUITPY_ESP_USB_SERIAL_JTAG && CIRCUITPY_CONSOLE_UART
|
||||||
|
#error CIRCUITPY_ESP_USB_SERIAL_JTAG and CIRCUITPY_CONSOLE_UART cannot both be enabled.
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_ESP_USB_SERIAL_JTAG
|
#if CIRCUITPY_ESP_USB_SERIAL_JTAG
|
||||||
#include "supervisor/usb_serial_jtag.h"
|
#include "supervisor/usb_serial_jtag.h"
|
||||||
#endif
|
#endif
|
||||||
@ -37,14 +41,13 @@ void port_serial_init(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool port_serial_connected(void) {
|
bool port_serial_connected(void) {
|
||||||
#if CIRCUITPY_ESP_USB_SERIAL_JTAG
|
#if CIRCUITPY_ESP_USB_SERIAL_JTAG
|
||||||
if (usb_serial_jtag_connected()) {
|
return usb_serial_jtag_connected();
|
||||||
return true;
|
#else
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
char port_serial_read(void) {
|
char port_serial_read(void) {
|
||||||
@ -58,12 +61,10 @@ char port_serial_read(void) {
|
|||||||
|
|
||||||
bool port_serial_bytes_available(void) {
|
bool port_serial_bytes_available(void) {
|
||||||
#if CIRCUITPY_ESP_USB_SERIAL_JTAG
|
#if CIRCUITPY_ESP_USB_SERIAL_JTAG
|
||||||
if (usb_serial_jtag_bytes_available()) {
|
return usb_serial_jtag_bytes_available();
|
||||||
return true;
|
#else
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void port_serial_write_substring(const char *text, uint32_t length) {
|
void port_serial_write_substring(const char *text, uint32_t length) {
|
||||||
|
@ -16,9 +16,8 @@
|
|||||||
#define DEFAULT_UART_BUS_RX (&pin_GPIO_AD_B1_07)
|
#define DEFAULT_UART_BUS_RX (&pin_GPIO_AD_B1_07)
|
||||||
#define DEFAULT_UART_BUS_TX (&pin_GPIO_AD_B1_06)
|
#define DEFAULT_UART_BUS_TX (&pin_GPIO_AD_B1_06)
|
||||||
|
|
||||||
#define CIRCUITPY_DEBUG_UART_TX (&pin_GPIO_AD_B0_12)
|
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO_AD_B0_12)
|
||||||
#define CIRCUITPY_DEBUG_UART_RX (&pin_GPIO_AD_B0_13)
|
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO_AD_B0_13)
|
||||||
|
|
||||||
|
|
||||||
// Put host on the first USB so that right angle OTG adapters can fit. This is
|
// Put host on the first USB so that right angle OTG adapters can fit. This is
|
||||||
// the right port when looking at the board.
|
// the right port when looking at the board.
|
||||||
|
@ -33,9 +33,7 @@
|
|||||||
#include "fsl_clock.h"
|
#include "fsl_clock.h"
|
||||||
#include "fsl_lpuart.h"
|
#include "fsl_lpuart.h"
|
||||||
|
|
||||||
// TODO: Switch this to using DEBUG_UART.
|
#if defined(CIRCUITPY_CONSOLE_UART)
|
||||||
// If the board defined a debug uart tx or rx pin then we enable this code
|
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_TX) || defined(CIRCUITPY_DEBUG_UART_RX)
|
|
||||||
// static LPUART_Type *uart_instance = LPUART1; // evk
|
// static LPUART_Type *uart_instance = LPUART1; // evk
|
||||||
static LPUART_Type *uart_instance = LPUART4; // feather 1011
|
static LPUART_Type *uart_instance = LPUART4; // feather 1011
|
||||||
// static LPUART_Type *uart_instance = LPUART2; // feather 1062
|
// static LPUART_Type *uart_instance = LPUART2; // feather 1062
|
||||||
@ -89,4 +87,4 @@ void port_serial_write_substring(const char *text, uint32_t len) {
|
|||||||
|
|
||||||
LPUART_WriteBlocking(uart_instance, (uint8_t *)text, len);
|
LPUART_WriteBlocking(uart_instance, (uint8_t *)text, len);
|
||||||
}
|
}
|
||||||
#endif // USE_DEBUG_PORT_CODE
|
#endif // CIRCUITPY_CONSOLE_UART
|
||||||
|
@ -52,5 +52,6 @@
|
|||||||
#define BOOTLOADER_SETTING_SIZE (0)
|
#define BOOTLOADER_SETTING_SIZE (0)
|
||||||
|
|
||||||
#define BOARD_HAS_32KHZ_XTAL (0)
|
#define BOARD_HAS_32KHZ_XTAL (0)
|
||||||
#define CIRCUITPY_DEBUG_UART_TX (&pin_P0_06)
|
|
||||||
#define CIRCUITPY_DEBUG_UART_RX (&pin_P1_08)
|
#define CIRCUITPY_CONSOLE_UART_TX (&pin_P0_06)
|
||||||
|
#define CIRCUITPY_CONSOLE_UART_RX (&pin_P1_08)
|
||||||
|
@ -46,5 +46,5 @@
|
|||||||
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal
|
#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) // ST boards use the STLink clock signal
|
||||||
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
|
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
|
||||||
|
|
||||||
#define CIRCUITPY_DEBUG_UART_TX (&pin_PD08)
|
#define CIRCUITPY_CONSOLE_UART_TX (&pin_PD08)
|
||||||
#define CIRCUITPY_DEBUG_UART_RX (&pin_PD09)
|
#define CIRCUITPY_CONSOLE_UART_RX (&pin_PD09)
|
||||||
|
@ -198,10 +198,11 @@ typedef long mp_off_t;
|
|||||||
|
|
||||||
|
|
||||||
// extra built in names to add to the global namespace
|
// extra built in names to add to the global namespace
|
||||||
|
// Not indented so as not to confused the editor.
|
||||||
#define MICROPY_PORT_BUILTINS \
|
#define MICROPY_PORT_BUILTINS \
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_help), (mp_obj_t)&mp_builtin_help_obj }, \
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_help), (mp_obj_t)&mp_builtin_help_obj }, \
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, \
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// board-specific definitions, which control and may override definitions below.
|
// board-specific definitions, which control and may override definitions below.
|
||||||
@ -296,6 +297,18 @@ typedef long mp_off_t;
|
|||||||
#define BOARD_UART_ROOT_POINTER mp_obj_t board_uart_bus;
|
#define BOARD_UART_ROOT_POINTER mp_obj_t board_uart_bus;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CIRCUITPY_CONSOLE_UART_RX) || defined(CIRCUITPY_CONSOLE_UART_TX)
|
||||||
|
#if !(defined(CIRCUITPY_CONSOLE_UART_RX) && defined(CIRCUITPY_CONSOLE_UART_TX))
|
||||||
|
#error Both CIRCUITPY_CONSOLE_UART_RX and CIRCUITPY_CONSOLE_UART_TX must be defined if one is defined.
|
||||||
|
#endif
|
||||||
|
#define CIRCUITPY_CONSOLE_UART (1)
|
||||||
|
#ifndef CIRCUITPY_CONSOLE_UART_BAUDRATE
|
||||||
|
#define CIRCUITPY_CONSOLE_UART_BAUDRATE (115200)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define CIRCUITPY_CONSOLE_UART (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
// These CIRCUITPY_xxx values should all be defined in the *.mk files as being on or off.
|
// These CIRCUITPY_xxx values should all be defined in the *.mk files as being on or off.
|
||||||
// So if any are not defined in *.mk, they'll throw an error here.
|
// So if any are not defined in *.mk, they'll throw an error here.
|
||||||
|
|
||||||
|
@ -168,9 +168,6 @@ CFLAGS += -DCIRCUITPY_OPT_LOAD_ATTR_FAST_PATH=$(CIRCUITPY_OPT_LOAD_ATTR_FAST_PAT
|
|||||||
CIRCUITPY_OPT_MAP_LOOKUP_CACHE ?= $(CIRCUITPY_FULL_BUILD)
|
CIRCUITPY_OPT_MAP_LOOKUP_CACHE ?= $(CIRCUITPY_FULL_BUILD)
|
||||||
CFLAGS += -DCIRCUITPY_OPT_MAP_LOOKUP_CACHE=$(CIRCUITPY_OPT_MAP_LOOKUP_CACHE)
|
CFLAGS += -DCIRCUITPY_OPT_MAP_LOOKUP_CACHE=$(CIRCUITPY_OPT_MAP_LOOKUP_CACHE)
|
||||||
|
|
||||||
CIRCUITPY_CONSOLE_UART ?= 0
|
|
||||||
CFLAGS += -DCIRCUITPY_CONSOLE_UART=$(CIRCUITPY_CONSOLE_UART)
|
|
||||||
|
|
||||||
CIRCUITPY_COUNTIO ?= $(CIRCUITPY_FULL_BUILD)
|
CIRCUITPY_COUNTIO ?= $(CIRCUITPY_FULL_BUILD)
|
||||||
CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
|
CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
|
||||||
|
|
||||||
|
@ -51,12 +51,13 @@ bool serial_connected(void);
|
|||||||
|
|
||||||
// These have no-op versions that are weak and the port can override. They work
|
// These have no-op versions that are weak and the port can override. They work
|
||||||
// in tandem with the cross-port mechanics like USB and BLE.
|
// in tandem with the cross-port mechanics like USB and BLE.
|
||||||
|
void port_serial_early_init(void);
|
||||||
void port_serial_init(void);
|
void port_serial_init(void);
|
||||||
bool port_serial_connected(void);
|
bool port_serial_connected(void);
|
||||||
char port_serial_read(void);
|
char port_serial_read(void);
|
||||||
bool port_serial_bytes_available(void);
|
bool port_serial_bytes_available(void);
|
||||||
void port_serial_write_substring(const char *text, uint32_t length);
|
void port_serial_write_substring(const char *text, uint32_t length);
|
||||||
|
|
||||||
int debug_uart_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
int console_uart_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H
|
#endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H
|
||||||
|
@ -45,42 +45,43 @@
|
|||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
#if CIRCUITPY_CONSOLE_UART
|
||||||
* Note: DEBUG_UART currently only works on STM32 and nRF.
|
|
||||||
* Enabling on another platform will cause a crash.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_TX) || defined(CIRCUITPY_DEBUG_UART_RX)
|
|
||||||
#include "py/mpprint.h"
|
#include "py/mpprint.h"
|
||||||
#include "shared-bindings/busio/UART.h"
|
#include "shared-bindings/busio/UART.h"
|
||||||
busio_uart_obj_t debug_uart;
|
|
||||||
byte buf_array[256];
|
busio_uart_obj_t console_uart;
|
||||||
|
// on Espressif, the receive buffer must be larger than the hardware FIFO length. See uart_driver_install().
|
||||||
|
#if defined(SOC_UART_FIFO_LEN)
|
||||||
|
byte console_uart_rx_buf[SOC_UART_FIFO_LEN + 1];
|
||||||
|
#else
|
||||||
|
byte console_uart_rx_buf[64];
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_USB_VENDOR
|
#if CIRCUITPY_USB_VENDOR
|
||||||
bool tud_vendor_connected(void);
|
bool tud_vendor_connected(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_TX)
|
#if CIRCUITPY_CONSOLE_UART
|
||||||
STATIC void debug_uart_print_strn(void *env, const char *str, size_t len) {
|
STATIC void console_uart_print_strn(void *env, const char *str, size_t len) {
|
||||||
(void)env;
|
(void)env;
|
||||||
int uart_errcode;
|
int uart_errcode;
|
||||||
common_hal_busio_uart_write(&debug_uart, (const uint8_t *)str, len, &uart_errcode);
|
common_hal_busio_uart_write(&console_uart, (const uint8_t *)str, len, &uart_errcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
const mp_print_t debug_uart_print = {NULL, debug_uart_print_strn};
|
const mp_print_t console_uart_print = {NULL, console_uart_print_strn};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int debug_uart_printf(const char *fmt, ...) {
|
int console_uart_printf(const char *fmt, ...) {
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_TX)
|
#if CIRCUITPY_CONSOLE_UART
|
||||||
// Skip prints that occur before debug serial is started. It's better than
|
// Skip prints that occur before console serial is started. It's better than
|
||||||
// crashing.
|
// crashing.
|
||||||
if (common_hal_busio_uart_deinited(&debug_uart)) {
|
if (common_hal_busio_uart_deinited(&console_uart)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
int ret = mp_vprintf(&debug_uart_print, fmt, ap);
|
int ret = mp_vprintf(&console_uart_print, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
@ -88,6 +89,9 @@ int debug_uart_printf(const char *fmt, ...) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MP_WEAK void port_serial_early_init(void) {
|
||||||
|
}
|
||||||
|
|
||||||
MP_WEAK void port_serial_init(void) {
|
MP_WEAK void port_serial_init(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,29 +113,24 @@ MP_WEAK void port_serial_write_substring(const char *text, uint32_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void serial_early_init(void) {
|
void serial_early_init(void) {
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_TX) || defined(CIRCUITPY_DEBUG_UART_RX)
|
// Set up console UART, if enabled.
|
||||||
debug_uart.base.type = &busio_uart_type;
|
|
||||||
|
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_RX)
|
#if CIRCUITPY_CONSOLE_UART
|
||||||
const mcu_pin_obj_t *rx = MP_OBJ_TO_PTR(CIRCUITPY_DEBUG_UART_RX);
|
console_uart.base.type = &busio_uart_type;
|
||||||
#else
|
|
||||||
const mcu_pin_obj_t *rx = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_TX)
|
const mcu_pin_obj_t *console_rx = MP_OBJ_TO_PTR(CIRCUITPY_CONSOLE_UART_RX);
|
||||||
const mcu_pin_obj_t *tx = MP_OBJ_TO_PTR(CIRCUITPY_DEBUG_UART_TX);
|
const mcu_pin_obj_t *console_tx = MP_OBJ_TO_PTR(CIRCUITPY_CONSOLE_UART_TX);
|
||||||
#else
|
|
||||||
const mcu_pin_obj_t *tx = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
common_hal_busio_uart_construct(&debug_uart, tx, rx, NULL, NULL, NULL,
|
common_hal_busio_uart_construct(&console_uart, console_tx, console_rx, NULL, NULL, NULL,
|
||||||
false, 115200, 8, BUSIO_UART_PARITY_NONE, 1, 1.0f, 64,
|
false, 115200, 8, BUSIO_UART_PARITY_NONE, 1, 1.0f, sizeof(console_uart_rx_buf),
|
||||||
buf_array, true);
|
console_uart_rx_buf, true);
|
||||||
common_hal_busio_uart_never_reset(&debug_uart);
|
common_hal_busio_uart_never_reset(&console_uart);
|
||||||
|
|
||||||
// Do an initial print so that we can confirm the serial output is working.
|
// Do an initial print so that we can confirm the serial output is working.
|
||||||
debug_uart_printf("Serial debug setup\r\n");
|
console_uart_printf("Serial console setup\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
port_serial_early_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_init(void) {
|
void serial_init(void) {
|
||||||
@ -145,7 +144,7 @@ bool serial_connected(void) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_TX) && defined(CIRCUITPY_DEBUG_UART_RX)
|
#if CIRCUITPY_CONSOLE_UART
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -180,11 +179,11 @@ char serial_read(void) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_RX)
|
#if CIRCUITPY_CONSOLE_UART
|
||||||
if (common_hal_busio_uart_rx_characters_available(&debug_uart)) {
|
if (common_hal_busio_uart_rx_characters_available(&console_uart)) {
|
||||||
int uart_errcode;
|
int uart_errcode;
|
||||||
char text;
|
char text;
|
||||||
common_hal_busio_uart_read(&debug_uart, (uint8_t *)&text, 1, &uart_errcode);
|
common_hal_busio_uart_read(&console_uart, (uint8_t *)&text, 1, &uart_errcode);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -217,8 +216,8 @@ bool serial_bytes_available(void) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_RX)
|
#if CIRCUITPY_CONSOLE_UART
|
||||||
if (common_hal_busio_uart_rx_characters_available(&debug_uart)) {
|
if (common_hal_busio_uart_rx_characters_available(&console_uart)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -261,10 +260,10 @@ void serial_write_substring(const char *text, uint32_t length) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CIRCUITPY_DEBUG_UART_TX)
|
#if CIRCUITPY_CONSOLE_UART
|
||||||
int uart_errcode;
|
int uart_errcode;
|
||||||
|
|
||||||
common_hal_busio_uart_write(&debug_uart, (const uint8_t *)text, length, &uart_errcode);
|
common_hal_busio_uart_write(&console_uart, (const uint8_t *)text, length, &uart_errcode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_SERIAL_BLE
|
#if CIRCUITPY_SERIAL_BLE
|
||||||
|
@ -48,8 +48,8 @@ extern "C" {
|
|||||||
// COMMON CONFIGURATION
|
// COMMON CONFIGURATION
|
||||||
// --------------------------------------------------------------------+
|
// --------------------------------------------------------------------+
|
||||||
|
|
||||||
// When debugging TinyUSB, only output to the UART debug link.
|
// When debugging TinyUSB, only output to the console UART link.
|
||||||
#if CIRCUITPY_DEBUG_TINYUSB > 0 && defined(CIRCUITPY_DEBUG_UART_TX)
|
#if CIRCUITPY_DEBUG_TINYUSB > 0 && defined(CIRCUITPY_CONSOLE_UART)
|
||||||
#define CFG_TUSB_DEBUG CIRCUITPY_DEBUG_TINYUSB
|
#define CFG_TUSB_DEBUG CIRCUITPY_DEBUG_TINYUSB
|
||||||
#define CFG_TUSB_DEBUG_PRINTF debug_uart_printf
|
#define CFG_TUSB_DEBUG_PRINTF debug_uart_printf
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user