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.

CC251X: Cannot write to internal flash when source is flash

Other Parts Discussed in Thread: CC2511, CC2510

Dear Forum,

I am writing a flash routine which is able to rewrite some sectors by DMA. When the source is RAM everything works fine. When source is the flash itself the code stucks because the DMA never ends and therefore the loop

 while (!(DMAIRQ & DMA_CHANNEL_0));

is never ending. Is there any restriction regarding flashing by DMA using source and destination the flash? My code is based on the example SW supplied by TI, so I am aware of the word aligned FCTL.WRITE and so on.

Thanks for any help

spachner

  • I've never tried programming the flash with data directly from flash myself, but it do sound a bit trickier for the flash controller than from RAM to flash: (fetch a flash word from flash into flash cache, let DMA copy the bytes into FWDATA, then let the flash controller (erase+)program flash word -- and if the CPU is going to execute code while this all occur, I'm not surprised that the flash controller might start to cry).

    You say your while(...) polling gets stuck. You are trying to await the DMA ch0 to complete the whole flash write transfer, right after trigging it with a FCTL.WRITE=1?

    If you do this with a debugger, do you see any sign of the data you are trying to copy from flash to flash is properly written? Could it be that the DMA tries to access the flash, but are stuck in a lock or something, by the CPU? (Would it help to fiddle with DMA vs CPU memory bus priority setting, do you think?)

    spachner: I'm sorry for my ramblings, I haven't tested this myself, so I don't know the exact answer. Hopefully someone who has will come by soon.
  • Right aevon, writing flash to flash sounds complicated, but the manual states explicitly:

    2.3.2.1 DMA Flash Write
    When using the DMA to write to flash, the data to be written is stored in the XDATA memory space (RAM or flash).

    So I gave him a try. I did not see any bytes written checked by the debugger. The first DMA transfer stucks. Well, I did a simple workaround and copied the data to be flashed first into RAM, then it works. But the issue should be solved by Chipcon or at least the manual corrected.

    regards

    spachner

  • m also getting the same problem.can u provied some short of example how u solved this DMA issue using RAM???

  • Well, quite simple, just declare an varaible array which is located in xdata, copy the source from flash into it and use them for DMA source. Hope this helps. My code is based on the example code provided by Chipcon some weeks ago.

    regards

    spachner

    static __xdata BYTE tempSector[1024];

    static void dmaFlashSector(BYTE *pDestBuf, BYTE *pSrcBuf, UINT16 byteCnt) {
        SET_FLASH_WRITE_TIME();             // Setup flash timing (26MHz)

        FADDRH =  (int)pDestBuf >> 9;
        FADDRL = ((int)pDestBuf >> 1) & ~0xFF00;

        LOG("flash dst: 0x%x, src: 0x%x, cnt: %d\n", (int)pDestBuf, (int)pSrcBuf, (int)byteCnt);

        for(int i = 0; i < byteCnt; ++i)
        {
            tempSector[i] = *pSrcBuf;   // Here the flash content is copied to RAM
            pSrcBuf++;
        }

    ... further code like in example provided by chipcon

    }

  • hey spachner...thanks man but it works for CC2510. it again stucks for CC2511. :(

  • I haven't tried the CC2511 yet. Did you check the flash write timing. The CC2511's 8051 core is running with 48/2 MHz, the CC2510 with 26 or 27 MHz, depending on your implementation.

    regards

    spachner

  • ya i checked that. again in CC2511 it works if u write through CPU but DMA sucks :(

  • i got it. i had declared DMA variable as only static. i made it static __xdata .it works fine.

  • I think it is also a good idea to align the temp buffer in xdata to word boundaries. I am not really sure if it is necessary, but is does not hurt:

    IAR code:

    #pragma data_alignment=2
    static __xdata BYTE tempSector[1024];

    regards

    spachner

  • Everyone.

    This skipped my attention. There seems to be a typo in most if not all system-on-chips with DMA:
    The correct statement should be:
    When using the DMA to write to flash, the data to be written is stored in the XDATA memory space (RAM or registers).

    Will add a note to all datasheets that this gets fixed with the next datasheet updates. Spachners suggestion above with first copying the data into RAM is the way to go.

    Thanks for pointing this out!

    Rgds,
    Kjetil

  • Hello,

    I am using the CC1111 and having the same problem, but cannot use the fix above. It still gets stuck at the DMA IRQ line. I have moved the data to be written to xdata and set the FWT up for 24MHz system clock (0x1f). Any thoughts?

     

  • Hi AMorris,

    please check you MEMCTR setting (when the CC1111 has this). I encounterred problems when the flash prefetch is enabled while doing internal flashing. See http://e2e.ti.com/forums/p/7527/30410.aspx#30410.  Despite this it works perfetlcy for me.

    regards

    spachner

    xLDen>de GoogleDicC
    Seite
  • Hi Spachner,

    Thanks for the suggestion. I tried disabling flash prefetch, but it made no difference. This is both with my own code and the example source code given by TI, so there must be some other setting to change.

     

    Regards


    AMorris