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.

How to add watchdog to Flash API for F2837x?

Expert 1960 points
Other Parts Discussed in Thread: CONTROLSUITE

Hi Folks,

I'm trying to add watchdog to code around flash writing in case of lock up. To start with, I used the TI example flash_programming_cpu01 in controlSuite. I added ServiceDog() in user-defined function Fapi_serviceWatchdogTimer(), and also the code to enable and disable watchdog before and after flash writing (Example_CallFlashAPI()). However, the example does not work anymore afterwards. It always ended up in an Example _Error() function. It would work fine if I simply remove/comment-out "ServiceDog" line from Fapi_serviceWatchdogTimer(). You can try this easily by simply adding "SericeDog() in Fapi_serviceWatchdogTimer() in the TI example. Do you have any idea or suggestions on how and why? Thanks!

  • Shef,

    I will try it and let you know sometime this week or early next week.

    Thanks and regards,

    Vamsi

  • Thanks for your super-quick reply. You guys are awesome!
    I look forward to hearing from you again soon!
  • Shef,

    This is still in my to-do list.  Will try it on Friday.  

    Thanks and regards,

    Vamsi

  • Hi Vamsi,
    Thanks for the notes. I'm still waiting, and might have some related or follow-up question when you have a chance to look at it.
  • Shef,

    ServiceDog() function executes EDIS at the end to disallow writes to protected registers.  Flash API functions that execute after the ServiceDog() function are not able to write to Flash registers and hence the control is ending up in error function.  Try below code.  Include below header file as well.

    Thanks and regards,
    Vamsi

    #include "F2837xD_device.h" // Headerfile Include File

    Fapi_StatusType Fapi_serviceWatchdogTimer(void)
    {
    /* User to add their own watchdog servicing code here */

    ServiceDog();
    EALLOW;
    return(Fapi_Status_Success);
    }

  • Hi Vamsi,
    Thank you so much for getting this to work! Your solution makes a lot of sense. In fact, I found that I have to use "EALLOW" anytime when I call a function from flash API, perhaps for the same reason.
    One further question: if I have Memory Browser open in CCS debugger connected to the 28377D board. When the code writes into flash, the contents in Memory Browser will all changed to 0's or some strange numbers in red, indicating that the flash memory was corruppted. But if I reset MCU and refresh the Memory Browser, it shows correct contents. Is this normal, and is there anything I can do to avoid this? Thanks again!
  • Shef,

    Good that your watchdog integration works.

    Regarding Flash contents in memory browser:  Can you check the Flash wait-state value when this happens?

    Thanks and regards,
    Vamsi

  • Hi Vamsi,
    Please pardon my ignorance, but where do I check or set the flash wait-state value? Is it in CCS and which window? In my code, I just called the TI standard InitFlash() in F2837xD_SysCtrl.c which seems to set the wait state to 3.

    #if CPU_FRQ_200MHZ
    Flash0CtrlRegs.FRDCNTL.bit.RWAIT = 0x3;
    #endif
  • Shef,

    This looks correct. Did you check whether this is getting executed or not? You can check the value of this register in CCS registers window.

    Did you make sure that your SYSCLK is configured correctly as 200MHz? (Check your PLL configuration code).

    If yes, did you observe this in more than 1 unit?

    Which emulator are you using?

    Thanks and regards,
    Vamsi

  • Shef,

    Any update on this?

    Thanks and regards,
    Vamsi
  • Hi Vamsi,
    Thanks for getting back to me and sorry for not replying earlier. Yes I did confirm that the line above-mentioned about wait-state gets executed since the macro CPU_FRQ_200MHZ is defined as 1 in header file. I am not sure about SYSCLK yet but I guess that I can configured it to GPIO73 and watch it on scope. I just use the default setting in TI example code without change in PLL area. Here is a line in F2837xD_SysCtrl.c setting PLL:

    InitSysPll(XTAL_OSC,IMULT_20,FMULT_0,PLLCLK_BY_2);

    I use Blackhawk XDS560v2 and also the built-in XDS100v2, and have multiple boards to shuffle around. They are all the same. Similar symtom also happens if the code let watchdog timer to reset the MCU while connecting to the debugger with Memory Browser open. It's not a serious problem since I can always recover by reset MCU manually. But it'd be helpful if I can understand the root cause of this nuisance.

    I'd appreciate it if you have any further info or suggestions. Thanks!
  • Shef,

    Flash reads are not allowed/guaranteed during a program/erase operation and hence you notice this behavior. Close the Flash memory window during an erase/program operation. Reset causes Flash bank and pump to go to sleep and hence you noticed that behavior. You can ignore it.

    Thanks and regards,
    Vamsi