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.

Flash routine in section sysmem seems not reliably initialised

I'm encountering a silly problem with a flash routine that is declared to work in sysmem RAM section (CCS4), but sometimes thisRAM section seems disturbed shortly after power-up. Hard to believe that it is overwritten by a stack, since the stack usage is really limited.

Therefore I want to review the startup code (auto_init), But I don't find it in the ccsv4\ools\compiler\msp430 directory. It looks like it is contained in object form. Is that true?

The function in RAM especially tends to get corrupted when the target device is run without attached debugger. Any suggestions to localize the problem is appreciated.

The flash function is taken from old sample fet40_flashwrite_02, but avoiding the silly RAM copy mechanism:

#define FLASH_START (char *)0x1000

#pragma CODE_SECTION (flash_write, ".sysmem")

/*
 * this function also erases the flash segment
 */
void flash_write(void *data, unsigned int size)
{
    int i;                           // Use as write counter
    char *Flash_ptr = FLASH_START;            // Initialize Flash pointer
    char *ptr = data;
    
    FCTL2 = FWKEY | FSSEL1 | 19;            // MCLK/2 for Flash Timing Generator
    FCTL1 = FWKEY | ERASE;                  // Set Erase bit
    FCTL3 = FWKEY;                          // Clear Lock bit
    _DINT();
    while(FCTL3 & BUSY);                      // Check Flash BUSY bit
    FCTL1 = FWKEY + ERASE;                  // Set Erase bit
    FCTL3 = FWKEY;                          // Clear Lock bit
    
    *Flash_ptr = 0;                         // Dummy write to erase Flash segment
    while(!(FCTL3 & WAIT))                 // WAIT until Flash is ready
        ;
    while(FCTL3 & BUSY);                      // Check Flash BUSY bit
    FCTL1 = FWKEY + BLKWRT + WRT;             // Enable block-write operation
    for(i = 0; i < size; i++)
    {
        *Flash_ptr = *ptr;                     // Write value to flash
        Flash_ptr++;
        ptr++;
        while(!(FCTL3 & WAIT))                 // WAIT until Flash is ready
            ;
    }
    FCTL1 = FWKEY;                            // Clear BLKWRT & WRT bits
    while(FCTL3 & BUSY)                      // Check Flash BUSY bit
        ;
    FCTL3 = FWKEY + LOCK;                     // Reset LOCK bit
    _EINT();
    return;                                   // Exits routine
}


  • Well, Rob,

    indeed, any code that is assigned to a RAM section is not automatically placed in a const table like the global variable section.

    the code in boot only copies global & static function variables.

    Note: due to a deadline, I have simply created a copy of this function in another file, with _rom suffix and without section assignment, and then added a simple copy function. This way, calls to the RAM function are with normal symbolic name, instead of saying asm("CALL #300h") or so.

  • Indeed, placing a funciton in ram doe sdexactly this: it places the function in ram. If you're lucky, the FET will copy the function code into ram. If you're unlucky, nothing is copied at all. And even if, after a power-cycle it's gone. (If it's just a short power loss, most of it may still be intact)

    To have the function located in ram, but placed in rom and copied over at program start, the function must be handled like initialized variables.
    You can place the function in the same segment as initialized variables, so it is just landled like them.
    Some compilers have a specific __ramfunc qualifier, or similar ways of marking such functions.

  • Thanks Jens-Michael,

    your answer documents (for me) once more the difference in terms of value when I speak about the different forums here. When I post a message in the Stellaris Forum, I get almost 100% chance that a reply comes from a TI guy. In the MSP430 forum, this tends to go to 0%. That's a pity. Of course, MSP430 is very mature, compared to Stellaris, and TI apparently believes that more value vor money can be gained by supervising forums related to hi-market stuff. Again, that's a pity, since MSP430 is still an optimum choice for lowest power and optimum mixed-signal performance. And still a great instruction set amongst the micros out there.

    -Rob 

  • Well, getting an answer from a TI guy doesn't say anything about the quality of the answer. There are TI guys asking for help themselves in the forum. Workign for TI does not mean that you're an experienced applications engineer. You might be a member of the sales department getting a customer request. Or a forum administrator without any technical knowledge at all.

    Also, I fear that the fact that you'll get an answer from a forum member is the reason why the MSP forum doesn't get so many answers by TI officials. The MSP forum is the one with the highest average experience level amongst the long-time users.
    The first three gurus in the whole E2E community were MSP forum users. There are lots of highly skilled people around here. Mark Tenney, Berhard Weller, Roberto Romano, Old Cow Yellow, Peter Bigot and some others.
    So if any of them has an answer, ther eis no need for a TI official to give one. Unless the answer is that no answer can be given, or is obviously wrong, or nobody answers ona question that hasn't been answered a hundred times in other threads.

    Just reading the new threads every day takes about an hour (more on mondays). Answering a few adds another one or two. So why wasting this time on a forum that 'works' fine, just to show 'presence', when it is dearer needed in other forums (like the Stellaris :) )

    When I started here about two years ago, almost each thread had an 'official' answer. That doesn't mean that there are so much less now, just that there are so many more threads now. Still every now and then an official (Katie, Brandon, sometimes Priya, others) writes an answer with corrections or additional information. But usually, it's simply not needed.

    I agree with you about the MSP and its value (even if there are people who think that any microcontrolle below 1GHz and some MG of flash/ram isn't worth to deal with, as it won't run Microsoft .NET for microcontrollers or other huge bloated frameworks).
    But showing less 'presence' doesn't mean it is less valued by TI. Just that there is less need of writing.

    Peronally, I tend to go the same way: If I see a thread wher ethe answer is relatively simple but would take some time to write, I just put it on the heap and wait if someone else answers. If not, I do next day or so. If, and I don't have anything significant to add, I proceed. Else I couldn't keep up with the traffic at all.

    Don't forget, it's not just your question that wants to be answered. And answering your question is not the only thing someone has to do the whole day. Most of the Ti officials here have other duties. Like building new EXP boards, writing new example programs, working on improving the documentation. Nobody who's skilled enough to answer MSP detail questions will be hired for just working on the forum all day long. That's usually an additional duty, but not the main one.

    So don't be sad that you didn't get 'official' attention. Be happy that you got an 'independent' answer, and if it's not enough to solve your problem, you can still ask for more.
    On other (even big) companies, the only way to get help is a call center in India, and the people there often don't know at all what they (or you) are talking about - if you can understand them at all. Or a mail address from where you get standard text snippets back.

  • Oops, that's a very extensive answer. I feel a bit like Job may have felt after God's monologue when he terminates Job's miserable personal state...

    Thanks for that bit explanation regarding the matureness of a product that may indeed lead to a situation where non-officials "rule" the msp forum. Sounds plausible. Regarding Stellaris: no doubt about the quality of the official support there!

    I think that's enough off-topic now.

    Approx. 12 years ago, as I started with msp430, I worked mainly with IAR. I rejected CCS e.g. due to several reasons. Now, after a pause of 6 years I forgot that. Now I'm again confronted with the drawbacks of the ccs compiler. I'll live with it, next time, since eclipse has become the IDE of choice for me.

    -Rob 

  • Rob Maris said:
    Oops, that's a very extensive answer.

    It was meant not only for you alone, but for everyone else reading this thread and wondering.

    Rob Maris said:
    I feel a bit like Job may have felt after God's monologue when he terminates Job's miserable personal state...

    I'm only 'guru' :)

    Rob Maris said:
    Approx. 12 years ago, as I started with msp430, I worked mainly with IAR. I rejected CCS e.g. due to several reasons.

    I too think that IAR is (still) the more mature product from users view, but CCS is faster adapting new features and integrates better with other processors (e.g. stellaris) and of course if you're used to Eclipse (Java coding, Flex builder), it feels more 'familiar'.
    Personally, I started with mspgcc and still use it. :)

  • Yes, mspgcc also was finally my compiler of choice. Only disadvantage was lack of debugger support that includes views of special function registers. I'd immediately move to mspgcc when debugger lacks are a mere minor nature now.

**Attention** This is a public forum