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.

CCS/TM4C129ENCPDT: Code start from debugger behaves differently than from Power-cycle

Part Number: TM4C129ENCPDT

Tool/software: Code Composer Studio

I am using TIVA RTOS with NDK.  Here is my code - 

The main task at the bottom, calls the board.h functions to start up the chip peripherals.  Then an init task is started, top function, to do the remainder task creation.

The NDK is started and when the iniTaskFxn task completes the network is supposed to be up and running. 

/******************************************************************************
 * initTaskFxn
 * init task
 *
 * called from Scheduler to initialize application.  This function:
 * 1) sets up the eeprom
 * 2) validates the contents of the eeprom
 * 3) reads and instantiates the parameters
 * 4) calls all task init functions
 *
 * @param arg0 - task parameter
 * @param arg1 - task parameter
 * @return none
 *
 *****************************************************************************/
void initTaskFxn(UArg arg0, UArg arg1)
{
    // intialize the EEPROM hardware 
    initEEPROM();

#if 0
    //*****JKP - Remove - test only
    EEPROM_Format();
    //**** JKP - End Remove
#endif

    // copy the default parameters into the working parameters
    memcpy(&WorkingConfigParams, &DefaultConfigParams, sizeof(Config_Params_t));

    // set the temporary parameters to the default parameters
    // When parsing the JSON, only those parameters contained in the JSON
    // are updated. Missing JSON parameters are defaulted to the default values.
    memcpy(&TempConfigParams, &DefaultConfigParams, sizeof(Config_Params_t));

    // get the board id
    BoardId = IPMI_GetBoardID();

    // Check the eeprom and extract the current configuration parameters
    // If the eeprom is not setup, it will format the eeprom.
    EEPROM_Open();

    // at this point, the WorkingConfigParams are valid.
    System_printf("eeprom open\n");
    System_flush();

    // signal the EEPROM parameters is completed
    Semaphore_post(EEPROM_Semaphore);
    eepromIsOpen = true;

    // wait for the network
    Semaphore_pend(Network_Semaphore, 0);
    while(!networkIsOpen)
    {
      Task_sleep(1000);
    }

    // call the board gpio function with the board Id
    Board_initGPIO(BoardId);

    // Start the IPMI UDP socket task
    initPIC_IPMI();

    // Init the UDP configuration update task
    initConfigUpdate();

    // Board specific task initializations
    if(BoardId == BOARD_TYPE_CPU)
    {
        // ARcpu board

        // Setup the switch based on the parameters
        initSwitchConfig();

        // Start the Console UART task
        initConsole();

        // check that the EMAC link is up - else do a cpu reset
        Task_sleep(2000);
        if (EMACSnow_isLinkUp(0) != true)
        {
            SysCtlReset();
        }

        Console_printfStr("CPU board is ready ... \n\r");
    }
    else if(BoardId == BOARD_TYPE_EIO)
    {
        // AReio board
        // Start the GPIO UDP and TCP tasks
        initGPIO();

        // Start the RS232 UDP and TCP tasks
        initNetRS232();

        // Start the RS422 UDP and TCP tasks
        initNetRS422();
    }
    else
    {
        // Bad Board ID
        // TODO - error handler here

    }

    // spawn the registered UDP/TCP socket tasks
    InitSocketConfig();

    // this task ends and is never called again.

}


/******************************************************************************
 * main
 * Entry point for the application
 *
 * @param void
 * @return application exit value
 *
 *****************************************************************************/
int main(void)
{
    // local task setup structure
    Task_Params taskParams;
    // local SPI parameters
    SPI_Params Spi0Params;

    // crc_pointer = (uint32_t *) &_text_crc;

    // setup up initialization flags
    eepromIsOpen = false;
    networkIsOpen = false;

    /* Call board init functions */
    Board_initGeneral();
    // initialize the Ethernet peripheral
    Board_initEMAC();
    // Initialize the GPIO
    Board_initGPIO(BOARD_TYPE_UNKNOWN);
    // initialize the board spi's
    Board_initSPI();
    // initialize the UARTs
    Board_initUART();

    // Open the EEPROM SPI port
    SPI_Params_init(&Spi0Params);

    // Initialize the SPI peripheral that is connected to the EEPROM and the switch chips
    Spi0Handle = SPI_open(Board_SPI0, &Spi0Params);
    if (Spi0Handle == NULL)
    {
        System_abort("EPROM SPI_open failed\n");
    }

    // create a hardware mutex to the EEPROM/Switch SPI
    GateMutex_construct(&(SPI0gate), NULL);
    
    // create a semaphore to the EPROM/Switch spi bus
    Semaphore_Params    EEPROM_SemParams;
    Semaphore_Params_init(&EEPROM_SemParams);
    EEPROM_SemParams.mode = Semaphore_Mode_BINARY;
    EEPROM_Semaphore = Semaphore_create(0, &EEPROM_SemParams, NULL);
    Semaphore_Params    Network_SemParams;
    Semaphore_Params_init(&Network_SemParams);
    Network_SemParams.mode = Semaphore_Mode_BINARY;
    Network_Semaphore = Semaphore_create(0, &Network_SemParams, NULL);

    // Create the Initialization Task
    Task_Params_init(&taskParams);
    taskParams.priority = 8;
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)initTaskFxn, &taskParams, NULL);

    // initialize the Boot loader
    initBootLoaderUpdate();

    // compute the application CRC
    uint32_t mycrc =     getCrc();
    // SysMin will only print to the console when you call flush or exit
    // FORDEBUG
    // JumpToBootLoader();

    // print any pending messages to the debug console.
    System_flush();

    // start the RTOS system

    // Start BIOS - kick off the tasks
    BIOS_start();

    return (0);
}

I am having an issue during startup of my code.

1) using the debugger, the code always starts and behaves properly.

2) When I take the debugger probe off and cycle power, my application does not behave normally.  The NDK does not startup properly.  The code appears to startup however the network does not function.  The initTaskFnx creates some UDP and TCP tasks. When a power-cycle these tasks appear not to run.

3) If I put cause an external reset the code starts up properly and the network UDP/TCP tasks operate normally.

4) I have tried to detect a POR using the SysCtrlCauseGet() and perform a software reset via SysCtlRest(), but this does not work.  Only an external reset strobe on the reset pin.

5) I have also loaded the code using the UNIFLASHER, but the result is the same.  

Questions:

1) what is the difference between code starting up from a debugging session vs from power up?  

2) When I load code using the debugger, and then remove the debugger, and then power cycle the board - should this work properly?  it does not.

3) What is the difference between RELEASE CODE and DEBUG code?

4) Is there a difference between loading the code using the debugger and the Uniflasher?

  • Hi,

    Thanks for such detailed post and thorough debug. This scenario is quite common when bringing up code from a cold boot / power up and is usually related to incomplete or out-of-order initialization of either internal or external peripherals. 

    1) The major differences can be tied to both an initialization script on the debugger (a GEL file) or the fact a previous run left the device and its external peripherals partially initialized. In the specific case for the TM4C1294, the GEL file does not perform any hardware initialization, thus leaving the most probable cause the second one. 

    Combining your assertives 1) and 2) above, I am lead to believe that either:

      - an external peripheral (PHY) may need extra delays to be properly initialized after power up. Since the debugger usually halts at main(), this requirement is fulfilled;
      - the internal MAC or external PHY may contain pre-configured settings from the previous run that make it work properly. At power cycle, everything is being executed for the first time and therefore all registers and configurations are set to their reset values. 

    Your assertives 3) and 4) above give me two alternatives:

       - if the SysCtlReset() is a warm reset, the internal perihperals (MAC) may not have been reset and contain pre-configured settings from the previous run. A pin assert may perform a deeper reset that also initializes the peripherals. 
       - the external peripheral (PHY) may not be properly initialized at the first code run, either due to the aforementioned required delays or executing out-of-order initilalization steps. A cold reset on the device would fulfill either the delay or fulfill the missing initialization steps.  

    2) Yes, provided the initialization is done properly. 

    3) Mostly the optimizer is turned on ( the -o option in the Compiler options), but other options can also be explored. 

    4) In general, no - unless CCS is configured in a very non-standard way.  

    I will also notify the device experts as they may have additional insights. 

    Hope this helps,

    Rafael

  • Thank you for your quick response.

    Yes, I agree its in the EMAC peripheral that seems to not get setup in time.  Most of my other peripherals seem to work properly - but the Ethernet capability does not.

    1) Note we are using the TIVA RTOS, so a lot of the initialization is out of our control.  

    - Is there anything we should do differently in the configuration of the Ethernet configuration?

    - what about the priority of the Ethernet tasks?

    - most of my other tasks are set at a priority of 6,7 or 8.

    - Should I start a special Ethernet task to wait for the Ethernet task to start up first?

    1) In my main() -

    a) should I change the order of the initialization?  These functions are from board.h/

    b) Should I call another routine first?

    c) Are there other startup routines I should call first

    d) Is there a status or flag I should check to make sure the MAC/PHY network services are setup properly?

    e) Where would you put the startup delay and how would you do this?

    - I put a delay in the initTaskFXN - task_sleep(2000) but this does not help.

    - I have put in delay at the start of main  using a for loop - 

    for (i=0;i<10000;i++)

    but this may get optimized out - is there a better way?

    f) Is there a flag I can check to make sure the MAC/PHY are ready to go?

    Thanks for your help.

  • Hi Jon,

    I can't answer all of your questions, but I'll respond to what I can.

    1) Your Ethernet configuration looks fine. For NDK stack tasks the NDK documentation recommends a priority of OS_TASKPRINORM, which in <ndk_install_dir>/packages/ti/ndk/inc/nettools/netcfg.h is defined as 4.

    The recommended approach for using the NDK can be seen in the network examples provided with the SDK, as you may have seen. Networking tasks within an application are typically started from a user defined function that is called by the NDK's networkOpenHook(), which is called after the NDK scheduler starts.

    What task or function calls Semaphore_post(Network_semaphore)?
    Are you calling it from the NDK's networkOpenHook()? Do you have a hook function attached to the networkOpenHook() function in your application?

    When you say that the network tasks appear not to run in the case where the debugger is not attached, where do you see the failure? Are the calls to Task_create() called?

    What version of tirtos and the ndk are you using? In case we need to reference this later.

    Regards,
    Brandon

  • In answer to you question -  the semaphore is done in the NetOpenHook.

    void netOpenHook()
    {
    networkIsOpen = true;
    Semaphore_post(Network_Semaphore);
    }

    We solved the problem by putting in a large delay, about 3 seconds, before the call to BIOS_Start(). See line 75:

    QUESTION - can you tell me WHY this delay fixed the problem?

    int main(void)
    {
    // delay to allow system hardware to initialize
    SysCtlDelay(100000000);

    // local task setup structure
    Task_Params taskParams;
    // local SPI parameters
    SPI_Params Spi0Params;

    // setup up initialization flags to enable custom IP addr/mask setup
    eepromIsOpen = false;
    networkIsOpen = false;

    /* Call board init functions */
    Board_initGeneral();
    // initialize the Ethernet peripheral
    Board_initEMAC();
    // Initialize the GPIO
    Board_initGPIO(BOARD_TYPE_UNKNOWN);
    // initialize the board spi's
    Board_initSPI();
    // initialize the UARTs
    Board_initUART();

    // Open the EEPROM SPI port
    SPI_Params_init(&Spi0Params);

    // Initialize the SPI peripheral that is connected to the EEPROM and the switch chips
    Spi0Handle = SPI_open(Board_SPI0, &Spi0Params);
    if (Spi0Handle == NULL)
    {
    System_abort("EPROM SPI_open failed\n");
    }

    // create a hardware mutex to the EEPROM/Switch SPI
    GateMutex_construct(&(SPI0gate), NULL);

    // create two semaphors to sync the networking system to enable
    // setting the custom IP address and mask. The IP address must be
    // set after the EEPROM JSON is read, but before the network init has
    // completed. These semaphores are used for this synchronization.
    // create a semaphore to the EPROM/Switch spi bus
    Semaphore_Params EEPROM_SemParams;
    Semaphore_Params_init(&EEPROM_SemParams);
    EEPROM_SemParams.mode = Semaphore_Mode_BINARY;
    EEPROM_Semaphore = Semaphore_create(0, &EEPROM_SemParams, NULL);
    // create a semaphore to the Network
    Semaphore_Params Network_SemParams;
    Semaphore_Params_init(&Network_SemParams);
    Network_SemParams.mode = Semaphore_Mode_BINARY;
    Network_Semaphore = Semaphore_create(0, &Network_SemParams, NULL);

    // Create the Initialization Task
    Task_Params_init(&taskParams);
    taskParams.priority = 8;
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)initTaskFxn, &taskParams, NULL);

    // initialize the Boot loader
    initBootLoaderUpdate();

    // compute the application CRC
    uint32_t mycrc = ComputeAppCrc();
    // SysMin will only print to the console when you call flush or exit
    // FORDEBUG
    // JumpToBootLoader();

    // print any pending messages to the debug console.
    System_flush();

    // - delay before starting to enable other initializtion
    //***** DONOT CHANGE *****//
    SysCtlDelay(100000000);
    //***** DONOT CHANGE *****//

    // start the RTOS system
    BIOS_start();

    // exit - never returns - RTOS schedule takes over
    return (0);
    }

    int main(void)
    {
        // delay to allow system hardware to initialize
        SysCtlDelay(100000000);
    
        // local task setup structure
        Task_Params taskParams;
        // local SPI parameters
        SPI_Params Spi0Params;
    
        // setup up initialization flags to enable custom IP addr/mask setup
        eepromIsOpen = false;
        networkIsOpen = false;
    
        /* Call board init functions */
        Board_initGeneral();
        // initialize the Ethernet peripheral
        Board_initEMAC();
        // Initialize the GPIO
        Board_initGPIO(BOARD_TYPE_UNKNOWN);
        // initialize the board spi's
        Board_initSPI();
        // initialize the UARTs
        Board_initUART();
    
        // Open the EEPROM SPI port
        SPI_Params_init(&Spi0Params);
    
        // Initialize the SPI peripheral that is connected to the EEPROM and the switch chips
        Spi0Handle = SPI_open(Board_SPI0, &Spi0Params);
        if (Spi0Handle == NULL)
        {
            System_abort("EPROM SPI_open failed\n");
        }
    
        // create a hardware mutex to the EEPROM/Switch SPI
        GateMutex_construct(&(SPI0gate), NULL);
        
        // create two semaphors to sync the networking system to enable
        // setting the custom IP address and mask.  The IP address must be
        // set after the EEPROM JSON is read, but before the network init has
        // completed.  These semaphores are used for this synchronization.
        // create a semaphore to the EPROM/Switch spi bus
        Semaphore_Params    EEPROM_SemParams;
        Semaphore_Params_init(&EEPROM_SemParams);
        EEPROM_SemParams.mode = Semaphore_Mode_BINARY;
        EEPROM_Semaphore = Semaphore_create(0, &EEPROM_SemParams, NULL);
        // create a semaphore to the Network
        Semaphore_Params    Network_SemParams;
        Semaphore_Params_init(&Network_SemParams);
        Network_SemParams.mode = Semaphore_Mode_BINARY;
        Network_Semaphore = Semaphore_create(0, &Network_SemParams, NULL);
    
        // Create the Initialization Task
        Task_Params_init(&taskParams);
        taskParams.priority = 8;
        taskParams.stackSize = TASKSTACKSIZE;
        taskParams.stack = &task0Stack;
        Task_construct(&task0Struct, (Task_FuncPtr)initTaskFxn, &taskParams, NULL);
    
        // initialize the Boot loader
        initBootLoaderUpdate();
    
        // compute the application CRC
        uint32_t mycrc = ComputeAppCrc();
        // SysMin will only print to the console when you call flush or exit
        // FORDEBUG
        // JumpToBootLoader();
    
        // print any pending messages to the debug console.
        System_flush();
    
        // - delay before starting to enable other initializtion
        //***** DONOT CHANGE *****//
        SysCtlDelay(100000000);
        //***** DONOT CHANGE *****//
    
        // start the RTOS system
        BIOS_start();
    
        // exit - never returns - RTOS schedule takes over
        return (0);
    }

  • Hi,

    I am checking with a colleague and will respond once I know more.

    Brandon

  • Hi Jon,

    Despite your solution, it's still not clear what the underlying issue was.

    Some questions to help narrow it down:

    1. Is your IP configuration dynamic or static?
    2. Before you put the delay in that solved your problem were you able to receive an IP address?
    3. If you are able to receive an IP address, can you successfully ping it?

    Also an approach that may take some effort is: if you made your application simpler, and tested it with and without the debugger attached, do you see the same behavior?

    Brandon

  • 1) the IP address is static.  We set it in the myndk_ThreadInit by setting the LinkAddr and LinkMask variables.

    2) No. Could not ping.

  • Hi Jon,

    Have you/can you attempt a wireshark trace of the unsuccessful ping? Do you see any packets from the device using the NDK whatsoever in wireshark?

    Also, using the unsuccessful setup, before you added the delays, can you examine the following struct that contains the driver's stats?

    /*
     *  The struct is used to store the private data for the EMACSnow controller.
     */
    typedef struct EMACSnow_Data {
        STKEVENT_Handle  hEvent;
        PBMQ             PBMQ_tx;
        PBMQ             PBMQ_rx;
        uint32_t         rxCount;
        uint32_t         rxDropped;
        uint32_t         txSent;
        uint32_t         txDropped;
        uint32_t         abnormalInts;
        uint32_t         isrCount;
        uint32_t         linkUp;
        tDescriptorList *pTxDescList;
        tDescriptorList *pRxDescList;
    } EMACSnow_Data;
    
    /* Only supporting one EMACSnow device */
    static EMACSnow_Data EMACSnow_private; 
    

    It is defined in EMACSnow.c. To view it in the CCS Expressions view you can use the syntax 

    ‘EMACSnow.c’::EMACSnow_private

    Brandon