<feed xmlns='http://www.w3.org/2005/Atom'>
<title>tinyusb.git/src/portable/nordic, branch 0.14.0</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.</subtitle>
<id>http://cgit.235523.xyz/tinyusb.git/atom/src/portable/nordic?h=0.14.0</id>
<link rel='self' href='http://cgit.235523.xyz/tinyusb.git/atom/src/portable/nordic?h=0.14.0'/>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/'/>
<updated>2022-06-02T15:23:35Z</updated>
<entry>
<title>nrf5x: Fix DMA access</title>
<updated>2022-06-02T15:23:35Z</updated>
<author>
<name>Jerzy Kasenberg</name>
<email>jerzy.kasenberg@gmail.com</email>
</author>
<published>2022-06-01T19:50:15Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/commit/?id=8b37aa157911ff2cd470d090bb2e276ca57f5af4'/>
<id>urn:sha1:8b37aa157911ff2cd470d090bb2e276ca57f5af4</id>
<content type='text'>
There were two problems:
- dma_running flag could be checked in USB interrupt (not set yet) then higher priority
  interrupt could start transfer, check dma_running (not set yet) set it to true start
  DMA; then when USB interrupt continues it starts another DMA that is not allowed
- when DMA is started some registers can't be safely accessed, read can yield invalid
  values (SIZE.EPOUT, SIZE.EPISO)
  current implementation could start DMA for one OUT endpoint then check that another
  endpoint also has data and while DMA was not started right away, SIZE.EPOUT was copied
  already to MAXCNT register. Later on when DMA was started not all data was read from
  endpoint due to incorrect DMA size previously set.

To prevent both cases dma_running is changed in atomic way.
Only code that actually set this value to true starts DMA, code that tried and
had dma_running flag already set simply defers DMA start to USB task.
This eliminates also need to have mutex that was there to limit access to dma_running flag
to one task only.
transfer also now has started flag that is set only after dcd_edpt_xfer() sets up total_len
and actua_len. Previously USB interrupt was disabled when total_len and actual_len were
setup to prevent race condition when data arrived to ednpoint before transfer was setup
was finished.
</content>
</entry>
<entry>
<title>added dcd_sof_enable() stubs for all other ports</title>
<updated>2022-03-07T16:05:05Z</updated>
<author>
<name>hathach</name>
<email>thach@tinyusb.org</email>
</author>
<published>2022-03-07T16:05:05Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/commit/?id=606f932d92322a71960f51148ecc91eaf29bf507'/>
<id>urn:sha1:606f932d92322a71960f51148ecc91eaf29bf507</id>
<content type='text'>
</content>
</entry>
<entry>
<title>rename TUSB_OPT_DEVICE_ENABLED to CFG_TUD_ENABLED</title>
<updated>2022-02-25T11:35:21Z</updated>
<author>
<name>hathach</name>
<email>thach@tinyusb.org</email>
</author>
<published>2022-02-23T14:46:40Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/commit/?id=d10326cb4e0f48a05bc39c6f51b7b0fb29427cc9'/>
<id>urn:sha1:d10326cb4e0f48a05bc39c6f51b7b0fb29427cc9</id>
<content type='text'>
TUSB_OPT_DEVICE_ENABLED still usable for backward compatible
</content>
</entry>
<entry>
<title>nrf5x: Fix EP OUT race conditions in OS build</title>
<updated>2022-01-19T08:48:04Z</updated>
<author>
<name>Jerzy Kasenberg</name>
<email>jerzy.kasenberg@codecoup.pl</email>
</author>
<published>2022-01-14T08:44:38Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/commit/?id=36b6ed8ff9035ad0c2e75de92e08799dc3a4b7ed'/>
<id>urn:sha1:36b6ed8ff9035ad0c2e75de92e08799dc3a4b7ed</id>
<content type='text'>
When two tasks entered dcd_edpt_xfer() it was possible that
first disabled interrupt to setup total_len and actual_len
but second task for another endpoint enabled interrupt
between total_len and actual_len resulting in race
condition with interrupt, hence mutex is added on top of interrupt being blocked.
</content>
</entry>
<entry>
<title>nrf5x: Fix DMA access race condition</title>
<updated>2022-01-19T08:06:43Z</updated>
<author>
<name>Jerzy Kasenberg</name>
<email>jerzy.kasenberg@codecoup.pl</email>
</author>
<published>2022-01-14T08:14:49Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/commit/?id=980ffe3b4e41ce5e43c3e8ae13f605f7d7b50b7f'/>
<id>urn:sha1:980ffe3b4e41ce5e43c3e8ae13f605f7d7b50b7f</id>
<content type='text'>
In multi-thread mode starting DMA in thread mode was
prone to race condition resulting in infinite loop.
It may happen on single core CPU with strict priority based
tasks scheduler where ready high prio task never yields to
ready low prio task (Mynewt).

Sequence that failed (T1 - low priority task, T2 - high priority task)
- T1 called start_dma()
- T1 set _dcd.dma_running (DMA not started yet, context switch happens)
- T2 took CPU and saw that _dcd.dma_running is set, so waits for _dcd.dma_running to be 0
- T1 never gets CPU again, DMA is not started T2 waits forever

OSAL mutex resolves problem of DMA starting from thread-context.
</content>
</entry>
<entry>
<title>Merge pull request #1279 from kasjer/kasjer/nrf5x-int-race</title>
<updated>2022-01-19T03:33:37Z</updated>
<author>
<name>Ha Thach</name>
<email>thach@tinyusb.org</email>
</author>
<published>2022-01-19T03:33:37Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/commit/?id=983abfd6d81f780c079df284b0329d5ef780d21e'/>
<id>urn:sha1:983abfd6d81f780c079df284b0329d5ef780d21e</id>
<content type='text'>
nrf5x: Fix EP OUT race conditions</content>
</entry>
<entry>
<title>nrf5x: Request HFXO via OS</title>
<updated>2022-01-18T07:12:49Z</updated>
<author>
<name>Jerzy Kasenberg</name>
<email>jerzy.kasenberg@codecoup.pl</email>
</author>
<published>2022-01-11T09:45:36Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/commit/?id=f4725120a42edc853aa6db87c1d21b2ffc401a92'/>
<id>urn:sha1:f4725120a42edc853aa6db87c1d21b2ffc401a92</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>nrf5x: Fix EP OUT race conditions</title>
<updated>2022-01-14T08:46:39Z</updated>
<author>
<name>Jerzy Kasenberg</name>
<email>jerzy.kasenberg@codecoup.pl</email>
</author>
<published>2022-01-14T08:44:38Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/commit/?id=da44fe3fc91ad643ec3892cc01a68eb52ed3dc5e'/>
<id>urn:sha1:da44fe3fc91ad643ec3892cc01a68eb52ed3dc5e</id>
<content type='text'>
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-&gt;total_len and actual_len correctly
but then context switch happens before xfer-&gt;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.
</content>
</entry>
<entry>
<title>nrf5x: Fix race condition during startup</title>
<updated>2021-12-08T07:27:27Z</updated>
<author>
<name>Jerzy Kasenberg</name>
<email>jerzy.kasenberg@codecoup.pl</email>
</author>
<published>2021-12-01T12:38:20Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/commit/?id=21db2351fdd3edd560e14d2949b9b0d217a51f93'/>
<id>urn:sha1:21db2351fdd3edd560e14d2949b9b0d217a51f93</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>more clean up</title>
<updated>2021-11-23T02:52:11Z</updated>
<author>
<name>hathach</name>
<email>thach@tinyusb.org</email>
</author>
<published>2021-11-23T02:52:11Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/tinyusb.git/commit/?id=c9e9f4785f68c9f9e99c4832af8615847c5fae92'/>
<id>urn:sha1:c9e9f4785f68c9f9e99c4832af8615847c5fae92</id>
<content type='text'>
</content>
</entry>
</feed>
