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.

CCS/MSP430F5438A: flash memory read/write

Part Number: MSP430F5438A


Tool/software: Code Composer Studio

I am trying to use the MSP430F5438A Experimenter's Board to complete a project for one of my classes. Currently I am using the User Experience Demo specifically the audio record/playback app.

My goal is to modify the audio data AFTER it has been recorded and stored in flash but BEFORE it is played back. Currently when I run the method, I can retrieve the data, but I cannot write it back to memory. Below is the function I use and it's location in the demo program. 

void audioRecord(unsigned char mode)
{
    unsigned char i;

    setupRecord();

    //...
    //...
    //...

    synthesizeVoice();  //my function is called
    shutdownRecord();
}
void synthesizeVoice(){
	unsigned long flash_loc;
	FCTL3 = FWKEY; // Unlock the flash for write
	FCTL1 = FWKEY + WRT;  //Set flash to write byte
	unsigned long FlashPtr;  //Long pointer to flash memory
	FlashPtr = PlaybackPtr;  //load starting location of audio
	for(flash_loc = AUDIO_MEMSTART; flash_loc <= lastAudioByte; flash_loc++){  //loop

		unsigned char data = (*((unsigned char*)FlashPtr));  //retrieve data from flash

		(*((unsigned char*)FlashPtr)) = (data + 1);  //modify data and store in flash at same location

		FlashPtr++;  //increment flash pointer location
	}
	FCTL3 = FWKEY + LOCK;                   // Lock the flash from write
	//char data[AUDIO_MEMEND-AUDIO_MEMSTART];
}

So far, I can think of a few solutions to the problem but I would like to get some advice on which route to pursue. 

Option 1) I do not erase the flash before writing to it. I have seen this mentioned several times on the E2E forms and I feel this could be why the (data+1) is not written to flash. Erasing the flash would not be efficient in the current design because the audio is written to flash in blocks using the DMA. There is usually a few thousand samples which means reading a sample, erasing that location, and rewriting it would need to happen a few thousand times and that would impossibly slow. 

Option 2) Instead of using the DMA to write to flash, I could read the ADC12MEM0 every interrupt and save the audio sample in RAM and modify it there. However this would take a lot of rewriting of the demo and I am not very experienced with MSP430. Another potential problemcould be the speed of the reading of ADC12MEM0, modifying, and storing in flash before the next audio sample is read in. 

I appreciate any help with this and that you for your time. 

  • LC,

    Kasthuri and I think option 2 is best but we don't what are your performance requirements.   In general if you are doing a bunch of write and re-writes you should use RAM not flash because a lot of flash writes will degrade the flash (and its slow).  

    Chris

  • Flash must be erased before writing. In source code each byte in flash is updated without erasing.

    Don't know about writing to flash by DMA, but if speed is important, than for 5xx should be used flash block writing with smart bit enabled (250 KByte / sec).

**Attention** This is a public forum