Repeatedly aborting and restarting streaming transfers from flash loses data #122
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#122
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I was trying out the flash data streaming functionality as used in the example here: https://github.com/raspberrypi/pico-examples/blob/master/flash/xip_stream
I found that if I start then repeatedly abort and restart the streaming transfer, then the third transfer loses the first word that should be transferred.
Project that reproduces the problem here: https://github.com/MichaelBell/pico-projects/tree/master/flashtest
Adding a 1us sleep after aborting the streaming transfer fixes the problem.
As requested by @Wren6991 I've added a binary that reproduces the problem here: https://github.com/MichaelBell/pico-projects/raw/master/flashtest/flashtest.bin
Thanks, your repro does hit the breakpoint in the sim. Will try to dig in now and understand what's happening.
I think I understand what is happening. Following a stream abort, your code is sometimes able to setup a new DMA transfer, and start a new stream, before the last QSPI access from the aborted stream completes. There is some logic to handle this case, and it correctly marks that transfer as dirty, suppressing the FIFO write and the count decrement. However the address increment is not suppressed, so the addresses of your stream are offset by 1 word once your stream starts. This is a hardware bug.
Will have a look around and see if there is some state to poll to fence off on the last transfer following an abort (replacing your 1us delay) -- the SSI BUSY flag should get you within a few cycles.
Once we've found a good workaround, I'll add an errata entry to the datasheet, and we can look at updating the software and other docs.
Took me a while to chase everything through -- the SSI BUSY flag doesn't have quite the right timing internally, but the QSPI transfer in progress creates a bus stall when you poll the flag, that should delay sampling to the correct point.
Do you still see the same behaviour if you insert this polling:
Following your clearing of the the stream counter?
Alternatively you should actually be able to do a dummy read of any SSI register and make use of the bus stall
My test works with the first option. Woohoo!
The second option just locks up and leaves the pico in a state where I can't reprogram over SWD :-( It says things like:
Reset with BOOTSEL held lets me get back to a good state though, so that's OK!
That's interesting, I'll dig in further on Monday to make sure my understanding is complete. Glad to hear the first option works, but want to understand the issue fully before adding the errata entry to the datasheet.
yeah, i'm pretty sure the first option is still a bit broken... it seems to lock up if i start mixing printfs to display progress every 65536 iterations
I updated the flashtest.bin file in my repo with the "workaround 2" version that locks everything up, hopefully that's useful to you.
I am also seeing things stop working in my actual use case with the workaround in, but had assumed that the problem was now in my code - haven't debugged into that to check yet.
Thanks, I am able to reproduce with the binary you provided, but don't see the same behaviour when I build your source with my local GCC 9 (I get slightly different timing of the dummy read). Adding this immediately after the counter clear (rather than trying to access an SSI register) results in correct DMA data:
i.e. do a dummy XIP read to flush out any in-progress stream XIP read.
My local build does still trip the breakpoint with this fix in place, but I see the DMA transferring the correct data. The processor only seems to access the DMA buffer once, before any DMA transfers actually take place, and then later only checks a stack variable (presumably
uint32_t buff[4];in your code), so that seems like the compiler trying to optimise things out.Yep so changing the flash abort to this
And putting a "here be dragons" for the compiler so it doesn't try to think too hard about the DMA dataflow
Means this seems to work reliably for me now
That suggestion is working reliably for me too. Thank you!
Thanks, this is now listed in a datasheet errata entry, will appear in the next docs release