dma_channel_abort does not wait for CHAN_ABORT to go zero #923
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 assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#923
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?
The source for
dma_channel_abortfrom SDK 1.4.0:Note that while it waits for the channel's
BUSYflag to go zero, it does not wait forCHAN_ABORTto go zero.From the datasheet, emphasis mine:
Also from the datasheet:
The datasheet does not indicate whether it is necessary to wait for both
BUSYto go zero andCHAN_ABORTto go zero or if waiting for either condition is sufficient. It also does not indicate in which order code should wait for them to go zero. As mentioned, dma_channel_abort only waits forBUSYto go zero.I suggest there is either a bug in
dma_channel_abort(if it ought to be waiting for both) or the datasheet would benefit from clarification.See also Errata RP2040-E13 in the RP2040 datasheet, if you haven't already.
Given RP2040-E13, I agree that this is documentation.
The workaround recommends "Before aborting a channel, clear its interrupt enable. After aborting a channel, poll the CTRL.BUSY bit to wait for completion (not the ABORT bit), clear the spurious IRQ, and restore the interrupt enable."
I suggest this could be improved too. CHAN_ABORT can be used to abort multiple channels with a single write to the register. In fact this seems like the best way to abort multiple channels that trigger each other, with other methods likely to suffer from race conditions.
The workaround recommendation assumes that only a single channel is being aborted. It would be good to confirm that, even when multiple channels are aborted, it is adequate and necessary to check only the CTRL.BUSY bits for each channel in turn and not to check CHAN_ABORT. Without that clarification, it is not clear that checking only CTRL.BUSY is free of race conditions when aborting multiple channels.
moving to 1.5.1 so it doesn't get forgotten (even if the docs aren't fixed there)
Related, and for posterity, I have a DMA control+data setup, with the data channel re-starting control at the end, rather than issuing a null transfer, emulating a ring. This required me to do two CHAN_ABORT on both channels to ensure it stops. I'm thinking the DMA trigger register may already be in the DMA FIFO, making this racy even with CHAN_ABORT. To be safe, I have it in a loop:
@tommie I have the exact same problem and would like to try your approach, but coming up against
dma_channel_abort_maskis undefined. A quick search turned out nothing, so I was wondering if this was your own local definition, or whether the API actually exists anywhere?P.S.: For future reference, replacing this call with two single-channel
dma_channel_abortcalls also works, so leaving it for now.@glopesdev Yepp, you're right.
Any updates on this yet ?, facing the same issue in 2.2.0 !
@kilograham
One more -maybe related- issue, is that changing any of the two stop_dma_loop() functions to try and disable the PIO before aborting the dma channels results in CPU getting completely stuck.