AnsweredAssumed Answered

FTM input capture with DMA - a cautionary tale

Question asked by SCOTT MILLER on Sep 23, 2017
Latest reply on Sep 27, 2017 by Hui_Ma

I wasted hours on this today.  I was just about to post this as a question when I figured it out, so I'm posting this as a warning in case anyone else runs into the same bug.


I'm using an MK22FN1M0AVLH12 with Codewarrior 10.7.  For a soft UART implementation I need to use DMA to take values from an FTM channel in input capture mode.


This would seem to be fairly straightforward, but I found that whenever I'd check the results in the debugger, the entire buffer would be filled with the same (most recent) value.  This happened regardless of how I set up the number of major loop iterations. It'd trigger a transfer complete interrupt after 16 transfers, for example, and the debugger would stop in the ISR so I could check the results, and 512 entries would have the same value.


The cause?  The DMA_PDD_EnableDebug() macro's description is wrong.  It says it enables or disables the DMA controller in debug mode.  Which is sort of true, but it's misleading.  PDD_DISABLE does not disable the controller in debug mode - it clears the disable flag.  The sense is reversed.


This means that whenever I'd pause the debugger, the FTM would stop capturing, but apparently the channel flag doesn't clear while it's stopped, so the DMA transfer would run continuously with the most recent value.  It was capturing the right values all along - it was just overwriting them all as soon as I'd stop to look.