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.

TM4C129DNCPDT: TI RTOS

Genius 13919 points
Part Number: TM4C129DNCPDT
Other Parts Discussed in Thread: SYSBIOS

Hi Experts,

We have this query from Cx, asking help with regards TI-RTOS:

We go through the debug process. and i get GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_3, 1<<3); instruction giving run time fault.

Device used: TM4C129DNCPDT

For your guidance. Thank you.

Regards,
Archie A.

  • Hi,

      The reason is that the PortN is not first enabled. If the peripheral is not enabled and you attempt to access the peripheral registers then it will generate a bus fault. Before you call GPIOPinWrite, you should first enable the peripheral like below. 

    //
    // Enable the GPIO port N.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);

    //
    // Check if the peripheral access is enabled.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
    {
    }

    //
    // Enable the GPIO pin 3. Set the direction as output, and
    // enable the GPIO pin for digital function.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_3);

    // Set Port N pin 3 high.

    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_3, GPIO_PIN_3);

  • Hello Charles,

    Thank you for your prompt response.

    We have done the initialization.

    SysCtlPeripheralEnable( SYSCTL_PERIPH_GPION );
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
    {

    }
    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,
    GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);

    Sorry but still getting same problem.

    Regards,
    Archie A.

  • Hi,

      I just modify the stock TI-RTOS gpiointerrupt example for Tiva. I added the line highlighted in red. I don't see any bus fault. Why don't you try it first? Perhaps show your code too. 

    /*
    * ======== gpiointerrupt.c ========
    */

    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>

    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>

    /* TI-RTOS Header files */
    #include <ti/drivers/GPIO.h>

    /* Example/Board Header files */
    #include "Board.h"

    //------------------------------------------
    // TivaWare Header Files
    //------------------------------------------
    #include <stdint.h>
    #include <stdbool.h>

    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"

    /* variable to be read by GUI Composer */
    int count = 0;

    /*
    * ======== gpioButtonFxn0 ========
    * Callback function for the GPIO interrupt on Board_BUTTON0.
    */
    void gpioButtonFxn0(unsigned int index)
    {
    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_LED0);

    if (count++ == 100) {
    count = 0;
    }
    }

    /*
    * ======== gpioButtonFxn1 ========
    * Callback function for the GPIO interrupt on Board_BUTTON1.
    * This may not be used for all boards.
    */
    void gpioButtonFxn1(unsigned int index)
    {
    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_LED1);

    if (count++ == 100) {
    count = 0;
    }
    }

    /*
    * ======== main ========
    */
    int main(void)
    {
    /* Call board init functions */
    Board_initGeneral();
    Board_initGPIO();
    Board_initUART();

    /* Turn on user LED */
    GPIO_write(Board_LED0, Board_LED_ON);

    SysCtlPeripheralEnable( SYSCTL_PERIPH_GPION );
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
    {

    }
    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,
    GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0,
    GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);


    System_printf("Starting the GPIO Interrupt example\nSystem provider is set"
    " to SysMin. Halt the target to view any SysMin contents in"
    " ROV.\n");
    /* SysMin will only print to the console when you call flush or exit */
    System_flush();

    /* install Button callback */
    GPIO_setCallback(Board_BUTTON0, gpioButtonFxn0);

    /* Enable interrupts */
    GPIO_enableInt(Board_BUTTON0);

    /*
    * If more than one input pin is available for your device, interrupts
    * will be enabled on Board_BUTTON1.
    */
    if (Board_BUTTON0 != Board_BUTTON1) {
    /* install Button callback */
    GPIO_setCallback(Board_BUTTON1, gpioButtonFxn1);
    GPIO_enableInt(Board_BUTTON1);
    }

    /* Start BIOS */
    BIOS_start();

    return (0);
    }

  • Thank you, Charles.

    We have observed one thing if GPIOWrite instruction is just after initialization then it has no issue. But in real scenario it is not possible.

    // *****************No issue
    SysCtlPeripheralEnable( SYSCTL_PERIPH_GPION );
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
    {
    }
    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,
    GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0,
    GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);

    //****************with issue

    SysCtlPeripheralEnable( SYSCTL_PERIPH_GPION );
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
    {
    }
    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,
    GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);
    // some others instructions then Gpio write instruction

    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0,
    GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);

    Regards,
    Archie A.

  • Hi,

      so where exactly in your code that fails? Is it on GPIOPinWrite or inside your some other instructions before the GPIO write. What are these some other instructions? Can you do a single step?