@@ -201,11 +201,15 @@ there exist no intrinsic that's more fine grained than `compiler_fence`.
201
201
202
202
### Don't we need a memory barrier?
203
203
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:
206
206
207
207
[ AN321 ] : https://static.docs.arm.com/dai0321/a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
208
208
209
+ > 3.2 Typical usages
210
+ >
211
+ > (..)
212
+ >
209
213
> The use of DMB is rarely needed in Cortex-M processors because they do not
210
214
> reorder memory transactions. However, it is needed if the software is to be
211
215
> reused on other ARM processors, especially multi-master systems. For example:
@@ -214,12 +218,29 @@ says:
214
218
> access and a DMA operation.
215
219
>
216
220
> (..)
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.
217
238
218
239
If your target is a multi-core system then it's very likely that you'll need
219
240
memory barriers.
220
241
221
242
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.
223
244
224
245
[ `atomic::fence` ] : https://doc.rust-lang.org/core/sync/atomic/fn.fence.html
225
246
0 commit comments