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.

Tiva registers do not reset between debug sessions



Hi,

I'm just starting out with the Tiva TM4C123 launchpad and CCS. I noticed that after I modify my program and start a debug session (which loads the new program), the register values visible in the debugger are the same as they were from the previous run. I expected that loading a new program will reset the target, and thus set all the registers to their reset values described in the datasheet. that is however not the case.

I found and checked the options "reset the target on a program load or restart" and "restart the target on a symbol load as well as a program load". I expected these are exactly what will solve this, but it changed nothing.

this behavior can be a source for bugs - for example, as I fiddle with various initialization commands for a peripheral, I can reach a state where it finally works and I think my code is correct - but it only worked because of a combination of the current code and some previous code runs that modified registers, which never went back to their initial power-on state... running this supposedly good code on a "clean" device (e.g. after power off) will result in incorrect behavior.

so, how can I make all the registers automatically revert to their proper reset values that I see in the datasheet?

thanks,

Guy.

  • Hi Guy,

    the register values visible in the debugger are the same as they were from the previous run.

    We would like to get more info on what values did you modify and what register values are you checking in the expression window.

    Just attach the code stating the modified value  and the default value in comments. Until we've a look at the code commenting on this would be unfair.

    Regards,

    Gautam

  • Guy Ovadia said:
    I expected that loading a new program will reset the target, and thus set all the registers to their reset values described in the datasheet. that is however not the case.

    I have also found that on connecting CCS doesn't perform a full reset, in that when started a new debug session with a modified program that some registers could be left at the values from the previous run. Found that executing system reset (Ctl+Shift+S) in the debug session would perform a full reset.

    Can't remember for the Tiva TM4C123 launchpad if found a CCS project option to perform a full reset on starting a debug session. [The possible reset methods vary according to the emulator / device in use].

    See also http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/316375/1123688.aspx#1123688

  • Hi,


    here is a simple program that reproduces the issue I'm talking about, even without checking register values directly in the debugger (instructions below):

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    
    #define RED_LED   GPIO_PIN_1
    #define BLUE_LED  GPIO_PIN_2
    #define GREEN_LED GPIO_PIN_3
    
    int main(void)
    {
        SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
        SysCtlDelay(10);
    
        GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED);
        // GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RED_LED);
    
        while(1)
        {
            GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED,RED_LED|BLUE_LED|GREEN_LED);
            SysCtlDelay(2000000);
            GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, 0);
            SysCtlDelay(2000000);
        }
    }
    

    this is used with the Tiva TM4C123 launchpad. notice there are two calls to GPIOPinTypeGPIOOutput(), one of them is commented out. to reproduce the confusing behavior, follow these steps:

    1. first build the program as it is.

    2. press the debug button, which will switch to debug perspective and load the program to the launchpad.

    3. press the red "stop" button to exit the debug mode.

    4. the program now runs in the launchpad and the LED flashes white (all R,G,B channels of the LED work). So far so good.

    5. now, comment out the first call to GPIOPinTypeGPIOOutput() and uncomment the second one.

    6. Again, build the program, press the debug button, and once it's loaded press the stop button.

    7. The expected behavior at this point is that the LED will flash in red, as only the pin connected to the red LED is set up as output (the other pins should be at their default mode after reset, which is input mode). however, it actually flashes white (i.e. with all pins active), just as before, because the pin direction register remembers its value from the previous run and it was not reset to the default state.

    8. now, turn off the power to the launchpad board and then turn on again. suddenly the LED flashes in red as the code in it was supposed to do in the first place.

    this behavior is confusing, especially when debugging something much more complex than this simple example. unless I remember to manually reset the board for each test-run, the test-runs will not give a true indication of whether my code is correct or not.

    Thanks for the "system reset" tip, Chester - I discovered this myself too after posting. However it's still manual and it's easy to forget to do that, especially since it "feels" ok if you don't - after all, the code does run, only with subtly altered behavior, which may go unnoticed... this could lead to nasty bugs for someone not familiar with this issue - one time it works, another time (after power cycling) it doesn't, and it feels like a problem just magically appeared or disappeared...

    I found no way to do a "system reset" automatically after program load - the reset-after-program option I found did not change the behavior described above. anyone has an automated solution?


    thanks,

    Guy.

  • Guy Ovadia said:

    I found no way to do a "system reset" automatically after program load - the reset-after-program option I found did not change the behavior described above. anyone has an automated solution?

    Have you tried enabling the "Reset target during program load to Flash memory"  checkbox in the On-chip Flash settings? You can get to it from menu Tools->On-chip Flash (you will need to be connected to target first).

  • AartiG said:
    Have you tried enabling the "Reset target during program load to Flash memory"  checkbox in the On-chip Flash settings?

    I tried that option with CCSv6 and a Tiva launchpad - and confirm that the device registers were reset when the program was loaded.

  • thanks, that did the trick :) In my opinion, it would be a good idea to make this option the default.

  • I have filed an enhancement request so the relevant team can analyze whether it makes sense to enable this by default. The tracking # is SDSCM00050049.

  • All,

    When we implemented this feature, we decided to leave the default value of this option to off. This is because performing a reset might introduce unexpected behaviour of the device, which will sometimes affect Flash Programming.

    I will try to ask around to see if there is a better to handle this case, but for now, please set this option for your case as needed.

    Thanks,

    Ricky

  • Hi, I know that there is a reset button on the Tiva c series launchpad. But, is there any way to reset the program without pressing the reset button but to use programming code? 

  • Kent Wong said:
    But, is there any way to reset the program without pressing the reset button but to use programming code?

    If you mean the device resets itself under program control, the TivaWare SysCtlReset() function performs a software reset of the entire device.