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.

cc2530 flash write

Other Parts Discussed in Thread: CC2530

Hello, 

In cc2530 program some data must be stored in flash and sometimes this data must be changed. After studing forums http://e2e.ti.com/support/wireless_connectivity/f/155/t/15758 

#define F_A 0x78C0

SFRX(FLASH_DATA, F_A); // Data stored in flash

unsigned char to_flash [27] =
{
0x11, 0x22, 0x33, 0x44,
0x55, 0x66, 0x77, 0x88,
0x99, 0xAA, 0xBB, 0xCC,
0xDD, 0xEE, 0xFF, 0x00,
0x11, 0x22, 0x33, 0x22,
0x11, 0x22, 0x11, 0x22,
0x11, 0x22, 0x11
};

typedef struct {
unsigned char SRCADDRH; //Byte 0
unsigned char SRCADDRL; //Byte 1
unsigned char DESTADDRH; //Byte 2
unsigned char DESTADDRL; //Byte 3
unsigned char LENH:5; //Byte 4 - Bit 4:0
unsigned char VLEN:3; //Byte 4 - Bit 7:5
unsigned char LENL; //Byte 5
unsigned char TRIG:5; //Byte 6 - Bit 4:0
unsigned char TMODE:2; //Byte 6 - Bit 6:5
unsigned char WORDSIZE:1; //Byte 6 - Bit 7
unsigned char PRIORITY:2; //Byte 7 - Bit 1:0
unsigned char M8:1; //Byte 7 - Bit 2
unsigned char IRQMASK:1; //Byte 7 - Bit 3
unsigned char DESTINC:2; //Byte 7 - Bit 5:4
unsigned char SRCINC:2; //Byte 7 - Bit 7:6
} DMA_DESC;

void FC_FlashWriteDMA(unsigned int AHI_WriteAddress, unsigned char* pData, unsigned int data_len)
{
DMA_DESC dmaConfig0;

dmaConfig0.SRCADDRH = ((unsigned int)pData >> 8) & 0x00FF;
dmaConfig0.SRCADDRL = (unsigned int)pData & 0x00FF;
dmaConfig0.DESTADDRH = (((unsigned int)&FWDATA) >> 8) & 0x00FF;
dmaConfig0.DESTADDRL = ((unsigned int)&FWDATA) & 0x00FF;
dmaConfig0.VLEN = 0;
dmaConfig0.LENH = (data_len >> 8) & 0x00FF;
dmaConfig0.LENL = data_len & 0x00FF;
dmaConfig0.WORDSIZE = 0;
dmaConfig0.TMODE = 0;
dmaConfig0.TRIG = 18;
dmaConfig0.SRCINC = 1;
dmaConfig0.DESTINC = 0;
dmaConfig0.IRQMASK = 0;
dmaConfig0.M8 = 0;
dmaConfig0.PRIORITY = 2;
while (FCTL & 0x80);
FADDRH = (AHI_WriteAddress >> 10) & 0x00FF;
FADDRL = (AHI_WriteAddress >> 2) & 0x00FF;

DMA0CFGH = (((unsigned int)&dmaConfig0) >> 8) & 0x00FF;
DMA0CFGL = ((unsigned int)&dmaConfig0) & 0x00FF;
DMAARM |= 0x01;
FCTL |= 0x02;
while (!(DMAIRQ & 0x01));
DMAIRQ = 0xFE;
while (FCTL & (0x80));
}

void main(void)
{
EA = 0;

halMcuInit();

EA = 1;

FC_FlashWriteDMA(F_A + 0x10, to_flash, 27);
flash_dump = (unsigned char *)&FLASH_DATA;
while(1) {
<some code to send data from flash_dump to check if recoding was successful>
}