Other Parts Discussed in Thread: MSP430FG4618, CC430F5137
I'm having problems writing a DMA routine that transfers data from a C array, held in RAM, to FLASH memory.
Here's some example code. I'm running it on the MSP430FG4618 on the experimenter board.
#include "msp430xG46x.h"
void main(void)
{
unsigned short inData[16];
unsigned int i;
// create some dummy data
for (i = 0; i < 16; i++)
{
inData[i] = i + 1;
}
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
__data16_write_addr((unsigned short)&DMA0SA, (unsigned int)inData);
// Start block address
__data16_write_addr((unsigned short)&DMA0DA, 0x10000ul);
// Destination block address
DMA0SZ = 0x0010; // Block size
DMA0CTL = DMADT_5 + DMASRCINCR_3 + DMADSTINCR_3 + DMAEN; // Rpt, inc, enable
// Setup and erase Flash memory
// (Rem.: This time is also used to wait for
// the voltages getting stabilized)
FCTL2 = FWKEY + FSSEL1 + FN1; // SMCLK/3 = ~333kHz
FCTL3 = FWKEY; // Unlock Flash memory for write
// Erase memory block
FCTL1 = FWKEY + ERASE;
__data20_write_char(0x1000ul, 0x00); // Dummy write activates segment erase
FCTL1 = FWKEY + WRT; // Enable Flash write for copying
DMA0CTL |= DMAREQ; // Trigger block transfer
// Deactivate Flash memory write access
FCTL1 = FWKEY; // Disable Flash write
FCTL3 = FWKEY + LOCK; // Lock Flash memory
}
It doesn't work. It only writes some random byte to the first word of FLASH.
Any ideas what I've done wrong or missed out?
I know that the x4xx Family User's Guide (SLAU056H) states that "write transfers to the Flash memory succeed if the Flash controller set--up is prior to the DMA transfer and if the Flash is not busy" in Section 10.2.14, but it doesn't seem to be as simple as that. Do I need to do single transfers rather than a block transfer?
Thanks!
Derek