Skip to content

Commit 0f61412

Browse files
AGlass0fMilkArto Kinnunen
authored andcommitted
Removed unnecessary logic and changed round robin DMA scheduling
1 parent 42d31ab commit 0f61412

File tree

1 file changed

+10
-51
lines changed

1 file changed

+10
-51
lines changed

usb/device/targets/TARGET_NORDIC/TARGET_MCU_NRF52840/USBPhy_Nordic.cpp

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@
2121

2222
#include "nrf_clock.h"
2323

24-
/*
25-
* TODO list for nRF52840 USBD driver
26-
*
27-
* 1.) Properly enable/disable start-of-frame interrupt.
28-
*
29-
* Description: Currently, start-of-frame interrupts are masked by a flag at this layer
30-
* but still cause the processor to be interrupted for no purpose.
31-
*
32-
* The Nordic driver requires you to call nrf_drv_start(bool)
33-
* with a boolean flag indicating whether it should enable start-of-frame
34-
* interrupts or not. From the datasheet it seems to be possible to
35-
* enable/disable SoF interrupts on the fly, but the fact that they
36-
* force you to make the SoF decision during "start" makes me suspicious
37-
* the underlying driver may manage/use the SoF flag in other ways.
38-
*
39-
* Next steps: Investigate how the SoF flag is used during "nrf_drv_start" and
40-
* determine if enabling/disabling this interrupt would cause internal problems
41-
* with the Nordic USBD driver
42-
*
43-
*
44-
*/
4524
#define MAX_PACKET_SIZE_SETUP NRF_DRV_USBD_EPSIZE
4625
#define MAX_PACKET_NON_ISO NRF_DRV_USBD_EPSIZE
4726
#define MAX_PACKET_ISO NRF_DRV_USBD_ISOSIZE
@@ -67,19 +46,10 @@ void USBD_HAL_IRQHandler(void);
6746
static USBPhyHw *instance = 0;
6847

6948
static volatile bool virtual_status_xfer_event;
70-
static volatile bool irq_already_pending;
7149

7250
static void usbd_event_handler(nrf_drv_usbd_evt_t const * const p_event);
7351
static void power_usb_event_handler(nrf_drv_power_usb_evt_t event);
7452

75-
#if USBD_DEBUG
76-
77-
// Static array of saved events to track what happens
78-
static nrf_drv_usbd_evt_t debug_events[32];
79-
static uint8_t debug_evt_index = 0;
80-
81-
#endif
82-
8353
USBPhy *get_usb_phy() {
8454
static USBPhyHw usbphy;
8555
return &usbphy;
@@ -127,22 +97,15 @@ void USBPhyHw::init(USBPhyEvents *events) {
12797
instance = this;
12898

12999
virtual_status_xfer_event = false;
130-
irq_already_pending = false;
131100

132101
/*
133-
* TODO - Configure ISOIN endpoint to respond with ZLP when
102+
* Configure ISOIN endpoint to respond with ZLP when
134103
* no data is ready to be sent
135-
*
136-
* This is a feature available in the Nordic SDK15.2
137-
* For now we just configure the appropriate register on initialization
138104
*/
139105
NRF_USBD->ISOINCONFIG |= 0x01; // set RESPONSE to 1 (respond with ZLP)
140106

141107
// Enable IRQ
142-
//NVIC_SetVector(USBD_IRQn, (uint32_t)USBD_IRQHandler);
143108
NVIC_SetVector(USBD_IRQn, (uint32_t)USBD_HAL_IRQHandler);
144-
//NVIC_SetPriority(USBD_IRQn, 7);
145-
//NVIC_EnableIRQ(USBD_IRQn); // This is handled by the Nordic driver
146109
}
147110

148111
void USBPhyHw::deinit() {
@@ -214,6 +177,7 @@ void USBPhyHw::sof_enable() {
214177
// TODO - Enable SOF interrupt
215178
// Can this safely be done if
216179
// nrf_drv_usbd_start is called with SoF enabled?
180+
// For now just mask the interrupt with a boolean flag
217181
sof_enabled = true;
218182
}
219183

@@ -304,8 +268,6 @@ void USBPhyHw::ep0_read(uint8_t *data, uint32_t size) {
304268

305269
virtual_status_xfer_event = true;
306270

307-
irq_already_pending = NVIC_GetPendingIRQ(USBD_IRQn);
308-
309271
// Trigger an interrupt to process the virtual status event
310272
NVIC_SetPendingIRQ(USBD_IRQn);
311273

@@ -349,8 +311,6 @@ void USBPhyHw::ep0_write(uint8_t *buffer, uint32_t size) {
349311

350312
virtual_status_xfer_event = true;
351313

352-
irq_already_pending = NVIC_GetPendingIRQ(USBD_IRQn);
353-
354314
// Trigger an interrupt to process the virtual status event
355315
NVIC_SetPendingIRQ(USBD_IRQn);
356316

@@ -429,10 +389,7 @@ bool USBPhyHw::endpoint_write(usb_ep_t endpoint, uint8_t *data, uint32_t size) {
429389
}
430390

431391
void USBPhyHw::endpoint_abort(usb_ep_t endpoint) {
432-
nrf_drv_usbd_ep_t nrf_ep = get_nordic_endpoint(endpoint);
433-
// Don't call abort on ISO endpoints -- this will cause an ASSERT in the Nordic driver
434-
//if(nrf_ep != NRF_DRV_USBD_EPOUT8 && nrf_ep != NRF_DRV_USBD_EPIN8)
435-
nrf_drv_usbd_ep_abort(nrf_ep);
392+
nrf_drv_usbd_ep_abort(get_nordic_endpoint(endpoint));
436393
}
437394

438395
void USBPhyHw::process() {
@@ -604,7 +561,9 @@ void USBPhyHw::_reset(void)
604561

605562
usb_event_type = USB_HW_EVENT_NONE;
606563

607-
// TODO - Clear all endpoint interrupts?
564+
// Clear all endpoint interrupts
565+
NVIC_ClearPendingIRQ(USBD_IRQn);
566+
nrf_usbd_event_clear((nrf_usbd_event_t)0x01FFFFFF);
608567
}
609568

610569
void USBPhyHw::enable_usb_interrupts(void) {
@@ -643,15 +602,15 @@ void USBD_HAL_IRQHandler(void)
643602
if(virtual_status_xfer_event)
644603
{
645604
if(instance) {
605+
//if(!irq_already_pending)
606+
// return;
607+
608+
//irq_already_pending = false;
646609
instance->_usb_virtual_status_event_handler();
647610
}
648611

649612
virtual_status_xfer_event = false;
650613

651-
if(!irq_already_pending)
652-
return;
653-
654-
irq_already_pending = false;
655614
}
656615
// Call Nordic driver IRQ handler
657616
USBD_IRQHandler();

0 commit comments

Comments
 (0)