Skip to content

Commit 828228b

Browse files
committed
note that memory barriers are needed when dealing with caches
1 parent ebc3110 commit 828228b

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/dma.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,15 @@ there exist no intrinsic that's more fine grained than `compiler_fence`.
201201

202202
### Don't we need a memory barrier?
203203

204-
That depends on the target architecture. In the case of Cortex-M cores, [AN321]
205-
says:
204+
That depends on the target architecture. In the case of Cortex M0 to M4F cores,
205+
[AN321] says:
206206

207207
[AN321]: https://static.docs.arm.com/dai0321/a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
208208

209+
> 3.2 Typical usages
210+
>
211+
> (..)
212+
>
209213
> The use of DMB is rarely needed in Cortex-M processors because they do not
210214
> reorder memory transactions. However, it is needed if the software is to be
211215
> reused on other ARM processors, especially multi-master systems. For example:
@@ -214,12 +218,29 @@ says:
214218
> access and a DMA operation.
215219
>
216220
> (..)
221+
>
222+
> 4.18 Multi-master systems
223+
>
224+
> (..)
225+
>
226+
> Omitting the DMB or DSB instruction in the examples in Figure 41 on page 47
227+
> and Figure 42 would not cause any error because the Cortex-M processors:
228+
>
229+
> - do not re-order memory transfers
230+
> - do not permit two write transfers to be overlapped.
231+
232+
Where Figure 41 shows a DMB (memory barrier) instruction being used before
233+
starting a DMA transaction.
234+
235+
In the case of Cortex-M7 cores you'll need memory barriers (DMB/DSB) if you are
236+
using the data cache (DCache), unless you manually invalidate the buffer used by
237+
the DMA.
217238

218239
If your target is a multi-core system then it's very likely that you'll need
219240
memory barriers.
220241

221242
If you do need the memory barrier then you need to use [`atomic::fence`] instead
222-
of `compiler_fence`.
243+
of `compiler_fence`. That should generate a DMB instruction on Cortex-M devices.
223244

224245
[`atomic::fence`]: https://doc.rust-lang.org/core/sync/atomic/fn.fence.html
225246

0 commit comments

Comments
 (0)