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.

How to use DMA Flash Write and Erase?

Other Parts Discussed in Thread: CC2510

As title.

I'm trying to write a flash write routine using DAM method for my CC2510F32.My code is below:

#include <ioCC2510.h>
#include <ioCCxx10_bitdef.h>
#include <hal_types.h>
#include <dma.h>

/* One whole page of flash memory is to be reserved, i.e., 1 KiB. */
#define PAGE_SIZE 1024

/* String length (exluding the terminal '\0'). */
#define DATA_AMOUNT 16

/* The "string" to be written to flash ('\0' not included). */
static const char data[DATA_AMOUNT] = "Flash Controller";
static char writeCheck[DATA_AMOUNT];
unsigned char c=0;

__no_init const char __code flashDataAddr[PAGE_SIZE] @ 0x4400;

/* DMA configuration descriptor used for flash write. */
static DMA_DESC dmaConfig0;


/*******************************************************************************
* LOCAL FUNCTIONS
*/

// Prototype for local functions (implemented in assembly).
void halFlashStartErase(void);
void halFlashStartWrite(void);

int main(void)
{
//    DMA_DESC dmaConfig0;

    P1SEL = 0x00;
    P1DIR = 0x03;
    P1_0 = 0;P1_1 = 0;

    dmaConfig0.SRCADDRH  = ((uint16)data >> 8) & 0x00FF;
    dmaConfig0.SRCADDRL  = (uint16)data & 0x00FF;
    dmaConfig0.DESTADDRH = ((uint16)&X_FWDATA >> 8) & 0x00FF;
    dmaConfig0.DESTADDRL = (uint16)&X_FWDATA & 0x00FF;
    dmaConfig0.VLEN      = DMA_VLEN_USE_LEN;
    dmaConfig0.LENH      = (DATA_AMOUNT >> 8) & 0x00FF;
    dmaConfig0.LENL      = DATA_AMOUNT & 0x00FF;
    dmaConfig0.WORDSIZE  = DMA_WORDSIZE_BYTE;
    dmaConfig0.TMODE     = DMA_TMODE_SINGLE;
    dmaConfig0.TRIG      = DMA_TRIG_FLASH;
    dmaConfig0.SRCINC    = DMA_SRCINC_1;
    dmaConfig0.DESTINC   = DMA_DESTINC_0;
    dmaConfig0.IRQMASK   = DMA_IRQMASK_DISABLE;
    dmaConfig0.M8        = DMA_M8_USE_8_BITS;
    dmaConfig0.PRIORITY  = DMA_PRI_HIGH;
   
    DMA0CFGH = ((uint16)&dmaConfig0 >> 8) & 0x00FF;
    DMA0CFGL = (uint16)&dmaConfig0 & 0x00FF;

    /* Waiting for the flash controller to be ready */
    while (FCTL & FCTL_BUSY);
   
    FWT = 0x22;
    //FADDRH = (int)flashDataAddr >> 9;
    //FADDRL = ((int)flashDataAddr >> 1) & ~0xFF00;
    FADDRH = (int)flashDataAddr >> 8;
    FADDRL = ((int)flashDataAddr ) & 0x00FF;

      
    DMAARM |= DMAARM0;
    /* Erase the page that will be written to. */
    FCTL = 0x01;
    asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");
    asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");
    asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");
    asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");
    asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");
    asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");

    /* Wait for the erase operation to complete. */
    while (FCTL & FCTL_BUSY);
   
    /* Arm the DMA channel, so that a DMA trigger will initiate DMA writing. */
    DMAREQ |= DMAREQ0;
    P1_0 = 1;
   
    /* Enable flash write. Generates a DMA trigger. Must be aligned on a 2-byte
     * boundary and is therefor implemented in assembly.
     */
   
    FCTL |= 0x02;
   
    /* Wait for DMA transfer to complete. */
    while (!(DMAIRQ & DMAIRQ_DMAIF0));
    //while (!(DMAIRQ & 0x01));
    P1_1 = 1;
   
    /* Wait until flash controller not busy. */
    while (FCTL & (FCTL_BUSY | FCTL_SWBSY));
   
    /* By now, the transfer is completed, so the transfer count is reached.
     * The DMA channel 0 interrupt flag is then set, so we clear it here.
     */
    DMAIRQ &= ~DMAIRQ_DMAIF0;

    /* Read from flash to check whether the write was successful. */
    uint8 i;
    for (i = 0; i < DATA_AMOUNT; i++)
    {
        writeCheck[i] = flashDataAddr[i];
    }

    return 0;
}

 

I use its sample code, but always stop in below code:

"  while (!(DMAIRQ & DMAIRQ_DMAIF0));  /* Wait for DMA0 transfer to complete. */  "

And I don't know "   halFlashStartErase();   "     and    "      halFlashStartWrite()      ", what's these content of sub routine?

In my code,these  content of sub routine is my guess.

 

I search the other related subject of anyone, and anyone say use sample code is OK.

But I use sample code is wrong.

 

I must  need to learn to use FLASH Write and Erase.

Please help me.

Thanks a lot.

 

  • Is there anyone can help me?

    Please...

    I'm really no ideal about FLASH write and Erase.

    Please help me.

  • Hi,everyone.

    Now,I can use FLASH wirte and erase by sample code(\cc1110_cc2510_Basic Software_Examples\ide\iar\examples\flash\flash.eww)

    But , If I use "\cc1110_cc2510_Basic Software_Examples\source\examples\flash\flash_cpu.c"

    It can't compile, reason is Segment XSTACK is too large for segment definition.

    And if I use "\cc1110_cc2510_Basic Software_Examples\source\examples\flash\flash_dma.c"

    It can't compile either,reason is

    Error[e46]: Undefined external "halFlashStartErase" referred in main.

    Error[e46]: Undefined external "halFlashStartWrite" referred in main

     

    I try to change workspace parameter.But it's no useful.

    Please help me.

    Thank a lot. 

  • OK,now I only use "flash.eww".It's no problem.

    But I find a question.

    I can use debug interface to see the flash data and let LED is bling

    EX:

    for (i = 0; i < DATA_AMOUNT; i++)
    {
        writeCheck[i] = flashDataAddr[i];
    }
    if(writeCheck[0]==0x46)
        P1_0 = 1;

     

    It's OK.

    But if I program to my PCB(CC2510F32) ,the LED is no bling.Why???