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.

Getting fault on LM4F232 evaluation board

Hi!

I am new to embedded programming, so please, forgive me possibly idiotic question.

I need a simple application that will read several ADC channels each 100usec, perform some simplest calculation and send the output to the display. So i am trying to combine several examples to do this.

Now i am stuck, as since some point, whatever i do, the controller gets fault an different lines. it may be the GrStringDraw, or ROM_IntMasterDisable, or anything. I just cannot continue...

In the code below, the fault comes in timer handler, on the first GrStringDraw line.

Please, help!

upd:

the specific assembly line that throws me to fault is BLX r12... Is it helpful?

#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/fpu.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
#include "grlib/grlib.h"
#include "drivers/cfal96x64x16.h"
#include "utils/uartstdio.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/adc.h"
#include "driverlib/interrupt.h"
#include "inc/hw_ints.h"

#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

static float PMotor;

static float PTotal;

static tContext sContext;
static char TextOut[10];

static unsigned long ulADC0_Value[3];

void NumToString (char *str, float num)
{
    char digit;
    float factor=1;

    if (num>1)
    {
        while (factor<num)
        {
            factor=factor * 10;
        }
    }
    else
    {
        *str='0';
        str++;
    }

    if (num==0)
    {
        *str=48;
        str++;
        *str=0;
        return;
    }
    else
    {
        while ((factor>num) && (factor>0.0001))
        {
            if (factor==1)
            {
                 *str='.';
                str++;
            }
            factor=factor/10;
            digit=(char)(num/factor);
            *str=(char) (digit+'0');
            str++;
            num=num-digit*factor;
        }
        *str=' ';
        str++;
        *str=0;
    }

    return;
}

void
Timer0IntHandler(void)
{
    float Efficiency;
    char efficiency_string[20];

    //
    // Clear the timer interrupt.
    //
    ROM_IntMasterDisable();
    ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

//    ADCProcessorTrigger(ADC0_BASE, 0);
//    while(!ADCIntStatus(ADC0_BASE, 0, false))
//    {
//    }
//    ADCSequenceDataGet(ADC0_BASE, 0, ulADC0_Value);

    PMotor=PMotor+1;
    PTotal=PTotal+1;
    Efficiency=(float) (PMotor/PTotal);
    

    NumToString(efficiency_string, (float)PMotor);
    GrStringDraw(&sContext, efficiency_string, -1, 50,
                 26, 1);
    NumToString(efficiency_string, (float)PTotal);
    GrStringDraw(&sContext, efficiency_string, -1, 50,
                 36, 1);
    NumToString(efficiency_string, (float)Efficiency);
    GrStringDraw(&sContext, efficiency_string, -1, 50,
                 46, 1);

//    UARTprintf("Motor %f, Total %f, n %f", PMotor, PTotal, efficiency);
    ROM_IntMasterEnable();

    SysCtlDelay(1000);

}

void
InitADC(void)
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);

    ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    HWREG(GPIO_PORTB_BASE + 0x00000528) |= GPIO_PIN_6;

    ROM_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

    ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH21 | ADC_CTL_IE | ADC_CTL_END);

//    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH21 | ADC_CTL_IE | ADC_CTL_END);
//    ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);
//    ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH9 | ADC_CTL_IE | ADC_CTL_END);
    ROM_ADCSequenceEnable(ADC0_BASE, 0);
    ROM_ADCSequenceDataGet(ADC0_BASE, 0, ulADC0_Value);
    ADCIntClear(ADC0_BASE, 0);
    ROM_ADCIntClear(ADC0_BASE, 0);
    ROM_ADCIntEnable(ADC0_BASE, 0);


    SysCtlDelay(1000);

    return;

}

void
InitTimer(void)
{
    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    //
    // Enable processor interrupts.
    //

    //
    // Configure the two 32-bit periodic timers.
    //
    ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()/10);

    //
    // Setup the interrupts for the timer timeouts.
    //
    ROM_IntEnable(INT_TIMER0A);
    ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

    //
    // Enable the timers.
    //
    ROM_TimerEnable(TIMER0_BASE, TIMER_A);


    SysCtlDelay(1000);

    return;
}


int
main(void)
{
    tContext sContext;
    tRectangle sRect;

    FPUEnable();
    FPULazyStackingEnable();

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Initialize the UART.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioInit(0);

    UARTprintf("Hello, world!\n");

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sCFAL96x64x16);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.sYMax = 23;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrRectDraw(&sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_pFontCm12);
    GrStringDrawCentered(&sContext, "hello", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 10, 0);

    //
    // Say hello using the Computer Modern 40 point font.
    //

    GrStringDraw(&sContext, "PMotor: ", -1, 3,
                 26, 1);

    GrStringDraw(&sContext, "PTotal: ", -1, 3,
                 36, 1);

    GrStringDraw(&sContext, "n :     ", -1, 3,
                 46, 1);



    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    InitTimer();
//    InitADC();
    ROM_IntMasterEnable();

    //
    // We are finished. Hang around doing nothing.
    //
    while(1)
    {
    }
}


  • Guys, not even one reply? Please, someone must have some idea...

  • Hate to see you hang - but that is a lot of code.  (I have same board as you - will cut/paste soon as I escape from dungeon later)

    You can simplify the life of yourself/others by simplifying your code - too much has to go right for your code to run now.  For example - you have ADC, Timer, Oled Graphic all having to perform.  You can easily eliminate the ADC by substituting "faked" values - this will enable you to test/verify the non-ADC portions of your program.  Likewise you can eliminate the "timer" function for now - simply "call" your "faked" ADC function from main - verify that it works.  Only after you have built and verified each individual main code segment - as I've illustrated - would I then attempt to "bring it all together." 

    Usual suspect is the improper inclusion of your named interrupt handlers w/in startup.c.  (provided by your particular IDE - insure that yours match)

    Proceed by refinement is the best method we/others have found to get a complex program to work.  You have set a very ambitious goal for a beginner - sometimes its important to match one's objective to reality.  Small - focused success is my best advice...

  • Thanks for the reply!!!

    Actually i am trying to do exactly that for several days... I will try again today.

    Please, if you can run this code (you will see, most of it is not even used), i will really appreciate it.

    Thank you!

  • Forgive me - know that I can solve this - could not escape dungeon till 20:00 last night - no strength left then to set-up, load & run from home.  Can you wait till this Friday - dungeon-free day then...

    If not - suggest the following so that you can make progress:

    a) bypass (by commenting out) all calls to ADC - instead use a fixed (faked) value in place of the ADC's output

    b) bypass (same as above) all calls to Timer - instead call your display function just once from main.  Insure that all data required by the display function is proper & available prior to main's reaching this function call.

    Should you "not" be able to get the above to work - your addition of ADC and Timer routines is folly.  Once you succeed with the above I suggest that you first add "just" the timer function - you may want to increment the "faked" ADC value with each timer call.  (proves that your timer really ticked.)  When you get the timer to work - then is time to try to replace the faked value with an actural ADC conversion.   If this simpler method fails provide your code listing and a clear description of the failure.  I would avoid interrupts at this stage of your testing - everyone you're after can be achieved/verified via simple function calls from w/in main.

  • Cb1_mobile, thank you!

    Friday is good, much much better than anything i had until now :)

    Generally i have passed the way you suggest. Actually i had it run with one sample in a sequence, with the timer and graphics. The trouble started when i tried to add two more samples to the sequence. The weird thing is that from this state i cannot go back to the state when it worked with one sample, which suggests, that even when it worked, something was not defined.

    So i am making another attempt, but all my hope is on friday :) When it works, i owe you a new year gift.

    Thank you!!!!

  • Gregory Kornblum said:
    When it works, i owe you a new year gift.

    Liz Taylor's giant diamond already sold @ auction!  (will have to come up with equally suitable reward)

    Will respond as promised this Friday.  You can assist - paste your "start-up" file for review.  (this will list all the interrupts)

    Gregory Kornblum said:
    Actually i had it run with one sample in a sequence

    One should always - always SAVE such intermediate victories!  Much easier to "build" upon small victories than fight the war from square one.  It would be useful if today you could put in the time/effort and try to get us back to even the most basic "working."  I'm off to deep dungeon now - will see you tomorrow...

  • To give you something to work on before tomorrow's answer from cb1, you may like to review this thread which has some great tips on how to debug faults.

  • Dave, thank you!

    I will read it carefully.

    Cb1, the setting file:


    ;******************************************************************************
    ;
    ; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
    ;
    ;******************************************************************************
    Stack   EQU     0x00000200

    ;******************************************************************************
    ;
    ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
    ;
    ;******************************************************************************
    Heap    EQU     0x00000200

    ;******************************************************************************
    ;
    ; Allocate space for the stack.
    ;
    ;******************************************************************************
            AREA    STACK, NOINIT, READWRITE, ALIGN=3
    StackMem
            SPACE   Stack
    __initial_sp

    ;******************************************************************************
    ;
    ; Allocate space for the heap.
    ;
    ;******************************************************************************
            AREA    HEAP, NOINIT, READWRITE, ALIGN=3
    __heap_base
    HeapMem
            SPACE   Heap
    __heap_limit

    ;******************************************************************************
    ;
    ; Indicate that the code in this file preserves 8-byte alignment of the stack.
    ;
    ;******************************************************************************
            PRESERVE8

    ;******************************************************************************
    ;
    ; Place code into the reset code section.
    ;
    ;******************************************************************************
            AREA    RESET, CODE, READONLY
            THUMB


            EXTERN Timer0IntHandler

    ;******************************************************************************
    ;
    ; The vector table.
    ;
    ;******************************************************************************
            EXPORT  __Vectors
    __Vectors
            DCD     StackMem + Stack            ; Top of Stack
            DCD     Reset_Handler               ; Reset Handler
            DCD     NmiSR                       ; NMI Handler
            DCD     FaultISR                    ; Hard Fault Handler
            DCD     IntDefaultHandler           ; The MPU fault handler
            DCD     IntDefaultHandler           ; The bus fault handler
            DCD     IntDefaultHandler           ; The usage fault handler
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     IntDefaultHandler           ; SVCall handler
            DCD     IntDefaultHandler           ; Debug monitor handler
            DCD     0                           ; Reserved
            DCD     IntDefaultHandler           ; The PendSV handler
            DCD     IntDefaultHandler           ; The SysTick handler
            DCD     IntDefaultHandler           ; GPIO Port A
            DCD     IntDefaultHandler           ; GPIO Port B
            DCD     IntDefaultHandler           ; GPIO Port C
            DCD     IntDefaultHandler           ; GPIO Port D
            DCD     IntDefaultHandler           ; GPIO Port E
            DCD     IntDefaultHandler           ; UART0 Rx and Tx
            DCD     IntDefaultHandler           ; UART1 Rx and Tx
            DCD     IntDefaultHandler           ; SSI0 Rx and Tx
            DCD     IntDefaultHandler           ; I2C0 Master and Slave
            DCD     IntDefaultHandler           ; PWM Fault
            DCD     IntDefaultHandler           ; PWM Generator 0
            DCD     IntDefaultHandler           ; PWM Generator 1
            DCD     IntDefaultHandler           ; PWM Generator 2
            DCD     IntDefaultHandler           ; Quadrature Encoder 0
            DCD     IntDefaultHandler           ; ADC Sequence 0
            DCD     IntDefaultHandler           ; ADC Sequence 1
            DCD     IntDefaultHandler           ; ADC Sequence 2
            DCD     IntDefaultHandler           ; ADC Sequence 3
            DCD     IntDefaultHandler           ; Watchdog timer
            DCD     Timer0IntHandler            ; Timer 0 subtimer A
            DCD     IntDefaultHandler           ; Timer 0 subtimer B
            DCD     IntDefaultHandler           ; Timer 1 subtimer A
            DCD     IntDefaultHandler           ; Timer 1 subtimer B
            DCD     IntDefaultHandler           ; Timer 2 subtimer A
            DCD     IntDefaultHandler           ; Timer 2 subtimer B
            DCD     IntDefaultHandler           ; Analog Comparator 0
            DCD     IntDefaultHandler           ; Analog Comparator 1
            DCD     IntDefaultHandler           ; Analog Comparator 2
            DCD     IntDefaultHandler           ; System Control (PLL, OSC, BO)
            DCD     IntDefaultHandler           ; FLASH Control
            DCD     IntDefaultHandler           ; GPIO Port F
            DCD     IntDefaultHandler           ; GPIO Port G
            DCD     IntDefaultHandler           ; GPIO Port H
            DCD     IntDefaultHandler           ; UART2 Rx and Tx
            DCD     IntDefaultHandler           ; SSI1 Rx and Tx
            DCD     IntDefaultHandler           ; Timer 3 subtimer A
            DCD     IntDefaultHandler           ; Timer 3 subtimer B
            DCD     IntDefaultHandler           ; I2C1 Master and Slave
            DCD     IntDefaultHandler           ; Quadrature Encoder 1
            DCD     IntDefaultHandler           ; CAN0
            DCD     IntDefaultHandler           ; CAN1
            DCD     IntDefaultHandler           ; CAN2
            DCD     IntDefaultHandler           ; Ethernet
            DCD     IntDefaultHandler           ; Hibernate
            DCD     IntDefaultHandler           ; USB0
            DCD     IntDefaultHandler           ; PWM Generator 3
            DCD     IntDefaultHandler           ; uDMA Software Transfer
            DCD     IntDefaultHandler           ; uDMA Error
            DCD     IntDefaultHandler           ; ADC1 Sequence 0
            DCD     IntDefaultHandler           ; ADC1 Sequence 1
            DCD     IntDefaultHandler           ; ADC1 Sequence 2
            DCD     IntDefaultHandler           ; ADC1 Sequence 3
            DCD     IntDefaultHandler           ; I2S0
            DCD     IntDefaultHandler           ; External Bus Interface 0
            DCD     IntDefaultHandler           ; GPIO Port J
            DCD     IntDefaultHandler           ; GPIO Port K
            DCD     IntDefaultHandler           ; GPIO Port L
            DCD     IntDefaultHandler           ; SSI2 Rx and Tx
            DCD     IntDefaultHandler           ; SSI3 Rx and Tx
            DCD     IntDefaultHandler           ; UART3 Rx and Tx
            DCD     IntDefaultHandler           ; UART4 Rx and Tx
            DCD     IntDefaultHandler           ; UART5 Rx and Tx
            DCD     IntDefaultHandler           ; UART6 Rx and Tx
            DCD     IntDefaultHandler           ; UART7 Rx and Tx
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     IntDefaultHandler           ; I2C2 Master and Slave
            DCD     IntDefaultHandler           ; I2C3 Master and Slave
            DCD     IntDefaultHandler           ; Timer 4 subtimer A
            DCD     IntDefaultHandler           ; Timer 4 subtimer B
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     0                           ; Reserved
            DCD     IntDefaultHandler           ; Timer 5 subtimer A
            DCD     IntDefaultHandler           ; Timer 5 subtimer B
            DCD     IntDefaultHandler           ; Wide Timer 0 subtimer A
            DCD     IntDefaultHandler           ; Wide Timer 0 subtimer B
            DCD     IntDefaultHandler           ; Wide Timer 1 subtimer A
            DCD     IntDefaultHandler           ; Wide Timer 1 subtimer B
            DCD     IntDefaultHandler           ; Wide Timer 2 subtimer A
            DCD     IntDefaultHandler           ; Wide Timer 2 subtimer B
            DCD     IntDefaultHandler           ; Wide Timer 3 subtimer A
            DCD     IntDefaultHandler           ; Wide Timer 3 subtimer B
            DCD     IntDefaultHandler           ; Wide Timer 4 subtimer A
            DCD     IntDefaultHandler           ; Wide Timer 4 subtimer B
            DCD     IntDefaultHandler           ; Wide Timer 5 subtimer A
            DCD     IntDefaultHandler           ; Wide Timer 5 subtimer B
            DCD     IntDefaultHandler           ; FPU
            DCD     IntDefaultHandler           ; PECI 0
            DCD     IntDefaultHandler           ; LPC 0
            DCD     IntDefaultHandler           ; I2C4 Master and Slave
            DCD     IntDefaultHandler           ; I2C5 Master and Slave
            DCD     IntDefaultHandler           ; GPIO Port M
            DCD     IntDefaultHandler           ; GPIO Port N
            DCD     IntDefaultHandler           ; Quadrature Encoder 2
            DCD     IntDefaultHandler           ; Fan 0
            DCD     0                           ; Reserved
            DCD     IntDefaultHandler           ; GPIO Port P (Summary or P0)
            DCD     IntDefaultHandler           ; GPIO Port P1
            DCD     IntDefaultHandler           ; GPIO Port P2
            DCD     IntDefaultHandler           ; GPIO Port P3
            DCD     IntDefaultHandler           ; GPIO Port P4
            DCD     IntDefaultHandler           ; GPIO Port P5
            DCD     IntDefaultHandler           ; GPIO Port P6
            DCD     IntDefaultHandler           ; GPIO Port P7
            DCD     IntDefaultHandler           ; GPIO Port Q (Summary or Q0)
            DCD     IntDefaultHandler           ; GPIO Port Q1
            DCD     IntDefaultHandler           ; GPIO Port Q2
            DCD     IntDefaultHandler           ; GPIO Port Q3
            DCD     IntDefaultHandler           ; GPIO Port Q4
            DCD     IntDefaultHandler           ; GPIO Port Q5
            DCD     IntDefaultHandler           ; GPIO Port Q6
            DCD     IntDefaultHandler           ; GPIO Port Q7
            DCD     IntDefaultHandler           ; GPIO Port R
            DCD     IntDefaultHandler           ; GPIO Port S
            DCD     IntDefaultHandler           ; PWM 1 Generator 0
            DCD     IntDefaultHandler           ; PWM 1 Generator 1
            DCD     IntDefaultHandler           ; PWM 1 Generator 2
            DCD     IntDefaultHandler           ; PWM 1 Generator 3
            DCD     IntDefaultHandler           ; PWM 1 Fault

    ;******************************************************************************
    ;
    ; This is the code that gets called when the processor first starts execution
    ; following a reset event.
    ;
    ;******************************************************************************
            EXPORT  Reset_Handler
    Reset_Handler
            ;
            ; Call the C library enty point that handles startup.  This will copy
            ; the .data section initializers from flash to SRAM and zero fill the
            ; .bss section.
            ;
            IMPORT  __main
            B       __main

    ;******************************************************************************
    ;
    ; This is the code that gets called when the processor receives a NMI.  This
    ; simply enters an infinite loop, preserving the system state for examination
    ; by a debugger.
    ;
    ;******************************************************************************
    NmiSR
            B       NmiSR

    ;******************************************************************************
    ;
    ; This is the code that gets called when the processor receives a fault
    ; interrupt.  This simply enters an infinite loop, preserving the system state
    ; for examination by a debugger.
    ;
    ;******************************************************************************
    FaultISR
            B       FaultISR

    ;******************************************************************************
    ;
    ; This is the code that gets called when the processor receives an unexpected
    ; interrupt.  This simply enters an infinite loop, preserving the system state
    ; for examination by a debugger.
    ;
    ;******************************************************************************
    IntDefaultHandler
            B       IntDefaultHandler

    ;******************************************************************************
    ;
    ; Make sure the end of this section is aligned.
    ;
    ;******************************************************************************
            ALIGN

    ;******************************************************************************
    ;
    ; Some code in the normal code section for initializing the heap and stack.
    ;
    ;******************************************************************************
            AREA    |.text|, CODE, READONLY

    ;******************************************************************************
    ;
    ; The function expected of the C library startup code for defining the stack
    ; and heap memory locations.  For the C library version of the startup code,
    ; provide this function so that the C library initialization code can find out
    ; the location of the stack and heap.
    ;
    ;******************************************************************************
        IF :DEF: __MICROLIB
            EXPORT  __initial_sp
            EXPORT  __heap_base
            EXPORT  __heap_limit
        ELSE
            IMPORT  __use_two_region_memory
            EXPORT  __user_initial_stackheap
    __user_initial_stackheap
            LDR     R0, =HeapMem
            LDR     R1, =(StackMem + Stack)
            LDR     R2, =(HeapMem + Heap)
            LDR     R3, =StackMem
            BX      LR
        ENDIF

    ;******************************************************************************
    ;
    ; Make sure the end of this section is aligned.
    ;
    ;******************************************************************************
            ALIGN

    ;******************************************************************************
    ;
    ; Tell the assembler that we're done.
    ;
    ;******************************************************************************
            END


  • Got it - thanks - working now on downloading/probing your code...   "I'll be back..."  Arnold soto voice... 

    noted: static unsigned long ulADC0_Value[3];

    for giggles - change this 3 to 4 and perform 2 duplicate ADC reads by duplicating your SequenceStepConfigure "2" for added SequenceStepConfigure "3".

    19:19 CST update:  have cut/pasted your code into my IAR - deluged with errors - fixed many - continuing...

  • I guess, i planted some errors while removing comments... At least it passed keil's compilation before i pasted it here. it's so idiotic, sorry about it.

  • Boy - did not expect this - I can now compile but cannot download to M4F Eval board.  Here's what happens (perhaps of use to others using IAR):

    I "never" got this @ office - dawned that I am one IAR paid update behind @ home.  (where I worked yesterday/today)

    So - am driving to office shortly to ideally copy most updated version of IAR and at minimum copy "missing" .svd.xml file.  I have work to do for firm's 4F631 - really need to "fix" my home system.  I tested on several Stellaris M3 (also brand S M3) - they all compile/download fine - I just cannot get the M4 to download...

     

     

  • Oh, i am so sorry! I never intended to ruin your new year. Diamond or not, but i do owe you something now :) May be, i can download and send you something, that will replace the drive to the office? I don't know, full IAR or something like that?

  •  Hi - trying to paste in simple text file - clicked the "attach" icon - learned that .c files are rejected!  (how nice to know)  Renamed to .txt - typed description/explanation - that too was lost - resulting in completely blank post.  So here is cut/paste - this is a template for you - implements a timer which will read 4 channels of ADC and display each @ 1 Sec intervals.  (ADC not fully implemented - will try to add/paste in this p.m.)  EVK led blinks @ 1 Sec rate - confirming that timer has fired.

    I have removed many of your math/code operations which "killed" prior program - template presented here gives you a good beginning basis for development...

    //***************************************************************************
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/timer.h"
    #include "driverlib/rom.h"
    #include "grlib/grlib.h"
    #include "driverlib/gpio.h"
    #include "driverlib/adc.h"

    #include "drivers/cfal96x64x16.h"
    #include "driverlib/pin_map.h"
    #include "inc/lm4f232h5qd.h"

    #define PART_IS_ <LM4F232H5QD>
    //***************************************************************************

    static float PMotor;

    static float PTotal;

    static tContext sContext;
    static char TextOut[10];

    static unsigned long ulADC0_Value[3];

    void
    Timer0IntHandler(void)
    {
        float Efficiency;
        char efficiency_string[20];
        //
        // Clear the timer interrupt.

        ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

    //    ADCProcessorTrigger(ADC0_BASE, 0);
    //    while(!ADCIntStatus(ADC0_BASE, 0, false))
    //    {
    //    }
    //    ADCSequenceDataGet(ADC0_BASE, 0, ulADC0_Value);

        PMotor=PMotor+1;
        PTotal=PTotal+1;
        Efficiency=(float) (PMotor/PTotal);
       
    /*
        NumToString(efficiency_string, (float)PMotor);
        GrStringDraw(&sContext, efficiency_string, -1, 50,
                     26, 1);
        NumToString(efficiency_string, (float)PTotal);
        GrStringDraw(&sContext, efficiency_string, -1, 50,
                     36, 1);
        NumToString(efficiency_string, (float)Efficiency);
        GrStringDraw(&sContext, efficiency_string, -1, 50,
                     46, 1);
    */   

        ROM_GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2,
                         ~ROM_GPIOPinRead(GPIO_PORTG_BASE, GPIO_PIN_2));
       
    //    UARTprintf("Motor %f, Total %f, n %f", PMotor, PTotal, efficiency);
    //    ROM_IntMasterEnable();
    //    SysCtlDelay(1000);
    }

    void
    InitADC(void)
    {
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);

        ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
        HWREG(GPIO_PORTB_BASE + 0x00000528) |= GPIO_PIN_6;

        ROM_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

        ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH21 | ADC_CTL_IE | ADC_CTL_END);

    //    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH21 | ADC_CTL_IE | ADC_CTL_END);
    //    ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);
    //    ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH9 | ADC_CTL_IE | ADC_CTL_END);
        ROM_ADCSequenceEnable(ADC0_BASE, 0);
        ROM_ADCSequenceDataGet(ADC0_BASE, 0, ulADC0_Value);
        ADCIntClear(ADC0_BASE, 0);
        ROM_ADCIntClear(ADC0_BASE, 0);
        ROM_ADCIntEnable(ADC0_BASE, 0);

        SysCtlDelay(1000);

        return;

    }

    void
    InitTimer(void)
    {

        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);              //  1

        ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC);        //  2
       
        ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); //  3

        ROM_IntEnable(INT_TIMER0A);                                  //  4

        ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);        //   5
       
        ROM_TimerEnable(TIMER0_BASE, TIMER_A);                      //   6
       
    }


    int
    main(void)
    {
        tContext sContext;
        tRectangle sRect;
       
        FPUEnable();
        FPULazyStackingEnable();

        //
        // Set the clocking to run directly from the crystal.
        //
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                           SYSCTL_OSC_MAIN);

        //
        // Initialize the UART.
        //
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
        ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
        ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
        ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
        ROM_GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);
        ROM_GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0);
    //    UARTStdioInit(0);

    //    UARTprintf("Hello, world!\n");

        //
        // Initialize the display driver.
        //
        CFAL96x64x16Init();

        //
        // Initialize the graphics context.
        //
        GrContextInit(&sContext, &g_sCFAL96x64x16);

        //
        // Fill the top 24 rows of the screen with blue to create the banner.
        //
        sRect.sXMin = 0;
        sRect.sYMin = 0;
        sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1;
        sRect.sYMax = 23;
        GrContextForegroundSet(&sContext, ClrDarkBlue);
        GrRectFill(&sContext, &sRect);

        //
        // Put a white box around the banner.
        //
        GrContextForegroundSet(&sContext, ClrWhite);
        GrRectDraw(&sContext, &sRect);

        //
        // Put the application name in the middle of the banner.
        //
        GrContextFontSet(&sContext, g_pFontCm12);
        GrStringDrawCentered(&sContext, "hello", -1,
                             GrContextDpyWidthGet(&sContext) / 2, 10, 0);

        //
        // Say hello using the Computer Modern 40 point font.
        //

        GrStringDraw(&sContext, "PMotor: ", -1, 3,
                     26, 1);

        GrStringDraw(&sContext, "PTotal: ", -1, 3,
                     36, 1);

        GrStringDraw(&sContext, "n :     ", -1, 3,
                     46, 1);

     

        //
        // Flush any cached drawing operations.
        //
        GrFlush(&sContext);

        InitTimer();
    //    InitADC();
        ROM_IntMasterEnable();

        //
        // We are finished. Hang around doing nothing.
        //
        while(1)
        {
        }
    }

     

     

     

     

  • Thank you!!! I will try it soon.

    Please, contact me on lapserdak@gmail.com, i really feel that i owe you :)

  • cb1_mobile, hi again.

    I am now trying the code you provided. Indeed, it runs, it "tolerates" the InitADC(). So i am stuck- why would such innocent function as NumToString that you removed stuck the CPU? Even if it's never called... upd: Actually, only when it is called. But still, may be it's only because the compiler removes it, if not used.

    And is the function, or just the code size that got small, and now i don't intrude to some prohibited memory zones?

    I mean, i can live without that specific function, but i will need something one day :)

  • Hello, everybody!

    Thanks to cb1_mobile, i have solved this problem, and may be it is interesting for somebody else.

    So the problem appeared that the compiler (keil uVision 4.22) put "vpush.64 {d8-d8}" instruction as the first instruction of main. Since the FPU is disabled on reset, this instruction caused hard fault "NOCP".

    In some conditions the program did run, because optimization occasionally removed the vpush.64 from there. With optimization level 0 the faulty instruction was always there.

    So the first solution is to simply disable the FPU commands by setting Target Options>Targer>Floating Point Hardware>Not Used.

    To still use the FPU, it has to be enabled on reset, before main() runs. For that the reset_handler in the startup_rvmdk.s has to be changed:

    before B __main, the following has to be added:

    ; CPACR is located at address 0xE000ED88
    
    LDR.W   R0, =0xE000ED88
    
    ; Read CPACR
    
    LDR     R1, [R0]
    
    ; Set bits 20-23 to enable CP10 and CP11 coprocessors
    
    ORR     R1, R1, #(0xF << 20)
    
    ; Write back the modified value to the CPACR
    
    STR     R1, [R0]; wait for store to complete
    
    DSB
    
    ;reset pipeline now the FPU is enabled
    
    ISB
    

    This is FPU enabling code from here: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/BEHBJHIG.html

    And then it just works :D