1

I am writing some device parameters to non volatile flash memory of msp430f2619 controller. Sample code shows that function writing to flash should be copied to RAM in initialization section.

But I am using this function to write into dedicated few of the Flash segment. ( Actually I am writing to Information memory segment B )

So is it really necessary to copy this code in RAM.

I am running low on RAM and by freeing this memory for storing flash write function I can use it for my application.

prasad
  • 169
  • 10
  • Link to sample code? – Passerby Aug 21 '15 at 23:57
  • And if this is a one time write, write it to flash once then change your code to just read. – Passerby Aug 21 '15 at 23:58
  • Your micro will get programmed faster, and the code will run faster when writing into RAM, but there is usually no requirement that you put your code there. Code Composer has a nice memory view that will allow you to spot which sectors of flash/RAM have space available so that you can alter your linker and move things around to suit your needs. – RYS Aug 22 '15 at 00:31

1 Answers1

2

No it's not necessary.

You can write on the information memory while the code with the writing instructions is executed from flash. Not only the information memory, but the whole flash (except the code section which actually writes the flash) can be written from flash.

Actually the flash controller of the MSP430 handles it quite intelligently, while it states in big scary sentences that:

Reading from or writing to flash memory while it is being programmed or erased is prohibited. If CPU execution is required during the write or erase, the code to be executed must be in RAM.

This sounds a bit intimidating at first, but if you read through the whole chapter (highly recommended) you will stumble upon information which tells you, that while the flash controller is busy, a read from the CPU will return 0x3FFF which turns out to be the opcode for JUMP PC (jump to the program counter) which will just stall the CPU until the flash controller is finished doing it's thing. (2)

The block write mode is not supported from flash, so you won't be able to get the fastest write times if you execute your write from flash. I'd say if you just want to write some calibration values or serial numbers, it won't matter much. If you try to implement your own bootloader to flash the whole device, you better run it from RAM and use the block write mode to gain speed.

Just be careful with the erase instruction first to actually delete only the stuff you need to delete, I accidentally lost all calibration information once because I wasn't.

Arsenal
  • 17,464
  • 1
  • 32
  • 59
  • The most useful method is the block write mode, which does *not* work from flash code. – CL. Aug 22 '15 at 07:04
  • @CL. whether or not the block write mode is the most useful method depends strongly on the application, but I've added a paragraph about block write mode and the restriction to only execute it from RAM. – Arsenal Aug 22 '15 at 07:58