Merge branch 'master' into develop

This commit is contained in:
hathach
2020-03-17 10:24:37 +07:00
9 changed files with 38 additions and 18 deletions

View File

@@ -42,7 +42,7 @@ enum {
BLINK_UNPRESSED = 1000 BLINK_UNPRESSED = 1000
}; };
#define HELLO_STR "Hello from TinyUSB\n" #define HELLO_STR "Hello from TinyUSB\r\n"
int main(void) int main(void)
{ {

View File

@@ -39,7 +39,7 @@
#error CFG_TUSB_MCU must be defined #error CFG_TUSB_MCU must be defined
#endif #endif
#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX #if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || CFG_TUSB_MCU == OPT_MCU_NUC505
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED) #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED)
#else #else
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE

View File

@@ -335,12 +335,12 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request
switch ( request->bRequest ) switch ( request->bRequest )
{ {
case CDC_REQUEST_SET_LINE_CODING: case CDC_REQUEST_SET_LINE_CODING:
TU_LOG2(" Set Line Coding\n"); TU_LOG2(" Set Line Coding\r\n");
tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t)); tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
break; break;
case CDC_REQUEST_GET_LINE_CODING: case CDC_REQUEST_GET_LINE_CODING:
TU_LOG2(" Get Line Coding\n"); TU_LOG2(" Get Line Coding\r\n");
tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t)); tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
break; break;
@@ -356,7 +356,7 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request
p_cdc->line_state = (uint8_t) request->wValue; p_cdc->line_state = (uint8_t) request->wValue;
TU_LOG2(" Set Control Line State: DTR = %d, RTS = %d\n", dtr, rts); TU_LOG2(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
tud_control_status(rhport, request); tud_control_status(rhport, request);

View File

@@ -407,7 +407,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
TU_ASSERT( event == XFER_RESULT_SUCCESS && TU_ASSERT( event == XFER_RESULT_SUCCESS &&
xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE ); xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE );
TU_LOG2(" SCSI Command: %s\n", lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0])); TU_LOG2(" SCSI Command: %s\r\n", lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0]));
// TU_LOG2_MEM(p_cbw, xferred_bytes, 2); // TU_LOG2_MEM(p_cbw, xferred_bytes, 2);
p_csw->signature = MSC_CSW_SIGNATURE; p_csw->signature = MSC_CSW_SIGNATURE;
@@ -480,7 +480,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
break; break;
case MSC_STAGE_DATA: case MSC_STAGE_DATA:
TU_LOG2(" SCSI Data\n"); TU_LOG2(" SCSI Data\r\n");
//TU_LOG2_MEM(_mscd_buf, xferred_bytes, 2); //TU_LOG2_MEM(_mscd_buf, xferred_bytes, 2);
// OUT transfer, invoke callback if needed // OUT transfer, invoke callback if needed
@@ -577,7 +577,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
// Wait for the Status phase to complete // Wait for the Status phase to complete
if( (ep_addr == p_msc->ep_in) && (xferred_bytes == sizeof(msc_csw_t)) ) if( (ep_addr == p_msc->ep_in) && (xferred_bytes == sizeof(msc_csw_t)) )
{ {
TU_LOG2(" SCSI Status: %u\n", p_csw->status); TU_LOG2(" SCSI Status: %u\r\n", p_csw->status);
// TU_LOG2_MEM(p_csw, xferred_bytes, 2); // TU_LOG2_MEM(p_csw, xferred_bytes, 2);
// Move to default CMD stage // Move to default CMD stage

View File

@@ -64,7 +64,7 @@ CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t received[CFG_TUD_NET_PACK
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t transmitted[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN]; CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t transmitted[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
#if CFG_TUD_NET == OPT_NET_RNDIS #if CFG_TUD_NET == OPT_NET_RNDIS
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t rndis_buf[128]; CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t rndis_buf[120];
#endif #endif
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@@ -198,7 +198,17 @@ bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request
TU_VERIFY (_netd_itf.itf_num == request->wIndex); TU_VERIFY (_netd_itf.itf_num == request->wIndex);
#if CFG_TUD_NET == OPT_NET_RNDIS #if CFG_TUD_NET == OPT_NET_RNDIS
tud_control_xfer(rhport, request, rndis_buf, sizeof(rndis_buf)); if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
{
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *)rndis_buf;
uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
TU_ASSERT(msglen <= sizeof(rndis_buf));
tud_control_xfer(rhport, request, rndis_buf, msglen);
}
else
{
tud_control_xfer(rhport, request, rndis_buf, sizeof(rndis_buf));
}
#else #else
(void)rhport; (void)rhport;
#endif #endif

View File

@@ -222,7 +222,7 @@ void tu_print_mem(void const *buf, uint16_t count, uint8_t indent);
// Log with debug level 1 // Log with debug level 1
#define TU_LOG1 tu_printf #define TU_LOG1 tu_printf
#define TU_LOG1_MEM tu_print_mem #define TU_LOG1_MEM tu_print_mem
#define TU_LOG1_LOCATION() tu_printf("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__) #define TU_LOG1_LOCATION() tu_printf("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__)
// Log with debug level 2 // Log with debug level 2
#if CFG_TUSB_DEBUG > 1 #if CFG_TUSB_DEBUG > 1

View File

@@ -76,8 +76,8 @@
#if CFG_TUSB_DEBUG #if CFG_TUSB_DEBUG
#include <stdio.h> #include <stdio.h>
#define _MESS_ERR(_err) printf("%s %d: failed, error = %s\n", __func__, __LINE__, tusb_strerr[_err]) #define _MESS_ERR(_err) printf("%s %d: failed, error = %s\r\n", __func__, __LINE__, tusb_strerr[_err])
#define _MESS_FAILED() printf("%s %d: assert failed\n", __func__, __LINE__) #define _MESS_FAILED() printf("%s %d: assert failed\r\n", __func__, __LINE__)
#else #else
#define _MESS_ERR(_err) #define _MESS_ERR(_err)
#define _MESS_FAILED() #define _MESS_FAILED()

View File

@@ -63,7 +63,7 @@ static inline bool _status_stage_xact(uint8_t rhport, tusb_control_request_t con
// Opposite to endpoint in Data Phase // Opposite to endpoint in Data Phase
uint8_t const ep_addr = request->bmRequestType_bit.direction ? EDPT_CTRL_OUT : EDPT_CTRL_IN; uint8_t const ep_addr = request->bmRequestType_bit.direction ? EDPT_CTRL_OUT : EDPT_CTRL_IN;
TU_LOG2(" XFER Endpoint: 0x%02X, Bytes: %d\n", ep_addr, 0); TU_LOG2(" XFER Endpoint: 0x%02X, Bytes: %d\r\n", ep_addr, 0);
// status direction is reversed to one in the setup packet // status direction is reversed to one in the setup packet
// Note: Status must always be DATA1 // Note: Status must always be DATA1
@@ -96,7 +96,7 @@ static bool _data_stage_xact(uint8_t rhport)
if ( xact_len ) memcpy(_usbd_ctrl_buf, _ctrl_xfer.buffer, xact_len); if ( xact_len ) memcpy(_usbd_ctrl_buf, _ctrl_xfer.buffer, xact_len);
} }
TU_LOG2(" XACT Control: 0x%02X, Bytes: %d\n", ep_addr, xact_len); TU_LOG2(" XACT Control: 0x%02X, Bytes: %d\r\n", ep_addr, xact_len);
return dcd_edpt_xfer(rhport, ep_addr, xact_len ? _usbd_ctrl_buf : NULL, xact_len); return dcd_edpt_xfer(rhport, ep_addr, xact_len ? _usbd_ctrl_buf : NULL, xact_len);
} }
@@ -112,7 +112,7 @@ bool tud_control_xfer(uint8_t rhport, tusb_control_request_t const * request, vo
{ {
TU_ASSERT(buffer); TU_ASSERT(buffer);
TU_LOG2(" XFER Endpoint: 0x%02X, Bytes: %d\n", request->bmRequestType_bit.direction ? EDPT_CTRL_IN : EDPT_CTRL_OUT, _ctrl_xfer.data_len); TU_LOG2(" XFER Endpoint: 0x%02X, Bytes: %d\r\n", request->bmRequestType_bit.direction ? EDPT_CTRL_IN : EDPT_CTRL_OUT, _ctrl_xfer.data_len);
// Data stage // Data stage
TU_ASSERT( _data_stage_xact(rhport) ); TU_ASSERT( _data_stage_xact(rhport) );

View File

@@ -33,6 +33,12 @@
nomenclature of EPA through EPL. nomenclature of EPA through EPL.
*/ */
/*
Note on OPT_MCU_NUC505_USB_DMA: the author suggests against using this option.
The DMA functionality of the USBD peripheral does not appear to succeed with
transfer lengths that are longer (> 64 bytes) and are not a multiple of 4.
*/
#include "tusb_option.h" #include "tusb_option.h"
#if TUSB_OPT_DEVICE_ENABLED && (CFG_TUSB_MCU == OPT_MCU_NUC505) #if TUSB_OPT_DEVICE_ENABLED && (CFG_TUSB_MCU == OPT_MCU_NUC505)
@@ -211,6 +217,7 @@ static void bus_reset(void)
current_dma_xfer = NULL; current_dma_xfer = NULL;
} }
#ifdef OPT_MCU_NUC505_USB_DMA
/* this must only be called by the ISR; it does its best to share the single DMA engine across all user EPs (IN and OUT) */ /* this must only be called by the ISR; it does its best to share the single DMA engine across all user EPs (IN and OUT) */
static void service_dma(void) static void service_dma(void)
{ {
@@ -243,6 +250,7 @@ static void service_dma(void)
return; return;
} }
} }
#endif
/* centralized location for USBD interrupt enable bit masks */ /* centralized location for USBD interrupt enable bit masks */
static const uint32_t enabled_irqs = USBD_GINTEN_USBIEN_Msk | \ static const uint32_t enabled_irqs = USBD_GINTEN_USBIEN_Msk | \
@@ -366,7 +374,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
for (int count = 0; count < total_bytes; count++) for (int count = 0; count < total_bytes; count++)
*buffer++ = USBD->CEPDAT_BYTE; *buffer++ = USBD->CEPDAT_BYTE;
usb_control_send_zlp(); dcd_event_xfer_complete(0, ep_addr, total_bytes, XFER_RESULT_SUCCESS, true);
} }
} }
else else
@@ -465,6 +473,7 @@ void USBD_IRQHandler(void)
if (bus_state & USBD_BUSINTSTS_DMADONEIF_Msk) if (bus_state & USBD_BUSINTSTS_DMADONEIF_Msk)
{ {
#ifdef OPT_MCU_NUC505_USB_DMA
if (current_dma_xfer) if (current_dma_xfer)
{ {
current_dma_xfer->dma_requested = false; current_dma_xfer->dma_requested = false;
@@ -480,6 +489,7 @@ void USBD_IRQHandler(void)
current_dma_xfer = NULL; current_dma_xfer = NULL;
service_dma(); service_dma();
} }
#endif
} }
if (bus_state & USBD_BUSINTSTS_VBUSDETIF_Msk) if (bus_state & USBD_BUSINTSTS_VBUSDETIF_Msk)
@@ -597,7 +607,7 @@ void USBD_IRQHandler(void)
if (out_ep) if (out_ep)
{ {
#if 1 #ifdef OPT_MCU_NUC505_USB_DMA
xfer->dma_requested = true; xfer->dma_requested = true;
service_dma(); service_dma();
#else #else