Skip to content

Move to tinyusb 0.9.0 #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 547 files
6 changes: 6 additions & 0 deletions src/rp2_common/hardware_uart/include/hardware/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ static inline uint uart_get_index(uart_inst_t *uart) {
return uart == uart1 ? 1 : 0;
}

static inline uart_inst_t *uart_get_instance(uint instance) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed by this PR, or was it just pulled in coincidentally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

static_assert(NUM_UARTS == 2, "");
invalid_params_if(UART, instance >= NUM_UARTS);
return instance ? uart1 : uart0;
}

static inline uart_hw_t *uart_get_hw(uart_inst_t *uart) {
uart_get_index(uart); // check it is a hw uart
return (uart_hw_t *)uart;
Expand Down
12 changes: 5 additions & 7 deletions src/rp2_common/pico_stdio_usb/reset_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ static uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const
}

// Support for parameterized reset via vendor interface control request
static bool resetd_control_request_cb(uint8_t __unused rhport, tusb_control_request_t const *request) {
static bool resetd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) {
// nothing to do with DATA & ACK stage
if (stage != CONTROL_STAGE_SETUP) return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are reset mcu, it should be better to reset when stage == ACK (ACK is complete), this will prevent host OS to complain about the failure of control transfer. For example, touch1200 is common way for Arduino to do reset to DFU.

https://github.com/hathach/tinyusb/blob/master/src/class/cdc/cdc_device.c#L354

    case CDC_REQUEST_SET_LINE_CODING:
      if (stage == CONTROL_STAGE_SETUP)
      {
        TU_LOG2("  Set Line Coding\r\n");
        tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
      }
      else if ( stage == CONTROL_STAGE_ACK)
      {
        if ( tud_cdc_line_coding_cb ) tud_cdc_line_coding_cb(itf, &p_cdc->line_coding);
      }
    break;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah; good point thanks


if (request->wIndex == itf_num) {

#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL
Expand Down Expand Up @@ -69,10 +72,6 @@ static bool resetd_control_request_cb(uint8_t __unused rhport, tusb_control_requ
return false;
}

static bool resetd_control_complete_cb(uint8_t __unused rhport, tusb_control_request_t __unused const *request) {
return true;
}

static bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) {
return true;
}
Expand All @@ -85,8 +84,7 @@ static usbd_class_driver_t const _resetd_driver =
.init = resetd_init,
.reset = resetd_reset,
.open = resetd_open,
.control_request = resetd_control_request_cb,
.control_complete = resetd_control_complete_cb,
.control_xfer_cb = resetd_control_xfer_cb,
.xfer_cb = resetd_xfer_cb,
.sof = NULL
};
Expand Down
40 changes: 39 additions & 1 deletion src/rp2_common/tinyusb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,46 @@ if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH})

add_library(tinyusb_board INTERFACE)
target_sources(tinyusb_board INTERFACE
${PICO_TINYUSB_PATH}/hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c
${PICO_TINYUSB_PATH}/hw/bsp/rp2040/family.c
)
target_include_directories(tinyusb_board INTERFACE ${PICO_TINYUSB_PATH}/hw/bsp/rp2040/boards/sdk_selected)

set(PICO_TINYUSB_PATH_INTERNAL ${PICO_TINYUSB_PATH} CACHE INTERNAL "")
add_library(tinyusb_example_support INTERFACE)
target_compile_definitions(tinyusb_example_support INTERFACE
CFG_TUSB_OS=OPT_OS_PICO
BOARD=pants
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👖

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops - i was checking something by deliberately using an invalid board ;-) that ain't gonna compile

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

)
target_link_libraries(tinyusb_example_support INTERFACE tinyusb_board)
endif()

# SHORT_TYPE is 'dev' or 'host'; LONG_TYPE is 'device' or 'host'
macro(internal_add_tinyusb_example SHORT_TYPE LONG_TYPE NAME )
if (TARGET tinyusb_${LONG_TYPE})
set(TARGET_NAME "usb_${SHORT_TYPE}_${NAME}")
# todo we ought to be able to include the examples, but we can't because they are very standalone
# todo maybe allow passing file names if necessary - doesn't seem to be right now
set(EXAMPLE_SOURCE_PATH ${PICO_TINYUSB_PATH_INTERNAL}/examples/${LONG_TYPE}/${NAME}/src)
file(GLOB EXAMPLE_SOURCE ${EXAMPLE_SOURCE_PATH}/*.c)
add_executable(${TARGET_NAME}
${EXAMPLE_SOURCE}
)

target_include_directories(${TARGET_NAME} PRIVATE ${EXAMPLE_SOURCE_PATH})
target_link_libraries(${TARGET_NAME} PRIVATE pico_stdlib tinyusb_${LONG_TYPE} tinyusb_example_support)
pico_add_extra_outputs(${TARGET_NAME})

# add url via pico_set_program_url
# todo lets point at the right place
#example_auto_set_url(${NAME})
endif()
endmacro()

function(add_tinyusb_device_example NAME)
internal_add_tinyusb_example(dev device ${NAME})
endfunction()

function(add_tinyusb_host_example NAME)
internal_add_tinyusb_example(host host ${NAME})
endfunction()