• AVR Freaks

Hot!DSPIC33EP ping pong DMA status register not updated correctly

Author
mkmstie
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/10/17 05:11:24
  • Location: 0
  • Status: offline
2019/10/18 01:39:37 (permalink)
0

DSPIC33EP ping pong DMA status register not updated correctly

Hello,
I am using DISPIC33EP512 microcontroller.
I am observing a strange behaviour while using DMAPPS register to know which ping pong buffer is being used by the DMA.
I am using DMA2 in continuous ping pong mode for SPI1 RX. I use DMAPPS register to know the buffer being used. Sometimes, DMA2 bit in this register is not showing the correct buffer being used.
I get the correct buffer indication if I use DMA Channel Start Address Register (DMA2STAL).
 
DMA2 is configured as below -
  DMA2CON = 0x0002U;  // Continuous, Ping-Pong mode enabled
  DMA2REQ = 0x000AU;  // SPI1 Transfer Done

  DMA2PAD = (U16)&SPI1BUF; // Use SPI1 as data source
 
  // Number of words to count (0 = 1 word)
  DMA2CNT = 47U;
 
  // DMA2 ram start address register a
  DMA2STAL = (U16)&Intf_asSpiSpyRxDataBuffer[0];
  DMA2STAH = 0x0000U;
 
  // DMA2 ram start address register b
  DMA2STBL = (U16)&Intf_asSpiSpyRxDataBuffer[1];
  DMA2STBH = 0x0000U;

  IPC6 |= 7;              // DMA2 interrupt priority = 7
 
  IEC1 |= BIT_IEC1_DMA2;  // Enable DMA2 interrupt
 
  IFS1 &= ~BIT_IFS1_DMA2; // Clear DMA2 interrupt flag

DMAPPS register is read as below to get the buffer status -
  bBufferBInUse = ((SFR_DMA_DMAPPS & DMA_PING_PONG_DM2) == DMA_PING_PONG_DM2)
 
Has someone seen this issue and is there a way to know what could be causing it?
 
Thank you very much.
 
#1
du00000001
Just Some Member
  • Total Posts : 3175
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: DSPIC33EP ping pong DMA status register not updated correctly 2019/10/18 09:37:18 (permalink)
0
Are you sure about SFR_DMA_DMAPPS being wrong but DMA2STAL being correct?
As the buffer may be swapped at any time and provided you're first reading ...DMAPPS, then ...STAL, the buffer might have been swapped inbetween.
If you reverse the read order, you might find ...STAL being wrong and ...DMAPPS being right.
 
Basically your approach is not appropriate: you just can't try such things in an unsynchronized manner.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#2
mkmstie
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/10/17 05:11:24
  • Location: 0
  • Status: offline
Re: DSPIC33EP ping pong DMA status register not updated correctly 2019/10/21 00:15:05 (permalink)
0
Hi,
I have used following code to read DMAPPS before and after reading DMA2STAL -
  u16Dmapps1  = DMAPPS;
  u16DmaStal1 = DMA2STAL;
  u16Dmapps2  = DMAPPS;
u16Dmapps1 and u16Dmapps2 are exactly same but do not correspond to u16DmaStal1.
What would be a better approach to read DMAPPS?
Thank you.
#3
Jump to:
© 2019 APG vNext Commercial Version 4.5