100 Commits

Author SHA1 Message Date
Ha Thach
983abfd6d8
Merge pull request #1279 from kasjer/kasjer/nrf5x-int-race
nrf5x: Fix EP OUT race conditions
2022-01-19 10:33:37 +07:00
Jerzy Kasenberg
f4725120a4 nrf5x: Request HFXO via OS
Mynewt (similar to Soft Device) has its own reference counting for
HFXO oscillator.
So far TinyUSB requested HFXO when VBUS was detected and stopped when
VBUS was removed.
But with Mynewt running HFXO can be stopped when other interested parties
don't require HFXO anymore. This results in very difficult to track
USB transmission errors.

This change enables Mynewt specific HFXO management in Soft Device fashion.
2022-01-18 08:12:49 +01:00
Jerzy Kasenberg
da44fe3fc9 nrf5x: Fix EP OUT race conditions
When dcd_edpt_xfer() starts new transfer two separate problems were observed.
For both problems stream of OUT packets was pouring from host.

First problem was that total_len and actual_len were not atomic.
In case where incoming OUT packets are less (63) than MPS (64), actual_len and total_len
are set 63.
Then transfer complete from USBD is called that will schedule next 64 bytes transfer.
At that point incoming packet would start DMA if there is place in RAM, normally
it does not happen since actual_len == total_len.
If packets arrives and interrupt is raised after total_len is set (64) but actual_len is still 63 from
previous transfer, interrupt code sees that there is place in ram (1 byte) and transfer this 1 byte
to buffer that was already filled with previous packet.
To remedy this USB interrupt is blocked during transfer setup.

Second problem can happen when dcd_edpt_xfer setups xfer->total_len and actual_len correctly
but then context switch happens before xfer->data_received is checked.
If during this time two packets arrive one will be copied to RAM second will stay in endpoint with
data_received set to 1.
Then when xfer_edpt_xfer() checks data_receive flag it starts DMA again overwriting data.
To remedy this, data_received is checked together with check if data was already transferred.
If transfer was complete, there is no need to start DMA yet.
In such case data_received will be handled in same place by next xfer_edpt_xfer() correctly.
2022-01-14 09:46:39 +01:00
Jerzy Kasenberg
21db2351fd nrf5x: Fix race condition during startup
When NRF5x device is reset by software (after DFU for example),
power event is ready from the beginning.
When power interrupt is triggered before tud_init() finished
USBD_IRQn is enabled before it would be enabled in tud_init().
This in turn may result in BUS RESET event being sent from
USB interrupt to USB task when queue is not initialized yet.
This scenario often happens in Mynewt build where queue creation
takes more time.

To prevent this scenario USBD_IRQn is not enabled in power event
interrupt handler before dcd_init() was called.
2021-12-08 08:27:27 +01:00
hathach
c9e9f4785f more clean up 2021-11-23 09:52:11 +07:00
hathach
0fc11746c0 clean up 2021-11-23 09:46:45 +07:00
hathach
a994540860 fix nrf easy dma race condition 2021-11-23 09:36:28 +07:00
hathach
5af989384b remove ep descriptor wMaxPacketSize bitfield due to endian issue 2021-10-24 13:11:21 +07:00
hathach
0b249618b0 fix -Wcast-qual 2021-10-15 23:54:31 +07:00
hathach
ad21b69277 fix nrf clear data toggle sequence when clearing stall 2021-08-29 12:05:34 +07:00
hathach
66c292e2ec fix a couple of nrf dcd issue
- limit out xact dma to prevent usbd overflow in certain situation after
stalled
- drained already acked data when stalling an OUT endpoint
2021-08-29 00:34:21 +07:00
hathach
8bad0af849 explicitly clear stall and data toggle for edpoint upon open() 2021-08-27 22:31:08 +07:00
hathach
81c73c235f implement dcd_edpt_close_all() for nrf52840 2021-08-27 22:30:30 +07:00
hathach
71e77e47fa
add dcd_edpt_close_all() for clear existing configured state
correctly responded to TD 9.13 Set Configuration Test
2021-08-26 17:07:03 +07:00
hathach
ab2eec77d4 complete suspend, resume, remote wakeup for nrf52 2021-08-16 20:22:14 +07:00
DuMaM
b5ce269675
GCC 11 build fix
During Adafruit Bootloader compilation, I spotted bellow error which do not allow me build project.

``` c
    inlined from 'hfclk_running' at lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c:785:13:
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c:792:31: error: 'is_running' may be used uninitialized [-Werror=maybe-uninitialized]
  792 |     return (is_running ? true : false);
      |            ~~~~~~~~~~~~~~~~~~~^~~~~~~~
```
2021-06-26 17:03:46 +02:00
hathach
6b621baeb3 fix race condition with control since TASKS_EP0RCVOUT also require EasyDMA 2021-06-19 01:58:27 +07:00
hathach
9233269a2c only apply errata walkaround for nrf52 2021-05-11 18:38:23 +07:00
Jerzy Kasenberg
e2f795067a Allow build for NRF5340 MCU
Errata code referred to NRF_USBD_BASE.
This definition is not present in NRF5340 but both NRF52 and NRF53
do have NRF_USBD which maps to NRF_USBD_BASE for NRF52 and
to NRF_USBD_S_BASE for NRF5340.
This just make build possible for NRF5340.
2021-05-11 12:37:08 +02:00
hathach
64f41dea62 fix race condition that could cause drop packet of Bulk OUT transfer
NRF_USBD->SIZE.EPOUT[epnum] only need to write once to enable
Bulk/Interrupt transfer. We only need to do it in dcd_edpt_open() and
dcd_edpt_clear_stall()
2021-03-18 15:07:07 +07:00
hathach
6e6e6265e4 use dcd_event_bus_reset() with speed to replace bus_signal 2021-01-08 22:34:36 +07:00
Jerzy Kasenberg
96da1ca4b8 nrf5x: Add support for ISO endpoints
ISO endpoints were not covered so far by the driver code.
This adds support for ISO IN and OUT endpoint handling.
Registers for ISO IN(OUT) endpoints are placed just after normal IN(OUT)
so in some cases common code could be used for handling all type of
transfers.
Generally code synchronizes ISO endpoint handling to SOF interrupt.
This code does not change the way of how non-ISO endpoints are treated.

Code uses strategy outlined in nRF52840 Produce Specification v1.0
sections 6.35.11.1 and 6.35.11.2.
2020-10-01 09:22:55 +02:00
Jerzy Kasenberg
6f5ee09511 nrf5x: Increase size of mps to 16 bits
msp stores max packet size.
For ISO endpoints 8 bits is not enough so it's changed to 16 bits.
2020-10-01 09:22:55 +02:00
Jerzy Kasenberg
fceb8853c7 nrf5x: Add dcd_edpt_close
Closing endpoints can be important when there are alternate
instances. This adds functionality of closing endpoints
similar to what exists in other drivers.
2020-10-01 09:22:55 +02:00
Jerzy Kasenberg
62a76c0e04 nrf52: Fix edpt_dma_start() wrong condition check
Operator < used in while condition was obviously incorrect.
Loop starts with checking if unsigned variable is less then 0.
This condition is always false.

This reverses condition to follow intention of of the code.
2020-09-15 16:08:23 +02:00
hathach
7d9efd0697 manually submit unplugged event for nrf dcd_disconnect() 2020-08-04 14:18:12 +07:00
hathach
9bf2b33366
correct isr context for nrf DCD_EVENT_UNPLUGGED
also rename debug lookup to prevent conflict
2020-08-01 12:02:59 +07:00
hathach
ff9994116e fix nrf hanged (blocking wait) when called within critical section 2020-05-21 21:22:12 +07:00
hathach
58b99e59d4 detect if SD is actually present on the flash using SD magic
even with SOFTDEVICE_PRESENT defined, SD may not be present on actual
flash.
2020-05-05 23:07:56 +07:00
hathach
6f9c256ad0
complete remove dcd_set_config(), fix unit test 2020-04-17 13:52:34 +07:00
hathach
50be9d7c3a
mass rename tud/dcd_irq_handler to tud/dcd_init_handler 2020-04-17 12:27:53 +07:00
Ha Thach
04a06ec401
Merge branch 'master' into refactor-irqhandler 2020-04-11 15:49:34 +07:00
hathach
c1f3fbbc03 implement dcd connect/disconnect for samd and nrf 2020-04-09 11:47:02 +07:00
hathach
4179334aca call tud_irq_handler() for all nrf5x board 2020-04-06 17:35:11 +07:00
hathach
c8247f0907 fix zlp for nrf52840 2020-03-08 14:20:28 +07:00
hathach
4008f0d1e6 update dcd nrf5x to be indepent from nrf_usbd.h
fix build error with nrfx 2.0
2019-11-11 00:01:12 +07:00
hathach
47cd08d526 clean up 2019-08-05 22:31:41 +07:00
hathach
d1df041519 nrf5x remove the depenedent on nrfx_power.h 2019-08-05 22:09:37 +07:00
hathach
d211035a0a merge dcd/hal_nrf5x.c into dcd/dcd_nrf5x.c 2019-08-05 21:54:20 +07:00
hathach
73d7ab201e
remove dcd_edpt_busy() 2019-06-10 22:29:18 +07:00
hathach
3e6d911ce9
more clean up use inline bit funciton instead of macros 2019-05-14 12:54:29 +07:00
hathach
61ec407752
update license year to 2019 2019-05-14 11:48:05 +07:00
hathach
77bc421359 fix clear stall usage, fix reset data toggle with dcd_clear_stall for nrf52 2019-05-09 23:31:18 +07:00
hathach
2050778763 clean up 2019-05-01 20:41:26 +07:00
hathach
64bed848d0 fix #53 use nrfx_usbd_errata.h 2019-04-08 17:36:12 +07:00
hathach
06e1fac7c5
nrf5x enable suspend after set address, instead of set config 2019-04-02 01:20:34 +07:00
hathach
2cc4ab2aef
nrf5x added LOWPOWER when suspend/resume 2019-03-31 23:57:38 +07:00
hathach
eabfc53f38
added tud_suspended() and tud_ready() 2019-03-30 23:01:23 +07:00
hathach
b28cc6ddb1 added dcd_remote_wakeup() stub for all ports 2019-03-30 14:47:11 +07:00
hathach
93a853cd5b usbd add connected, suspended, remote_wakeup
- remove use of osal_queue_reset
2019-03-30 02:26:15 +07:00