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

Forum Post: CC2530 Rewriting Firmware during runtime, what am i doing wrong?

$
0
0

Hi, i´ve been trying to rewrite the firmware during runtime for a while now and i cant seem to get it to work. I have tested that all my functions are working correctly if executed from flash. But i need to run my flashwrite function from RAM and i get IDATA overflow everytime. what am i doing wrong? Here is my code.

int main(void)
{ unsigned char* DMA_configuration_pointer;
// Initialize Clock
CLKCONCMD = 0x20;
// Resulting frequency to timers 2 MHz
while ((CLKCONSTA & 0x20) != 0x20);

while(1)
{
//Write whole hexfile to flash
Erase_Flash(INFO_PAGE+1);
tempCount = Write_Hexfile_To_Flash();
Read_Flash(INFO_PAGE+1,32,tempProgramBuffer,tempCount);

//Separation of databytes from hexfile and storing them to INFO_PAGE+2
temp();

//Load Databytes to buffer in RAM
tempCount = 200;
function_pointer = (unsigned char)((unsigned int)(0x0000));
Read_Flash(INFO_PAGE+2,32,Databytes_of_tempProgramBuffer,tempCount);

//Move DMA configuration to 0x200 of SRAM both for DMA transfer of DBGDATA and one for flashwrite
DMA_configuration_pointer = dma_desc_0;
function_pointer = (unsigned char)((unsigned int)(0x0000));
for(i=0;i<0x200;i++){function_pointer++;}
for(i=0;i<8;i++){*function_pointer++ = *DMA_configuration_pointer++;}
DMA_configuration_pointer = dma_desc_1;
for(i=0;i<8;i++){*function_pointer++ = *DMA_configuration_pointer++;}

// 3. Set DMA controller pointer to the DBGDATA DMA descriptor
DMA0CFGH = (ADDR_DMA_DESC_0 >> 8);
DMA0CFGL = (ADDR_DMA_DESC_0 & 0xFF);

//Transfer Debug interface to SRAM
init_DMA_configuration();

// 3. Set DMA controller pointer to the Write flash DMA descriptor
XREG(DUP_DMA0CFGH) = ((ADDR_DMA_DESC_0 + 8) >> 8);
XREG(DUP_DMA0CFGL) = ((ADDR_DMA_DESC_0 + 8) & 0xFF);

//Load function to SRAM part of XDATA start at 0x10
tempCount = 100;
function_pointer = (unsigned char)((unsigned int)(0x0000));
for(i=0;i<0x10;i++){function_pointer++;}
Read_Flash(5,0,function_pointer,tempCount);

//Initiate running from SRAM
MEMCTR |= 0x08;

//Write Databytes_of_tempProgramBuffer to flash
asm("LJMP 0x8010");
//Write_Flash_From_RAM(Databytes_of_tempProgramBuffer,200,0,0);

//Check if written to Page 25
tempCount = 200;
function_pointer = (unsigned char)((unsigned int)(0x0000));
Read_Flash(INFO_PAGE+5,0,function_pointer,tempCount);

asm("LJMP 0x8000");
if(i == 1){temp();Write_Flash_From_RAM(function_pointer,200,0,0);}

}
}

void Write_Flash_From_RAM(const unsigned char *data, unsigned char length, unsigned char pg, unsigned int offset) @ "REPROGRAM"
{
unsigned char i;
pg = 0;
length = 200;
offset = 0;

//STOP INTERRUPTS
XREG(0x70A8) |= 0x00;

//Erase flash page
XREG(DUP_FADDRH) = 0x00;
XREG(DUP_FCTL) |= 0x01;

//WRITING PART
if (length < 16)
{
length = length + 2;
}

XREG(DUP_DMAIRQ) = 0x00;

XREG(DUP_DMAARM) |= 0x01;

offset = (offset / HAL_FLASH_WORD_SIZE) + (pg * (HAL_FLASH_PAGE_SIZE / HAL_FLASH_WORD_SIZE));

// set destination of DMA transfer
XREG(DUP_FADDRL) = offset;
XREG(DUP_FADDRH) = ((offset) >> 8);

XREG(DUP_FCTL) |= 0x02;
// Wait until writing is done.

while (XREG(DUP_FCTL) & 0x80);

asm("LJMP 0x0000");
}

Greatly appreciate any respons!


Viewing all articles
Browse latest Browse all 116964

Trending Articles