From faa31152b4473166e099fc02500534018ce8c465 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 26 May 2021 20:25:44 +0700 Subject: [PATCH 01/47] rename usbd_edpt_iso_xfer to usbd_edpt_xfer_fifo --- src/class/audio/audio_device.c | 6 +++--- src/device/usbd.c | 2 +- src/device/usbd_pvt.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/class/audio/audio_device.c b/src/class/audio/audio_device.c index 72533013c..3afe6ce3f 100644 --- a/src/class/audio/audio_device.c +++ b/src/class/audio/audio_device.c @@ -548,7 +548,7 @@ static bool audiod_rx_done_cb(uint8_t rhport, audiod_function_t* audio, uint16_t TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_out, audio->lin_buf_out, audio->ep_out_sz), false); #else // Data is already placed in EP FIFO, schedule for next receive - TU_VERIFY(usbd_edpt_iso_xfer(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false); + TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false); #endif #endif @@ -852,7 +852,7 @@ static bool audiod_tx_done_cb(uint8_t rhport, audiod_function_t * audio) TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_in, audio->lin_buf_in, n_bytes_tx)); #else // Send everything in ISO EP FIFO - TU_VERIFY(usbd_edpt_iso_xfer(rhport, audio->ep_in, &audio->ep_in_ff, n_bytes_tx)); + TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_in, &audio->ep_in_ff, n_bytes_tx)); #endif #endif @@ -1611,7 +1611,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const * #if USE_LINEAR_BUFFER_RX TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_out, audio->lin_buf_out, audio->ep_out_sz), false); #else - TU_VERIFY(usbd_edpt_iso_xfer(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false); + TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false); #endif } diff --git a/src/device/usbd.c b/src/device/usbd.c index 8454a2951..71c5d4e6c 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -1271,7 +1271,7 @@ bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t // bytes should be written and second to keep the return value free to give back a boolean // success message. If total_bytes is too big, the FIFO will copy only what is available // into the USB buffer! -bool usbd_edpt_iso_xfer(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes) +bool usbd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes) { uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const dir = tu_edpt_dir(ep_addr); diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index 44310f022..c42bfd97b 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -73,7 +73,7 @@ void usbd_edpt_close(uint8_t rhport, uint8_t ep_addr); bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes); // Submit a usb ISO transfer by use of a FIFO (ring buffer) - all bytes in FIFO get transmitted -bool usbd_edpt_iso_xfer(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes); +bool usbd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes); // Claim an endpoint before submitting a transfer. // If caller does not make any transfer, it must release endpoint for others. From 814edec89f5440b5dad43cc405e97af4f8fae175 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 26 May 2021 20:29:18 +0700 Subject: [PATCH 02/47] clean up --- src/tusb_option.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tusb_option.h b/src/tusb_option.h index b317f7630..feff013c7 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -55,11 +55,11 @@ #define OPT_MCU_NRF5X 100 ///< Nordic nRF5x series // SAM -#define OPT_MCU_SAMD11 204 ///< MicroChip SAMD11 #define OPT_MCU_SAMD21 200 ///< MicroChip SAMD21 #define OPT_MCU_SAMD51 201 ///< MicroChip SAMD51 -#define OPT_MCU_SAME5X 203 ///< MicroChip SAM E5x #define OPT_MCU_SAMG 202 ///< MicroChip SAMDG series +#define OPT_MCU_SAME5X 203 ///< MicroChip SAM E5x +#define OPT_MCU_SAMD11 204 ///< MicroChip SAMD11 #define OPT_MCU_SAML22 205 ///< MicroChip SAML22 // STM32 From c7cecf28c8bd409c3032a11180333654c90020d4 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 27 May 2021 00:13:07 +0700 Subject: [PATCH 03/47] clean up --- README.md | 2 +- src/common/tusb_fifo.h | 13 ++++++------- src/device/usbd.h | 4 ++-- src/device/usbd_pvt.h | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index bef49eea4..f7b2cd811 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Supports multiple device configurations by dynamically changing usb descriptors. TinyUSB is completely thread-safe by pushing all ISR events into a central queue, then process it later in the non-ISR context task function. It also uses semaphore/mutex to access shared resources such as CDC FIFO. Therefore the stack needs to use some of OS's basic APIs. Following OSes are already supported out of the box. -- **No OS** : Disabling USB IRQ is used as way to provide mutex +- **No OS** - **FreeRTOS** - **Mynewt** Due to the newt package build system, Mynewt examples are better to be on its [own repo](https://github.com/hathach/mynewt-tinyusb-example) diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h index 8d73911f0..1f9da94d1 100644 --- a/src/common/tusb_fifo.h +++ b/src/common/tusb_fifo.h @@ -53,9 +53,6 @@ extern "C" { #define tu_fifo_mutex_t osal_mutex_t #endif -/** \struct tu_fifo_t - * \brief Simple Circular FIFO - */ typedef struct { uint8_t* buffer ; ///< buffer pointer @@ -104,7 +101,8 @@ bool tu_fifo_clear(tu_fifo_t *f); bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable); #if CFG_FIFO_MUTEX -static inline void tu_fifo_config_mutex(tu_fifo_t *f, tu_fifo_mutex_t write_mutex_hdl, tu_fifo_mutex_t read_mutex_hdl) +TU_ATTR_ALWAYS_INLINE static inline +void tu_fifo_config_mutex(tu_fifo_t *f, tu_fifo_mutex_t write_mutex_hdl, tu_fifo_mutex_t read_mutex_hdl) { f->mutex_wr = write_mutex_hdl; f->mutex_rd = read_mutex_hdl; @@ -129,15 +127,16 @@ uint16_t tu_fifo_remaining (tu_fifo_t* f); bool tu_fifo_overflowed (tu_fifo_t* f); void tu_fifo_correct_read_pointer (tu_fifo_t* f); -static inline uint16_t tu_fifo_depth(tu_fifo_t* f) +static inline +uint16_t tu_fifo_depth(tu_fifo_t* f) { return f->depth; } // Pointer modifications intended to be used in combinations with DMAs. // USE WITH CARE - NO SAFTY CHECKS CONDUCTED HERE! NOT MUTEX PROTECTED! -void tu_fifo_advance_write_pointer (tu_fifo_t *f, uint16_t n); -void tu_fifo_advance_read_pointer (tu_fifo_t *f, uint16_t n); +void tu_fifo_advance_write_pointer(tu_fifo_t *f, uint16_t n); +void tu_fifo_advance_read_pointer (tu_fifo_t *f, uint16_t n); // If you want to read/write from/to the FIFO by use of a DMA, you may need to conduct two copies // to handle a possible wrapping part. These functions deliver a pointer to start diff --git a/src/device/usbd.h b/src/device/usbd.h index 53519c4de..3857295d7 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -70,8 +70,8 @@ bool tud_mounted(void); bool tud_suspended(void); // Check if device is ready to transfer -TU_ATTR_ALWAYS_INLINE -static inline bool tud_ready(void) +TU_ATTR_ALWAYS_INLINE static inline +bool tud_ready(void) { return tud_mounted() && !tud_suspended(); } diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index c42bfd97b..65fdadf51 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -94,7 +94,7 @@ void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr); // Check if endpoint is stalled bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr); -static inline +TU_ATTR_ALWAYS_INLINE static inline bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr) { return !usbd_edpt_busy(rhport, ep_addr) && !usbd_edpt_stalled(rhport, ep_addr); From 9736e54734a85c03d9055c24414e23f112a67968 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 27 May 2021 17:40:39 +0700 Subject: [PATCH 04/47] include clean up --- src/class/audio/audio_device.c | 3 +- src/class/audio/audio_device.h | 4 -- src/class/bth/bth_device.c | 1 - src/class/cdc/cdc_device.c | 4 +- src/class/cdc/cdc_device.h | 1 - src/class/dfu/dfu_device.c | 4 +- src/class/dfu/dfu_device.h | 2 - src/class/dfu/dfu_rt_device.c | 4 +- src/class/dfu/dfu_rt_device.h | 2 - src/class/hid/hid_device.c | 5 ++- src/class/hid/hid_device.h | 2 - src/class/midi/midi_device.c | 5 ++- src/class/midi/midi_device.h | 3 -- src/class/msc/msc_device.c | 5 ++- src/class/msc/msc_device.h | 72 +++++++++++++------------------- src/class/net/net_device.c | 4 +- src/class/net/net_device.h | 1 - src/class/usbtmc/usbtmc_device.c | 8 +--- src/class/vendor/vendor_device.c | 4 +- src/class/vendor/vendor_device.h | 1 - src/common/tusb_common.h | 5 ++- src/device/dcd.h | 1 + 22 files changed, 62 insertions(+), 79 deletions(-) diff --git a/src/class/audio/audio_device.c b/src/class/audio/audio_device.c index 3afe6ce3f..8e4420ed0 100644 --- a/src/class/audio/audio_device.c +++ b/src/class/audio/audio_device.c @@ -55,9 +55,10 @@ //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ +#include "device/usbd.h" #include "device/usbd_pvt.h" + #include "audio_device.h" -//#include "common/tusb_fifo.h" //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF diff --git a/src/class/audio/audio_device.h b/src/class/audio/audio_device.h index b8e6ef9c0..5a469523c 100644 --- a/src/class/audio/audio_device.h +++ b/src/class/audio/audio_device.h @@ -28,10 +28,6 @@ #ifndef _TUSB_AUDIO_DEVICE_H_ #define _TUSB_AUDIO_DEVICE_H_ -#include "assert.h" -#include "common/tusb_common.h" -#include "device/usbd.h" - #include "audio.h" //--------------------------------------------------------------------+ diff --git a/src/class/bth/bth_device.c b/src/class/bth/bth_device.c index 481dc134e..1d27ae7c5 100755 --- a/src/class/bth/bth_device.c +++ b/src/class/bth/bth_device.c @@ -32,7 +32,6 @@ // INCLUDE //--------------------------------------------------------------------+ #include "bth_device.h" -#include #include //--------------------------------------------------------------------+ diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index f5853fddb..cac811c45 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -28,9 +28,11 @@ #if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_CDC) -#include "cdc_device.h" +#include "device/usbd.h" #include "device/usbd_pvt.h" +#include "cdc_device.h" + //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 986585c5b..7ff757add 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -28,7 +28,6 @@ #define _TUSB_CDC_DEVICE_H_ #include "common/tusb_common.h" -#include "device/usbd.h" #include "cdc.h" //--------------------------------------------------------------------+ diff --git a/src/class/dfu/dfu_device.c b/src/class/dfu/dfu_device.c index 8496cb02b..81045ff7b 100644 --- a/src/class/dfu/dfu_device.c +++ b/src/class/dfu/dfu_device.c @@ -28,9 +28,11 @@ #if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_DFU_MODE) -#include "dfu_device.h" +#include "device/usbd.h" #include "device/usbd_pvt.h" +#include "dfu_device.h" + //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ diff --git a/src/class/dfu/dfu_device.h b/src/class/dfu/dfu_device.h index c45c436c5..9a09a46b1 100644 --- a/src/class/dfu/dfu_device.h +++ b/src/class/dfu/dfu_device.h @@ -27,8 +27,6 @@ #ifndef _TUSB_DFU_DEVICE_H_ #define _TUSB_DFU_DEVICE_H_ -#include "common/tusb_common.h" -#include "device/usbd.h" #include "dfu.h" #ifdef __cplusplus diff --git a/src/class/dfu/dfu_rt_device.c b/src/class/dfu/dfu_rt_device.c index faeae9b68..07e6f30f3 100644 --- a/src/class/dfu/dfu_rt_device.c +++ b/src/class/dfu/dfu_rt_device.c @@ -28,9 +28,11 @@ #if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_DFU_RUNTIME) -#include "dfu_rt_device.h" +#include "device/usbd.h" #include "device/usbd_pvt.h" +#include "dfu_rt_device.h" + //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ diff --git a/src/class/dfu/dfu_rt_device.h b/src/class/dfu/dfu_rt_device.h index 0e5fd005a..babaa8214 100644 --- a/src/class/dfu/dfu_rt_device.h +++ b/src/class/dfu/dfu_rt_device.h @@ -27,8 +27,6 @@ #ifndef _TUSB_DFU_RT_DEVICE_H_ #define _TUSB_DFU_RT_DEVICE_H_ -#include "common/tusb_common.h" -#include "device/usbd.h" #include "dfu.h" #ifdef __cplusplus diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 0d9cdb22b..c7f5d04ec 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -31,10 +31,11 @@ //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ -#include "common/tusb_common.h" -#include "hid_device.h" +#include "device/usbd.h" #include "device/usbd_pvt.h" +#include "hid_device.h" + //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 61274be4d..beb755888 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -27,8 +27,6 @@ #ifndef _TUSB_HID_DEVICE_H_ #define _TUSB_HID_DEVICE_H_ -#include "common/tusb_common.h" -#include "device/usbd.h" #include "hid.h" #ifdef __cplusplus diff --git a/src/class/midi/midi_device.c b/src/class/midi/midi_device.c index 2c50bc4f3..953ca26e6 100644 --- a/src/class/midi/midi_device.c +++ b/src/class/midi/midi_device.c @@ -31,10 +31,11 @@ //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ -#include "midi_device.h" -#include "class/audio/audio.h" +#include "device/usbd.h" #include "device/usbd_pvt.h" +#include "midi_device.h" + //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ diff --git a/src/class/midi/midi_device.h b/src/class/midi/midi_device.h index 67f03930c..211edc8d1 100644 --- a/src/class/midi/midi_device.h +++ b/src/class/midi/midi_device.h @@ -27,9 +27,6 @@ #ifndef _TUSB_MIDI_DEVICE_H_ #define _TUSB_MIDI_DEVICE_H_ -#include "common/tusb_common.h" -#include "device/usbd.h" - #include "class/audio/audio.h" #include "midi.h" diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 539941935..9b06b7a33 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -28,11 +28,12 @@ #if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_MSC) -#include "common/tusb_common.h" -#include "msc_device.h" +#include "device/usbd.h" #include "device/usbd_pvt.h" #include "device/dcd.h" // for faking dcd_event_xfer_complete +#include "msc_device.h" + //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index 469f2f2f7..8f90ef4ad 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -28,7 +28,6 @@ #define _TUSB_MSC_DEVICE_H_ #include "common/tusb_common.h" -#include "device/usbd.h" #include "msc.h" #ifdef __cplusplus @@ -51,53 +50,45 @@ TU_VERIFY_STATIC(CFG_TUD_MSC_EP_BUFSIZE < UINT16_MAX, "Size is not correct"); -/** \addtogroup ClassDriver_MSC - * @{ - * \defgroup MSC_Device Device - * @{ */ +//--------------------------------------------------------------------+ +// Application API +//--------------------------------------------------------------------+ +// Set SCSI sense response bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier); //--------------------------------------------------------------------+ // Application Callbacks (WEAK is optional) //--------------------------------------------------------------------+ -/** - * Invoked when received \ref SCSI_CMD_READ_10 command - * \param[in] lun Logical unit number - * \param[in] lba Logical Block Address to be read - * \param[in] offset Byte offset from LBA - * \param[out] buffer Buffer which application need to update with the response data. - * \param[in] bufsize Requested bytes - * - * \return Number of byte read, if it is less than requested bytes by \a \b bufsize. Tinyusb will transfer - * this amount first and invoked this again for remaining data. - * - * \retval zero Indicate application is not ready yet to response e.g disk I/O is not complete. - * tinyusb will invoke this callback with the same parameters again some time later. - * - * \retval negative Indicate error e.g reading disk I/O. tinyusb will \b STALL the corresponding - * endpoint and return failed status in command status wrapper phase. - */ +// Invoked when received SCSI READ10 command +// - Address = lba * BLOCK_SIZE + offset +// - offset is only needed if CFG_TUD_MSC_EP_BUFSIZE is smaller than BLOCK_SIZE. +// +// - Application fill the buffer (up to bufsize) with address contents and return number of read byte. If +// - read < bufsize : These bytes are transferred first and callback invoked again for remaining data. +// +// - read == 0 : Indicate application is not ready yet e.g disk I/O busy. +// Callback invoked again with the same parameters later on. +// +// - read < 0 : Indicate application error e.g invalid address. This request will be STALLed +// and return failed status in command status wrapper phase. int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize); -/** - * Invoked when received \ref SCSI_CMD_WRITE_10 command - * \param[in] lun Logical unit number - * \param[in] lba Logical Block Address to be write - * \param[in] offset Byte offset from LBA - * \param[out] buffer Buffer which holds written data. - * \param[in] bufsize Requested bytes - * - * \return Number of byte written, if it is less than requested bytes by \a \b bufsize. Tinyusb will proceed with - * other work and invoked this again with adjusted parameters. - * - * \retval zero Indicate application is not ready yet e.g disk I/O is not complete. - * Tinyusb will invoke this callback with the same parameters again some time later. - * - * \retval negative Indicate error writing disk I/O. Tinyusb will \b STALL the corresponding - * endpoint and return failed status in command status wrapper phase. - */ +// Invoked when received SCSI WRITE10 command +// - Address = lba * BLOCK_SIZE + offset +// - offset is only needed if CFG_TUD_MSC_EP_BUFSIZE is smaller than BLOCK_SIZE. +// +// - Application write data from buffer to address contents (up to bufsize) and return number of written byte. If +// - write < bufsize : callback invoked again with remaining data later on. +// +// - write == 0 : Indicate application is not ready yet e.g disk I/O busy. +// Callback invoked again with the same parameters later on. +// +// - write < 0 : Indicate application error e.g invalid address. This request will be STALLed +// and return failed status in command status wrapper phase. +// +// TODO change buffer to const uint8_t* int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize); // Invoked when received SCSI_CMD_INQUIRY @@ -152,9 +143,6 @@ TU_ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[1 // Hook to make a mass storage device read-only. TODO remove TU_ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun); -/** @} */ -/** @} */ - //--------------------------------------------------------------------+ // Internal Class Driver API //--------------------------------------------------------------------+ diff --git a/src/class/net/net_device.c b/src/class/net/net_device.c index ce1131223..9d9719ce4 100644 --- a/src/class/net/net_device.c +++ b/src/class/net/net_device.c @@ -29,8 +29,10 @@ #if ( TUSB_OPT_DEVICE_ENABLED && CFG_TUD_NET ) -#include "net_device.h" +#include "device/usbd.h" #include "device/usbd_pvt.h" + +#include "net_device.h" #include "rndis_protocol.h" void rndis_class_set_handler(uint8_t *data, int size); /* found in ./misc/networking/rndis_reports.c */ diff --git a/src/class/net/net_device.h b/src/class/net/net_device.h index 38c47d647..f5f0cd8f1 100644 --- a/src/class/net/net_device.h +++ b/src/class/net/net_device.h @@ -28,7 +28,6 @@ #ifndef _TUSB_NET_DEVICE_H_ #define _TUSB_NET_DEVICE_H_ -#include "common/tusb_common.h" #include "device/usbd.h" #include "class/cdc/cdc.h" diff --git a/src/class/usbtmc/usbtmc_device.c b/src/class/usbtmc/usbtmc_device.c index d5f8fe41d..c1ee49f45 100644 --- a/src/class/usbtmc/usbtmc_device.c +++ b/src/class/usbtmc/usbtmc_device.c @@ -77,15 +77,11 @@ #if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_USBTMC) -#include -#include "usbtmc.h" -#include "usbtmc_device.h" #include "device/usbd.h" -#include "osal/osal.h" - -// FIXME: I shouldn't need to include _pvt headers, but it is necessary for usbd_edpt_xfer, _stall, and _busy #include "device/usbd_pvt.h" +#include "usbtmc_device.h" + #ifdef xDEBUG #include "uart_util.h" static char logMsg[150]; diff --git a/src/class/vendor/vendor_device.c b/src/class/vendor/vendor_device.c index 5fc7dd569..081aac9f6 100644 --- a/src/class/vendor/vendor_device.c +++ b/src/class/vendor/vendor_device.c @@ -28,9 +28,11 @@ #if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_VENDOR) -#include "vendor_device.h" +#include "device/usbd.h" #include "device/usbd_pvt.h" +#include "vendor_device.h" + //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ diff --git a/src/class/vendor/vendor_device.h b/src/class/vendor/vendor_device.h index 2c3d79a3d..6d9c784c0 100644 --- a/src/class/vendor/vendor_device.h +++ b/src/class/vendor/vendor_device.h @@ -28,7 +28,6 @@ #define _TUSB_VENDOR_DEVICE_H_ #include "common/tusb_common.h" -#include "device/usbd.h" #ifndef CFG_TUD_VENDOR_EPSIZE #define CFG_TUD_VENDOR_EPSIZE 64 diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 88e85c9e0..1ebd8dd61 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -72,10 +72,11 @@ #include "tusb_option.h" #include "tusb_compiler.h" #include "tusb_verify.h" -#include "tusb_error.h" // TODO remove -#include "tusb_timeout.h" #include "tusb_types.h" +#include "tusb_error.h" // TODO remove +#include "tusb_timeout.h" // TODO remove + //------------- Mem -------------// #define tu_memclr(buffer, size) memset((buffer), 0, (size)) #define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var))) diff --git a/src/device/dcd.h b/src/device/dcd.h index 71e88054c..e17c62d4e 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -28,6 +28,7 @@ #define _TUSB_DCD_H_ #include "common/tusb_common.h" +#include "osal/osal.h" #include "common/tusb_fifo.h" #ifdef __cplusplus From b36b211c26d807214da1132b41669915fbd21c83 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 27 May 2021 17:58:42 +0700 Subject: [PATCH 05/47] clean up tusb_fifo.h include --- src/portable/espressif/esp32sx/dcd_esp32sx.c | 1 - src/portable/microchip/samg/dcd_samg.c | 1 - src/portable/nuvoton/nuc120/dcd_nuc120.c | 1 - src/portable/nuvoton/nuc121/dcd_nuc121.c | 1 - src/portable/nuvoton/nuc505/dcd_nuc505.c | 1 - src/portable/raspberrypi/rp2040/dcd_rp2040.c | 2 -- src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 1 - src/portable/st/synopsys/dcd_synopsys.c | 2 -- src/portable/template/dcd_template.c | 1 - src/portable/ti/msp430x5xx/dcd_msp430x5xx.c | 1 - 10 files changed, 12 deletions(-) diff --git a/src/portable/espressif/esp32sx/dcd_esp32sx.c b/src/portable/espressif/esp32sx/dcd_esp32sx.c index 502273a9b..d728487c2 100644 --- a/src/portable/espressif/esp32sx/dcd_esp32sx.c +++ b/src/portable/espressif/esp32sx/dcd_esp32sx.c @@ -40,7 +40,6 @@ #include "soc/gpio_sig_map.h" #include "soc/usb_periph.h" -#include "common/tusb_fifo.h" #include "device/dcd.h" // Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval) diff --git a/src/portable/microchip/samg/dcd_samg.c b/src/portable/microchip/samg/dcd_samg.c index 9b6a1f9a5..d50621ce4 100644 --- a/src/portable/microchip/samg/dcd_samg.c +++ b/src/portable/microchip/samg/dcd_samg.c @@ -29,7 +29,6 @@ #if CFG_TUSB_MCU == OPT_MCU_SAMG #include "sam.h" -#include "common/tusb_fifo.h" #include "device/dcd.h" // TODO should support (SAM3S || SAM4S || SAM4E || SAMG55) diff --git a/src/portable/nuvoton/nuc120/dcd_nuc120.c b/src/portable/nuvoton/nuc120/dcd_nuc120.c index 7aeb49f2a..047fa3fa6 100644 --- a/src/portable/nuvoton/nuc120/dcd_nuc120.c +++ b/src/portable/nuvoton/nuc120/dcd_nuc120.c @@ -37,7 +37,6 @@ #if TUSB_OPT_DEVICE_ENABLED && (CFG_TUSB_MCU == OPT_MCU_NUC120) -#include "common/tusb_fifo.h" #include "device/dcd.h" #include "NUC100Series.h" diff --git a/src/portable/nuvoton/nuc121/dcd_nuc121.c b/src/portable/nuvoton/nuc121/dcd_nuc121.c index e76d7118c..37b7b0106 100644 --- a/src/portable/nuvoton/nuc121/dcd_nuc121.c +++ b/src/portable/nuvoton/nuc121/dcd_nuc121.c @@ -37,7 +37,6 @@ #if TUSB_OPT_DEVICE_ENABLED && ( (CFG_TUSB_MCU == OPT_MCU_NUC121) || (CFG_TUSB_MCU == OPT_MCU_NUC126) ) -#include "common/tusb_fifo.h" #include "device/dcd.h" #include "NuMicro.h" diff --git a/src/portable/nuvoton/nuc505/dcd_nuc505.c b/src/portable/nuvoton/nuc505/dcd_nuc505.c index 46081d4d0..4e633086d 100644 --- a/src/portable/nuvoton/nuc505/dcd_nuc505.c +++ b/src/portable/nuvoton/nuc505/dcd_nuc505.c @@ -37,7 +37,6 @@ #if TUSB_OPT_DEVICE_ENABLED && (CFG_TUSB_MCU == OPT_MCU_NUC505) -#include "common/tusb_fifo.h" #include "device/dcd.h" #include "NUC505Series.h" diff --git a/src/portable/raspberrypi/rp2040/dcd_rp2040.c b/src/portable/raspberrypi/rp2040/dcd_rp2040.c index 7731078b5..0048270a6 100644 --- a/src/portable/raspberrypi/rp2040/dcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/dcd_rp2040.c @@ -35,8 +35,6 @@ #include "pico/fix/rp2040_usb_device_enumeration.h" #endif -#include "osal/osal.h" -#include "common/tusb_fifo.h" #include "device/dcd.h" /*------------------------------------------------------------------*/ diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c index 0b7605a73..74c144107 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c @@ -120,7 +120,6 @@ // Some definitions are copied to our private include file. #undef USE_HAL_DRIVER -#include "common/tusb_fifo.h" #include "device/dcd.h" #include "portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h" diff --git a/src/portable/st/synopsys/dcd_synopsys.c b/src/portable/st/synopsys/dcd_synopsys.c index 76f5c6050..8a196e061 100644 --- a/src/portable/st/synopsys/dcd_synopsys.c +++ b/src/portable/st/synopsys/dcd_synopsys.c @@ -94,10 +94,8 @@ #else #error "Unsupported MCUs" - #endif -#include "common/tusb_fifo.h" #include "device/dcd.h" //--------------------------------------------------------------------+ diff --git a/src/portable/template/dcd_template.c b/src/portable/template/dcd_template.c index 92a9f3144..12b9144bf 100644 --- a/src/portable/template/dcd_template.c +++ b/src/portable/template/dcd_template.c @@ -28,7 +28,6 @@ #if CFG_TUSB_MCU == OPT_MCU_NONE -#include "common/tusb_fifo.h" #include "device/dcd.h" //--------------------------------------------------------------------+ diff --git a/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c b/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c index e13ee697e..027ed26c9 100644 --- a/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c +++ b/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c @@ -30,7 +30,6 @@ #if TUSB_OPT_DEVICE_ENABLED && ( CFG_TUSB_MCU == OPT_MCU_MSP430x5xx ) #include "msp430.h" -#include "common/tusb_fifo.h" #include "device/dcd.h" /*------------------------------------------------------------------*/ From f384d6f67e200b855e7b07a1fc3218c874e43a42 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 27 May 2021 18:04:28 +0700 Subject: [PATCH 06/47] more with clean up --- src/common/tusb_fifo.c | 2 -- src/common/tusb_fifo.h | 15 +++++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c index 5f7b6a26d..1eb886aa1 100644 --- a/src/common/tusb_fifo.c +++ b/src/common/tusb_fifo.c @@ -25,8 +25,6 @@ * This file is part of the TinyUSB stack. */ -#include - #include "osal/osal.h" #include "tusb_fifo.h" diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h index 1f9da94d1..cf299269d 100644 --- a/src/common/tusb_fifo.h +++ b/src/common/tusb_fifo.h @@ -28,6 +28,10 @@ #ifndef _TUSB_FIFO_H_ #define _TUSB_FIFO_H_ +#ifdef __cplusplus +extern "C" { +#endif + // Due to the use of unmasked pointers, this FIFO does not suffer from loosing // one item slice. Furthermore, write and read operations are completely // decoupled as write and read functions do not modify a common state. Henceforth, @@ -37,17 +41,12 @@ // read pointers can be updated from within a DMA ISR. Overflows are detectable // within a certain number (see tu_fifo_overflow()). +#include "common/tusb_common.h" + // mutex is only needed for RTOS // for OS None, we don't get preempted #define CFG_FIFO_MUTEX (CFG_TUSB_OS != OPT_OS_NONE) -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - #if CFG_FIFO_MUTEX #include "osal/osal.h" #define tu_fifo_mutex_t osal_mutex_t @@ -127,7 +126,7 @@ uint16_t tu_fifo_remaining (tu_fifo_t* f); bool tu_fifo_overflowed (tu_fifo_t* f); void tu_fifo_correct_read_pointer (tu_fifo_t* f); -static inline +TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_fifo_depth(tu_fifo_t* f) { return f->depth; From 9ad6fadf6a65363f9873178e7f80c923452bfb47 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 27 May 2021 18:18:30 +0700 Subject: [PATCH 07/47] more include clean up --- src/class/cdc/cdc_host.c | 2 +- src/class/cdc/cdc_host.h | 2 -- src/class/hid/hid_host.c | 2 +- src/class/hid/hid_host.h | 7 ------- src/class/msc/msc.h | 10 ---------- src/class/msc/msc_host.c | 5 +---- src/class/msc/msc_host.h | 2 -- src/class/vendor/vendor_host.c | 2 +- src/class/vendor/vendor_host.h | 7 ------- src/host/hub.c | 4 +--- src/host/hub.h | 1 - src/host/usbh.h | 9 +-------- src/portable/sony/cxd56/dcd_cxd56.c | 1 - 13 files changed, 6 insertions(+), 48 deletions(-) diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index a897fb58a..c22107bbb 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -28,7 +28,7 @@ #if (TUSB_OPT_HOST_ENABLED && CFG_TUH_CDC) -#include "common/tusb_common.h" +#include "host/usbh.h" #include "cdc_host.h" //--------------------------------------------------------------------+ diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index 66c2f0727..6ff392709 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -27,8 +27,6 @@ #ifndef _TUSB_CDC_HOST_H_ #define _TUSB_CDC_HOST_H_ -#include "common/tusb_common.h" -#include "host/usbh.h" #include "cdc.h" #ifdef __cplusplus diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 1bc86e4ad..83f3f3039 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -28,7 +28,7 @@ #if (TUSB_OPT_HOST_ENABLED && CFG_TUH_HID) -#include "common/tusb_common.h" +#include "host/usbh.h" #include "hid_host.h" //--------------------------------------------------------------------+ diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h index ea693df69..2e4cce600 100644 --- a/src/class/hid/hid_host.h +++ b/src/class/hid/hid_host.h @@ -24,14 +24,9 @@ * This file is part of the TinyUSB stack. */ -/** \addtogroup ClassDriver_HID - * @{ */ - #ifndef _TUSB_HID_HOST_H_ #define _TUSB_HID_HOST_H_ -#include "common/tusb_common.h" -#include "host/usbh.h" #include "hid.h" #ifdef __cplusplus @@ -134,5 +129,3 @@ void hidh_close(uint8_t dev_addr); #endif #endif /* _TUSB_HID_HOST_H_ */ - -/** @} */ // ClassDriver_HID diff --git a/src/class/msc/msc.h b/src/class/msc/msc.h index 0bdc00692..84b6e4d79 100644 --- a/src/class/msc/msc.h +++ b/src/class/msc/msc.h @@ -24,13 +24,6 @@ * This file is part of the TinyUSB stack. */ -/** \ingroup group_class - * \defgroup ClassDriver_MSC MassStorage (MSC) - * @{ */ - -/** \defgroup ClassDriver_MSC_Common Common Definitions - * @{ */ - #ifndef _TUSB_MSC_H_ #define _TUSB_MSC_H_ @@ -387,6 +380,3 @@ TU_VERIFY_STATIC(sizeof(scsi_write10_t) == 10, "size is not correct"); #endif #endif /* _TUSB_MSC_H_ */ - -/// @} -/// @} diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index ca360ca2a..5a4ffff48 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -28,10 +28,7 @@ #if TUSB_OPT_HOST_ENABLED & CFG_TUH_MSC -//--------------------------------------------------------------------+ -// INCLUDE -//--------------------------------------------------------------------+ -#include "common/tusb_common.h" +#include "host/usbh.h" #include "msc_host.h" //--------------------------------------------------------------------+ diff --git a/src/class/msc/msc_host.h b/src/class/msc/msc_host.h index b5ffcd401..ce4fe64dc 100644 --- a/src/class/msc/msc_host.h +++ b/src/class/msc/msc_host.h @@ -27,8 +27,6 @@ #ifndef _TUSB_MSC_HOST_H_ #define _TUSB_MSC_HOST_H_ -#include "common/tusb_common.h" -#include "host/usbh.h" #include "msc.h" #ifdef __cplusplus diff --git a/src/class/vendor/vendor_host.c b/src/class/vendor/vendor_host.c index 0524cb981..1978ef61c 100644 --- a/src/class/vendor/vendor_host.c +++ b/src/class/vendor/vendor_host.c @@ -31,7 +31,7 @@ //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ -#include "common/tusb_common.h" +#include "host/usbh.h" #include "vendor_host.h" //--------------------------------------------------------------------+ diff --git a/src/class/vendor/vendor_host.h b/src/class/vendor/vendor_host.h index fa1879376..07fa56c61 100644 --- a/src/class/vendor/vendor_host.h +++ b/src/class/vendor/vendor_host.h @@ -24,15 +24,10 @@ * This file is part of the TinyUSB stack. */ -/** \ingroup group_class - * \defgroup Group_Custom Custom Class (not supported yet) - * @{ */ - #ifndef _TUSB_VENDOR_HOST_H_ #define _TUSB_VENDOR_HOST_H_ #include "common/tusb_common.h" -#include "host/usbh.h" #ifdef __cplusplus extern "C" { @@ -70,5 +65,3 @@ void cush_close(uint8_t dev_addr); #endif #endif /* _TUSB_VENDOR_HOST_H_ */ - -/** @} */ diff --git a/src/host/hub.c b/src/host/hub.c index 2191c4560..4db680f9e 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -28,9 +28,7 @@ #if (TUSB_OPT_HOST_ENABLED && CFG_TUH_HUB) -//--------------------------------------------------------------------+ -// INCLUDE -//--------------------------------------------------------------------+ +#include "usbh.h" #include "hub.h" //--------------------------------------------------------------------+ diff --git a/src/host/hub.h b/src/host/hub.h index 851bb8e66..2b2f39ee1 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -37,7 +37,6 @@ #define _TUSB_HUB_H_ #include "common/tusb_common.h" -#include "usbh.h" #ifdef __cplusplus extern "C" { diff --git a/src/host/usbh.h b/src/host/usbh.h index 590c8a359..a9790b484 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -34,10 +34,7 @@ extern "C" { #endif -//--------------------------------------------------------------------+ -// INCLUDE -//--------------------------------------------------------------------+ -#include "osal/osal.h" // TODO refractor move to common.h ? +#include "common/tusb_common.h" #include "hcd.h" //--------------------------------------------------------------------+ @@ -67,10 +64,6 @@ typedef struct { typedef bool (*tuh_control_complete_cb_t)(uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); -//--------------------------------------------------------------------+ -// INTERNAL OBJECT & FUNCTION DECLARATION -//--------------------------------------------------------------------+ - //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ diff --git a/src/portable/sony/cxd56/dcd_cxd56.c b/src/portable/sony/cxd56/dcd_cxd56.c index 54958182b..834976468 100644 --- a/src/portable/sony/cxd56/dcd_cxd56.c +++ b/src/portable/sony/cxd56/dcd_cxd56.c @@ -33,7 +33,6 @@ #include #include "device/dcd.h" -#include "osal/osal.h" #define CXD56_EPNUM (7) #define CXD56_SETUP_QUEUE_DEPTH (4) From 7c66c5121b862443aacf7eadbef45153a3fa3060 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 27 May 2021 19:31:55 +0700 Subject: [PATCH 08/47] update doc --- CONTRIBUTORS.md | 10 +++++- docs/changelog.md | 63 +++++++++++++++++++++++++++++++++----- src/class/net/net_device.h | 1 - 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 5ce352f57..5fa3e5250 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -25,6 +25,10 @@ - Improve Audio driver and add uac2_headset example - Improve STM32 Synopsys DCD with various PRs +- **[J McCarthy](https://github.com/xmos-jmccarthy)** + - Add new DFU 1.1 class driver + - Add new example for dfu + - **[Kamil Tomaszewski](https://github.com/kamtom480)** - Add new DCD port for **Sony CXD56** (spresnese board) @@ -53,10 +57,14 @@ - **[Raspberry Pi Team](https://github.com/raspberrypi)** - Add new DCD port for **Raspberry Pi RP2040** + - Add new HCD port for **Raspberry Pi RP2040** - **[Reinhard Panhuber](https://github.com/PanRe)** - Add new class driver for **USB Audio Class 2.0 (UAC2)** - - Enhance tu_fifo with unmasked pointer, which better support DMA + - Rework tu_fifo with unmasked pointer, add DMA support, and constant address support + - Add new DCD/USBD edpt_xfer_fifo() API for optimizing endpoint transfer + - Add and greatly improve Isochronous transfer + - Add new audio examples: audio_test and audio_4_channel_mic - **[Scott Shawcroft](https://github.com/tannewt)** - Add new DCD port for **SAMD21 and SAMD51** diff --git a/docs/changelog.md b/docs/changelog.md index 436259cee..fba362904 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,18 +2,65 @@ ## WIP -- Add new port Silabs EFM32GG12, board EFM32GG12 Thunderboard Kit (SLTB009A) -- Add new port Renesas RX63N, board GR-CITRUS -- MIDI - - Fix MIDI buffer overflow issue +- Rework tu_fifo_t with separated mutex for read and write, better support DMA with read/write buffer info. And constant address mode +- Improve audio_test example and add audio_4_channel_mic example +- Add new dfu example +- Remove pico-sdk from submodule + +### Device Controller Driver (DCD) + +- Add new DCD port for Silabs EFM32GG12 with board Thunderboard Kit (SLTB009A) +- Add new DCD port Renesas RX63N, board GR-CITRUS +- Add new (optional) endpoint API dcd_edpt_xfer_fifo +- Fix build with nRF5340 +- Fix build with lpc15 and lpc54 +- Fix build with lpc177x_8x +- STM32 Synopsys: greatly improve Isochronous transfer with edpt_xfer_fifo API +- Support LPC55 port1 highspeed +- Add support for Espressif esp32s3 +- nRF: fix race condition that could cause drop packet of Bulk OUT transfer + +### USB Device Driver (USBD) + +- Add new (optional) endpoint ADPI usbd_edpt_xfer_fifo + +### Device Class Driver + +CDC + +- [Breaking] tud_cdc_peek(), tud_vendor_peek() dropped position parameter. If needed, tu_fifo_get_read_info() can be used to peek at random offset. + +DFU + +- Add new DFU 1.1 class driver (WIP) + +HID + +- Fix keyboard report descriptor template +- Add more hid keys constant from 0x6B to 0xA4 +- [Breaking] rename API + - HID_PROTOCOL_NONE/KEYBOARD/MOUST to HID_ITF_PROTOCOL_NONE/KEYBOARD/MOUSE + - tud_hid_boot_mode() to tud_hid_get_protocol() + - tud_hid_boot_mode_cb() to tud_hid_set_protocol_cb() + +MIDI + +- Fix MIDI buffer overflow issue +- [Breaking] rename API - Rename tud_midi_read() to tud_midi_stream_read() - Rename tud_midi_write() to tud_midi_stream_write() - Rename tud_midi_receive() to tud_midi_packet_read() - Rename tud_midi_send() to tud_midi_packet_write() -- New board stm32f072-eval -- Breaking changes - - tud_cdc_peek(), tud_vendor_peek() dropped position parameter. If needed, tu_fifo_get_read_info() can be used to peek - at random offset. + +### Host Controller Driver (HCD) + +### USB Host Driver (USBH) + +### Host Class Driver + +HID + +- Rework host hid driver, basically everything changes ## 0.9.0 - 2021.03.12 diff --git a/src/class/net/net_device.h b/src/class/net/net_device.h index f5f0cd8f1..f030f3077 100644 --- a/src/class/net/net_device.h +++ b/src/class/net/net_device.h @@ -28,7 +28,6 @@ #ifndef _TUSB_NET_DEVICE_H_ #define _TUSB_NET_DEVICE_H_ -#include "device/usbd.h" #include "class/cdc/cdc.h" /* declared here, NOT in usb_descriptors.c, so that the driver can intelligently ZLP as needed */ From e9c22e4a5c797e33c4ed5a735bf0d3d6e45b9a78 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 28 May 2021 17:24:35 +0700 Subject: [PATCH 09/47] increase version for release --- docs/changelog.md | 12 +++++++----- src/tusb_option.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index fba362904..323b6b6e2 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,6 +1,6 @@ # TinyUSB Changelog -## WIP +## 0.10.0 - 2021.05.28 - Rework tu_fifo_t with separated mutex for read and write, better support DMA with read/write buffer info. And constant address mode - Improve audio_test example and add audio_4_channel_mic example @@ -28,7 +28,7 @@ CDC -- [Breaking] tud_cdc_peek(), tud_vendor_peek() dropped position parameter. If needed, tu_fifo_get_read_info() can be used to peek at random offset. +- [Breaking] tud_cdc_peek(), tud_vendor_peek() no longer support random offset and dropped position parameter. DFU @@ -54,13 +54,15 @@ MIDI ### Host Controller Driver (HCD) +- No noticable changes + ### USB Host Driver (USBH) +- No noticable changes + ### Host Class Driver -HID - -- Rework host hid driver, basically everything changes +- HID: Rework host hid driver, basically everything changes ## 0.9.0 - 2021.03.12 diff --git a/src/tusb_option.h b/src/tusb_option.h index feff013c7..f8456ca4c 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -28,7 +28,7 @@ #define _TUSB_OPTION_H_ #define TUSB_VERSION_MAJOR 0 -#define TUSB_VERSION_MINOR 9 +#define TUSB_VERSION_MINOR 10 #define TUSB_VERSION_REVISION 0 #define TUSB_VERSION_STRING TU_STRING(TUSB_VERSION_MAJOR) "." TU_STRING(TUSB_VERSION_MINOR) "." TU_STRING(TUSB_VERSION_REVISION) From 164778a71682559670cc2549565b4d8d5f021fa9 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 28 May 2021 17:42:13 +0700 Subject: [PATCH 10/47] update limit each transfer not less than 64 --- src/portable/raspberrypi/rp2040/hcd_rp2040.c | 2 ++ src/portable/raspberrypi/rp2040/rp2040_usb.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/src/portable/raspberrypi/rp2040/hcd_rp2040.c index 5201d1d4c..eff950de2 100644 --- a/src/portable/raspberrypi/rp2040/hcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/hcd_rp2040.c @@ -452,6 +452,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * if (ep_addr != ep->ep_addr) { // Direction has flipped so re init it but with same properties + // TODO treat IN and OUT as invidual endpoints _hw_endpoint_init(ep, dev_addr, ep_addr, ep->wMaxPacketSize, ep->transfer_type, 0); } @@ -531,6 +532,7 @@ bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) bool hcd_edpt_stalled(uint8_t dev_addr, uint8_t ep_addr) { panic("hcd_pipe_stalled"); + return false; } bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr) diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.c b/src/portable/raspberrypi/rp2040/rp2040_usb.c index 98ffea9a3..88d94aaec 100644 --- a/src/portable/raspberrypi/rp2040/rp2040_usb.c +++ b/src/portable/raspberrypi/rp2040/rp2040_usb.c @@ -161,7 +161,10 @@ void _hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t t // Fill in info now that we're kicking off the hw ep->total_len = total_len; ep->len = 0; - ep->transfer_size = tu_min16(total_len, ep->wMaxPacketSize); + + // Limit by packet size but not less 64 (i.e low speed 8 bytes EP0) + ep->transfer_size = tu_min16(total_len, tu_max16(64, ep->wMaxPacketSize)); + ep->active = true; ep->user_buf = buffer; #if TUSB_OPT_HOST_ENABLED @@ -240,8 +243,9 @@ bool _hw_endpoint_xfer_continue(struct hw_endpoint *ep) _hw_endpoint_xfer_sync(ep); // Now we have synced our state with the hardware. Is there more data to transfer? + // Limit by packet size but not less 64 (i.e low speed 8 bytes EP0) uint16_t remaining_bytes = ep->total_len - ep->len; - ep->transfer_size = tu_min16(remaining_bytes, ep->wMaxPacketSize); + ep->transfer_size = tu_min16(remaining_bytes, tu_max16(64, ep->wMaxPacketSize)); #if TUSB_OPT_HOST_ENABLED _hw_endpoint_update_last_buf(ep); #endif From 4f97915d488953f250ff6bfa4f600e512b341633 Mon Sep 17 00:00:00 2001 From: Ha Thach Date: Sun, 30 May 2021 13:50:14 +0700 Subject: [PATCH 11/47] Update bug_report.md --- .github/ISSUE_TEMPLATE/bug_report.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index b364c0ca5..00d16bc2b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -11,6 +11,7 @@ assignees: '' - **PC OS** e.g Ubuntu 20.04 / Windows 10/ macOS 10.15 - **Board** e.g Feather nRF52840 Express (if custom specify your MCUs) +- **TinyUSB version** relase version or git hash (preferrably running with master for lastest code) - **Firmware** e.g examples/device/cdc_msc **Describe The Bug** From 3973ec4b5e457aecf742da47dac3c91d1a143865 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Thu, 8 Apr 2021 12:15:15 -0500 Subject: [PATCH 12/47] rp2040: fix debug compilation error --- src/portable/raspberrypi/rp2040/hcd_rp2040.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/src/portable/raspberrypi/rp2040/hcd_rp2040.c index 5201d1d4c..48cf8b602 100644 --- a/src/portable/raspberrypi/rp2040/hcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/hcd_rp2040.c @@ -294,7 +294,6 @@ static void _hw_endpoint_init(struct hw_endpoint *ep, uint8_t dev_addr, uint8_t uint8_t const num = tu_edpt_number(ep_addr); tusb_dir_t const dir = tu_edpt_dir(ep_addr); - bool in = ep_addr & TUSB_DIR_IN_MASK; ep->ep_addr = ep_addr; ep->dev_addr = dev_addr; From eb8ca14bf8171b48832410ed5e3f888df6564800 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 30 May 2021 22:19:46 +0700 Subject: [PATCH 13/47] add level 3 log for info, add generic TU_LOG() --- src/common/tusb_common.h | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 1ebd8dd61..6f2905697 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -307,25 +307,40 @@ void tu_print_var(uint8_t const* buf, uint32_t bufsize) for(uint32_t i=0; i 1 +// Log Level 2: Warn +#if CFG_TUSB_DEBUG >= 2 #define TU_LOG2 TU_LOG1 #define TU_LOG2_MEM TU_LOG1_MEM #define TU_LOG2_VAR TU_LOG1_VAR #define TU_LOG2_INT TU_LOG1_INT #define TU_LOG2_HEX TU_LOG1_HEX - #define TU_LOG2_LOCATION() TU_LOG1_LOCATION() #endif +// Log Level 3: Info +#if CFG_TUSB_DEBUG >= 3 + #define TU_LOG3 TU_LOG1 + #define TU_LOG3_MEM TU_LOG1_MEM + #define TU_LOG3_VAR TU_LOG1_VAR + #define TU_LOG3_INT TU_LOG1_INT + #define TU_LOG3_HEX TU_LOG1_HEX +#endif typedef struct { @@ -370,6 +385,15 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3 #define TU_LOG2_LOCATION() #endif +#ifndef TU_LOG3 + #define TU_LOG3(...) + #define TU_LOG3_MEM(...) + #define TU_LOG3_VAR(...) + #define TU_LOG3_INT(...) + #define TU_LOG3_HEX(...) + #define TU_LOG3_LOCATION() +#endif + #ifdef __cplusplus } #endif From 6498ee19966d394113530c44c91deb860ce37d78 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 30 May 2021 23:35:54 +0700 Subject: [PATCH 14/47] fix incorrect data toggle when max packet size < 64 fix host buf_sel panic with "already available" --- src/portable/raspberrypi/rp2040/hcd_rp2040.c | 2 + src/portable/raspberrypi/rp2040/rp2040_usb.c | 28 ++++++++++++- src/portable/raspberrypi/rp2040/rp2040_usb.h | 44 ++++++++++++++++++-- 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/src/portable/raspberrypi/rp2040/hcd_rp2040.c index eff950de2..c09469ff5 100644 --- a/src/portable/raspberrypi/rp2040/hcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/hcd_rp2040.c @@ -212,6 +212,7 @@ static void hcd_rp2040_irq(void) if (status & USB_INTS_BUFF_STATUS_BITS) { handled |= USB_INTS_BUFF_STATUS_BITS; + // print_bufctrl32(*epx.buffer_control); hw_handle_buff_status(); } @@ -233,6 +234,7 @@ static void hcd_rp2040_irq(void) if (status & USB_INTS_ERROR_DATA_SEQ_BITS) { usb_hw_clear->sie_status = USB_SIE_STATUS_DATA_SEQ_ERROR_BITS; + // print_bufctrl32(*epx.buffer_control); panic("Data Seq Error \n"); } diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.c b/src/portable/raspberrypi/rp2040/rp2040_usb.c index 88d94aaec..60a039556 100644 --- a/src/portable/raspberrypi/rp2040/rp2040_usb.c +++ b/src/portable/raspberrypi/rp2040/rp2040_usb.c @@ -46,7 +46,7 @@ static inline void _hw_endpoint_lock_update(struct hw_endpoint *ep, int delta) { #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; + ep->last_buf = (ep->len + ep->transfer_size == ep->total_len); } #endif @@ -126,8 +126,29 @@ void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep) // PID val |= ep->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID; + +#if TUSB_OPT_DEVICE_ENABLED ep->next_pid ^= 1u; +#else + // For Host (also device but since we dictate the endpoint size, following scenario does not occur) + // Next PID depends on the number of packet in case wMaxPacketSize < 64 (e.g Interrupt Endpoint 8, or 12) + // Special case with control status stage where PID is always DATA1 + if ( ep->transfer_size == 0 ) + { + ep->next_pid ^= 1u; + }else + { + uint32_t packet_count = 1 + ((ep->transfer_size - 1) / ep->wMaxPacketSize); + + if ( packet_count & 0x01 ) + { + ep->next_pid ^= 1u; + } + } +#endif + + #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 @@ -143,6 +164,7 @@ void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep) // the next time the controller polls this dpram address _hw_endpoint_buffer_control_set_value32(ep, val); pico_trace("buffer control (0x%p) <- 0x%x\n", ep->buffer_control, val); + //print_bufctrl16(val); } @@ -189,10 +211,14 @@ void _hw_endpoint_xfer_sync(struct hw_endpoint *ep) #if TUSB_OPT_HOST_ENABLED // tag::host_buf_sel_fix[] + // TODO need changes to support double buffering if (ep->buf_sel == 1) { // Host can erroneously write status to top half of buf_ctrl register buf_ctrl = buf_ctrl >> 16; + + // update buf1 -> buf0 to prevent panic with "already available" + *ep->buffer_control = buf_ctrl; } // Flip buf sel for host ep->buf_sel ^= 1u; diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.h b/src/portable/raspberrypi/rp2040/rp2040_usb.h index bb88d977f..32d20051f 100644 --- a/src/portable/raspberrypi/rp2040/rp2040_usb.h +++ b/src/portable/raspberrypi/rp2040/rp2040_usb.h @@ -16,8 +16,6 @@ #define TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX PICO_RP2040_USB_DEVICE_ENUMERATION_FIX #endif -// For memset -#include #if false && !defined(NDEBUG) #define pico_trace(format,args...) printf(format, ## args) @@ -78,7 +76,7 @@ struct hw_endpoint #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 + // RP2040-E4: HOST BUG. Host will incorrect write status to top half of buffer // control register when doing transfers > 1 packet uint8_t buf_sel; // Only needed for host @@ -119,4 +117,44 @@ static inline uintptr_t hw_data_offset(uint8_t *buf) extern const char *ep_dir_string[]; +typedef union TU_ATTR_PACKED +{ + uint16_t u16; + struct TU_ATTR_PACKED + { + uint16_t xfer_len : 10; + uint16_t available : 1; + uint16_t stall : 1; + uint16_t reset_bufsel : 1; + uint16_t data_toggle : 1; + uint16_t last_buf : 1; + uint16_t full : 1; + }; +} rp2040_buffer_control_t; + +TU_VERIFY_STATIC(sizeof(rp2040_buffer_control_t) == 2, "size is not correct"); + +static inline void print_bufctrl16(uint32_t u16) +{ + rp2040_buffer_control_t bufctrl; + + bufctrl.u16 = u16; + + TU_LOG(2, "len = %u, available = %u, stall = %u, reset = %u, toggle = %u, last = %u, full = %u\r\n", + bufctrl.xfer_len, bufctrl.available, bufctrl.stall, bufctrl.reset_bufsel, bufctrl.data_toggle, bufctrl.last_buf, bufctrl.full); +} + +static inline void print_bufctrl32(uint32_t u32) +{ + uint16_t u16; + + u16 = u32 >> 16; + TU_LOG(2, "Buffer Control 1 0x%x: ", u16); + print_bufctrl16(u16); + + u16 = u32 & 0x0000ffff; + TU_LOG(2, "Buffer Control 0 0x%x: ", u16); + print_bufctrl16(u16); +} + #endif From 54c915057484d4d63d0697114f156aef2837b728 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 30 May 2021 23:41:59 +0700 Subject: [PATCH 15/47] add errata number --- src/portable/raspberrypi/rp2040/rp2040_usb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.c b/src/portable/raspberrypi/rp2040/rp2040_usb.c index 60a039556..7718293e5 100644 --- a/src/portable/raspberrypi/rp2040/rp2040_usb.c +++ b/src/portable/raspberrypi/rp2040/rp2040_usb.c @@ -210,6 +210,7 @@ void _hw_endpoint_xfer_sync(struct hw_endpoint *ep) uint16_t transferred_bytes = buf_ctrl & USB_BUF_CTRL_LEN_MASK; #if TUSB_OPT_HOST_ENABLED + // RP2040-E4 // tag::host_buf_sel_fix[] // TODO need changes to support double buffering if (ep->buf_sel == 1) From c2a0c1507b0db15a06773e321bd5c782bac54d39 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 30 May 2021 23:44:29 +0700 Subject: [PATCH 16/47] add more comment --- src/portable/raspberrypi/rp2040/rp2040_usb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.c b/src/portable/raspberrypi/rp2040/rp2040_usb.c index 7718293e5..a0263612f 100644 --- a/src/portable/raspberrypi/rp2040/rp2040_usb.c +++ b/src/portable/raspberrypi/rp2040/rp2040_usb.c @@ -136,6 +136,7 @@ void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep) // Special case with control status stage where PID is always DATA1 if ( ep->transfer_size == 0 ) { + // ZLP also toggle data ep->next_pid ^= 1u; }else { From edbccb5e19692a95d72f0467901818a0e1cf7251 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Sun, 30 May 2021 18:37:51 -0500 Subject: [PATCH 17/47] don't override CFG_TUSB_OS in cdc_dual_ports example --- examples/device/cdc_dual_ports/src/tusb_config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/device/cdc_dual_ports/src/tusb_config.h b/examples/device/cdc_dual_ports/src/tusb_config.h index 7db520dd1..c7e87bf67 100644 --- a/examples/device/cdc_dual_ports/src/tusb_config.h +++ b/examples/device/cdc_dual_ports/src/tusb_config.h @@ -64,8 +64,9 @@ #error "Incorrect RHPort configuration" #endif -// This example doesn't use an RTOS +#ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE +#endif // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 From 95f2478146ef83d18b52408c0692222bf2a15053 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Sun, 30 May 2021 18:41:07 -0500 Subject: [PATCH 18/47] Rework rp2040 examples and CMake build: - Examples should be CMake buildable from their own subdirectory; such a build will error out based on matching .skip.MCU_xxx or a mismatched .only.MCU_ - It should be possible to build from a higher level and use .skip.MCU_ and .only.MCU_ to filter which examples get built - The intention is for the CMakeLists.txts in the examples to be non family specific and without MCU based IFs. I have started this work, but am not really sure the state of the esp32 stuff; in any case the plan is to have everything encapsulated in the FAMILY/family.cmake - pico_examples now just includes examples/device/CMakeLists.txt and examples/host/CMakeLists.txt directly, as they also build correctly when included from there. Note that .skip.MCU_ for esp32 in the directories it wasn't previously avaiable has not been added, as the .skip is common to the regular Makefile builds also. It isn't clear whether these examples should build for esp32, but if not .skip should be added. --- examples/device/CMakeLists.txt | 27 ++++ .../device/audio_4_channel_mic/CMakeLists.txt | 51 +++--- examples/device/audio_test/CMakeLists.txt | 51 +++--- examples/device/board_test/CMakeLists.txt | 47 +++--- examples/device/cdc_dual_ports/CMakeLists.txt | 49 +++--- examples/device/cdc_msc/CMakeLists.txt | 51 +++--- examples/device/dfu/CMakeLists.txt | 49 +++--- examples/device/dfu_runtime/CMakeLists.txt | 51 +++--- .../dynamic_configuration/CMakeLists.txt | 51 +++--- examples/device/hid_composite/CMakeLists.txt | 49 +++--- .../device/hid_generic_inout/CMakeLists.txt | 51 +++--- .../hid_multiple_interface/CMakeLists.txt | 51 +++--- examples/device/midi_test/CMakeLists.txt | 51 +++--- examples/device/msc_dual_lun/CMakeLists.txt | 53 +++---- .../device/net_lwip_webserver/CMakeLists.txt | 146 +++++++++--------- examples/device/uac2_headset/CMakeLists.txt | 51 +++--- examples/device/usbtmc/CMakeLists.txt | 51 +++--- examples/device/webusb_serial/CMakeLists.txt | 51 +++--- examples/host/CMakeLists.txt | 9 ++ examples/host/cdc_msc_hid/CMakeLists.txt | 53 +++---- hw/bsp/esp32s2/family.cmake | 4 + hw/bsp/esp32s3/family.cmake | 4 + hw/bsp/family.cmake | 61 ++++++++ .../{boards/raspberry_pi_pico => }/board.h | 12 +- .../adafruit_feather_rp2040/board.cmake | 1 - .../boards/adafruit_feather_rp2040/board.h | 53 ------- .../adafruit_itsybitsy_rp2040/board.cmake | 1 - .../boards/adafruit_itsybitsy_rp2040/board.h | 53 ------- .../boards/adafruit_qt_rp2040/board.cmake | 1 - .../rp2040/boards/adafruit_qt_rp2040/board.h | 55 ------- .../boards/raspberry_pi_pico/board.cmake | 1 - hw/bsp/rp2040/family.c | 15 +- hw/bsp/rp2040/family.cmake | 128 +++++++-------- hw/mcu/microchip | 2 +- hw/mcu/sony/cxd56/spresense-exported-sdk | 2 +- lib/lwip | 2 +- 36 files changed, 616 insertions(+), 822 deletions(-) create mode 100644 examples/device/CMakeLists.txt create mode 100644 examples/host/CMakeLists.txt create mode 100644 hw/bsp/family.cmake rename hw/bsp/rp2040/{boards/raspberry_pi_pico => }/board.h (80%) delete mode 100644 hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake delete mode 100644 hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h delete mode 100644 hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake delete mode 100644 hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h delete mode 100644 hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake delete mode 100644 hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h delete mode 100644 hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake diff --git a/examples/device/CMakeLists.txt b/examples/device/CMakeLists.txt new file mode 100644 index 000000000..4ed693cde --- /dev/null +++ b/examples/device/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/${FAMILY}/family.cmake) + +project(tinyusb_device_examples) +family_initialize_project(tinyusb_device_examples ${CMAKE_CURRENT_LIST_DIR}) + +# family_add_subdirectory will filter what to actually add based on selected FAMILY +family_add_subdirectory(audio_4_channel_mic) +family_add_subdirectory(audio_test) +family_add_subdirectory(board_test) +family_add_subdirectory(cdc_dual_ports) +family_add_subdirectory(cdc_msc) +family_add_subdirectory(cdc_msc_freertos) +family_add_subdirectory(dfu) +family_add_subdirectory(dfu_runtime) +family_add_subdirectory(dynamic_configuration) +family_add_subdirectory(hid_composite) +family_add_subdirectory(hid_composite_freertos) +family_add_subdirectory(hid_generic_inout) +family_add_subdirectory(hid_multiple_interface) +family_add_subdirectory(midi_test) +family_add_subdirectory(msc_dual_lun) +family_add_subdirectory(net_lwip_webserver) +family_add_subdirectory(uac2_headset) +family_add_subdirectory(usbtmc) +family_add_subdirectory(webusb_serial) diff --git a/examples/device/audio_4_channel_mic/CMakeLists.txt b/examples/device/audio_4_channel_mic/CMakeLists.txt index f2c81c4d3..b653fc91f 100644 --- a/examples/device/audio_4_channel_mic/CMakeLists.txt +++ b/examples/device/audio_4_channel_mic/CMakeLists.txt @@ -1,37 +1,28 @@ -# use BOARD-Directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +add_executable(${PROJECT}) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c +) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt index f2c81c4d3..fac0ca64f 100644 --- a/examples/device/audio_test/CMakeLists.txt +++ b/examples/device/audio_test/CMakeLists.txt @@ -1,37 +1,28 @@ -# use BOARD-Directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +add_executable(${PROJECT}) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c +) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index c41ad92ab..5bb8cb700 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -1,44 +1,41 @@ cmake_minimum_required(VERSION 3.5) -# use BOARD-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) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) # Check for -DFAMILY= if(FAMILY MATCHES "^esp32s[2-3]") - cmake_minimum_required(VERSION 3.5) + # use BOARD-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) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) project(${PROJECT}) -elseif(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) +else() + + # Family chooses name based on passed name and vars (e.g. -) + get_filename_component(DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) + family_get_project_name(PROJECT "${DIR_NAME}") + project(${PROJECT}) + 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/main.c + ) # Example include target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") + # Configure compilation flags and libraries for the example... see the corresponding function + # in hw/bsp/FAMILY/family.cmake for details. + family_configure_device_example(${PROJECT}) endif() diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt index 4160c0c88..18367a893 100644 --- a/examples/device/cdc_dual_ports/CMakeLists.txt +++ b/examples/device/cdc_dual_ports/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +project(${PROJECT}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +add_executable(${PROJECT}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index 6c828a396..5da761a04 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -1,38 +1,29 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +project(${PROJECT}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +add_executable(${PROJECT}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/dfu/CMakeLists.txt b/examples/device/dfu/CMakeLists.txt index 4160c0c88..18367a893 100644 --- a/examples/device/dfu/CMakeLists.txt +++ b/examples/device/dfu/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +project(${PROJECT}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +add_executable(${PROJECT}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/dfu_runtime/CMakeLists.txt b/examples/device/dfu_runtime/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/dfu_runtime/CMakeLists.txt +++ b/examples/device/dfu_runtime/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +add_executable(${PROJECT}) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt index a99b755d3..5da761a04 100644 --- a/examples/device/dynamic_configuration/CMakeLists.txt +++ b/examples/device/dynamic_configuration/CMakeLists.txt @@ -1,38 +1,29 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +project(${PROJECT}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +add_executable(${PROJECT}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt index 3b677b3b1..18367a893 100644 --- a/examples/device/hid_composite/CMakeLists.txt +++ b/examples/device/hid_composite/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +project(${PROJECT}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +add_executable(${PROJECT}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/hid_generic_inout/CMakeLists.txt +++ b/examples/device/hid_generic_inout/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +add_executable(${PROJECT}) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/hid_multiple_interface/CMakeLists.txt +++ b/examples/device/hid_multiple_interface/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +add_executable(${PROJECT}) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/midi_test/CMakeLists.txt +++ b/examples/device/midi_test/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +add_executable(${PROJECT}) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt index 8b4722278..f60be8eda 100644 --- a/examples/device/msc_dual_lun/CMakeLists.txt +++ b/examples/device/msc_dual_lun/CMakeLists.txt @@ -1,38 +1,29 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +add_executable(${PROJECT}) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index 4325b4ea6..63cca04a8 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -1,84 +1,82 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# 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 "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - # lwip Stack source - set(SRC_LWIP - ${TOP}/lib/lwip/src/core/altcp.c - ${TOP}/lib/lwip/src/core/altcp_alloc.c - ${TOP}/lib/lwip/src/core/altcp_tcp.c - ${TOP}/lib/lwip/src/core/def.c - ${TOP}/lib/lwip/src/core/dns.c - ${TOP}/lib/lwip/src/core/inet_chksum.c - ${TOP}/lib/lwip/src/core/init.c - ${TOP}/lib/lwip/src/core/ip.c - ${TOP}/lib/lwip/src/core/mem.c - ${TOP}/lib/lwip/src/core/memp.c - ${TOP}/lib/lwip/src/core/netif.c - ${TOP}/lib/lwip/src/core/pbuf.c - ${TOP}/lib/lwip/src/core/raw.c - ${TOP}/lib/lwip/src/core/stats.c - ${TOP}/lib/lwip/src/core/sys.c - ${TOP}/lib/lwip/src/core/tcp.c - ${TOP}/lib/lwip/src/core/tcp_in.c - ${TOP}/lib/lwip/src/core/tcp_out.c - ${TOP}/lib/lwip/src/core/timeouts.c - ${TOP}/lib/lwip/src/core/udp.c - ${TOP}/lib/lwip/src/core/ipv4/autoip.c - ${TOP}/lib/lwip/src/core/ipv4/dhcp.c - ${TOP}/lib/lwip/src/core/ipv4/etharp.c - ${TOP}/lib/lwip/src/core/ipv4/icmp.c - ${TOP}/lib/lwip/src/core/ipv4/igmp.c - ${TOP}/lib/lwip/src/core/ipv4/ip4.c - ${TOP}/lib/lwip/src/core/ipv4/ip4_addr.c - ${TOP}/lib/lwip/src/core/ipv4/ip4_frag.c - ${TOP}/lib/lwip/src/netif/ethernet.c - ${TOP}/lib/lwip/src/netif/slipif.c - ${TOP}/lib/lwip/src/apps/http/httpd.c - ${TOP}/lib/lwip/src/apps/http/fs.c - ${TOP}/lib/networking/dhserver.c - ${TOP}/lib/networking/dnserver.c - ${TOP}/lib/networking/rndis_reports.c - ) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ${SRC_LWIP} - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${TOP}/lib/lwip/src/include + ${TOP}/lib/lwip/src/include/ipv4 + ${TOP}/lib/lwip/src/include/lwip/apps + ${TOP}/lib/networking + ) + +target_sources(${PROJECT} PUBLIC + ${TOP}/lib/lwip/src/core/altcp.c + ${TOP}/lib/lwip/src/core/altcp_alloc.c + ${TOP}/lib/lwip/src/core/altcp_tcp.c + ${TOP}/lib/lwip/src/core/def.c + ${TOP}/lib/lwip/src/core/dns.c + ${TOP}/lib/lwip/src/core/inet_chksum.c + ${TOP}/lib/lwip/src/core/init.c + ${TOP}/lib/lwip/src/core/ip.c + ${TOP}/lib/lwip/src/core/mem.c + ${TOP}/lib/lwip/src/core/memp.c + ${TOP}/lib/lwip/src/core/netif.c + ${TOP}/lib/lwip/src/core/pbuf.c + ${TOP}/lib/lwip/src/core/raw.c + ${TOP}/lib/lwip/src/core/stats.c + ${TOP}/lib/lwip/src/core/sys.c + ${TOP}/lib/lwip/src/core/tcp.c + ${TOP}/lib/lwip/src/core/tcp_in.c + ${TOP}/lib/lwip/src/core/tcp_out.c + ${TOP}/lib/lwip/src/core/timeouts.c + ${TOP}/lib/lwip/src/core/udp.c + ${TOP}/lib/lwip/src/core/ipv4/autoip.c + ${TOP}/lib/lwip/src/core/ipv4/dhcp.c + ${TOP}/lib/lwip/src/core/ipv4/etharp.c + ${TOP}/lib/lwip/src/core/ipv4/icmp.c + ${TOP}/lib/lwip/src/core/ipv4/igmp.c + ${TOP}/lib/lwip/src/core/ipv4/ip4.c + ${TOP}/lib/lwip/src/core/ipv4/ip4_addr.c + ${TOP}/lib/lwip/src/core/ipv4/ip4_frag.c + ${TOP}/lib/lwip/src/netif/ethernet.c + ${TOP}/lib/lwip/src/netif/slipif.c + ${TOP}/lib/lwip/src/apps/http/httpd.c + ${TOP}/lib/lwip/src/apps/http/fs.c + ${TOP}/lib/networking/dhserver.c + ${TOP}/lib/networking/dnserver.c + ${TOP}/lib/networking/rndis_reports.c + ) + +target_compile_definitions(${PROJECT} PUBLIC + PBUF_POOL_SIZE=2 + TCP_WND=2*TCP_MSS + HTTPD_USE_CUSTOM_FSDATA=0 +) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ${TOP}/lib/lwip/src/include - ${TOP}/lib/lwip/src/include/ipv4 - ${TOP}/lib/lwip/src/include/lwip/apps - ${TOP}/lib/networking - ) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - PBUF_POOL_SIZE=2 - TCP_WND=2*TCP_MSS - HTTPD_USE_CUSTOM_FSDATA=0 - ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/uac2_headset/CMakeLists.txt +++ b/examples/device/uac2_headset/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +add_executable(${PROJECT}) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt index c14595dbe..4306da8cb 100644 --- a/examples/device/usbtmc/CMakeLists.txt +++ b/examples/device/usbtmc/CMakeLists.txt @@ -1,38 +1,29 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +project(${PROJECT}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usbtmc_app.c - ) +add_executable(${PROJECT}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usbtmc_app.c + ) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/webusb_serial/CMakeLists.txt +++ b/examples/device/webusb_serial/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +add_executable(${PROJECT}) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/host/CMakeLists.txt b/examples/host/CMakeLists.txt new file mode 100644 index 000000000..c70d11d5b --- /dev/null +++ b/examples/host/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/${FAMILY}/family.cmake) + +project(tinyusb_host_examples) +family_initialize_project(tinyusb_host_examples ${CMAKE_CURRENT_LIST_DIR}) + +# family_add_subdirectory will filter what to actually add based on selected FAMILY +family_add_subdirectory(cdc_msc_hid) diff --git a/examples/host/cdc_msc_hid/CMakeLists.txt b/examples/host/cdc_msc_hid/CMakeLists.txt index ac57bf6dd..ad0f412e2 100644 --- a/examples/host/cdc_msc_hid/CMakeLists.txt +++ b/examples/host/cdc_msc_hid/CMakeLists.txt @@ -1,38 +1,29 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) +add_executable(${PROJECT}) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c + ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_host_example(${PROJECT}) \ No newline at end of file diff --git a/hw/bsp/esp32s2/family.cmake b/hw/bsp/esp32s2/family.cmake index c19221b14..656f7d852 100644 --- a/hw/bsp/esp32s2/family.cmake +++ b/hw/bsp/esp32s2/family.cmake @@ -4,3 +4,7 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s2/boards" "${TOP}/hw/bsp/esp32s2/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(SUPPORTED_TARGETS esp32s2) + +# include basic family CMake functionality +set(FAMILY_MCUS esp32s2 ESP32S2) +include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) diff --git a/hw/bsp/esp32s3/family.cmake b/hw/bsp/esp32s3/family.cmake index 558ec5752..e57920bf7 100644 --- a/hw/bsp/esp32s3/family.cmake +++ b/hw/bsp/esp32s3/family.cmake @@ -4,3 +4,7 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s3/boards" "${TOP}/hw/bsp/esp32s3/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(SUPPORTED_TARGETS esp32s3) + +# include basic family CMake functionality +set(FAMILY_MCUS esp32s3 ESP32S3) # TODO MERGE THIS WITH supported targets? +include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) diff --git a/hw/bsp/family.cmake b/hw/bsp/family.cmake new file mode 100644 index 000000000..124399675 --- /dev/null +++ b/hw/bsp/family.cmake @@ -0,0 +1,61 @@ +if (NOT FAMILY_MCUS) + set(FAMILY_MCUS ${FAMILY}) +endif() + +# save it in case of re-inclusion +set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "") + +function(family_filter RESULT DIR) + get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + file(GLOB ONLYS "${DIR}/.only.MCU_*") + if (ONLYS) + foreach(MCU IN LISTS FAMILY_MCUS) + if (EXISTS ${DIR}/.only.MCU_${MCU}) + set(${RESULT} 1 PARENT_SCOPE) + return() + endif() + endforeach() + else() + foreach(MCU IN LISTS FAMILY_MCUS) + if (EXISTS ${DIR}/.skip.MCU_${MCU}) + set(${RESULT} 0 PARENT_SCOPE) + return() + endif() + endforeach() + endif() + set(${RESULT} 1 PARENT_SCOPE) +endfunction() + +function(family_add_subdirectory DIR) + family_filter(SHOULD_ADD "${DIR}") + if (SHOULD_ADD) + add_subdirectory(${DIR}) + endif() +endfunction() + +function(family_get_project_name OUTPUT_NAME DIR) + get_filename_component(SHORT_NAME ${DIR} NAME) + if (TINYUSB_FAMILY_PROJECT_NAME_INCLUDES_BOARD OR NOT DEFINED TINYUSB_FAMILY_PROJECT_NAME_INCLUDES_BOARD) + set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${BOARD}-${SHORT_NAME} PARENT_SCOPE) + else() + set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) + endif() +endfunction() + +function(family_initialize_project PROJECT DIR) + family_filter(ALLOWED "${DIR}") + if (NOT ALLOWED) + get_filename_component(SHORT_NAME ${DIR} NAME) + message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}") + endif() +endfunction() + +# configure an executable target to link to tinyusb in device mode, and add the board implementation +function(family_configure_device_example TARGET) + # default implentation is empty, the function should be redefined in the FAMILY/family.cmake +endfunction() + +# configure an executable target to link to tinyusb in host mode, and add the board implementation +function(family_configure_host_example TARGET) + # default implentation is empty, the function should be redefined in the FAMILY/family.cmake +endfunction() diff --git a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h b/hw/bsp/rp2040/board.h similarity index 80% rename from hw/bsp/rp2040/boards/raspberry_pi_pico/board.h rename to hw/bsp/rp2040/board.h index e4a6514ad..237f29dc2 100644 --- a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h +++ b/hw/bsp/rp2040/board.h @@ -31,16 +31,20 @@ extern "C" { #endif +#ifdef PICO_DEFAULT_LED_PIN #define LED_PIN PICO_DEFAULT_LED_PIN -#define LED_STATE_ON 1 +#define LED_STATE_ON (!(PICO_DEFAULT_LED_PIN_INVERTED)) +#endif // 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 +#if defined(PICO_DEFAULT_UART_TX_PIN) && defined(PICO_DEFAULT_UART_RX_PIN) && defined(PICO_DEFAULT_UART) +#define UART_DEV PICO_DEFAULT_UART +#define UART_TX_PIN PICO_DEFAULT_UART_TX_PIN +#define UART_RX_PIN PICO_DEFAULT_UART_RX_PIN +#endif #ifdef __cplusplus } diff --git a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake deleted file mode 100644 index ea4070cf3..000000000 --- a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_generic_03h.S") diff --git a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h deleted file mode 100644 index 281b215d3..000000000 --- a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021, Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#ifndef BOARD_H_ -#define BOARD_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -#define LED_PIN 13 -#define LED_STATE_ON 1 - -#define NEOPIXEL_PIN 16 -#define NEOPIXEL_POWER_PIN 17 -#define NEOPIXEL_POWER_STATE 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 - -#endif /* BOARD_H_ */ diff --git a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake deleted file mode 100644 index eb9f219d2..000000000 --- a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_w25q080.S") diff --git a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h deleted file mode 100644 index 72265176c..000000000 --- a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021, Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#ifndef BOARD_H_ -#define BOARD_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -#define LED_PIN 11 -#define LED_STATE_ON 1 - -#define NEOPIXEL_PIN 17 -#define NEOPIXEL_POWER_PIN 16 -#define NEOPIXEL_POWER_STATE 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 - -#endif /* BOARD_H_ */ diff --git a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake deleted file mode 100644 index eb9f219d2..000000000 --- a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_w25q080.S") diff --git a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h deleted file mode 100644 index c0915f704..000000000 --- a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021, Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#ifndef BOARD_H_ -#define BOARD_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -// TODO QT RP2040 only has neopixel -#define LED_PIN 11 -#define LED_STATE_ON 1 - -#define NEOPIXEL_PIN 12 -#define NEOPIXEL_POWER_PIN 11 -#define NEOPIXEL_POWER_STATE 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 - -#endif /* BOARD_H_ */ diff --git a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake deleted file mode 100644 index eb9f219d2..000000000 --- a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_w25q080.S") diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c index 9995c23d7..b2dbd3e6a 100644 --- a/hw/bsp/rp2040/family.c +++ b/hw/bsp/rp2040/family.c @@ -26,6 +26,7 @@ */ #include "pico/stdlib.h" +#include "pico/binary_info.h" #include "hardware/gpio.h" #include "hardware/sync.h" #include "hardware/structs/ioqspi.h" @@ -110,10 +111,14 @@ void stdio_rtt_init(void) #endif +#ifdef UART_DEV +static uart_inst_t *uart_inst; +#endif void board_init(void) { #ifdef LED_PIN + bi_decl(bi_1pin_with_name(LED_PIN, "LED")); gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT); #endif @@ -123,7 +128,9 @@ void board_init(void) #endif #ifdef UART_DEV - stdio_uart_init_full(UART_DEV, CFG_BOARD_UART_BAUDRATE, UART_TX_PIN, UART_RX_PIN); + bi_decl(bi_2pins_with_func(UART_TX_PIN, UART_TX_PIN, GPIO_FUNC_UART)); + uart_inst = uart_get_instance(UART_DEV); + stdio_uart_init_full(uart_inst, CFG_BOARD_UART_BAUDRATE, UART_TX_PIN, UART_RX_PIN); #endif #if defined(LOGGER_RTT) @@ -164,7 +171,7 @@ int board_uart_read(uint8_t* buf, int len) { #ifdef UART_DEV for(int i=0;i Date: Mon, 31 May 2021 11:11:00 +0700 Subject: [PATCH 19/47] fix cast-align warning in msc host --- src/class/msc/msc_host.c | 7 ++++--- src/host/hcd.h | 2 ++ src/portable/ehci/ehci.c | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 5a4ffff48..205f0fd2d 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -71,7 +71,8 @@ CFG_TUSB_MEM_SECTION static msch_interface_t _msch_itf[CFG_TUSB_HOST_DEVICE_MAX] // buffer used to read scsi information when mounted // largest response data currently is inquiry TODO Inquiry is not part of enum anymore -CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4) static uint8_t _msch_buffer[sizeof(scsi_inquiry_resp_t)]; +CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4) +static uint8_t _msch_buffer[sizeof(scsi_inquiry_resp_t)]; static inline msch_interface_t* get_itf(uint8_t dev_addr) { @@ -438,7 +439,7 @@ static bool config_test_unit_ready_complete(uint8_t dev_addr, msc_cbw_t const* c { // Unit is ready, read its capacity TU_LOG2("SCSI Read Capacity\r\n"); - tuh_msc_read_capacity(dev_addr, cbw->lun, (scsi_read_capacity10_resp_t*) _msch_buffer, config_read_capacity_complete); + tuh_msc_read_capacity(dev_addr, cbw->lun, (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer), config_read_capacity_complete); }else { // Note: During enumeration, some device fails Test Unit Ready and require a few retries @@ -465,7 +466,7 @@ static bool config_read_capacity_complete(uint8_t dev_addr, msc_cbw_t const* cbw msch_interface_t* p_msc = get_itf(dev_addr); // Capacity response field: Block size and Last LBA are both Big-Endian - scsi_read_capacity10_resp_t* resp = (scsi_read_capacity10_resp_t*) _msch_buffer; + scsi_read_capacity10_resp_t* resp = (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer); p_msc->capacity[cbw->lun].block_count = tu_ntohl(resp->last_lba) + 1; p_msc->capacity[cbw->lun].block_size = tu_ntohl(resp->block_size); diff --git a/src/host/hcd.h b/src/host/hcd.h index ba6a9c5ca..df19f3e22 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -28,6 +28,8 @@ #define _TUSB_HCD_H_ #include "common/tusb_common.h" +#include "osal/osal.h" +#include "common/tusb_fifo.h" #ifdef __cplusplus extern "C" { diff --git a/src/portable/ehci/ehci.c b/src/portable/ehci/ehci.c index eab1f8928..a1c12e70d 100644 --- a/src/portable/ehci/ehci.c +++ b/src/portable/ehci/ehci.c @@ -302,7 +302,6 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const dir = tu_edpt_dir(ep_addr); - // FIXME control only for now if ( epnum == 0 ) { ehci_qhd_t* qhd = qhd_control(dev_addr); From 3fb80e76ce554018fd81b2922c1db9121f446ac1 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 31 May 2021 12:08:37 +0700 Subject: [PATCH 20/47] remove obsolete hcd_pipe_queue_xfer()/hcd_pipe_xfer() --- src/class/cdc/cdc_host.c | 6 +- src/class/cdc/cdc_rndis_host.c | 2 +- src/class/vendor/vendor_host.c | 4 +- src/host/hcd.h | 11 +-- src/host/hub.c | 2 +- src/portable/ehci/ehci.c | 82 ++++++-------------- src/portable/raspberrypi/rp2040/hcd_rp2040.c | 10 --- 7 files changed, 33 insertions(+), 84 deletions(-) diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index c22107bbb..facf86d56 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -96,24 +96,26 @@ bool tuh_cdc_serial_is_mounted(uint8_t dev_addr) bool tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify) { + (void) is_notify; TU_VERIFY( tuh_cdc_mounted(dev_addr) ); TU_VERIFY( p_data != NULL && length, TUSB_ERROR_INVALID_PARA); uint8_t const ep_out = cdch_data[dev_addr-1].ep_out; if ( hcd_edpt_busy(dev_addr, ep_out) ) return false; - return hcd_pipe_xfer(dev_addr, ep_out, (void *) p_data, length, is_notify); + return usbh_edpt_xfer(dev_addr, ep_out, (void *) p_data, length); } bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify) { + (void) is_notify; TU_VERIFY( tuh_cdc_mounted(dev_addr) ); TU_VERIFY( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA); uint8_t const ep_in = cdch_data[dev_addr-1].ep_in; if ( hcd_edpt_busy(dev_addr, ep_in) ) return false; - return hcd_pipe_xfer(dev_addr, ep_in, p_buffer, length, is_notify); + return usbh_edpt_xfer(dev_addr, ep_in, p_buffer, length); } bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_control_complete_cb_t complete_cb) diff --git a/src/class/cdc/cdc_rndis_host.c b/src/class/cdc/cdc_rndis_host.c index 767b917a1..42b9993bc 100644 --- a/src/class/cdc/cdc_rndis_host.c +++ b/src/class/cdc/cdc_rndis_host.c @@ -239,7 +239,7 @@ static tusb_error_t send_message_get_response_subtask( uint8_t dev_addr, cdch_da if ( TUSB_ERROR_NONE != error ) STASK_RETURN(error); //------------- waiting for Response Available notification -------------// - (void) hcd_pipe_xfer(p_cdc->pipe_notification, msg_notification[dev_addr-1], 8, true); + (void) usbh_edpt_xfer(p_cdc->pipe_notification, msg_notification[dev_addr-1], 8); osal_semaphore_wait(rndish_data[dev_addr-1].sem_notification_hdl, OSAL_TIMEOUT_NORMAL, &error); if ( TUSB_ERROR_NONE != error ) STASK_RETURN(error); STASK_ASSERT(msg_notification[dev_addr-1][0] == 1); diff --git a/src/class/vendor/vendor_host.c b/src/class/vendor/vendor_host.c index 1978ef61c..f7a6b2bf0 100644 --- a/src/class/vendor/vendor_host.c +++ b/src/class/vendor/vendor_host.c @@ -66,7 +66,7 @@ tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t pr return TUSB_ERROR_INTERFACE_IS_BUSY; } - (void) hcd_pipe_xfer( custom_interface[dev_addr-1].pipe_in, p_buffer, length, true); + (void) usbh_edpt_xfer( custom_interface[dev_addr-1].pipe_in, p_buffer, length); return TUSB_ERROR_NONE; } @@ -80,7 +80,7 @@ tusb_error_t tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t p return TUSB_ERROR_INTERFACE_IS_BUSY; } - (void) hcd_pipe_xfer( custom_interface[dev_addr-1].pipe_out, p_data, length, true); + (void) usbh_edpt_xfer( custom_interface[dev_addr-1].pipe_out, p_data, length); return TUSB_ERROR_NONE; } diff --git a/src/host/hcd.h b/src/host/hcd.h index df19f3e22..0a9f00a0c 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -143,21 +143,12 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr); bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]); bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); +bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen); bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr); bool hcd_edpt_stalled(uint8_t dev_addr, uint8_t ep_addr); bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr); -// TODO merge with pipe_xfer -bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen); - -//--------------------------------------------------------------------+ -// PIPE API - TODO remove later -//--------------------------------------------------------------------+ -// TODO control xfer should be used via usbh layer -bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes); // only queue, not transferring yet -bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete); - //--------------------------------------------------------------------+ // Event API (implemented by stack) //--------------------------------------------------------------------+ diff --git a/src/host/hub.c b/src/host/hub.c index 4db680f9e..2d4033a26 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -352,7 +352,7 @@ void hub_close(uint8_t dev_addr) bool hub_status_pipe_queue(uint8_t dev_addr) { usbh_hub_t * p_hub = &hub_data[dev_addr-1]; - return hcd_pipe_xfer(dev_addr, p_hub->ep_in, &p_hub->status_change, 1, true); + return usbh_edpt_xfer(dev_addr, p_hub->ep_in, &p_hub->status_change, 1); } diff --git a/src/portable/ehci/ehci.c b/src/portable/ehci/ehci.c index a1c12e70d..70a497f0a 100644 --- a/src/portable/ehci/ehci.c +++ b/src/portable/ehci/ehci.c @@ -293,8 +293,31 @@ static void ehci_stop(uint8_t rhport) #endif //--------------------------------------------------------------------+ -// CONTROL PIPE API +// Endpoint API //--------------------------------------------------------------------+ + +bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]) +{ + (void) rhport; + + ehci_qhd_t* qhd = &ehci_data.control[dev_addr].qhd; + ehci_qtd_t* td = &ehci_data.control[dev_addr].qtd; + + qtd_init(td, (void*) setup_packet, 8); + td->pid = EHCI_PID_SETUP; + td->int_on_complete = 1; + td->next.terminate = 1; + + // sw region + qhd->p_qtd_list_head = td; + qhd->p_qtd_list_tail = td; + + // attach TD + qhd->qtd_overlay.next.address = (uint32_t) td; + + return true; +} + bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen) { (void) rhport; @@ -342,31 +365,6 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * return true; } -bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]) -{ - (void) rhport; - - ehci_qhd_t* qhd = &ehci_data.control[dev_addr].qhd; - ehci_qtd_t* td = &ehci_data.control[dev_addr].qtd; - - qtd_init(td, (void*) setup_packet, 8); - td->pid = EHCI_PID_SETUP; - td->int_on_complete = 1; - td->next.terminate = 1; - - // sw region - qhd->p_qtd_list_head = td; - qhd->p_qtd_list_tail = td; - - // attach TD - qhd->qtd_overlay.next.address = (uint32_t) td; - - return true; -} - -//--------------------------------------------------------------------+ -// BULK/INT/ISO PIPE API -//--------------------------------------------------------------------+ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) { (void) rhport; @@ -420,38 +418,6 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const return true; } -bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes) -{ - //------------- set up QTD -------------// - ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr); - ehci_qtd_t *p_qtd = qtd_find_free(); - - TU_ASSERT(p_qtd); - - qtd_init(p_qtd, buffer, total_bytes); - p_qtd->pid = p_qhd->pid; - - //------------- insert TD to TD list -------------// - qtd_insert_to_qhd(p_qhd, p_qtd); - - return true; -} - -bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) -{ - TU_ASSERT ( hcd_pipe_queue_xfer(dev_addr, ep_addr, buffer, total_bytes) ); - - ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr); - - if ( int_on_complete ) - { // the just added qtd is pointed by list_tail - p_qhd->p_qtd_list_tail->int_on_complete = 1; - } - p_qhd->qtd_overlay.next.address = (uint32_t) p_qhd->p_qtd_list_head; // attach head QTD to QHD start transferring - - return true; -} - bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) { ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr); diff --git a/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/src/portable/raspberrypi/rp2040/hcd_rp2040.c index c09469ff5..b8833fbec 100644 --- a/src/portable/raspberrypi/rp2040/hcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/hcd_rp2040.c @@ -543,14 +543,4 @@ bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr) return true; } -bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) -{ - pico_trace("hcd_pipe_xfer dev_addr %d, ep_addr 0x%x, total_bytes %d, int_on_complete %d\n", - dev_addr, ep_addr, total_bytes, int_on_complete); - - // Same logic as hcd_edpt_xfer as far as I am concerned - hcd_edpt_xfer(0, dev_addr, ep_addr, buffer, total_bytes); - - return true; -} #endif From 65e5872d8109f7f12c48c52a5fdd537e676b0514 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 31 May 2021 15:18:24 +0700 Subject: [PATCH 21/47] add hub_port_set_feature() --- src/host/hub.c | 112 ++++++++++++++++++++++++++++++++----------------- src/host/hub.h | 4 +- 2 files changed, 76 insertions(+), 40 deletions(-) diff --git a/src/host/hub.c b/src/host/hub.c index 2d4033a26..6eea6ee4e 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -42,13 +42,30 @@ typedef struct uint8_t status_change; // data from status change interrupt endpoint hub_port_status_response_t port_status; -}usbh_hub_t; +} hub_interface_t; -CFG_TUSB_MEM_SECTION static usbh_hub_t hub_data[CFG_TUSB_HOST_DEVICE_MAX]; +CFG_TUSB_MEM_SECTION static hub_interface_t hub_data[CFG_TUSB_HOST_DEVICE_MAX]; TU_ATTR_ALIGNED(4) CFG_TUSB_MEM_SECTION static uint8_t _hub_buffer[sizeof(descriptor_hub_desc_t)]; -//OSAL_SEM_DEF(hub_enum_semaphore); -//static osal_semaphore_handle_t hub_enum_sem_hdl; +#if CFG_TUSB_DEBUG +static char const* const _hub_feature_str[] = +{ + [HUB_FEATURE_PORT_CONNECTION ] = "PORT_CONNECTION", + [HUB_FEATURE_PORT_ENABLE ] = "PORT_ENABLE", + [HUB_FEATURE_PORT_SUSPEND ] = "PORT_SUSPEND", + [HUB_FEATURE_PORT_OVER_CURRENT ] = "PORT_OVER_CURRENT", + [HUB_FEATURE_PORT_RESET ] = "PORT_RESET", + [HUB_FEATURE_PORT_POWER ] = "PORT_POWER", + [HUB_FEATURE_PORT_LOW_SPEED ] = "PORT_LOW_SPEED", + [HUB_FEATURE_PORT_CONNECTION_CHANGE ] = "PORT_CONNECTION_CHANGE", + [HUB_FEATURE_PORT_ENABLE_CHANGE ] = "PORT_ENABLE_CHANGE", + [HUB_FEATURE_PORT_SUSPEND_CHANGE ] = "PORT_SUSPEND_CHANGE", + [HUB_FEATURE_PORT_OVER_CURRENT_CHANGE ] = "PORT_OVER_CURRENT_CHANGE", + [HUB_FEATURE_PORT_RESET_CHANGE ] = "PORT_RESET_CHANGE", + [HUB_FEATURE_PORT_TEST ] = "PORT_TEST", + [HUB_FEATURE_PORT_INDICATOR ] = "PORT_INDICATOR", +}; +#endif //--------------------------------------------------------------------+ // HUB @@ -69,11 +86,37 @@ bool hub_port_clear_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature, .wLength = 0 }; - TU_LOG2("HUB Clear Port Feature: addr = %u port = %u, feature = %u\r\n", hub_addr, hub_port, feature); + TU_LOG2("HUB Clear Feature: %s, addr = %u port = %u\r\n", _hub_feature_str[feature], hub_addr, hub_port); TU_ASSERT( tuh_control_xfer(hub_addr, &request, NULL, complete_cb) ); return true; } +bool hub_port_set_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature, tuh_control_complete_cb_t complete_cb) +{ + tusb_control_request_t const request = + { + .bmRequestType_bit = + { + .recipient = TUSB_REQ_RCPT_OTHER, + .type = TUSB_REQ_TYPE_CLASS, + .direction = TUSB_DIR_OUT + }, + .bRequest = HUB_REQUEST_SET_FEATURE, + .wValue = feature, + .wIndex = hub_port, + .wLength = 0 + }; + + TU_LOG2("HUB Set Feature: %s, addr = %u port = %u\r\n", _hub_feature_str[feature], hub_addr, hub_port); + TU_ASSERT( tuh_control_xfer(hub_addr, &request, NULL, complete_cb) ); + return true; +} + +bool hub_port_reset(uint8_t hub_addr, uint8_t hub_port, tuh_control_complete_cb_t complete_cb) +{ + return hub_port_set_feature(hub_addr, hub_port, HUB_FEATURE_PORT_RESET, complete_cb); +} + bool hub_port_get_status(uint8_t hub_addr, uint8_t hub_port, void* resp, tuh_control_complete_cb_t complete_cb) { tusb_control_request_t const request = @@ -95,33 +138,12 @@ bool hub_port_get_status(uint8_t hub_addr, uint8_t hub_port, void* resp, tuh_con return true; } -bool hub_port_reset(uint8_t hub_addr, uint8_t hub_port, tuh_control_complete_cb_t complete_cb) -{ - tusb_control_request_t const request = - { - .bmRequestType_bit = - { - .recipient = TUSB_REQ_RCPT_OTHER, - .type = TUSB_REQ_TYPE_CLASS, - .direction = TUSB_DIR_OUT - }, - .bRequest = HUB_REQUEST_SET_FEATURE, - .wValue = HUB_FEATURE_PORT_RESET, - .wIndex = hub_port, - .wLength = 0 - }; - - TU_LOG2("HUB Reset Port: addr = %u port = %u\r\n", hub_addr, hub_port); - TU_ASSERT( tuh_control_xfer(hub_addr, &request, NULL, complete_cb) ); - return true; -} - //--------------------------------------------------------------------+ // CLASS-USBH API (don't require to verify parameters) //--------------------------------------------------------------------+ void hub_init(void) { - tu_memclr(hub_data, CFG_TUSB_HOST_DEVICE_MAX*sizeof(usbh_hub_t)); + tu_memclr(hub_data, CFG_TUSB_HOST_DEVICE_MAX*sizeof( hub_interface_t)); // hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) ); } @@ -147,6 +169,10 @@ bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf return true; } +//--------------------------------------------------------------------+ +// Set Configure +//--------------------------------------------------------------------+ + static bool config_get_hub_desc_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); static bool config_port_power_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); @@ -155,7 +181,7 @@ static bool config_get_hub_desc_complete (uint8_t dev_addr, tusb_control_request (void) request; TU_ASSERT(XFER_RESULT_SUCCESS == result); - usbh_hub_t* p_hub = &hub_data[dev_addr-1]; + hub_interface_t* p_hub = &hub_data[dev_addr-1]; // only use number of ports in hub descriptor descriptor_hub_desc_t const* desc_hub = (descriptor_hub_desc_t const*) _hub_buffer; @@ -163,7 +189,7 @@ static bool config_get_hub_desc_complete (uint8_t dev_addr, tusb_control_request // May need to GET_STATUS - // Ports must be powered on to be able to detect connection + // Set Port Power to be able to detect connection tusb_control_request_t const new_request = { .bmRequestType_bit = @@ -178,6 +204,8 @@ static bool config_get_hub_desc_complete (uint8_t dev_addr, tusb_control_request .wLength = 0 }; + TU_LOG(2, "HUB Set Port Power: port = %u\r\n", new_request.wIndex); + TU_ASSERT( tuh_control_xfer(dev_addr, &new_request, NULL, config_port_power_complete) ); return true; @@ -186,7 +214,7 @@ static bool config_get_hub_desc_complete (uint8_t dev_addr, tusb_control_request static bool config_port_power_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result) { TU_ASSERT(XFER_RESULT_SUCCESS == result); - usbh_hub_t* p_hub = &hub_data[dev_addr-1]; + hub_interface_t* p_hub = &hub_data[dev_addr-1]; if (request->wIndex == p_hub->port_count) { @@ -200,6 +228,8 @@ static bool config_port_power_complete (uint8_t dev_addr, tusb_control_request_t tusb_control_request_t new_request = *request; new_request.wIndex++; // power next port + TU_LOG(2, "HUB Set Port Power: port = %u\r\n", new_request.wIndex); + TU_ASSERT( tuh_control_xfer(dev_addr, &new_request, NULL, config_port_power_complete) ); } @@ -208,7 +238,7 @@ static bool config_port_power_complete (uint8_t dev_addr, tusb_control_request_t bool hub_set_config(uint8_t dev_addr, uint8_t itf_num) { - usbh_hub_t* p_hub = &hub_data[dev_addr-1]; + hub_interface_t* p_hub = &hub_data[dev_addr-1]; TU_ASSERT(itf_num == p_hub->itf_num); //------------- Get Hub Descriptor -------------// @@ -231,6 +261,10 @@ bool hub_set_config(uint8_t dev_addr, uint8_t itf_num) return true; } +//--------------------------------------------------------------------+ +// Connection Changes +//--------------------------------------------------------------------+ + static bool connection_clear_conn_change_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); static bool connection_get_status_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); static bool connection_port_reset_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); @@ -263,7 +297,7 @@ static bool connection_clear_conn_change_complete (uint8_t dev_addr, tusb_contro { TU_ASSERT(result == XFER_RESULT_SUCCESS); - usbh_hub_t * p_hub = &hub_data[dev_addr-1]; + hub_interface_t * p_hub = &hub_data[dev_addr-1]; uint8_t const port_num = (uint8_t) request->wIndex; if ( p_hub->port_status.status.connection ) @@ -293,7 +327,7 @@ static bool connection_clear_conn_change_complete (uint8_t dev_addr, tusb_contro static bool connection_get_status_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result) { TU_ASSERT(result == XFER_RESULT_SUCCESS); - usbh_hub_t * p_hub = &hub_data[dev_addr-1]; + hub_interface_t * p_hub = &hub_data[dev_addr-1]; uint8_t const port_num = (uint8_t) request->wIndex; // Connection change @@ -325,12 +359,13 @@ bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32 (void) ep_addr; TU_ASSERT( result == XFER_RESULT_SUCCESS); - usbh_hub_t * p_hub = &hub_data[dev_addr-1]; + hub_interface_t * p_hub = &hub_data[dev_addr-1]; - TU_LOG2("Port Status Change = 0x%02X\r\n", p_hub->status_change); + TU_LOG2(" Port Status Change = 0x%02X\r\n", p_hub->status_change); + + // Hub ignore bit0 in status change for (uint8_t port=1; port <= p_hub->port_count; port++) { - // TODO HUB ignore bit0 hub_status_change if ( tu_bit_test(p_hub->status_change, port) ) { hub_port_get_status(dev_addr, port, &p_hub->port_status, connection_get_status_complete); @@ -345,13 +380,12 @@ bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32 void hub_close(uint8_t dev_addr) { - tu_memclr(&hub_data[dev_addr-1], sizeof(usbh_hub_t)); -// osal_semaphore_reset(hub_enum_sem_hdl); + tu_memclr(&hub_data[dev_addr-1], sizeof( hub_interface_t)); } bool hub_status_pipe_queue(uint8_t dev_addr) { - usbh_hub_t * p_hub = &hub_data[dev_addr-1]; + hub_interface_t * p_hub = &hub_data[dev_addr-1]; return usbh_edpt_xfer(dev_addr, p_hub->ep_in, &p_hub->status_change, 1); } diff --git a/src/host/hub.h b/src/host/hub.h index 2b2f39ee1..a5111b8e7 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -171,9 +171,11 @@ typedef struct { TU_VERIFY_STATIC( sizeof(hub_port_status_response_t) == 4, "size is not correct"); +bool hub_port_clear_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature, tuh_control_complete_cb_t complete_cb); +bool hub_port_set_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature, tuh_control_complete_cb_t complete_cb); + bool hub_port_reset(uint8_t hub_addr, uint8_t hub_port, tuh_control_complete_cb_t complete_cb); bool hub_port_get_status(uint8_t hub_addr, uint8_t hub_port, void* resp, tuh_control_complete_cb_t complete_cb); -bool hub_port_clear_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature, tuh_control_complete_cb_t complete_cb); bool hub_status_pipe_queue(uint8_t dev_addr); //--------------------------------------------------------------------+ From 4b2f32b7786674a1a5ccf7347a2e67e68665e1c3 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 31 May 2021 15:41:40 +0700 Subject: [PATCH 22/47] update hub --- src/host/hub.c | 224 ++++++++++++++++++++++-------------------------- src/host/usbh.c | 4 +- 2 files changed, 103 insertions(+), 125 deletions(-) diff --git a/src/host/hub.c b/src/host/hub.c index 6eea6ee4e..f921027c7 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -144,7 +144,6 @@ bool hub_port_get_status(uint8_t hub_addr, uint8_t hub_port, void* resp, tuh_con void hub_init(void) { tu_memclr(hub_data, CFG_TUSB_HOST_DEVICE_MAX*sizeof( hub_interface_t)); -// hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) ); } bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length) @@ -169,19 +168,56 @@ bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf return true; } +void hub_close(uint8_t dev_addr) +{ + tu_memclr(&hub_data[dev_addr-1], sizeof( hub_interface_t)); +} + +bool hub_status_pipe_queue(uint8_t dev_addr) +{ + hub_interface_t * p_hub = &hub_data[dev_addr-1]; + return usbh_edpt_xfer(dev_addr, p_hub->ep_in, &p_hub->status_change, 1); +} + + //--------------------------------------------------------------------+ // Set Configure //--------------------------------------------------------------------+ -static bool config_get_hub_desc_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); +static bool config_set_port_power (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); static bool config_port_power_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); -static bool config_get_hub_desc_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result) +bool hub_set_config(uint8_t dev_addr, uint8_t itf_num) +{ + hub_interface_t* p_hub = &hub_data[dev_addr-1]; + TU_ASSERT(itf_num == p_hub->itf_num); + + // Get Hub Descriptor + tusb_control_request_t const request = + { + .bmRequestType_bit = + { + .recipient = TUSB_REQ_RCPT_DEVICE, + .type = TUSB_REQ_TYPE_CLASS, + .direction = TUSB_DIR_IN + }, + .bRequest = HUB_REQUEST_GET_DESCRIPTOR, + .wValue = 0, + .wIndex = 0, + .wLength = sizeof(descriptor_hub_desc_t) + }; + + TU_ASSERT( tuh_control_xfer(dev_addr, &request, _hub_buffer, config_set_port_power) ); + + return true; +} + +static bool config_set_port_power (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result) { (void) request; TU_ASSERT(XFER_RESULT_SUCCESS == result); - hub_interface_t* p_hub = &hub_data[dev_addr-1]; + hub_interface_t* p_hub = &hub_data[dev_addr-1]; // only use number of ports in hub descriptor descriptor_hub_desc_t const* desc_hub = (descriptor_hub_desc_t const*) _hub_buffer; @@ -189,26 +225,9 @@ static bool config_get_hub_desc_complete (uint8_t dev_addr, tusb_control_request // May need to GET_STATUS - // Set Port Power to be able to detect connection - tusb_control_request_t const new_request = - { - .bmRequestType_bit = - { - .recipient = TUSB_REQ_RCPT_OTHER, - .type = TUSB_REQ_TYPE_CLASS, - .direction = TUSB_DIR_OUT - }, - .bRequest = HUB_REQUEST_SET_FEATURE, - .wValue = HUB_FEATURE_PORT_POWER, - .wIndex = 1, // starting with port 1 - .wLength = 0 - }; - - TU_LOG(2, "HUB Set Port Power: port = %u\r\n", new_request.wIndex); - - TU_ASSERT( tuh_control_xfer(dev_addr, &new_request, NULL, config_port_power_complete) ); - - return true; + // Set Port Power to be able to detect connection, starting with port 1 + uint8_t const hub_port = 1; + return hub_port_set_feature(dev_addr, hub_port, HUB_FEATURE_PORT_POWER, config_port_power_complete); } static bool config_port_power_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result) @@ -225,70 +244,71 @@ static bool config_port_power_complete (uint8_t dev_addr, tusb_control_request_t usbh_driver_set_config_complete(dev_addr, p_hub->itf_num); }else { - tusb_control_request_t new_request = *request; - new_request.wIndex++; // power next port - - TU_LOG(2, "HUB Set Port Power: port = %u\r\n", new_request.wIndex); - - TU_ASSERT( tuh_control_xfer(dev_addr, &new_request, NULL, config_port_power_complete) ); + // power next port + uint8_t const hub_port = (uint8_t) (request->wIndex + 1); + return hub_port_set_feature(dev_addr, hub_port, HUB_FEATURE_PORT_POWER, config_port_power_complete); } return true; } -bool hub_set_config(uint8_t dev_addr, uint8_t itf_num) -{ - hub_interface_t* p_hub = &hub_data[dev_addr-1]; - TU_ASSERT(itf_num == p_hub->itf_num); - - //------------- Get Hub Descriptor -------------// - tusb_control_request_t request = - { - .bmRequestType_bit = - { - .recipient = TUSB_REQ_RCPT_DEVICE, - .type = TUSB_REQ_TYPE_CLASS, - .direction = TUSB_DIR_IN - }, - .bRequest = HUB_REQUEST_GET_DESCRIPTOR, - .wValue = 0, - .wIndex = 0, - .wLength = sizeof(descriptor_hub_desc_t) - }; - - TU_ASSERT( tuh_control_xfer(dev_addr, &request, _hub_buffer, config_get_hub_desc_complete) ); - - return true; -} - //--------------------------------------------------------------------+ // Connection Changes //--------------------------------------------------------------------+ -static bool connection_clear_conn_change_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); static bool connection_get_status_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); +static bool connection_clear_conn_change_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); static bool connection_port_reset_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); -static bool connection_port_reset_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result) +// callback as response of interrupt endpoint polling +bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) { + (void) xferred_bytes; // TODO can be more than 1 for hub with lots of ports + (void) ep_addr; TU_ASSERT(result == XFER_RESULT_SUCCESS); - // usbh_hub_t * p_hub = &hub_data[dev_addr-1]; + hub_interface_t * p_hub = &hub_data[dev_addr-1]; + + TU_LOG2(" Port Status Change = 0x%02X\r\n", p_hub->status_change); + + // Hub ignore bit0 in status change + for (uint8_t port=1; port <= p_hub->port_count; port++) + { + if ( tu_bit_test(p_hub->status_change, port) ) + { + hub_port_get_status(dev_addr, port, &p_hub->port_status, connection_get_status_complete); + break; + } + } + + // NOTE: next status transfer is queued by usbh.c after handling this request + + return true; +} + +static bool connection_get_status_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result) +{ + TU_ASSERT(result == XFER_RESULT_SUCCESS); + hub_interface_t * p_hub = &hub_data[dev_addr-1]; uint8_t const port_num = (uint8_t) request->wIndex; - // submit attach event - hcd_event_t event = + // Connection change + if (p_hub->port_status.change.connection) { - .rhport = usbh_get_rhport(dev_addr), - .event_id = HCD_EVENT_DEVICE_ATTACH, - .connection = - { - .hub_addr = dev_addr, - .hub_port = port_num - } - }; + // Port is powered and enabled + //TU_VERIFY(port_status.status_current.port_power && port_status.status_current.port_enable, ); - hcd_event_handler(&event, false); + // Acknowledge Port Connection Change + hub_port_clear_feature(dev_addr, port_num, HUB_FEATURE_PORT_CONNECTION_CHANGE, connection_clear_conn_change_complete); + }else + { + // Other changes are: Enable, Suspend, Over Current, Reset, L1 state + // TODO clear change + + // prepare for next hub status + // TODO continue with status_change, or maybe we can do it again with status + hub_status_pipe_queue(dev_addr); + } return true; } @@ -324,70 +344,28 @@ static bool connection_clear_conn_change_complete (uint8_t dev_addr, tusb_contro return true; } -static bool connection_get_status_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result) +static bool connection_port_reset_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result) { TU_ASSERT(result == XFER_RESULT_SUCCESS); - hub_interface_t * p_hub = &hub_data[dev_addr-1]; + + // usbh_hub_t * p_hub = &hub_data[dev_addr-1]; uint8_t const port_num = (uint8_t) request->wIndex; - // Connection change - if (p_hub->port_status.change.connection) + // submit attach event + hcd_event_t event = { - // Port is powered and enabled - //TU_VERIFY(port_status.status_current.port_power && port_status.status_current.port_enable, ); - - // Acknowledge Port Connection Change - hub_port_clear_feature(dev_addr, port_num, HUB_FEATURE_PORT_CONNECTION_CHANGE, connection_clear_conn_change_complete); - }else - { - // Other changes are: Enable, Suspend, Over Current, Reset, L1 state - // TODO clear change - - // prepare for next hub status - // TODO continue with status_change, or maybe we can do it again with status - hub_status_pipe_queue(dev_addr); - } - - return true; -} - -// is the response of interrupt endpoint polling -#include "usbh_hcd.h" // FIXME remove -bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) -{ - (void) xferred_bytes; // TODO can be more than 1 for hub with lots of ports - (void) ep_addr; - TU_ASSERT( result == XFER_RESULT_SUCCESS); - - hub_interface_t * p_hub = &hub_data[dev_addr-1]; - - TU_LOG2(" Port Status Change = 0x%02X\r\n", p_hub->status_change); - - // Hub ignore bit0 in status change - for (uint8_t port=1; port <= p_hub->port_count; port++) - { - if ( tu_bit_test(p_hub->status_change, port) ) + .rhport = usbh_get_rhport(dev_addr), + .event_id = HCD_EVENT_DEVICE_ATTACH, + .connection = { - hub_port_get_status(dev_addr, port, &p_hub->port_status, connection_get_status_complete); - break; + .hub_addr = dev_addr, + .hub_port = port_num } - } + }; - // NOTE: next status transfer is queued by usbh.c after handling this request + hcd_event_handler(&event, false); return true; } -void hub_close(uint8_t dev_addr) -{ - tu_memclr(&hub_data[dev_addr-1], sizeof( hub_interface_t)); -} - -bool hub_status_pipe_queue(uint8_t dev_addr) -{ - hub_interface_t * p_hub = &hub_data[dev_addr-1]; - return usbh_edpt_xfer(dev_addr, p_hub->ep_in, &p_hub->status_change, 1); -} - - #endif diff --git a/src/host/usbh.c b/src/host/usbh.c index ac0b654ef..e50421b43 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -455,7 +455,7 @@ void hcd_event_device_attach(uint8_t rhport, bool in_isr) { hcd_event_t event = { - .rhport = rhport, + .rhport = rhport, .event_id = HCD_EVENT_DEVICE_ATTACH }; @@ -469,7 +469,7 @@ void hcd_event_device_remove(uint8_t hostid, bool in_isr) { hcd_event_t event = { - .rhport = hostid, + .rhport = hostid, .event_id = HCD_EVENT_DEVICE_REMOVE }; From 04797bc5a5e90304e5882ebc29c4c0f7d81ae012 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 31 May 2021 16:05:55 +0700 Subject: [PATCH 23/47] clean up --- src/host/usbh_control.c | 4 +- src/portable/ehci/ehci.c | 131 +++++++++++++++++++++++---------------- src/portable/ehci/ehci.h | 45 ++------------ 3 files changed, 84 insertions(+), 96 deletions(-) diff --git a/src/host/usbh_control.c b/src/host/usbh_control.c index 974d10662..4dbf8592a 100644 --- a/src/host/usbh_control.c +++ b/src/host/usbh_control.c @@ -108,7 +108,7 @@ bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t resu _ctrl_xfer.stage = STAGE_DATA; if (request->wLength) { - // Note: initial data toggle is always 1 + // DATA stage: initial data toggle is always 1 hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, request->bmRequestType_bit.direction), _ctrl_xfer.buffer, request->wLength); return true; } @@ -123,7 +123,7 @@ bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t resu TU_LOG2_MEM(_ctrl_xfer.buffer, request->wLength, 2); } - // data toggle is always 1 + // ACK stage: toggle is always 1 hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, 1-request->bmRequestType_bit.direction), NULL, 0); break; diff --git a/src/portable/ehci/ehci.c b/src/portable/ehci/ehci.c index 70a497f0a..1462d0c6a 100644 --- a/src/portable/ehci/ehci.c +++ b/src/portable/ehci/ehci.c @@ -44,6 +44,28 @@ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ +typedef struct +{ + ehci_link_t period_framelist[EHCI_FRAMELIST_SIZE]; + + // for NXP ECHI, only implement 1 ms & 2 ms & 4 ms, 8 ms (framelist) + // [0] : 1ms, [1] : 2ms, [2] : 4ms, [3] : 8 ms + ehci_qhd_t period_head_arr[4]; + + // Note control qhd of dev0 is used as head of async list + struct { + ehci_qhd_t qhd; + ehci_qtd_t qtd; + }control[CFG_TUSB_HOST_DEVICE_MAX+1]; + + ehci_qhd_t qhd_pool[HCD_MAX_ENDPOINT]; + ehci_qtd_t qtd_pool[HCD_MAX_XFER] TU_ATTR_ALIGNED(32); + + ehci_registers_t* regs; + + volatile uint32_t uframe_number; +}ehci_data_t; + //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ @@ -67,7 +89,8 @@ static inline ehci_qhd_t* qhd_control(uint8_t dev_addr) static inline ehci_qhd_t* qhd_async_head(uint8_t rhport) { (void) rhport; - return qhd_control(0); // control qhd of dev0 is used as async head + // control qhd of dev0 is used as async head + return qhd_control(0); } static inline ehci_qtd_t* qtd_control(uint8_t dev_addr) @@ -296,6 +319,59 @@ static void ehci_stop(uint8_t rhport) // Endpoint API //--------------------------------------------------------------------+ +bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) +{ + (void) rhport; + + // TODO not support ISO yet + TU_ASSERT (ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); + + //------------- Prepare Queue Head -------------// + ehci_qhd_t * p_qhd; + + if ( ep_desc->bEndpointAddress == 0 ) + { + p_qhd = qhd_control(dev_addr); + }else + { + p_qhd = qhd_find_free(); + } + TU_ASSERT(p_qhd); + + qhd_init(p_qhd, dev_addr, ep_desc); + + // control of dev0 is always present as async head + if ( dev_addr == 0 ) return true; + + // Insert to list + ehci_link_t * list_head = NULL; + + switch (ep_desc->bmAttributes.xfer) + { + case TUSB_XFER_CONTROL: + case TUSB_XFER_BULK: + list_head = (ehci_link_t*) qhd_async_head(rhport); + break; + + case TUSB_XFER_INTERRUPT: + list_head = get_period_head(rhport, p_qhd->interval_ms); + break; + + case TUSB_XFER_ISOCHRONOUS: + // TODO iso is not supported + break; + + default: break; + } + + TU_ASSERT(list_head); + + // TODO might need to disable async/period list + list_insert(list_head, (ehci_link_t*) p_qhd, EHCI_QTYPE_QHD); + + return true; +} + bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]) { (void) rhport; @@ -365,59 +441,6 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * return true; } -bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) -{ - (void) rhport; - - // TODO not support ISO yet - TU_ASSERT (ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); - - //------------- Prepare Queue Head -------------// - ehci_qhd_t * p_qhd; - - if ( ep_desc->bEndpointAddress == 0 ) - { - p_qhd = qhd_control(dev_addr); - }else - { - p_qhd = qhd_find_free(); - } - TU_ASSERT(p_qhd); - - qhd_init(p_qhd, dev_addr, ep_desc); - - // control of dev0 is always present as async head - if ( dev_addr == 0 ) return true; - - // Insert to list - ehci_link_t * list_head = NULL; - - switch (ep_desc->bmAttributes.xfer) - { - case TUSB_XFER_CONTROL: - case TUSB_XFER_BULK: - list_head = (ehci_link_t*) qhd_async_head(rhport); - break; - - case TUSB_XFER_INTERRUPT: - list_head = get_period_head(rhport, p_qhd->interval_ms); - break; - - case TUSB_XFER_ISOCHRONOUS: - // TODO iso is not supported - break; - - default: break; - } - - TU_ASSERT(list_head); - - // TODO might need to disable async/period list - list_insert(list_head, (ehci_link_t*) p_qhd, EHCI_QTYPE_QHD); - - return true; -} - bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) { ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr); diff --git a/src/portable/ehci/ehci.h b/src/portable/ehci/ehci.h index 212f605b1..874195a0c 100644 --- a/src/portable/ehci/ehci.h +++ b/src/portable/ehci/ehci.h @@ -24,12 +24,6 @@ * This file is part of the TinyUSB stack. */ -/** \ingroup Group_HCD - * @{ - * \defgroup EHCI - * \brief EHCI driver. All documents sources mentioned here (eg section 3.5) is referring to EHCI Specs unless state otherwise - * @{ */ - #ifndef _TUSB_EHCI_H_ #define _TUSB_EHCI_H_ @@ -309,12 +303,11 @@ enum ehci_usbcmd_pos_ { enum ehci_portsc_change_mask_{ EHCI_PORTSC_MASK_CURRENT_CONNECT_STATUS = TU_BIT(0), - EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE = TU_BIT(1), - EHCI_PORTSC_MASK_PORT_EANBLED = TU_BIT(2), - EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE = TU_BIT(3), - EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE = TU_BIT(5), - - EHCI_PORTSC_MASK_PORT_RESET = TU_BIT(8), + EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE = TU_BIT(1), + EHCI_PORTSC_MASK_PORT_EANBLED = TU_BIT(2), + EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE = TU_BIT(3), + EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE = TU_BIT(5), + EHCI_PORTSC_MASK_PORT_RESET = TU_BIT(8), EHCI_PORTSC_MASK_ALL = EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE | @@ -425,36 +418,8 @@ typedef volatile struct }; }ehci_registers_t; -//--------------------------------------------------------------------+ -// EHCI Data Organization -//--------------------------------------------------------------------+ -typedef struct -{ - ehci_link_t period_framelist[EHCI_FRAMELIST_SIZE]; - - // for NXP ECHI, only implement 1 ms & 2 ms & 4 ms, 8 ms (framelist) - // [0] : 1ms, [1] : 2ms, [2] : 4ms, [3] : 8 ms - ehci_qhd_t period_head_arr[4]; - - // Note control qhd of dev0 is used as head of async list - struct { - ehci_qhd_t qhd; - ehci_qtd_t qtd; - }control[CFG_TUSB_HOST_DEVICE_MAX+1]; - - ehci_qhd_t qhd_pool[HCD_MAX_ENDPOINT]; - ehci_qtd_t qtd_pool[HCD_MAX_XFER] TU_ATTR_ALIGNED(32); - - ehci_registers_t* regs; - - volatile uint32_t uframe_number; -}ehci_data_t; - #ifdef __cplusplus } #endif #endif /* _TUSB_EHCI_H_ */ - -/** @} */ -/** @} */ From da8000d42d6d6252eef9627efb6cf2557dfcf1d2 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 31 May 2021 16:34:07 +0700 Subject: [PATCH 24/47] clean up ohci, remove obsolete api --- src/portable/ohci/ohci.c | 173 +++++++++++++++------------------------ 1 file changed, 66 insertions(+), 107 deletions(-) diff --git a/src/portable/ohci/ohci.c b/src/portable/ohci/ohci.c index ee294856b..e6bd446ea 100644 --- a/src/portable/ohci/ohci.c +++ b/src/portable/ohci/ohci.c @@ -27,7 +27,7 @@ #include #if TUSB_OPT_HOST_ENABLED && \ - (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC40XX) + (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX) //--------------------------------------------------------------------+ // INCLUDE @@ -244,7 +244,7 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr) //--------------------------------------------------------------------+ //--------------------------------------------------------------------+ -// CONTROL PIPE API +// List Helper //--------------------------------------------------------------------+ static inline tusb_xfer_type_t ed_get_xfer_type(ohci_ed_t const * const p_ed) { @@ -310,57 +310,6 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet return true; } -// TODO move around -static ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr); -static ohci_gtd_t * gtd_find_free(void); -static void td_insert_to_ed(ohci_ed_t* p_ed, ohci_gtd_t * p_gtd); - -bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen) -{ - (void) rhport; - - uint8_t const epnum = tu_edpt_number(ep_addr); - uint8_t const dir = tu_edpt_dir(ep_addr); - - // FIXME control only for now - if ( epnum == 0 ) - { - ohci_ed_t* const p_ed = &ohci_data.control[dev_addr].ed; - ohci_gtd_t *p_data = &ohci_data.control[dev_addr].gtd; - - gtd_init(p_data, buffer, buflen); - - p_data->index = dev_addr; - p_data->pid = dir ? OHCI_PID_IN : OHCI_PID_OUT; - p_data->data_toggle = TU_BIN8(11); // DATA1 - p_data->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; - - p_ed->td_head.address = (uint32_t) p_data; - - OHCI_REG->command_status_bit.control_list_filled = 1; - }else - { - ohci_ed_t * p_ed = ed_from_addr(dev_addr, ep_addr); - ohci_gtd_t* p_gtd = gtd_find_free(); - - TU_ASSERT(p_gtd); - - gtd_init(p_gtd, buffer, buflen); - p_gtd->index = p_ed-ohci_data.ed_pool; - p_gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; - - td_insert_to_ed(p_ed, p_gtd); - - tusb_xfer_type_t xfer_type = ed_get_xfer_type( ed_from_addr(dev_addr, ep_addr) ); - if (TUSB_XFER_BULK == xfer_type) OHCI_REG->command_status_bit.bulk_list_filled = 1; - } - - return true; -} - -//--------------------------------------------------------------------+ -// BULK/INT/ISO PIPE API -//--------------------------------------------------------------------+ static ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr) { if ( tu_edpt_number(ep_addr) == 0 ) return &ohci_data.control[dev_addr].ed; @@ -420,9 +369,36 @@ static void ed_list_remove_by_addr(ohci_ed_t * p_head, uint8_t dev_addr) } } +static ohci_gtd_t * gtd_find_free(void) +{ + for(uint8_t i=0; i < HCD_MAX_XFER; i++) + { + if ( !ohci_data.gtd_pool[i].used ) return &ohci_data.gtd_pool[i]; + } + + return NULL; +} + +static void td_insert_to_ed(ohci_ed_t* p_ed, ohci_gtd_t * p_gtd) +{ + // tail is always NULL + if ( tu_align16(p_ed->td_head.address) == 0 ) + { // TD queue is empty --> head = TD + p_ed->td_head.address |= (uint32_t) p_gtd; + } + else + { // TODO currently only support queue up to 2 TD each endpoint at a time + ((ohci_gtd_t*) tu_align16(p_ed->td_head.address))->next = (uint32_t) p_gtd; + } +} + +//--------------------------------------------------------------------+ +// Endpoint API +//--------------------------------------------------------------------+ + bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) { - (void) rhport; + (void) rhport; // TODO iso support TU_ASSERT(ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); @@ -454,63 +430,46 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const return true; } -static ohci_gtd_t * gtd_find_free(void) +bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen) { - for(uint8_t i=0; i < HCD_MAX_XFER; i++) + (void) rhport; + + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); + + // FIXME control only for now + if ( epnum == 0 ) { - if ( !ohci_data.gtd_pool[i].used ) return &ohci_data.gtd_pool[i]; + ohci_ed_t* ed = &ohci_data.control[dev_addr].ed; + ohci_gtd_t* gtd = &ohci_data.control[dev_addr].gtd; + + gtd_init(gtd, buffer, buflen); + + gtd->index = dev_addr; + gtd->pid = dir ? OHCI_PID_IN : OHCI_PID_OUT; + gtd->data_toggle = 3; // Both Data and Ack stage start with DATA1 + gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; + + ed->td_head.address = (uint32_t) gtd; + + OHCI_REG->command_status_bit.control_list_filled = 1; + }else + { + ohci_ed_t * ed = ed_from_addr(dev_addr, ep_addr); + ohci_gtd_t* gtd = gtd_find_free(); + + TU_ASSERT(gtd); + + gtd_init(gtd, buffer, buflen); + gtd->index = ed-ohci_data.ed_pool; + gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; + + td_insert_to_ed(ed, gtd); + + tusb_xfer_type_t xfer_type = ed_get_xfer_type( ed_from_addr(dev_addr, ep_addr) ); + if (TUSB_XFER_BULK == xfer_type) OHCI_REG->command_status_bit.bulk_list_filled = 1; } - return NULL; -} - -static void td_insert_to_ed(ohci_ed_t* p_ed, ohci_gtd_t * p_gtd) -{ - // tail is always NULL - if ( tu_align16(p_ed->td_head.address) == 0 ) - { // TD queue is empty --> head = TD - p_ed->td_head.address |= (uint32_t) p_gtd; - } - else - { // TODO currently only support queue up to 2 TD each endpoint at a time - ((ohci_gtd_t*) tu_align16(p_ed->td_head.address))->next = (uint32_t) p_gtd; - } -} - -static bool pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) -{ - ohci_ed_t* const p_ed = ed_from_addr(dev_addr, ep_addr); - - // not support ISO yet - TU_VERIFY ( !p_ed->is_iso ); - - ohci_gtd_t * const p_gtd = gtd_find_free(); - TU_ASSERT(p_gtd); // not enough gtd - - gtd_init(p_gtd, buffer, total_bytes); - p_gtd->index = p_ed-ohci_data.ed_pool; - - if ( int_on_complete ) p_gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; - - td_insert_to_ed(p_ed, p_gtd); - - return true; -} - -bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes) -{ - return pipe_queue_xfer(dev_addr, ep_addr, buffer, total_bytes, false); -} - -bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) -{ - (void) int_on_complete; - TU_ASSERT( pipe_queue_xfer(dev_addr, ep_addr, buffer, total_bytes, true) ); - - tusb_xfer_type_t xfer_type = ed_get_xfer_type( ed_from_addr(dev_addr, ep_addr) ); - - if (TUSB_XFER_BULK == xfer_type) OHCI_REG->command_status_bit.bulk_list_filled = 1; - return true; } From 4e98ce914774390adcdbe9e2a299f6d47852cd07 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 31 May 2021 18:15:47 +0700 Subject: [PATCH 25/47] use hcd_frame_number() instead of uframe --- src/host/hcd.h | 9 +-------- src/host/usbh.c | 2 ++ src/portable/ehci/ehci.c | 5 ++--- src/portable/raspberrypi/rp2040/hcd_rp2040.c | 5 ++--- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/host/hcd.h b/src/host/hcd.h index 0a9f00a0c..46209dc45 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -108,15 +108,8 @@ void hcd_int_enable (uint8_t rhport); // Disable USB interrupt void hcd_int_disable(uint8_t rhport); -// Get micro frame number (125 us) -uint32_t hcd_uframe_number(uint8_t rhport); - // Get frame number (1ms) -TU_ATTR_ALWAYS_INLINE static inline -uint32_t hcd_frame_number(uint8_t rhport) -{ - return hcd_uframe_number(rhport) >> 3; -} +uint32_t hcd_frame_number(uint8_t rhport); //--------------------------------------------------------------------+ // Port API diff --git a/src/host/usbh.c b/src/host/usbh.c index e50421b43..ca0653409 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -378,6 +378,8 @@ bool usbh_edpt_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_ bool usbh_edpt_control_open(uint8_t dev_addr, uint8_t max_packet_size) { + TU_LOG2("Open EP Control with Size = %u\r\n", max_packet_size); + tusb_desc_endpoint_t ep0_desc = { .bLength = sizeof(tusb_desc_endpoint_t), diff --git a/src/portable/ehci/ehci.c b/src/portable/ehci/ehci.c index 1462d0c6a..bcba360bb 100644 --- a/src/portable/ehci/ehci.c +++ b/src/portable/ehci/ehci.c @@ -65,7 +65,6 @@ typedef struct volatile uint32_t uframe_number; }ehci_data_t; - //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ @@ -125,10 +124,10 @@ static inline ehci_link_t* list_next (ehci_link_t *p_link_pointer); // HCD API //--------------------------------------------------------------------+ -uint32_t hcd_uframe_number(uint8_t rhport) +uint32_t hcd_frame_number(uint8_t rhport) { (void) rhport; - return ehci_data.uframe_number + ehci_data.regs->frame_index; + return (ehci_data.uframe_number + ehci_data.regs->frame_index) >> 3; } void hcd_port_reset(uint8_t rhport) diff --git a/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/src/portable/raspberrypi/rp2040/hcd_rp2040.c index b8833fbec..864c6253e 100644 --- a/src/portable/raspberrypi/rp2040/hcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/hcd_rp2040.c @@ -504,10 +504,9 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet return true; } -uint32_t hcd_uframe_number(uint8_t rhport) +uint32_t hcd_frame_number(uint8_t rhport) { - // Microframe number is (125us) but we are max full speed so return miliseconds * 8 - return usb_hw->sof_rd * 8; + return usb_hw->sof_rd; } bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) From 31077f48d2f54dde8e692179761df17beafa7770 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 31 May 2021 18:16:07 +0700 Subject: [PATCH 26/47] correct ohci endpoint address in xfer complete --- src/portable/ohci/ohci.c | 129 +++++++++++++++++++++++---------------- src/portable/ohci/ohci.h | 18 +----- 2 files changed, 76 insertions(+), 71 deletions(-) diff --git a/src/portable/ohci/ohci.c b/src/portable/ohci/ohci.c index e6bd446ea..459e583cb 100644 --- a/src/portable/ohci/ohci.c +++ b/src/portable/ohci/ohci.c @@ -123,6 +123,23 @@ enum { OHCI_INT_ON_COMPLETE_YES = 0, OHCI_INT_ON_COMPLETE_NO = TU_BIN8(111) }; + +enum { + GTD_DT_TOGGLE_CARRY = 0, + GTD_DT_DATA0 = TU_BIT(1) | 0, + GTD_DT_DATA1 = TU_BIT(1) | 1, +}; + +enum { + PID_SETUP = 0, + PID_OUT, + PID_IN, +}; + +enum { + PID_FROM_TD = 0, +}; + //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ @@ -185,10 +202,10 @@ bool hcd_init(uint8_t rhport) return true; } -uint32_t hcd_uframe_number(uint8_t rhport) +uint32_t hcd_frame_number(uint8_t rhport) { (void) rhport; - return (ohci_data.frame_number_hi << 16 | OHCI_REG->frame_number) << 3; + return (ohci_data.frame_number_hi << 16) | OHCI_REG->frame_number; } @@ -248,12 +265,12 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr) //--------------------------------------------------------------------+ static inline tusb_xfer_type_t ed_get_xfer_type(ohci_ed_t const * const p_ed) { - return (p_ed->ep_number == 0 ) ? TUSB_XFER_CONTROL : - (p_ed->is_iso ) ? TUSB_XFER_ISOCHRONOUS : - (p_ed->is_interrupt_xfer ) ? TUSB_XFER_INTERRUPT : TUSB_XFER_BULK; + return (p_ed->ep_number == 0 ) ? TUSB_XFER_CONTROL : + (p_ed->is_iso ) ? TUSB_XFER_ISOCHRONOUS : + (p_ed->is_interrupt_xfer) ? TUSB_XFER_INTERRUPT : TUSB_XFER_BULK; } -static void ed_init(ohci_ed_t *p_ed, uint8_t dev_addr, uint16_t max_packet_size, uint8_t endpoint_addr, uint8_t xfer_type, uint8_t interval) +static void ed_init(ohci_ed_t *p_ed, uint8_t dev_addr, uint16_t ep_size, uint8_t ep_addr, uint8_t xfer_type, uint8_t interval) { (void) interval; @@ -263,18 +280,18 @@ static void ed_init(ohci_ed_t *p_ed, uint8_t dev_addr, uint16_t max_packet_size, tu_memclr(p_ed, sizeof(ohci_ed_t)); } - p_ed->dev_addr = dev_addr; - p_ed->ep_number = endpoint_addr & 0x0F; - p_ed->pid = (xfer_type == TUSB_XFER_CONTROL) ? OHCI_PID_SETUP : ( (endpoint_addr & TUSB_DIR_IN_MASK) ? OHCI_PID_IN : OHCI_PID_OUT ); + p_ed->dev_addr = dev_addr; + p_ed->ep_number = ep_addr & 0x0F; + p_ed->pid = (xfer_type == TUSB_XFER_CONTROL) ? PID_FROM_TD : (tu_edpt_dir(ep_addr) ? PID_IN : PID_OUT); p_ed->speed = _usbh_devices[dev_addr].speed; p_ed->is_iso = (xfer_type == TUSB_XFER_ISOCHRONOUS) ? 1 : 0; - p_ed->max_packet_size = max_packet_size; + p_ed->max_packet_size = ep_size; p_ed->used = 1; p_ed->is_interrupt_xfer = (xfer_type == TUSB_XFER_INTERRUPT ? 1 : 0); } -static void gtd_init(ohci_gtd_t* p_td, void* data_ptr, uint16_t total_bytes) +static void gtd_init(ohci_gtd_t* p_td, uint8_t* data_ptr, uint16_t total_bytes) { tu_memclr(p_td, sizeof(ohci_gtd_t)); @@ -286,28 +303,7 @@ static void gtd_init(ohci_gtd_t* p_td, void* data_ptr, uint16_t total_bytes) p_td->condition_code = OHCI_CCODE_NOT_ACCESSED; p_td->current_buffer_pointer = data_ptr; - p_td->buffer_end = total_bytes ? (((uint8_t*) data_ptr) + total_bytes-1) : NULL; -} - -bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]) -{ - (void) rhport; - - ohci_ed_t* p_ed = &ohci_data.control[dev_addr].ed; - ohci_gtd_t *p_setup = &ohci_data.control[dev_addr].gtd; - - gtd_init(p_setup, (void*) setup_packet, 8); - p_setup->index = dev_addr; - p_setup->pid = OHCI_PID_SETUP; - p_setup->data_toggle = TU_BIN8(10); // DATA0 - p_setup->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; - - //------------- Attach TDs list to Control Endpoint -------------// - p_ed->td_head.address = (uint32_t) p_setup; - - OHCI_REG->command_status_bit.control_list_filled = 1; - - return true; + p_td->buffer_end = total_bytes ? (data_ptr + total_bytes-1) : data_ptr; } static ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr) @@ -319,7 +315,7 @@ static ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr) for(uint32_t i=0; iindex = dev_addr; + qtd->pid = PID_SETUP; + qtd->data_toggle = GTD_DT_DATA0; + qtd->delay_interrupt = 0; + + //------------- Attach TDs list to Control Endpoint -------------// + ed->td_head.address = (uint32_t) qtd; + + OHCI_REG->command_status_bit.control_list_filled = 1; + + return true; +} + bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen) { (void) rhport; @@ -437,7 +454,6 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const dir = tu_edpt_dir(ep_addr); - // FIXME control only for now if ( epnum == 0 ) { ohci_ed_t* ed = &ohci_data.control[dev_addr].ed; @@ -446,9 +462,9 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * gtd_init(gtd, buffer, buflen); gtd->index = dev_addr; - gtd->pid = dir ? OHCI_PID_IN : OHCI_PID_OUT; - gtd->data_toggle = 3; // Both Data and Ack stage start with DATA1 - gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; + gtd->pid = dir ? PID_IN : PID_OUT; + gtd->data_toggle = GTD_DT_DATA1; // Both Data and Ack stage start with DATA1 + gtd->delay_interrupt = 0; ed->td_head.address = (uint32_t) gtd; @@ -462,7 +478,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * gtd_init(gtd, buffer, buflen); gtd->index = ed-ohci_data.ed_pool; - gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; + gtd->delay_interrupt = 0; td_insert_to_ed(ed, gtd); @@ -539,7 +555,12 @@ static inline ohci_ed_t* gtd_get_ed(ohci_gtd_t const * const p_qtd) } static inline uint32_t gtd_xfer_byte_left(uint32_t buffer_end, uint32_t current_buffer) -{ // 5.2.9 OHCI sample code +{ + // 5.2.9 OHCI sample code + + // CBP is 0 mean all data is transferred + if (current_buffer == 0) return 0; + return (tu_align4k(buffer_end ^ current_buffer) ? 0x1000 : 0) + tu_offset4k(buffer_end) - tu_offset4k(current_buffer) + 1; } @@ -555,16 +576,16 @@ static void done_queue_isr(uint8_t hostid) { // TODO check if td_head is iso td //------------- Non ISO transfer -------------// - ohci_gtd_t * const p_qtd = (ohci_gtd_t *) td_head; - xfer_result_t const event = (p_qtd->condition_code == OHCI_CCODE_NO_ERROR) ? XFER_RESULT_SUCCESS : - (p_qtd->condition_code == OHCI_CCODE_STALL) ? XFER_RESULT_STALLED : XFER_RESULT_FAILED; + ohci_gtd_t * const qtd = (ohci_gtd_t *) td_head; + xfer_result_t const event = (qtd->condition_code == OHCI_CCODE_NO_ERROR) ? XFER_RESULT_SUCCESS : + (qtd->condition_code == OHCI_CCODE_STALL) ? XFER_RESULT_STALLED : XFER_RESULT_FAILED; - p_qtd->used = 0; // free TD - if ( (p_qtd->delay_interrupt == OHCI_INT_ON_COMPLETE_YES) || (event != XFER_RESULT_SUCCESS) ) + qtd->used = 0; // free TD + if ( (qtd->delay_interrupt == OHCI_INT_ON_COMPLETE_YES) || (event != XFER_RESULT_SUCCESS) ) { - ohci_ed_t * const p_ed = gtd_get_ed(p_qtd); + ohci_ed_t * const ed = gtd_get_ed(qtd); - uint32_t const xferred_bytes = p_qtd->expected_bytes - gtd_xfer_byte_left((uint32_t) p_qtd->buffer_end, (uint32_t) p_qtd->current_buffer_pointer); + uint32_t const xferred_bytes = qtd->expected_bytes - gtd_xfer_byte_left((uint32_t) qtd->buffer_end, (uint32_t) qtd->current_buffer_pointer); // NOTE Assuming the current list is BULK and there is no other EDs in the list has queued TDs. // When there is a error resulting this ED is halted, and this EP still has other queued TD @@ -575,14 +596,14 @@ static void done_queue_isr(uint8_t hostid) // the TailP must be set back to NULL for processing remaining TDs if ((event != XFER_RESULT_SUCCESS)) { - p_ed->td_tail &= 0x0Ful; - p_ed->td_tail |= tu_align16(p_ed->td_head.address); // mark halted EP as empty queue - if ( event == XFER_RESULT_STALLED ) p_ed->is_stalled = 1; + ed->td_tail &= 0x0Ful; + ed->td_tail |= tu_align16(ed->td_head.address); // mark halted EP as empty queue + if ( event == XFER_RESULT_STALLED ) ed->is_stalled = 1; } - hcd_event_xfer_complete(p_ed->dev_addr, - tu_edpt_addr(p_ed->ep_number, p_ed->pid == OHCI_PID_IN), - xferred_bytes, event, true); + uint8_t dir = (ed->ep_number == 0) ? (qtd->pid == PID_IN) : (ed->pid == PID_IN); + + hcd_event_xfer_complete(ed->dev_addr, tu_edpt_addr(ed->ep_number, dir), xferred_bytes, event, true); } td_head = (ohci_td_item_t*) td_head->next; @@ -631,7 +652,7 @@ void hcd_int_handler(uint8_t hostid) } //------------- Transfer Complete -------------// - if ( int_status & OHCI_INT_WRITEBACK_DONEHEAD_MASK) + if (int_status & OHCI_INT_WRITEBACK_DONEHEAD_MASK) { done_queue_isr(hostid); } diff --git a/src/portable/ohci/ohci.h b/src/portable/ohci/ohci.h index 7f9e55b21..6a634592a 100644 --- a/src/portable/ohci/ohci.h +++ b/src/portable/ohci/ohci.h @@ -24,12 +24,6 @@ * This file is part of the TinyUSB stack. */ -/** \ingroup Group_HCD - * @{ - * \defgroup OHCI - * \brief OHCI driver. All documents sources mentioned here (eg section 3.5) is referring to OHCI Specs unless state otherwise - * @{ */ - #ifndef _TUSB_OHCI_H_ #define _TUSB_OHCI_H_ @@ -48,12 +42,6 @@ enum { OHCI_MAX_ITD = 4 }; -enum { - OHCI_PID_SETUP = 0, - OHCI_PID_OUT, - OHCI_PID_IN, -}; - //--------------------------------------------------------------------+ // OHCI Data Structure //--------------------------------------------------------------------+ @@ -73,7 +61,6 @@ typedef struct { uint32_t reserved2; }ohci_td_item_t; - typedef struct TU_ATTR_ALIGNED(16) { // Word 0 @@ -105,7 +92,7 @@ typedef struct TU_ATTR_ALIGNED(16) // Word 0 uint32_t dev_addr : 7; uint32_t ep_number : 4; - uint32_t pid : 2; // 00b from TD, 01b Out, 10b In + uint32_t pid : 2; uint32_t speed : 1; uint32_t skip : 1; uint32_t is_iso : 1; @@ -286,6 +273,3 @@ TU_VERIFY_STATIC( sizeof(ohci_registers_t) == 0x5c, "size is not correct"); #endif #endif /* _TUSB_OHCI_H_ */ - -/** @} */ -/** @} */ From bc0a0386e9aba4c3eccf9806a8ed7aecdefe23d6 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 31 May 2021 18:41:08 +0700 Subject: [PATCH 27/47] clean up --- src/portable/ohci/ohci.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/portable/ohci/ohci.c b/src/portable/ohci/ohci.c index 459e583cb..dbd2cc793 100644 --- a/src/portable/ohci/ohci.c +++ b/src/portable/ohci/ohci.c @@ -84,23 +84,23 @@ enum { }; enum { - OHCI_RHPORT_CURRENT_CONNECT_STATUS_MASK = TU_BIT(0), - OHCI_RHPORT_PORT_ENABLE_STATUS_MASK = TU_BIT(1), - OHCI_RHPORT_PORT_SUSPEND_STATUS_MASK = TU_BIT(2), - OHCI_RHPORT_PORT_OVER_CURRENT_INDICATOR_MASK = TU_BIT(3), - OHCI_RHPORT_PORT_RESET_STATUS_MASK = TU_BIT(4), ///< write '1' to reset port + RHPORT_CURRENT_CONNECT_STATUS_MASK = TU_BIT(0), + RHPORT_PORT_ENABLE_STATUS_MASK = TU_BIT(1), + RHPORT_PORT_SUSPEND_STATUS_MASK = TU_BIT(2), + RHPORT_PORT_OVER_CURRENT_INDICATOR_MASK = TU_BIT(3), + RHPORT_PORT_RESET_STATUS_MASK = TU_BIT(4), ///< write '1' to reset port - OHCI_RHPORT_PORT_POWER_STATUS_MASK = TU_BIT(8), - OHCI_RHPORT_LOW_SPEED_DEVICE_ATTACHED_MASK = TU_BIT(9), + RHPORT_PORT_POWER_STATUS_MASK = TU_BIT(8), + RHPORT_LOW_SPEED_DEVICE_ATTACHED_MASK = TU_BIT(9), - OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK = TU_BIT(16), - OHCI_RHPORT_PORT_ENABLE_CHANGE_MASK = TU_BIT(17), - OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK = TU_BIT(18), - OHCI_RHPORT_OVER_CURRENT_CHANGE_MASK = TU_BIT(19), - OHCI_RHPORT_PORT_RESET_CHANGE_MASK = TU_BIT(20), + RHPORT_CONNECT_STATUS_CHANGE_MASK = TU_BIT(16), + RHPORT_PORT_ENABLE_CHANGE_MASK = TU_BIT(17), + RHPORT_PORT_SUSPEND_CHANGE_MASK = TU_BIT(18), + RHPORT_OVER_CURRENT_CHANGE_MASK = TU_BIT(19), + RHPORT_PORT_RESET_CHANGE_MASK = TU_BIT(20), - OHCI_RHPORT_ALL_CHANGE_MASK = OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK | OHCI_RHPORT_PORT_ENABLE_CHANGE_MASK | - OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK | OHCI_RHPORT_OVER_CURRENT_CHANGE_MASK | OHCI_RHPORT_PORT_RESET_CHANGE_MASK + RHPORT_ALL_CHANGE_MASK = RHPORT_CONNECT_STATUS_CHANGE_MASK | RHPORT_PORT_ENABLE_CHANGE_MASK | + RHPORT_PORT_SUSPEND_CHANGE_MASK | RHPORT_OVER_CURRENT_CHANGE_MASK | RHPORT_PORT_RESET_CHANGE_MASK }; enum { @@ -215,7 +215,7 @@ uint32_t hcd_frame_number(uint8_t rhport) void hcd_port_reset(uint8_t hostid) { (void) hostid; - OHCI_REG->rhport_status[0] = OHCI_RHPORT_PORT_RESET_STATUS_MASK; + OHCI_REG->rhport_status[0] = RHPORT_PORT_RESET_STATUS_MASK; } bool hcd_port_connect_status(uint8_t hostid) @@ -626,16 +626,16 @@ void hcd_int_handler(uint8_t hostid) //------------- RootHub status -------------// if ( int_status & OHCI_INT_RHPORT_STATUS_CHANGE_MASK ) { - uint32_t const rhport_status = OHCI_REG->rhport_status[0] & OHCI_RHPORT_ALL_CHANGE_MASK; + uint32_t const rhport_status = OHCI_REG->rhport_status[0] & RHPORT_ALL_CHANGE_MASK; // TODO dual port is not yet supported - if ( rhport_status & OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK ) + if ( rhport_status & RHPORT_CONNECT_STATUS_CHANGE_MASK ) { // TODO check if remote wake-up if ( OHCI_REG->rhport_status_bit[0].current_connect_status ) { // TODO reset port immediately, without this controller will got 2-3 (debouncing connection status change) - OHCI_REG->rhport_status[0] = OHCI_RHPORT_PORT_RESET_STATUS_MASK; + OHCI_REG->rhport_status[0] = RHPORT_PORT_RESET_STATUS_MASK; hcd_event_device_attach(hostid, true); }else { @@ -643,7 +643,7 @@ void hcd_int_handler(uint8_t hostid) } } - if ( rhport_status & OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK) + if ( rhport_status & RHPORT_PORT_SUSPEND_CHANGE_MASK) { } From 5d161b79bbf9116d36ecf4b08d24dfae1738235f Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 31 May 2021 10:06:07 -0500 Subject: [PATCH 28/47] Fix up build_family style builds: - added back pre-existing board directories which now just select PICO_BOARD - added boards/pico_sdk which just uses the pre-existing PICO_BOARD setting - fixed rp2040/family.cmake to include the magic string "CFG_TUSB_MCU=OPT_MCU_RP2040" expected by build_family.py --- examples/device/board_test/CMakeLists.txt | 8 +++++--- hw/bsp/esp32s2/family.cmake | 2 +- hw/bsp/esp32s3/family.cmake | 2 +- .../boards/adafruit_feather_rp2040/board.cmake | 1 + .../adafruit_itsybitsy_rp2040/board.cmake | 1 + .../boards/adafruit_qtpy_rp2040/board.cmake | 1 + hw/bsp/rp2040/boards/pico_sdk/board.cmake | 1 + .../boards/raspberry_pi_pico/board.cmake | 1 + hw/bsp/rp2040/family.cmake | 18 ++++++++++-------- lib/CMSIS_5 | 2 +- 10 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake create mode 100644 hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake create mode 100644 hw/bsp/rp2040/boards/adafruit_qtpy_rp2040/board.cmake create mode 100644 hw/bsp/rp2040/boards/pico_sdk/board.cmake create mode 100644 hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index 5bb8cb700..8cd5b9ea4 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -17,12 +17,14 @@ if(FAMILY MATCHES "^esp32s[2-3]") else() - # Family chooses name based on passed name and vars (e.g. -) - get_filename_component(DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - family_get_project_name(PROJECT "${DIR_NAME}") + # gets PROJECT name for the example (e.g. -) + family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT}) + # Checks this example is valid for the family and initializes the project + family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + add_executable(${PROJECT}) # Example source diff --git a/hw/bsp/esp32s2/family.cmake b/hw/bsp/esp32s2/family.cmake index 656f7d852..02957fa1d 100644 --- a/hw/bsp/esp32s2/family.cmake +++ b/hw/bsp/esp32s2/family.cmake @@ -6,5 +6,5 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(SUPPORTED_TARGETS esp32s2) # include basic family CMake functionality -set(FAMILY_MCUS esp32s2 ESP32S2) +set(FAMILY_MCUS ESP32S2) include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) diff --git a/hw/bsp/esp32s3/family.cmake b/hw/bsp/esp32s3/family.cmake index e57920bf7..b530b326d 100644 --- a/hw/bsp/esp32s3/family.cmake +++ b/hw/bsp/esp32s3/family.cmake @@ -6,5 +6,5 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(SUPPORTED_TARGETS esp32s3) # include basic family CMake functionality -set(FAMILY_MCUS esp32s3 ESP32S3) # TODO MERGE THIS WITH supported targets? +set(FAMILY_MCUS ESP32S3) include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) diff --git a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake new file mode 100644 index 000000000..e527a8ce3 --- /dev/null +++ b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake @@ -0,0 +1 @@ +set(PICO_BOARD adafruit_feather_rp2040) \ No newline at end of file diff --git a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake new file mode 100644 index 000000000..3fd2dd06b --- /dev/null +++ b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake @@ -0,0 +1 @@ +set(PICO_BOARD adafruit_itsybitsy_rp2040) \ No newline at end of file diff --git a/hw/bsp/rp2040/boards/adafruit_qtpy_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_qtpy_rp2040/board.cmake new file mode 100644 index 000000000..469929c51 --- /dev/null +++ b/hw/bsp/rp2040/boards/adafruit_qtpy_rp2040/board.cmake @@ -0,0 +1 @@ +set(PICO_BOARD adafruit_qtpy_rp2040) \ No newline at end of file diff --git a/hw/bsp/rp2040/boards/pico_sdk/board.cmake b/hw/bsp/rp2040/boards/pico_sdk/board.cmake new file mode 100644 index 000000000..d57cbe52b --- /dev/null +++ b/hw/bsp/rp2040/boards/pico_sdk/board.cmake @@ -0,0 +1 @@ +# This builds with settings based purely on the current PICO_BOARD set via the SDK diff --git a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake new file mode 100644 index 000000000..8280c835d --- /dev/null +++ b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake @@ -0,0 +1 @@ +set(PICO_BOARD pico) \ No newline at end of file diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index 544718a6e..cc9bf65bd 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -3,17 +3,18 @@ if (NOT TARGET _rp2040_family_inclusion_marker) add_library(_rp2040_family_inclusion_marker INTERFACE) # include basic family CMake functionality - set(FAMILY_MCUS RP2040 rp2040) - include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) - - if (BOARD AND NOT PICO_BOARD) - message("Defaulting PICO_BOARD from BOARD ('${BOARD}')") - set(PICO_BOARD ${BOARD}) - endif() + set(FAMILY_MCUS RP2040) # add the SDK in case we are standalone tinyusb example (noop if already present) include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake) - set(BOARD ${PICO_BOARD}) + + include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) + + # todo should we default to pico_sdk? + if (NOT BOARD) + message(FATAL_ERROR "BOARD must be specified") + endif() + include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") @@ -24,6 +25,7 @@ if (NOT TARGET _rp2040_family_inclusion_marker) target_compile_definitions(tinyusb_additions INTERFACE PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1 + CFG_TUSB_MCU=OPT_MCU_RP2040 # this is already included in the SDK, but needed here for build_family.py grep ) if(DEFINED LOG) diff --git a/lib/CMSIS_5 b/lib/CMSIS_5 index 202852626..b7b26f50d 160000 --- a/lib/CMSIS_5 +++ b/lib/CMSIS_5 @@ -1 +1 @@ -Subproject commit 20285262657d1b482d132d20d755c8c330d55c1f +Subproject commit b7b26f50d00072812aec8453f643e24bafedccb5 From 13951b43c22ffe5bad531c2d7e5d22d540e82118 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 31 May 2021 10:58:14 -0500 Subject: [PATCH 29/47] set PICO_TINYUSB_PATH for when building from within tinyusb without pico-sdk/tinyusb submodule --- hw/bsp/rp2040/family.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index cc9bf65bd..cb9d8094a 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -20,6 +20,10 @@ if (NOT TARGET _rp2040_family_inclusion_marker) set(TOP "../../..") get_filename_component(TOP "${TOP}" REALPATH) + if (NOT PICO_TINYUSB_PATH) + set(PICO_TINYUSB_PATH ${TOP}) + endif() + # tinyusb_additions will hold our extra settings libraries add_library(tinyusb_additions INTERFACE) From db138a530cadfc91241ac158a188cefe7452c90e Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 31 May 2021 11:10:55 -0500 Subject: [PATCH 30/47] Switch checks to use tinyusb-0.10.0 branch of pico-sdk due to circular dependency --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ed20b859..0c91bda84 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,6 +68,7 @@ jobs: if: matrix.family == 'rp2040' run: | git clone --depth 1 https://github.com/raspberrypi/pico-sdk ~/pico-sdk + git checkout tinyusb-0.10.0 echo >> $GITHUB_ENV PICO_SDK_PATH=~/pico-sdk - name: Set Toolchain URL From 90d7483d925eab3ab2c05d286d0671cb8ec66ecc Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 31 May 2021 11:18:26 -0500 Subject: [PATCH 31/47] guard stdio_uart_init_full with LIB_PICO_STDUI_UART as the function doesn't exist otherwise --- hw/bsp/rp2040/family.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c index b2dbd3e6a..10ead2776 100644 --- a/hw/bsp/rp2040/family.c +++ b/hw/bsp/rp2040/family.c @@ -127,7 +127,7 @@ void board_init(void) #ifndef BUTTON_BOOTSEL #endif -#ifdef UART_DEV +#if defined(UART_DEV) && defined(LIB_PICO_STDIO_UART) bi_decl(bi_2pins_with_func(UART_TX_PIN, UART_TX_PIN, GPIO_FUNC_UART)); uart_inst = uart_get_instance(UART_DEV); stdio_uart_init_full(uart_inst, CFG_BOARD_UART_BAUDRATE, UART_TX_PIN, UART_RX_PIN); From 9b17acd1683cc6cd4ea1835991daf15fe8e2e368 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 31 May 2021 11:23:14 -0500 Subject: [PATCH 32/47] actually fix pico-sdk checkout to checkout the right branch --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0c91bda84..09236db65 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,8 +67,7 @@ jobs: - name: Checkout pico-sdk if: matrix.family == 'rp2040' run: | - git clone --depth 1 https://github.com/raspberrypi/pico-sdk ~/pico-sdk - git checkout tinyusb-0.10.0 + git clone --depth 1 -b tinyusb-0.10.0 https://github.com/raspberrypi/pico-sdk ~/pico-sdk echo >> $GITHUB_ENV PICO_SDK_PATH=~/pico-sdk - name: Set Toolchain URL From f5572e24b25800c133b2f9fd4eae02e0934cd935 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 31 May 2021 11:49:15 -0500 Subject: [PATCH 33/47] restore unintentionally modified submodules --- hw/mcu/microchip | 2 +- hw/mcu/sony/cxd56/spresense-exported-sdk | 2 +- lib/CMSIS_5 | 2 +- lib/lwip | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/mcu/microchip b/hw/mcu/microchip index 66b5a1199..f7087f047 160000 --- a/hw/mcu/microchip +++ b/hw/mcu/microchip @@ -1 +1 @@ -Subproject commit 66b5a11995025426224e0ba6f377322e6e8893b6 +Subproject commit f7087f04783c896627061fc151fa3527b73733c7 diff --git a/hw/mcu/sony/cxd56/spresense-exported-sdk b/hw/mcu/sony/cxd56/spresense-exported-sdk index b473b28a1..2ec2a1538 160000 --- a/hw/mcu/sony/cxd56/spresense-exported-sdk +++ b/hw/mcu/sony/cxd56/spresense-exported-sdk @@ -1 +1 @@ -Subproject commit b473b28a14a03f3d416b6e2c071bcfd4fb92cb63 +Subproject commit 2ec2a1538362696118dc3fdf56f33dacaf8f4067 diff --git a/lib/CMSIS_5 b/lib/CMSIS_5 index b7b26f50d..202852626 160000 --- a/lib/CMSIS_5 +++ b/lib/CMSIS_5 @@ -1 +1 @@ -Subproject commit b7b26f50d00072812aec8453f643e24bafedccb5 +Subproject commit 20285262657d1b482d132d20d755c8c330d55c1f diff --git a/lib/lwip b/lib/lwip index 0192fe773..159e31b68 160000 --- a/lib/lwip +++ b/lib/lwip @@ -1 +1 @@ -Subproject commit 0192fe773ec28e11f66ec76f4e827fbb58b7e257 +Subproject commit 159e31b689577dbf69cf0683bbaffbd71fa5ee10 From abf83c6985c62234256f56cf0872fe93e7451ff3 Mon Sep 17 00:00:00 2001 From: Ha Thach Date: Tue, 1 Jun 2021 13:36:19 +0700 Subject: [PATCH 34/47] add note for custom class driver --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f7b2cd811..bea6d0d49 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ Supports multiple device configurations by dynamically changing usb descriptors. - Vendor-specific class support with generic In & Out endpoints. Can be used with MS OS 2.0 compatible descriptor to load winUSB driver without INF file. - [WebUSB](https://github.com/WICG/webusb) with vendor-specific class +If you have special need, `usbd_app_driver_get_cb()` can be used to write your own class driver without modifying the stack. Here is how RPi team add their reset interface [raspberrypi/pico-sdk#197](https://github.com/raspberrypi/pico-sdk/pull/197) + ## Host Stack **Most active development is on the Device stack. The Host stack is under rework and largely untested.** From 8782d0b8df507a0d2e1f7a12a27a76d50e0d4477 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 1 Jun 2021 09:04:08 -0500 Subject: [PATCH 35/47] fix rp2040 examples build from local tinyusb tree --- hw/bsp/rp2040/family.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index cb9d8094a..ee17d4d46 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -17,7 +17,7 @@ if (NOT TARGET _rp2040_family_inclusion_marker) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) # TOP is absolute path to root directory of TinyUSB git repo - set(TOP "../../..") + set(TOP "${CMAKE_CURRENT_LIST_DIR}/../../..") get_filename_component(TOP "${TOP}" REALPATH) if (NOT PICO_TINYUSB_PATH) From 6e29bf6e54ce08edb2ad5936805af0746639ff39 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 1 Jun 2021 09:09:25 -0500 Subject: [PATCH 36/47] rename family.cmake to family_common.cmake --- hw/bsp/esp32s2/family.cmake | 2 +- hw/bsp/esp32s3/family.cmake | 2 +- hw/bsp/{family.cmake => family_common.cmake} | 0 hw/bsp/rp2040/family.cmake | 3 ++- hw/mcu/microchip | 2 +- hw/mcu/sony/cxd56/spresense-exported-sdk | 2 +- lib/CMSIS_5 | 2 +- lib/lwip | 2 +- 8 files changed, 8 insertions(+), 7 deletions(-) rename hw/bsp/{family.cmake => family_common.cmake} (100%) diff --git a/hw/bsp/esp32s2/family.cmake b/hw/bsp/esp32s2/family.cmake index 02957fa1d..9eb1627a1 100644 --- a/hw/bsp/esp32s2/family.cmake +++ b/hw/bsp/esp32s2/family.cmake @@ -7,4 +7,4 @@ set(SUPPORTED_TARGETS esp32s2) # include basic family CMake functionality set(FAMILY_MCUS ESP32S2) -include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) diff --git a/hw/bsp/esp32s3/family.cmake b/hw/bsp/esp32s3/family.cmake index b530b326d..c99c3728b 100644 --- a/hw/bsp/esp32s3/family.cmake +++ b/hw/bsp/esp32s3/family.cmake @@ -7,4 +7,4 @@ set(SUPPORTED_TARGETS esp32s3) # include basic family CMake functionality set(FAMILY_MCUS ESP32S3) -include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) diff --git a/hw/bsp/family.cmake b/hw/bsp/family_common.cmake similarity index 100% rename from hw/bsp/family.cmake rename to hw/bsp/family_common.cmake diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index ee17d4d46..e791648a9 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -8,7 +8,7 @@ if (NOT TARGET _rp2040_family_inclusion_marker) # add the SDK in case we are standalone tinyusb example (noop if already present) include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake) - include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) + include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) # todo should we default to pico_sdk? if (NOT BOARD) @@ -68,6 +68,7 @@ if (NOT TARGET _rp2040_family_inclusion_marker) endfunction() function(family_initialize_project PROJECT DIR) + # call the original version of this function from family_common.cmake _family_initialize_project(${PROJECT} ${DIR}) enable_language(C CXX ASM) pico_sdk_init() diff --git a/hw/mcu/microchip b/hw/mcu/microchip index f7087f047..66b5a1199 160000 --- a/hw/mcu/microchip +++ b/hw/mcu/microchip @@ -1 +1 @@ -Subproject commit f7087f04783c896627061fc151fa3527b73733c7 +Subproject commit 66b5a11995025426224e0ba6f377322e6e8893b6 diff --git a/hw/mcu/sony/cxd56/spresense-exported-sdk b/hw/mcu/sony/cxd56/spresense-exported-sdk index 2ec2a1538..b473b28a1 160000 --- a/hw/mcu/sony/cxd56/spresense-exported-sdk +++ b/hw/mcu/sony/cxd56/spresense-exported-sdk @@ -1 +1 @@ -Subproject commit 2ec2a1538362696118dc3fdf56f33dacaf8f4067 +Subproject commit b473b28a14a03f3d416b6e2c071bcfd4fb92cb63 diff --git a/lib/CMSIS_5 b/lib/CMSIS_5 index 202852626..b7b26f50d 160000 --- a/lib/CMSIS_5 +++ b/lib/CMSIS_5 @@ -1 +1 @@ -Subproject commit 20285262657d1b482d132d20d755c8c330d55c1f +Subproject commit b7b26f50d00072812aec8453f643e24bafedccb5 diff --git a/lib/lwip b/lib/lwip index 159e31b68..0192fe773 160000 --- a/lib/lwip +++ b/lib/lwip @@ -1 +1 @@ -Subproject commit 159e31b689577dbf69cf0683bbaffbd71fa5ee10 +Subproject commit 0192fe773ec28e11f66ec76f4e827fbb58b7e257 From ebf6461c4279d22e89101d2705fa2c91e4ad2993 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 1 Jun 2021 10:58:44 -0500 Subject: [PATCH 37/47] damn submodules! --- hw/mcu/microchip | 2 +- hw/mcu/sony/cxd56/spresense-exported-sdk | 2 +- lib/CMSIS_5 | 2 +- lib/lwip | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/mcu/microchip b/hw/mcu/microchip index 66b5a1199..f7087f047 160000 --- a/hw/mcu/microchip +++ b/hw/mcu/microchip @@ -1 +1 @@ -Subproject commit 66b5a11995025426224e0ba6f377322e6e8893b6 +Subproject commit f7087f04783c896627061fc151fa3527b73733c7 diff --git a/hw/mcu/sony/cxd56/spresense-exported-sdk b/hw/mcu/sony/cxd56/spresense-exported-sdk index b473b28a1..2ec2a1538 160000 --- a/hw/mcu/sony/cxd56/spresense-exported-sdk +++ b/hw/mcu/sony/cxd56/spresense-exported-sdk @@ -1 +1 @@ -Subproject commit b473b28a14a03f3d416b6e2c071bcfd4fb92cb63 +Subproject commit 2ec2a1538362696118dc3fdf56f33dacaf8f4067 diff --git a/lib/CMSIS_5 b/lib/CMSIS_5 index b7b26f50d..202852626 160000 --- a/lib/CMSIS_5 +++ b/lib/CMSIS_5 @@ -1 +1 @@ -Subproject commit b7b26f50d00072812aec8453f643e24bafedccb5 +Subproject commit 20285262657d1b482d132d20d755c8c330d55c1f diff --git a/lib/lwip b/lib/lwip index 0192fe773..159e31b68 160000 --- a/lib/lwip +++ b/lib/lwip @@ -1 +1 @@ -Subproject commit 0192fe773ec28e11f66ec76f4e827fbb58b7e257 +Subproject commit 159e31b689577dbf69cf0683bbaffbd71fa5ee10 From 109d02531e3ba208627b4dfab29d29df3d8a4565 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 1 Jun 2021 11:21:19 -0500 Subject: [PATCH 38/47] remove TINYUSB_FAMILT_PROJECT_NAME_INCLUDES_BOARD setting --- hw/bsp/family_common.cmake | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hw/bsp/family_common.cmake b/hw/bsp/family_common.cmake index 124399675..2544c58c6 100644 --- a/hw/bsp/family_common.cmake +++ b/hw/bsp/family_common.cmake @@ -35,11 +35,7 @@ endfunction() function(family_get_project_name OUTPUT_NAME DIR) get_filename_component(SHORT_NAME ${DIR} NAME) - if (TINYUSB_FAMILY_PROJECT_NAME_INCLUDES_BOARD OR NOT DEFINED TINYUSB_FAMILY_PROJECT_NAME_INCLUDES_BOARD) - set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${BOARD}-${SHORT_NAME} PARENT_SCOPE) - else() - set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) - endif() + set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) endfunction() function(family_initialize_project PROJECT DIR) From 6e2cf2a3eec141e2714937532320c9fc46b95f9b Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 2 Jun 2021 00:10:35 +0700 Subject: [PATCH 39/47] clean up log --- src/class/hid/hid_device.c | 2 +- src/class/msc/msc_device.c | 2 +- src/class/vendor/vendor_device.c | 2 +- src/common/tusb_common.h | 4 ---- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index c7f5d04ec..151a36225 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -225,7 +225,7 @@ uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint1 { if ( !usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)) ) { - TU_LOG1_FAILED(); + TU_LOG_FAILED(); TU_BREAKPOINT(); } } diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 9b06b7a33..7f13b4891 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -172,7 +172,7 @@ uint16_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1 // Prepare for Command Block Wrapper if ( !usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) ) { - TU_LOG1_FAILED(); + TU_LOG_FAILED(); TU_BREAKPOINT(); } diff --git a/src/class/vendor/vendor_device.c b/src/class/vendor/vendor_device.c index 081aac9f6..6718a97bf 100644 --- a/src/class/vendor/vendor_device.c +++ b/src/class/vendor/vendor_device.c @@ -195,7 +195,7 @@ uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, ui // Prepare for incoming data if ( !usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, sizeof(p_vendor->epout_buf)) ) { - TU_LOG1_FAILED(); + TU_LOG_FAILED(); TU_BREAKPOINT(); } diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 6f2905697..d9b388916 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -372,8 +372,6 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3 #define TU_LOG1_VAR(...) #define TU_LOG1_INT(...) #define TU_LOG1_HEX(...) - #define TU_LOG1_LOCATION() - #define TU_LOG1_FAILED() #endif #ifndef TU_LOG2 @@ -382,7 +380,6 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3 #define TU_LOG2_VAR(...) #define TU_LOG2_INT(...) #define TU_LOG2_HEX(...) - #define TU_LOG2_LOCATION() #endif #ifndef TU_LOG3 @@ -391,7 +388,6 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3 #define TU_LOG3_VAR(...) #define TU_LOG3_INT(...) #define TU_LOG3_HEX(...) - #define TU_LOG3_LOCATION() #endif #ifdef __cplusplus From 54107100bbc32756324070a6a06146b958f653d6 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 2 Jun 2021 00:26:50 +0700 Subject: [PATCH 40/47] fix missing TU_LOG symbol --- src/common/tusb_common.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index d9b388916..3350ed86c 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -24,10 +24,6 @@ * This file is part of the TinyUSB stack. */ -/** \ingroup Group_Common - * \defgroup Group_CommonH common.h - * @{ */ - #ifndef _TUSB_COMMON_H_ #define _TUSB_COMMON_H_ @@ -288,8 +284,9 @@ TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16 (void* mem, ui // CFG_TUSB_DEBUG for debugging // 0 : no debug -// 1 : print when there is error -// 2 : print out log +// 1 : print error +// 2 : print warning +// 3 : print info #if CFG_TUSB_DEBUG void tu_print_mem(void const *buf, uint32_t count, uint8_t indent); @@ -316,7 +313,6 @@ void tu_print_var(uint8_t const* buf, uint32_t bufsize) #define TU_LOG_LOCATION() tu_printf("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__) #define TU_LOG_FAILED() tu_printf("%s: %d: Failed\r\n", __PRETTY_FUNCTION__, __LINE__) - // Log Level 1: Error #define TU_LOG1 tu_printf #define TU_LOG1_MEM tu_print_mem @@ -366,6 +362,17 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3 #endif // CFG_TUSB_DEBUG +#ifndef TU_LOG +#define TU_LOG(n, ...) +#define TU_LOG_MEM(n, ...) +#define TU_LOG_VAR(n, ...) +#define TU_LOG_INT(n, ...) +#define TU_LOG_HEX(n, ...) +#define TU_LOG_LOCATION() +#define TU_LOG_FAILED() +#endif + +// TODO replace all TU_LOGn with TU_LOG(n) #ifndef TU_LOG1 #define TU_LOG1(...) #define TU_LOG1_MEM(...) @@ -395,5 +402,3 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3 #endif #endif /* _TUSB_COMMON_H_ */ - -/** @} */ From bef33d108a2f183227ccbc1f2027f354415a39fb Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Wed, 2 Jun 2021 08:32:21 -0500 Subject: [PATCH 41/47] move core definition of source file includes from SDK into family.cmake only build webserver example if lwip submodule initialized --- .../device/net_lwip_webserver/CMakeLists.txt | 136 +++++++++--------- hw/bsp/rp2040/family.cmake | 95 ++++++++++-- 2 files changed, 156 insertions(+), 75 deletions(-) diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index 63cca04a8..b8d769c4e 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -1,82 +1,84 @@ cmake_minimum_required(VERSION 3.5) -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +if (EXISTS ${TOP}/lib/lwip/src) + set(TOP "../../..") + get_filename_component(TOP "${TOP}" REALPATH) -include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) -# gets PROJECT name for the example (e.g. -) -family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + # gets PROJECT name for the example (e.g. -) + family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) -project(${PROJECT}) + project(${PROJECT}) -# Checks this example is valid for the family and initializes the project -family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + # Checks this example is valid for the family and initializes the project + family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) -add_executable(${PROJECT}) + add_executable(${PROJECT}) -# Example source -target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) + # Example source + target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) -# Example include -target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ${TOP}/lib/lwip/src/include - ${TOP}/lib/lwip/src/include/ipv4 - ${TOP}/lib/lwip/src/include/lwip/apps - ${TOP}/lib/networking - ) + # Example include + target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${TOP}/lib/lwip/src/include + ${TOP}/lib/lwip/src/include/ipv4 + ${TOP}/lib/lwip/src/include/lwip/apps + ${TOP}/lib/networking + ) -target_sources(${PROJECT} PUBLIC - ${TOP}/lib/lwip/src/core/altcp.c - ${TOP}/lib/lwip/src/core/altcp_alloc.c - ${TOP}/lib/lwip/src/core/altcp_tcp.c - ${TOP}/lib/lwip/src/core/def.c - ${TOP}/lib/lwip/src/core/dns.c - ${TOP}/lib/lwip/src/core/inet_chksum.c - ${TOP}/lib/lwip/src/core/init.c - ${TOP}/lib/lwip/src/core/ip.c - ${TOP}/lib/lwip/src/core/mem.c - ${TOP}/lib/lwip/src/core/memp.c - ${TOP}/lib/lwip/src/core/netif.c - ${TOP}/lib/lwip/src/core/pbuf.c - ${TOP}/lib/lwip/src/core/raw.c - ${TOP}/lib/lwip/src/core/stats.c - ${TOP}/lib/lwip/src/core/sys.c - ${TOP}/lib/lwip/src/core/tcp.c - ${TOP}/lib/lwip/src/core/tcp_in.c - ${TOP}/lib/lwip/src/core/tcp_out.c - ${TOP}/lib/lwip/src/core/timeouts.c - ${TOP}/lib/lwip/src/core/udp.c - ${TOP}/lib/lwip/src/core/ipv4/autoip.c - ${TOP}/lib/lwip/src/core/ipv4/dhcp.c - ${TOP}/lib/lwip/src/core/ipv4/etharp.c - ${TOP}/lib/lwip/src/core/ipv4/icmp.c - ${TOP}/lib/lwip/src/core/ipv4/igmp.c - ${TOP}/lib/lwip/src/core/ipv4/ip4.c - ${TOP}/lib/lwip/src/core/ipv4/ip4_addr.c - ${TOP}/lib/lwip/src/core/ipv4/ip4_frag.c - ${TOP}/lib/lwip/src/netif/ethernet.c - ${TOP}/lib/lwip/src/netif/slipif.c - ${TOP}/lib/lwip/src/apps/http/httpd.c - ${TOP}/lib/lwip/src/apps/http/fs.c - ${TOP}/lib/networking/dhserver.c - ${TOP}/lib/networking/dnserver.c - ${TOP}/lib/networking/rndis_reports.c - ) + target_sources(${PROJECT} PUBLIC + ${TOP}/lib/lwip/src/core/altcp.c + ${TOP}/lib/lwip/src/core/altcp_alloc.c + ${TOP}/lib/lwip/src/core/altcp_tcp.c + ${TOP}/lib/lwip/src/core/def.c + ${TOP}/lib/lwip/src/core/dns.c + ${TOP}/lib/lwip/src/core/inet_chksum.c + ${TOP}/lib/lwip/src/core/init.c + ${TOP}/lib/lwip/src/core/ip.c + ${TOP}/lib/lwip/src/core/mem.c + ${TOP}/lib/lwip/src/core/memp.c + ${TOP}/lib/lwip/src/core/netif.c + ${TOP}/lib/lwip/src/core/pbuf.c + ${TOP}/lib/lwip/src/core/raw.c + ${TOP}/lib/lwip/src/core/stats.c + ${TOP}/lib/lwip/src/core/sys.c + ${TOP}/lib/lwip/src/core/tcp.c + ${TOP}/lib/lwip/src/core/tcp_in.c + ${TOP}/lib/lwip/src/core/tcp_out.c + ${TOP}/lib/lwip/src/core/timeouts.c + ${TOP}/lib/lwip/src/core/udp.c + ${TOP}/lib/lwip/src/core/ipv4/autoip.c + ${TOP}/lib/lwip/src/core/ipv4/dhcp.c + ${TOP}/lib/lwip/src/core/ipv4/etharp.c + ${TOP}/lib/lwip/src/core/ipv4/icmp.c + ${TOP}/lib/lwip/src/core/ipv4/igmp.c + ${TOP}/lib/lwip/src/core/ipv4/ip4.c + ${TOP}/lib/lwip/src/core/ipv4/ip4_addr.c + ${TOP}/lib/lwip/src/core/ipv4/ip4_frag.c + ${TOP}/lib/lwip/src/netif/ethernet.c + ${TOP}/lib/lwip/src/netif/slipif.c + ${TOP}/lib/lwip/src/apps/http/httpd.c + ${TOP}/lib/lwip/src/apps/http/fs.c + ${TOP}/lib/networking/dhserver.c + ${TOP}/lib/networking/dnserver.c + ${TOP}/lib/networking/rndis_reports.c + ) -target_compile_definitions(${PROJECT} PUBLIC - PBUF_POOL_SIZE=2 - TCP_WND=2*TCP_MSS - HTTPD_USE_CUSTOM_FSDATA=0 -) + target_compile_definitions(${PROJECT} PUBLIC + PBUF_POOL_SIZE=2 + TCP_WND=2*TCP_MSS + HTTPD_USE_CUSTOM_FSDATA=0 + ) -# Configure compilation flags and libraries for the example... see the corresponding function -# in hw/bsp/FAMILY/family.cmake for details. -family_configure_device_example(${PROJECT}) + # Configure compilation flags and libraries for the example... see the corresponding function + # in hw/bsp/FAMILY/family.cmake for details. + family_configure_device_example(${PROJECT}) +endif() diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index e791648a9..e70cbd129 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -5,31 +5,110 @@ if (NOT TARGET _rp2040_family_inclusion_marker) # include basic family CMake functionality set(FAMILY_MCUS RP2040) + if (NOT BOARD) + message(FATAL_ERROR "BOARD must be specified") + endif() + # add the SDK in case we are standalone tinyusb example (noop if already present) include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake) include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) - # todo should we default to pico_sdk? - if (NOT BOARD) - message(FATAL_ERROR "BOARD must be specified") - endif() include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "${CMAKE_CURRENT_LIST_DIR}/../../..") get_filename_component(TOP "${TOP}" REALPATH) - if (NOT PICO_TINYUSB_PATH) - set(PICO_TINYUSB_PATH ${TOP}) + if (NOT TOP) + set(TOP ${TOP}) endif() - # tinyusb_additions will hold our extra settings libraries + # Base config for both device and host; wrapped by SDK's tinyusb_common + add_library(tinyusb_common_base INTERFACE) + + target_sources(tinyusb_common_base INTERFACE + ${TOP}/src/tusb.c + ${TOP}/src/common/tusb_fifo.c + ) + + target_include_directories(tinyusb_common_base INTERFACE + ${TOP}/src + ${TOP}/src/common + ${TOP}/hw + ) + + target_link_libraries(tinyusb_common_base INTERFACE + hardware_structs + hardware_irq + hardware_resets + pico_sync + ) + + set(TINYUSB_DEBUG_LEVEL 0) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + message("Compiling TinyUSB with CFG_TUSB_DEBUG=1") + set(TINYUSB_DEBUG_LEVEL 1) + endif () + + target_compile_definitions(tinyusb_common_base INTERFACE + CFG_TUSB_MCU=OPT_MCU_RP2040 + CFG_TUSB_OS=OPT_OS_PICO + CFG_TUSB_DEBUG=${TINYUSB_DEBUG_LEVEL} + ) + + # Base config for device mode; wrapped by SDK's tinyusb_device + add_library(tinyusb_device_base INTERFACE) + target_sources(tinyusb_device_base INTERFACE + ${TOP}/src/portable/raspberrypi/rp2040/dcd_rp2040.c + ${TOP}/src/portable/raspberrypi/rp2040/rp2040_usb.c + ${TOP}/src/device/usbd.c + ${TOP}/src/device/usbd_control.c + ${TOP}/src/class/audio/audio_device.c + ${TOP}/src/class/cdc/cdc_device.c + ${TOP}/src/class/dfu/dfu_device.c + ${TOP}/src/class/dfu/dfu_rt_device.c + ${TOP}/src/class/hid/hid_device.c + ${TOP}/src/class/midi/midi_device.c + ${TOP}/src/class/msc/msc_device.c + ${TOP}/src/class/net/net_device.c + ${TOP}/src/class/usbtmc/usbtmc_device.c + ${TOP}/src/class/vendor/vendor_device.c + ) + + + # Base config for host mode; wrapped by SDK's tinyusb_host + add_library(tinyusb_host_base INTERFACE) + target_sources(tinyusb_host_base INTERFACE + ${TOP}/src/portable/raspberrypi/rp2040/hcd_rp2040.c + ${TOP}/src/portable/raspberrypi/rp2040/rp2040_usb.c + ${TOP}/src/host/usbh.c + ${TOP}/src/host/usbh_control.c + ${TOP}/src/host/hub.c + ${TOP}/src/class/cdc/cdc_host.c + ${TOP}/src/class/hid/hid_host.c + ${TOP}/src/class/msc/msc_host.c + ${TOP}/src/class/vendor/vendor_host.c + ) + + # Sometimes have to do host specific actions in mostly + # common functions + target_compile_definitions(tinyusb_host_base INTERFACE + RP2040_USB_HOST_MODE=1 + ) + + add_library(tinyusb_bsp INTERFACE) + target_sources(tinyusb_bsp INTERFACE + ${TOP}/hw/bsp/rp2040/family.c + ) +# target_include_directories(tinyusb_bsp INTERFACE +# ${TOP}/hw/bsp/rp2040) + + # tinyusb_additions will hold our extra settings for examples add_library(tinyusb_additions INTERFACE) target_compile_definitions(tinyusb_additions INTERFACE PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1 - CFG_TUSB_MCU=OPT_MCU_RP2040 # this is already included in the SDK, but needed here for build_family.py grep ) if(DEFINED LOG) From 1fb211f3900d4ce27083930edf4d8a107c7d4610 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Wed, 2 Jun 2021 09:52:49 -0500 Subject: [PATCH 42/47] minor comment change to force rebuild --- hw/bsp/rp2040/family.cmake | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index e70cbd129..8c9b9ec1d 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 3.13) if (NOT TARGET _rp2040_family_inclusion_marker) add_library(_rp2040_family_inclusion_marker INTERFACE) - # include basic family CMake functionality - set(FAMILY_MCUS RP2040) - if (NOT BOARD) message(FATAL_ERROR "BOARD must be specified") endif() @@ -12,6 +9,8 @@ if (NOT TARGET _rp2040_family_inclusion_marker) # add the SDK in case we are standalone tinyusb example (noop if already present) include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake) + # include basic family CMake functionality + set(FAMILY_MCUS RP2040) include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) From de436e1f766c136edaec298d11c55edd937678fe Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Wed, 2 Jun 2021 11:30:42 -0500 Subject: [PATCH 43/47] undo search replace error --- hw/bsp/rp2040/family.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index 8c9b9ec1d..752eb0cab 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -19,8 +19,8 @@ if (NOT TARGET _rp2040_family_inclusion_marker) set(TOP "${CMAKE_CURRENT_LIST_DIR}/../../..") get_filename_component(TOP "${TOP}" REALPATH) - if (NOT TOP) - set(TOP ${TOP}) + if (NOT PICO_TINYUSB_PATH) + set(PICO_TINYUSB_PATH ${TOP}) endif() # Base config for both device and host; wrapped by SDK's tinyusb_common From fea5cbaf74a033d3f0c462b6bf2d334a67f6a732 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Wed, 2 Jun 2021 12:37:12 -0500 Subject: [PATCH 44/47] fixed net_lwip_webserver cmake build --- examples/device/net_lwip_webserver/CMakeLists.txt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index b8d769c4e..f1f79b2d1 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.5) -if (EXISTS ${TOP}/lib/lwip/src) - set(TOP "../../..") - get_filename_component(TOP "${TOP}" REALPATH) +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) +if (EXISTS ${TOP}/lib/lwip/src) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) # gets PROJECT name for the example (e.g. -) @@ -73,12 +73,9 @@ if (EXISTS ${TOP}/lib/lwip/src) PBUF_POOL_SIZE=2 TCP_WND=2*TCP_MSS HTTPD_USE_CUSTOM_FSDATA=0 - ) + ) # Configure compilation flags and libraries for the example... see the corresponding function # in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT}) -endif() - - - +endif() \ No newline at end of file From a50fd963f530278585418708c6032277c6307643 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 3 Jun 2021 01:13:22 +0700 Subject: [PATCH 45/47] increase version for release, update changelog --- docs/changelog.md | 12 ++++++++++++ src/tusb_option.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 323b6b6e2..3725c5a81 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,17 @@ # TinyUSB Changelog +## 0.10.1 - 2021.06.03 + +- rework rp2040 examples and CMake build, allow better integration with pico-sdk + +### Host Controller Driver (HCD) + +- Fix rp2040 host driver: incorrect PID with low speed device with max packet size of 8 bytes +- Improve hub driver +- Remove obsolete hcd_pipe_queue_xfer()/hcd_pipe_xfer() +- Use hcd_frame_number() instead of micro frame +- Fix OHCI endpoint address and xferred_bytes in xfer complete event + ## 0.10.0 - 2021.05.28 - Rework tu_fifo_t with separated mutex for read and write, better support DMA with read/write buffer info. And constant address mode diff --git a/src/tusb_option.h b/src/tusb_option.h index f8456ca4c..cdaf074db 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -29,7 +29,7 @@ #define TUSB_VERSION_MAJOR 0 #define TUSB_VERSION_MINOR 10 -#define TUSB_VERSION_REVISION 0 +#define TUSB_VERSION_REVISION 1 #define TUSB_VERSION_STRING TU_STRING(TUSB_VERSION_MAJOR) "." TU_STRING(TUSB_VERSION_MINOR) "." TU_STRING(TUSB_VERSION_REVISION) /** \defgroup group_mcu Supported MCU From d49938d0f5052bce70e55c652b657c0a6a7e84fe Mon Sep 17 00:00:00 2001 From: Ha Thach Date: Thu, 3 Jun 2021 01:16:27 +0700 Subject: [PATCH 46/47] change ci to pico-sdk develop --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 09236db65..529a77bb1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,7 +67,7 @@ jobs: - name: Checkout pico-sdk if: matrix.family == 'rp2040' run: | - git clone --depth 1 -b tinyusb-0.10.0 https://github.com/raspberrypi/pico-sdk ~/pico-sdk + git clone --depth 1 -b develop https://github.com/raspberrypi/pico-sdk ~/pico-sdk echo >> $GITHUB_ENV PICO_SDK_PATH=~/pico-sdk - name: Set Toolchain URL From c81bc38d422f419cd8949019fd5f2eadc9ec2333 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Thu, 3 Jun 2021 10:10:44 -0500 Subject: [PATCH 47/47] Add __unused to variables that are only used if TU_LOG does something --- src/portable/raspberrypi/rp2040/rp2040_usb.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.h b/src/portable/raspberrypi/rp2040/rp2040_usb.h index 32d20051f..33f3ecd41 100644 --- a/src/portable/raspberrypi/rp2040/rp2040_usb.h +++ b/src/portable/raspberrypi/rp2040/rp2040_usb.h @@ -134,11 +134,11 @@ typedef union TU_ATTR_PACKED TU_VERIFY_STATIC(sizeof(rp2040_buffer_control_t) == 2, "size is not correct"); -static inline void print_bufctrl16(uint32_t u16) +static inline void print_bufctrl16(uint32_t __unused u16) { - rp2040_buffer_control_t bufctrl; - - bufctrl.u16 = u16; + rp2040_buffer_control_t __unused bufctrl = { + .u16 = u16 + }; TU_LOG(2, "len = %u, available = %u, stall = %u, reset = %u, toggle = %u, last = %u, full = %u\r\n", bufctrl.xfer_len, bufctrl.available, bufctrl.stall, bufctrl.reset_bufsel, bufctrl.data_toggle, bufctrl.last_buf, bufctrl.full);