nrf52 finish usbd startup, able to got setup packet

This commit is contained in:
hathach 2018-03-14 15:21:47 +07:00
parent b33e89ac66
commit fc82ab3c97
4 changed files with 3077 additions and 50 deletions

View File

@ -82,6 +82,8 @@
<folder Name="nrf52">
<folder Name="tusb_port">
<file file_name="../../../../hw/mcu/nordic/nrf52/tusb_port/hal_nrf52.c" />
<file file_name="../../../../hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.c" />
<file file_name="../../../../hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.h" />
</folder>
<folder
Name="sdk"

View File

@ -1,7 +1,12 @@
<!DOCTYPE CrossStudio_Session_File>
<session>
<Bookmarks/>
<Breakpoints groups="Breakpoints" active_group="Breakpoints"/>
<Breakpoints groups="Breakpoints" active_group="Breakpoints">
<BreakpointListItem trigger="" line="253" counter="0" hardwareBreakpoint="" isFunctionBreakpoint="false" action="" expression="" group="Breakpoints" type="Breakpoint" state="2" filename="../../../../hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.c" useHWbreakpoint="false"/>
<BreakpointListItem trigger="" line="286" counter="0" hardwareBreakpoint="" isFunctionBreakpoint="false" action="" expression="" group="Breakpoints" type="Breakpoint" state="4" filename="../../../../hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.c" useHWbreakpoint="false"/>
<BreakpointListItem trigger="" line="354" counter="0" hardwareBreakpoint="" isFunctionBreakpoint="false" action="" expression="" group="Breakpoints" type="Breakpoint" state="2" filename="../../../../hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.c" useHWbreakpoint="false"/>
<BreakpointListItem trigger="" line="67" counter="0" hardwareBreakpoint="" isFunctionBreakpoint="false" action="" expression="" group="Breakpoints" type="Breakpoint" state="2" filename="../../../../hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.c" useHWbreakpoint="false"/>
</Breakpoints>
<ExecutionProfileWindow/>
<FrameBufferWindow>
<FrameBufferWindow bufferHeight="-1" addressSpace="" addressText="" bufferWidth="-1"/>
@ -25,7 +30,24 @@
<Project>
<ProjectSessionItem path="nrf52840"/>
<ProjectSessionItem path="nrf52840;nrf52840"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu;nordic"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu;nordic;nrf52"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu;nordic;nrf52;sdk"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu;nordic;nrf52;sdk;drivers_nrf"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu;nordic;nrf52;sdk;drivers_nrf;clock"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu;nordic;nrf52;sdk;drivers_nrf;hal"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu;nordic;nrf52;sdk;drivers_nrf;usbd"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu;nordic;nrf52;sdk;softdevice"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu;nordic;nrf52;sdk;softdevice;common"/>
<ProjectSessionItem path="nrf52840;nrf52840;hw;mcu;nordic;nrf52;tusb_port"/>
<ProjectSessionItem path="nrf52840;nrf52840;src"/>
<ProjectSessionItem path="nrf52840;nrf52840;System Files"/>
<ProjectSessionItem path="nrf52840;nrf52840;tinyusb"/>
<ProjectSessionItem path="nrf52840;nrf52840;tinyusb;class"/>
<ProjectSessionItem path="nrf52840;nrf52840;tinyusb;class;cdc"/>
<ProjectSessionItem path="nrf52840;nrf52840;tinyusb;device"/>
</Project>
<Register1>
<RegisterWindow visibleNodes="CPU - Current Context/r0;CPU - Current Context/r1;CPU - Current Context/r2;CPU - Current Context/r3;CPU - Current Context/r4;CPU - Current Context/r5;CPU - Current Context/r6;CPU - Current Context/r7;CPU - Current Context/r8;CPU - Current Context/r9;CPU - Current Context/r10;CPU - Current Context/r11;CPU - Current Context/r12;CPU - Current Context/sp(r13);CPU - Current Context/lr(r14);CPU - Current Context/pc(r15);CPU - Current Context/apsr;CPU/r0;CPU/r1;CPU/r2;CPU/r3;CPU/r4;CPU/r5;CPU/r6;CPU/r7;CPU/r8;CPU/r9;CPU/r10;CPU/r11;CPU/r12;CPU/sp(r13);CPU/lr(r14);CPU/pc(r15);CPU/xpsr;CPU/msp;CPU/psp;CPU/cfbp" binaryNodes="" asciiNodes="" openNodes="CPU - Current Context" name="device_virtual_com" decimalNodes="" octalNodes="" unsignedNodes=""/>
@ -61,10 +83,16 @@
<Files>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="59" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../hw/bsp/pca10056/board_pca10056.c" debugPath="../../../../hw/bsp/pca10056/board_pca10056.c" selected="0" top="54" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="290" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../hw/mcu/nordic/nrf52/sdk/sdk_config.h" debugPath="../../../../hw/mcu/nordic/nrf52/sdk/sdk_config.h" selected="0" top="281" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="18" y="62" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../hw/mcu/nordic/nrf52/hal/hal_nrf52.c" debugPath="../../../../hw/mcu/nordic/nrf52/hal/hal_nrf52.c" selected="0" top="67" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="19" y="63" useTextEdit="1" useBinaryEdit="0" left="0" path="../src/main.c" debugPath="../src/main.c" selected="0" top="56" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="3" y="38" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../hw/mcu/nordic/nrf52/sdk/softdevice/common/nrf_sdh_freertos.c" debugPath="../../../../hw/mcu/nordic/nrf52/sdk/softdevice/common/nrf_sdh_freertos.c" selected="0" top="10" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="28" y="16" useTextEdit="1" useBinaryEdit="0" left="0" path="../src/tusb_descriptors.c" debugPath="../src/tusb_descriptors.c" selected="1" top="0" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="61" useTextEdit="1" useBinaryEdit="0" left="0" path="../src/main.c" debugPath="../src/main.c" selected="0" top="56" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="16" useTextEdit="1" useBinaryEdit="0" left="0" path="../src/tusb_descriptors.c" debugPath="../src/tusb_descriptors.c" selected="0" top="0" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="142" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../tinyusb/class/cdc/cdc_device.c" debugPath="../../../../tinyusb/class/cdc/cdc_device.c" selected="0" top="123" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="31" y="254" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.c" debugPath="../../../../hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.c" selected="0" top="60" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="141" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../hw/mcu/nordic/nrf52/sdk/drivers_nrf/usbd/nrf_drv_usbd_errata.h" debugPath="../../../../hw/mcu/nordic/nrf52/sdk/drivers_nrf/usbd/nrf_drv_usbd_errata.h" selected="0" top="141" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="373" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../hw/mcu/nordic/nrf52/sdk/drivers_nrf/hal/nrf_clock.h" debugPath="../../../../hw/mcu/nordic/nrf52/sdk/drivers_nrf/hal/nrf_clock.h" selected="0" top="352" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="369" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../hw/mcu/nordic/nrf52/sdk/drivers_nrf/clock/nrf_drv_clock.c" debugPath="../../../../hw/mcu/nordic/nrf52/sdk/drivers_nrf/clock/nrf_drv_clock.c" selected="0" top="348" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="39" useTextEdit="1" useBinaryEdit="0" left="0" path="ses_nrf52840_Vectors.s" debugPath="ses_nrf52840_Vectors.s" selected="0" top="18" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="3" y="23" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../hw/mcu/nordic/nrf52/sdk/softdevice/common/nrf_sdh_freertos.c" debugPath="../../../../hw/mcu/nordic/nrf52/sdk/softdevice/common/nrf_sdh_freertos.c" selected="0" top="10" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="1516" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../hw/mcu/nordic/nrf52/sdk/drivers_nrf/usbd/nrf_drv_usbd.c" debugPath="../../../../hw/mcu/nordic/nrf52/sdk/drivers_nrf/usbd/nrf_drv_usbd.c" selected="1" top="1483" codecName="Default"/>
</Files>
<ARMCrossStudioWindow activeProject="nrf52840" fileDialogDefaultFilter="*.c" autoConnectTarget="J-Link" buildConfiguration="Debug" debugSearchFileMap="" fileDialogInitialDirectory="/home/hathach/Dropbox/tinyusb/workspace/tinyusb/hw/mcu/nordic/nrf52/hal" debugSearchPath="" autoConnectCapabilities="3711"/>
<ARMCrossStudioWindow activeProject="nrf52840" fileDialogDefaultFilter="*.c" autoConnectTarget="J-Link" buildConfiguration="Debug" debugSearchFileMap="" fileDialogInitialDirectory="/home/hathach/Dropbox/tinyusb/workspace/tinyusb/hw/mcu/nordic/nrf52/tusb_port" debugSearchPath="" autoConnectCapabilities="3199"/>
</session>

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,10 @@
#include "nrf_power.h"
#include "nrf_usbd.h"
#include "nrf_drv_power.h"
#include "nrf_drv_clock.h"
#include "nrf_drv_usbd_errata.h"
#include "tusb_dcd.h"
/*------------------------------------------------------------------*/
@ -54,7 +58,7 @@
*------------------------------------------------------------------*/
static void hfclk_ready(nrf_drv_clock_evt_type_t event)
{
// do nothing
}
static void enable_usb(void)
@ -73,68 +77,93 @@ static void enable_usb(void)
nrf_drv_clock_hfclk_request(&clock_handler_item);
/* Waiting for peripheral to enable, this should take a few us */
while ( 0 == (NRF_USBD_EVENTCAUSE_READY_MASK & nrf_usbd_eventcause_get()) ) { }
while ( !(NRF_USBD_EVENTCAUSE_READY_MASK & NRF_USBD->EVENTCAUSE) ) { }
nrf_usbd_eventcause_clear(NRF_USBD_EVENTCAUSE_READY_MASK);
nrf_usbd_event_clear(NRF_USBD_EVENT_USBEVENT);
// Wait until power is ready
while (!nrf_power_usbregstatus_outrdy_get()) {}
// Wait until PHY is powered
while ( nrf_drv_clock_hfclk_is_running() ) {}
if ( nrf_drv_usbd_errata_166() )
{
*((volatile uint32_t *) (NRF_USBD_BASE + 0x800)) = 0x7E3;
*((volatile uint32_t *) (NRF_USBD_BASE + 0x804)) = 0x40;
__ISB();
__DSB();
}
nrf_usbd_isosplit_set(NRF_USBD_ISOSPLIT_Half);
// Enable interrupt
NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_STARTED_Msk |
USBD_INTEN_ENDEPIN0_Msk | USBD_INTEN_EP0DATADONE_Msk | USBD_INTEN_ENDEPOUT0_Msk | USBD_INTEN_EP0SETUP_Msk |
USBD_INTEN_USBEVENT_Msk | USBD_INTEN_EPDATA_Msk | USBD_INTEN_ACCESSFAULT_Msk;
//USBD_INTEN_SOF_Msk
// if (enable_sof || nrf_drv_usbd_errata_104())
// {
// ints_to_enable |= NRF_USBD_INT_SOF_MASK;
// }
// Enable interrupt
NVIC_ClearPendingIRQ(USBD_IRQn);
NVIC_EnableIRQ(USBD_IRQn);
// Enable pull up
nrf_usbd_pullup_enable();
}
static void power_usb_event_handler(nrf_drv_power_usb_evt_t event)
{
// 51.4 specs USBD start-up sequene
switch ( event )
{
case NRF_DRV_POWER_USB_EVT_DETECTED:
if ( !NRF_USBD->ENABLE )
{
enable_usb();
/* Prepare for READY event receiving */
nrf_usbd_eventcause_clear(NRF_USBD_EVENTCAUSE_READY_MASK);
/* Enable the peripheral */
nrf_usbd_enable();
// Enable HFCLK
nrf_drv_clock_handler_item_t clock_handler_item =
{
.event_handler = hfclk_ready
};
nrf_drv_clock_hfclk_request(&clock_handler_item);
/* Waiting for peripheral to enable, this should take a few us */
while ( !(NRF_USBD_EVENTCAUSE_READY_MASK & NRF_USBD->EVENTCAUSE) ) { }
nrf_usbd_eventcause_clear(NRF_USBD_EVENTCAUSE_READY_MASK);
nrf_usbd_event_clear(NRF_USBD_EVENT_USBEVENT);
}
break;
case NRF_DRV_POWER_USB_EVT_READY:
// Wait for HFCLK
while ( !nrf_drv_clock_hfclk_is_running() ) {}
if ( nrf_drv_usbd_errata_166() )
{
*((volatile uint32_t *) (NRF_USBD_BASE + 0x800)) = 0x7E3;
*((volatile uint32_t *) (NRF_USBD_BASE + 0x804)) = 0x40;
__ISB();
__DSB();
}
nrf_usbd_isosplit_set(NRF_USBD_ISOSPLIT_Half);
// Enable interrupt
NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_STARTED_Msk |
USBD_INTEN_ENDEPIN0_Msk | USBD_INTEN_EP0DATADONE_Msk | USBD_INTEN_ENDEPOUT0_Msk | USBD_INTEN_EP0SETUP_Msk |
USBD_INTEN_USBEVENT_Msk | USBD_INTEN_EPDATA_Msk | USBD_INTEN_ACCESSFAULT_Msk;
//USBD_INTEN_SOF_Msk
// if (enable_sof || nrf_drv_usbd_errata_104())
// {
// ints_to_enable |= NRF_USBD_INT_SOF_MASK;
// }
// Enable interrupt
NVIC_ClearPendingIRQ(USBD_IRQn);
NVIC_EnableIRQ(USBD_IRQn);
// Enable pull up
nrf_usbd_pullup_enable();
break;
case NRF_DRV_POWER_USB_EVT_REMOVED:
if ( NRF_USBD->ENABLE )
{
nrf_drv_usbd_stop();
// Abort all transfers
// Disable pull up
nrf_usbd_pullup_disable();
// Disable Interrupt
NVIC_DisableIRQ(USBD_IRQn);
// disable all interrupt
NRF_USBD->INTENCLR = NRF_USBD->INTEN;
NRF_USBD->INTENCLR = NRF_USBD->INTEN; // disable all interrupt
nrf_usbd_disable();
}
break;
case NRF_DRV_POWER_USB_EVT_READY:
break;
default: break;
}
}
@ -149,10 +178,83 @@ bool tusb_dcd_init (uint8_t port)
VERIFY( NRF_SUCCESS == nrf_drv_power_usbevt_init(&config) );
}
void tusb_dcd_connect (uint8_t port);
void tusb_dcd_disconnect (uint8_t port);
void tusb_dcd_set_address (uint8_t port, uint8_t dev_addr);
void tusb_dcd_set_config (uint8_t port, uint8_t config_num);
void tusb_dcd_connect (uint8_t port)
{
}
void tusb_dcd_disconnect (uint8_t port)
{
}
void tusb_dcd_set_address (uint8_t port, uint8_t dev_addr)
{
}
void tusb_dcd_set_config (uint8_t port, uint8_t config_num)
{
}
/*------------------------------------------------------------------*/
/* Control
*------------------------------------------------------------------*/
bool tusb_dcd_control_xfer (uint8_t port, tusb_dir_t dir, uint8_t * p_buffer, uint16_t length, bool int_on_complete)
{
return true;
}
void tusb_dcd_control_stall (uint8_t port)
{
}
/*------------------------------------------------------------------*/
/*
*------------------------------------------------------------------*/
bool tusb_dcd_edpt_open (uint8_t port, tusb_descriptor_endpoint_t const * p_endpoint_desc)
{
return true;
}
bool tusb_dcd_edpt_xfer (uint8_t port, uint8_t edpt_addr, uint8_t * buffer, uint16_t total_bytes, bool int_on_complete)
{
return true;
}
bool tusb_dcd_edpt_queue_xfer (uint8_t port, uint8_t edpt_addr, uint8_t * buffer, uint16_t total_bytes)
{
return true;
}
void tusb_dcd_edpt_stall (uint8_t port, uint8_t edpt_addr)
{
}
void tusb_dcd_edpt_clear_stall (uint8_t port, uint8_t edpt_addr)
{
}
// TODO may remove
bool tusb_dcd_edpt_busy (uint8_t port, uint8_t edpt_addr)
{
return true;
}
/*------------------------------------------------------------------*/
/*
*------------------------------------------------------------------*/
void bus_reset(void)
{
for(int i=0; i<8; i++)
{
NRF_USBD->TASKS_STARTEPIN[i] = 0;
NRF_USBD->TASKS_STARTEPOUT[i] = 0;
}
NRF_USBD->TASKS_STARTISOIN = 0;
NRF_USBD->TASKS_STARTISOOUT = 0;
}
void USBD_IRQHandler(void)
{
@ -268,8 +370,18 @@ void USBD_IRQHandler(void)
if ( int_status & USBD_INTEN_USBRESET_Msk )
{
bus_reset();
tusb_dcd_bus_event(0, USBD_BUS_EVENT_RESET);
}
if ( int_status & USBD_INTEN_EP0SETUP_Msk )
{
uint8_t setup[8] = {
NRF_USBD->BMREQUESTTYPE, NRF_USBD->BREQUEST, NRF_USBD->WVALUEL, NRF_USBD->WVALUEH,
NRF_USBD->WINDEXL, NRF_USBD->WINDEXH, NRF_USBD->WLENGTHL, NRF_USBD->WLENGTHH
};
tusb_dcd_setup_received(0, setup);
}
}