diff --git a/examples/host/cdc_msc_hid/.only.MCU_RP2040 b/examples/host/cdc_msc_hid/.only.MCU_RP2040 new file mode 100644 index 000000000..e69de29bb diff --git a/examples/host/cdc_msc_hid/CMakeLists.txt b/examples/host/cdc_msc_hid/CMakeLists.txt new file mode 100644 index 000000000..dc2effde9 --- /dev/null +++ b/examples/host/cdc_msc_hid/CMakeLists.txt @@ -0,0 +1,46 @@ +# use directory name for project id +get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) + +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + +# Check for -DFAMILY= +if(FAMILY STREQUAL "esp32s2") + cmake_minimum_required(VERSION 3.5) + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + project(${PROJECT}) + +elseif(FAMILY STREQUAL "rp2040") + cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) + include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) + pico_sdk_init() + add_executable(${PROJECT}) + + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + + # Example source + target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c + ) + + # Example include + target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) + pico_add_extra_outputs(${PROJECT}) + +else() + message(FATAL_ERROR "Invalid FAMILY specified") +endif() diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index e4f5f47b4..699ad174d 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -13,8 +13,15 @@ set(SRC_TINYUSB ${TOP}/src/class/net/net_device.c ${TOP}/src/class/usbtmc/usbtmc_device.c ${TOP}/src/class/vendor/vendor_device.c - ${TOP}/src/portable/raspberrypi/${FAMILY}/dcd_rp2040.c + ${TOP}/src/host/hub.c + ${TOP}/src/host/usbh.c + ${TOP}/src/host/usbh_control.c + ${TOP}/src/class/cdc/cdc_host.c + ${TOP}/src/class/hid/hid_host.c + ${TOP}/src/class/msc/msc_host.c ${TOP}/src/portable/raspberrypi/${FAMILY}/rp2040_usb.c + ${TOP}/src/portable/raspberrypi/${FAMILY}/dcd_rp2040.c + ${TOP}/src/portable/raspberrypi/${FAMILY}/hcd_rp2040.c ) target_sources(${PROJECT} PUBLIC diff --git a/src/host/usbh.c b/src/host/usbh.c index 0bc6378b2..a4ee4cb5c 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -157,6 +157,7 @@ tusb_speed_t tuh_device_get_speed (uint8_t const dev_addr) return (tusb_speed_t) _usbh_devices[dev_addr].speed; } +#if CFG_TUSB_OS == OPT_OS_NONE void osal_task_delay(uint32_t msec) { (void) msec; @@ -164,6 +165,7 @@ void osal_task_delay(uint32_t msec) const uint32_t start = hcd_frame_number(TUH_OPT_RHPORT); while ( ( hcd_frame_number(TUH_OPT_RHPORT) - start ) < msec ) {} } +#endif //--------------------------------------------------------------------+ // CLASS-USBD API (don't require to verify parameters) diff --git a/src/osal/osal.h b/src/osal/osal.h index 02e3e0a06..28bdf479c 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -66,7 +66,6 @@ typedef void (*osal_task_func_t)( void * ); //--------------------------------------------------------------------+ // OSAL Porting API //--------------------------------------------------------------------+ -//static inline void osal_task_delay(uint32_t msec); //------------- Semaphore -------------// static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef); diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index ea6818621..a1f997cf2 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -34,14 +34,7 @@ //--------------------------------------------------------------------+ // TASK API //--------------------------------------------------------------------+ -//static inline void osal_task_delay(uint32_t msec) -//{ -// (void) msec; -// // TODO only used by Host stack, will implement using SOF -// -//// uint32_t start = tusb_hal_millis(); -//// while ( ( tusb_hal_millis() - start ) < msec ) {} -//} + //--------------------------------------------------------------------+ // Binary Semaphore API diff --git a/src/osal/osal_pico.h b/src/osal/osal_pico.h index de964a7a0..c277af271 100644 --- a/src/osal/osal_pico.h +++ b/src/osal/osal_pico.h @@ -39,12 +39,10 @@ //--------------------------------------------------------------------+ // TASK API //--------------------------------------------------------------------+ -#ifndef RP2040_USB_HOST_MODE static inline void osal_task_delay(uint32_t msec) { - sleep_ms(msec); + sleep_ms(msec); } -#endif //--------------------------------------------------------------------+ // Binary Semaphore API diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.c b/src/portable/raspberrypi/rp2040/rp2040_usb.c index 70b676087..c6f6d7231 100644 --- a/src/portable/raspberrypi/rp2040/rp2040_usb.c +++ b/src/portable/raspberrypi/rp2040/rp2040_usb.c @@ -43,7 +43,7 @@ static inline void _hw_endpoint_lock_update(struct hw_endpoint *ep, int delta) { // sense to have worker and IRQ on same core, however I think using critsec is about equivalent. } -#ifdef RP2040_USB_HOST_MODE +#if TUSB_OPT_HOST_ENABLED static inline void _hw_endpoint_update_last_buf(struct hw_endpoint *ep) { ep->last_buf = ep->len + ep->transfer_size == ep->total_len; @@ -69,7 +69,7 @@ void hw_endpoint_reset_transfer(struct hw_endpoint *ep) { ep->stalled = false; ep->active = false; -#ifdef RP2040_USB_HOST_MODE +#if TUSB_OPT_HOST_ENABLED ep->sent_setup = false; #endif ep->total_len = 0; @@ -92,7 +92,7 @@ void _hw_endpoint_buffer_control_update32(struct hw_endpoint *ep, uint32_t and_m *ep->buffer_control = value & ~USB_BUF_CTRL_AVAIL; // 12 cycle delay.. (should be good for 48*12Mhz = 576Mhz) // Don't need delay in host mode as host is in charge -#ifndef RP2040_USB_HOST_MODE +#if !TUSB_OPT_HOST_ENABLED __asm volatile ( "b 1f\n" "1: b 1f\n" @@ -125,7 +125,7 @@ void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep) val |= ep->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID; ep->next_pid ^= 1u; -#ifdef RP2040_USB_HOST_MODE +#if TUSB_OPT_HOST_ENABLED // Is this the last buffer? Only really matters for host mode. Will trigger // the trans complete irq but also stop it polling. We only really care about // trans complete for setup packets being sent @@ -161,7 +161,7 @@ void _hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t t ep->transfer_size = tu_min16(total_len, ep->wMaxPacketSize); ep->active = true; ep->user_buf = buffer; -#ifdef RP2040_USB_HOST_MODE +#if TUSB_OPT_HOST_ENABLED // Recalculate if this is the last buffer _hw_endpoint_update_last_buf(ep); ep->buf_sel = 0; @@ -181,7 +181,7 @@ void _hw_endpoint_xfer_sync(struct hw_endpoint *ep) uint32_t buf_ctrl = _hw_endpoint_buffer_control_get_value32(ep); uint16_t transferred_bytes = buf_ctrl & USB_BUF_CTRL_LEN_MASK; -#ifdef RP2040_USB_HOST_MODE +#if TUSB_OPT_HOST_ENABLED // tag::host_buf_sel_fix[] if (ep->buf_sel == 1) { @@ -239,7 +239,7 @@ bool _hw_endpoint_xfer_continue(struct hw_endpoint *ep) // Now we have synced our state with the hardware. Is there more data to transfer? uint16_t remaining_bytes = ep->total_len - ep->len; ep->transfer_size = tu_min16(remaining_bytes, ep->wMaxPacketSize); -#ifdef RP2040_USB_HOST_MODE +#if TUSB_OPT_HOST_ENABLED _hw_endpoint_update_last_buf(ep); #endif diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.h b/src/portable/raspberrypi/rp2040/rp2040_usb.h index c3ad5e21f..bb88d977f 100644 --- a/src/portable/raspberrypi/rp2040/rp2040_usb.h +++ b/src/portable/raspberrypi/rp2040/rp2040_usb.h @@ -75,7 +75,7 @@ struct hw_endpoint // Interrupt, bulk, etc uint8_t transfer_type; -#ifdef RP2040_USB_HOST_MODE +#if TUSB_OPT_HOST_ENABLED // Only needed for host mode bool last_buf; // HOST BUG. Host will incorrect write status to top half of buffer