• AVR Freaks

Why are my PMP reads always 1 word behind?

Author
hneel
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2010/03/03 06:30:43
  • Location: The Netherlands
  • Status: offline
2018/10/03 02:13:37 (permalink)
0

Why are my PMP reads always 1 word behind?

I'm having a board where my PIC32 connects to a RAM chip over a standard data/address bus.
 
First I used bitbanging in all functions. This worked fine, but rather slow. So I want to replace it with PMP functions.
The problem is that when I read a block of data, all words are 1 step behind. 
 
Here is my code:
      addr = 0;
      len = 0x100;
      
      mPMPOpen( PMP_ON | PMP_IDLE_CON | PMP_MUX_OFF | PMP_READ_WRITE_OFF | PMP_TTL | PMP_CS2_CS1_OFF |
                   PMP_CS2_POL_LO | PMP_CS1_POL_LO | PMP_WRITE_POL_LO | PMP_READ_POL_LO,
                PMP_IRQ_OFF | PMP_AUTO_ADDR_OFF | PMP_DATA_BUS_16 | PMP_MODE_MASTER2 |
// PMP_WAIT_BEG_1 | PMP_WAIT_MID_0 | PMP_WAIT_END_1,
// PMP_WAIT_BEG_4 | PMP_WAIT_MID_15 | PMP_WAIT_END_4,
                  PMP_WAIT_BEG_1 | PMP_WAIT_MID_1 | PMP_WAIT_END_1,
                PMP_PEN_ALL,
                PMP_INT_OFF );
      
      
      // Slow bitbanged method for setting the address. Still needed for the higher address lines.
      MemSetAddr( addr );

      for( i=0; i<len; i+=2 )
      {
        PMPSetAddress( addr+i );

        // Set CE and OE pins low
        SetPin_MEM_CER_L();
        SetPin_MEM_RD_L();
#if 1
        // PMP read functions. All variants have the same result.
        
        //valw = PMPMasterRead();
        //valw = mPMPMasterReadWord();
        valw = PMDIN;
#else
        // Slow bitbanged read function.
        valw = MemRead();
#endif
        // Set CE and OE pins high
        SetPin_MEM_RD_H();
        SetPin_MEM_CER_H();

        // Save it.
        rxbuffer[i] = valw & 0x00FF;
        rxbuffer[i+1] = (valw >> 8);
      }

      mPMPClose();

      // Print the result.
      PrintFormattedHex( rxbuffer, len, addr, true, RespString );

 
This is the result of the bit-banged reads:
10:43:51 00000000: EB 3C 90 4D 53 44 4F 53 - 33 2E 33 00 02 01 01 00 .<.MSDOS3.3..... 
10:43:52 00000010: 02 80 00 00 10 F8 0C 00 - 0F 00 02 00 00 00 00 00 ................
10:43:52 00000020: 00 00 00 00 00 00 29 17 - 48 F8 03 43 53 4D 46 6F ......).H..CSMFo
10:43:52 00000030: 72 6D 31 2E 33 32 46 41 - 54 31 32 20 20 20 FA 33 rm1.32FAT12 .3
10:43:53 00000040: C0 8E D0 BC 00 7C FB 0E - 1F FC BE 66 7C E8 06 00 .....|.....f|...
10:43:53 00000050: 33 C0 CD 16 CD 19 AC 0A - C0 74 09 B4 0E BB 07 00 3........t......
10:43:53 00000060: CD 10 EB F2 F8 C3 54 68 - 69 73 20 63 61 72 64 20 ......This card
10:43:54 00000070: 77 61 73 20 66 6F 72 6D - 61 74 74 65 64 20 77 69 was formatted wi
10:43:54 00000080: 74 68 6F 75 74 20 74 68 - 65 20 2F 53 20 70 61 72 thout the /S par
10:43:54 00000090: 61 6D 65 74 65 72 2E 0D - 0A 49 74 20 64 6F 65 73 ameter...It does
10:43:55 000000A0: 20 6E 6F 74 20 63 6F 6E - 74 61 69 6E 20 61 20 6F not contain a o
10:43:55 000000B0: 70 65 72 61 74 69 6E 67 - 20 73 79 73 74 65 6D 2E perating system.
10:43:55 000000C0: 0D 0A 50 6C 65 61 73 65 - 20 72 65 6D 6F 76 65 20 ..Please remove
10:43:56 000000D0: 74 68 65 20 63 61 72 64 - 20 61 6E 64 20 70 72 65 the card and pre
10:43:56 000000E0: 73 73 20 61 6E 79 20 6B - 65 79 20 21 00 FF FF FF ss any key !....
10:43:56 000000F0: FF FF FF FF FF FF FF FF - FF FF FF FF FF FF FF FF ................

 
And this the result of the PMP reads:
 
10:44:58 00000000: 00 00 EB 3C 90 4D 53 44 - 4F 53 33 2E 33 00 02 01 ...<.MSDOS3.3... 
10:44:58 00000010: 01 00 02 80 00 00 10 F8 - 0C 00 0F 00 02 00 00 00 ................
10:44:58 00000020: 00 00 00 00 00 00 00 00 - 29 17 48 F8 03 43 53 4D ........).H..CSM
10:44:59 00000030: 46 6F 72 6D 31 2E 33 32 - 46 41 54 31 32 20 20 20 Form1.32FAT12
10:44:59 00000040: FA 33 C0 8E D0 BC 00 7C - FB 0E 1F FC BE 66 7C E8 .3.....|.....f|.
10:44:59 00000050: 06 00 33 C0 CD 16 CD 19 - AC 0A C0 74 09 B4 0E BB ..3........t....
10:45:00 00000060: 07 00 CD 10 EB F2 F8 C3 - 54 68 69 73 20 63 61 72 ........This car
10:45:00 00000070: 64 20 77 61 73 20 66 6F - 72 6D 61 74 74 65 64 20 d was formatted
10:45:00 00000080: 77 69 74 68 6F 75 74 20 - 74 68 65 20 2F 53 20 70 without the /S p
10:45:01 00000090: 61 72 61 6D 65 74 65 72 - 2E 0D 0A 49 74 20 64 6F arameter...It do
10:45:01 000000A0: 65 73 20 6E 6F 74 20 63 - 6F 6E 74 61 69 6E 20 61 es not contain a
10:45:01 000000B0: 20 6F 70 65 72 61 74 69 - 6E 67 20 73 79 73 74 65 operating syste
10:45:02 000000C0: 6D 2E 0D 0A 50 6C 65 61 - 73 65 20 72 65 6D 6F 76 m...Please remov
10:45:02 000000D0: 65 20 74 68 65 20 63 61 - 72 64 20 61 6E 64 20 70 e the card and p
10:45:02 000000E0: 72 65 73 73 20 61 6E 79 - 20 6B 65 79 20 21 00 FF ress any key !..
10:45:03 000000F0: FF FF FF FF FF FF FF FF - FF FF FF FF FF FF FF FF ................

 
I guess the difference is obvious. It looks like the PMP reads are somehow going through a buffer. But I haven't been able to find anything about that.
 
 
#1

2 Replies Related Threads

    hneel
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2010/03/03 06:30:43
    • Location: The Netherlands
    • Status: offline
    Re: Why are my PMP reads always 1 word behind? 2018/10/03 04:05:19 (permalink)
    0
    I noticed that if I read twice in each loop iteration, the result is correct.
    A rather poor workaround if you aske me, but still a lot faster than the bitbang method.
     
    #2
    simong123
    Lab Member No. 003
    • Total Posts : 1313
    • Reward points : 0
    • Joined: 2012/02/07 18:21:03
    • Location: Future Gadget Lab (UK Branch)
    • Status: offline
    Re: Why are my PMP reads always 1 word behind? 2018/10/03 08:26:02 (permalink)
    5 (1)
    You obviously haven't read the datasheet or FRM section. You have to read from PMDIN to initiate a transfer, then read again to get the result.
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5