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.

Strange behavior while writing to flash without using the API

Other Parts Discussed in Thread: TMS570LC4357

Hello,

First, I want to say I know you cannot write to flash like you would do RAM, you need to use an API.

I use a TMS570LC4357 and CCS5.5 with compiler V5.1.8.

My question is, why when I write to flash using a pointer, I can read back the value even if it was not really written in flash. I would expect the write to have no effect and to be able to read back the value in flash.

For example, I use a pointer to access address 0x000991D0 located in my program in flash and this address contains an instructions continuously used by my program in the idle loop.

If I do “variable = *((unsigned long *)0x000991D0L)”, the variable takes value 0xE35C0FFA which is a BLT instruction. This is the behavior I would expect.

If I do “*((unsigned long *)0x000991D0L) = 10L” and then “variable = *((unsigned long *)0x000991D0L)”, the variable take value 10. I know the flash was not changed because my program still runs. But I would expect the variable to still have value 0xE35C0FFA.

If I connect with an XDS510 emulator, in the Eclipse memory browser I see value 10 at address 0x000991D0L. If I do a CPU reset, the value is still 10 and when I do a System reset the value goes back to the original value of 0xE35C0FFA.

I would like to understand why this is happening. Apparently reading memory and instruction fetching don’t return the same value. Did I just find 4Mb of extra RAM?

Thanks,

Martin

  • Hello Martin,

    You are writing to the data cache (32KB), and also reading it back from the data cache thereafter. It is a write-through cache and you are right in that the value 10L will not get written to the flash memory, but the data cache still gets written with 10L.

    You should configure an MPU region to define the 4MB flash memory as a read-only region. This way the MPU can signal a fault when you acidentally try to update a location that falls in the flash memory space, but may get updated in cache.

    Regards,
    Sunil