From c3c4f65fea69c7db53c9834cf426a831dc28f2eb Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 27 Jan 2021 13:04:38 +0700 Subject: [PATCH 1/3] wrap rp2040_usb around opt mcu --- src/portable/raspberrypi/rp2040/rp2040_usb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.c b/src/portable/raspberrypi/rp2040/rp2040_usb.c index a44607e99..5c536e314 100644 --- a/src/portable/raspberrypi/rp2040/rp2040_usb.c +++ b/src/portable/raspberrypi/rp2040/rp2040_usb.c @@ -24,10 +24,13 @@ * This file is part of the TinyUSB stack. */ +#include "tusb_option.h" + +#if CFG_TUSB_MCU == OPT_MCU_RP2040 + #include #include "rp2040_usb.h" #include "hardware/clocks.h" -#include "tusb_option.h" // Direction strings for debug const char *ep_dir_string[] = { @@ -277,3 +280,4 @@ void _hw_endpoint_xfer(struct hw_endpoint *ep, uint8_t *buffer, uint16_t total_l } } +#endif From 1abf9eeb808d9c023352c62a486e68bdf75e1ff6 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 27 Jan 2021 13:18:03 +0700 Subject: [PATCH 2/3] clean up rp2040 assigned_address, remove panic from remote_wakeup --- src/portable/raspberrypi/rp2040/dcd_rp2040.c | 11 +++-------- tools/build_family.py | 3 ++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/portable/raspberrypi/rp2040/dcd_rp2040.c b/src/portable/raspberrypi/rp2040/dcd_rp2040.c index 80e5d3c4b..aaaa22e55 100644 --- a/src/portable/raspberrypi/rp2040/dcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/dcd_rp2040.c @@ -48,7 +48,6 @@ #define usb_hw_clear hw_clear_alias(usb_hw) // Init these in dcd_init -static uint8_t assigned_address; static uint8_t *next_buffer_ptr; // Endpoints 0-15, direction 0 for out and 1 for in. @@ -319,8 +318,7 @@ static void dcd_rp2040_irq(void) if (status & USB_INTS_BUS_RESET_BITS) { pico_trace("BUS RESET (addr %d -> %d)\n", assigned_address, 0); - assigned_address = 0; - usb_hw->dev_addr_ctrl = assigned_address; + usb_hw->dev_addr_ctrl = 0; handled |= USB_INTS_BUS_RESET_BITS; dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true); usb_hw_clear->sie_status = USB_SIE_STATUS_BUS_RESET_BITS; @@ -355,7 +353,6 @@ void dcd_init (uint8_t rhport) irq_set_exclusive_handler(USBCTRL_IRQ, dcd_rp2040_irq); memset(hw_endpoints, 0, sizeof(hw_endpoints)); - assigned_address = 0; next_buffer_ptr = &usb_dpram->epx_data[0]; // EP0 always exists so init it now @@ -394,14 +391,12 @@ void dcd_set_address (uint8_t rhport, uint8_t dev_addr) assert(rhport == 0); // Can't set device address in hardware until status xfer has complete - assigned_address = dev_addr; - ep0_0len_status(); } void dcd_remote_wakeup(uint8_t rhport) { - panic("dcd_remote_wakeup %d\n", rhport); + pico_info("dcd_remote_wakeup %d is not supported yet\n", rhport); assert(rhport == 0); } @@ -435,7 +430,7 @@ void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * re request->bRequest == TUSB_REQ_SET_ADDRESS) { pico_trace("Set HW address %d\n", assigned_address); - usb_hw->dev_addr_ctrl = assigned_address; + usb_hw->dev_addr_ctrl = (uint8_t) request->wValue; } reset_ep0(); diff --git a/tools/build_family.py b/tools/build_family.py index b178d8d41..23a08c663 100644 --- a/tools/build_family.py +++ b/tools/build_family.py @@ -49,6 +49,7 @@ def build_family(example, family): for entry in os.scandir("hw/bsp/{}/boards".format(family)): if entry.is_dir(): all_boards.append(entry.name) + filter_with_input(all_boards) all_boards.sort() for board in all_boards: @@ -83,7 +84,7 @@ def build_board(example, board): print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) if build_result.returncode != 0: - print(build_result.stdout.decode("utf-8")) + print(build_result.stdout.decode("utf-8")) def build_size(example, board): #elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board) From 4fef2ddb4c500f23115781aa87afd1f83b049b9d Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 27 Jan 2021 16:37:31 +0700 Subject: [PATCH 3/3] rp2040 move uart id to board specific --- examples/device/board_test/src/main.c | 4 ---- .../boards/adafruit_feather_rp2040/board.h | 5 ++++- .../boards/adafruit_itsybitsy_rp2040/board.h | 5 ++++- .../rp2040/boards/adafruit_qt_rp2040/board.h | 6 +++++- .../rp2040/boards/raspberry_pi_pico/board.h | 5 ++++- hw/bsp/rp2040/family.c | 20 ++++++++++++++++--- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/examples/device/board_test/src/main.c b/examples/device/board_test/src/main.c index 71665550f..d94b24650 100644 --- a/examples/device/board_test/src/main.c +++ b/examples/device/board_test/src/main.c @@ -55,10 +55,6 @@ int main(void) { uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED; - // uart echo -// uint8_t ch; -// if ( board_uart_read(&ch, 1) ) board_uart_write(&ch, 1); - // Blink every interval ms if ( !(board_millis() - start_ms < interval_ms) ) { diff --git a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h index 44985cd6f..417db3d5d 100644 --- a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h +++ b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h @@ -35,10 +35,13 @@ #define LED_STATE_ON 1 // Button pin is BOOTSEL which is flash CS pin - #define BUTTON_BOOTSEL #define BUTTON_STATE_ACTIVE 0 +#define UART_DEV uart0 +#define UART_TX_PIN 0 +#define UART_RX_PIN 1 + #ifdef __cplusplus } #endif diff --git a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h index 3a2de12f9..b45008fcc 100644 --- a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h +++ b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h @@ -35,10 +35,13 @@ #define LED_STATE_ON 1 // Button pin is BOOTSEL which is flash CS pin - #define BUTTON_BOOTSEL #define BUTTON_STATE_ACTIVE 0 +#define UART_DEV uart0 +#define UART_TX_PIN 0 +#define UART_RX_PIN 1 + #ifdef __cplusplus } #endif diff --git a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h index 5f37105e7..d3850a19e 100644 --- a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h +++ b/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h @@ -36,10 +36,14 @@ #define LED_STATE_ON 1 // Button pin is BOOTSEL which is flash CS pin - #define BUTTON_BOOTSEL #define BUTTON_STATE_ACTIVE 0 + +#define UART_DEV uart0 +#define UART_TX_PIN 0 +#define UART_RX_PIN 1 + #ifdef __cplusplus } #endif diff --git a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h index 61532d8cb..e4a6514ad 100644 --- a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h +++ b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h @@ -35,10 +35,13 @@ #define LED_STATE_ON 1 // Button pin is BOOTSEL which is flash CS pin - #define BUTTON_BOOTSEL #define BUTTON_STATE_ACTIVE 0 +#define UART_DEV uart0 +#define UART_TX_PIN 0 +#define UART_RX_PIN 1 + #ifdef __cplusplus } #endif diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c index e616acd19..e0dc47b39 100644 --- a/hw/bsp/rp2040/family.c +++ b/hw/bsp/rp2040/family.c @@ -78,7 +78,6 @@ bool __no_inline_not_in_flash_func(get_bootsel_button)() { void board_init(void) { - setup_default_uart(); gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT); @@ -86,6 +85,12 @@ void board_init(void) #ifndef BUTTON_BOOTSEL #endif +#ifdef UART_DEV + uart_init(UART_DEV, CFG_BOARD_UART_BAUDRATE); + gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART); + gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART); +#endif + // todo probably set up device mode? #if TUSB_OPT_DEVICE_ENABLED @@ -116,18 +121,27 @@ uint32_t board_button_read(void) int board_uart_read(uint8_t* buf, int len) { +#ifdef UART_DEV for(int i=0;i