2014-03-04 04:59 AM
Hello,
We use
STM32Fxx MPU
in many projects
. During the development
of new equipment with STM32F427
, wehave run into this
problem:
We use
SPI
4, whichis controlled by the
DMA
. Streamer DMA2_Stream1 is used for sending, DMA2_Stream0 for reading. DMA2_Stream0 generates an interrupt, whichprocesses the
data
and restarts
transmission
(for manyreasons it is not
possible to use
cyclic DMA)
.Interrupt handler looks like this
(actually the last
version
, programhas been
completely
rewritten
,unfortunately
behavior is the same
:(void DMA2_Stream0_Irq (
)
{
...
SPI_Cmd(SPI4, DISABLE);
SPI_DMACmd(SPI4, SPI_DMAReq_Rx | SPI_DMAReq_Tx, DISABLE);
DMA_Cmd(DMA2_Stream0, DISABLE);
DMA_Cmd(DMA2_Stream1, DISABLE);
while (DMA_GetCmdStatus(DMA2_Stream0)!=DISABLE) {};
while (DMA_GetCmdStatus(DMA2_Stream1)!=DISABLE) {};
DMA_SetCurrDataCounter(DMA2_Stream0, 14);
DMA_SetCurrDataCounter(DMA2_Stream1, 14);
DMA_MemoryTargetConfig(DMA2_Stream0, MemRx, DMA_Memory_0);
DMA_MemoryTargetConfig(DMA2_Stream1, MemTx, DMA_Memory_0);
DMA_Cmd(DMA2_Stream0, ENABLE);
DMA_Cmd(DMA2_Stream1, ENABLE);
SPI_DMACmd(SPI4, SPI_DMAReq_Rx | SPI_DMAReq_Tx, ENABLE);
SPI_Cmd(SPI4, ENABLE);
}
Up to this point
everything is
ok
.
The transmission
works perfectly,
a
ll tests
of reliability and
performance
went well.
Then we
implemented a
simple
DMA
transfer
memory2memory (for the purposes of
TCP
stack). We used
DMA2_Stream7.
Separately,
both
communication works
perfectly
. If, however, are
used simultaneously
,errors occur
.DMA2_Stream0 interrupt is not called
.
It looks as
if the
SPI4
readby one character
less
than
sent
.After error, DMA2_Stream0 is enabled (and
waits
indefinitely
), hasNDTR=1 and
TCIF
=0
.
DMA2_Stream1 is stopped, has
NDTR=0 and
TCIF=1.
From these data
it is evident
why
SPI
stops working
.I remembered
that a similar
errata was
in the chip
STM32F407. And indeed,
error
occurs
only
if
source addr is FMC!!!Shortly
, if dma memory2memory is:
SRAM-
>
SRAM ... everything is
ok
SRAM-
>FMC
... everything is
ok
FMC
-
>FMC
... error
FMC
-
>
SRAM ... error
Oddly enough
, this error
is not described in
the
errata documentation.
It is
this error
and is there a
workaround
?Or am I doing
something
wrong
?
2014-03-04 05:27 AM
Yeah
,
I forgot to add
the following
:We tried
all possible configurations
DMA
(with and without
FIFO
, variousstreamers
, etc.)We wrote
many variants of
the interrupt handler
(recentlypublished
,
in
fact,
is not good.
DMA
should be stopped
prior to
the disabling SP4 - but
it has no effect
).2014-03-04 09:58 AM
Hello,
it's hard to help you and answer your questions with few details can you share: - HCLK,PCLK2,SPI4_CK frequencies - SPI_SR register value (when the fail is seen). - DMA2_Stream7 CR register value and NDTR - DMA2_Stream0 CR register value - FMC BCR and BTR registers value. Br, Abdelhamid.2014-03-04 01:09 PM
2014-03-04 01:29 PM
I forgot:
SP4->CR1 = 0x0364
SP4->CR2 = 0x0003
SP4->SR = 0x0042
2014-03-04 11:46 PM
Ahoj Zbyňku,
> SP4->SR = 0x0042 The SPI receiver overruns due to the DMA being busy with the FMC->xxx transfer for too long. Try transferring shorter chunks of data from FMC, or lower the SPI clock rate. If the timing is marginal, assigning the SPI-Rx DMA stream higher priority than the SPI-Tx DMA stream might help, but in a more complex setup I wouldn't rely on that and I would attempt to calculate (I admit there may be not enough information in the published documetnation for this) or establish experimentally the timing budget. JW2014-03-05 05:55 AM
Cześć
Honzo,
Thanks a lot
for your advice
, butunfortunately
it did not help
.
I changed the
priority
of DMA Stream (RX=VeryHigh, TX=High, M2M=Low), slowedSPI
, butwithout any progress.
Today I received by mail an official statement from STM. The report does not indicate whether content can be published, so here is my
brief
transcript
:They
admitted that
the problem may be in
the chip
. More specifically,in the
FIFO,
which
is
built into the
FMC
. Errata DMA2 was not fixed.As a
workaround
they
recommend to use DMA M2M triggered by timer.
<end of
transcript
>Use this
DMA
seems to me
like a pretty good idea
.
I
'll try it
and let you know
.Zbynek
2014-03-05 09:10 AM
>
I changed the
priority
of DMA Stream (RX=VeryHigh, TX=High, M2M=Low), slowedSPI
, butwithout any progress.
Yes, but your data/address setup times indicate that your FMC/SRAM read is set to really, really, incredibly sloooooooow... 15+255=270 cycles, that's 1.5us even at 180MHz clock. And the other DMA channels have to wait until the whole transfer is finished, so add a couple of cycles for the write to internal SRAM, and multiply that by the number of bytes you are trying to transfer... I'd say, you should try some benchmarking. > Theyadmitted that
the problem may be in
the chip
. More specifically,in the
FIFO,
which
is
built into the
FMC
. I am not sure they understood your problem. There's no FIFO involved when you are *reading* from the SRAM controller of the FMC.The timer-triggered DMA is a good idea, but for a different reason: as it involves only one transfer at a time, it allows to interleave other DMA streams (if they have higher priority); but bear in mind that still the DMA will wait at least for that one read (btw. the whole AHB bus where the FMC is sitting is blocked for that time, luckily, there's no other peripheral on that bus; so unless some other master e.g. the processor wants to access FMC it's not a big issue). It's that 1.5us, so, if your SPI is say 10MHz/8bit, i.e. one received frame per
0.8us
, and you are in trouble again. Is it really necessary to have such data/address setup times? Jano Waclawek (áno, to priezvisko je mätúce... :) )2014-03-05 01:02 PM
Cześć Jano,
Unbelievable
!
T
he
problem
seems to be
solved!
After
I read
„that's 1.5us even“ everythingsuddenly became clear
. Of courseyou're right, 1.5us
is awfully
long time
. Now Itotally
understand what
was happening on the
AHB
bus
. Ohyeah, it's embarrassing
.
That's
a real
chess
blindness
.
With 250ns bus cycle, everything is OK.I had
in my head
that old
errataand
I was too
focused
on it. I did not realize
that the
FMC cycle
takes so
long.
Meanwhile,I have
implemented
and tested
the mentioned
M2M DMA, works well, but I'm notdecided
whether
to
use it.
Jano, I would
like
to
thank
you for
the
useful
advice
.
Y
ou helped me very much.
I do not know
how to
repay
you
.
With kind regards
Zbynek