Need guidance on addressing Bus Fault error. I am using an EK-TM4C123GXL TIVA C launchpad with TIvaWare 2.1.2.111 Code Composer Studio Version: 6.1.2.00015 for programming and debug. The TIVA is interfacing with a Kentec EB-LMF4120-L35 LCD touchscreen.
The code should display an array of slider widgets on a main panel and when the user presses the push button widget, the current main black canvas and its child, the array of sliders, should be removed from the widget tree and the second red panel should display on screen. When the push button is pressed again the reverse should happen and the main panel and its sliders should be redrawn on screen.
Currently I am able to draw the second panel on a button press but once I try to switch back to the first panel the code enables the FaultISR. I have tried diagnosing the issue using this document: http://www.ti.com/lit/an/spma043/spma043.pdf but my fault seems to be very vague. When viewing the NVIC Fault Registers, only the Instruction Bus Error flag is set. I am not sure how to carry on with diagnosing the problem. Any help would be much appreciated.
#include "stdint.h"
#include "stdbool.h"
#include "time.h"
#include "inc/hw_memmap.h"
#include "inc/hw_nvic.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/flash.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "driverlib/udma.h"
#include "driverlib/rom.h"
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/checkbox.h"
#include "grlib/container.h"
#include "grlib/pushbutton.h"
#include "grlib/radiobutton.h"
#include "grlib/slider.h"
#include "utils/ustdlib.h"
#include "Kentec320x240x16_ssd2119_8bit.h"
#include "touch.h"
#include "images.h"
/*
* DMA Structure Table
*/
#ifdef ewarm
#pragma data_alignment=1024
tDMAControlTable sDMAControlTable[64];
#elif defined(ccs)
#pragma DATA_ALIGN(sDMAControlTable, 1024)
tDMAControlTable sDMAControlTable[64];
#else
tDMAControlTable sDMAControlTable[64] __attribute__ ((aligned(1024)));
#endif
tContext sContext;
tRectangle sRect;
extern tCanvasWidget g_sMainPanel; /*Declarartion of Main Panel Canvas*/
extern tCanvasWidget g_sVUPanel; /*Declaration of VU meter Panel*/
extern tCanvasWidget g_psPanels[];
extern tSliderWidget g_psMainSlider[];
void OnSlideChange(tWidget *pWidget); /*Handler for Slider Value Changes to be used in SPI interface of Potentionmeters*/
void OnButtonPress(tWidget *pWidget); /*Handler for Push Button to switch between Main and VU Meter Panels*/
tSliderWidget g_psMainSlider[] =
{
SliderStruct(&g_sMainPanel, g_psMainSlider + 1, 0 /*&g_sSliderValueCanvas*/, &g_sKentec320x240x16_SSD2119, 270, 45, 40, 150, 0, 100, 50,
(SL_STYLE_BACKG_FILL | SL_STYLE_FILL |SL_STYLE_VERTICAL | SL_STYLE_OUTLINE | SL_STYLE_TEXT |SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE),
ClrGreen, ClrRed, ClrSilver, ClrWhite, 0, g_psFontCmss22b, 0, 0, 0, 0),
SliderStruct(&g_sMainPanel, g_psMainSlider + 2, 0, &g_sKentec320x240x16_SSD2119, 5, 115, 200, 30, 0, 100, 25,
(SL_STYLE_OUTLINE | SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_TEXT |SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE |SL_STYLE_BACKG_TEXT_OPAQUE),
ClrBlue, ClrDimGray, ClrBlue, ClrDimGray, ClrBlue, &g_sFontCm18, "Bass", 0, 0, 0),
SliderStruct(&g_sMainPanel, g_psMainSlider + 3, 0, &g_sKentec320x240x16_SSD2119, 5, 75, 200, 30, 0, 100, 50,
(SL_STYLE_OUTLINE |SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_TEXT |SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE |SL_STYLE_BACKG_TEXT_OPAQUE),
ClrCrimson, ClrLime, ClrSilver, ClrLime, ClrCrimson, &g_sFontCm18, "Mid", 0, 0, 0),
SliderStruct(&g_sMainPanel, g_psMainSlider + 4, 0, &g_sKentec320x240x16_SSD2119, 5, 35, 200, 30, 0, 100, 50,
(SL_STYLE_OUTLINE |SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_TEXT |SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE |SL_STYLE_BACKG_TEXT_OPAQUE),
ClrYellow, ClrPurple, ClrSilver, ClrPurple, ClrYellow, &g_sFontCm18, "Treble", 0, 0, 0),
SliderStruct(&g_sMainPanel, g_psMainSlider + 5, 0, &g_sKentec320x240x16_SSD2119, 5, 155, 200, 30, 0, 100, 50,
(SL_STYLE_OUTLINE |SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_TEXT |SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE |SL_STYLE_BACKG_TEXT_OPAQUE),
ClrDarkOrange, ClrWhiteSmoke, ClrSilver, ClrWhiteSmoke, ClrDarkOrange, &g_sFontCm18, "Balance", 0, 0, 0)
};
/*Initialize Sliders for VU Meter
tSliderWidget g_psVUSlider[] =
{
SliderStruct(&g_sVUPanel, g_psVUSlider + 1, 0, &g_sKentec320x240x16_SSD2119, 5, 115, 200, 30, 0, 100, 25,
(SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE | SL_STYLE_LOCKED),
ClrDarkGreen, ClrDarkRed, ClrSilver, 0, 0, 0, 0, 0, 0, 0),
SliderStruct(&g_sVUPanel, g_psVUSlider + 2, 0, &g_sKentec320x240x16_SSD2119, 5, 75, 200, 30, 0, 100, 50,
(SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE | SL_STYLE_LOCKED),
ClrDarkGreen, ClrDarkRed, ClrSilver, 0, 0, 0, 0, 0, 0, 0)
};*/
/*Create define for Heading of LCD screen to be shown on all panels*/
Canvas(g_sHeading, 0, 0, 0, &g_sKentec320x240x16_SSD2119,
0, 0, 320, 23, (CANVAS_STYLE_FILL | CANVAS_STYLE_OUTLINE | CANVAS_STYLE_TEXT),
ClrBlack, ClrWhite, ClrRed, g_psFontCm20, "USB HIFI System", 0, 0);
/*Create define Main Panel Parent to Main Panel Sliders*/
Canvas(g_sMainPanel, 0, 0, g_psMainSlider, &g_sKentec320x240x16_SSD2119,
0, 23, 320, (240 - 23), CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0);
/*Create define of VU Panel Parent to VU Sliders*/
Canvas(g_sVUPanel, 0, 0, 0, &g_sKentec320x240x16_SSD2119,
0, 23, 320, (240 - 23), CANVAS_STYLE_FILL, ClrTomato, 0, 0, 0, 0, 0, 0);
/* Create Define Push button to control LED*/
RectangularButton(g_sPushBtn, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 100, 200, 220, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |PB_STYLE_FILL),
ClrGray, ClrWhite, ClrRed, ClrRed, g_psFontCmss22b, "Switch Panels", 0, 0, 0, 0, OnButtonPress);
/*Handler for Push Button. Turn on LED and and switch Panels and sliders. LED intialized to be off*/
bool g_RedLedOn = false;
void OnButtonPress(tWidget *pWidget)
{
g_RedLedOn = !g_RedLedOn;
if(g_RedLedOn)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x02);
WidgetRemove((tWidget *)&g_sMainPanel);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sVUPanel);
WidgetPaint((tWidget *)&g_sVUPanel);
}
else
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00);
WidgetRemove((tWidget *)&g_sVUPanel);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMainPanel);
WidgetPaint((tWidget *)&g_sMainPanel);
}
}
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00);
Kentec320x240x16_SSD2119Init();
GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);
TouchScreenInit();
TouchScreenCallbackSet(WidgetPointerMessage);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMainPanel);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPushBtn);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);
WidgetPaint(WIDGET_ROOT);
while(1)
{
WidgetMessageQueueProcess();
}
}
#include "stdint.h"#include "stdbool.h"#include "time.h"#include "inc/hw_memmap.h"#include "inc/hw_nvic.h"#include "inc/hw_sysctl.h"#include "inc/hw_types.h"#include "driverlib/fpu.h"#include "driverlib/gpio.h"#include "driverlib/flash.h"#include "driverlib/sysctl.h"#include "driverlib/systick.h"#include "driverlib/uart.h"#include "driverlib/udma.h"#include "driverlib/rom.h"#include "grlib/grlib.h"#include "grlib/widget.h"#include "grlib/canvas.h"#include "grlib/checkbox.h"#include "grlib/container.h"#include "grlib/pushbutton.h"#include "grlib/radiobutton.h"#include "grlib/slider.h"#include "utils/ustdlib.h"#include "Kentec320x240x16_ssd2119_8bit.h"#include "touch.h"#include "images.h"
/* * DMA Structure Table */#ifdef ewarm#pragma data_alignment=1024tDMAControlTable sDMAControlTable[64];#elif defined(ccs)#pragma DATA_ALIGN(sDMAControlTable, 1024)tDMAControlTable sDMAControlTable[64];#elsetDMAControlTable sDMAControlTable[64] __attribute__ ((aligned(1024)));#endif
tContext sContext;tRectangle sRect;extern tCanvasWidget g_sMainPanel; /*Declarartion of Main Panel Canvas*/extern tCanvasWidget g_sVUPanel; /*Declaration of VU meter Panel*/extern tCanvasWidget g_psPanels[];extern tSliderWidget g_psMainSlider[];
void OnSlideChange(tWidget *pWidget); /*Handler for Slider Value Changes to be used in SPI interface of Potentionmeters*/void OnButtonPress(tWidget *pWidget); /*Handler for Push Button to switch between Main and VU Meter Panels*/
tSliderWidget g_psMainSlider[] ={ SliderStruct(&g_sMainPanel, g_psMainSlider + 1, 0 /*&g_sSliderValueCanvas*/, &g_sKentec320x240x16_SSD2119, 270, 45, 40, 150, 0, 100, 50, (SL_STYLE_BACKG_FILL | SL_STYLE_FILL |SL_STYLE_VERTICAL | SL_STYLE_OUTLINE | SL_STYLE_TEXT |SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE), ClrGreen, ClrRed, ClrSilver, ClrWhite, 0, g_psFontCmss22b, 0, 0, 0, 0), SliderStruct(&g_sMainPanel, g_psMainSlider + 2, 0, &g_sKentec320x240x16_SSD2119, 5, 115, 200, 30, 0, 100, 25, (SL_STYLE_OUTLINE | SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_TEXT |SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE |SL_STYLE_BACKG_TEXT_OPAQUE), ClrBlue, ClrDimGray, ClrBlue, ClrDimGray, ClrBlue, &g_sFontCm18, "Bass", 0, 0, 0), SliderStruct(&g_sMainPanel, g_psMainSlider + 3, 0, &g_sKentec320x240x16_SSD2119, 5, 75, 200, 30, 0, 100, 50, (SL_STYLE_OUTLINE |SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_TEXT |SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE |SL_STYLE_BACKG_TEXT_OPAQUE), ClrCrimson, ClrLime, ClrSilver, ClrLime, ClrCrimson, &g_sFontCm18, "Mid", 0, 0, 0), SliderStruct(&g_sMainPanel, g_psMainSlider + 4, 0, &g_sKentec320x240x16_SSD2119, 5, 35, 200, 30, 0, 100, 50, (SL_STYLE_OUTLINE |SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_TEXT |SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE |SL_STYLE_BACKG_TEXT_OPAQUE), ClrYellow, ClrPurple, ClrSilver, ClrPurple, ClrYellow, &g_sFontCm18, "Treble", 0, 0, 0), SliderStruct(&g_sMainPanel, g_psMainSlider + 5, 0, &g_sKentec320x240x16_SSD2119, 5, 155, 200, 30, 0, 100, 50, (SL_STYLE_OUTLINE |SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_TEXT |SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE |SL_STYLE_BACKG_TEXT_OPAQUE), ClrDarkOrange, ClrWhiteSmoke, ClrSilver, ClrWhiteSmoke, ClrDarkOrange, &g_sFontCm18, "Balance", 0, 0, 0)};
/*Initialize Sliders for VU MetertSliderWidget g_psVUSlider[] ={ SliderStruct(&g_sVUPanel, g_psVUSlider + 1, 0, &g_sKentec320x240x16_SSD2119, 5, 115, 200, 30, 0, 100, 25, (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE | SL_STYLE_LOCKED), ClrDarkGreen, ClrDarkRed, ClrSilver, 0, 0, 0, 0, 0, 0, 0), SliderStruct(&g_sVUPanel, g_psVUSlider + 2, 0, &g_sKentec320x240x16_SSD2119, 5, 75, 200, 30, 0, 100, 50, (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE | SL_STYLE_LOCKED), ClrDarkGreen, ClrDarkRed, ClrSilver, 0, 0, 0, 0, 0, 0, 0)};*/
/*Create define for Heading of LCD screen to be shown on all panels*/Canvas(g_sHeading, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 0, 320, 23, (CANVAS_STYLE_FILL | CANVAS_STYLE_OUTLINE | CANVAS_STYLE_TEXT), ClrBlack, ClrWhite, ClrRed, g_psFontCm20, "USB HIFI System", 0, 0);
/*Create define Main Panel Parent to Main Panel Sliders*/Canvas(g_sMainPanel, 0, 0, g_psMainSlider, &g_sKentec320x240x16_SSD2119, 0, 23, 320, (240 - 23), CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0);
/*Create define of VU Panel Parent to VU Sliders*/Canvas(g_sVUPanel, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 23, 320, (240 - 23), CANVAS_STYLE_FILL, ClrTomato, 0, 0, 0, 0, 0, 0);
/* Create Define Push button to control LED*/RectangularButton(g_sPushBtn, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 100, 200, 220, 40, (PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |PB_STYLE_FILL), ClrGray, ClrWhite, ClrRed, ClrRed, g_psFontCmss22b, "Switch Panels", 0, 0, 0, 0, OnButtonPress);
/*Handler for Push Button. Turn on LED and and switch Panels and sliders. LED intialized to be off*/bool g_RedLedOn = false;
void OnButtonPress(tWidget *pWidget){ g_RedLedOn = !g_RedLedOn; if(g_RedLedOn) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x02);
WidgetRemove((tWidget *)&g_sMainPanel); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sVUPanel);
WidgetPaint((tWidget *)&g_sVUPanel); } else { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00);
WidgetRemove((tWidget *)&g_sVUPanel); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMainPanel);
WidgetPaint((tWidget *)&g_sMainPanel); }}
int main(void){ SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00);
Kentec320x240x16_SSD2119Init(); GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); TouchScreenInit(); TouchScreenCallbackSet(WidgetPointerMessage);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMainPanel); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPushBtn); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);
WidgetPaint(WIDGET_ROOT);
while(1) { WidgetMessageQueueProcess(); }}