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.

Writing to particular memory address in TMS320F28027

Other Parts Discussed in Thread: CONTROLSUITE, TMS320F28027

I want to write to particular memory address in flash

So i have following code before main()

unsigned int i2c=0;

# define PORTBASE 0x003F6BB8

unsigned int volatile *const port=(unsigned int *) PORTBASE;

And inside main I have added

*port=0xAAAA;
i2c=*port;

I watch view when i monitor the variable i2c It shows value FFFF it dosent get changed to AAAA

Please guide its urgent

  • Ashutosh,

    You cannot write to flash. Flash has to be programmed. It is a more involved process. I don't know what your intention is so far as storage to flash, but you can program flash using the flash API functions for F2802x. These can be found in ControlSuite.

    As a general statement, the flash is intended to store code, and was not designed for frequent storing of data. In order to change a single word in flash, you need to erase the entire flash sector.

    - David
  • I have added above said code to existing program of flash in control suite

    But even though it is not working

    If you can store program code in flash why can't we store data at specified location

  • Ashutosh,

    Code and data are the same in terms of what is stored in flash. In both cases you're just storing a binary value. The difference between code and data is the usage. Code is typically not changed much, and when it is changed you change the entire code. Therefore, erasing all affected flash sectors is no problem. Data is typically changed frequently and/or just a single word at a time is changed. As I mentioned in my previous post, you cannot just erase a single word in a flash sector. The entire flash sector must be erased. To be more technical, a 1 bit can always be programmed to a 0 in flash, but in order to change a 0 back to a 1 you must erase the entire flash sector. Hence, I say that the flash is not intended to be used for data really. Some people do use the flash to store calibration data, error logging, and other stuff that doesn't change often. Alternately, people use two or more sectors of the flash as sort of a circular buffer. Suppose you have a block of 10 words that need to get recorded periodically. Instead of overwriting the block each time with the new values, you write the new values to the next 10 words available in the flash. You keep track of where the latest values are located (maybe you hunt for this on power-up, looking for one or more consecutive words of 0xFFFF in the flash, and then you backup to the last data block). When you fill up one sector and move to the next, you can then erase the previous sector. See the picture? At the extreme, people can implement a full-blown EEPROM emulation strategy with link lists that track the location of the latest value of a particular data object.

    In terms of you're saying the flash APIs are not working for you, focus on something simple first. Just try to get erase() to work. Have your code link something to a flash sector you are using for data (for example, link the .const section to a specific flash sector, and put nothing else in that sector). Use CCS to flash your code. Inspect the flash sector in a memory window. Your values should be visible. Now get your code to simply erase that sector using the flash APIs. Make sure you follow the instructions in the API documentation carefully.

    Regards,
    David
  • Dear David

    However if I go for emulated eeprom , I have to dedicate complete one sector which is almost 8kb for f28027 . while I need to store only three words to get stored and updated rarely. Won't it waste my capacity

  • Ashutosh,

    You are correct about EEPROM emulation using up a lot of flash. In fact, you need at least two flash sectors for EEPROM emulation so that you can erase one sector while the other retains the latest copies of the data. In my previous post, I was just stating what can be done from a device independent perspective. On F2802x, EEPROM emulation is impractical.

    If you only need to update your 3 words a limited times over the life of the product, you can reserve the needed amount of space in one flash sector and just update the data when needed. You will never be able to erase that sector however (unless you also re-program whatever else is in the flash sector, e.g., code). During code init, the code can start at the beginning of the flash array and search for the last entry (by looking for one or more 0xFFFFs). Or, you can use a flash word as a location indicator. Remember you casn always change a 1 to a 0, so you can set a bit to 0 in the word each time you update the data to the next position. In other words, 0xFFFF->0xFFFE->0xFFF8->0xFFF0, and so on. Then when you want to access the data, you read the indicator word and it tells you the offset that the latest data is stored at.

    Regards,
    David
  • Dear David,

    # define memory_address mem_points=(unsigned int *) 0x3F0005;

    Uint16 *mem_points;

    *(mem_points)=0xFFFE;

    1. I have wirtten above code for wirtting a word at particular memory location but its not changing the data at that location it is showing 0xFFFF

    2. Also in previous email u said, if I change only one bit from i.e 0xFFFF to 0xFFFE and then 0xFFFC at same memory location it is possible ( is this u mean) or to store FFFC I need to move to next address. While doing this I am making 1 to 0 not reverse way, thus I understand I can continue till all bits are 0000, this will final change.

  • Hello Ashutosh,

    Ashutosh Pailwan1 said:

    # define memory_address mem_points=(unsigned int *) 0x3F0005;

    Uint16 *mem_points;

    *(mem_points)=0xFFFE;

    1. I have wirtten above code for wirtting a word at particular memory location but its not changing the data at that location it is showing 0xFFFF

    As I said previously, you cannot "Write" to flash memory using regular code.  The flash must be programmed using the flash API functions provided by TI.

    Ashutosh Pailwan1 said:

    2. Also in previous email u said, if I change only one bit from i.e 0xFFFF to 0xFFFE and then 0xFFFC at same memory location it is possible ( is this u mean) or to store FFFC I need to move to next address. While doing this I am making 1 to 0 not reverse way, thus I understand I can continue till all bits are 0000, this will final change.

    You can write 0xFFFE, then 0xFFFC, and so on, at the SAME location.  In that way, each location can indicate up to 16 data block offsets.  If you need to update your data more than 16 times, you would use two indicator words, and so on.  Yes, you continue until the indicator word is 0x0000.  Then if needed, you'd go on to the next indicator word.

    Regards,

    David

  • can u share latest API for TMS320F28027
  • The flash APIs for F2802x devices can be found in Controlsuite here: C:\TI\controlSUITE\libs\utilities\flash_api\2802x

    If you do not already have Controlsuite installed on your PC, you can download it here: www.ti.com/.../CONTROLSUITE


    - David