mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-14 04:18:56 +00:00
Merge pull request #294 from hathach/fix-rndis-zlp
Fix zlp for nrf52840
This commit is contained in:
commit
e764421164
@ -25,7 +25,8 @@ LDFLAGS += -L$(TOP)/hw/mcu/nordic/nrfx/mdk
|
||||
|
||||
SRC_C += \
|
||||
hw/mcu/nordic/nrfx/drivers/src/nrfx_power.c \
|
||||
hw/mcu/nordic/nrfx/mdk/system_nrf52840.c \
|
||||
hw/mcu/nordic/nrfx/drivers/src/nrfx_uarte.c \
|
||||
hw/mcu/nordic/nrfx/mdk/system_nrf52840.c
|
||||
|
||||
INC += \
|
||||
$(TOP)/hw/mcu/nordic/cmsis/Include \
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "nrfx.h"
|
||||
#include "nrfx/hal/nrf_gpio.h"
|
||||
#include "nrfx/drivers/include/nrfx_power.h"
|
||||
#include "nrfx/drivers/include/nrfx_uarte.h"
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#include "nrf_sdm.h"
|
||||
@ -45,12 +46,20 @@
|
||||
|
||||
#define BUTTON_PIN _PINNUM(1, 02)
|
||||
|
||||
#define UART_RX_PIN 24
|
||||
#define UART_TX_PIN 25
|
||||
|
||||
static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(0);
|
||||
|
||||
// tinyusb function that handles power event (detected, ready, removed)
|
||||
// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.
|
||||
extern void tusb_hal_nrf_power_event(uint32_t event);
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
// stop LF clock just in case we jump from application without reset
|
||||
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
|
||||
|
||||
// Config clock source: XTAL or RC in sdk_config.h
|
||||
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
|
||||
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
|
||||
@ -67,6 +76,24 @@ void board_init(void)
|
||||
SysTick_Config(SystemCoreClock/1000);
|
||||
#endif
|
||||
|
||||
// UART
|
||||
nrfx_uarte_config_t uart_cfg =
|
||||
{
|
||||
.pseltxd = UART_TX_PIN,
|
||||
.pselrxd = UART_RX_PIN,
|
||||
.pselcts = NRF_UARTE_PSEL_DISCONNECTED,
|
||||
.pselrts = NRF_UARTE_PSEL_DISCONNECTED,
|
||||
.p_context = NULL,
|
||||
.baudrate = NRF_UARTE_BAUDRATE_115200, // CFG_BOARD_UART_BAUDRATE
|
||||
.interrupt_priority = 7,
|
||||
.hal_cfg = {
|
||||
.hwfc = NRF_UARTE_HWFC_DISABLED,
|
||||
.parity = NRF_UARTE_PARITY_EXCLUDED,
|
||||
}
|
||||
};
|
||||
|
||||
nrfx_uarte_init(&_uart_id, &uart_cfg, NULL); //uart_handler);
|
||||
|
||||
#if TUSB_OPT_DEVICE_ENABLED
|
||||
// Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice
|
||||
// 2 is highest for application
|
||||
@ -127,12 +154,12 @@ int board_uart_read(uint8_t* buf, int len)
|
||||
{
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
// return NRFX_SUCCESS == nrfx_uart_rx(&_uart_id, buf, (size_t) len) ? len : 0;
|
||||
}
|
||||
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
return (NRFX_SUCCESS == nrfx_uarte_tx(&_uart_id, (uint8_t const*) buf, (size_t) len)) ? len : 0;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
@ -26,7 +26,7 @@ LDFLAGS += -L$(TOP)/hw/mcu/nordic/nrfx/mdk
|
||||
SRC_C += \
|
||||
hw/mcu/nordic/nrfx/drivers/src/nrfx_power.c \
|
||||
hw/mcu/nordic/nrfx/drivers/src/nrfx_uarte.c \
|
||||
hw/mcu/nordic/nrfx/mdk/system_nrf52840.c \
|
||||
hw/mcu/nordic/nrfx/mdk/system_nrf52840.c
|
||||
|
||||
INC += \
|
||||
$(TOP)/hw/mcu/nordic/cmsis/Include \
|
||||
|
@ -264,6 +264,9 @@ static char const* const _usbd_driver_str[USBD_CLASS_DRIVER_COUNT] =
|
||||
#if CFG_TUD_USBTMC
|
||||
"USBTMC"
|
||||
#endif
|
||||
#if CFG_TUD_NET
|
||||
"NET"
|
||||
#endif
|
||||
};
|
||||
|
||||
static char const* const _tusb_std_request_str[] =
|
||||
|
@ -96,6 +96,8 @@ static bool _data_stage_xact(uint8_t rhport)
|
||||
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);
|
||||
|
||||
return dcd_edpt_xfer(rhport, ep_addr, xact_len ? _usbd_ctrl_buf : NULL, xact_len);
|
||||
}
|
||||
|
||||
@ -110,10 +112,10 @@ bool tud_control_xfer(uint8_t rhport, tusb_control_request_t const * request, vo
|
||||
{
|
||||
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);
|
||||
|
||||
// Data stage
|
||||
TU_ASSERT( _data_stage_xact(rhport) );
|
||||
|
||||
TU_LOG2(" XFER Endpoint: 0x%02X, Bytes: %d\n", request->bmRequestType_bit.direction ? EDPT_CTRL_IN : EDPT_CTRL_OUT, _ctrl_xfer.data_len);
|
||||
}else
|
||||
{
|
||||
// Status stage
|
||||
|
@ -276,8 +276,10 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
xfer->total_len = total_bytes;
|
||||
xfer->actual_len = 0;
|
||||
|
||||
// Control endpoint with zero-length packet --> status stage
|
||||
if ( epnum == 0 && total_bytes == 0 )
|
||||
// Control endpoint with zero-length packet and opposite direction to 1st request byte --> status stage
|
||||
bool const control_status = (epnum == 0 && total_bytes == 0 && dir != tu_edpt_dir(NRF_USBD->BMREQUESTTYPE));
|
||||
|
||||
if ( control_status )
|
||||
{
|
||||
// Status Phase also require Easy DMA has to be free as well !!!!
|
||||
edpt_dma_start(&NRF_USBD->TASKS_EP0STATUS);
|
||||
|
@ -323,29 +323,27 @@ void dcd_remote_wakeup(uint8_t rhport)
|
||||
remoteWakeCountdown = 4u; // required to be 1 to 15 ms, ESOF should trigger every 1ms.
|
||||
}
|
||||
|
||||
// I'm getting a weird warning about missing braces here that I don't
|
||||
// know how to fix.
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 7)
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wmissing-braces"
|
||||
#endif
|
||||
static const tusb_desc_endpoint_t ep0OUT_desc =
|
||||
{
|
||||
.wMaxPacketSize = CFG_TUD_ENDPOINT0_SIZE,
|
||||
.bDescriptorType = TUSB_XFER_CONTROL,
|
||||
.bEndpointAddress = 0x00
|
||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||
|
||||
.bEndpointAddress = 0x00,
|
||||
.bmAttributes = { .xfer = TUSB_XFER_CONTROL },
|
||||
.wMaxPacketSize = { .size = CFG_TUD_ENDPOINT0_SIZE },
|
||||
.bInterval = 0
|
||||
};
|
||||
|
||||
static const tusb_desc_endpoint_t ep0IN_desc =
|
||||
{
|
||||
.wMaxPacketSize = CFG_TUD_ENDPOINT0_SIZE,
|
||||
.bDescriptorType = TUSB_XFER_CONTROL,
|
||||
.bEndpointAddress = 0x80
|
||||
};
|
||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 7)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
.bEndpointAddress = 0x80,
|
||||
.bmAttributes = { .xfer = TUSB_XFER_CONTROL },
|
||||
.wMaxPacketSize = { .size = CFG_TUD_ENDPOINT0_SIZE },
|
||||
.bInterval = 0
|
||||
};
|
||||
|
||||
static void dcd_handle_bus_reset(void)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user