This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Reading nonzero data from zero memory..

I'm using a C5535 EZUSB kit, and coding up functions for a new project I'm working on. I've run into something peculiar.

I've got a buffer in DARAM which is initialized to zero by code - and looking at it with the memory browser in CCS, it's zero. But in my assembly code, I'm reading from this buffer using AR1, and it's reading nonzero data.

Here's a screenshot (hopefully it's readable and not scaled or anything):

XAR1 points to 0x317E, which according to the memory browser, should be zero. In the code window (process-a.asm) I've just executed the "MOV dbl(*AR1), AC0" test instruction, and AC0 now contains nonzero data.

Any hints/tips/suggestions? Thanks!

  • Perhaps the CCS memory view window is addressable with 8-bit byte addresses rather than target addresses?  See if the value at (0x317e * 2) 0x62fc is 0x6e707064, as shown in AC0_HL.

  • Memory view window is word addressed as far as I can tell.

    Memory at 0x62FC (double) is 0x36A0 0x0269, memory at 0x18BF (half) is 0xF456 0x4704. Haven't found a match yet in memory for what's getting read.

  • I want to make sure what we're seeing is what's actually going on.  Try adding NOPs around the read to make sure that surrounding instructions are not affecting the memory view.  Add around 10 NOPs before and after the read.

  • After executing 10 NOPs before and after the read, getting the same result.

    XAR0 address is the same (0x317E), still displaying zeros in the memory browser, and still reading the same value into AC0 - 0x006E707064.

  • Make sure circular addressing is disabled for XAR1 at the point of the MOV; this is configured by a bit in ST2, AR1LC.  This bit is set to 1 if circular addressing is enabled for XAR1.

  • Hmm...

    AR1LC cleared = MOV reads correct data
    AR1LC set = MOV reads garbage

    Unfortunately this is going in a filter routine where I do need circular addressing to work, so AR1LC has to be set at some point.

    BSA01 is 0x3000, BK03 is 0x0180, so buffer should range from 0x3000-0x317F. Circular buffer reading does seem to be working - with AR1LC set, a post-dec double read with XAR0 at 0x3000 makes XAR0 wrap to 0x317E, incrementing it again brings it back to 0x3000. Just the data being read is garbage.

    I'll confess that I'm new to the C5000 DSP, there's probably something I've forgot to configure somewhere...

  • If your buffer is at address 0x3000 and BSA01 is at 0x3000,  I think you want XAR0 to be 0x0 to read the first location.  I'd double-check this, it's been a long time since I've looked at C55x circular addressing.

    If you must use XAR1 for circular addressing, can't you use some other XAR for non-circular addressing?  How about turning AR1LC on only when you want it to be circular?

  • The buffer in question is a FIFO of sorts - the first location I read from the buffer isn't necessarily the start address of the buffer, and I do require address wrapping to occur. So I do need AR1LC set, period.

    Anyway, I've figured out there's actually an address doubling going on - my circular buffer is still at 0x3000 to 0x317F, as described before, and 16-bit FIR coefficients are placed at 0x6080 through 0x60FF

    My assembly code function is passed XAR0 (base address, 0x3000) and XAR1 (offset into the buffer, 0x3060) from C code. I do the following:

    MOV AR0, mmap(BSA01) ; set base address
    MOV #384, BK03 ; set buffer length (384 words)
    BSET AR1LC ; enable AR1 circular addressing

    Then I have a test loop that reads the buffer as dwords, so I can look at it with the emulator:

    RPT 191
    MOV dbl(*AR1+), AC0

    With XAR1 = 0x3060, the FIR taps seen at 0x60C0 (double) get loaded - 0x60C0 gets loaded into AC0H, 0x60C1 gets loaded into AC0L. If I change the dbl(*AR1+) to *AR1+ to do a 16-bit read, I get 0x60C0 loaded into AC0. But if I clear AR1LC, it correctly reads the buffer at 0x3000.

    In either the instruction set or CPU manual, I can't find anything saying that addresses get doubled when AR1LC is set. I wrote fresh code which uses XAR3/BK03/BSA23 and sets the AR3LC flag, following the instructions in 6.10.1 of the CPU manual, figuring it's an order of operations problem making the DSP do something undefined but that's not the case - same behavior is happening in that case.

    Is this normal behavior which isn't mentioned (at least not obviously) in the CPU documentation?

  • The address isn't being doubled; you are supposed to put the offset from the start of the buffer into XAR1.  If the buffer is at address 0x3000, you need to set BSA01 to 0x3000 and XAR1 to 0x60.  See Figure 6-14. Circular Buffer Computation in 23-bit page 6-114 of C55x v3.x CPU Reference Guide SWPU073E

  • THANK YOU! never realized that ARx is an offset with circular addressing mode. One asub line later, everything's working.

    Thanks again!