Quantcast
Channel: Wireless Connectivity
Viewing all articles
Browse latest Browse all 116964

Forum Post: How to use DMA Flash Write and Erase?

$
0
0

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.

 


Viewing all articles
Browse latest Browse all 116964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>