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/TM4C1294NCPDT: FlashProgram Not multiples of 4

Tool/software: Code Composer Studio

Dear team,

I have the same question. 

I am doing online upgrade function. The byte size of the updated file is not a multiple of 4, but FlashProgram(uint32_t *pui32Data, uint32_t ui32Address, uint32_t ui32Count) This function address and the number of bytes must both be multiples of 4. What should I do? 

Below is the description taken from peripheral driver library pdf :

  FlashProgram

Programs flash.
Prototype:
int32_t
FlashProgram(uint32_t *pui32Data,
uint32_t ui32Address,
uint32_t ui32Count)
Parameters:
pui32Data is a pointer to the data to be programmed.
ui32Address is the starting address in flash to be programmed. Must be a multiple of four.
ui32Count is the number of bytes to be programmed. Must be a multiple of four.
Description:
This function programs a sequence of words into the on-chip flash. Each word in a page of
flash can only be programmed one time between an erase of that page; programming a word
multiple times results in an unpredictable value in that word of flash.
Because the flash is programmed one word at a time, the starting address and byte count
must both be multiples of four. It is up to the caller to verify the programmed contents, if such
verification is required.
This function does not return until the data has been programmed.
April 11, 2013 99
Flash
Returns:
Returns 0 on success, or -1 if a programming error is encountered.

Please help.

  • The answer depends on what is in the flash before you start programming. Let's assume that you start at a word boundary but need to program 6 bytes. Pad your buffer with two bytes of 0xFF and program 8 bytes. Now you want to add another 6 bytes to the array, but want to start at then end of the last valid data. First read the word that contains the last two bytes of data and the two bytes of 0xFF. Pre-pend your new buffer with the last two bytes from the previous data, followed by the new 6 bytes. Program 8 bytes starting at address offset of 4 into the flash array. When programming, you can only turn 1's to 0's. Programming the same values over in the same location does not affect the data. Programming a byte to a value of 0xFF leaves it unchanged.