diff --git a/bricks/_common/sources.mk b/bricks/_common/sources.mk index cdc3a044f..ba99c0b18 100644 --- a/bricks/_common/sources.mk +++ b/bricks/_common/sources.mk @@ -155,7 +155,6 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\ drv/gpio/gpio_stm32l4.c \ drv/imu/imu_lsm6ds3tr_c_stm32.c \ drv/ioport/ioport_pup.c \ - drv/ioport/ioport_debug_uart.c \ drv/led/led_array_pwm.c \ drv/led/led_array.c \ drv/led/led_core.c \ diff --git a/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c b/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c index 92c83b22d..edc64c9df 100644 --- a/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c +++ b/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c @@ -45,21 +45,9 @@ PROCESS(pbdrv_bluetooth_spi_process, "Bluetooth SPI"); -#define DEBUG_ON_LAST_UART_PORT (0) - -#if DEBUG_ON_LAST_UART_PORT -#include -#define DBG(...) -#define DEBUG_PRINT(...) -#define DEBUG_PRINT_PT PBDRV_IOPORT_DEBUG_UART_PT_PRINTF -static void uart_poll_callback(pbdrv_uart_dev_t *uart) { - process_poll(&pbdrv_bluetooth_spi_process); -} -#else #define DBG(...) #define DEBUG_PRINT(...) #define DEBUG_PRINT_PT(...) -#endif // hub name goes in special section so that it can be modified when flashing firmware __attribute__((section(".name"))) @@ -2271,14 +2259,6 @@ PROCESS_THREAD(pbdrv_bluetooth_spi_process, ev, data) { PROCESS_BEGIN(); - #if DEBUG_ON_LAST_UART_PORT - // Wait for the UART to be ready for debugging. - while (pbdrv_ioport_debug_uart_init(uart_poll_callback) != PBIO_SUCCESS) { - etimer_set(&timer, 100); - PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER && etimer_expired(&timer)); - } - #endif // DEBUG_ON_LAST_UART_PORT - start: // take Bluetooth chip out of reset bluetooth_reset(RESET_STATE_OUT_HIGH); diff --git a/lib/pbio/drv/ioport/ioport_debug_uart.c b/lib/pbio/drv/ioport/ioport_debug_uart.c deleted file mode 100644 index 2de0060b0..000000000 --- a/lib/pbio/drv/ioport/ioport_debug_uart.c +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2023 The Pybricks Authors - -#include - -#if PBDRV_CONFIG_IOPORT_DEBUG_UART - -#include -#include -#include - -#include - -#include -#include - -#include "ioport_pup.h" - -#if (PBDRV_CONFIG_IOPORT_NUM_DEV - PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV) != 1 -#error "PBDRV_CONFIG_IOPORT_DEBUG_UART requires exactly one port" -#endif - -// Use globals for simplified debug macro inside protothreads. -struct pt debug_printf_thread; -char debug_buffer[64]; -pbdrv_uart_dev_t *debug_uart; -pbio_error_t debug_err; - -pbio_error_t pbdrv_ioport_debug_uart_init(pbdrv_uart_poll_callback_t callback) { - - // Get the debug uart from last port. - const pbdrv_ioport_pup_port_platform_data_t *port_data = &pbdrv_ioport_pup_platform_data.ports[PBDRV_CONFIG_IOPORT_NUM_DEV - 1]; - pbio_error_t err = pbdrv_uart_get(port_data->uart_driver_index, &debug_uart); - if (err != PBIO_SUCCESS) { - debug_uart = NULL; - return err; - } - - pbdrv_uart_set_poll_callback(debug_uart, callback); - - // Enable and configure uart. - const pbdrv_ioport_pup_pins_t *pins = &port_data->pins; - pbdrv_gpio_alt(&pins->uart_rx, pins->uart_alt); - pbdrv_gpio_alt(&pins->uart_tx, pins->uart_alt); - pbdrv_gpio_out_low(&pins->uart_buf); - - pbdrv_uart_set_baud_rate(debug_uart, 115200); - pbdrv_uart_flush(debug_uart); - return PBIO_SUCCESS; -} - -void pbdrv_ioport_debug_uart_printf_buffer(const char *format, ...) { - va_list args; - va_start(args, format); - vsnprintf(debug_buffer, sizeof(debug_buffer), format, args); - va_end(args); -} - -#endif // PBDRV_CONFIG_IOPORT_DEBUG_UART diff --git a/lib/pbio/drv/ioport/ioport_debug_uart.h b/lib/pbio/drv/ioport/ioport_debug_uart.h deleted file mode 100644 index 12921d3d0..000000000 --- a/lib/pbio/drv/ioport/ioport_debug_uart.h +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2023 The Pybricks Authors - -#ifndef _INTERNAL_PBDRV_IOPORT_DEBUG_UART_H_ -#define _INTERNAL_PBDRV_IOPORT_DEBUG_UART_H_ - -#include - -#include - -#include -#include - -#if PBDRV_CONFIG_IOPORT_DEBUG_UART - -extern char debug_buffer[]; -extern struct pt debug_printf_thread; -extern pbdrv_uart_dev_t *debug_uart; -extern pbio_error_t debug_err; - -PT_THREAD(pbdrv_ioport_debug_uart_debug_printf_thread(struct pt *pt, const char *format, ...)); - -void pbdrv_ioport_debug_uart_printf_buffer(const char *format, ...); - -/** - * Spawns a task to print debug information on the last ioport. - * - * Useful for debugging from a protothread. This will pause the protothread - * until the debug message is sent, so must not be used when timing is critical. - * - * @param [in] pt Protothread to spawn on. - * @param [in] ... Format string and arguments. - */ -#define PBDRV_IOPORT_DEBUG_UART_PT_PRINTF(pt, ...) \ - pbdrv_ioport_debug_uart_printf_buffer(__VA_ARGS__); \ - if (debug_uart) { \ - PT_SPAWN(pt, &debug_printf_thread, pbdrv_uart_write(&debug_printf_thread, debug_uart, (uint8_t *)debug_buffer, strlen(debug_buffer), 250, &debug_err)); \ - } \ - -pbio_error_t pbdrv_ioport_debug_uart_init(pbdrv_uart_poll_callback_t callback); - -#else // PBDRV_CONFIG_IOPORT_DEBUG_UART - -#define PBDRV_IOPORT_DEBUG_UART_PT_PRINTF(pt, ...) - -#endif // PBDRV_CONFIG_IOPORT_DEBUG_UART - -#endif // _INTERNAL_PBDRV_IOPORT_DEBUG_UART_H_ diff --git a/lib/pbio/platform/city_hub/pbdrvconfig.h b/lib/pbio/platform/city_hub/pbdrvconfig.h index c488f276d..c06794c25 100644 --- a/lib/pbio/platform/city_hub/pbdrvconfig.h +++ b/lib/pbio/platform/city_hub/pbdrvconfig.h @@ -45,7 +45,6 @@ #define PBDRV_CONFIG_IOPORT_PUP (1) #define PBDRV_CONFIG_IOPORT_NUM_DEV (2) #define PBDRV_CONFIG_IOPORT_PUP_QUIRK_POWER_CYCLE (1) -#define PBDRV_CONFIG_IOPORT_DEBUG_UART (0) // Doesn't work. #define PBDRV_CONFIG_LED (1) #define PBDRV_CONFIG_LED_NUM_DEV (1) @@ -55,7 +54,7 @@ #define PBDRV_CONFIG_LEGODEV (1) #define PBDRV_CONFIG_LEGODEV_PUP (1) #define PBDRV_CONFIG_LEGODEV_PUP_NUM_INT_DEV (0) -#define PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV (2 - PBDRV_CONFIG_IOPORT_DEBUG_UART) +#define PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV (2) #define PBDRV_CONFIG_LEGODEV_PUP_UART (1) #define PBDRV_CONFIG_LEGODEV_MODE_INFO (1) #define PBDRV_CONFIG_LEGODEV_PUP_UART_NUM_DEV (PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV) diff --git a/lib/pbio/platform/essential_hub/pbdrvconfig.h b/lib/pbio/platform/essential_hub/pbdrvconfig.h index 16c2fc207..cccffc87b 100644 --- a/lib/pbio/platform/essential_hub/pbdrvconfig.h +++ b/lib/pbio/platform/essential_hub/pbdrvconfig.h @@ -69,7 +69,6 @@ #define PBDRV_CONFIG_IOPORT_PUP (1) #define PBDRV_CONFIG_IOPORT_NUM_DEV (2) #define PBDRV_CONFIG_IOPORT_PUP_QUIRK_POWER_CYCLE (0) -#define PBDRV_CONFIG_IOPORT_DEBUG_UART (0) #define PBDRV_CONFIG_LED (1) #define PBDRV_CONFIG_LED_NUM_DEV (2) @@ -79,7 +78,7 @@ #define PBDRV_CONFIG_LEGODEV (1) #define PBDRV_CONFIG_LEGODEV_PUP (1) #define PBDRV_CONFIG_LEGODEV_PUP_NUM_INT_DEV (0) -#define PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV (2 - PBDRV_CONFIG_IOPORT_DEBUG_UART) +#define PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV (2) #define PBDRV_CONFIG_LEGODEV_PUP_UART (1) #define PBDRV_CONFIG_LEGODEV_MODE_INFO (1) #define PBDRV_CONFIG_LEGODEV_PUP_UART_NUM_DEV (PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV) diff --git a/lib/pbio/platform/move_hub/pbdrvconfig.h b/lib/pbio/platform/move_hub/pbdrvconfig.h index 9ccd9fed1..104aeafe7 100644 --- a/lib/pbio/platform/move_hub/pbdrvconfig.h +++ b/lib/pbio/platform/move_hub/pbdrvconfig.h @@ -44,7 +44,6 @@ #define PBDRV_CONFIG_IOPORT_PUP (1) #define PBDRV_CONFIG_IOPORT_NUM_DEV (2) #define PBDRV_CONFIG_IOPORT_PUP_QUIRK_POWER_CYCLE (0) -#define PBDRV_CONFIG_IOPORT_DEBUG_UART (0) // Doesn't work. #define PBDRV_CONFIG_LED (1) #define PBDRV_CONFIG_LED_NUM_DEV (1) @@ -54,7 +53,7 @@ #define PBDRV_CONFIG_LEGODEV (1) #define PBDRV_CONFIG_LEGODEV_PUP (1) #define PBDRV_CONFIG_LEGODEV_PUP_NUM_INT_DEV (2) -#define PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV (2 - PBDRV_CONFIG_IOPORT_DEBUG_UART) +#define PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV (2) #define PBDRV_CONFIG_LEGODEV_PUP_UART (1) #define PBDRV_CONFIG_LEGODEV_MODE_INFO (0) // Reduces build size by disabling some unused features of the protocol. #define PBDRV_CONFIG_LEGODEV_PUP_UART_NUM_DEV (PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV) diff --git a/lib/pbio/platform/prime_hub/pbdrvconfig.h b/lib/pbio/platform/prime_hub/pbdrvconfig.h index 7d1b9d4a0..83c713cb1 100644 --- a/lib/pbio/platform/prime_hub/pbdrvconfig.h +++ b/lib/pbio/platform/prime_hub/pbdrvconfig.h @@ -70,7 +70,6 @@ #define PBDRV_CONFIG_IOPORT_PUP (1) #define PBDRV_CONFIG_IOPORT_NUM_DEV (6) #define PBDRV_CONFIG_IOPORT_PUP_QUIRK_POWER_CYCLE (0) -#define PBDRV_CONFIG_IOPORT_DEBUG_UART (0) #define PBDRV_CONFIG_LED (1) #define PBDRV_CONFIG_LED_NUM_DEV (5) @@ -87,7 +86,7 @@ #define PBDRV_CONFIG_LEGODEV (1) #define PBDRV_CONFIG_LEGODEV_PUP (1) #define PBDRV_CONFIG_LEGODEV_PUP_NUM_INT_DEV (0) -#define PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV (6 - PBDRV_CONFIG_IOPORT_DEBUG_UART) +#define PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV (6) #define PBDRV_CONFIG_LEGODEV_PUP_UART (1) #define PBDRV_CONFIG_LEGODEV_MODE_INFO (1) #define PBDRV_CONFIG_LEGODEV_PUP_UART_NUM_DEV (PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV) diff --git a/lib/pbio/platform/technic_hub/pbdrvconfig.h b/lib/pbio/platform/technic_hub/pbdrvconfig.h index 6e5321eb6..6f86923f9 100644 --- a/lib/pbio/platform/technic_hub/pbdrvconfig.h +++ b/lib/pbio/platform/technic_hub/pbdrvconfig.h @@ -55,7 +55,6 @@ #define PBDRV_CONFIG_IOPORT_PUP (1) #define PBDRV_CONFIG_IOPORT_NUM_DEV (4) #define PBDRV_CONFIG_IOPORT_PUP_QUIRK_POWER_CYCLE (1) -#define PBDRV_CONFIG_IOPORT_DEBUG_UART (0) #define PBDRV_CONFIG_LED (1) #define PBDRV_CONFIG_LED_NUM_DEV (1) @@ -65,7 +64,7 @@ #define PBDRV_CONFIG_LEGODEV (1) #define PBDRV_CONFIG_LEGODEV_PUP (1) #define PBDRV_CONFIG_LEGODEV_PUP_NUM_INT_DEV (0) -#define PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV (4 - PBDRV_CONFIG_IOPORT_DEBUG_UART) +#define PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV (4) #define PBDRV_CONFIG_LEGODEV_PUP_UART (1) #define PBDRV_CONFIG_LEGODEV_MODE_INFO (1) #define PBDRV_CONFIG_LEGODEV_PUP_UART_NUM_DEV (PBDRV_CONFIG_LEGODEV_PUP_NUM_EXT_DEV)